Skip to content

Commit c7823c1

Browse files
justin-lovellrurounijones
authored andcommitted
SendChat and SendChatTo
Initial implementation of the `net.*` namespace with the: - `send_chat_to` - `send_chat` `send_chat_to` does not implement the DCS API parameter of `fromPlayerId` due to the social impact of a player being emulated is more severe than a breached system and hence why the parameter has been redacted. If there is a valid use case, please do feel free to present your use case and why alternatives do not meet the user requirements. See PR #94 Added `net` as global read for lua linter
1 parent ca52949 commit c7823c1

File tree

10 files changed

+94
-0
lines changed

10 files changed

+94
-0
lines changed

.luacheckrc

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ read_globals = {
77
"AI",
88
"atmosphere",
99
"coalition",
10+
"net",
1011
"coord",
1112
"DCS",
1213
"env",

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Generated scaffolding for the `net.*` scope into `NetService`
10+
- `SendChat` API
11+
- `SendChatTo` API
12+
813
### Changed
914
- Stream `PlayerSendChatEvent` to the `MissionService.StreamEvents` for clients to observe the chat as part of the event stream
1015

lua/DCS-gRPC/grpc.lua

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ dofile(GRPC.luaPath .. [[methods\custom.lua]])
143143
dofile(GRPC.luaPath .. [[methods\group.lua]])
144144
dofile(GRPC.luaPath .. [[methods\hook.lua]])
145145
dofile(GRPC.luaPath .. [[methods\mission.lua]])
146+
dofile(GRPC.luaPath .. [[methods\net.lua]])
146147
dofile(GRPC.luaPath .. [[methods\timer.lua]])
147148
dofile(GRPC.luaPath .. [[methods\trigger.lua]])
148149
dofile(GRPC.luaPath .. [[methods\unit.lua]])

lua/DCS-gRPC/methods/net.lua

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--
2+
-- RPC net actions
3+
-- https://wiki.hoggitworld.com/view/DCS_singleton_net
4+
--
5+
6+
GRPC.methods.sendChatTo = function(params)
7+
-- note: it was explicitly decided not to place "from player id" parameter
8+
-- due to the magnitude of a social attack vector.
9+
-- https://github.com/DCS-gRPC/rust-server/pull/94#discussion_r780777794
10+
net.send_chat_to(params.message, params.targetPlayerId)
11+
return GRPC.success(nil)
12+
end
13+
14+
GRPC.methods.sendChat = function(params)
15+
if params.coalition > 1 then
16+
return GRPC.errorInvalidArgument("Chat messages can only be sent to all or neutral/spectators")
17+
end
18+
19+
local toAll = params.coalition ~= 1
20+
net.send_chat(params.message, toAll)
21+
return GRPC.success(nil)
22+
end

protos/dcs/dcs.proto

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "dcs/custom/v0/custom.proto";
1010
import "dcs/group/v0/group.proto";
1111
import "dcs/hook/v0/hook.proto";
1212
import "dcs/mission/v0/mission.proto";
13+
import "dcs/net/v0/net.proto";
1314
import "dcs/timer/v0/timer.proto";
1415
import "dcs/trigger/v0/trigger.proto";
1516
import "dcs/unit/v0/unit.proto";

protos/dcs/net/v0/net.proto

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
syntax = "proto3";
2+
package dcs.net.v0;
3+
import "dcs/common/v0/common.proto";
4+
5+
service NetService {
6+
// https://wiki.hoggitworld.com/view/DCS_func_send_chat_to
7+
rpc SendChatTo(SendChatToRequest) returns (SendChatToResponse) {}
8+
9+
// https://wiki.hoggitworld.com/view/DCS_func_send_chat
10+
rpc SendChat(SendChatRequest) returns (SendChatResponse) {}
11+
}
12+
13+
message SendChatToRequest {
14+
// the message to send in the chat
15+
string message = 1;
16+
// the target player of the direct message
17+
uint32 target_player_id = 2;
18+
}
19+
20+
message SendChatToResponse {}
21+
22+
message SendChatRequest {
23+
// the message to send in the chat
24+
string message = 1;
25+
// which coalition? DCS only supports ALL or NEUTRAL (only applicable to send_chat)
26+
dcs.common.v0.Coalition coalition = 2;
27+
}
28+
29+
message SendChatResponse {}

src/rpc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod custom;
1515
mod group;
1616
mod hook;
1717
mod mission;
18+
mod net;
1819
mod timer;
1920
mod trigger;
2021
mod unit;

src/rpc/net.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::MissionRpc;
2+
use stubs::net::v0::net_service_server::NetService;
3+
use stubs::*;
4+
use tonic::{Request, Response, Status};
5+
6+
#[tonic::async_trait]
7+
impl NetService for MissionRpc {
8+
async fn send_chat_to(
9+
&self,
10+
request: Request<net::v0::SendChatToRequest>,
11+
) -> Result<Response<net::v0::SendChatToResponse>, Status> {
12+
self.notification("sendChatTo", request).await?;
13+
Ok(Response::new(net::v0::SendChatToResponse {}))
14+
}
15+
16+
async fn send_chat(
17+
&self,
18+
request: Request<net::v0::SendChatRequest>,
19+
) -> Result<Response<net::v0::SendChatResponse>, Status> {
20+
self.notification("sendChat", request).await?;
21+
Ok(Response::new(net::v0::SendChatResponse {}))
22+
}
23+
}

src/services.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use stubs::custom::v0::custom_service_server::CustomServiceServer;
66
use stubs::group::v0::group_service_server::GroupServiceServer;
77
use stubs::hook::v0::hook_service_server::HookServiceServer;
88
use stubs::mission::v0::mission_service_server::MissionServiceServer;
9+
use stubs::net::v0::net_service_server::NetServiceServer;
910
use stubs::timer::v0::timer_service_server::TimerServiceServer;
1011
use stubs::trigger::v0::trigger_service_server::TriggerServiceServer;
1112
use stubs::unit::v0::unit_service_server::UnitServiceServer;
@@ -36,6 +37,7 @@ pub struct DcsServices {
3637
group: GroupServiceServer<MissionRpc>,
3738
hook: HookServiceServer<HookRpc>,
3839
mission: MissionServiceServer<MissionRpc>,
40+
net: NetServiceServer<MissionRpc>,
3941
timer: TimerServiceServer<MissionRpc>,
4042
trigger: TriggerServiceServer<MissionRpc>,
4143
unit: UnitServiceServer<MissionRpc>,
@@ -52,6 +54,7 @@ impl DcsServices {
5254
group: GroupServiceServer::new(mission_rpc.clone()),
5355
hook: HookServiceServer::new(hook_rpc),
5456
mission: MissionServiceServer::new(mission_rpc.clone()),
57+
net: NetServiceServer::new(mission_rpc.clone()),
5558
timer: TimerServiceServer::new(mission_rpc.clone()),
5659
trigger: TriggerServiceServer::new(mission_rpc.clone()),
5760
unit: UnitServiceServer::new(mission_rpc.clone()),
@@ -93,6 +96,8 @@ impl Service<http::Request<transport::Body>> for DcsServices {
9396
self.hook.call(req)
9497
} else if path.starts_with(MissionServiceServer::<MissionRpc>::NAME) {
9598
self.mission.call(req)
99+
} else if path.starts_with(NetServiceServer::<MissionRpc>::NAME) {
100+
self.net.call(req)
96101
} else if path.starts_with(TimerServiceServer::<MissionRpc>::NAME) {
97102
self.timer.call(req)
98103
} else if path.starts_with(TriggerServiceServer::<MissionRpc>::NAME) {

stubs/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ pub mod mission {
4646
}
4747
}
4848

49+
pub mod net {
50+
pub mod v0 {
51+
tonic::include_proto!("dcs.net.v0");
52+
}
53+
}
54+
4955
pub mod timer {
5056
pub mod v0 {
5157
tonic::include_proto!("dcs.timer.v0");

0 commit comments

Comments
 (0)