about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlfred Eriksson <somerunce@gmail.com>2009-01-12 19:35:38 +0000
committerAlfred Eriksson <somerunce@gmail.com>2009-01-12 19:35:38 +0000
commitefd0dbab25533b67c0b231767318e903faf61f3c (patch)
treedf1e02fdacd121658360539951fdfab52ea24f84
parent2693bfdaecae78af20b12daff0c3b4eb2888203c (diff)
downloadzcatch-efd0dbab25533b67c0b231767318e903faf61f3c.tar.gz
zcatch-efd0dbab25533b67c0b231767318e903faf61f3c.zip
added vote command on the server to enforce a vote. added sv_vote_kick_bantime to choose how long a user will be banned at votekick (0 for just kick) thanks to magnet and xara
-rw-r--r--src/game/server/gamecontext.cpp5
-rw-r--r--src/game/server/gamecontext.hpp7
-rw-r--r--src/game/server/hooks.cpp14
-rw-r--r--src/game/variables.hpp1
4 files changed, 25 insertions, 2 deletions
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp
index 087dd469..287fe767 100644
--- a/src/game/server/gamecontext.cpp
+++ b/src/game/server/gamecontext.cpp
@@ -236,6 +236,7 @@ void GAMECONTEXT::start_vote(const char *desc, const char *command)
 		return;
 
 	// reset votes
+	vote_enforce = VOTE_ENFORCE_UNKNOWN;
 	for(int i = 0; i < MAX_CLIENTS; i++)
 	{
 		if(players[i])
@@ -343,7 +344,7 @@ void GAMECONTEXT::tick()
 				}
 			}
 		
-			if(yes >= total/2+1)
+			if(vote_enforce == VOTE_ENFORCE_YES || yes >= total/2+1)
 			{
 				console_execute_line(vote_command);
 				end_vote();
@@ -352,7 +353,7 @@ void GAMECONTEXT::tick()
 				if(players[vote_creator])
 					players[vote_creator]->last_votecall = 0;
 			}
-			else if(time_get() > vote_closetime || no >= total/2+1 || yes+no == total)
+			else if(vote_enforce == VOTE_ENFORCE_NO || 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 e98593aa..bea087cb 100644
--- a/src/game/server/gamecontext.hpp
+++ b/src/game/server/gamecontext.hpp
@@ -57,6 +57,13 @@ public:
 	int64 vote_closetime;
 	char vote_description[512];
 	char vote_command[512];
+	int vote_enforce;
+	enum
+	{
+		VOTE_ENFORCE_UNKNOWN=0,
+		VOTE_ENFORCE_NO,
+		VOTE_ENFORCE_YES,
+	};
 
 	// helper functions
 	void create_damageind(vec2 p, float angle_mod, int amount);
diff --git a/src/game/server/hooks.cpp b/src/game/server/hooks.cpp
index 8ce2cf56..93ce3ae0 100644
--- a/src/game/server/hooks.cpp
+++ b/src/game/server/hooks.cpp
@@ -254,6 +254,10 @@ void mods_message(int msgtype, int client_id)
 			str_format(chatmsg, sizeof(chatmsg), "Vote called to kick '%s'", server_clientname(kick_id));
 			str_format(desc, sizeof(desc), "Kick '%s'", server_clientname(kick_id));
 			str_format(cmd, sizeof(cmd), "kick %d", kick_id);
+			if (!config.sv_vote_kick_bantime)
+				str_format(cmd, sizeof(cmd), "kick %d", kick_id);
+			else
+				str_format(cmd, sizeof(cmd), "ban %d %d", kick_id, config.sv_vote_kick_bantime);
 		}
 		
 		if(cmd[0])
@@ -480,6 +484,15 @@ static void con_addvote(void *result, void *user_data)
 	dbg_msg("server", "added option '%s'", option->command);
 }
 
+static void con_vote(void *result, void *user_data)
+{
+	if(str_comp_nocase(console_arg_string(result, 0), "yes") == 0)
+		game.vote_enforce = GAMECONTEXT::VOTE_ENFORCE_YES;
+	else if(str_comp_nocase(console_arg_string(result, 0), "no") == 0)
+		game.vote_enforce = GAMECONTEXT::VOTE_ENFORCE_NO;
+	dbg_msg("server", "forcing vote %s", console_arg_string(result, 0));
+}
+
 void mods_console_init()
 {
 	MACRO_REGISTER_COMMAND("tune", "si", con_tune_param, 0);
@@ -493,6 +506,7 @@ void mods_console_init()
 	MACRO_REGISTER_COMMAND("set_team", "ii", con_set_team, 0);
 
 	MACRO_REGISTER_COMMAND("addvote", "r", con_addvote, 0);
+	MACRO_REGISTER_COMMAND("vote", "r", con_vote, 0);
 }
 
 void mods_init()
diff --git a/src/game/variables.hpp b/src/game/variables.hpp
index ccde5a9e..19afc4a0 100644
--- a/src/game/variables.hpp
+++ b/src/game/variables.hpp
@@ -62,6 +62,7 @@ MACRO_CONFIG_INT(sv_teambalance_time, 1, 0, 1000, CFGFLAG_SERVER, "How many minu
 
 MACRO_CONFIG_INT(sv_vote_map, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to change map. (see sv_maplist)")
 MACRO_CONFIG_INT(sv_vote_kick, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to kick players")
+MACRO_CONFIG_INT(sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time to ban a player if kicked by vote. 0 makes it just use kick")
 MACRO_CONFIG_INT(sv_vote_scorelimit, 0, 0, 1, CFGFLAG_SERVER, "Allow voting to change score limit")
 MACRO_CONFIG_INT(sv_vote_timelimit, 0, 0, 1, CFGFLAG_SERVER, "Allow voting to change time limit")