]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/vote.qc
Improve end of warmup countdown abort (when player count drops too low)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / vote.qc
index de5524526c9585b00d347a246431c6e41c2d7d0a..795ea09e5242f12fc0297a500e2b8a29efc8d601 100644 (file)
@@ -419,7 +419,8 @@ void reset_map(bool dorespawn, bool is_fake_round_start)
 // Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown is set)
 void ReadyRestart_think(entity this)
 {
-       reset_map(true, false);
+       if (!warmup_stage) // if the countdown was not aborted
+               reset_map(true, false);
        delete(this);
 }
 
@@ -498,7 +499,7 @@ void ReadyRestart(bool forceWarmupEnd)
        if(forceWarmupEnd || autocvar_g_campaign)
                warmup_stage = 0; // forcefully end warmup and go to match stage
        else
-               warmup_stage = cvar("g_warmup"); // go into warmup if it's enabled, otherwise restart into match stage
+               warmup_stage = autocvar_g_warmup; // go into warmup if it's enabled, otherwise restart into match stage
 
        ReadyRestart_force(false);
 }
@@ -524,19 +525,26 @@ void ReadyCount()
 
        Nagger_ReadyCounted();
 
-       if (t_players < map_minplayers) // map_minplayers will only be set if g_warmup -1 at worldspawn
+       // can't read warmup_stage here as it could have been set to 0 by ReadyRestart()
+       // and we need to use this when checking if we should abort the countdown
+       // map_minplayers can only be > 0 if g_warmup was -1 at worldspawn
+       int minplayers = autocvar_g_warmup > 1 ? autocvar_g_warmup : map_minplayers;
+
+       if (t_players < minplayers)
        {
                if (game_starttime > time) // someone bailed during countdown, back to warmup
                {
-                       warmup_stage = -1; // CAN change it AFTER calling Nagger_ReadyCounted() this frame
+                       warmup_stage = autocvar_g_warmup; // CAN change it AFTER calling Nagger_ReadyCounted() this frame
                        game_starttime = time;
-                       Send_Notification(NOTIF_ALL, NULL, MSG_MULTI, COUNTDOWN_STOP, map_minplayers);
+                       Send_Notification(NOTIF_ALL, NULL, MSG_MULTI, COUNTDOWN_STOP, minplayers);
+                       if (!sv_ready_restart_after_countdown) // if we ran reset_map() at start of countdown
+                               FOREACH_CLIENT(IS_PLAYER(it), { GiveWarmupResources(it); });
                }
                if (warmup_limit > 0)
                        warmup_limit = -1;
                return; // don't ReadyRestart if players are ready but too few
        }
-       else if (map_minplayers && warmup_limit <= 0)
+       else if (minplayers && warmup_limit <= 0)
        {
                // there's enough players now but we're still in infinite warmup
                warmup_limit = cvar("g_warmup_limit");
@@ -559,9 +567,9 @@ void ReadyCount()
 //  Supporting functions for VoteCommand
 // ======================================
 
-float Votecommand_check_assignment(entity caller, float assignment)
+bool Votecommand_check_assignment(entity caller, float assignment)
 {
-       float from_server = (!caller);
+       bool from_server = (!caller);
 
        if ((assignment == VC_ASGNMNT_BOTH)
            || ((!from_server && assignment == VC_ASGNMNT_CLIENTONLY)
@@ -580,33 +588,32 @@ string VoteCommand_extractcommand(string input, float startpos, int argc)
        return output;
 }
 
-float VoteCommand_checknasty(string vote_command)
+bool VoteCommand_checknasty(string vote_command)
 {
-       if ((strstrofs(vote_command, ";", 0) >= 0)
+       return !((strstrofs(vote_command, ";", 0) >= 0)
            || (strstrofs(vote_command, "\n", 0) >= 0)
            || (strstrofs(vote_command, "\r", 0) >= 0)
-           || (strstrofs(vote_command, "$", 0) >= 0)) return false;
-
-       return true;
+           || (strstrofs(vote_command, "$", 0) >= 0));
 }
 
 // NOTE: requires input to be surrounded by spaces
 string VoteCommand_checkreplacements(string input)
 {
-       string output = input;
+       // add a space around the input so the start and end of the list is captured
+       string output = strcat(" ", input, " ");
        // allow gotomap replacements
        output = strreplace(" map ", " gotomap ", output);
        output = strreplace(" chmap ", " gotomap ", output);
        return output;
 }
 
-float VoteCommand_checkinlist(string vote_command, string list)
+bool VoteCommand_checkinlist(string vote_command, string list)
 {
-       string l = VoteCommand_checkreplacements(strcat(" ", list, " "));
+       if (vote_command == "" || list == "")
+               return false;
 
-       if (strstrofs(l, VoteCommand_checkreplacements(strcat(" ", vote_command, " ")), 0) >= 0) return true;
-
-       return false;
+       string l = VoteCommand_checkreplacements(list);
+       return (strstrofs(l, VoteCommand_checkreplacements(vote_command), 0) >= 0);
 }
 
 string ValidateMap(string validated_map, entity caller)