summaryrefslogtreecommitdiff
path: root/src/network/network_gamelist.c
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-01-02 19:19:48 +0000
committerrubidium <rubidium@openttd.org>2007-01-02 19:19:48 +0000
commit66bbf336c6af7353ef0aeed58002c46543b30635 (patch)
treead4a63860df2626b22f77e7dac712e958bea54cb /src/network/network_gamelist.c
parentccc0a3f4dbf58c005b22341ac8874252924690cd (diff)
downloadopenttd-66bbf336c6af7353ef0aeed58002c46543b30635.tar.xz
(svn r7759) -Merge: makefile rewrite. This merge features:
- A proper ./configure, so everything needs to be configured only once, not for every make. - Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies. - A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC. - Proper support for OSX universal binaries. - Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files. - Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files. Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy.
Diffstat (limited to 'src/network/network_gamelist.c')
-rw-r--r--src/network/network_gamelist.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/network/network_gamelist.c b/src/network/network_gamelist.c
new file mode 100644
index 000000000..a830073ad
--- /dev/null
+++ b/src/network/network_gamelist.c
@@ -0,0 +1,74 @@
+/* $Id$ */
+
+#ifdef ENABLE_NETWORK
+
+#include "../stdafx.h"
+#include "../debug.h"
+#include "network_data.h"
+#include "../newgrf_config.h"
+
+// This file handles the GameList
+// Also, it handles the request to a server for data about the server
+
+/** Add a new item to the linked gamelist. If the IP and Port match
+ * return the existing item instead of adding it again
+ * @param ip the IP-address (inet_addr) of the to-be added item
+ * @param port the port the server is running on
+ * @return a point to the newly added or already existing item */
+NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
+{
+ NetworkGameList *item, *prev_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;
+ }
+
+ item = malloc(sizeof(*item));
+ memset(item, 0, sizeof(*item));
+ item->next = NULL;
+ item->ip = ip;
+ item->port = port;
+
+ if (prev_item == NULL) {
+ _network_game_list = item;
+ } else {
+ prev_item->next = item;
+ }
+ DEBUG(net, 4, "[gamelist] added server to list");
+
+ UpdateNetworkGameWindow(false);
+
+ return item;
+}
+
+/** Remove an item from the gamelist linked list
+ * @param remove pointer to the item to be removed */
+void NetworkGameListRemoveItem(NetworkGameList *remove)
+{
+ NetworkGameList *item, *prev_item;
+
+ 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;
+ }
+
+ /* Remove GRFConfig information */
+ ClearGRFConfigList(&remove->info.grfconfig);
+ free(remove);
+ remove = NULL;
+
+ DEBUG(net, 4, "[gamelist] removed server from list");
+ UpdateNetworkGameWindow(false);
+ return;
+ }
+ prev_item = item;
+ }
+}
+
+#endif /* ENABLE_NETWORK */