about summary refs log tree commit diff
diff options
context:
space:
mode:
authorscosu <scosu@gmx.de>2008-10-21 17:26:32 +0000
committerscosu <scosu@gmx.de>2008-10-21 17:26:32 +0000
commit37abbcbd2863f103d6a506490fb8bb3d4d7fff68 (patch)
tree76ac0602e5ad6ca66df59d71578ca8f6568aadb4
parent1e961fdece03e1002ea286aade6626c1272456f3 (diff)
downloadzcatch-37abbcbd2863f103d6a506490fb8bb3d4d7fff68.tar.gz
zcatch-37abbcbd2863f103d6a506490fb8bb3d4d7fff68.zip
If the player who should be kicked by a vote leaves the game, the vote is aborted. ticket 523
-rw-r--r--src/game/server/gamecontext.cpp60
-rw-r--r--src/game/server/gamecontext.hpp1
-rw-r--r--src/game/server/hooks.cpp1
3 files changed, 40 insertions, 22 deletions
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp
index c4b956ad..8c4b634a 100644
--- a/src/game/server/gamecontext.cpp
+++ b/src/game/server/gamecontext.cpp
@@ -1,3 +1,4 @@
+#include <string.h>
 #include <new>
 #include <engine/e_server_interface.h>
 #include "gamecontext.hpp"
@@ -285,6 +286,12 @@ void GAMECONTEXT::send_vote_status(int cid)
 	
 }
 
+void GAMECONTEXT::abort_vote_kick_on_disconnect(int client_id)
+{
+	if(vote_closetime && !strncmp(vote_command, "kick ", 5) && atoi(&vote_command[5]) == client_id)
+		vote_closetime = -1;
+}
+
 void GAMECONTEXT::tick()
 {
 	world.core.tuning = tuning;
@@ -302,33 +309,42 @@ void GAMECONTEXT::tick()
 	// update voting
 	if(vote_closetime)
 	{
-		// count votes
-		int total = 0, yes = 0, no = 0;
-		for(int i = 0; i < MAX_CLIENTS; i++)
+		// abort the kick-vote on player-leave
+		if(vote_closetime == -1)
 		{
-			if(players[i])
+			send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote aborted");
+			end_vote();
+		}
+		else
+		{
+			// count votes
+			int total = 0, yes = 0, no = 0;
+			for(int i = 0; i < MAX_CLIENTS; i++)
 			{
-				total++;
-				if(players[i]->vote > 0)
-					yes++;
-				else if(players[i]->vote < 0)
-					no++;
+				if(players[i])
+				{
+					total++;
+					if(players[i]->vote > 0)
+						yes++;
+					else if(players[i]->vote < 0)
+						no++;
+				}
 			}
-		}
 		
-		if(yes >= total/2+1)
-		{
-			console_execute_line(vote_command);
-			end_vote();
-			send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote passed");
+			if(yes >= total/2+1)
+			{
+				console_execute_line(vote_command);
+				end_vote();
+				send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote passed");
 			
-			if(players[vote_creator])
-				players[vote_creator]->last_votecall = 0;
-		}
-		else if(time_get() > vote_closetime || no >= total/2+1 || yes+no == total)
-		{
-			end_vote();
-			send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote failed");
+				if(players[vote_creator])
+					players[vote_creator]->last_votecall = 0;
+			}
+			else if(time_get() > vote_closetime || no >= total/2+1 || yes+no == total)
+			{
+				end_vote();
+				send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote failed");
+			}
 		}
 	}
 }
diff --git a/src/game/server/gamecontext.hpp b/src/game/server/gamecontext.hpp
index 1c4571eb..90559d26 100644
--- a/src/game/server/gamecontext.hpp
+++ b/src/game/server/gamecontext.hpp
@@ -52,6 +52,7 @@ public:
 	void end_vote();
 	void send_vote_set(int cid);
 	void send_vote_status(int cid);
+	void abort_vote_kick_on_disconnect(int client_id);
 	int vote_creator;
 	int64 vote_closetime;
 	char vote_description[512];
diff --git a/src/game/server/hooks.cpp b/src/game/server/hooks.cpp
index 077315dd..bc264f70 100644
--- a/src/game/server/hooks.cpp
+++ b/src/game/server/hooks.cpp
@@ -112,6 +112,7 @@ void mods_connected(int client_id)
 
 void mods_client_drop(int client_id)
 {
+	game.abort_vote_kick_on_disconnect(client_id);
 	game.players[client_id]->on_disconnect();
 	delete game.players[client_id];
 	game.players[client_id] = 0;