]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/clientcommands.qc
Rewrite of vote code.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / clientcommands.qc
index 92e4b8ac18ac0a0c4c264fd311fc5297a7ac987f..c1d3162a5739da2da60f6604d6f4a72368414aaa 100644 (file)
@@ -1,11 +1,22 @@
 entity nagger;
 float readycount;
+
 float Nagger_SendEntity(entity to, float sendflags)
 {
        float nags, i, f, b;
        entity e;
        WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER);
 
+       // bits:
+       //   1 = ready
+       //   2 = player needs to ready up
+       //   4 = vote
+       //   8 = player needs to vote
+       //  16 = warmup
+       // sendflags:
+       //  64 = vote counts
+       // 128 = vote string
+
        nags = 0;
        if(readycount)
        {
@@ -22,16 +33,28 @@ float Nagger_SendEntity(entity to, float sendflags)
        if(inWarmupStage)
                nags |= 16;
 
+       if(sendflags & 64)
+               nags |= 64;
+
        if(sendflags & 128)
                nags |= 128;
 
+       if(!(nags & 4)) // no vote called? send no string
+               nags &~= (64 | 128);
+
        WriteByte(MSG_ENTITY, nags);
 
-       if(nags & 128)
+       if(nags & 64)
        {
-               WriteString(MSG_ENTITY, votecalledvote_display);
+               WriteByte(MSG_ENTITY, vote_yescount);
+               WriteByte(MSG_ENTITY, vote_nocount);
+               WriteByte(MSG_ENTITY, vote_needed_absolute);
+               WriteChar(MSG_ENTITY, to.vote_vote);
        }
 
+       if(nags & 128)
+               WriteString(MSG_ENTITY, votecalledvote_display);
+
        if(nags & 1)
        {
                for(i = 1; i <= maxclients; i += 8)
@@ -57,7 +80,7 @@ void Nagger_VoteChanged()
 void Nagger_VoteCountChanged()
 {
        if(nagger)
-               nagger.SendFlags |= 1;
+               nagger.SendFlags |= 64;
 }
 void Nagger_ReadyCounted()
 {
@@ -120,6 +143,7 @@ float cmd_floodcheck()
        return FALSE;
 }
 
+.float checkfail;
 void SV_ParseClientCommand(string s) {
        string cmd;
        float tokens;
@@ -128,7 +152,7 @@ void SV_ParseClientCommand(string s) {
 
        tokens = tokenize_console(s);
 
-       cmd = argv(0);
+       cmd = strtolower(argv(0));
        if(cmd != "reportcvar")
        if(cmd != "sentcvar")
        if(cmd != "pause")
@@ -144,6 +168,9 @@ void SV_ParseClientCommand(string s) {
                return;
        } else if(GameCommand_MapVote(argv(0))) {
                return;
+       } else if(cmd == "checkfail") {
+               print(sprintf("CHECKFAIL: %s (%s) epically failed check %s\n", self.netname, self.netaddress, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))));
+               self.checkfail = 1;
        } else if(cmd == "autoswitch") {
                // be backwards compatible with older clients (enabled)
                self.autoswitch = ("0" != argv(1));
@@ -164,14 +191,13 @@ void SV_ParseClientCommand(string s) {
                } else {
                        self.version = stof(argv(1));
                }
-               if(self.version != autocvar_gameversion)
+               if(self.version < autocvar_gameversion_min || self.version > autocvar_gameversion_max)
                {
-                       self.classname = "observer";
                        self.version_mismatch = 1;
-                       PutClientInServer();
+                       ClientKill_TeamChange(-2); // observe
                } else if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force) {
                        //JoinBestTeam(self, FALSE, TRUE);
-               } else if(teams_matter && !autocvar_sv_spectate && !(self.team_forced > 0)) {
+               } else if(teamplay && !autocvar_sv_spectate && !(self.team_forced > 0)) {
                        self.classname = "observer";
                        stuffcmd(self,"menu_showteamselect\n");
                }
@@ -211,17 +237,7 @@ void SV_ParseClientCommand(string s) {
                        }
                }
                if(self.classname == "player" && autocvar_sv_spectate == 1) {
-                       if(self.flagcarried)
-                               DropFlag(self.flagcarried, world, world);
-                       if(self.ballcarried && g_nexball)
-                               DropBall(self.ballcarried, self.origin, self.velocity);
-                       WaypointSprite_PlayerDead();
-                       self.classname = "observer";
-                       if(g_ca)
-                               self.caplayer = 0;
-                       if(blockSpectators)
-                               sprint(self, strcat("^7You have to become a player within the next ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
-                       PutClientInServer();
+                       ClientKill_TeamChange(-2); // observe
                }
        } else if(cmd == "join") {
                if not(self.flags & FL_CLIENT)
@@ -229,7 +245,7 @@ void SV_ParseClientCommand(string s) {
                if(!g_arena)
                if (self.classname != "player" && !lockteams)
                {
-                       if(isJoinAllowed()) {
+                       if(nJoinAllowed(1)) {
                                self.classname = "player";
                                if(g_ca)
                                        self.caplayer = 1;
@@ -247,7 +263,7 @@ void SV_ParseClientCommand(string s) {
        } else if( cmd == "selectteam" ) {
                if not(self.flags & FL_CLIENT)
                        return;
-               if( !teams_matter ) {
+               if( !teamplay ) {
                        sprint( self, "selectteam can only be used in teamgames\n");
                } else if(autocvar_g_campaign) {
                        //JoinBestTeam(self, 0);
@@ -256,15 +272,15 @@ void SV_ParseClientCommand(string s) {
                } else if(lockteams) {
                        sprint( self, "^7The game has already begun, you must wait until the next map to be able to join a team.\n");
                } else if( argv(1) == "red" ) {
-                       DoTeamChange(COLOR_TEAM1);
+                       ClientKill_TeamChange(COLOR_TEAM1);
                } else if( argv(1) == "blue" ) {
-                       DoTeamChange(COLOR_TEAM2);
+                       ClientKill_TeamChange(COLOR_TEAM2);
                } else if( argv(1) == "yellow" ) {
-                       DoTeamChange(COLOR_TEAM3);
+                       ClientKill_TeamChange(COLOR_TEAM3);
                } else if( argv(1) == "pink" ) {
-                       DoTeamChange(COLOR_TEAM4);
+                       ClientKill_TeamChange(COLOR_TEAM4);
                } else if( argv(1) == "auto" ) {
-                       DoTeamChange(-1);
+                       ClientKill_TeamChange(-1);
                } else {
                        sprint( self, strcat( "selectteam none/red/blue/yellow/pink/auto - \"", argv(1), "\" not recognised\n" ) );
                }
@@ -272,7 +288,7 @@ void SV_ParseClientCommand(string s) {
                if not(self.flags & FL_CLIENT)
                        return;
 
-               if((inWarmupStage && 0 >= g_warmup_limit) // with unlimited warmup players have to be able to restart
+               if((inWarmupStage)
                   || autocvar_sv_ready_restart || g_race_qualifying == 2)
                {
                        if(!readyrestart_happened || autocvar_sv_ready_restart_repeatable)
@@ -369,6 +385,7 @@ void SV_ParseClientCommand(string s) {
                sprint(self, cvar_purechanges);
        } else if(CheatCommand(tokens)) {
        } else {
+#if 0
                //if(ctf_clientcommand())
                //      return;
                // grep for Cmd_AddCommand_WithClientCommand to find them all
@@ -394,6 +411,7 @@ void SV_ParseClientCommand(string s) {
                        print("WARNING: Invalid clientcommand by ", self.netname, ": ", s, "\n");
                        return;
                }
+#endif
 
                if(self.jointime > 0 && time > self.jointime + 10 && time > self.nickspamtime) // allow any changes in the first 10 seconds since joining
                if(cmd == "name" || cmd == "playermodel") // TODO also playerskin and color?
@@ -447,7 +465,7 @@ void ReadyRestartForce()
        readycount = 0;
        Nagger_ReadyCounted(); // NOTE: this causes a resend of that entity, and will also turn off warmup state on the client
 
-       if(autocvar_teamplay_lockonrestart && teams_matter) {
+       if(autocvar_teamplay_lockonrestart && teamplay) {
                lockteams = 1;
                bprint("^1The teams are now locked.\n");
        }