]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Finish up work on timeout system, now has much cleaner functionality (though it still...
authorSamual <samual@xonotic.org>
Tue, 27 Dec 2011 19:24:47 +0000 (14:24 -0500)
committerSamual <samual@xonotic.org>
Tue, 27 Dec 2011 19:24:47 +0000 (14:24 -0500)
qcsrc/server/cl_client.qc
qcsrc/server/cl_impulse.qc
qcsrc/server/cl_player.qc
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/command/cmd.qc
qcsrc/server/command/common.qc
qcsrc/server/command/vote.qc
qcsrc/server/g_hook.qc
qcsrc/server/g_world.qc
qcsrc/server/sv_main.qc

index 9ddcaabac3fb991128d2c9c49337d0a189c59409..92e2687cb8bdb9411c631d52bf3c920135821578 100644 (file)
@@ -1528,7 +1528,7 @@ void ClientConnect (void)
        }
 
        self.jointime = time;
-       self.allowedTimeouts = autocvar_sv_timeout_number;
+       self.allowed_timeouts = autocvar_sv_timeout_number;
 
        if(clienttype(self) == CLIENTTYPE_REAL)
        {
@@ -2603,7 +2603,7 @@ void PlayerPreThink (void)
                }
 
                //don't allow the player to turn around while game is paused!
-               if(timeoutStatus == 2) {
+               if(timeout_status == TIMEOUT_ACTIVE) {
                        // FIXME turn this into CSQC stuff
                        self.v_angle = self.lastV_angle;
                        self.angles = self.lastV_angle;
index 9e662bb848e204b1a5b59dcd283424247d396951..524e796af2e32859054ee3a82522eae1ddb85147 100644 (file)
@@ -46,7 +46,7 @@ void ImpulseCommands (void)
                return;
        self.impulse = 0;
 
-       if (timeoutStatus == 2) //don't allow any impulses while the game is paused
+       if (timeout_status == TIMEOUT_ACTIVE) //don't allow any impulses while the game is paused
                return;
 
        if(CheatImpulse(imp))
index 5b369c27c5e2eea45e4bccb73c2df778b11c72f4..f67ac1be93cc229ee162d688e5f08a49fe9949ad 100644 (file)
@@ -962,7 +962,7 @@ float Say(entity source, float teamsay, entity privatesay, string msgin, float f
                                flood = 1;
                }
 
-               if (timeoutStatus == 2) //when game is paused, no flood protection
+               if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
                        source.flood_field = flood = 0;
        }
 
index 2062f446fdb9b6f35ac59a0a3758d5f8be6ab57c..e049ef8588e2ca97501451d092149e9b037c7679 100644 (file)
@@ -913,7 +913,7 @@ float weapon_prepareattack_check(float secondary, float attacktime)
                return FALSE;
        }
 
-       if (timeoutStatus == 2) //don't allow the player to shoot while game is paused
+       if (timeout_status == TIMEOUT_ACTIVE) //don't allow the player to shoot while game is paused
                return FALSE;
 
        // do not even think about shooting if switching
index f218a4e6705fa9eafc27f19ef1b8cc4157eb0054..521db1a0ab1c5de878747c01bdc6e1185b56ade5 100644 (file)
@@ -5,7 +5,7 @@
 
 float SV_ParseClientCommand_floodcheck()
 {
-       if (timeoutStatus != 2) // if the game is not paused... but wait, doesn't that mean it could be dos'd by pausing it? eh? (old code)
+       if not(timeout_status) // not while paused
        {
                if(time <= (self.cmd_floodtime + autocvar_sv_clientcommand_antispam_time))
                {
@@ -192,7 +192,7 @@ void ClientCommand_ready(float request) // todo: anti-spam for toggling readynes
                                                }
 
                                                // cannot reset the game while a timeout is active!
-                                               if(!timeoutStatus)
+                                               if not(timeout_status)
                                                        ReadyCount();
                                        } else {
                                                sprint(self, "^1Game has already been restarted\n");
index 2e40340206ec6bb120cc9b92553b269bce81be1f..c333910ec6ab6e6a63cd5f68587b474c30706cc2 100644 (file)
@@ -104,6 +104,99 @@ void print_to(entity to, string input)
 //  Supporting functions for common commands
 // ==========================================
 
+// used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such.
+void timeout_handler_reset()
+{
+       entity tmp_player;
+       
+       timeout_caller = world;
+       timeout_time = 0;
+       timeout_leadtime = 0;
+       
+       FOR_EACH_REALPLAYER(tmp_player)
+               Send_CSQC_Centerprint_Generic_Expire(tmp_player, CPID_TIMEOUT_COUNTDOWN);
+                               
+       remove(self);
+}
+
+void timeout_handler_think() 
+{
+       entity tmp_player;
+       
+       switch(timeout_status)
+       {
+               case TIMEOUT_ACTIVE:
+               {
+                       if(timeout_time > 0) // countdown is still going
+                       {
+                               FOR_EACH_REALPLAYER(tmp_player)
+                                       Send_CSQC_Centerprint_Generic(tmp_player, CPID_TIMEOUT_COUNTDOWN, "Timeout ends in %d seconds!", 1, timeout_time);
+
+                               if(timeout_time == autocvar_sv_timeout_resumetime) // play a warning sound when only <sv_timeout_resumetime> seconds are left
+                                       Announce("prepareforbattle");
+
+                               self.nextthink = time + TIMEOUT_SLOWMO_VALUE; // think again in one second
+                               timeout_time -= 1; // decrease the time counter
+                       }
+                       else // time to end the timeout
+                       {
+                               timeout_status = TIMEOUT_INACTIVE;
+                               
+                               // reset the slowmo value back to normal
+                               cvar_set("slowmo", ftos(orig_slowmo));
+                               
+                               // unlock the view for players so they can move around again
+                               FOR_EACH_REALPLAYER(tmp_player) 
+                                       tmp_player.fixangle = FALSE;
+                                       
+                               timeout_handler_reset();
+                       }
+                       
+                       return;
+               }
+               
+               case TIMEOUT_LEADTIME:
+               {
+                       if (timeout_leadtime > 0) // countdown is still going
+                       {
+                               // centerprint the information to every player
+                               FOR_EACH_REALPLAYER(tmp_player) 
+                                       Send_CSQC_Centerprint_Generic(tmp_player, CPID_TIMEOUT_COUNTDOWN, "Timeout begins in %d seconds!", 1, timeout_leadtime);
+                               
+                               self.nextthink = time + 1; // think again in one second
+                               timeout_leadtime -= 1; // decrease the time counter
+                       }
+                       else // time to begin the timeout
+                       {
+                               timeout_status = TIMEOUT_ACTIVE;
+                               
+                               // set the slowmo value to the timeout default slowmo value
+                               cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
+                               
+                               // reset all the flood variables
+                               FOR_EACH_CLIENT(tmp_player)
+                                       tmp_player.nickspamcount = tmp_player.nickspamtime = tmp_player.floodcontrol_chat =
+                                       tmp_player.floodcontrol_chatteam = tmp_player.floodcontrol_chattell = 
+                                       tmp_player.floodcontrol_voice = tmp_player.floodcontrol_voiceteam = 0;
+                                       
+                               // copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
+                               FOR_EACH_REALPLAYER(tmp_player) 
+                                       tmp_player.lastV_angle = tmp_player.v_angle;
+                               
+                               self.nextthink = time; // think again next frame to handle it under TIMEOUT_ACTIVE code
+                       }
+               }
+               
+               
+               case TIMEOUT_INACTIVE:
+               default:
+               {
+                       timeout_handler_reset();
+                       return;
+               }
+       }
+}
+
 
 
 // ===================================================
@@ -399,7 +492,7 @@ void CommonCommand_timein(float request, entity caller)
                                                case TIMEOUT_ACTIVE:
                                                {
                                                        timeout_time = autocvar_sv_timeout_resumetime;
-                                                       timeoutHandler.nextthink = time; // timeout_handler has to take care of it immediately
+                                                       timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately
                                                        bprint(strcat("^1Attention: ^7", caller.netname, " resumed the game! Prepare for battle!\n"));
                                                        return;
                                                }
@@ -443,7 +536,7 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN
                                {                                       
                                        if(caller) { caller.allowed_timeouts -= 1; }
                                        
-                                       bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowedTimeouts), " timeouts left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left)
+                                       bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowed_timeouts), " timeouts left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left)
                                        
                                        timeout_status = TIMEOUT_LEADTIME;
                                        timeout_caller = caller;
index 1c7b170220bc8123919fb05fd3af5c3f531abf15..bf636a3877893a8d7ea4d7587fab07cfe636c167 100644 (file)
@@ -367,7 +367,7 @@ void ReadyRestart_force()
        }
 
        // after a restart every players number of allowed timeouts gets reset, too
-       if(autocvar_sv_timeout) { FOR_EACH_REALPLAYER(tmp_player) { tmp_player.allowedTimeouts = autocvar_sv_timeout_number; } }
+       if(autocvar_sv_timeout) { FOR_EACH_REALPLAYER(tmp_player) { tmp_player.allowed_timeouts = autocvar_sv_timeout_number; } }
 
        //reset map immediately if this cvar is not set
        if not(autocvar_sv_ready_restart_after_countdown) { reset_map(TRUE); }
@@ -625,7 +625,7 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm
                        if not(autocvar_sv_vote_call || !caller) { print_to(caller, "^1Vote calling is not allowed."); }
                        else if(vote_called) { print_to(caller, "^1There is already a vote called."); }
                        else if(!spectators_allowed && (caller && (caller.classname != "player"))) { print_to(caller, "^1Only players can call a vote."); }
-                       else if(timeoutStatus) { print_to(caller, "^1You can not call a vote while a timeout is active."); }
+                       else if(timeout_status) { print_to(caller, "^1You can not call a vote while a timeout is active."); }
                        else if(caller && (time < caller.vote_waittime)) { print_to(caller, strcat("^1You have to wait ^2", ftos(ceil(caller.vote_waittime - time)), "^1 seconds before you can again call a vote.")); }
                        else if not(VoteCommand_checknasty(vote_command)) { print_to(caller, "^1Syntax error in command, see 'vhelp' for more info."); }
                        else if not(VoteCommand_parse(caller, vote_command, autocvar_sv_vote_commands, 2, argc)) { print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); }
@@ -719,6 +719,7 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co
                                        {
                                                if not(autocvar_sv_vote_master_callable) { print_to(caller, "^1Vote to become vote master is not allowed."); }
                                                else if(vote_called) { print_to(caller, "^1There is already a vote called."); }
+                                               else if(timeout_status) { print_to(caller, "^1You can not call a vote while a timeout is active."); }
                                                
                                                else // everything went okay, continue with creating vote
                                                {
index 84ea0210184792e0f313df1b4e089925f6872359..370f2fb9878041cea1bac0cd540d82d2c450a231 100644 (file)
@@ -382,7 +382,7 @@ void FireGrapplingHook (void)
 
 void GrapplingHookFrame()
 {
-       if(g_grappling_hook && timeoutStatus != 2 && self.weapon != WEP_HOOK)
+       if(g_grappling_hook && timeout_status != TIMEOUT_ACTIVE && self.weapon != WEP_HOOK)
        {
                // offhand hook controls
                if(self.BUTTON_HOOK)
index 41288a80869b72639a97740c2cff94789e3b99ec..80a34a0e69b393eccf1f1a9fc4c770929af4fb4c 100644 (file)
@@ -95,83 +95,6 @@ void fteqcc_testbugs()
        world.cnt = 0;
 }
 
-/**
- * Takes care of pausing and unpausing the game.
- * Centerprints the information about an upcoming or active timeout to all active
- * players. Also plays reminder sounds.
- */
-void timeoutHandler_Think() {
-       entity plr;
-       if (timeoutStatus == 1) {
-               if (remainingLeadTime > 0) {
-                       //centerprint the information to every player
-                       FOR_EACH_REALCLIENT(plr) {
-                               if(plr.classname == "player") {
-                                       Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, "Timeout begins in %d seconds!", 1, remainingLeadTime);
-                               }
-                       }
-                       remainingLeadTime -= 1;
-                       //think again in 1 second:
-                       self.nextthink = time + 1;
-               }
-               else {
-                       //now pause the game:
-                       timeoutStatus = 2;
-                       //reset all the flood variables
-                       FOR_EACH_CLIENT(plr) {
-                               plr.nickspamcount = plr.nickspamtime = plr.floodcontrol_chat = plr.floodcontrol_chatteam = plr.floodcontrol_chattell = plr.floodcontrol_voice = plr.floodcontrol_voiceteam = 0;
-                       }
-                       cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
-                       //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
-                       FOR_EACH_REALPLAYER(plr) {
-                               plr.lastV_angle = plr.v_angle;
-                       }
-                       self.nextthink = time;
-               }
-       }
-       else if (timeoutStatus == 2) {
-               if (remainingTimeoutTime > 0) {
-                       FOR_EACH_REALCLIENT(plr) {
-                               if(plr.classname == "player") {
-                                       Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, "Timeout ends in %d seconds!", 1, remainingTimeoutTime);
-                               }
-                       }
-                       if(remainingTimeoutTime == autocvar_sv_timeout_resumetime) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
-                               Announce("prepareforbattle");
-                       }
-                       remainingTimeoutTime -= 1;
-                       self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
-               }
-               else {
-                       //unpause the game again
-                       remainingTimeoutTime = timeoutStatus = 0;
-                       cvar_set("slowmo", ftos(orig_slowmo));
-                       //and unlock the fixed view again once there is no timeout active anymore
-                       FOR_EACH_REALPLAYER(plr) {
-                               plr.fixangle = FALSE;
-                       }
-                       //get rid of the countdown message
-                       FOR_EACH_REALCLIENT(plr) {
-                               if(plr.classname == "player") {
-                                       Send_CSQC_Centerprint_Generic_Expire(plr, CPID_TIMEOUT_COUNTDOWN);
-                               }
-                       }
-                       remove(self);
-                       return;
-               }
-
-       }
-       else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
-               FOR_EACH_REALCLIENT(plr) {
-                       if(plr.classname == "player") {
-                               Send_CSQC_Centerprint_Generic_Expire(plr, CPID_TIMEOUT_COUNTDOWN);
-                       }
-               }
-               remove(self);
-               return;
-       }
-}
-
 void GotoFirstMap()
 {
        float n;
index 7ec4b49d671db22414e9f5b043b9071de1c3a735..d9a0ad460e016746ea796de9e2c8cbc31b0208af 100644 (file)
@@ -196,7 +196,7 @@ void StartFrame (void)
        if(sys_frametime <= 0)
                sys_frametime = 1.0 / 60.0; // somewhat safe fallback
 
-       if (timeoutStatus == 1) // just before the timeout (when timeoutStatus will be 2)
+       if (timeout_status == TIMEOUT_LEADTIME) // just before the timeout (when timeout_status will be TIMEOUT_ACTIVE)
                orig_slowmo = autocvar_slowmo; // slowmo will be restored after the timeout
 
        skill = autocvar_skill;