From fe867bfb3a09b6651f24193af041a8f73fb33a7a Mon Sep 17 00:00:00 2001 From: Samual Date: Sun, 4 Dec 2011 03:35:22 -0500 Subject: [PATCH] Mostly functional now, just gotta add the rest of the commands --- qcsrc/server/clientcommands.qc | 2 +- qcsrc/server/g_world.qc | 42 ++--- qcsrc/server/gamecommand.qc | 2 +- qcsrc/server/vote.qc | 299 +++++++++++++++++++++++++-------- qcsrc/server/vote.qh | 4 +- 5 files changed, 253 insertions(+), 96 deletions(-) diff --git a/qcsrc/server/clientcommands.qc b/qcsrc/server/clientcommands.qc index febaf1a62..cfe266bb3 100644 --- a/qcsrc/server/clientcommands.qc +++ b/qcsrc/server/clientcommands.qc @@ -894,7 +894,7 @@ void ClientCommand_(float request) CLIENT_COMMAND("timein", ClientCommand_timein(request), "Resume the game from being paused with a timeout") \ CLIENT_COMMAND("timeout", ClientCommand_timeout(request), "Call a timeout which pauses the game for certain amount of time unless unpaused") \ CLIENT_COMMAND("voice", ClientCommand_voice(request, arguments, command), "Send voice message via sound") \ - CLIENT_COMMAND("vote", VoteCommand(self, arguments), "Request an action to be voted upon by players") // handled in server/vote.qc \ + CLIENT_COMMAND("vote", VoteCommand(request, self, arguments), "Request an action to be voted upon by players") /* handled in server/vote.qc */ \ /* nothing */ void ClientCommand_macro_help() diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 77b56d376..6ed8fee3f 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -2307,8 +2307,8 @@ string mapvote_maps_pakfile[MAPVOTE_COUNT]; float mapvote_maps_suggested[MAPVOTE_COUNT]; string mapvote_suggestions[MAPVOTE_COUNT]; float mapvote_suggestion_ptr; -float mapvote_voters; -float mapvote_votes[MAPVOTE_COUNT]; +float mapvote_selectionrs; +float mapvote_selections[MAPVOTE_COUNT]; float mapvote_run; float mapvote_detail; float mapvote_abstain; @@ -2532,7 +2532,7 @@ float MapVote_SendEntity(entity to, float sf) if(mapvote_detail) for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "") - WriteByte(MSG_ENTITY, mapvote_votes[i]); + WriteByte(MSG_ENTITY, mapvote_selections[i]); WriteByte(MSG_ENTITY, to.mapvote); } @@ -2564,16 +2564,16 @@ float MapVote_Finished(float mappos) if(autocvar_sv_eventlog) { result = strcat(":vote:finished:", mapvote_maps[mappos]); - result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::"); - didntvote = mapvote_voters; + result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::"); + didntvote = mapvote_selectionrs; for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "") { - didntvote -= mapvote_votes[i]; + didntvote -= mapvote_selections[i]; if(i != mappos) { result = strcat(result, ":", mapvote_maps[i]); - result = strcat(result, ":", ftos(mapvote_votes[i])); + result = strcat(result, ":", ftos(mapvote_selections[i])); } } result = strcat(result, ":didn't vote:", ftos(didntvote)); @@ -2598,18 +2598,18 @@ void MapVote_CheckRules_1() for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "") { //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n"); - mapvote_votes[i] = 0; + mapvote_selections[i] = 0; } - mapvote_voters = 0; + mapvote_selectionrs = 0; FOR_EACH_REALCLIENT(other) { - ++mapvote_voters; + ++mapvote_selectionrs; if(other.mapvote) { i = other.mapvote - 1; //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n"); - mapvote_votes[i] = mapvote_votes[i] + 1; + mapvote_selections[i] = mapvote_selections[i] + 1; } } } @@ -2619,19 +2619,19 @@ float MapVote_CheckRules_2() float i; float firstPlace, secondPlace; float firstPlaceVotes, secondPlaceVotes; - float mapvote_voters_real; + float mapvote_selectionrs_real; string result; if(mapvote_count_real == 1) return MapVote_Finished(0); - mapvote_voters_real = mapvote_voters; + mapvote_selectionrs_real = mapvote_selectionrs; if(mapvote_abstain) - mapvote_voters_real -= mapvote_votes[mapvote_count - 1]; + mapvote_selectionrs_real -= mapvote_selections[mapvote_count - 1]; RandomSelection_Init(); for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "") - RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]); + RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]); firstPlace = RandomSelection_chosen_float; firstPlaceVotes = RandomSelection_best_priority; //dprint("First place: ", ftos(firstPlace), "\n"); @@ -2640,7 +2640,7 @@ float MapVote_CheckRules_2() RandomSelection_Init(); for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "") if(i != firstPlace) - RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]); + RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]); secondPlace = RandomSelection_chosen_float; secondPlaceVotes = RandomSelection_best_priority; //dprint("Second place: ", ftos(secondPlace), "\n"); @@ -2649,11 +2649,11 @@ float MapVote_CheckRules_2() if(firstPlace == -1) error("No first place in map vote... WTF?"); - if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes) + if(secondPlace == -1 || time > mapvote_timeout || (mapvote_selectionrs_real - firstPlaceVotes) < firstPlaceVotes) return MapVote_Finished(firstPlace); if(mapvote_keeptwotime) - if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes) + if(time > mapvote_keeptwotime || (mapvote_selectionrs_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes) { float didntvote; MapVote_TouchMask(); @@ -2663,16 +2663,16 @@ float MapVote_CheckRules_2() result = strcat(result, ":", ftos(firstPlaceVotes)); result = strcat(result, ":", mapvote_maps[secondPlace]); result = strcat(result, ":", ftos(secondPlaceVotes), "::"); - didntvote = mapvote_voters; + didntvote = mapvote_selectionrs; for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "") { - didntvote -= mapvote_votes[i]; + didntvote -= mapvote_selections[i]; if(i != firstPlace) if(i != secondPlace) { result = strcat(result, ":", mapvote_maps[i]); - result = strcat(result, ":", ftos(mapvote_votes[i])); + result = strcat(result, ":", ftos(mapvote_selections[i])); if(i < mapvote_count_real) { strunzone(mapvote_maps[i]); diff --git a/qcsrc/server/gamecommand.qc b/qcsrc/server/gamecommand.qc index 74dc541a6..cd8c623f3 100644 --- a/qcsrc/server/gamecommand.qc +++ b/qcsrc/server/gamecommand.qc @@ -1927,7 +1927,7 @@ void GameCommand_(float request) SERVER_COMMAND("trace", GameCommand_trace(request, arguments), "Various debugging tools with tracing") \ SERVER_COMMAND("unlockteams", GameCommand_unlockteams(request), "Enable the ability for players to switch or enter teams") \ SERVER_COMMAND("warp", GameCommand_warp(request, arguments), "Choose different level in campaign") \ - SERVER_COMMAND("vote", VoteCommand(world, arguments), "Server side control of voting") \ + SERVER_COMMAND("vote", VoteCommand(request, world, arguments), "Server side control of voting") /* handled in server/vote.qc */ \ /* nothing */ void GameCommand_macro_help() diff --git a/qcsrc/server/vote.qc b/qcsrc/server/vote.qc index 420b20434..1e6a33549 100644 --- a/qcsrc/server/vote.qc +++ b/qcsrc/server/vote.qc @@ -10,6 +10,10 @@ #define VC_ASGNMNT_CLIENTONLY 2 #define VC_ASGNMNT_SERVERONLY 3 +#define VOTE_SELECT_ABSTAIN -2 +#define VOTE_SELECT_REJECT -1 +#define VOTE_SELECT_NULL 0 +#define VOTE_SELECT_ACCEPT 1 // ============================ // Misc. Supporting Functions @@ -23,11 +27,9 @@ float Votecommand_check_assignment(entity caller, float assignment) || ((!from_server && assignment == VC_ASGNMNT_CLIENTONLY) || (from_server && assignment == VC_ASGNMNT_SERVERONLY))) { - print("check_assignment returned true\n"); return TRUE; } - - print("check_assignment returned false\n"); + return FALSE; } @@ -65,7 +67,7 @@ float Nagger_SendEntity(entity to, float sendflags) if(votecalled) { nags |= 4; - if(to.vote_vote == 0) + if(to.vote_selection == 0) nags |= 8; } if(inWarmupStage) @@ -87,7 +89,7 @@ float Nagger_SendEntity(entity to, float sendflags) WriteByte(MSG_ENTITY, vote_yescount); WriteByte(MSG_ENTITY, vote_nocount); WriteByte(MSG_ENTITY, vote_needed_absolute); - WriteChar(MSG_ENTITY, to.vote_vote); + WriteChar(MSG_ENTITY, to.vote_selection); } if(nags & 128) @@ -220,32 +222,29 @@ void ReadyRestart() */ void ReadyCount() { - local entity e; - local float r, p; + entity tmp_player; + float t_ready, t_players; - r = p = 0; - - FOR_EACH_REALPLAYER(e) + FOR_EACH_REALPLAYER(tmp_player) { - p += 1; - if(e.ready) - r += 1; + ++t_players; + if(tmp_player.ready) { ++t_ready; } } - readycount = r; + readycount = t_ready; Nagger_ReadyCounted(); - if(r) // at least one is ready - if(r == p) // and, everyone is ready + // TODO: Add ability to + if(t_ready) // at least one is ready + if(t_ready == t_players) // and, everyone is ready ReadyRestart(); } -/** - * Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown - * is set) - */ -void restartTimer_Think() { + +// Restarts the map after the countdown is over (and cvar sv_ready_restart_after_countdown is set) +void restartTimer_Think() +{ restart_mapalreadyrestarted = 1; reset_map(TRUE); Score_ClearAll(); @@ -263,6 +262,7 @@ float VoteCheckNasty(string cmd) return TRUE; if(strstrofs(cmd, "$", 0) >= 0) return TRUE; + return FALSE; } @@ -324,7 +324,7 @@ entity GetKickVoteVictim(string vote, string cmd, entity caller) } string RemapVote_display; -string RemapVote_vote; +string Remapvote_selection; float RemapVote(string vote, string cmd, entity e) { float vote_argc; @@ -359,12 +359,12 @@ float RemapVote(string vote, string cmd, entity e) { if(!(victim = GetKickVoteVictim(vote, cmd, e))) return FALSE; - RemapVote_vote = GetKickVoteVictim_newcommand; + Remapvote_selection = GetKickVoteVictim_newcommand; RemapVote_display = strcat("^1", vote, " (^7", victim.netname, "^1): ", GetKickVoteVictim_reason); } else { - RemapVote_vote = vote; + Remapvote_selection = vote; RemapVote_display = strzone(strcat("^1", vote)); } @@ -377,6 +377,58 @@ float RemapVote(string vote, string cmd, entity e) // ======================= void VoteCommand_abstain(float request, entity caller) +{ + switch(request) + { + case VC_REQUEST_COMMAND: + { + if(votecalled) + { + if(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) + { + print_to(caller, "^1You abstained from your vote."); + caller.vote_selection = VOTE_SELECT_ABSTAIN; + msg_entity = caller; + if(!autocvar_sv_vote_singlecount) { VoteCount(); } + } + else { print_to(caller, "^1You have already voted."); } + } + else { print_to(caller, "^1No vote called."); } + + return; + } + + default: + case VC_REQUEST_USAGE: + { + print("\nUsage:^3 vote abstain\n"); + print(" No arguments required.\n"); + return; + } + } +} + +void VoteCommand_call(float request, entity caller, float argc) +{ + switch(request) + { + case VC_REQUEST_COMMAND: + { + + return; + } + + default: + case VC_REQUEST_USAGE: + { + print("\nUsage:^3 vote call\n"); + print(" No arguments required.\n"); + return; + } + } +} + +void VoteCommand_force(float request, float argc) { switch(request) { @@ -396,6 +448,78 @@ void VoteCommand_abstain(float request, entity caller) } } +void VoteCommand_master(float request, entity caller, float argc) +{ + switch(request) + { + case VC_REQUEST_COMMAND: + { + + return; + } + + default: + case VC_REQUEST_USAGE: + { + print("\nUsage:^3 vote master action [arguments]\n"); + print(" No arguments required.\n"); + return; + } + } +} + +void VoteCommand_no(float request, entity caller) +{ + switch(request) + { + case VC_REQUEST_COMMAND: + { + if(votecalled) + { + if(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) + { + print_to(caller, "^1You rejected the vote."); + caller.vote_selection = VOTE_SELECT_REJECT; + msg_entity = caller; + if(!autocvar_sv_vote_singlecount) { VoteCount(); } + } + else { print_to(caller, "^1You have already voted."); } + } + else { print_to(caller, "^1No vote called."); } + + return; + } + + default: + case VC_REQUEST_USAGE: + { + print("\nUsage:^3 vote no\n"); + print(" No arguments required.\n"); + return; + } + } +} + +void VoteCommand_status(float request, entity caller) +{ + switch(request) + { + case VC_REQUEST_COMMAND: + { + + return; + } + + default: + case VC_REQUEST_USAGE: + { + print("\nUsage:^3 vote status\n"); + print(" No arguments required.\n"); + return; + } + } +} + void VoteCommand_stop(float request, entity caller) { switch(request) @@ -409,7 +533,39 @@ void VoteCommand_stop(float request, entity caller) default: case VC_REQUEST_USAGE: { - print("\nUsage:^3 vote \n"); + print("\nUsage:^3 vote stop\n"); + print(" No arguments required.\n"); + return; + } + } +} + +void VoteCommand_yes(float request, entity caller) +{ + switch(request) + { + case VC_REQUEST_COMMAND: + { + if(votecalled) + { + if(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) + { + print_to(caller, "^1You accepted the vote."); + caller.vote_selection = VOTE_SELECT_ACCEPT; + msg_entity = caller; + if(!autocvar_sv_vote_singlecount) { VoteCount(); } + } + else { print_to(caller, "^1You have already voted."); } + } + else { print_to(caller, "^1No vote called."); } + + return; + } + + default: + case VC_REQUEST_USAGE: + { + print("\nUsage:^3 vote yes\n"); print(" No arguments required.\n"); return; } @@ -439,53 +595,57 @@ void VoteCommand_(float request) */ -// ================================== -// Macro system for server commands -// ================================== +// ================================ +// Macro system for vote commands +// ================================ // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) #define VOTE_COMMANDS(request,caller,arguments) \ VOTE_COMMAND("abstain", VoteCommand_abstain(request, caller), "Abstain your vote in current vote", VC_ASGNMNT_CLIENTONLY) \ VOTE_COMMAND("call", VoteCommand_call(request, caller, arguments), "Create a new vote for players to decide on", VC_ASGNMNT_BOTH) \ - VOTE_COMMAND("force", VoteCommand_force(request, caller), "Force a result of a vote", VC_ASGNMNT_SERVERONLY) \ - VOTE_COMMAND("help", VoteCommand_macro_help(caller), "Shows this information", VC_ASGNMNT_BOTH) \ + VOTE_COMMAND("force", VoteCommand_force(request, arguments), "Force the result of a vote", VC_ASGNMNT_SERVERONLY) \ + VOTE_COMMAND("help", VoteCommand_macro_help(caller, arguments), "Shows this information", VC_ASGNMNT_BOTH) \ VOTE_COMMAND("master", VoteCommand_master(request, caller, arguments), "", VC_ASGNMNT_CLIENTONLY) \ - VOTE_COMMAND("no", VoteCommand_no(request, caller), "Vote no in current poll", VC_ASGNMNT_CLIENTONLY) \ - VOTE_COMMAND("status", VoteCommand_status(request, caller), "Prints information about current poll", VC_ASGNMNT_BOTH) \ + VOTE_COMMAND("no", VoteCommand_no(request, caller), "Select no in current vote", VC_ASGNMNT_CLIENTONLY) \ + VOTE_COMMAND("status", VoteCommand_status(request, caller), "Prints information about current vote", VC_ASGNMNT_BOTH) \ VOTE_COMMAND("stop", VoteCommand_stop(request, caller), "Immediately end a vote", VC_ASGNMNT_BOTH) \ - VOTE_COMMAND("yes", VoteCommand_yes(request, caller), "Vote yes in current poll", VC_ASGNMNT_CLIENTONLY) \ + VOTE_COMMAND("yes", VoteCommand_yes(request, caller), "Select yes in current vote", VC_ASGNMNT_CLIENTONLY) \ /* nothing */ -void VoteCommand_macro_help(entity caller) +void VoteCommand_macro_help(entity caller, float argc) { - print("\nUsage:^3 ", VoteCommand_getprefix(caller), " vote COMMAND...^7, where possible commands are:\n"); + string command_origin = VoteCommand_getprefix(caller); - #define VOTE_COMMAND(name,function,description,assignment) \ - { if(Votecommand_check_assignment(caller, assignment)) { print(" ^2", name, "^7: ", description, "\n"); } } + if(argc == 2) // help display listing all commands + { + print("\nUsage:^3 ", command_origin, " vote COMMAND...^7, where possible commands are:\n"); - VOTE_COMMANDS(0, caller, 0) - #undef VOTE_COMMAND + #define VOTE_COMMAND(name,function,description,assignment) \ + { if(Votecommand_check_assignment(caller, assignment)) { print(" ^2", name, "^7: ", description, "\n"); } } + + VOTE_COMMANDS(0, caller, 0) + #undef VOTE_COMMAND + + print("For help about specific commands, type ", command_origin, " vote help COMMAND\n"); + } + else // usage for individual command + { + #define VOTE_COMMAND(name,function,description,assignment) \ + { if(Votecommand_check_assignment(caller, assignment)) { if(name == strtolower(argv(2))) { function; return; } } } + + VOTE_COMMANDS(VC_REQUEST_USAGE, caller, argc) + #undef VOTE_COMMAND + } return; } float VoteCommand_macro_command(entity caller, float argc) -{ - #define VOTE_COMMAND(name,function,description,assignment) \ - { if(Votecommand_check_assignment(caller, assignment)) { if(name == strtolower(argv(0))) { function; return TRUE; } } } - - VOTE_COMMANDS(VC_REQUEST_COMMAND, caller, argc) - #undef VOTE_COMMAND - - return FALSE; -} - -float VoteCommand_macro_usage(entity caller, float argc) { #define VOTE_COMMAND(name,function,description,assignment) \ { if(Votecommand_check_assignment(caller, assignment)) { if(name == strtolower(argv(1))) { function; return TRUE; } } } - VOTE_COMMANDS(VC_REQUEST_USAGE, caller, argc) + VOTE_COMMANDS(VC_REQUEST_COMMAND, caller, argc) #undef VOTE_COMMAND return FALSE; @@ -496,27 +656,24 @@ float VoteCommand_macro_usage(entity caller, float argc) // Main function handling vote commands // ====================================== -void VoteCommand(entity caller, float argc) +void VoteCommand(float request, entity caller, float argc) { - if(strtolower(argv(0)) == "help") + switch(request) { - if(argc == 1) + case VC_REQUEST_COMMAND: { - VoteCommand_macro_help(caller); - return; + if(VoteCommand_macro_command(caller, argc)) + return; } - else if(VoteCommand_macro_usage(caller, argc)) + + default: + print_to(caller, strcat("Unknown vote command", ((argv(1) != "") ? strcat(" \"", argv(1), "\"") : ""), ". For a list of supported commands, try ", VoteCommand_getprefix(caller), " help.\n")); + case VC_REQUEST_USAGE: { + VoteCommand_macro_help(caller, argc); return; } } - else if(VoteCommand_macro_command(caller, argc)) - { - return; - } - - // nothing above caught the command, must be invalid - //print("Unknown server command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try sv_cmd help.\n"); } void VoteHelp(entity e) { @@ -645,7 +802,7 @@ void VoteReset() { FOR_EACH_CLIENT(player) { - player.vote_vote = 0; + player.vote_selection = 0; } if(votecalled) @@ -754,21 +911,21 @@ void VoteCount() { FOR_EACH_REALCLIENT(player) { - if(player.vote_vote == -1) { + if(player.vote_selection == -1) { ++vote_nocount; - } else if(player.vote_vote == 1) { + } else if(player.vote_selection == 1) { ++vote_yescount; - } else if(player.vote_vote == -2) { + } else if(player.vote_selection == -2) { ++vote_abstaincount; } ++playercount; //do the same for real players if(player.classname == "player") { - if(player.vote_vote == -1) { + if(player.vote_selection == -1) { ++realplayernocount; - } else if(player.vote_vote == 1) { + } else if(player.vote_selection == 1) { ++realplayeryescount; - } else if(player.vote_vote == -2) { + } else if(player.vote_selection == -2) { ++realplayerabstaincount; } ++realplayercount; diff --git a/qcsrc/server/vote.qh b/qcsrc/server/vote.qh index 530a80605..7a25bda64 100644 --- a/qcsrc/server/vote.qh +++ b/qcsrc/server/vote.qh @@ -6,7 +6,7 @@ entity votecaller; float votefinished; .float vote_master; .float vote_next; -.float vote_vote; +.float vote_selection; float vote_yescount; float vote_nocount; float vote_abstaincount; @@ -15,7 +15,7 @@ float vote_needed_simple; float VoteCheckNasty(string cmd); entity GetKickVoteVictim(string vote, string cmd, entity caller); -void VoteCommand(entity caller, float argc); +void VoteCommand(float request, entity caller, float argc); void VoteHelp(entity e); string VoteNetname(entity e); string ValidateMap(string m, entity e); -- 2.39.2