From: terencehill <piuntn@gmail.com>
Date: Sat, 4 Feb 2023 23:47:20 +0000 (+0100)
Subject: Count votes of eliminated players too if sv_vote_nospectators is active
X-Git-Tag: xonotic-v0.8.6~182
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8842c05be28a2479fca5cbc4e41e48a98015c943;p=xonotic%2Fxonotic-data.pk3dir.git

Count votes of eliminated players too if sv_vote_nospectators is active
---

diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc
index 10d1d3822..9095bb43a 100644
--- a/qcsrc/server/command/vote.qc
+++ b/qcsrc/server/command/vote.qc
@@ -219,23 +219,23 @@ void VoteCount(float first_count)
 	Nagger_VoteCountChanged();
 
 	// add up all the votes from each connected client
-	FOREACH_CLIENT(IS_REAL_CLIENT(it) && IS_CLIENT(it), {
+	FOREACH_CLIENT(IS_REAL_CLIENT(it), {
 		++vote_player_count;
-		if (IS_PLAYER(it))   ++vote_real_player_count;
+		if (IS_PLAYER(it) || INGAME(it)) ++vote_real_player_count;
 		switch (it.vote_selection)
 		{
 			case VOTE_SELECT_REJECT:
-			{ ++vote_reject_count;
-			  { if (IS_PLAYER(it)) ++vote_real_reject_count; } break;
-			}
+				++vote_reject_count;
+				if (IS_PLAYER(it) || INGAME(it)) ++vote_real_reject_count;
+				break;
 			case VOTE_SELECT_ACCEPT:
-			{ ++vote_accept_count;
-			  { if (IS_PLAYER(it)) ++vote_real_accept_count; } break;
-			}
+				++vote_accept_count;
+				if (IS_PLAYER(it) || INGAME(it)) ++vote_real_accept_count;
+				break;
 			case VOTE_SELECT_ABSTAIN:
-			{ ++vote_abstain_count;
-			  { if (IS_PLAYER(it)) ++vote_real_abstain_count; } break;
-			}
+				++vote_abstain_count;
+				if (IS_PLAYER(it) || INGAME(it)) ++vote_real_abstain_count;
+				break;
 			default: break;
 		}
 	});
@@ -877,6 +877,29 @@ void print_available_commands_to(entity caller)
 	print_to(caller, strcat("You can call a vote for or execute these commands: ^3", autocvar_sv_vote_commands, "^7 and maybe further ^3arguments^7"));
 }
 
+bool VoteCommand_checkclients()
+{
+	float c = 0, nc = 0;
+	FOREACH_CLIENT(true,
+	{
+		//if(!IS_DISCONNECTED_CLIENT(it)) c++;
+		if(!IS_BOT_CLIENT(it)) c++; // test code, counts bots as unconnected
+		else nc++;
+	});
+	LOG_INFOF("^x8f0 %d / %d\n", c, nc);
+	if (!nc)
+		return false;
+	// if true vote is not allowed
+	// connessi 2 non connessi 1  false   allowed
+	// connessi 3 non connessi 1  false   allowed
+	// connessi 2 non connessi 2  true  not allowed
+	// connessi 3 non connessi 2  true  not allowed
+	// connessi 5 non connessi 3  true  not allowed
+	// connessi 5 non connessi 2  false   allowed
+	// if the not connected are half or less
+	return (c < nc * 2);
+}
+
 void VoteCommand_call(int request, entity caller, int argc, string vote_command)  // BOTH
 {
 	switch (request)
@@ -896,6 +919,10 @@ void VoteCommand_call(int request, entity caller, int argc, string vote_command)
 			{
 				print_to(caller, "^1Vote calling is not allowed before the match has started.");
 			}
+			else if (time < 10) // test, change to 4 or somthing
+			{
+				print_to(caller, "^1Vote calling is not allowed in the very first seconds of the game.");
+			}
 			else if (vote_called)
 			{
 				print_to(caller, "^1There is already a vote called.");
@@ -904,6 +931,10 @@ void VoteCommand_call(int request, entity caller, int argc, string vote_command)
 			{
 				print_to(caller, "^1Only players can call a vote.");
 			}
+			else if (VoteCommand_checkclients())
+			{
+				print_to(caller, "^1Too many unconnected clients.");
+			}
 			else if (caller && !IS_CLIENT(caller))
 			{
 				print_to(caller, "^1Only connected clients can vote.");