Changeset - r25977:e1f4fbb88a36
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-09-19 20:52:46
truebrain@openttd.org
Add: [Network] On join, log the ClientID + IP + Name clearly (#9558)

Additionally, reword the disconnect to match connect / join messages.

Co-authored-by: Berbe <4251220+Berbe@users.noreply.github.com>
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/network/network_server.cpp
Show inline comments
 
@@ -260,49 +260,49 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		/* We did not receive a leave message from this client... */
 
		std::string client_name = this->GetClientName();
 

	
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
 

	
 
		/* Inform other clients of this... strange leaving ;) */
 
		for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
			if (new_cs->status > STATUS_AUTHORIZED && this != new_cs) {
 
				new_cs->SendErrorQuit(this->client_id, NETWORK_ERROR_CONNECTION_LOST);
 
			}
 
		}
 
	}
 

	
 
	/* If we were transfering a map to this client, stop the savegame creation
 
	 * process and queue the next client to receive the map. */
 
	if (this->status == STATUS_MAP) {
 
		/* Ensure the saving of the game is stopped too. */
 
		this->savegame->Destroy();
 
		this->savegame = nullptr;
 

	
 
		this->CheckNextClientToSendMap(this);
 
	}
 

	
 
	NetworkAdminClientError(this->client_id, NETWORK_ERROR_CONNECTION_LOST);
 
	Debug(net, 3, "Closed client connection {}", this->client_id);
 
	Debug(net, 3, "[{}] Client #{} closed connection", ServerNetworkGameSocketHandler::GetName(), this->client_id);
 

	
 
	/* We just lost one client :( */
 
	if (this->status >= STATUS_AUTHORIZED) _network_game_info.clients_on--;
 
	extern byte _network_clients_connected;
 
	_network_clients_connected--;
 

	
 
	this->SendPackets(true);
 

	
 
	delete this->GetInfo();
 
	delete this;
 

	
 
	InvalidateWindowData(WC_CLIENT_LIST, 0);
 

	
 
	return status;
 
}
 

	
 
/**
 
 * Whether an connection is allowed or not at this moment.
 
 * @return true if the connection is allowed.
 
 */
 
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
 
{
 
	extern byte _network_clients_connected;
 
	bool accept = _network_clients_connected < MAX_CLIENTS;
 
@@ -927,48 +927,50 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	}
 

	
 
	/* Check if someone else is receiving the map */
 
	for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
		if (new_cs->status == STATUS_MAP) {
 
			/* Tell the new client to wait */
 
			this->status = STATUS_MAP_WAIT;
 
			return this->SendWait();
 
		}
 
	}
 

	
 
	/* We receive a request to upload the map.. give it to the client! */
 
	return this->SendMap();
 
}
 

	
 
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *p)
 
{
 
	/* Client has the map, now start syncing */
 
	if (this->status == STATUS_DONE_MAP && !this->HasClientQuit()) {
 
		std::string client_name = this->GetClientName();
 

	
 
		NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, "", this->client_id);
 
		InvalidateWindowData(WC_CLIENT_LIST, 0);
 

	
 
		Debug(net, 3, "[{}] Client #{} ({}) joined as {}", ServerNetworkGameSocketHandler::GetName(), this->client_id, this->GetClientIP(), client_name);
 

	
 
		/* Mark the client as pre-active, and wait for an ACK
 
		 *  so we know it is done loading and in sync with us */
 
		this->status = STATUS_PRE_ACTIVE;
 
		NetworkHandleCommandQueue(this);
 
		this->SendFrame();
 
		this->SendSync();
 

	
 
		/* This is the frame the client receives
 
		 *  we need it later on to make sure the client is not too slow */
 
		this->last_frame = _frame_counter;
 
		this->last_frame_server = _frame_counter;
 

	
 
		for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
 
			if (new_cs->status >= STATUS_AUTHORIZED) {
 
				new_cs->SendClientInfo(this->GetInfo());
 
				new_cs->SendJoin(this->client_id);
 
			}
 
		}
 

	
 
		NetworkAdminClientInfo(this, true);
 

	
 
		/* also update the new client with our max values */
 
		this->SendConfigUpdate();
 

	
0 comments (0 inline, 0 general)