more multiplayer fixes

git-svn-id: https://svn.eduke32.com/eduke32@1570 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2009-12-14 09:54:11 +00:00
parent e38f060ce8
commit 18f098ba93
5 changed files with 44 additions and 28 deletions

View file

@ -1104,6 +1104,7 @@ enum DukePacket_t
PACKET_REQUEST_GAMESTATE, PACKET_REQUEST_GAMESTATE,
PACKET_NEW_GAME, PACKET_NEW_GAME,
PACKET_LOAD_GAME, PACKET_LOAD_GAME,
PACKET_VERSION,
// any packet with an ID higher than PACKET_BROADCAST is rebroadcast by server // 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 // 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_WEAPON_CHOICE,
PACKET_PLAYER_OPTIONS, PACKET_PLAYER_OPTIONS,
PACKET_PLAYER_NAME, PACKET_PLAYER_NAME,
PACKET_VERSION,
PACKET_MESSAGE, PACKET_MESSAGE,
PACKET_USER_MAP, PACKET_USER_MAP,
@ -1123,7 +1123,7 @@ enum DukePacket_t
PACKET_MAP_VOTE_CANCEL, PACKET_MAP_VOTE_CANCEL,
PACKET_PLAYER_READY, PACKET_PLAYER_READY,
PACKET_QUIT = 255 // should match mmulti I think PACKET_QUIT = 255
}; };
#pragma pack(pop) #pragma pack(pop)

View file

@ -53,6 +53,7 @@ ENetHost * net_server = NULL;
ENetHost * net_client = NULL; ENetHost * net_client = NULL;
ENetPeer * net_peer = NULL; ENetPeer * net_peer = NULL;
int32_t net_port = 23513; int32_t net_port = 23513;
int32_t g_netDisconnect = 0;
#ifdef _WIN32 #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@ -696,8 +697,7 @@ void Net_SendQuit(void)
{ {
g_gameQuit = 1; g_gameQuit = 1;
quittimer = totalclock+120; quittimer = totalclock+120;
Net_Disconnect(); g_netDisconnect = 1;
G_GameExit(" ");
} }
else if (numplayers < 2) else if (numplayers < 2)
G_GameExit(" "); G_GameExit(" ");
@ -732,8 +732,8 @@ static void Net_SendVersion(void)
if (numplayers < 2) return; if (numplayers < 2) return;
buf[0] = PACKET_VERSION; buf[0] = PACKET_VERSION;
buf[1] = (uint8_t)atoi(s_buildDate); buf[1] = BYTEVERSION;
buf[2] = BYTEVERSION; buf[2] = (uint8_t)atoi(s_buildDate);
buf[3] = myconnectindex; buf[3] = myconnectindex;
if (net_client) if (net_client)
@ -1224,16 +1224,20 @@ process:
break; break;
case PACKET_VERSION: 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)); if (packbuf[1] != BYTEVERSION || packbuf[2] != (uint8_t)atoi(s_buildDate))
G_GameExit("You cannot play with different versions of EDuke32!"); {
} Bsprintf(tempbuf, "Server protocol is version %d.%d, expecting %d.%d\n",
if (packbuf[2] != BYTEVERSION) packbuf[1], packbuf[2], BYTEVERSION, (uint8_t)atoi(s_buildDate));
{ initprintf(tempbuf);
initprintf("Player %d has version %d, expecting %d\n",other,packbuf[2],BYTEVERSION); initprintf("Version mismatch! You cannot play Duke with different versions!\n");
G_GameExit("You cannot play Duke with different versions!"); g_netDisconnect = 1;
return;
}
} }
else if (net_server)
Net_SendVersion();
break; break;
case PACKET_NUM_PLAYERS: case PACKET_NUM_PLAYERS:
@ -1462,6 +1466,15 @@ void Net_GetPackets(void)
G_HandleSpecialKeys(); G_HandleSpecialKeys();
if (g_netDisconnect)
{
Net_Disconnect();
g_netDisconnect = 0;
if (g_gameQuit)
G_GameExit(" ");
}
if (net_server) if (net_server)
{ {
ENetEvent event; ENetEvent event;
@ -1643,12 +1656,14 @@ void Net_GetPackets(void)
else else
{ {
initprintf("Invalid map state from server!\n"); initprintf("Invalid map state from server!\n");
Net_Disconnect(); g_netDisconnect = 1;
return;
} }
} }
else else
{ {
initprintf("Error allocating memory!\n"); initprintf("Error allocating memory!\n");
g_netDisconnect = 1;
return; return;
} }
} }

View file

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#include "duke3d.h" #include "duke3d.h"
const char *s_buildDate = "20091212"; const char *s_buildDate = "20091214";
char *MusicPtr = NULL; char *MusicPtr = NULL;
int32_t g_musicSize; int32_t g_musicSize;

View file

@ -1149,8 +1149,9 @@ static int32_t osdcmd_inittimer(const osdfuncparm_t *parm)
static int32_t osdcmd_disconnect(const osdfuncparm_t *parm) static int32_t osdcmd_disconnect(const osdfuncparm_t *parm)
{ {
extern int32_t g_netDisconnect;
UNREFERENCED_PARAMETER(parm); UNREFERENCED_PARAMETER(parm);
Net_Disconnect(); g_netDisconnect = 1;
return OSDCMD_OK; return OSDCMD_OK;
} }

View file

@ -3826,17 +3826,6 @@ void P_FragPlayer(int32_t snum)
randomseed = ticrandomseed; 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) if (s->pal != 1)
{ {
p->pals[0] = 63; 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; p->dead_flag = (512-((krand()&1)<<10)+(krand()&255)-512)&2047;
if (p->dead_flag == 0) if (p->dead_flag == 0)
p->dead_flag++; 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; p->jetpack_on = 0;