diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index e7863d09..1fa2f51d 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -89,7 +89,7 @@ void changeteam(int team, bool respawn) // force team and respawn c2sinit = false; if(m_ctf) tryflagdrop(NULL); filtertext(player1->team, team_string(team), false, MAXTEAMLEN); - if(respawn) spawnplayer(player1); + if(respawn) addmsg(SV_CHANGETEAM, "r"); } void newteam(char *name) @@ -130,16 +130,17 @@ extern void thrownade(playerent *d, const vec &vel, bounceent *p); void deathstate(playerent *pl) { - pl->lastpain = lastmillis; - pl->attacking = false; pl->state = CS_DEAD; - pl->pitch = 0; - //pl->roll = 60; - pl->strafe = 0; + pl->lastpain = pl->lastaction = lastmillis; + pl->move = pl->pitch = pl->strafe = pl->roll = 0; + pl->attacking = false; + if(pl == player1) { dblend = 0; - if(pl->inhandnade) thrownade(pl, vec(0,0,0), pl->inhandnade); + showscores(true); + setscope(false); + if(editmode) toggleedit(); } } @@ -423,18 +424,8 @@ void dokill(playerent *pl, playerent *act, bool gib) else outf("\f2%s %s %s", aname, death, pname); } - pl->state = CS_DEAD; - pl->lastaction = lastmillis; - pl->pitch = 0; - //pl->roll = 60; - pl->move = pl->strafe = 0; - pl->attacking = false; - playsound(S_DIE1+rnd(2), NULL, NULL, pl == player1 ? NULL : &pl->o); if(pl==player1) { - showscores(true); - setscope(false); - dblend = 0; if(pl->inhandnade) thrownade(pl, vec(0,0,0), pl->inhandnade); if(m_ctf) tryflagdrop(pl!=act && isteam(act->team, pl->team)); } @@ -448,6 +439,9 @@ void dokill(playerent *pl, playerent *act, bool gib) if(pl==act || isteam(pl->team, act->team)) act->frags--; else act->frags += gib ? 2 : 1; } + + deathstate(pl); + playsound(S_DIE1+rnd(2), NULL, NULL, pl == player1 ? NULL : &pl->o); } VAR(minutesremaining, 1, 0, 0); @@ -495,7 +489,7 @@ void initclient() { clientmap[0] = 0; newname("unarmed"); - changeteam(rnd(2)); + changeteam(rnd(2), false); } entity flagdummies[2]; // in case the map does not provide flags diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 4930eb39..3b1fe849 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -165,11 +165,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_MAPCHANGE: getstring(text, p); changemapserv(text, getint(p)); - if(m_arena && joining>2) - { - deathstate(player1); - showscores(true); - } + if(m_arena && joining>2) deathstate(player1); mapchanged = true; break; @@ -504,12 +500,14 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) int cn = getint(p); playerent *d = cn==getclientnum() ? player1 : newclient(cn); if(!d) break; - if(d==player1) + // FIXME + /*if(d==player1) { if(editmode) toggleedit(); showscores(true); } - d->state = CS_DEAD; + d->state = CS_DEAD;*/ + deathstate(d); break; } diff --git a/source/src/command.cpp b/source/src/command.cpp index c0e83f68..92b0b2bc 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -327,7 +327,7 @@ void writecfg() FILE *f = openfile(cfgname, "w"); if(!f) return; fprintf(f, "// automatically written on exit, DO NOT MODIFY\n// delete this file to have defaults.cfg overwrite these settings\n// modify settings in game, or put settings in autoexec.cfg to override anything\n\n"); - fprintf(f, "name %s\nteam %s\nskin %d\n", player1->name, player1->team, player1->nextskin); + fprintf(f, "name %s\nskin %d\n", player1->name, player1->nextskin); extern Texture *crosshair; fprintf(f, "loadcrosshair %s\n", crosshair->name+strlen("packages/misc/crosshairs/")); extern int lowfps, highfps; diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index fe3d0545..2f841c0c 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -117,7 +117,7 @@ char msgsizesl[] = // size inclusive message token, 0 for variable SV_ARENAWIN, 2, SV_SETMASTER, 2, SV_SETADMIN, 0, SV_SERVOPINFO, 3, SV_CALLVOTE, 0, SV_CALLVOTESUC, 1, SV_CALLVOTEERR, 2, SV_VOTE, 2, SV_VOTERESULT, 2, - SV_FORCETEAM, 2, SV_AUTOTEAM, 2, + SV_FORCETEAM, 2, SV_AUTOTEAM, 2, SV_CHANGETEAM, 1, SV_WHOIS, 2, SV_WHOISINFO, 3, SV_LISTDEMOS, 1, SV_SENDDEMOLIST, 0, SV_GETDEMO, 2, SV_SENDDEMO, 0, SV_DEMOPLAYBACK, 2, SV_CONNECT, 0, diff --git a/source/src/protocol.h b/source/src/protocol.h index 83276e85..b125e793 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -24,7 +24,7 @@ enum SV_ARENAWIN, SV_SETMASTER, SV_SETADMIN, SV_SERVOPINFO, SV_CALLVOTE, SV_CALLVOTESUC, SV_CALLVOTEERR, SV_VOTE, SV_VOTERESULT, - SV_FORCETEAM, SV_AUTOTEAM, + SV_FORCETEAM, SV_AUTOTEAM, SV_CHANGETEAM, SV_WHOIS, SV_WHOISINFO, SV_LISTDEMOS, SV_SENDDEMOLIST, SV_GETDEMO, SV_SENDDEMO, SV_DEMOPLAYBACK, SV_CONNECT, diff --git a/source/src/server.cpp b/source/src/server.cpp index a1795fe4..4e5469c9 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -220,7 +220,7 @@ struct client // server side version of "dynent" type void reset() { - name[0] = 0; + name[0] = team[0] = 0; position.setsizenodelete(0); messages.setsizenodelete(0); isauthed = false; @@ -228,6 +228,13 @@ struct client // server side version of "dynent" type lastvotecall = 0; mapchange(); } + + void zap() + { + type = ST_EMPTY; + role = CR_DEFAULT; + isauthed = false; + } }; vector clients; @@ -380,15 +387,6 @@ int numclients() { return countclients(ST_EMPTY, true); } int numlocalclients() { return countclients(ST_LOCAL); } int numnonlocalclients() { return countclients(ST_TCPIP); } - -void zapclient(int c) -{ - if(!clients.inrange(c)) return; - clients[c]->type = ST_EMPTY; - clients[c]->isauthed = false; - clients[c]->role = CR_DEFAULT; -} - int freeteam() { int teamsize[2] = {0, 0}; @@ -954,7 +952,7 @@ void disconnect_client(int n, int reason = -1) else printf("disconnected client (%s)\n", c.hostname); c.peer->data = (void *)-1; if(reason>=0) enet_peer_disconnect(c.peer, reason); - zapclient(n); + clients[n]->zap(); sendf(-1, 1, "rii", SV_CDIS, n); checkvotes(); } @@ -1296,7 +1294,7 @@ void shuffleteams() { int team = rnd(2); if(teamsize[team] >= numplayers/2) team = team_opposite(team); - forceteam(i, team, false); + forceteam(i, team, true); teamsize[team]++; } } @@ -1618,7 +1616,7 @@ void welcomepacket(ucharbuf &p, int n) putint(p, -1); } putint(p, SV_AUTOTEAM); - putint(p, autoteam); + putint(p, autoteam ? 1 : 0); if(motd) { putint(p, SV_TEXT); @@ -1776,6 +1774,12 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 break; } + case SV_CHANGETEAM: + cl->state.state = CS_DEAD; + cl->state.respawn(); + sendf(-1, 1, "rii", SV_FORCEDEATH, cl->clientnum); + break; + case SV_TRYSPAWN: if(cl->state.state!=CS_DEAD || cl->state.lastspawn>=0 || !canspawn(cl)) break; if(cl->state.lastdeath) cl->state.respawn(); @@ -2300,7 +2304,7 @@ void extinfo_teamscorebuf(ucharbuf &p) #ifndef STANDALONE void localdisconnect() { - loopv(clients) if(clients[i]->type==ST_LOCAL) zapclient(i); + loopv(clients) if(clients[i]->type==ST_LOCAL) clients[i]->zap(); } void localconnect() diff --git a/source/src/serveractions.h b/source/src/serveractions.h index c73ad21e..08cd5c76 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -108,7 +108,7 @@ struct autoteamaction : enableaction void perform() { sendf(-1, 1, "ri2", SV_AUTOTEAM, (autoteam = enable) == 1 ? 1 : 0); - if(m_teammode) shuffleteams(); + if(m_teammode && enable) shuffleteams(); } autoteamaction(bool enable) : enableaction(enable) {