diff --git a/CHANGELOG.md b/CHANGELOG.md index e0477dda..d4d51537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Generated scaffolding for the `net.*` scope into `NetService` - `SendChat` API - `SendChatTo` API +- `GetPlayers` API ### Changed - Stream `PlayerSendChatEvent` to the `MissionService.StreamEvents` for clients to observe the chat as part of the event stream diff --git a/lua/DCS-gRPC/methods/net.lua b/lua/DCS-gRPC/methods/net.lua index f36a7921..54910e09 100644 --- a/lua/DCS-gRPC/methods/net.lua +++ b/lua/DCS-gRPC/methods/net.lua @@ -20,3 +20,24 @@ GRPC.methods.sendChat = function(params) net.send_chat(params.message, toAll) return GRPC.success(nil) end + +GRPC.methods.getPlayers = function() + local players = {}; + + for _,v in pairs(net.get_player_list()) do + local playerInfo = net.get_player_info(v); + + table.insert(players, { + id = playerInfo.id, + name = playerInfo.name, + coalition = playerInfo.side + 1, -- common.Coalition enum offset + slot = playerInfo.slot, + ping = playerInfo.ping, + remoteAddress = playerInfo.ipaddr, + ucid = playerInfo.ucid, + locale = playerInfo.lang + }) + end + + return GRPC.success({players = players}) +end diff --git a/protos/dcs/net/v0/net.proto b/protos/dcs/net/v0/net.proto index 66bcc11e..2990166f 100644 --- a/protos/dcs/net/v0/net.proto +++ b/protos/dcs/net/v0/net.proto @@ -8,6 +8,10 @@ service NetService { // https://wiki.hoggitworld.com/view/DCS_func_send_chat rpc SendChat(SendChatRequest) returns (SendChatResponse) {} + + // returns a list of all connected players. + // https://wiki.hoggitworld.com/view/DCS_func_get_player_info + rpc GetPlayers(GetPlayersRequest) returns (GetPlayersResponse) {} } message SendChatToRequest { @@ -27,3 +31,31 @@ message SendChatRequest { } message SendChatResponse {} + +message GetPlayersRequest {} + +message GetPlayersResponse { + message GetPlayerInfo { + // the player id + uint32 id = 1; + // player's online name + string name = 2; + // coalition which player is slotted in + dcs.common.v0.Coalition coalition = 3; + // the slot identifier + string slot = 4; + // the ping of the player + uint32 ping = 5; + // the connection ip address and port the client has established with the server + string remoteAddress = 6; + // the unique identifier for the player + string ucid = 7; + // abbreviated language (locale) e.g. "en" + string locale = 8; + } + + // list of all the players connected to the server + repeated GetPlayerInfo players = 1; +} + + diff --git a/src/rpc/net.rs b/src/rpc/net.rs index 4a1be4ab..8250e86c 100644 --- a/src/rpc/net.rs +++ b/src/rpc/net.rs @@ -20,4 +20,12 @@ impl NetService for MissionRpc { self.notification("sendChat", request).await?; Ok(Response::new(net::v0::SendChatResponse {})) } + + async fn get_players( + &self, + request: Request, + ) -> Result, Status> { + let res: net::v0::GetPlayersResponse = self.request("getPlayers", request).await?; + Ok(Response::new(res)) + } }