diff options
-rw-r--r-- | src/network/network.cpp | 2 | ||||
-rw-r--r-- | src/network/network_server.cpp | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index 0902fcdb0..04268dbf6 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -682,6 +682,8 @@ static void NetworkInitGameInfo() /* The server is a client too */ _network_game_info.clients_on = _network_dedicated ? 0 : 1; + /* There should be always space for the server. */ + assert(NetworkClientInfo::CanAllocateItem()); NetworkClientInfo *ci = new NetworkClientInfo(CLIENT_ID_SERVER); ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : _local_company; /* Give the server a valid IP; banning it is pointless anyways */ diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index d79c5b566..be27d75a6 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -155,6 +155,13 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo this->status = STATUS_INACTIVE; this->client_id = _network_client_id++; this->receive_limit = _settings_client.network.bytes_per_frame_burst; + + /* The Socket and Info pools need to be the same in size. After all, + * each Socket will be associated with at most one Info object. As + * such if the Socket was allocated the Info object can as well. */ + assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE); + assert(NetworkClientInfo::CanAllocateItem()); + NetworkClientInfo *ci = new NetworkClientInfo(this->client_id); this->SetInfo(ci); ci->client_playas = COMPANY_INACTIVE_CLIENT; @@ -250,7 +257,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta /* static */ bool ServerNetworkGameSocketHandler::AllowConnection() { extern byte _network_clients_connected; - return _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients; + bool accept = _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients; + + /* We can't go over the MAX_CLIENTS limit here. However, the + * pool must have place for all clients and ourself. */ + assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1); + assert(ServerNetworkGameSocketHandler::CanAllocateItem()); + return accept; } /** Send the packets for the server sockets. */ |