Skip to content

Commit 985cf53

Browse files
authored
Add coalition, toAll and playerName to sendchat event (#298)
1 parent 619a719 commit 985cf53

5 files changed

Lines changed: 28 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Request uses `dcs.common.v0.ObjectCategory[]` and `SearchVolume` (with `InputPosition` for geo points).
1212
- Response returns `dcs.common.v0.Target[]` for consistent object union across services.
1313
- Lua implementation unwraps grpcui oneof wrapper (`volume.shape`) and supports both wrapped and flattened shapes.
14+
- Added `coalition`, `player_name`, and `to_all` fields to `PlayerSendChatEvent`.
1415

1516
## [0.8.1] 2024-11-05
1617

lua/DCS-gRPC/grpc-hook.lua

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,29 @@ end
4545
-- None of these methods should return anything as doing so breaks other scripts attempting to
4646
-- react to the hook as well.
4747

48-
function handler.onPlayerTrySendChat(playerID, msg)
48+
function handler.onPlayerTrySendChat(playerID, msg, all)
4949
-- note: currently `all` (third parameter) will always `=true` regardless if the target is to the coalition/team
5050
-- or to everybody. When ED fixes this, implementation should determine the dcs.common.v0.Coalition
51-
51+
local playerInfo = net.get_player_info(playerID)
52+
local coalition, playerName
53+
if playerInfo ~= nil then
54+
coalition = net.get_player_info(playerID, "side")
55+
playerName = net.get_player_info(playerID, "name")
56+
end
57+
local toAll = true
58+
if coalition ~= nil then coalition = coalition + 1 end
59+
if all == -2 then toAll = false end
5260
grpc.event({
5361
time = DCS.getModelTime(),
5462
event = {
5563
type = "playerSendChat",
5664
playerId = playerID,
57-
message = msg
65+
message = msg,
66+
coalition = coalition,
67+
playerName = playerName,
68+
toAll = toAll
5869
},
5970
})
60-
6171
end
6272

6373
function handler.onPlayerTryConnect(addr, name, ucid, id)

protos/dcs/mission/v0/mission.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ message StreamEventsResponse {
387387
uint32 player_id = 1;
388388
// what was typed
389389
string message = 2;
390+
// player's coalition
391+
dcs.common.v0.Coalition coalition = 3;
392+
// player's name
393+
string player_name = 4;
394+
// sent to all chat
395+
bool to_all = 5;
390396
}
391397

392398
// fired when the player changes across to a slot

src/authentication.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ impl RequestInterceptor for AuthInterceptor {
2626
}
2727
}
2828

29-
if client.is_some() {
30-
log::debug!("Authenticated client: {}", client.unwrap());
31-
Ok(req)
32-
} else {
33-
Err(Status::unauthenticated("Unauthenticated"))
29+
match client {
30+
Some(client_name) => {
31+
log::debug!("Authenticated client: {}", client_name);
32+
Ok(req)
33+
}
34+
_ => Err(Status::unauthenticated("Unauthenticated")),
3435
}
3536
}
3637
_ => Err(Status::unauthenticated("Unauthenticated")),

src/rpc/custom.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl CustomService for MissionRpc {
5252
Ok(Response::new(custom::v0::EvalResponse { json }))
5353
}
5454

55+
#[allow(clippy::result_large_err)]
5556
async fn get_magnetic_declination(
5657
&self,
5758
request: Request<custom::v0::GetMagneticDeclinationRequest>,

0 commit comments

Comments
 (0)