Changeset - r16214:7fd822f2f61a
[Not reviewed]
master
0 7 0
rubidium - 14 years ago 2010-10-15 14:29:13
rubidium@openttd.org
(svn r20925) -Codechange: make the client send commands have a slightly more sensible name
7 files changed with 89 insertions and 71 deletions:
0 comments (0 inline, 0 general)
src/network/network.cpp
Show inline comments
 
@@ -276,13 +276,13 @@ static void NetworkClientError(NetworkRe
 
		default:                                  errorno = NETWORK_ERROR_GENERAL; break;
 
	}
 

	
 
	/* This means we fucked up and the server closed the connection */
 
	if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL &&
 
			res != NETWORK_RECV_STATUS_SERVER_BANNED) {
 
		SEND_COMMAND(PACKET_CLIENT_ERROR)(errorno);
 
		MyClient::SendError(errorno);
 
	}
 

	
 
	_switch_mode = SM_MENU;
 
	NetworkCloseClient(cs, res);
 
	_networking = false;
 
}
 
@@ -630,13 +630,13 @@ static void InitializeNetworkPools()
 
static void NetworkClose()
 
{
 
	NetworkClientSocket *cs;
 

	
 
	FOR_ALL_CLIENT_SOCKETS(cs) {
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_QUIT)();
 
			MyClient::SendQuit();
 
			cs->Send_Packets();
 
		}
 
		NetworkCloseClient(cs, NETWORK_RECV_STATUS_CONN_LOST);
 
	}
 

	
 
	if (_network_server) {
 
@@ -684,13 +684,13 @@ public:
 
	}
 

	
 
	virtual void OnConnect(SOCKET s)
 
	{
 
		_networking = true;
 
		NetworkAllocClient(s);
 
		SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO)();
 
		MyClient::SendCompanyInformationQuery();
 
	}
 
};
 

	
 
/* Query a server to fetch his game-info
 
 *  If game_info is true, only the gameinfo is fetched,
 
 *   else only the client_info is fetched */
 
@@ -1000,13 +1000,13 @@ static bool NetworkDoClientLoop()
 

	
 
			/* If this is the first time we have a sync-frame, we
 
			 *   need to let the server know that we are ready and at the same
 
			 *   frame as he is.. so we can start playing! */
 
			if (_network_first_time) {
 
				_network_first_time = false;
 
				SEND_COMMAND(PACKET_CLIENT_ACK)();
 
				MyClient::SendAck();
 
			}
 

	
 
			_sync_frame = 0;
 
		} else if (_sync_frame < _frame_counter) {
 
			DEBUG(net, 1, "Missed frame for sync-test (%d / %d)", _sync_frame, _frame_counter);
 
			_sync_frame = 0;
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -261,13 +261,13 @@ void NetworkDrawChatMessage()
 

	
 

	
 
static void SendChat(const char *buf, DestType type, int dest)
 
{
 
	if (StrEmpty(buf)) return;
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
 
		MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
 
	} else {
 
		NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
 
	}
 
}
 

	
 
/** Widget numbers of the chat window. */
src/network/network_client.cpp
Show inline comments
 
@@ -37,16 +37,25 @@
 
/**
 
 * Create a new socket for the client side of the game connection.
 
 * @param s The socket to connect with.
 
 */
 
ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler(SOCKET s) : NetworkGameSocketHandler(s)
 
{
 
	assert(ClientNetworkGameSocketHandler::my_client == NULL);
 
	ClientNetworkGameSocketHandler::my_client = this;
 
}
 

	
 
/* So we don't make too much typos ;) */
 
#define MY_CLIENT NetworkClientSocket::Get(0)
 
/** Clear whatever we assigned. */
 
ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler()
 
{
 
	assert(ClientNetworkGameSocketHandler::my_client == this);
 
	ClientNetworkGameSocketHandler::my_client = NULL;
 
}
 

	
 
/** Our client's connection. */
 
ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = NULL;
 

	
 
static uint32 last_ack_frame;
 

	
 
/** One bit of 'entropy' used to generate a salt for the company passwords. */
 
static uint32 _password_game_seed;
 
/** The other bit of 'entropy' used to generate a salt for the company passwords. */
 
@@ -117,30 +126,30 @@ void HashCurrentCompanyPassword(const ch
 

	
 
/***********
 
 * Sending functions
 
 *   DEF_CLIENT_SEND_COMMAND has no parameters
 
 ************/
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyInformationQuery()
 
{
 
	/*
 
	 * Packet: CLIENT_COMPANY_INFO
 
	 * Function: Request company-info (in detail)
 
	 * Data:
 
	 *    <none>
 
	 */
 
	Packet *p;
 
	_network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO;
 
	SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
 

	
 
	p = new Packet(PACKET_CLIENT_COMPANY_INFO);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin()
 
{
 
	/*
 
	 * Packet: CLIENT_JOIN
 
	 * Function: Try to join the server
 
	 * Data:
 
	 *    String: OpenTTD Revision (norev000 if no revision)
 
@@ -155,60 +164,60 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JO
 

	
 
	p = new Packet(PACKET_CLIENT_JOIN);
 
	p->Send_string(_openttd_revision);
 
	p->Send_string(_settings_client.network.client_name); // Client name
 
	p->Send_uint8 (_network_join_as);     // PlayAs
 
	p->Send_uint8 (NETLANG_ANY);          // Language
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendNewGRFsOk()
 
{
 
	/*
 
	 * Packet: CLIENT_NEWGRFS_CHECKED
 
	 * Function: Tell the server that we have the required GRFs
 
	 * Data:
 
	 */
 

	
 
	Packet *p = new Packet(PACKET_CLIENT_NEWGRFS_CHECKED);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_GAME_PASSWORD)(const char *password)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendGamePassword(const char *password)
 
{
 
	/*
 
	 * Packet: CLIENT_GAME_PASSWORD
 
	 * Function: Send a password to the server to authorize
 
	 * Data:
 
	 *    uint8:  NetworkPasswordType
 
	 *    String: Password
 
	 */
 
	Packet *p = new Packet(PACKET_CLIENT_GAME_PASSWORD);
 
	p->Send_string(password);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMPANY_PASSWORD)(const char *password)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword(const char *password)
 
{
 
	/*
 
	 * Packet: CLIENT_COMPANY_PASSWORD
 
	 * Function: Send a password to the server to authorize
 
	 * Data:
 
	 *    uint8:  NetworkPasswordType
 
	 *    String: Password
 
	 */
 
	Packet *p = new Packet(PACKET_CLIENT_COMPANY_PASSWORD);
 
	p->Send_string(GenerateCompanyPasswordHash(password));
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap()
 
{
 
	/*
 
	 * Packet: CLIENT_GETMAP
 
	 * Function: Request the map from the server
 
	 * Data:
 
	 *    <none>
 
@@ -219,48 +228,48 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GE
 
	 * But only do it for stable releases because of those we are sure
 
	 * that everybody has the same NewGRF version. For trunk and the
 
	 * branches we make tarballs of the OpenTTDs compiled from tarball
 
	 * will have the lower bits set to 0. As such they would become
 
	 * incompatible, which we would like to prevent by this. */
 
	if (HasBit(_openttd_newgrf_version, 19)) p->Send_uint32(_openttd_newgrf_version);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk()
 
{
 
	/*
 
	 * Packet: CLIENT_MAP_OK
 
	 * Function: Tell the server that we are done receiving/loading the map
 
	 * Data:
 
	 *    <none>
 
	 */
 

	
 
	Packet *p = new Packet(PACKET_CLIENT_MAP_OK);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendAck()
 
{
 
	/*
 
	 * Packet: CLIENT_ACK
 
	 * Function: Tell the server we are done with this frame
 
	 * Data:
 
	 *    uint32: current FrameCounter of the client
 
	 */
 

	
 
	Packet *p = new Packet(PACKET_CLIENT_ACK);
 

	
 
	p->Send_uint32(_frame_counter);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/* Send a command packet to the server */
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(const CommandPacket *cp)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacket *cp)
 
{
 
	/*
 
	 * Packet: CLIENT_COMMAND
 
	 * Function: Send a DoCommand to the Server
 
	 * Data:
 
	 *    uint8:  CompanyID (0..MAX_COMPANIES-1)
 
@@ -270,20 +279,20 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLI
 
	 *    uint32: Tile
 
	 *    string: text
 
	 *    uint8:  CallBackID
 
	 */
 

	
 
	Packet *p = new Packet(PACKET_CLIENT_COMMAND);
 
	MY_CLIENT->Send_Command(p, cp);
 
	my_client->Send_Command(p, cp);
 

	
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/* Send a chat-packet over the network */
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
 
{
 
	/*
 
	 * Packet: CLIENT_CHAT
 
	 * Function: Send a chat-packet to the serve
 
	 * Data:
 
	 *    uint8:  ActionID (see network_data.h, NetworkAction)
 
@@ -298,91 +307,91 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLI
 
	p->Send_uint8 (action);
 
	p->Send_uint8 (type);
 
	p->Send_uint32(dest);
 
	p->Send_string(msg);
 
	p->Send_uint64(data);
 

	
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/* Send an error-packet over the network */
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendError(NetworkErrorCode errorno)
 
{
 
	/*
 
	 * Packet: CLIENT_ERROR
 
	 * Function: The client made an error and is quiting the game
 
	 * Data:
 
	 *    uint8:  ErrorID (see network_data.h, NetworkErrorCode)
 
	 */
 
	Packet *p = new Packet(PACKET_CLIENT_ERROR);
 

	
 
	p->Send_uint8(errorno);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetPassword(const char *password)
 
{
 
	/*
 
	 * Packet: PACKET_CLIENT_SET_PASSWORD
 
	 * Function: Set the password for the clients current company
 
	 * Data:
 
	 *    String: Password
 
	 */
 
	Packet *p = new Packet(PACKET_CLIENT_SET_PASSWORD);
 

	
 
	p->Send_string(GenerateCompanyPasswordHash(password));
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetName(const char *name)
 
{
 
	/*
 
	 * Packet: PACKET_CLIENT_SET_NAME
 
	 * Function: Gives the client a new name
 
	 * Data:
 
	 *    String: Name
 
	 */
 
	Packet *p = new Packet(PACKET_CLIENT_SET_NAME);
 

	
 
	p->Send_string(name);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/* Send an quit-packet over the network */
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)()
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit()
 
{
 
	/*
 
	 * Packet: CLIENT_QUIT
 
	 * Function: The client is quiting the game
 
	 * Data:
 
	 */
 
	Packet *p = new Packet(PACKET_CLIENT_QUIT);
 

	
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const char *pass, const char *command)
 
{
 
	Packet *p = new Packet(PACKET_CLIENT_RCON);
 
	p->Send_string(pass);
 
	p->Send_string(command);
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_MOVE)(CompanyID company, const char *pass)
 
NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, const char *pass)
 
{
 
	Packet *p = new Packet(PACKET_CLIENT_MOVE);
 
	p->Send_uint8(company);
 
	p->Send_string(GenerateCompanyPasswordHash(pass));
 
	MY_CLIENT->Send_Packet(p);
 
	my_client->Send_Packet(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 

	
 
/***********
 
 * Receiving functions
 
@@ -555,25 +564,25 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
			ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH;
 
		}
 
	}
 

	
 
	if (ret == NETWORK_RECV_STATUS_OKAY) {
 
		/* Start receiving the map */
 
		return SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)();
 
		return SendNewGRFsOk();
 
	}
 

	
 
	/* NewGRF mismatch, bail out */
 
	_switch_mode_errorstr = STR_NETWORK_ERROR_NEWGRF_MISMATCH;
 
	return ret;
 
}
 

	
 
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_NEED_GAME_PASSWORD)
 
{
 
	const char *password = _network_join_server_password;
 
	if (!StrEmpty(password)) {
 
		return SEND_COMMAND(PACKET_CLIENT_GAME_PASSWORD)(password);
 
		return SendGamePassword(password);
 
	}
 

	
 
	ShowNetworkNeedPassword(NETWORK_GAME_PASSWORD);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 
@@ -583,13 +592,13 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
	_password_game_seed = p->Recv_uint32();
 
	p->Recv_string(_password_server_id, sizeof(_password_server_id));
 
	if (this->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 

	
 
	const char *password = _network_join_company_password;
 
	if (!StrEmpty(password)) {
 
		return SEND_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD)(password);
 
		return SendCompanyPassword(password);
 
	}
 

	
 
	ShowNetworkNeedPassword(NETWORK_COMPANY_PASSWORD);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 
@@ -600,13 +609,13 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 

	
 
	/* Initialize the password hash salting variables, even if they were previously. */
 
	_password_game_seed = p->Recv_uint32();
 
	p->Recv_string(_password_server_id, sizeof(_password_server_id));
 

	
 
	/* Start receiving the map */
 
	return SEND_COMMAND(PACKET_CLIENT_GETMAP)();
 
	return SendGetMap();
 
}
 

	
 
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WAIT)
 
{
 
	_network_join_status = NETWORK_JOIN_STATUS_WAITING;
 
	_network_join_waiting = p->Recv_uint8();
 
@@ -682,13 +691,13 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 
			return NETWORK_RECV_STATUS_SAVEGAME;
 
		}
 
		/* If the savegame has successfully loaded, ALL windows have been removed,
 
		 * only toolbar/statusbar and gamefield are visible */
 

	
 
		/* Say we received the map and loaded it correctly! */
 
		SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
 
		SendMapOk();
 

	
 
		/* New company/spectator (invalid company) or company we want to join is not active
 
		 * Switch local company to spectator and await the server's judgement */
 
		if (_network_join_as == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join_as)) {
 
			SetLocalCompany(COMPANY_SPECTATOR);
 

	
 
@@ -727,13 +736,13 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_
 

	
 
	/* Let the server know that we received this frame correctly
 
	 *  We do this only once per day, to save some bandwidth ;) */
 
	if (!_network_first_time && last_ack_frame < _frame_counter) {
 
		last_ack_frame = _frame_counter + DAY_TICKS;
 
		DEBUG(net, 4, "Sent ACK at %d", _frame_counter);
 
		SEND_COMMAND(PACKET_CLIENT_ACK)();
 
		SendAck();
 
	}
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_SYNC)
 
@@ -941,29 +950,29 @@ void NetworkClient_Connected()
 
{
 
	/* Set the frame-counter to 0 so nothing happens till we are ready */
 
	_frame_counter = 0;
 
	_frame_counter_server = 0;
 
	last_ack_frame = 0;
 
	/* Request the game-info */
 
	SEND_COMMAND(PACKET_CLIENT_JOIN)();
 
	MyClient::SendJoin();
 
}
 

	
 
void NetworkClientSendRcon(const char *password, const char *command)
 
{
 
	SEND_COMMAND(PACKET_CLIENT_RCON)(password, command);
 
	MyClient::SendRCon(password, command);
 
}
 

	
 
/**
 
 * Notify the server of this client wanting to be moved to another company.
 
 * @param company_id id of the company the client wishes to be moved to.
 
 * @param pass the password, is only checked on the server end if a password is needed.
 
 * @return void
 
 */
 
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
 
{
 
	SEND_COMMAND(PACKET_CLIENT_MOVE)(company_id, pass);
 
	MyClient::SendMove(company_id, pass);
 
}
 

	
 
void NetworkClientsToSpectators(CompanyID cid)
 
{
 
	/* If our company is changing owner, go to spectators */
 
	if (cid == _local_company) SetLocalCompany(COMPANY_SPECTATOR);
 
@@ -982,31 +991,31 @@ void NetworkUpdateClientName()
 

	
 
	if (ci == NULL) return;
 

	
 
	/* Don't change the name if it is the same as the old name */
 
	if (strcmp(ci->client_name, _settings_client.network.client_name) != 0) {
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.client_name);
 
			MyClient::SendSetName(_settings_client.network.client_name);
 
		} else {
 
			if (NetworkFindName(_settings_client.network.client_name)) {
 
				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, _settings_client.network.client_name);
 
				strecpy(ci->client_name, _settings_client.network.client_name, lastof(ci->client_name));
 
				NetworkUpdateClientInfo(CLIENT_ID_SERVER);
 
			}
 
		}
 
	}
 
}
 

	
 
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
 
{
 
	SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg, data);
 
	MyClient::SendChat(action, type, dest, msg, data);
 
}
 

	
 
static void NetworkClientSetPassword(const char *password)
 
{
 
	SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(password);
 
	MyClient::SendSetPassword(password);
 
}
 

	
 
/**
 
 * Tell whether the client has team members where he/she can chat to.
 
 * @param cio client to check members of.
 
 * @return true if there is at least one team member.
src/network/network_client.h
Show inline comments
 
@@ -16,12 +16,14 @@
 

	
 
#include "network_internal.h"
 

	
 
/** Class for handling the client side of the game connection. */
 
class ClientNetworkGameSocketHandler : public NetworkGameSocketHandler {
 
protected:
 
	static ClientNetworkGameSocketHandler *my_client;
 

	
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_FULL);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_BANNED);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_ERROR);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEED_GAME_PASSWORD);
 
@@ -40,29 +42,39 @@ protected:
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_RCON);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_MOVE);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_UPDATE);
 
	DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_CONFIG_UPDATE);
 

	
 
	static NetworkRecvStatus SendNewGRFsOk();
 
	static NetworkRecvStatus SendGetMap();
 
	static NetworkRecvStatus SendMapOk();
 
public:
 
	ClientNetworkGameSocketHandler(SOCKET s);
 
	~ClientNetworkGameSocketHandler();
 

	
 
	static NetworkRecvStatus SendCompanyInformationQuery();
 

	
 
	static NetworkRecvStatus SendJoin();
 
	static NetworkRecvStatus SendCommand(const CommandPacket *cp);
 
	static NetworkRecvStatus SendError(NetworkErrorCode errorno);
 
	static NetworkRecvStatus SendQuit();
 
	static NetworkRecvStatus SendAck();
 

	
 
	static NetworkRecvStatus SendGamePassword(const char *password);
 
	static NetworkRecvStatus SendCompanyPassword(const char *password);
 

	
 
	static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
 
	static NetworkRecvStatus SendSetPassword(const char *password);
 
	static NetworkRecvStatus SendSetName(const char *name);
 
	static NetworkRecvStatus SendRCon(const char *password, const char *command);
 
	static NetworkRecvStatus SendMove(CompanyID company, const char *password);
 
};
 

	
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GAME_INFO);
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(const CommandPacket *cp);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)();
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType desttype, int dest, const char *msg, int64 data);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_GAME_PASSWORD)(const char *password);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMPANY_PASSWORD)(const char *password);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name);
 
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command);
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_MOVE)(CompanyID company, const char *pass);
 
typedef ClientNetworkGameSocketHandler MyClient;
 

	
 
void NetworkClient_Connected();
 

	
 
extern CompanyID _network_join_as;
 

	
 
extern const char *_network_join_server_password;
src/network/network_command.cpp
Show inline comments
 
@@ -148,13 +148,13 @@ void NetworkSend_Command(TileIndex tile,
 
		return;
 
	}
 

	
 
	c.frame = 0; // The client can't tell which frame, so just make it 0
 

	
 
	/* Clients send their command to the server and forget all about the packet */
 
	SEND_COMMAND(PACKET_CLIENT_COMMAND)(&c);
 
	MyClient::SendCommand(&c);
 
}
 

	
 
/**
 
 * Sync our local command queue to the command queue of the given
 
 * socket. This is needed for the case where we receive a command
 
 * before saving the game for a joining client, but without the
src/network/network_gui.cpp
Show inline comments
 
@@ -2237,14 +2237,14 @@ struct NetworkJoinStatusWindow : Window 
 
			NetworkDisconnect();
 
			ShowNetworkGameWindow();
 
			return;
 
		}
 

	
 
		switch (this->password_type) {
 
			case NETWORK_GAME_PASSWORD:    SEND_COMMAND(PACKET_CLIENT_GAME_PASSWORD)   (str); break;
 
			case NETWORK_COMPANY_PASSWORD: SEND_COMMAND(PACKET_CLIENT_COMPANY_PASSWORD)(str); break;
 
			case NETWORK_GAME_PASSWORD:    MyClient::SendGamePassword   (str); break;
 
			case NETWORK_COMPANY_PASSWORD: MyClient::SendCompanyPassword(str); break;
 
			default: NOT_REACHED();
 
		}
 
	}
 
};
 

	
 
static const NWidgetPart _nested_network_join_status_window_widgets[] = {
src/network/network_internal.h
Show inline comments
 
@@ -172,15 +172,12 @@ void NetworkGetClientName(char *clientna
 
uint NetworkCalculateLag(const NetworkClientSocket *cs);
 
NetworkClientSocket *NetworkFindClientStateFromClientID(ClientID client_id);
 
StringID GetNetworkErrorMsg(NetworkErrorCode err);
 
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
 

	
 
/* Macros to make life a bit more easier */
 
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
 
#define DEF_CLIENT_SEND_COMMAND(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command()
 
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command
 
#define DEF_SERVER_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(NetworkClientSocket *cs, Packet *p)
 
#define DEF_SERVER_SEND_COMMAND(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command(NetworkClientSocket *cs)
 
#define DEF_SERVER_SEND_COMMAND_PARAM(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command
 

	
 
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
 
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
0 comments (0 inline, 0 general)