Skip to content

Commit

Permalink
Add events and methods to track SRS clients (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa authored Oct 19, 2023
1 parent bf3d9e1 commit e91b906
Show file tree
Hide file tree
Showing 25 changed files with 1,221 additions and 670 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Breaking Changes
- Renamed `TtsService` to `SrsService`

### Added
- Added `ActivateGroup` API which allows to activate groups with late activation.
- Added `DestroyGroup` API which removes the entire group from the game world.
- `DestroyUnit` API
- Added `DestroyUnit` API
- Added `GetClients` to `SrsService`, which retrieves a list of units that are connected to SRS and the frequencies they are connected to.
- Added `SrsConnectEvent` and `SrsDisconnectEvent` events

### Fixed
- Fixed `MarkAddEvent`, `MarkChangeEvent` and `MarkRemoveEvent` position
Expand Down
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1.24", features = ["rt-multi-thread", "io-util", "net", "sync", "time", "parking_lot"] }
tokio = { version = "1.24", features = ["rt-multi-thread", "io-util", "net", "sync", "time", "parking_lot", "macros"] }
tokio-stream = { version = "0.1", features = ["sync"] }
tonic = "0.8"

Expand All @@ -37,6 +37,7 @@ edition.workspace = true
crate-type = ["cdylib"]

[dependencies]
backoff = { version = "0.4", features = ["tokio"] }
dcs-module-ipc = "0.8"
futures-util.workspace = true
igrf = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build:
powershell copy target/debug/dcs_grpc.dll target/debug/dcs_grpc_hot_reload.dll

watch:
cargo watch -x "check --features hot-reload"
cargo watch --ignore version.lua -x "check --features hot-reload"

test:
cargo test
9 changes: 9 additions & 0 deletions lua/DCS-gRPC/methods/unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ GRPC.methods.getUnit = function(params)
return GRPC.success({unit = GRPC.exporters.unit(unit)})
end

GRPC.methods.getUnitById = function(params)
local unit = Unit.getByName(Unit.getName({ id_ = params.id }))
if unit == nil then
return GRPC.errorNotFound("unit with id `" .. tostring(params.id) .. "` does not exist")
end

return GRPC.success({unit = GRPC.exporters.unit(unit)})
end

GRPC.methods.unitDestroy = function(params)
local unit = Unit.getByName(params.name)
if unit == nil then
Expand Down
Empty file removed lua/lua_files.rs
Empty file.
4 changes: 2 additions & 2 deletions protos/dcs/dcs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import "dcs/group/v0/group.proto";
import "dcs/hook/v0/hook.proto";
import "dcs/mission/v0/mission.proto";
import "dcs/net/v0/net.proto";
import "dcs/srs/v0/srs.proto";
import "dcs/timer/v0/timer.proto";
import "dcs/trigger/v0/trigger.proto";
import "dcs/tts/v0/tts.proto";
import "dcs/unit/v0/unit.proto";
import "dcs/world/v0/world.proto";
import "dcs/world/v0/world.proto";
29 changes: 27 additions & 2 deletions protos/dcs/mission/v0/mission.proto
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ message StreamEventsResponse {
}

/**
* Fired for every TTS request that contains the `text_plain` field, for other clients to use e.g.
* for accessibility use-cases.
* Fired for every TTS request that contains the `text_plain` field, for other
* clients to use e.g. for accessibility use-cases.
*/
message TtsEvent {
// The plain text that got transmitted.
Expand All @@ -475,6 +475,29 @@ message StreamEventsResponse {
optional string srs_client_name = 4;
}

/**
* Fired every time a player occuping a unit connects to a frequency on SRS.
*/
message SrsConnectEvent {
// The unit that connected to a frequency in SRS.
dcs.common.v0.Unit unit = 1;

// The radio frequency in Hz the unit connected to.
uint64 frequency = 2;
}

/**
* Fired every time a player occuping a unit disconnects from a frequency on
* SRS. It is not fired when the player leaves the unit or the unit dies.
*/
message SrsDisconnectEvent {
// The unit that disconnected from a frequency in SRS.
dcs.common.v0.Unit unit = 1;

// The radio frequency in Hz the unit disconnected from.
uint64 frequency = 2;
}

// The event's mission time.
double time = 1;
oneof event {
Expand Down Expand Up @@ -528,6 +551,8 @@ message StreamEventsResponse {
GroupCommandEvent group_command = 8198;
SimulationFpsEvent simulation_fps = 8199;
TtsEvent tts = 8200;
SrsConnectEvent srs_connect = 8201;
SrsDisconnectEvent srs_disconnect = 8202;
}
}

Expand Down
26 changes: 22 additions & 4 deletions protos/dcs/tts/v0/tts.proto → protos/dcs/srs/v0/srs.proto
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
syntax = "proto3";
package dcs.tts.v0;
package dcs.srs.v0;
import "dcs/common/v0/common.proto";
option csharp_namespace = "RurouniJones.Dcs.Grpc.V0.Tts";
option go_package = "github.com/DCS-gRPC/go-bindings/dcs/v0/tts";
option csharp_namespace = "RurouniJones.Dcs.Grpc.V0.Srs";
option go_package = "github.com/DCS-gRPC/go-bindings/dcs/v0/srs";

service TtsService {
service SrsService {
// Synthesize text to speech and transmit it over SRS. By default, this blocks until a
// transmission completed (unless `async` is set to `true`). This can be used to prevent
// transmission to overlap each other, by not sending another transmission on the same frequency
// until you've received the response from the previous transmission on that frequency. However,
// it does not block or prevent any other client from transmitting over the same frequency at the
// same time.
rpc Transmit(TransmitRequest) returns (TransmitResponse) {}

// Retrieve a list of units (players) and their active frequencies that are connected to SRS.
rpc GetClients(GetClientsRequest) returns (GetClientsResponse) {}
}

message TransmitRequest {
Expand Down Expand Up @@ -86,3 +89,18 @@ message TransmitResponse {
// The duration in milliseconds it roughly takes to speak the transmission.
uint32 duration_ms = 1;
}

message GetClientsRequest {
}

message GetClientsResponse {
message Client {
// The unit that is connected to SRS.
dcs.common.v0.Unit unit = 1;

// The radio frequencies in Hz the unit is connected to.
repeated uint64 frequencies = 2;
}

repeated Client clients = 1;
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod integrity;
pub mod rpc;
mod server;
mod shutdown;
mod srs;
mod stats;
mod stream;

Expand Down
9 changes: 7 additions & 2 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use stubs::mission::v0::StreamEventsResponse;
use tokio::sync::RwLock;
use tonic::{Request, Status};

pub use self::tts::Tts;
pub use self::srs::Srs;
use crate::shutdown::ShutdownHandle;
use crate::stats::Stats;

Expand All @@ -18,9 +18,9 @@ mod group;
mod hook;
mod mission;
mod net;
mod srs;
mod timer;
mod trigger;
mod tts;
mod unit;
mod world;

Expand Down Expand Up @@ -80,6 +80,11 @@ impl MissionRpc {
pub async fn events(&self) -> impl Stream<Item = StreamEventsResponse> {
self.ipc.events().await
}

pub async fn event(&self, event: StreamEventsResponse) {
log::debug!("Received event: {:#?}", event);
self.ipc.event(event).await
}
}

impl HookRpc {
Expand Down
Loading

0 comments on commit e91b906

Please sign in to comment.