author | celestar |
Mon, 15 Jan 2007 20:14:06 +0000 | |
branch | custombridgeheads |
changeset 5650 | aefc131bf5ce |
parent 5649 | 55c8267c933f |
permissions | -rw-r--r-- |
5642 | 1 |
/* $Id$ */ |
2 |
||
3 |
#ifdef ENABLE_NETWORK |
|
4 |
||
5 |
#include "../stdafx.h" |
|
6 |
#include "../debug.h" |
|
7 |
#include "network_data.h" |
|
8 |
#include "../newgrf_config.h" |
|
5650
aefc131bf5ce
(svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents:
5649
diff
changeset
|
9 |
#include "../helpers.hpp" |
5642 | 10 |
|
11 |
// This file handles the GameList |
|
12 |
// Also, it handles the request to a server for data about the server |
|
13 |
||
14 |
/** Add a new item to the linked gamelist. If the IP and Port match |
|
15 |
* return the existing item instead of adding it again |
|
16 |
* @param ip the IP-address (inet_addr) of the to-be added item |
|
17 |
* @param port the port the server is running on |
|
18 |
* @return a point to the newly added or already existing item */ |
|
19 |
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port) |
|
20 |
{ |
|
21 |
NetworkGameList *item, *prev_item; |
|
22 |
||
23 |
prev_item = NULL; |
|
24 |
for (item = _network_game_list; item != NULL; item = item->next) { |
|
25 |
if (item->ip == ip && item->port == port) return item; |
|
26 |
prev_item = item; |
|
27 |
} |
|
28 |
||
5650
aefc131bf5ce
(svn r8149) [cbh] - Sync with -r8038:8038 from trunk (the cpp merge)
celestar
parents:
5649
diff
changeset
|
29 |
MallocT(&item, 1); |
5642 | 30 |
memset(item, 0, sizeof(*item)); |
31 |
item->next = NULL; |
|
32 |
item->ip = ip; |
|
33 |
item->port = port; |
|
34 |
||
35 |
if (prev_item == NULL) { |
|
36 |
_network_game_list = item; |
|
37 |
} else { |
|
38 |
prev_item->next = item; |
|
39 |
} |
|
40 |
DEBUG(net, 4, "[gamelist] added server to list"); |
|
41 |
||
42 |
UpdateNetworkGameWindow(false); |
|
43 |
||
44 |
return item; |
|
45 |
} |
|
46 |
||
47 |
/** Remove an item from the gamelist linked list |
|
48 |
* @param remove pointer to the item to be removed */ |
|
49 |
void NetworkGameListRemoveItem(NetworkGameList *remove) |
|
50 |
{ |
|
51 |
NetworkGameList *item, *prev_item; |
|
52 |
||
53 |
prev_item = NULL; |
|
54 |
for (item = _network_game_list; item != NULL; item = item->next) { |
|
55 |
if (remove == item) { |
|
56 |
if (prev_item == NULL) { |
|
57 |
_network_game_list = remove->next; |
|
58 |
} else { |
|
59 |
prev_item->next = remove->next; |
|
60 |
} |
|
61 |
||
62 |
/* Remove GRFConfig information */ |
|
63 |
ClearGRFConfigList(&remove->info.grfconfig); |
|
64 |
free(remove); |
|
65 |
remove = NULL; |
|
66 |
||
67 |
DEBUG(net, 4, "[gamelist] removed server from list"); |
|
68 |
UpdateNetworkGameWindow(false); |
|
69 |
return; |
|
70 |
} |
|
71 |
prev_item = item; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
#endif /* ENABLE_NETWORK */ |