]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up vote list checking code to not check empty lists/votes, fixes #2751
authorMario <mario.mario@y7mail.com>
Sat, 12 Nov 2022 03:00:47 +0000 (13:00 +1000)
committerMario <mario.mario@y7mail.com>
Sat, 12 Nov 2022 03:00:47 +0000 (13:00 +1000)
qcsrc/server/command/vote.qc

index de5524526c9585b00d347a246431c6e41c2d7d0a..b360f34d3f325133ee88629f26110d54a5f508d8 100644 (file)
@@ -559,9 +559,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 +580,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)