about summary refs log tree commit diff
path: root/src/game/client/components/maplist.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-09-29 11:34:49 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-09-29 11:34:49 +0000
commiteac9658b7395a45d0b48cad340fd9ccf7bec0fde (patch)
treed5bd824038a9b095dd8ea5d9ab4cca88ce1afb0f /src/game/client/components/maplist.cpp
parent6d44adb7114a0be6ecb1b0fabc6fe69d308cad1c (diff)
downloadzcatch-eac9658b7395a45d0b48cad340fd9ccf7bec0fde.tar.gz
zcatch-eac9658b7395a45d0b48cad340fd9ccf7bec0fde.zip
added voting gui and a lot of other minor changes
Diffstat (limited to 'src/game/client/components/maplist.cpp')
-rw-r--r--src/game/client/components/maplist.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/game/client/components/maplist.cpp b/src/game/client/components/maplist.cpp
new file mode 100644
index 00000000..027ec449
--- /dev/null
+++ b/src/game/client/components/maplist.cpp
@@ -0,0 +1,45 @@
+#include <engine/e_client_interface.h>
+#include <game/generated/g_protocol.hpp>
+
+#include "maplist.hpp"
+
+MAPLIST::MAPLIST()
+{
+	on_reset();
+}
+
+void MAPLIST::on_reset()
+{
+	buffer[0] = 0;
+	num_maps = 0;
+}
+
+static bool is_separator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; }
+
+void MAPLIST::on_message(int msgtype, void *rawmsg)
+{
+	if(msgtype == NETMSGTYPE_SV_MAPLIST)
+	{
+		NETMSG_SV_MAPLIST *msg = (NETMSG_SV_MAPLIST*)rawmsg;
+		str_copy(buffer, msg->names, sizeof(buffer));
+		
+		// parse list
+		num_maps = 0;
+		char *ptr = buffer;
+		while(*ptr)
+		{
+			while(*ptr && is_separator(*ptr))
+			{
+				*ptr = 0;
+				ptr++;
+			}
+
+			if(*ptr)
+			{
+				maps[num_maps++] = ptr;
+				while(*ptr && !is_separator(*ptr))
+					ptr++;
+			}
+		}
+	}
+}