mirror of https://github.com/OpenTTD/OpenTTD
(svn r20930) -Codechange: simplify the socket handler allocation
parent
7ba07d9573
commit
76579df240
|
@ -475,25 +475,6 @@ void ParseConnectionString(const char **company, const char **port, char *connec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creates a new client from a socket
|
|
||||||
* Used both by the server and the client */
|
|
||||||
static NetworkClientSocket *NetworkAllocClient(SOCKET s)
|
|
||||||
{
|
|
||||||
if (!_network_server) {
|
|
||||||
return new ClientNetworkGameSocketHandler(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Can we handle a new client? */
|
|
||||||
if (_network_clients_connected >= MAX_CLIENTS) return NULL;
|
|
||||||
if (_network_game_info.clients_on >= _settings_client.network.max_clients) return NULL;
|
|
||||||
|
|
||||||
/* Register the login */
|
|
||||||
_network_clients_connected++;
|
|
||||||
|
|
||||||
SetWindowDirty(WC_CLIENT_LIST, 0);
|
|
||||||
return new ServerNetworkGameSocketHandler(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* For the server, to accept new clients */
|
/* For the server, to accept new clients */
|
||||||
static void NetworkAcceptClients(SOCKET ls)
|
static void NetworkAcceptClients(SOCKET ls)
|
||||||
{
|
{
|
||||||
|
@ -529,8 +510,9 @@ static void NetworkAcceptClients(SOCKET ls)
|
||||||
/* If this client is banned, continue with next client */
|
/* If this client is banned, continue with next client */
|
||||||
if (banned) continue;
|
if (banned) continue;
|
||||||
|
|
||||||
NetworkClientSocket *cs = NetworkAllocClient(s);
|
/* Can we handle a new client? */
|
||||||
if (cs == NULL) {
|
if (_network_clients_connected >= MAX_CLIENTS ||
|
||||||
|
_network_game_info.clients_on >= _settings_client.network.max_clients) {
|
||||||
/* no more clients allowed?
|
/* no more clients allowed?
|
||||||
* Send to the client that we are full! */
|
* Send to the client that we are full! */
|
||||||
Packet p(PACKET_SERVER_FULL);
|
Packet p(PACKET_SERVER_FULL);
|
||||||
|
@ -542,11 +524,11 @@ static void NetworkAcceptClients(SOCKET ls)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a new client has connected. We set him at inactive for now
|
/* Register the login */
|
||||||
* maybe he is only requesting server-info. Till he has sent a PACKET_CLIENT_MAP_OK
|
_network_clients_connected++;
|
||||||
* the client stays inactive */
|
|
||||||
cs->status = STATUS_INACTIVE;
|
|
||||||
|
|
||||||
|
SetWindowDirty(WC_CLIENT_LIST, 0);
|
||||||
|
ServerNetworkGameSocketHandler *cs = new ServerNetworkGameSocketHandler(s);
|
||||||
cs->GetInfo()->client_address = address; // Save the IP of the client
|
cs->GetInfo()->client_address = address; // Save the IP of the client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -638,7 +620,7 @@ public:
|
||||||
virtual void OnConnect(SOCKET s)
|
virtual void OnConnect(SOCKET s)
|
||||||
{
|
{
|
||||||
_networking = true;
|
_networking = true;
|
||||||
NetworkAllocClient(s);
|
new ClientNetworkGameSocketHandler(s);
|
||||||
MyClient::SendCompanyInformationQuery();
|
MyClient::SendCompanyInformationQuery();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -721,7 +703,7 @@ public:
|
||||||
virtual void OnConnect(SOCKET s)
|
virtual void OnConnect(SOCKET s)
|
||||||
{
|
{
|
||||||
_networking = true;
|
_networking = true;
|
||||||
NetworkAllocClient(s);
|
new ClientNetworkGameSocketHandler(s);
|
||||||
IConsoleCmdExec("exec scripts/on_client.scr 0");
|
IConsoleCmdExec("exec scripts/on_client.scr 0");
|
||||||
NetworkClient_Connected();
|
NetworkClient_Connected();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue