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
This commit is contained in:
ac_stef
2009-04-27 00:50:42 +00:00
parent 2f9ece1fb1
commit faa86ec001
6 changed files with 40 additions and 20 deletions
+9 -3
View File
@@ -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
+2 -2
View File
@@ -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();
+1 -1
View File
@@ -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;
}
+26 -14
View File
@@ -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);
+1
View File
@@ -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;
}
+1
View File
@@ -53,6 +53,7 @@ struct mapstats
{
struct header hdr;
int entcnt[MAXENTTYPES];
int cgzsize;
uchar *enttypes;
short *entposs;
int spawns[3];