From: Mario Date: Sat, 12 Nov 2022 03:00:47 +0000 (+1000) Subject: Clean up vote list checking code to not check empty lists/votes, fixes #2751 X-Git-Tag: xonotic-v0.8.6~246^2~11 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3b6210b710d7bc2c795b022d3cdc96d172dc01ac;p=xonotic%2Fxonotic-data.pk3dir.git Clean up vote list checking code to not check empty lists/votes, fixes #2751 --- diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index de5524526..b360f34d3 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -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)