network_gamelist.c
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 2885 c06f2f3985a0
child 4077 d3022f976946
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 1299
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 1299
diff changeset
     2
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1122
diff changeset
     4
#include "debug.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     5
#include "network_data.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     6
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     7
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     8
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     9
//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    10
// This file handles the GameList
e3b43338096b (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
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    12
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    13
extern void UpdateNetworkGameWindow(bool unselect);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    14
2885
c06f2f3985a0 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    15
/** 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
    16
 * 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
    17
 * @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
    18
 * @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
    19
 * @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
    20
NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    21
{
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    22
	NetworkGameList *item, *prev_item;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    23
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    24
	prev_item = NULL;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    25
	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
    26
		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
    27
		prev_item = item;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    28
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    29
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    30
	item = malloc(sizeof(*item));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    31
	memset(item, 0, sizeof(*item));
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    32
	item->next = NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    33
	item->ip = ip;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    34
	item->port = port;
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    35
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    36
	if (prev_item == NULL) {_network_game_list = item;}
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    37
	else {prev_item->next = item;}
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    38
	DEBUG(net, 4) ("[NET][GameList] Added server to list");
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    39
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    40
	UpdateNetworkGameWindow(false);
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
	return item;
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
2885
c06f2f3985a0 (svn r3435) - Fix a warning, removed unused extern and some comments in network_gamelist.c
Darkvater
parents: 2881
diff changeset
    45
/** 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
    46
 * @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
    47
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
    48
{
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    49
	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
    50
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    51
	prev_item = NULL;
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    52
	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
    53
		if (remove == item) {
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    54
			if (prev_item == NULL) {_network_game_list = remove->next;}
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    55
			else {prev_item->next = remove->next;}
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
    56
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
    57
			free(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
    58
			DEBUG(net, 4) ("[NET][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
    59
			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
    60
			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
    61
		}
2881
1ffbbdbf1685 (svn r3429) - Feature (Followup): Change the gamelist window to accomodate for the new information.
Darkvater
parents: 2186
diff changeset
    62
		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
    63
	}
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
    64
}
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
    65
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    66
#endif /* ENABLE_NETWORK */