summaryrefslogtreecommitdiff
path: root/network_gamelist.c
blob: a90b50aaacaca82ba09482c9dd32a375be05b3cc (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* $Id$ */

#include "stdafx.h"
#include "debug.h"
#include "network_data.h"

#ifdef ENABLE_NETWORK

//
// This file handles the GameList
// Also, it handles the request to a server for data about the server

extern void UpdateNetworkGameWindow(bool unselect);


NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
{
	NetworkGameList *item, *prev_item;

	prev_item = NULL;
	for (item = _network_game_list; item != NULL; item = item->next) {
		if (item->ip == ip && item->port == port) return item;
		prev_item = item;
	}

	item = malloc(sizeof(*item));
	memset(item, 0, sizeof(*item));
	item->next = NULL;
	item->ip = ip;
	item->port = port;

	if (prev_item == NULL) {_network_game_list = item;}
	else {prev_item->next = item;}
	DEBUG(net, 4) ("[NET][GameList] Added server to list");

	UpdateNetworkGameWindow(false);

	return item;
}

void NetworkGameListRemoveItem(NetworkGameList *remove)
{
	NetworkGameList *item, *prev_item;

	prev_item = NULL;
	for (item = _network_game_list; item != NULL; item = item->next) {
		if (remove == item) {
			if (prev_item == NULL) {_network_game_list = remove->next;}
			else {prev_item->next = remove->next;}

			free(remove);
			DEBUG(net, 4) ("[NET][GameList] Removed server from list");
			UpdateNetworkGameWindow(false);
			return;
		}
		prev_item = item;
	}
}

#endif /* ENABLE_NETWORK */