Skip to content

Commit c437fb4

Browse files
justin-lovellrurounijones
authored andcommitted
GetPlayers returns all connected player attributes
Getting the player info based on the players connected to the server. This is a combined loop of `net.get_player_list` and `net.get_player_info`. Notes about the player information which differs from official documentation. - locale is an undocumented attribute / would serve well for multilingual cases - ipAddr is actually `{address}:{port}` It was decided to perform the compound variation of the API. In theory, it should work effectively but needs to be verified by densely populated servers.
1 parent c7823c1 commit c437fb4

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Generated scaffolding for the `net.*` scope into `NetService`
1010
- `SendChat` API
1111
- `SendChatTo` API
12+
- `GetPlayers` API
1213

1314
### Changed
1415
- Stream `PlayerSendChatEvent` to the `MissionService.StreamEvents` for clients to observe the chat as part of the event stream

lua/DCS-gRPC/methods/net.lua

+21
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,24 @@ GRPC.methods.sendChat = function(params)
2020
net.send_chat(params.message, toAll)
2121
return GRPC.success(nil)
2222
end
23+
24+
GRPC.methods.getPlayers = function()
25+
local players = {};
26+
27+
for _,v in pairs(net.get_player_list()) do
28+
local playerInfo = net.get_player_info(v);
29+
30+
table.insert(players, {
31+
id = playerInfo.id,
32+
name = playerInfo.name,
33+
coalition = playerInfo.side + 1, -- common.Coalition enum offset
34+
slot = playerInfo.slot,
35+
ping = playerInfo.ping,
36+
remoteAddress = playerInfo.ipaddr,
37+
ucid = playerInfo.ucid,
38+
locale = playerInfo.lang
39+
})
40+
end
41+
42+
return GRPC.success({players = players})
43+
end

protos/dcs/net/v0/net.proto

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ service NetService {
88

99
// https://wiki.hoggitworld.com/view/DCS_func_send_chat
1010
rpc SendChat(SendChatRequest) returns (SendChatResponse) {}
11+
12+
// returns a list of all connected players.
13+
// https://wiki.hoggitworld.com/view/DCS_func_get_player_info
14+
rpc GetPlayers(GetPlayersRequest) returns (GetPlayersResponse) {}
1115
}
1216

1317
message SendChatToRequest {
@@ -27,3 +31,31 @@ message SendChatRequest {
2731
}
2832

2933
message SendChatResponse {}
34+
35+
message GetPlayersRequest {}
36+
37+
message GetPlayersResponse {
38+
message GetPlayerInfo {
39+
// the player id
40+
uint32 id = 1;
41+
// player's online name
42+
string name = 2;
43+
// coalition which player is slotted in
44+
dcs.common.v0.Coalition coalition = 3;
45+
// the slot identifier
46+
string slot = 4;
47+
// the ping of the player
48+
uint32 ping = 5;
49+
// the connection ip address and port the client has established with the server
50+
string remoteAddress = 6;
51+
// the unique identifier for the player
52+
string ucid = 7;
53+
// abbreviated language (locale) e.g. "en"
54+
string locale = 8;
55+
}
56+
57+
// list of all the players connected to the server
58+
repeated GetPlayerInfo players = 1;
59+
}
60+
61+

src/rpc/net.rs

+8
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ impl NetService for MissionRpc {
2020
self.notification("sendChat", request).await?;
2121
Ok(Response::new(net::v0::SendChatResponse {}))
2222
}
23+
24+
async fn get_players(
25+
&self,
26+
request: Request<net::v0::GetPlayersRequest>,
27+
) -> Result<Response<net::v0::GetPlayersResponse>, Status> {
28+
let res: net::v0::GetPlayersResponse = self.request("getPlayers", request).await?;
29+
Ok(Response::new(res))
30+
}
2331
}

0 commit comments

Comments
 (0)