From 18f098ba93f541ff625d4c980dd7e38b90dc6191 Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 14 Dec 2009 09:54:11 +0000 Subject: [PATCH] more multiplayer fixes git-svn-id: https://svn.eduke32.com/eduke32@1570 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/duke3d.h | 4 ++-- polymer/eduke32/source/game.c | 41 ++++++++++++++++++++++---------- polymer/eduke32/source/global.c | 2 +- polymer/eduke32/source/osdcmds.c | 3 ++- polymer/eduke32/source/player.c | 22 ++++++++--------- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index 69777cff6..3a02dcae9 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -1104,6 +1104,7 @@ enum DukePacket_t PACKET_REQUEST_GAMESTATE, PACKET_NEW_GAME, PACKET_LOAD_GAME, + PACKET_VERSION, // any packet with an ID higher than PACKET_BROADCAST is rebroadcast by server // this is so hacked clients can't create fake server packets and get the server @@ -1114,7 +1115,6 @@ enum DukePacket_t PACKET_WEAPON_CHOICE, PACKET_PLAYER_OPTIONS, PACKET_PLAYER_NAME, - PACKET_VERSION, PACKET_MESSAGE, PACKET_USER_MAP, @@ -1123,7 +1123,7 @@ enum DukePacket_t PACKET_MAP_VOTE_CANCEL, PACKET_PLAYER_READY, - PACKET_QUIT = 255 // should match mmulti I think + PACKET_QUIT = 255 }; #pragma pack(pop) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 8a404b5c8..e7344b593 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -53,6 +53,7 @@ ENetHost * net_server = NULL; ENetHost * net_client = NULL; ENetPeer * net_peer = NULL; int32_t net_port = 23513; +int32_t g_netDisconnect = 0; #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -696,8 +697,7 @@ void Net_SendQuit(void) { g_gameQuit = 1; quittimer = totalclock+120; - Net_Disconnect(); - G_GameExit(" "); + g_netDisconnect = 1; } else if (numplayers < 2) G_GameExit(" "); @@ -732,8 +732,8 @@ static void Net_SendVersion(void) if (numplayers < 2) return; buf[0] = PACKET_VERSION; - buf[1] = (uint8_t)atoi(s_buildDate); - buf[2] = BYTEVERSION; + buf[1] = BYTEVERSION; + buf[2] = (uint8_t)atoi(s_buildDate); buf[3] = myconnectindex; if (net_client) @@ -1224,16 +1224,20 @@ process: break; case PACKET_VERSION: - if (packbuf[1] != (uint8_t)atoi(s_buildDate)) + if (net_client) { - initprintf("Player %d has version %d, expecting %d\n",other,packbuf[1],(uint8_t)atoi(s_buildDate)); - G_GameExit("You cannot play with different versions of EDuke32!"); - } - if (packbuf[2] != BYTEVERSION) - { - initprintf("Player %d has version %d, expecting %d\n",other,packbuf[2],BYTEVERSION); - G_GameExit("You cannot play Duke with different versions!"); + if (packbuf[1] != BYTEVERSION || packbuf[2] != (uint8_t)atoi(s_buildDate)) + { + Bsprintf(tempbuf, "Server protocol is version %d.%d, expecting %d.%d\n", + packbuf[1], packbuf[2], BYTEVERSION, (uint8_t)atoi(s_buildDate)); + initprintf(tempbuf); + initprintf("Version mismatch! You cannot play Duke with different versions!\n"); + g_netDisconnect = 1; + return; + } } + else if (net_server) + Net_SendVersion(); break; case PACKET_NUM_PLAYERS: @@ -1462,6 +1466,15 @@ void Net_GetPackets(void) G_HandleSpecialKeys(); + if (g_netDisconnect) + { + Net_Disconnect(); + g_netDisconnect = 0; + + if (g_gameQuit) + G_GameExit(" "); + } + if (net_server) { ENetEvent event; @@ -1643,12 +1656,14 @@ void Net_GetPackets(void) else { initprintf("Invalid map state from server!\n"); - Net_Disconnect(); + g_netDisconnect = 1; + return; } } else { initprintf("Error allocating memory!\n"); + g_netDisconnect = 1; return; } } diff --git a/polymer/eduke32/source/global.c b/polymer/eduke32/source/global.c index e9868fb75..ede4a8389 100644 --- a/polymer/eduke32/source/global.c +++ b/polymer/eduke32/source/global.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //------------------------------------------------------------------------- #include "duke3d.h" -const char *s_buildDate = "20091212"; +const char *s_buildDate = "20091214"; char *MusicPtr = NULL; int32_t g_musicSize; diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 37d4ebd6c..11db40288 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -1149,8 +1149,9 @@ static int32_t osdcmd_inittimer(const osdfuncparm_t *parm) static int32_t osdcmd_disconnect(const osdfuncparm_t *parm) { + extern int32_t g_netDisconnect; UNREFERENCED_PARAMETER(parm); - Net_Disconnect(); + g_netDisconnect = 1; return OSDCMD_OK; } diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 2dc3f1d57..cf59d8d6b 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -3826,17 +3826,6 @@ void P_FragPlayer(int32_t snum) randomseed = ticrandomseed; - if (net_server) - { - packbuf[0] = PACKET_FRAG; - packbuf[1] = snum; - packbuf[2] = p->frag_ps; - packbuf[3] = ActorExtra[p->i].picnum; - packbuf[4] = myconnectindex; - - enet_host_broadcast(net_server, 0, enet_packet_create(packbuf, 5, ENET_PACKET_FLAG_RELIABLE)); - } - if (s->pal != 1) { p->pals[0] = 63; @@ -3855,6 +3844,17 @@ void P_FragPlayer(int32_t snum) p->dead_flag = (512-((krand()&1)<<10)+(krand()&255)-512)&2047; if (p->dead_flag == 0) p->dead_flag++; + + if (net_server) + { + packbuf[0] = PACKET_FRAG; + packbuf[1] = snum; + packbuf[2] = p->frag_ps; + packbuf[3] = ActorExtra[p->i].picnum; + packbuf[4] = myconnectindex; + + enet_host_broadcast(net_server, 0, enet_packet_create(packbuf, 5, ENET_PACKET_FLAG_RELIABLE)); + } } p->jetpack_on = 0;