summaryrefslogtreecommitdiff
path: root/network.c
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-12-20 22:14:39 +0000
committerdominik <dominik@openttd.org>2004-12-20 22:14:39 +0000
commit7cfaa8a418cf5e04d66e3b4207b13a29db134145 (patch)
tree29c55a04aa27eeacd62949e6621a682a22dc3cc0 /network.c
parent3bbea05a93f922a7e3c98f5474748027032ef2a9 (diff)
downloadopenttd-7cfaa8a418cf5e04d66e3b4207b13a29db134145.tar.xz
(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.
Diffstat (limited to 'network.c')
-rw-r--r--network.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/network.c b/network.c
index 35061f7b5..5f885892a 100644
--- a/network.c
+++ b/network.c
@@ -774,24 +774,23 @@ static void NetworkInitialize(void)
NetworkUDPInitialize();
// add all servers from the config file to our list
- for (i=0; i != lengthof(_network_server_list); i++) {
- if (_network_server_list[i] == NULL) break;
- NetworkAddServer(_network_server_list[i]);
+ for (i=0; i != lengthof(_network_host_list); i++) {
+ if (_network_host_list[i] == NULL) break;
+ NetworkAddServer(_network_host_list[i]);
}
}
// Query a server to fetch his game-info
// If game_info is true, only the gameinfo is fetched,
// else only the client_info is fetched
-void NetworkQueryServer(const byte* host, unsigned short port, bool game_info)
+NetworkGameList *NetworkQueryServer(const byte* host, unsigned short port, bool game_info)
{
- if (!_network_available) return;
+ if (!_network_available) return NULL;
NetworkDisconnect();
if (game_info) {
- NetworkUDPQueryServer(host, port);
- return;
+ return NetworkUDPQueryServer(host, port);
}
NetworkInitialize();
@@ -807,18 +806,22 @@ void NetworkQueryServer(const byte* host, unsigned short port, bool game_info)
// We are connected
if (_networking) {
SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO)();
- return;
+ return NULL;
}
// No networking, close everything down again
NetworkDisconnect();
+ return NULL;
}
-// validates an address entered as a string and adds the server to
-// the list
+/* Validates an address entered as a string and adds the server to
+ * the list. If you use this functions, the games will be marked
+ * as manually added. */
void NetworkAddServer(const byte *b)
{
if (*b != '\0') {
+ NetworkGameList *item;
+ uint i;
const byte *port = NULL;
const byte *player = NULL;
byte host[NETWORK_HOSTNAME_LENGTH];
@@ -834,7 +837,26 @@ void NetworkAddServer(const byte *b)
if (player != NULL) _network_playas = atoi(player);
if (port != NULL) rport = atoi(port);
- NetworkQueryServer(host, rport, true);
+ item = NetworkQueryServer(host, rport, true);
+ item->manually = true;
+ }
+}
+
+/* Generates the list of manually added hosts from NetworkGameList and
+ * dumps them into the array _network_host_list. This array is needed
+ * by the function that generates the config file. */
+void NetworkRebuildHostList()
+{
+ int i=0;
+ NetworkGameList *item = _network_game_list;
+ while (item != NULL && i!=lengthof(_network_host_list)) {
+ if (item->manually)
+ _network_host_list[i++] = strdup(item->info.hostname);
+ item = item->next;
+ }
+
+ for (; i<lengthof(_network_host_list); i++) {
+ _network_host_list[i] = strdup("");
}
}