From 37abbcbd2863f103d6a506490fb8bb3d4d7fff68 Mon Sep 17 00:00:00 2001 From: scosu Date: Tue, 21 Oct 2008 17:26:32 +0000 Subject: [PATCH] If the player who should be kicked by a vote leaves the game, the vote is aborted. ticket 523 --- src/game/server/gamecontext.cpp | 60 +++++++++++++++++++++------------ src/game/server/gamecontext.hpp | 1 + src/game/server/hooks.cpp | 1 + 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index c4b956adb..8c4b634a9 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1,3 +1,4 @@ +#include #include #include #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 1c4571ebd..90559d260 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 077315dd1..bc264f70f 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;