File diff r13522:764fd8565e70 → r13523:18c21261f627
src/network/network_server.cpp
Show inline comments
 
@@ -808,53 +808,48 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
		NetworkGetClientName(client_name, sizeof(client_name), cs);
 

	
 
		NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, NULL, cs->client_id);
 

	
 
		/* Mark the client as pre-active, and wait for an ACK
 
		 *  so we know he is done loading and in sync with us */
 
		cs->status = STATUS_PRE_ACTIVE;
 
		NetworkHandleCommandQueue(cs);
 
		SEND_COMMAND(PACKET_SERVER_FRAME)(cs);
 
		SEND_COMMAND(PACKET_SERVER_SYNC)(cs);
 

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

	
 
		FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
			if (new_cs->status > STATUS_AUTH) {
 
				SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(new_cs, cs->GetInfo());
 
				SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->client_id);
 
			}
 
		}
 

	
 
		if (_settings_client.network.pause_on_join) {
 
			/* Now pause the game till the client is in sync */
 
			DoCommandP(0, PM_PAUSED_JOIN, 1, CMD_PAUSE);
 
		}
 

	
 
		/* also update the new client with our max values */
 
		SEND_COMMAND(PACKET_SERVER_CONFIG_UPDATE)(cs);
 

	
 
		/* quickly update the syncing client with company details */
 
		SEND_COMMAND(PACKET_SERVER_COMPANY_UPDATE)(cs);
 
	} else {
 
		/* Wrong status for this packet, give a warning to client, and close connection */
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
	}
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** The client has done a command and wants us to handle it
 
 * @param *cs the connected client that has sent the command
 
 * @param *p the packet in which the command was sent
 
 */
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
 
{
 
	NetworkClientSocket *new_cs;
 

	
 
	/* The client was never joined.. so this is impossible, right?
 
	 *  Ignore the packet, give the client a warning, and close his connection */
 
	if (cs->status < STATUS_DONE_MAP || cs->HasClientQuit()) {
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
@@ -1001,52 +996,48 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	}
 

	
 
	cs->CloseConnection(false);
 
	return NETWORK_RECV_STATUS_CONN_LOST;
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
 
{
 
	if (cs->status < STATUS_AUTH) {
 
		/* Illegal call, return error and ignore the packet */
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED);
 
		return NETWORK_RECV_STATUS_OKAY;
 
	}
 

	
 
	uint32 frame = p->Recv_uint32();
 

	
 
	/* The client is trying to catch up with the server */
 
	if (cs->status == STATUS_PRE_ACTIVE) {
 
		/* The client is not yet catched up? */
 
		if (frame + DAY_TICKS < _frame_counter) return NETWORK_RECV_STATUS_OKAY;
 

	
 
		/* Now he is! Unpause the game */
 
		cs->status = STATUS_ACTIVE;
 

	
 
		if (_pause_mode & PM_PAUSED_JOIN) {
 
			DoCommandP(0, PM_PAUSED_JOIN, 0, CMD_PAUSE);
 
		}
 

	
 
		/* Execute script for, e.g. MOTD */
 
		IConsoleCmdExec("exec scripts/on_server_connect.scr 0");
 
	}
 

	
 
	/* The client received the frame, make note of it */
 
	cs->last_frame = frame;
 
	/* With those 2 values we can calculate the lag realtime */
 
	cs->last_frame_server = _frame_counter;
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 

	
 

	
 
void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data)
 
{
 
	NetworkClientSocket *cs;
 
	const NetworkClientInfo *ci, *ci_own, *ci_to;
 

	
 
	switch (desttype) {
 
	case DESTTYPE_CLIENT:
 
		/* Are we sending to the server? */
 
		if ((ClientID)dest == CLIENT_ID_SERVER) {
 
			ci = NetworkFindClientInfoFromClientID(from_id);
 
			/* Display the text locally, and that is it */