From 0d4a53766e151a31e5ae1291837f77abb43eda37 Mon Sep 17 00:00:00 2001 From: zicodxx <> Date: Wed, 25 Nov 2009 00:26:26 +0000 Subject: [PATCH] Again making the joining safer --- CHANGELOG.txt | 1 + main/net_udp.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4a25fb668..798419a8f 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -6,6 +6,7 @@ include/args.h, INSTALL.txt, main/net_udp.c, main/net_udp.h, main/fireball.c, ma main/net_udp.c: Remove the IP check when processing game info or version deny as the IP might be translated (IPv6 especially) main/net_udp.c, main/net_ipx.c, SConstruct: Improved Disconnect-handling between levels; Improved Kick-handling; Do not say that IPv4 and IPv6 builds are not compatible in scons -h anymore include/timer.h, main/net_udp.c, main/newmenu.c, main/multibot.c, main/menu.c, main/titles.c, main/kmatrix.c, main/net_ipx.c, main/digiobj.c, arch/sdl/timer.c: Removed timer_get_approx_seconds() and replaced with timer_get_fixed seconds since it was too inaccurate and created significant offset +main/net_udp.c: Again making the joining safer 20091117 -------- diff --git a/main/net_udp.c b/main/net_udp.c index 4c39c5374..834967815 100644 --- a/main/net_udp.c +++ b/main/net_udp.c @@ -855,7 +855,7 @@ void net_udp_welcome_player(UDP_sequence_packet *their) for (i = 0; i < N_players; i++) { - if (!memcmp((struct _sockaddr *)&their->player.protocol.udp.addr, (struct _sockaddr *)&Netgame.players[i].protocol.udp.addr, sizeof(struct _sockaddr))) + if ((!strcasecmp(Players[i].callsign, their->player.callsign )) && !memcmp((struct _sockaddr *)&their->player.protocol.udp.addr, (struct _sockaddr *)&Netgame.players[i].protocol.udp.addr, sizeof(struct _sockaddr))) { player_num = i; break; @@ -956,6 +956,7 @@ void net_udp_welcome_player(UDP_sequence_packet *their) UDP_sync_player.player.connected = player_num; Network_send_objects = 1; Network_send_objnum = -1; + Netgame.players[player_num].LastPacketTime = timer_get_fixed_seconds(); net_udp_send_objects(); } @@ -1461,11 +1462,13 @@ char * net_udp_get_player_name( int objnum ) void net_udp_add_player(UDP_sequence_packet *p) { int i; + fix time = timer_get_fixed_seconds(); for (i=0; iplayer.protocol.udp.addr, sizeof(struct _sockaddr))) { + Netgame.players[i].LastPacketTime = time; return; // already got them } } @@ -1485,7 +1488,7 @@ void net_udp_add_player(UDP_sequence_packet *p) net_udp_check_for_old_version (N_players); Players[N_players].KillGoalCount=0; Players[N_players].connected = CONNECT_PLAYING; - Netgame.players[N_players].LastPacketTime = timer_get_fixed_seconds(); + Netgame.players[N_players].LastPacketTime = time; N_players++; Netgame.numplayers = N_players; @@ -2057,9 +2060,10 @@ void net_udp_process_request(UDP_sequence_packet *their) int i; for (i = 0; i < N_players; i++) - if (!memcmp((struct _sockaddr *)&their->player.protocol.udp.addr, (struct _sockaddr *)&Netgame.players[i].protocol.udp.addr, sizeof(struct _sockaddr))) + if (!memcmp((struct _sockaddr *)&their->player.protocol.udp.addr, (struct _sockaddr *)&Netgame.players[i].protocol.udp.addr, sizeof(struct _sockaddr)) && (!strcasecmp(their->player.callsign, Netgame.players[i].callsign))) { Players[i].connected = CONNECT_PLAYING; + Netgame.players[i].LastPacketTime = timer_get_fixed_seconds(); break; } } @@ -3039,7 +3043,7 @@ void net_udp_send_sync(void) } // Randomize their starting locations... - + d_srand( timer_get_fixed_seconds() ); for (i=0; i time)) { Netgame.players[i].LastPacketTime = time; - continue; } - if ((time - Netgame.players[i].LastPacketTime) > UDP_TIMEOUT) + else if ((time - Netgame.players[i].LastPacketTime) > UDP_TIMEOUT) { net_udp_timeout_player(i); }