diff options
Diffstat (limited to 'src/fpsgame/server.cpp')
| -rw-r--r-- | src/fpsgame/server.cpp | 142 |
1 files changed, 65 insertions, 77 deletions
diff --git a/src/fpsgame/server.cpp b/src/fpsgame/server.cpp index fb02c5e..158772f 100644 --- a/src/fpsgame/server.cpp +++ b/src/fpsgame/server.cpp @@ -271,15 +271,15 @@ namespace server void setexceeded() { if(state.state==CS_ALIVE && !exceeded && !checkpushed(gamemillis, calcpushrange())) exceeded = gamemillis; - scheduleexceeded(); + scheduleexceeded(); } - + void setpushed() { pushed = max(pushed, gamemillis); if(exceeded && checkpushed(exceeded, calcpushrange())) exceeded = 0; } - + bool checkexceeded() { return state.state==CS_ALIVE && exceeded && gamemillis > exceeded + calcpushrange(); @@ -421,13 +421,13 @@ namespace server if(getclientip(c.clientnum) == ip) disconnect_client(c.clientnum, DISC_KICK); } } - + struct maprotation { static int exclude; int modes; string map; - + int calcmodemask() const { return modes&(1<<NUMGAMEMODES) ? modes & ~exclude : modes; } bool hasmode(int mode, int offset = STARTGAMEMODE) const { return (calcmodemask() & (1 << (mode-offset))) != 0; } @@ -510,7 +510,7 @@ namespace server for(; *h && *n; h++) { if(*h == *n) n++; - else if(*h != ' ') break; + else if(*h != ' ') break; } if(!*n) return true; if(*n == '.') return !*h; @@ -555,7 +555,7 @@ namespace server } return modemask; } - + bool addmaprotation(int modemask, const char *map) { if(!map[0]) loopk(NUMGAMEMODES) if(modemask&(1<<k) && !m_check(k+STARTGAMEMODE, M_EDIT)) modemask &= ~(1<<k); @@ -566,7 +566,7 @@ namespace server copystring(rot.map, map); return true; } - + void addmaprotations(tagval *args, int numargs) { vector<char *> modes, maps; @@ -587,7 +587,7 @@ namespace server rot.map[0] = '\0'; } } - + COMMAND(maprotationreset, ""); COMMANDN(maprotation, addmaprotations, "ss2V"); @@ -653,7 +653,7 @@ namespace server teamkillkick &kick = teamkillkicks.add(); kick.modes = genmodemask(modes); kick.limit = *limit; - kick.ban = *ban > 0 ? *ban*60000 : (*ban < 0 ? 0 : 30*60000); + kick.ban = *ban > 0 ? *ban*60000 : (*ban < 0 ? 0 : 30*60000); modes.deletearrays(); } @@ -673,8 +673,8 @@ namespace server if(!m_timed || actor->state.aitype != AI_NONE || actor->local || actor->privilege || (victim && victim->state.aitype != AI_NONE)) return; shouldcheckteamkills = true; uint ip = getclientip(actor->clientnum); - loopv(teamkills) if(teamkills[i].ip == ip) - { + loopv(teamkills) if(teamkills[i].ip == ip) + { teamkills[i].teamkills += n; return; } @@ -785,7 +785,7 @@ namespace server int numclients(int exclude = -1, bool nospec = true, bool noai = true, bool priv = false) { int n = 0; - loopv(clients) + loopv(clients) { clientinfo *ci = clients[i]; if(ci->clientnum!=exclude && (!nospec || ci->state.state!=CS_SPECTATOR || (priv && (ci->privilege || ci->local))) && (!noai || ci->state.aitype == AI_NONE)) n++; @@ -842,20 +842,12 @@ namespace server }; #define SERVMODE 1 - #include "capture.h" - #include "ctf.h" - #include "collect.h" - - captureservmode capturemode; - ctfservmode ctfmode; - collectservmode collectmode; servmode *smode = NULL; bool canspawnitem(int type) { return !m_noitems && (type>=I_SHELLS && type<=I_QUAD && (!m_noammo || type<I_SHELLS || type>I_CARTRIDGES)); } int spawntime(int type) { - if(m_classicsp) return INT_MAX; int np = numclients(-1, true, false); np = np<3 ? 4 : (np>4 ? 2 : 3); // spawn times are dependent on number of players int sec = 0; @@ -882,7 +874,6 @@ namespace server { case I_GREENARMOUR: case I_YELLOWARMOUR: - return !m_classicsp; case I_BOOST: case I_QUAD: return true; @@ -890,7 +881,7 @@ namespace server return false; } } - + bool pickup(int i, int sender) // server side item pickup, acknowledge first client that gets it { if((m_timed && gamemillis>=gamelimit) || !sents.inrange(i) || !sents[i].spawned) return false; @@ -1045,7 +1036,7 @@ namespace server loopi(n) delete[] demos[i].data; demos.remove(0, n); } - + void adddemo() { if(!demotmp) return; @@ -1062,7 +1053,7 @@ namespace server demotmp->read(d.data, len); DELETEP(demotmp); } - + void enddemorecord() { if(!demorecord) return; @@ -1374,7 +1365,7 @@ namespace server { char *name; char *desc; - + userkey() : name(NULL), desc(NULL) {} userkey(char *name, char *desc) : name(name), desc(desc) {} }; @@ -1449,7 +1440,7 @@ namespace server if(wantpriv <= ci->privilege) return true; else if(wantpriv <= PRIV_MASTER && !force) { - if(ci->state.state==CS_SPECTATOR) + if(ci->state.state==CS_SPECTATOR) { sendf(ci->clientnum, 1, "ris", N_SERVMSG, "Spectators may not claim master."); return false; @@ -1484,11 +1475,11 @@ namespace server allowedips.shrink(0); } string msg; - if(val && authname) + if(val && authname) { if(authdesc && authdesc[0]) formatstring(msg, "%s claimed %s as '\fs\f5%s\fr' [\fs\f0%s\fr]", colorname(ci), name, authname, authdesc); else formatstring(msg, "%s claimed %s as '\fs\f5%s\fr'", colorname(ci), name, authname); - } + } else formatstring(msg, "%s %s %s", colorname(ci), val ? "claimed" : "relinquished", name); packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE); putint(p, N_SERVMSG); @@ -1592,7 +1583,12 @@ namespace server } uchar operator[](int msg) const { return msg >= 0 && msg < NUMMSG ? msgmask[msg] : 0; } - } msgfilter(-1, N_CONNECT, N_SERVINFO, N_INITCLIENT, N_WELCOME, N_MAPCHANGE, N_SERVMSG, N_DAMAGE, N_HITPUSH, N_SHOTFX, N_EXPLODEFX, N_DIED, N_SPAWNSTATE, N_FORCEDEATH, N_TEAMINFO, N_ITEMACC, N_ITEMSPAWN, N_TIMEUP, N_CDIS, N_CURRENTMASTER, N_PONG, N_RESUME, N_BASESCORE, N_BASEINFO, N_BASEREGEN, N_ANNOUNCE, N_SENDDEMOLIST, N_SENDDEMO, N_DEMOPLAYBACK, N_SENDMAP, N_DROPFLAG, N_SCOREFLAG, N_RETURNFLAG, N_RESETFLAG, N_INVISFLAG, N_CLIENT, N_AUTHCHAL, N_INITAI, N_EXPIRETOKENS, N_DROPTOKENS, N_STEALTOKENS, N_DEMOPACKET, -2, N_REMIP, N_NEWMAP, N_GETMAP, N_SENDMAP, N_CLIPBOARD, -3, N_EDITENT, N_EDITF, N_EDITT, N_EDITM, N_FLIP, N_COPY, N_PASTE, N_ROTATE, N_REPLACE, N_DELCUBE, N_EDITVAR, N_EDITVSLOT, N_UNDO, N_REDO, -4, N_POS, NUMMSG), + } msgfilter(-1, N_CONNECT, N_SERVINFO, N_INITCLIENT, N_WELCOME, N_MAPCHANGE, N_SERVMSG, N_DAMAGE, N_HITPUSH, N_SHOTFX, N_EXPLODEFX, N_DIED, + N_SPAWNSTATE, N_FORCEDEATH, N_TEAMINFO, N_ITEMACC, N_ITEMSPAWN, N_TIMEUP, N_CDIS, N_CURRENTMASTER, N_PONG, N_RESUME, + N_ANNOUNCE, N_SENDDEMOLIST, N_SENDDEMO, N_DEMOPLAYBACK, N_SENDMAP, + N_CLIENT, N_AUTHCHAL, N_INITAI, N_EXPIRETOKENS, N_DROPTOKENS, N_STEALTOKENS, N_DEMOPACKET, -2, N_REMIP, + N_NEWMAP, N_GETMAP, N_SENDMAP, N_CLIPBOARD, -3, N_EDITENT, N_EDITF, N_EDITT, N_EDITM, N_FLIP, N_COPY, N_PASTE, N_ROTATE, N_REPLACE, + N_DELCUBE, N_EDITVAR, N_EDITVSLOT, N_UNDO, N_REDO, -4, N_POS, NUMMSG), connectfilter(-1, N_CONNECT, -2, N_AUTHANS, -3, N_PING, NUMMSG); int checktype(int type, clientinfo *ci) @@ -1928,7 +1924,7 @@ namespace server if(t.frags) { sendstring(t.team, p); putint(p, t.frags); } ); sendstring("", p); - } + } if(ci) { putint(p, N_SETTEAM); @@ -2030,7 +2026,7 @@ namespace server } notgotitems = false; } - + void changemap(const char *s, int mode) { stopdemo(); @@ -2059,10 +2055,7 @@ namespace server sendf(-1, 1, "risii", N_MAPCHANGE, smapname, gamemode, 1); - if(m_capture) smode = &capturemode; - else if(m_ctf) smode = &ctfmode; - else if(m_collect) smode = &collectmode; - else smode = NULL; + smode = NULL; clearteaminfo(); if(m_teammode) autoteam(); @@ -2098,7 +2091,7 @@ namespace server changemap("", 1); return; } - if(next) + if(next) { curmaprotation = findmaprotation(gamemode, smapname); if(curmaprotation >= 0) nextmaprotation(); @@ -2107,7 +2100,7 @@ namespace server maprotation &rot = maprotations[curmaprotation]; changemap(rot.map, rot.findmode(gamemode)); } - + struct votecount { char *map; @@ -2154,7 +2147,7 @@ namespace server void forcemap(const char *map, int mode) { stopdemo(); - if(!map[0] && !m_check(mode, M_EDIT)) + if(!map[0] && !m_check(mode, M_EDIT)) { int idx = findmaprotation(mode, smapname); if(idx < 0 && smapname[0]) idx = findmaprotation(mode, ""); @@ -2170,14 +2163,14 @@ namespace server clientinfo *ci = getinfo(sender); if(!ci || (ci->state.state==CS_SPECTATOR && !ci->privilege && !ci->local) || (!ci->local && !m_mp(reqmode))) return; if(!m_valid(reqmode)) return; - if(!map[0] && !m_check(reqmode, M_EDIT)) + if(!map[0] && !m_check(reqmode, M_EDIT)) { int idx = findmaprotation(reqmode, smapname); if(idx < 0 && smapname[0]) idx = findmaprotation(reqmode, ""); if(idx < 0) return; map = maprotations[idx].map; } - if(lockmaprotation && !ci->local && ci->privilege < (lockmaprotation > 1 ? PRIV_ADMIN : PRIV_MASTER) && findmaprotation(reqmode, map) < 0) + if(lockmaprotation && !ci->local && ci->privilege < (lockmaprotation > 1 ? PRIV_ADMIN : PRIV_MASTER) && findmaprotation(reqmode, map) < 0) { sendf(sender, 1, "ris", N_SERVMSG, "This server has locked the map rotation."); return; @@ -2283,13 +2276,13 @@ namespace server actor->state.effectiveness += fragvalue*friends/float(max(enemies, 1)); } teaminfo *t = m_teammode ? teaminfos.access(actor->team) : NULL; - if(t) t->frags += fragvalue; + if(t) t->frags += fragvalue; sendf(-1, 1, "ri5", N_DIED, target->clientnum, actor->clientnum, actor->state.frags, t ? t->frags : 0); target->position.setsize(0); if(smode) smode->died(target, actor); ts.state = CS_DEAD; ts.lastdeath = gamemillis; - if(actor!=target && isteam(actor->team, target->team)) + if(actor!=target && isteam(actor->team, target->team)) { actor->state.teamkills++; addteamkill(actor, target, 1); @@ -2507,7 +2500,7 @@ namespace server if(nextexceeded && gamemillis > nextexceeded && (!m_timed || gamemillis < gamelimit)) { nextexceeded = 0; - loopvrev(clients) + loopvrev(clients) { clientinfo &c = *clients[i]; if(c.state.aitype != AI_NONE) continue; @@ -2670,7 +2663,7 @@ namespace server void clientdisconnect(int n) { clientinfo *ci = getinfo(n); - loopv(clients) if(clients[i]->authkickvictim == ci->clientnum) clients[i]->cleanauth(); + loopv(clients) if(clients[i]->authkickvictim == ci->clientnum) clients[i]->cleanauth(); if(ci->connected) { if(ci->privilege) setmaster(ci, false); @@ -2710,7 +2703,7 @@ namespace server verifybans(); } - } ipbans, gbans; + } ipbans, gbans; bool checkbans(uint ip) { @@ -2730,7 +2723,7 @@ namespace server ICOMMAND(clearipbans, "", (), ipbans.clear()); ICOMMAND(ipban, "s", (const char *ipname), ipbans.add(ipname)); - + int allowconnect(clientinfo *ci, const char *pwd = "") { if(ci->local) return DISC_NONE; @@ -2782,7 +2775,7 @@ namespace server if(ci->authkickvictim >= 0) { if(setmaster(ci, true, "", ci->authname, NULL, PRIV_AUTH, false, true)) - trykick(ci, ci->authkickvictim, ci->authkickreason, ci->authname, NULL, PRIV_AUTH); + trykick(ci, ci->authkickvictim, ci->authkickreason, ci->authname, NULL, PRIV_AUTH); ci->cleanauthkick(); } else setmaster(ci, true, "", ci->authname, NULL, PRIV_AUTH); @@ -2807,7 +2800,7 @@ namespace server if(ci->authdesc[0]) { userinfo *u = users.access(userkey(ci->authname, ci->authdesc)); - if(u) + if(u) { uint seed[3] = { ::hthash(serverauth) + detrnd(size_t(ci) + size_t(user) + size_t(desc), 0x10000), uint(totalmillis), randomMT() }; vector<char> buf; @@ -2828,7 +2821,7 @@ namespace server bool answerchallenge(clientinfo *ci, uint id, char *val, const char *desc) { - if(ci->authreq != id || strcmp(ci->authdesc, desc)) + if(ci->authreq != id || strcmp(ci->authdesc, desc)) { ci->cleanauth(); return !ci->connectauth; @@ -2842,7 +2835,7 @@ namespace server if(ci->authchallenge && checkchallenge(val, ci->authchallenge)) { userinfo *u = users.access(userkey(ci->authname, ci->authdesc)); - if(u) + if(u) { if(ci->connectauth) connected(ci); if(ci->authkickvictim >= 0) @@ -2853,8 +2846,8 @@ namespace server else setmaster(ci, true, "", ci->authname, ci->authdesc, u->privilege); } } - ci->cleanauth(); - } + ci->cleanauth(); + } else if(!requestmasterf("confauth %u %s\n", id, val)) { ci->cleanauth(); @@ -2872,7 +2865,7 @@ namespace server loopvrev(clients) { clientinfo *ci = clients[i]; - if(ci->authreq) authfailed(ci); + if(ci->authreq) authfailed(ci); } } @@ -2966,9 +2959,9 @@ namespace server { getstring(text, p); filtertext(text, text, false, false, MAXNAMELEN); - if(!text[0]) copystring(text, "unnamed"); + if(!text[0]) copystring(text, "Anonymous"); copystring(ci->name, text, MAXNAMELEN+1); - ci->playermodel = getint(p); + ci->playermodel = 0; string password, authdesc, authname; getstring(password, p, sizeof(password)); @@ -2994,7 +2987,7 @@ namespace server getstring(desc, p, sizeof(desc)); uint id = (uint)getint(p); getstring(ans, p, sizeof(ans)); - if(!answerchallenge(ci, id, ans, desc)) + if(!answerchallenge(ci, id, ans, desc)) { disconnect_client(sender, ci->connectauth); return; @@ -3036,8 +3029,8 @@ namespace server { case N_POS: { - int pcn = getuint(p); - p.get(); + int pcn = getuint(p); + p.get(); uint flags = getuint(p); clientinfo *cp = getinfo(pcn); if(cp && pcn != sender && cp->ownernum != sender) cp = NULL; @@ -3080,7 +3073,7 @@ namespace server if(cp && (!ci->local || demorecord || hasnonlocalclients()) && (cp->state.state==CS_ALIVE || cp->state.state==CS_EDITING)) { flushclientposition(*cp); - sendf(-1, 0, "ri4x", N_TELEPORT, pcn, teleport, teledest, cp->ownernum); + sendf(-1, 0, "ri4x", N_TELEPORT, pcn, teleport, teledest, cp->ownernum); } break; } @@ -3098,7 +3091,7 @@ namespace server } break; } - + case N_FROMAI: { int qcn = getint(p); @@ -3230,7 +3223,7 @@ namespace server hit.rays = getint(p); loopk(3) hit.dir[k] = getint(p)/DNF; } - if(cq) + if(cq) { cq->addevent(shot); cq->setpushed(); @@ -3303,14 +3296,14 @@ namespace server QUEUE_MSG; getstring(text, p); filtertext(ci->name, text, false, false, MAXNAMELEN); - if(!ci->name[0]) copystring(ci->name, "unnamed"); + if(!ci->name[0]) copystring(ci->name, "Anonymous"); QUEUE_STR(ci->name); break; } case N_SWITCHMODEL: { - ci->playermodel = getint(p); + ci->playermodel = 0; QUEUE_MSG; break; } @@ -3495,7 +3488,7 @@ namespace server { int val = getint(p); if(ci->privilege < (restrictdemos ? PRIV_ADMIN : PRIV_MASTER) && !ci->local) break; - if(!maxdemos || !maxdemosize) + if(!maxdemos || !maxdemosize) { sendf(ci->clientnum, 1, "ris", N_SERVMSG, "the server has disabled demo recording"); break; @@ -3630,7 +3623,7 @@ namespace server { ci->authkickvictim = victim; ci->authkickreason = newstring(text); - } + } break; } @@ -3668,17 +3661,17 @@ namespace server case N_PASTE: if(ci->state.state!=CS_SPECTATOR) sendclipboard(ci); goto genericmsg; - + case N_CLIPBOARD: { - int unpacklen = getint(p), packlen = getint(p); + int unpacklen = getint(p), packlen = getint(p); ci->cleanclipboard(false); if(ci->state.state==CS_SPECTATOR) { if(packlen > 0) p.subbuf(packlen); break; } - if(packlen <= 0 || packlen > (1<<16) || unpacklen <= 0) + if(packlen <= 0 || packlen > (1<<16) || unpacklen <= 0) { if(packlen > 0) p.subbuf(packlen); packlen = unpacklen = 0; @@ -3687,12 +3680,12 @@ namespace server putint(q, N_CLIPBOARD); putint(q, ci->clientnum); putint(q, unpacklen); - putint(q, packlen); + putint(q, packlen); if(packlen > 0) p.get(q.subbuf(packlen).buf, packlen); ci->clipboard = q.finalize(); ci->clipboard->referenceCount++; break; - } + } case N_EDITT: case N_REPLACE: @@ -3732,12 +3725,7 @@ namespace server case N_SERVCMD: getstring(text, p); break; - - #define PARSEMESSAGES 1 - #include "capture.h" - #include "ctf.h" - #include "collect.h" - #undef PARSEMESSAGES + case -1: disconnect_client(sender, DISC_MSGERR); |
