about summary refs log tree commit diff
path: root/src/game/client/components/voting.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-11-08 12:50:46 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-11-08 12:50:46 +0000
commit388a04d957a0fd9af9287cbe6f1ee905371886c7 (patch)
treea493826c21bfca82dbd7b122d859025e0693c62e /src/game/client/components/voting.cpp
parent4fa7806009ec4b6acfbf545e56d22e87ea5fa3f2 (diff)
downloadzcatch-388a04d957a0fd9af9287cbe6f1ee905371886c7.tar.gz
zcatch-388a04d957a0fd9af9287cbe6f1ee905371886c7.zip
better voting support
Diffstat (limited to 'src/game/client/components/voting.cpp')
-rw-r--r--src/game/client/components/voting.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp
index 7411e2ca..f267542b 100644
--- a/src/game/client/components/voting.cpp
+++ b/src/game/client/components/voting.cpp
@@ -36,9 +36,20 @@ void VOTING::callvote_kick(int client_id)
 	callvote("kick", buf);
 }
 
-void VOTING::callvote_map(const char *map)
+void VOTING::callvote_option(int option_id)
 {
-	callvote("map", map);
+	VOTEOPTION *option = this->first;
+	while(option && option_id >= 0)
+	{
+		if(option_id == 0)
+		{
+			callvote("option", option->command);
+			break;
+		}
+		
+		option_id--;
+		option = option->next;
+	}
 }
 
 void VOTING::vote(int v)
@@ -50,9 +61,22 @@ void VOTING::vote(int v)
 
 VOTING::VOTING()
 {
+	heap = 0;
+	clearoptions();
 	on_reset();
 }
 
+
+void VOTING::clearoptions()
+{
+	if(heap)
+		memheap_destroy(heap);
+	heap = memheap_create();
+	
+	first = 0;
+	last = 0;
+}
+
 void VOTING::on_reset()
 {
 	closetime = 0;
@@ -91,6 +115,27 @@ void VOTING::on_message(int msgtype, void *rawmsg)
 		pass = msg->pass;
 		total = msg->total;
 	}	
+	else if(msgtype == NETMSGTYPE_SV_VOTE_CLEAROPTIONS)
+	{
+		clearoptions();
+	}
+	else if(msgtype == NETMSGTYPE_SV_VOTE_OPTION)
+	{
+		NETMSG_SV_VOTE_OPTION *msg = (NETMSG_SV_VOTE_OPTION *)rawmsg;
+		int len = str_length(msg->command);
+	
+		VOTEOPTION *option = (VOTEOPTION *)memheap_allocate(heap, sizeof(VOTEOPTION) + len);
+		option->next = 0;
+		option->prev = last;
+		if(option->prev)
+			option->prev->next = option;
+		last = option;
+		if(!first)
+			first = option;
+		
+		mem_copy(option->command, msg->command, len+1);
+
+	}
 }
 
 void VOTING::on_render()