Skip to content

Commit 9504583

Browse files
authored
Push room info to lobby when publicly hosting (#18267)
* Announce netplay player information to the lobby server This information is optional and merely informational. The lobby might ignore it (and it ignores it at the current version). * Display lobby information on player/spectator counts
1 parent 4d87f25 commit 9504583

6 files changed

Lines changed: 69 additions & 4 deletions

File tree

intl/msg_hash_us.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14213,6 +14213,14 @@ MSG_HASH(
1421314213
MSG_NETPLAY_S_HAS_JOINED_WITH_INPUT_DEVICES_S,
1421414214
"%.*s has joined with input devices %.*s"
1421514215
)
14216+
MSG_HASH(
14217+
MSG_NETPLAY_PLAYERS_INFO,
14218+
"%d player(s)"
14219+
)
14220+
MSG_HASH(
14221+
MSG_NETPLAY_SPECTATORS_INFO,
14222+
"%d player(s) (%d spectating)"
14223+
)
1421614224
MSG_HASH(
1421714225
MSG_NETPLAY_NOT_RETROARCH,
1421814226
"A netplay connection attempt failed because the peer is not running RetroArch, or is running an old version of RetroArch."

menu/cbs/menu_cbs_sublabel.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,14 +1817,23 @@ static int action_bind_sublabel_netplay_room(file_list_t *list,
18171817

18181818
if ( string_is_empty(room->subsystem_name)
18191819
|| string_is_equal_case_insensitive(room->subsystem_name, "N/A"))
1820-
snprintf(s + _len, len - _len, "(%08lX)",
1820+
_len += snprintf(s + _len, len - _len, "(%08lX)\n",
18211821
(unsigned long)(unsigned)room->gamecrc);
18221822
else
18231823
{
18241824
_len += strlcpy(s + _len, "(", len - _len);
18251825
_len += strlcpy(s + _len, room->subsystem_name, len - _len);
1826-
strlcpy(s + _len, ")", len - _len);
1826+
_len += strlcpy(s + _len, ")\n", len - _len);
18271827
}
1828+
1829+
if (room->spectator_count > 0)
1830+
_len += snprintf(s + _len, len - _len,
1831+
msg_hash_to_str(MSG_NETPLAY_SPECTATORS_INFO),
1832+
room->player_count, room->spectator_count);
1833+
else if (room->player_count >= 0)
1834+
_len += snprintf(s + _len, len - _len,
1835+
msg_hash_to_str(MSG_NETPLAY_PLAYERS_INFO),
1836+
room->player_count);
18281837
return 0;
18291838
}
18301839

msg_hash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ enum msg_hash_enums
208208
MSG_NETPLAY_PLAYER_S_LEFT,
209209
MSG_NETPLAY_S_HAS_JOINED_AS_PLAYER_N,
210210
MSG_NETPLAY_S_HAS_JOINED_WITH_INPUT_DEVICES_S,
211+
MSG_NETPLAY_PLAYERS_INFO,
212+
MSG_NETPLAY_SPECTATORS_INFO,
211213
MSG_NETPLAY_NOT_RETROARCH,
212214
MSG_NETPLAY_OUT_OF_DATE,
213215
MSG_NETPLAY_DIFFERENT_VERSIONS,

network/netplay/netplay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct netplay_room
7272
int port;
7373
int mitm_port;
7474
int host_method;
75+
int player_count;
76+
int spectator_count;
7577
char nickname[NETPLAY_NICK_LEN];
7678
char frontend[NETPLAY_HOST_STR_LEN];
7779
char corename[NETPLAY_HOST_STR_LEN];

network/netplay/netplay_frontend.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8400,6 +8400,31 @@ static bool netplay_should_skip(netplay_t *netplay)
84008400
netplay->self_mode >= NETPLAY_CONNECTION_CONNECTED;
84018401
}
84028402

8403+
static size_t retrieve_client_count(netplay_t *netplay,
8404+
unsigned *players, unsigned *spectators)
8405+
{
8406+
size_t i, r = 0;
8407+
8408+
for (i = 0; i < netplay->connections_size; i++)
8409+
{
8410+
struct netplay_connection *connection = &netplay->connections[i];
8411+
8412+
/* We only want info from already connected clients. */
8413+
if ( (connection->flags & NETPLAY_CONN_FLAG_ACTIVE)
8414+
&& (connection->mode >= NETPLAY_CONNECTION_CONNECTED))
8415+
{
8416+
r++;
8417+
if (connection->mode == NETPLAY_CONNECTION_SPECTATING)
8418+
(*spectators)++;
8419+
else if (connection->mode == NETPLAY_CONNECTION_PLAYING
8420+
|| connection->mode == NETPLAY_CONNECTION_SLAVE)
8421+
(*players)++;
8422+
}
8423+
}
8424+
8425+
return r;
8426+
}
8427+
84038428
bool init_netplay_deferred(const char *server, unsigned port, const char *mitm_session)
84048429
{
84058430
net_driver_state_t *net_st = &networking_driver_st;
@@ -8600,6 +8625,8 @@ static void netplay_announce(netplay_t *netplay)
86008625
int mitm_custom_port = 0;
86018626
int is_mitm = 0;
86028627
uint32_t content_crc = 0;
8628+
unsigned players = 0;
8629+
unsigned spectators = 0;
86038630
net_driver_state_t *net_st = &networking_driver_st;
86048631
struct netplay_room *host_room = &net_st->host_room;
86058632
struct retro_system_info *system = &runloop_state_get_ptr()->system.info;
@@ -8678,6 +8705,15 @@ static void netplay_announce(netplay_t *netplay)
86788705
else
86798706
net_http_urlencode(&mitm_custom_addr, "");
86808707

8708+
/* Purely informational, should not be used to guess if a host is full. */
8709+
retrieve_client_count(netplay, &players, &spectators);
8710+
8711+
if (netplay->self_mode == NETPLAY_CONNECTION_SPECTATING)
8712+
spectators++;
8713+
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING
8714+
|| netplay->self_mode == NETPLAY_CONNECTION_SLAVE)
8715+
players++;
8716+
86818717
/* Estimated to a maximum of 3062 bytes. */
86828718
snprintf(buf, sizeof(buf),
86838719
"username=%s&"
@@ -8695,7 +8731,9 @@ static void netplay_announce(netplay_t *netplay)
86958731
"subsystem_name=%s&"
86968732
"mitm_session=%s&"
86978733
"mitm_custom_addr=%s&"
8698-
"mitm_custom_port=%d",
8734+
"mitm_custom_port=%d&"
8735+
"player_count=%d&"
8736+
"spectator_count=%d",
86998737
username,
87008738
corename,
87018739
coreversion,
@@ -8711,7 +8749,9 @@ static void netplay_announce(netplay_t *netplay)
87118749
subsystemname,
87128750
mitm_session,
87138751
mitm_custom_addr,
8714-
mitm_custom_port);
8752+
mitm_custom_port,
8753+
players,
8754+
spectators);
87158755

87168756
if (task_push_http_post_transfer(FILE_PATH_LOBBY_LIBRETRO_URL "add", buf,
87178757
true, NULL, netplay_announce_cb, NULL))

network/netplay/netplay_room_parse.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ static bool netplay_json_object_member(void *ctx, const char *p_value,
223223
p_ctx->cur_member_bool = &net_st->rooms_data->cur->connectable;
224224
else if (string_is_equal(p_value, "is_retroarch"))
225225
p_ctx->cur_member_bool = &net_st->rooms_data->cur->is_retroarch;
226+
else if (string_is_equal(p_value, "player_count"))
227+
p_ctx->cur_member_int = &net_st->rooms_data->cur->player_count;
228+
else if (string_is_equal(p_value, "spectator_count"))
229+
p_ctx->cur_member_int = &net_st->rooms_data->cur->spectator_count;
226230
}
227231
}
228232

0 commit comments

Comments
 (0)