More careful disconnection.

This commit is contained in:
Gregor Richards 2016-12-13 19:25:09 -05:00
parent c8bba9a981
commit ab989d7f41
2 changed files with 20 additions and 12 deletions

View File

@ -298,21 +298,28 @@ static void hangup(netplay_t *netplay, struct netplay_connection *connection)
netplay_deinit_socket_buffer(&connection->recv_packet_buffer);
if (!netplay->is_server)
netplay->self_mode = NETPLAY_CONNECTION_NONE;
/* Remove this player */
if (connection->mode == NETPLAY_CONNECTION_PLAYING)
{
netplay->connected_players &= ~(1<<connection->player);
netplay->self_mode = NETPLAY_CONNECTION_NONE;
netplay->connected_players = 0;
/* FIXME: Duplication */
if (netplay->is_server)
}
else
{
/* Remove this player */
if (connection->mode == NETPLAY_CONNECTION_PLAYING)
{
uint32_t payload[2];
payload[0] = htonl(netplay->read_frame_count[connection->player]);
payload[1] = htonl(connection->player);
netplay_send_raw_cmd_all(netplay, connection, NETPLAY_CMD_MODE, payload, sizeof(payload));
netplay->connected_players &= ~(1<<connection->player);
/* FIXME: Duplication */
if (netplay->is_server)
{
uint32_t payload[2];
payload[0] = htonl(netplay->read_frame_count[connection->player]);
payload[1] = htonl(connection->player);
netplay_send_raw_cmd_all(netplay, connection, NETPLAY_CMD_MODE, payload, sizeof(payload));
}
}
}
}

View File

@ -245,7 +245,8 @@ void netplay_sync_post_frame(netplay_t *netplay)
netplay->self_frame_count++;
/* Only relevant if we're connected */
if (netplay->is_server && !netplay->connected_players)
if ((netplay->is_server && !netplay->connected_players) ||
(netplay->self_mode < NETPLAY_CONNECTION_CONNECTED))
{
netplay->other_frame_count = netplay->self_frame_count;
netplay->other_ptr = netplay->self_ptr;