Don't allow more players to join than are actually being polled

This commit is contained in:
Gregor Richards 2016-12-14 22:02:01 -05:00
parent 7ad4e3f115
commit 694b7a9723
4 changed files with 12 additions and 5 deletions

View File

@ -333,6 +333,9 @@ static int16_t netplay_input_state(netplay_t *netplay,
return 0;
}
if (port > netplay->player_max)
netplay->player_max = port;
if (netplay->buffer[ptr].have_real[port])
{
netplay->buffer[ptr].used_real[port] = true;

View File

@ -414,6 +414,7 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
netplay->tcp_port = port;
netplay->cbs = *cb;
netplay->connected_players = 0;
netplay->player_max = 1;
netplay->is_server = server == NULL;
netplay->nat_traversal = netplay->is_server ? nat_traversal : false;
netplay->delay_frames = delay_frames;

View File

@ -567,17 +567,17 @@ static bool netplay_get_cmd(netplay_t *netplay,
return netplay_cmd_nak(netplay, connection);
/* Find an available player slot */
for (player = 0; player < MAX_USERS; player++)
for (player = 0; player <= netplay->player_max; player++)
{
if (!(netplay->self_mode == NETPLAY_CONNECTION_PLAYING &&
netplay->self_player == player) &&
!(netplay->connected_players & (1<<player)))
break;
}
if (player == MAX_USERS)
if (player > netplay->player_max)
{
/* FIXME */
return netplay_cmd_nak(netplay, connection);
/* Sorry, you can't play! */
break;
}
if (connection->mode != NETPLAY_CONNECTION_PLAYING)

View File

@ -304,7 +304,10 @@ struct netplay
/* Bitmap of players with controllers (whether local or remote) (low bit is
* player 1) */
int connected_players;
uint32_t connected_players;
/* Maximum player number */
uint32_t player_max;
struct retro_callbacks cbs;