From faa86ec001c5eb9e4112d68bd96ebcb0e5491dce Mon Sep 17 00:00:00 2001 From: ac_stef Date: Mon, 27 Apr 2009 00:50:42 +0000 Subject: [PATCH] only allow spawning of clients with the right map & revision git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4359 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 12 +++++++++--- source/src/clientgame.cpp | 4 ++-- source/src/clients2c.cpp | 2 +- source/src/server.cpp | 40 +++++++++++++++++++++++++-------------- source/src/tools.cpp | 1 + source/src/world.h | 1 + 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 91dc20a5..1038aeb3 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -277,7 +277,7 @@ void addmsg(int type, const char *fmt, ...) } static int lastupdate = -1000, lastping = 0; -bool senditemstoserver = false; // after a map change, since server doesn't have map data +bool senditemstoserver = false, sendspawnlist = false; // after a map change, since server doesn't have map data void sendpackettoserv(int chan, ENetPacket *packet) { @@ -321,7 +321,7 @@ void c2sinfo(playerent *d) // send update to the server sendpackettoserv(0, packet); } - if(senditemstoserver || !c2sinit || messages.length() || totalmillis-lastping>250) + if(senditemstoserver || sendspawnlist || !c2sinit || messages.length() || totalmillis-lastping>250) { ENetPacket *packet = enet_packet_create (NULL, MAXTRANS, 0); ucharbuf p(packet->data, packet->dataLength); @@ -344,14 +344,20 @@ void c2sinfo(playerent *d) // send update to the server if(!m_noitems) putitems(p); putint(p, -1); } + senditemstoserver = false; + } + if(sendspawnlist) + { + packet->flags = ENET_PACKET_FLAG_RELIABLE; putint(p, SV_SPAWNLIST); putint(p, maploaded); if(maploaded > 0) { + putint(p, hdr.maprevision); loopi(3) putint(p, numspawn[i]); loopi(2) putint(p, numflagspawn[i]); } - senditemstoserver = false; + sendspawnlist = false; } int i = 0; while(i < messages.length()) // send messages collected during the previous frames diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 383affe2..8cc4954a 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -36,7 +36,7 @@ char *getclientmap() { return clientmap; } void mapname() { result(getclientmap()); } COMMAND(mapname, ARG_NONE); -extern bool c2sinit, senditemstoserver; +extern bool c2sinit, senditemstoserver, sendspawnlist; void setskin(playerent *pl, uint skin) { @@ -721,7 +721,7 @@ int suicided = -1; void startmap(const char *name, bool reset) // called just after a map load { s_strcpy(clientmap, name); - senditemstoserver = true; + senditemstoserver = sendspawnlist = true; // Added by Rick if(m_botmode) BotManager.BeginMap(name); else kickallbots(); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 9b377d0c..50373b6d 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -294,7 +294,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_SPAWNLIST: { - if(getint(p) > 0) loopi(5) getint(p); + if(getint(p) > 0) loopi(6) getint(p); break; } diff --git a/source/src/server.cpp b/source/src/server.cpp index 409aac2b..bad19162 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -54,6 +54,7 @@ int mastermode = MM_OPEN; #define gamemode smode string smapname, nextmapname; int smode = 0, nextgamemode; +int smapsize = 0; struct shotevent { @@ -2206,8 +2207,9 @@ void resetmap(const char *newname, int newmode, int newtime, bool notify) if(e.fitsmode(smode)) sents[i].spawned = true; } notgotitems = false; - copyrevision = ms->hdr.maprevision; + copyrevision = copymapsize == ms->cgzsize ? ms->hdr.maprevision : 0; } + smapsize = ms ? ms->cgzsize : 0; scores.setsize(0); ctfreset(); if(notify) @@ -2218,8 +2220,8 @@ void resetmap(const char *newname, int newmode, int newtime, bool notify) } if(newname[0]) { - logger->writeline(log::info, "\nGame start: %s on %s, %d players, %d minutes remaining, mastermode %d, (itemlist %spreloaded, 'getmap' %sprepared)", - modestr(smode), smapname, numclients(), minremain, mastermode, ms ? "" : "not ", mapavailable(smapname) ? "" : "not "); + logger->writeline(log::info, "\nGame start: %s on %s, %d players, %d minutes remaining, mastermode %d, (map rev %d/%d, itemlist %spreloaded, 'getmap' %sprepared)", + modestr(smode), smapname, numclients(), minremain, mastermode, copyrevision, smapsize, ms ? "" : "not ", mapavailable(smapname) ? "" : "not "); } arenaround = 0; if(m_arena) @@ -2595,7 +2597,6 @@ void getservermap(void) if(!gzbuf) gzbuf = new uchar[GZBUFSIZE]; if(!gzbuf) return; - if(!strcmp(name, behindpath(copyname))) return; s_sprintf(cgzname)(SERVERMAP_PATH "%s.cgz", name); path(cgzname); if(fileexists(cgzname, "r")) @@ -2801,6 +2802,13 @@ void sendwelcome(client *cl, int chan, bool forcedeath) cl->haswelcome = true; } +void forcedeath(client *cl) +{ + cl->state.state = CS_DEAD; + cl->state.respawn(); + sendf(-1, 1, "rii", SV_FORCEDEATH, cl->clientnum); +} + int checktype(int type, client *cl) { if(cl && cl->type==ST_LOCAL) return type; @@ -3064,11 +3072,19 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 case SV_SPAWNLIST: { - if(getint(p) > 0) + int gzs = getint(p), rev = 0; + if(gzs > 0) { - loopi(3) clnumspawn[i] = getint(p); - loopi(2) clnumflagspawn[i] = getint(p); + rev = getint(p); + if(copyrevision == 0) + { + loopi(3) clnumspawn[i] = getint(p); + loopi(2) clnumflagspawn[i] = getint(p); + } + else loopi(5) getint(p); } + if(smapsize == 0 || (smapsize == gzs && copyrevision == rev)) cl->isonrightmap = true; + else forcedeath(cl); QUEUE_MSG; break; } @@ -3108,16 +3124,11 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 } case SV_CHANGETEAM: - if(cl->state.state==CS_ALIVE) - { - cl->state.state = CS_DEAD; - cl->state.respawn(); - sendf(-1, 1, "rii", SV_FORCEDEATH, cl->clientnum); - } + if(cl->state.state==CS_ALIVE) forcedeath(cl); break; case SV_TRYSPAWN: - if(cl->state.state!=CS_DEAD || cl->state.lastspawn>=0 || !canspawn(cl)) break; + if(cl->state.state!=CS_DEAD || cl->state.lastspawn>=0 || !canspawn(cl) || !cl->isonrightmap) break; if(cl->state.lastdeath) cl->state.respawn(); sendspawn(cl); break; @@ -3254,6 +3265,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 getuint(p); loopi(5) getint(p); getuint(p); + if(!cl->isonrightmap) break; if(cl->type==ST_TCPIP && (cl->state.state==CS_ALIVE || cl->state.state==CS_EDITING)) { cl->position.setsizenodelete(0); diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 2900d889..f46f9834 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -410,6 +410,7 @@ mapstats *loadmapstats(const char *filename, bool getlayout) s.hasflags = s.flags[0] > 0 && s.flags[1] > 0; s.enttypes = enttypes; s.entposs = entposs; + s.cgzsize = getfilesize(filename); return &s; } diff --git a/source/src/world.h b/source/src/world.h index 64a67be3..3e354164 100644 --- a/source/src/world.h +++ b/source/src/world.h @@ -53,6 +53,7 @@ struct mapstats { struct header hdr; int entcnt[MAXENTTYPES]; + int cgzsize; uchar *enttypes; short *entposs; int spawns[3];