author | rubidium |
Wed, 10 Jan 2007 18:56:51 +0000 | |
changeset 5838 | 9c3129cb019b |
parent 5835 | e0ff603ae0b7 |
child 5860 | 7fdc9b423ba1 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
4826
63b1eb7c966b
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4077
diff
changeset
|
3 |
#ifdef ENABLE_NETWORK |
63b1eb7c966b
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4077
diff
changeset
|
4 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
5 |
#include "../stdafx.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
6 |
#include "../debug.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
7 |
#include "network_data.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
8 |
#include "../newgrf_config.h" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
9 |
#include "../helpers.hpp" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
10 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
11 |
// This file handles the GameList |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
12 |
// Also, it handles the request to a server for data about the server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
13 |
|
2885
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
14 |
/** Add a new item to the linked gamelist. If the IP and Port match |
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
15 |
* return the existing item instead of adding it again |
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
16 |
* @param ip the IP-address (inet_addr) of the to-be added item |
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
17 |
* @param port the port the server is running on |
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
18 |
* @return a point to the newly added or already existing item */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
19 |
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
20 |
{ |
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
21 |
NetworkGameList *item, *prev_item; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
22 |
|
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
23 |
prev_item = NULL; |
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
24 |
for (item = _network_game_list; item != NULL; item = item->next) { |
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
25 |
if (item->ip == ip && item->port == port) return item; |
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
26 |
prev_item = item; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
27 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
28 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
29 |
MallocT(&item, 1); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
30 |
memset(item, 0, sizeof(*item)); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
31 |
item->next = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
32 |
item->ip = ip; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
33 |
item->port = port; |
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
34 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
35 |
if (prev_item == NULL) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
36 |
_network_game_list = item; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
37 |
} else { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
38 |
prev_item->next = item; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
39 |
} |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5347
diff
changeset
|
40 |
DEBUG(net, 4, "[gamelist] added server to list"); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
41 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
42 |
UpdateNetworkGameWindow(false); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
43 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
44 |
return item; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
45 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
46 |
|
2885
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
47 |
/** Remove an item from the gamelist linked list |
c06f2f3985a0
(svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents:
2881
diff
changeset
|
48 |
* @param remove pointer to the item to be removed */ |
738
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
49 |
void NetworkGameListRemoveItem(NetworkGameList *remove) |
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
50 |
{ |
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
51 |
NetworkGameList *item, *prev_item; |
738
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
52 |
|
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
53 |
prev_item = NULL; |
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
54 |
for (item = _network_game_list; item != NULL; item = item->next) { |
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
55 |
if (remove == item) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
56 |
if (prev_item == NULL) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
57 |
_network_game_list = remove->next; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
58 |
} else { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
59 |
prev_item->next = remove->next; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
2885
diff
changeset
|
60 |
} |
738
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
61 |
|
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
62 |
/* Remove GRFConfig information */ |
5347
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5339
diff
changeset
|
63 |
ClearGRFConfigList(&remove->info.grfconfig); |
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5339
diff
changeset
|
64 |
free(remove); |
18836f961808
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5339
diff
changeset
|
65 |
remove = NULL; |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
66 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5347
diff
changeset
|
67 |
DEBUG(net, 4, "[gamelist] removed server from list"); |
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
68 |
UpdateNetworkGameWindow(false); |
738
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
69 |
return; |
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
70 |
} |
2881
1ffbbdbf1685
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents:
2186
diff
changeset
|
71 |
prev_item = item; |
738
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
72 |
} |
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
73 |
} |
0b2fb79e64fc
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
74 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
75 |
#endif /* ENABLE_NETWORK */ |