mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
(svn r22032) -Codechange: add some asserts to verify we don't allocate too many NetworkClientSockets/Infos
This commit is contained in:
parent
537bd8a429
commit
05a846a574
@ -682,6 +682,8 @@ static void NetworkInitGameInfo()
|
|||||||
/* The server is a client too */
|
/* The server is a client too */
|
||||||
_network_game_info.clients_on = _network_dedicated ? 0 : 1;
|
_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);
|
NetworkClientInfo *ci = new NetworkClientInfo(CLIENT_ID_SERVER);
|
||||||
ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : _local_company;
|
ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : _local_company;
|
||||||
/* Give the server a valid IP; banning it is pointless anyways */
|
/* Give the server a valid IP; banning it is pointless anyways */
|
||||||
|
@ -155,6 +155,13 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
|
|||||||
this->status = STATUS_INACTIVE;
|
this->status = STATUS_INACTIVE;
|
||||||
this->client_id = _network_client_id++;
|
this->client_id = _network_client_id++;
|
||||||
this->receive_limit = _settings_client.network.bytes_per_frame_burst;
|
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);
|
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
|
||||||
this->SetInfo(ci);
|
this->SetInfo(ci);
|
||||||
ci->client_playas = COMPANY_INACTIVE_CLIENT;
|
ci->client_playas = COMPANY_INACTIVE_CLIENT;
|
||||||
@ -250,7 +257,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
|
|||||||
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
|
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
|
||||||
{
|
{
|
||||||
extern byte _network_clients_connected;
|
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. */
|
/** Send the packets for the server sockets. */
|
||||||
|
Loading…
Reference in New Issue
Block a user