summaryrefslogtreecommitdiff
path: root/network_gamelist.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-01-25 19:03:50 +0000
committerDarkvater <darkvater@openttd.org>2006-01-25 19:03:50 +0000
commit2b287a9e72c0b717f9d39915441a0d681611124b (patch)
tree75d7c397982c18c2480f8bf3c9c44629f76776f3 /network_gamelist.c
parent0d80c70b5f1d29ac2fc2145ec5720dfb001e8eba (diff)
downloadopenttd-2b287a9e72c0b717f9d39915441a0d681611124b.tar.xz
(svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Diffstat (limited to 'network_gamelist.c')
-rw-r--r--network_gamelist.c55
1 files changed, 18 insertions, 37 deletions
diff --git a/network_gamelist.c b/network_gamelist.c
index bff7166d1..a90b50aaa 100644
--- a/network_gamelist.c
+++ b/network_gamelist.c
@@ -15,34 +15,23 @@ extern void UpdateNetworkGameWindow(bool unselect);
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
{
- NetworkGameList *item;
+ NetworkGameList *item, *prev_item;
- item = _network_game_list;
- if (item != NULL) {
- while (item->next != NULL) {
- if (item->ip == ip && item->port == port)
- return item;
- item = item->next;
- }
-
- if (item->ip == ip && item->port == port)
- return item;
-
- item->next = malloc(sizeof(*item));
- item = item->next;
- } else {
- item = malloc(sizeof(*item));
- _network_game_list = 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;
}
- DEBUG(net, 4) ("[NET][GameList] Added server to list");
-
+ item = malloc(sizeof(*item));
memset(item, 0, sizeof(*item));
-
item->next = NULL;
item->ip = ip;
item->port = port;
- _network_game_count++;
+
+ if (prev_item == NULL) {_network_game_list = item;}
+ else {prev_item->next = item;}
+ DEBUG(net, 4) ("[NET][GameList] Added server to list");
UpdateNetworkGameWindow(false);
@@ -51,28 +40,20 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
void NetworkGameListRemoveItem(NetworkGameList *remove)
{
- NetworkGameList *item;
+ NetworkGameList *item, *prev_item;
- item = _network_game_list;
-
- // examine head of the list
- if ( remove == _network_game_list ) {
- _network_game_list = remove->next;
- free(remove);
- DEBUG(net, 4) ("[NET][GameList] Removed server from list");
- return;
- }
+ 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;}
- // examine each item
- while ( item->next != NULL ) {
- if ( item->next == remove )
- {
- item->next = remove->next;
free(remove);
DEBUG(net, 4) ("[NET][GameList] Removed server from list");
+ UpdateNetworkGameWindow(false);
return;
}
- item = item->next;
+ prev_item = item;
}
}