If the player who should be kicked by a vote leaves the game, the vote is aborted. ticket 523

This commit is contained in:
scosu 2008-10-21 17:26:32 +00:00
parent 1e961fdece
commit 37abbcbd28
3 changed files with 40 additions and 22 deletions

View file

@ -1,3 +1,4 @@
#include <string.h>
#include <new> #include <new>
#include <engine/e_server_interface.h> #include <engine/e_server_interface.h>
#include "gamecontext.hpp" #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() void GAMECONTEXT::tick()
{ {
world.core.tuning = tuning; world.core.tuning = tuning;
@ -302,33 +309,42 @@ void GAMECONTEXT::tick()
// update voting // update voting
if(vote_closetime) if(vote_closetime)
{ {
// count votes // abort the kick-vote on player-leave
int total = 0, yes = 0, no = 0; if(vote_closetime == -1)
for(int i = 0; i < MAX_CLIENTS; i++)
{ {
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])
if(players[i]->vote > 0) {
yes++; total++;
else if(players[i]->vote < 0) if(players[i]->vote > 0)
no++; yes++;
else if(players[i]->vote < 0)
no++;
}
} }
}
if(yes >= total/2+1) if(yes >= total/2+1)
{ {
console_execute_line(vote_command); console_execute_line(vote_command);
end_vote(); end_vote();
send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote passed"); send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote passed");
if(players[vote_creator]) if(players[vote_creator])
players[vote_creator]->last_votecall = 0; players[vote_creator]->last_votecall = 0;
} }
else if(time_get() > vote_closetime || no >= total/2+1 || yes+no == total) else if(time_get() > vote_closetime || no >= total/2+1 || yes+no == total)
{ {
end_vote(); end_vote();
send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote failed"); send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote failed");
}
} }
} }
} }

View file

@ -52,6 +52,7 @@ public:
void end_vote(); void end_vote();
void send_vote_set(int cid); void send_vote_set(int cid);
void send_vote_status(int cid); void send_vote_status(int cid);
void abort_vote_kick_on_disconnect(int client_id);
int vote_creator; int vote_creator;
int64 vote_closetime; int64 vote_closetime;
char vote_description[512]; char vote_description[512];

View file

@ -112,6 +112,7 @@ void mods_connected(int client_id)
void mods_client_drop(int client_id) void mods_client_drop(int client_id)
{ {
game.abort_vote_kick_on_disconnect(client_id);
game.players[client_id]->on_disconnect(); game.players[client_id]->on_disconnect();
delete game.players[client_id]; delete game.players[client_id];
game.players[client_id] = 0; game.players[client_id] = 0;