about summary refs log tree commit diff
path: root/src/game/client/components/maplist.cpp
blob: 027ec449002e74b0125b72a91525d92607b41f61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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++;
			}
		}
	}
}