X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fvote.qc;h=59348d7af701a1e9401f640ddb4dc93c350ff973;hb=8643336b62c2c2881987dabddc842a0214839012;hp=fdb53ace94e1f5b3b11d5aaeb0c621ab03ae776d;hpb=13a42acaac2ee6b7f0494b0a02cefc1e270d9727;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index fdb53ace9..59348d7af 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -1,3 +1,23 @@ +#include "../../common/command/command.qh" +#include "vote.qh" +#include "../_all.qh" + +#include "common.qh" + +#include "../g_damage.qh" +#include "../g_world.qh" +#include "../race.qh" +#include "../round_handler.qh" +#include "../scores.qh" + +#include "../mutators/mutators_include.qh" + +#include "../../common/constants.qh" +#include "../../common/mapinfo.qh" +#include "../../common/notifications.qh" +#include "../../common/playerstats.qh" +#include "../../common/util.qh" + // ============================================= // Server side voting code, reworked by Samual // Last updated: December 27th, 2011 @@ -6,7 +26,7 @@ // Nagger for players to know status of voting float Nagger_SendEntity(entity to, float sendflags) { - float nags, i, f, b; + int nags, i, f, b; entity e; WriteByte(MSG_ENTITY, ENT_CLIENT_NAGGER); @@ -69,12 +89,12 @@ float Nagger_SendEntity(entity to, float sendflags) } } - return TRUE; + return true; } void Nagger_Init() { - Net_LinkEntity(nagger = spawn(), FALSE, 0, Nagger_SendEntity); + Net_LinkEntity(nagger = spawn(), false, 0, Nagger_SendEntity); } void Nagger_VoteChanged() @@ -95,6 +115,13 @@ void Nagger_ReadyCounted() nagger.SendFlags |= 1; } +// If the vote_caller is still here, return their name, otherwise vote_caller_name +string OriginalCallerName() +{ + if (IS_REAL_CLIENT(vote_caller)) + return vote_caller.netname; + return vote_caller_name; +} // ======================= // Game logic for voting @@ -110,10 +137,12 @@ void VoteReset() { strunzone(vote_called_command); strunzone(vote_called_display); + strunzone(vote_caller_name); } vote_called = VOTE_NULL; vote_caller = world; + vote_caller_name = string_null; vote_endtime = 0; vote_called_command = string_null; @@ -127,7 +156,7 @@ void VoteReset() void VoteStop(entity stopper) { - bprint("\{1}^2* ^3", GetCallerName(stopper), "^2 stopped ^3", GetCallerName(vote_caller), "^2's vote\n"); + bprint("\{1}^2* ^3", GetCallerName(stopper), "^2 stopped ^3", OriginalCallerName(), "^2's vote\n"); if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vstop:", ftos(stopper.playerid))); } // Don't force them to wait for next vote, this way they can e.g. correct their vote. @@ -138,7 +167,7 @@ void VoteStop(entity stopper) void VoteAccept() { - bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ^1", vote_called_display, "^2 was accepted\n"); + bprint("\{1}^2* ^3", OriginalCallerName(), "^2's vote for ^1", vote_called_display, "^2 was accepted\n"); if((vote_called == VOTE_MASTER) && vote_caller) vote_caller.vote_master = 1; @@ -153,14 +182,14 @@ void VoteAccept() void VoteReject() { - bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ", vote_called_display, "^2 was rejected\n"); + bprint("\{1}^2* ^3", OriginalCallerName(), "^2's vote for ", vote_called_display, "^2 was rejected\n"); VoteReset(); Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_VOTE_FAIL); } void VoteTimeout() { - bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ", vote_called_display, "^2 timed out\n"); + bprint("\{1}^2* ^3", OriginalCallerName(), "^2's vote for ", vote_called_display, "^2 timed out\n"); VoteReset(); Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_VOTE_FAIL); } @@ -213,7 +242,7 @@ void VoteCount(float first_count) switch(tmp_player.vote_selection) { case VOTE_SELECT_REJECT: { ++vote_reject_count; { if(IS_PLAYER(tmp_player)) ++vote_real_reject_count; } break; } - case VOTE_SELECT_ACCEPT: { ++vote_accept_count; { if(IS_PLAYER(tmp_player)) ++vote_real_reject_count; } break; } + case VOTE_SELECT_ACCEPT: { ++vote_accept_count; { if(IS_PLAYER(tmp_player)) ++vote_real_accept_count; } break; } case VOTE_SELECT_ABSTAIN: { ++vote_abstain_count; { if(IS_PLAYER(tmp_player)) ++vote_real_abstain_count; } break; } default: break; } @@ -306,7 +335,7 @@ void VoteThink() if(vote_endtime > 0) // a vote was called if(time > vote_endtime) // time is up { - VoteCount(FALSE); + VoteCount(false); } return; @@ -355,6 +384,10 @@ void reset_map(float dorespawn) } } + FOR_EACH_PLAYER(self) + if(self.frozen) + Unfreeze(self); + // Moving the player reset code here since the player-reset depends // on spawnpoint entities which have to be reset first --blub if(dorespawn) @@ -392,7 +425,7 @@ void reset_map(float dorespawn) void ReadyRestart_think() { restart_mapalreadyrestarted = 1; - reset_map(TRUE); + reset_map(true); Score_ClearAll(); remove(self); @@ -421,7 +454,7 @@ void ReadyRestart_force() { tmp_player.alivetime = 0; tmp_player.killcount = 0; - PlayerStats_Event(tmp_player, PLAYERSTATS_ALIVETIME, -PlayerStats_Event(tmp_player, PLAYERSTATS_ALIVETIME, 0)); + PS_GR_P_ADDVAL(tmp_player, PLAYERSTATS_ALIVETIME, -PS_GR_P_ADDVAL(tmp_player, PLAYERSTATS_ALIVETIME, 0)); } restart_mapalreadyrestarted = 0; // reset this var, needed when cvar sv_ready_restart_repeatable is in use @@ -429,6 +462,8 @@ void ReadyRestart_force() // disable the warmup global for the server warmup_stage = 0; // once the game is restarted the game is in match stage + Item_ItemsTime_Reset(); + // reset the .ready status of all players (also spectators) FOR_EACH_REALCLIENT(tmp_player) { tmp_player.ready = 0; } readycount = 0; @@ -453,7 +488,7 @@ void ReadyRestart_force() 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 (!autocvar_sv_ready_restart_after_countdown) { reset_map(TRUE); } + if (!autocvar_sv_ready_restart_after_countdown) { reset_map(true); } if(autocvar_sv_eventlog) { GameLogEcho(":restart"); } } @@ -519,10 +554,10 @@ float Votecommand_check_assignment(entity caller, float assignment) || ((!from_server && assignment == VC_ASGNMNT_CLIENTONLY) || (from_server && assignment == VC_ASGNMNT_SERVERONLY))) { - return TRUE; + return true; } - return FALSE; + return false; } string VoteCommand_extractcommand(string input, float startpos, float argc) @@ -543,9 +578,9 @@ float VoteCommand_checknasty(string vote_command) || (strstrofs(vote_command, "\n", 0) >= 0) || (strstrofs(vote_command, "\r", 0) >= 0) || (strstrofs(vote_command, "$", 0) >= 0)) - return FALSE; + return false; - return TRUE; + return true; } float VoteCommand_checkinlist(string vote_command, string list) @@ -553,9 +588,9 @@ float VoteCommand_checkinlist(string vote_command, string list) string l = strcat(" ", list, " "); if(strstrofs(l, strcat(" ", vote_command, " "), 0) >= 0) - return TRUE; + return true; - return FALSE; + return false; } string ValidateMap(string validated_map, entity caller) @@ -595,7 +630,7 @@ float VoteCommand_checkargs(float startpos, float argc) float checkmate; if(cmdrestriction == "") - return TRUE; + return true; ++startpos; // skip command name @@ -607,11 +642,11 @@ float VoteCommand_checkargs(float startpos, float argc) minargs = stof(cmdrestriction); if(argc - startpos < minargs) - return FALSE; + return false; p = strstrofs(cmdrestriction, ";", 0); // find first semicolon - for(;;) + for (;;) { // we know that at any time, startpos <= argc - minargs // so this means: argc-minargs >= startpos >= argc, thus @@ -628,7 +663,7 @@ float VoteCommand_checkargs(float startpos, float argc) break; // otherwise fail - return FALSE; + return false; } // cut to next semicolon @@ -648,7 +683,7 @@ float VoteCommand_checkargs(float startpos, float argc) checkmate = strlen(arg); for(check = 0; check < checkmate; ++check) if(strstrofs(charlist, substring(arg, check, 1), 0) < 0) - return FALSE; // not allowed character + return false; // not allowed character // all characters are allowed. FINE. } @@ -657,7 +692,7 @@ float VoteCommand_checkargs(float startpos, float argc) p = q; } - return TRUE; + return true; } float VoteCommand_parse(entity caller, string vote_command, string vote_list, float startpos, float argc) @@ -676,13 +711,13 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl && (strlen(substring(vote_command, argv_start_index(startpos), strlen(vote_command) - argv_start_index(startpos))) > autocvar_sv_vote_limit) ) - return FALSE; + return false; if (!VoteCommand_checkinlist(first_command, vote_list)) - return FALSE; + return false; if (!VoteCommand_checkargs(startpos, argc)) - return FALSE; + return false; switch(first_command) // now go through and parse the proper commands to adjust as needed. { @@ -690,7 +725,7 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl case "kickban": // catch all kick/kickban commands { entity victim = GetIndexedEntity(argc, (startpos + 1)); - float accepted = VerifyClientEntity(victim, TRUE, FALSE); + float accepted = VerifyClientEntity(victim, true, false); if(accepted > 0) { @@ -705,7 +740,7 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl vote_parsed_command = strcat(first_command, " # ", ftos(num_for_edict(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 false; } break; } @@ -715,7 +750,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 false; } vote_parsed_command = strcat("gotomap ", vote_command); vote_parsed_display = strzone(strcat("^1", vote_parsed_command)); @@ -731,7 +766,7 @@ float VoteCommand_parse(entity caller, string vote_command, string vote_list, fl } } - return TRUE; + return true; } @@ -753,7 +788,7 @@ void VoteCommand_abstain(float request, entity caller) // CLIENT ONLY print_to(caller, "^1You abstained from your vote."); caller.vote_selection = VOTE_SELECT_ABSTAIN; msg_entity = caller; - if(!autocvar_sv_vote_singlecount) { VoteCount(FALSE); } + if(!autocvar_sv_vote_singlecount) { VoteCount(false); } } return; @@ -788,6 +823,7 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm else if(!autocvar_sv_vote_gamestart && time < game_starttime) { print_to(caller, "^1Vote calling is not allowed before the match has started."); } else if(vote_called) { print_to(caller, "^1There is already a vote called."); } else if(!spectators_allowed && (caller && !IS_PLAYER(caller))) { print_to(caller, "^1Only players can call a vote."); } + else if(caller && !IS_CLIENT(caller)) { print_to(caller, "^1Only connected clients can vote."); } 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 (!VoteCommand_checknasty(vote_command)) { print_to(caller, "^1Syntax error in command, see 'vhelp' for more info."); } @@ -796,6 +832,7 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm else // everything went okay, continue with calling the vote { vote_caller = caller; // remember who called the vote + vote_caller_name = strzone(GetCallerName(vote_caller)); vote_called = VOTE_NORMAL; vote_called_command = strzone(vote_parsed_command); vote_called_display = strzone(vote_parsed_display); @@ -811,10 +848,10 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm FOR_EACH_REALCLIENT(tmp_player) { ++tmp_playercount; } if(tmp_playercount > 1) { Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_VOTE_CALL); } // don't announce a "vote now" sound if player is alone - bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2 calls a vote for ", vote_called_display, "\n"); + bprint("\{1}^2* ^3", OriginalCallerName(), "^2 calls a vote for ", vote_called_display, "\n"); if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display)); } Nagger_VoteChanged(); - VoteCount(TRUE); // needed if you are the only one + VoteCount(true); // needed if you are the only one } return; @@ -869,7 +906,7 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co else // everything went okay, proceed with giving this player master privilages { - caller.vote_master = TRUE; + caller.vote_master = true; print_to(caller, strcat("Accepted vote master login from ", GetCallerName(caller))); bprint("\{1}^2* ^3", GetCallerName(caller), "^2 logged in as ^3master^2\n"); if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vlogin:", ftos(caller.playerid))); } @@ -892,6 +929,7 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co else // everything went okay, continue with creating vote { vote_caller = caller; + vote_caller_name = strzone(GetCallerName(vote_caller)); vote_called = VOTE_MASTER; vote_called_command = strzone("XXX"); vote_called_display = strzone("^3master"); @@ -900,10 +938,10 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co caller.vote_selection = VOTE_SELECT_ACCEPT; caller.vote_waittime = time + autocvar_sv_vote_wait; - bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2 calls a vote to become ^3master^2.\n"); + bprint("\{1}^2* ^3", OriginalCallerName(), "^2 calls a vote to become ^3master^2.\n"); if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display)); } Nagger_VoteChanged(); - VoteCount(TRUE); // needed if you are the only one + VoteCount(true); // needed if you are the only one } return; @@ -941,7 +979,7 @@ void VoteCommand_no(float request, entity caller) // CLIENT ONLY print_to(caller, "^1You rejected the vote."); caller.vote_selection = VOTE_SELECT_REJECT; msg_entity = caller; - if(!autocvar_sv_vote_singlecount) { VoteCount(FALSE); } + if(!autocvar_sv_vote_singlecount) { VoteCount(false); } } return; @@ -964,7 +1002,7 @@ void VoteCommand_status(float request, entity caller) // BOTH case CMD_REQUEST_COMMAND: { if(vote_called) - print_to(caller, strcat("^7Vote for ", vote_called_display, "^7 called by ^7", GetCallerName(vote_caller), "^7.")); + print_to(caller, strcat("^7Vote for ", vote_called_display, "^7 called by ^7", OriginalCallerName(), "^7.")); else print_to(caller, "^1No vote called."); @@ -1018,7 +1056,7 @@ void VoteCommand_yes(float request, entity caller) // CLIENT ONLY print_to(caller, "^1You accepted the vote."); caller.vote_selection = VOTE_SELECT_ACCEPT; msg_entity = caller; - if(!autocvar_sv_vote_singlecount) { VoteCount(FALSE); } + if(!autocvar_sv_vote_singlecount) { VoteCount(false); } } return; @@ -1084,7 +1122,7 @@ void VoteCommand_macro_help(entity caller, float argc) #define VOTE_COMMAND(name,function,description,assignment) \ { if(Votecommand_check_assignment(caller, assignment)) { print_to(caller, strcat(" ^2", name, "^7: ", description)); } } - VOTE_COMMANDS(0, caller, 0, "") + VOTE_COMMANDS(0, caller, 0, ""); #undef VOTE_COMMAND print_to(caller, strcat("\nUsage:^3 ", command_origin, " vote COMMAND...^7, where possible commands are listed above.\n")); @@ -1096,7 +1134,7 @@ void VoteCommand_macro_help(entity caller, float argc) #define VOTE_COMMAND(name,function,description,assignment) \ { if(Votecommand_check_assignment(caller, assignment)) { if(name == strtolower(argv(2))) { function; return; } } } - VOTE_COMMANDS(CMD_REQUEST_USAGE, caller, argc, "") + VOTE_COMMANDS(CMD_REQUEST_USAGE, caller, argc, ""); #undef VOTE_COMMAND } @@ -1106,12 +1144,12 @@ void VoteCommand_macro_help(entity caller, float argc) float VoteCommand_macro_command(entity caller, float argc, string vote_command) { #define VOTE_COMMAND(name,function,description,assignment) \ - { if(Votecommand_check_assignment(caller, assignment)) { if(name == strtolower(argv(1))) { function; return TRUE; } } } + { if(Votecommand_check_assignment(caller, assignment)) { if(name == strtolower(argv(1))) { function; return true; } } } - VOTE_COMMANDS(CMD_REQUEST_COMMAND, caller, argc, vote_command) + VOTE_COMMANDS(CMD_REQUEST_COMMAND, caller, argc, vote_command); #undef VOTE_COMMAND - return FALSE; + return false; }