summaryrefslogtreecommitdiff
path: root/network.c
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-12-18 18:58:03 +0000
committerdominik <dominik@openttd.org>2004-12-18 18:58:03 +0000
commit88a8fa010486ce251273b5ea94197310a6a1ea3c (patch)
tree5e845319d36cb833763f462a08f7be2e4c008118 /network.c
parente33a63ee8dd27aa59df6f5374dfeb677096e547e (diff)
downloadopenttd-88a8fa010486ce251273b5ea94197310a6a1ea3c.tar.xz
(svn r1162) The server list can now be automatically filled from the config file. Add a section [servers] with the addresses each in a new line. Those will be checked upon OpenTTD startup.
Diffstat (limited to 'network.c')
-rw-r--r--network.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/network.c b/network.c
index c8b36eb65..bbee653ba 100644
--- a/network.c
+++ b/network.c
@@ -707,6 +707,7 @@ void NetworkClose(void)
void NetworkInitialize(void)
{
ClientState *cs;
+ uint i;
_local_command_queue = NULL;
@@ -730,6 +731,12 @@ void NetworkInitialize(void)
InitPlayerRandoms();
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;
+ AddServer(_network_server_list[i]);
+ }
}
// Query a server to fetch his game-info
@@ -766,6 +773,27 @@ void NetworkQueryServer(const byte* host, unsigned short port, bool game_info)
NetworkDisconnect();
}
+// validates an address entered as a string and adds the server to
+// the list
+void AddServer(byte *b)
+{
+ if (*b != '\0') {
+ const byte *port = NULL;
+ const byte *player = NULL;
+ uint16 rport;
+
+ ttd_strlcpy(_network_default_ip, b, lengthof(_network_default_ip));
+ rport = NETWORK_DEFAULT_PORT;
+
+ ParseConnectionString(&player, &port, b);
+
+ if (player != NULL) _network_playas = atoi(player);
+ if (port != NULL) rport = atoi(port);
+
+ NetworkQueryServer(b, rport, true);
+ }
+}
+
// Used by clients, to connect to a server
bool NetworkClientConnectGame(const byte* host, unsigned short port)
{