network_gamelist.c
author rubidium
Mon, 01 Jan 2007 22:00:54 +0000
changeset 5462 ebb6fe93a23a
parent 5380 8ea58542b6e0
permissions -rw-r--r--
(svn r7731) -Fix (r5999): off-by-one error in the date to YMD calculation for first 4 years of a century that was not divisable by 400.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1299
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1299
diff changeset
     2
4826
6a545d194528 (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4077
diff changeset
     3
#ifdef ENABLE_NETWORK
6a545d194528 (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4077
diff changeset
     4
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1122
diff changeset
     6
#include "debug.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     7
#include "network_data.h"
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5034
diff changeset
     8
#include "newgrf_config.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     9
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    10
// This file handles the GameList
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    11
// Also, it handles the request to a server for data about the server
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    12
2885
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    13
/** Add a new item to the linked gamelist. If the IP and Port match
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    14
 * return the existing item instead of adding it again
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    15
 * @param ip the IP-address (inet_addr) of the to-be added item
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    16
 * @param port the port the server is running on
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    17
 * @return a point to the newly added or already existing item */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    18
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    19
{
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    20
	NetworkGameList *item, *prev_item;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    21
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    22
	prev_item = NULL;
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    23
	for (item = _network_game_list; item != NULL; item = item->next) {
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    24
		if (item->ip == ip && item->port == port) return item;
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    25
		prev_item = item;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    26
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    27
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    28
	item = malloc(sizeof(*item));
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    29
	memset(item, 0, sizeof(*item));
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    30
	item->next = NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    31
	item->ip = ip;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    32
	item->port = port;
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    33
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    34
	if (prev_item == NULL) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    35
		_network_game_list = item;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    36
	} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    37
		prev_item->next = item;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    38
	}
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5347
diff changeset
    39
	DEBUG(net, 4, "[gamelist] added server to list");
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    40
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    41
	UpdateNetworkGameWindow(false);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    42
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    43
	return item;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    44
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    45
2885
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    46
/** Remove an item from the gamelist linked list
fc5297214b36 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    47
 * @param remove pointer to the item to be removed */
738
b96ab9e63d22 (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
    48
void NetworkGameListRemoveItem(NetworkGameList *remove)
b96ab9e63d22 (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
{
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    50
	NetworkGameList *item, *prev_item;
738
b96ab9e63d22 (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
    51
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    52
	prev_item = NULL;
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    53
	for (item = _network_game_list; item != NULL; item = item->next) {
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    54
		if (remove == item) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    55
			if (prev_item == NULL) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    56
				_network_game_list = remove->next;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    57
			} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    58
				prev_item->next = remove->next;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 2885
diff changeset
    59
			}
738
b96ab9e63d22 (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
    60
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5034
diff changeset
    61
			/* Remove GRFConfig information */
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5339
diff changeset
    62
			ClearGRFConfigList(&remove->info.grfconfig);
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5339
diff changeset
    63
			free(remove);
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5339
diff changeset
    64
			remove = NULL;
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5034
diff changeset
    65
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5347
diff changeset
    66
			DEBUG(net, 4, "[gamelist] removed server from list");
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    67
			UpdateNetworkGameWindow(false);
738
b96ab9e63d22 (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
    68
			return;
b96ab9e63d22 (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
		}
2881
ade9a553be53 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    70
		prev_item = item;
738
b96ab9e63d22 (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
    71
	}
b96ab9e63d22 (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
}
b96ab9e63d22 (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
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    74
#endif /* ENABLE_NETWORK */