From: z411 <z411@omaera.org>
Date: Thu, 15 Oct 2020 00:58:29 +0000 (-0300)
Subject: Team votes
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=db450463cafd0179a3ec1a4e2d95d90fdc73bef4;p=xonotic%2Fxonotic-data.pk3dir.git

Team votes
---

diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc
index b1d77fcabe..18e51fcb89 100644
--- a/qcsrc/server/client.qc
+++ b/qcsrc/server/client.qc
@@ -106,7 +106,6 @@ void send_CSQC_teamnagger() {
 void send_TeamNames(int channel, entity to) {
 	msg_entity = to;
 	
-	LOG_INFOF("Sending team names");
 	WriteHeader(channel, TE_CSQC_TEAMNAMES);
 	WriteString(channel, autocvar_g_teamnames_red);
 	WriteString(channel, autocvar_g_teamnames_blue);
diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc
index e6fad18c87..7a3ca3c76f 100644
--- a/qcsrc/server/command/sv_cmd.qc
+++ b/qcsrc/server/command/sv_cmd.qc
@@ -160,17 +160,52 @@ void GameCommand_adminmsg(int request, int argc)
 	}
 }
 
-void GameCommand_sendteams(int request)
+void GameCommand_team_name(int request, int argc)
 {
 	switch (request)
 	{
 		case CMD_REQUEST_COMMAND:
 		{
+			if (argv(1) == "")
+			{
+				return;
+			}
+			if (!teamplay)
+			{
+				LOG_INFO("selectteam can only be used in teamgames");
+				return;
+			}
+			
+			switch (argv(1))
+			{
+				case "red":
+				case "blue":
+				case "yellow":
+				case "pink":
+				{
+					if(argv(2) != "") {
+						cvar_set(strcat("g_teamnames_", argv(1)), argv(2));
+						int tm = Team_ColorToTeam(argv(1));
+						bprintf("\{1}%s%s^7 team is now known as %s^7\n", Team_ColorCode(tm), Team_ColorName(tm), argv(2));
+					} else {
+						cvar_set(strcat("g_teamnames_", argv(1)), "");
+						bprintf("\{1}%s%s^7 team now doesn't have a team name\n", Team_ColorCode(tm), Team_ColorName(tm), argv(2));
+					}
+					
+					break;
+				}
+				default:
+				{
+					return;
+				}
+			}
+			
 			send_TeamNames(MSG_BROADCAST, NULL);
 			return;
 		}
 
 		default:
+			LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
 		case CMD_REQUEST_USAGE:
 		{
 			LOG_HELP("Usage:^3 sv_cmd sendteams");
@@ -179,6 +214,7 @@ void GameCommand_sendteams(int request)
 		}
 	}
 }
+
 void GameCommand_allready(int request)
 {
 	switch (request)
@@ -1643,8 +1679,9 @@ void GameCommand_(int request)
 // ==================================
 
 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
+SERVER_COMMAND(team_name, "Set team name") { GameCommand_team_name(request, arguments); }
+
 SERVER_COMMAND(adminmsg, "Send an admin message to a client directly") { GameCommand_adminmsg(request, arguments); }
-SERVER_COMMAND(sendteams, "Send team names") { GameCommand_sendteams(request); }
 SERVER_COMMAND(allready, "Restart the server and reset the players") { GameCommand_allready(request); }
 SERVER_COMMAND(allspec, "Force all players to spectate") { GameCommand_allspec(request, arguments); }
 SERVER_COMMAND(anticheat, "Create an anticheat report for a client") { GameCommand_anticheat(request, arguments); }
diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc
index 8e49a653d6..8a05c1b95c 100644
--- a/qcsrc/server/command/vote.qc
+++ b/qcsrc/server/command/vote.qc
@@ -221,6 +221,10 @@ void VoteCount(float first_count)
 
 	// add up all the votes from each connected client
 	FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_CLIENT(it), {
+		// z411
+		if(vote_target_type == VOTE_TARGET_TEAM && it.team != vote_caller.team) continue;
+		if(vote_target_type == VOTE_TARGET_SINGLE && it != vote_target) continue;
+		
 		++vote_player_count;
 		if (IS_PLAYER(it))   ++vote_real_player_count;
 		switch (it.vote_selection)
@@ -689,6 +693,8 @@ int VoteCommand_parse(entity caller, string vote_command, string vote_list, floa
 		case MUT_VOTEPARSE_UNACCEPTABLE: { return 0; }
 	}
 
+	vote_target_type = VOTE_TARGET_ALL;
+	
 	switch (first_command) // now go through and parse the proper commands to adjust as needed.
 	{
 		case "kick":
@@ -707,7 +713,7 @@ int VoteCommand_parse(entity caller, string vote_command, string vote_list, floa
 				if (first_command == "kickban")
 					command_arguments = strcat(ftos(autocvar_g_ban_default_bantime), " ", ftos(autocvar_g_ban_default_masksize), " ~");
 
-				vote_parsed_command = strcat(first_command, " # ", ftos(etof(victim)), " ", command_arguments);
+				vote_parsed_command = strcat("defer 2 ", first_command, " # ", ftos(etof(victim)), " ", command_arguments);
 				vote_parsed_display = sprintf("^1%s #%d ^7%s^1 %s", first_command, etof(victim), victim.netname, reason);
 			}
 			else { print_to(caller, strcat("vcall: ", GetClientErrorString(accepted, argv(startpos + 1)), ".\n")); return 0; }
@@ -721,11 +727,27 @@ int VoteCommand_parse(entity caller, string vote_command, string vote_list, floa
 		{
 			vote_command = ValidateMap(argv(startpos + 1), caller);
 			if (!vote_command)  return -1;
-			vote_parsed_command = strcat("gotomap ", vote_command);
+			vote_parsed_command = strcat("defer 2 gotomap ", vote_command);
 			vote_parsed_display = strzone(strcat("^1", vote_parsed_command));
 
 			break;
 		}
+		
+		// z411 team calls
+		case "team_name":
+		{
+			if (teamplay && Team_IsValidTeam(caller.team)) {
+				vote_target_type = VOTE_TARGET_TEAM;
+			
+				string tmname = strtolower(Static_Team_ColorName(caller.team));
+				string newname = argv(startpos + 1);
+				
+				vote_parsed_command = strcat(first_command, " ", tmname, " \"", newname, "\"");
+				vote_parsed_display = strzone(strcat("^3(Team) ^1", first_command, " ^2", newname));
+			} else { print_to(caller, "vcall: Not in a team\n"); return 0; }
+			
+			break;
+		}
 
 		// TODO: replicate the old behaviour of being able to vote for maps from different modes on multimode servers (possibly support it in gotomap too)
 		// maybe fallback instead of aborting if map name is invalid?
@@ -755,10 +777,12 @@ int VoteCommand_parse(entity caller, string vote_command, string vote_list, floa
 		}
 
 		case "restart":
+		case "shuffleteams":
+		case "endmatch":
 		{
 			// add a delay so that vote result can be seen and announcer can be heard
 			// if the vote is accepted
-			vote_parsed_command = strcat("defer 1 ", vote_command);
+			vote_parsed_command = strcat("defer 2 ", vote_command);
 			vote_parsed_display = strzone(strcat("^1", vote_command));
 
 			break;
diff --git a/qcsrc/server/command/vote.qh b/qcsrc/server/command/vote.qh
index 7085ca0e1b..6c4d30d171 100644
--- a/qcsrc/server/command/vote.qh
+++ b/qcsrc/server/command/vote.qh
@@ -21,6 +21,11 @@ const float VOTE_NULL = 0;
 const float VOTE_NORMAL = 1;
 const float VOTE_MASTER = 2;
 
+// z411 vote targets
+const float VOTE_TARGET_ALL = 0;
+const float VOTE_TARGET_TEAM = 1;
+const float VOTE_TARGET_SINGLE = 2;
+
 // global vote information declarations
 entity vote_caller;         // original caller of the current vote
 string vote_caller_name;    // name of the vote caller
@@ -30,6 +35,8 @@ float vote_accept_count;    // total amount of players who accept the vote (coun
 float vote_reject_count;    // same as above, but rejected
 float vote_abstain_count;   // same as above, but abstained
 float vote_needed_overall;  // total amount of players NEEDED for a vote to pass (based on sv_vote_majority_factor)
+float vote_target_type; // z411
+entity vote_target; // z411
 .float vote_master;         // flag for if the player has vote master privelages
 .float vote_waittime;       // flag for how long the player must wait before they can vote again
 .float vote_selection;      // flag for which vote selection the player has made (See VOTE_SELECT_*)