summaryrefslogtreecommitdiff
path: root/network.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-01-31 22:16:15 +0000
committerDarkvater <darkvater@openttd.org>2006-01-31 22:16:15 +0000
commitf2448ebfd4324b0c914e36b81801fc1ffa04da94 (patch)
tree763ef198108c0320af48fbac22bf9c998430da2d /network.c
parent9d07426a29817fbaddcb8f8c726e16a32bb123d0 (diff)
downloadopenttd-f2448ebfd4324b0c914e36b81801fc1ffa04da94.tar.xz
(svn r3500) - Workaround the inaccurate count of spectators/companies that can happen in certain border-cases. For now just dynamically get this value when requested so it is always right. To do properly all player/client creation/destruction needs a hook for networking.
Diffstat (limited to 'network.c')
-rw-r--r--network.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/network.c b/network.c
index dfc47abae..b535e7a7a 100644
--- a/network.c
+++ b/network.c
@@ -103,6 +103,18 @@ void NetworkGetClientName(char *client_name, size_t size, const NetworkClientSta
snprintf(client_name, size, "%s", ci->client_name);
}
+byte NetworkSpectatorCount(void)
+{
+ const NetworkClientState *cs;
+ byte count = 0;
+
+ FOR_ALL_CLIENTS(cs) {
+ if (DEREF_CLIENT_INFO(cs)->client_playas == OWNER_SPECTATOR) count++;
+ }
+
+ return count;
+}
+
// This puts a text-message to the console, or in the future, the chat-box,
// (to keep it all a bit more general)
// If 'self_send' is true, this is the client who is sending the message
@@ -554,11 +566,7 @@ void NetworkCloseClient(NetworkClientState *cs)
if (_network_server) {
// We just lost one client :(
- if (cs->status > STATUS_INACTIVE) {
- _network_game_info.clients_on--;
- if (DEREF_CLIENT_INFO(cs)->client_playas == OWNER_SPECTATOR)
- _network_game_info.spectators_on--;
- }
+ if (cs->status > STATUS_INACTIVE) _network_game_info.clients_on--;
_network_clients_connected--;
while ((cs + 1) != DEREF_CLIENT(MAX_CLIENTS) && (cs + 1)->socket != INVALID_SOCKET) {