diff options
author | Simon Howard | 2010-12-07 22:35:17 +0000 |
---|---|---|
committer | Simon Howard | 2010-12-07 22:35:17 +0000 |
commit | 6727d54e95153c083acbba5ab77f1f9bce92b331 (patch) | |
tree | 234db6650cede94e0beda5cc2742b9d2b9307612 /src/net_server.c | |
parent | e4025e0a6a5e648ff59dd23973c5e7076a07eaa6 (diff) | |
download | chocolate-doom-6727d54e95153c083acbba5ab77f1f9bce92b331.tar.gz chocolate-doom-6727d54e95153c083acbba5ab77f1f9bce92b331.tar.bz2 chocolate-doom-6727d54e95153c083acbba5ab77f1f9bce92b331.zip |
Assign the oldest client to be the controller, not the first found in
the clients[] array.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2201
Diffstat (limited to 'src/net_server.c')
-rw-r--r-- | src/net_server.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/net_server.c b/src/net_server.c index 43584170..4307e2e2 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -69,6 +69,11 @@ typedef struct int last_send_time; char *name; + // Time that this client connected to the server. + // This is used to determine the controller (oldest client). + + unsigned int connect_time; + // Last time new gamedata was received from this client int last_gamedata_time; @@ -381,19 +386,29 @@ static void NET_SV_AdvanceWindow(void) static net_client_t *NET_SV_Controller(void) { + net_client_t *best; int i; - // first client in the list is the controller + // Find the oldest client (first to connect). + + best = NULL; for (i=0; i<MAXNETNODES; ++i) { - if (ClientConnected(&clients[i]) && !clients[i].drone) + // Can't be controller? + + if (!ClientConnected(&clients[i]) || clients[i].drone) { - return &clients[i]; + continue; + } + + if (best == NULL || clients[i].connect_time < best->connect_time) + { + best = &clients[i]; } } - return NULL; + return best; } // Given an address, find the corresponding client @@ -433,6 +448,7 @@ static void NET_SV_InitNewClient(net_client_t *client, char *player_name) { client->active = true; + client->connect_time = I_GetTimeMS(); NET_Conn_InitServer(&client->connection, addr); client->addr = addr; client->last_send_time = -1; |