From 2293c182dc687c3d6284e588028163122a57df5d Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 7 Aug 2017 15:58:43 +1000 Subject: [PATCH] Hack the vote command parser to return an error code to avoid the incorrect 'invalid vote' message when voting for an invalid map, also fix some warnings when a client is connecting --- qcsrc/server/command/vote.qc | 26 +++++++++++++++----------- qcsrc/server/g_world.qc | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index ed17ed0b8..9d5bf6f94 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -646,7 +646,7 @@ float VoteCommand_checkargs(float startpos, float argc) return true; } -float VoteCommand_parse(entity caller, string vote_command, string vote_list, float startpos, float argc) +int VoteCommand_parse(entity caller, string vote_command, string vote_list, float startpos, float argc) { string first_command; @@ -661,11 +661,11 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl (autocvar_sv_vote_limit > 0) && (strlen(substring(vote_command, argv_start_index(startpos), strlen(vote_command) - argv_start_index(startpos))) > autocvar_sv_vote_limit) - ) return false; + ) return 0; - if (!VoteCommand_checkinlist(first_command, vote_list)) return false; + if (!VoteCommand_checkinlist(first_command, vote_list)) return 0; - if (!VoteCommand_checkargs(startpos, argc)) return false; + if (!VoteCommand_checkargs(startpos, argc)) return 0; switch (first_command) // now go through and parse the proper commands to adjust as needed. { @@ -686,7 +686,7 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl vote_parsed_command = strcat(first_command, " # ", ftos(etof(victim)), " ", command_arguments); vote_parsed_display = strcat("^1", vote_command, " (^7", victim.netname, "^1): ", reason); } - else { print_to(caller, strcat("vcall: ", GetClientErrorString(accepted, argv(startpos + 1)), ".\n")); return false; } + else { print_to(caller, strcat("vcall: ", GetClientErrorString(accepted, argv(startpos + 1)), ".\n")); return 0; } break; } @@ -696,7 +696,7 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl case "gotomap": // re-direct all map selection commands to gotomap { vote_command = ValidateMap(argv(startpos + 1), caller); - if (!vote_command) return false; + if (!vote_command) return -1; vote_parsed_command = strcat("gotomap ", vote_command); vote_parsed_display = strzone(strcat("^1", vote_parsed_command)); @@ -712,7 +712,7 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl } } - return true; + return 1; } @@ -759,6 +759,7 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm case CMD_REQUEST_COMMAND: { float tmp_playercount = 0; + int parse_error; vote_command = VoteCommand_extractcommand(vote_command, 2, argc); @@ -791,9 +792,10 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm { print_to(caller, "^1Syntax error in command, see 'vhelp' for more info."); } - else if (!VoteCommand_parse(caller, vote_command, autocvar_sv_vote_commands, 2, argc)) + else if ((parse_error = VoteCommand_parse(caller, vote_command, autocvar_sv_vote_commands, 2, argc)) <= 0) { - print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); + if(parse_error == 0) + print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); } else // everything went okay, continue with calling the vote @@ -848,6 +850,7 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co { case "do": { + int parse_error; vote_command = VoteCommand_extractcommand(vote_command, 3, argc); if (!caller.vote_master) { print_to(caller, "^1You do not have vote master privelages."); } @@ -855,9 +858,10 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co { print_to(caller, "^1Syntax error in command, see 'vhelp' for more info."); } - else if (!VoteCommand_parse(caller, vote_command, strcat(autocvar_sv_vote_commands, " ", autocvar_sv_vote_master_commands), 3, argc)) + else if ((parse_error = VoteCommand_parse(caller, vote_command, strcat(autocvar_sv_vote_commands, " ", autocvar_sv_vote_master_commands), 3, argc)) <= 0) { - print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); + if(parse_error == 0) + print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); } else // everything went okay, proceed with command diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index f00db073e..ccba885f1 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -53,7 +53,7 @@ void PingPLReport_Think(entity this) this.nextthink = time + delta; e = edict_num(this.cnt + 1); - if(IS_REAL_CLIENT(e)) + if(IS_REAL_CLIENT(e) && IS_CLIENT(e)) { WriteHeader(MSG_BROADCAST, TE_CSQC_PINGPLREPORT); WriteByte(MSG_BROADCAST, this.cnt); -- 2.39.2