Changeset - r17642:ab10f4b22179
[Not reviewed]
master
0 8 0
rubidium - 14 years ago 2011-05-05 16:24:48
rubidium@openttd.org
(svn r22424) -Document: some more bits
8 files changed with 283 insertions and 43 deletions:
0 comments (0 inline, 0 general)
src/network/network.cpp
Show inline comments
 
@@ -123,13 +123,13 @@ NetworkClientInfo::~NetworkClientInfo()
 

	
 
/**
 
 * Return the client state given it's client-identifier
 
 * @param client_id the ClientID to search for
 
 * @return return a pointer to the corresponding NetworkClientSocket struct or NULL when not found
 
 */
 
/* static */ NetworkClientSocket *NetworkClientSocket::GetByClientID(ClientID client_id)
 
/* static */ ServerNetworkGameSocketHandler *ServerNetworkGameSocketHandler::GetByClientID(ClientID client_id)
 
{
 
	NetworkClientSocket *cs;
 

	
 
	FOR_ALL_CLIENT_SOCKETS(cs) {
 
		if (cs->client_id == client_id) return cs;
 
	}
 
@@ -476,12 +476,17 @@ void ParseConnectionString(const char **
 
				*p = '\0';
 
				break;
 
		}
 
	}
 
}
 

	
 
/**
 
 * Handle the acception of a connection to the server.
 
 * @param s The socket of the new connection.
 
 * @param address The address of the peer.
 
 */
 
/* static */ void ServerNetworkGameSocketHandler::AcceptConnection(SOCKET s, const NetworkAddress &address)
 
{
 
	/* Register the login */
 
	_network_clients_connected++;
 

	
 
	SetWindowDirty(WC_CLIENT_LIST, 0);
src/network/network_admin.cpp
Show inline comments
 
@@ -104,22 +104,31 @@ ServerNetworkAdminSocketHandler::~Server
 
		if (as->writable) {
 
			as->SendPackets();
 
		}
 
	}
 
}
 

	
 
/**
 
 * Handle the acception of a connection.
 
 * @param s The socket of the new connection.
 
 * @param address The address of the peer.
 
 */
 
/* static */ void ServerNetworkAdminSocketHandler::AcceptConnection(SOCKET s, const NetworkAddress &address)
 
{
 
	ServerNetworkAdminSocketHandler *as = new ServerNetworkAdminSocketHandler(s);
 
	as->address = address; // Save the IP of the client
 
}
 

	
 
/***********
 
 * Sending functions for admin network
 
 ************/
 

	
 
/**
 
 * Send an error to the admin.
 
 * @param error The error to send.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError(NetworkErrorCode error)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_ERROR);
 

	
 
	p->Send_uint8(error);
 
	this->SendPacket(p);
 
@@ -130,12 +139,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 

	
 
	DEBUG(net, 1, "[admin] the admin '%s' (%s) made an error and has been disconnected. Reason: '%s'", this->admin_name, this->admin_version, str);
 

	
 
	return this->CloseConnection(true);
 
}
 

	
 
/** Send the protocol version to the admin. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol()
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_PROTOCOL);
 

	
 
	/* announce the protocol version */
 
	p->Send_uint8(NETWORK_GAME_ADMIN_VERSION);
 
@@ -149,12 +159,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	p->Send_bool(false);
 
	this->SendPacket(p);
 

	
 
	return this->SendWelcome();
 
}
 

	
 
/** Send a welcome message to the admin. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
 
{
 
	this->status = ADMIN_STATUS_ACTIVE;
 

	
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_WELCOME);
 

	
 
@@ -171,46 +182,57 @@ NetworkRecvStatus ServerNetworkAdminSock
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Tell the admin we started a new game. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame()
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_NEWGAME);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Tell the admin we're shutting down. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown()
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_SHUTDOWN);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Tell the admin the date. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE);
 

	
 
	p->Send_uint32(_date);
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the admin that a client joined.
 
 * @param client_id The client that joined.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID client_id)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_JOIN);
 

	
 
	p->Send_uint32(client_id);
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send an initial set of data from some client's information.
 
 * @param cs The information about a client.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs)
 
{
 
	/* Only send data when we're a proper client, not just someone trying to query the server. */
 
	const NetworkClientInfo *ci = cs->GetInfo();
 
	if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
 

	
 
@@ -225,12 +247,17 @@ NetworkRecvStatus ServerNetworkAdminSock
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 

	
 
/**
 
 * Send an update for some client's information.
 
 * @param ci The information about a client.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate(const NetworkClientInfo *ci)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_UPDATE);
 

	
 
	p->Send_uint32(ci->client_id);
 
	p->Send_string(ci->client_name);
 
@@ -238,43 +265,60 @@ NetworkRecvStatus ServerNetworkAdminSock
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the admin that a client quit.
 
 * @param client_id The client that quit.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit(ClientID client_id)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_QUIT);
 

	
 
	p->Send_uint32(client_id);
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the admin that a client made an error.
 
 * @param client_id The client that made the error.
 
 * @param error The error that was made.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError(ClientID client_id, NetworkErrorCode error)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_ERROR);
 

	
 
	p->Send_uint32(client_id);
 
	p->Send_uint8 (error);
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the admin that a new company was founded.
 
 * @param company_id The company that was founded.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew(CompanyID company_id)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_NEW);
 
	p->Send_uint8(company_id);
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send the admin some information about a company.
 
 * @param c The company to send the information about.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company *c)
 
{
 
	char company_name[NETWORK_COMPANY_NAME_LENGTH];
 
	char manager_name[NETWORK_COMPANY_NAME_LENGTH];
 

	
 
	SetDParam(0, c->index);
 
@@ -295,12 +339,17 @@ NetworkRecvStatus ServerNetworkAdminSock
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 

	
 
/**
 
 * Send an update about a company.
 
 * @param c The company to send the update of.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Company *c)
 
{
 
	char company_name[NETWORK_COMPANY_NAME_LENGTH];
 
	char manager_name[NETWORK_COMPANY_NAME_LENGTH];
 

	
 
	SetDParam(0, c->index);
 
@@ -324,24 +373,30 @@ NetworkRecvStatus ServerNetworkAdminSock
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the admin that a company got removed.
 
 * @param company_id The company that got removed.
 
 * @param acrr The reason for removal, e.g. bankruptcy or merger.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason acrr)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_REMOVE);
 

	
 
	p->Send_uint8(company_id);
 
	p->Send_uint8(acrr);
 

	
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send economic information of all companies. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
 
{
 
	const Company *company;
 
	FOR_ALL_COMPANIES(company) {
 
		/* Get the income. */
 
		Money income = 0;
 
@@ -370,12 +425,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	}
 

	
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send statistics about the companies. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
 
{
 
	/* Fetch the latest version of the stats. */
 
	NetworkCompanyStats company_stats[MAX_COMPANIES];
 
	NetworkPopulateCompanyStats(company_stats);
 

	
 
@@ -399,12 +455,20 @@ NetworkRecvStatus ServerNetworkAdminSock
 
		this->SendPacket(p);
 
	}
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send a chat message.
 
 * @param action The action associated with the message.
 
 * @param desttype The destination type.
 
 * @param client_id The origin of the chat message.
 
 * @param msg The actual message.
 
 * @param data Arbitrary extra data.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT);
 

	
 
	p->Send_uint8 (action);
 
	p->Send_uint8 (desttype);
 
@@ -413,12 +477,17 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	p->Send_uint64(data);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send the reply of an rcon command.
 
 * @param colour The colour of the text.
 
 * @param result The result of the command.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16 colour, const char *result)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON);
 

	
 
	p->Send_uint16(colour);
 
	p->Send_string(result);
 
@@ -440,12 +509,17 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	_redirect_console_to_admin = this->index;
 
	IConsoleCmdExec(command);
 
	_redirect_console_to_admin = INVALID_ADMIN_ID;
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send console output of other clients.
 
 * @param origin The origin of the string.
 
 * @param string The string that's put on the console.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const char *origin, const char *string)
 
{
 
	/* If the length of both strings, plus the 2 '\0' terminations and 3 bytes of the packet
 
	 * are bigger than the MTU, just ignore the message. Better safe than sorry. It should
 
	 * never occur though as the longest strings are chat messages, which are still 30%
 
	 * smaller than SEND_MTU. */
 
@@ -457,12 +531,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	p->Send_string(string);
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send the names of the commands. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES);
 

	
 
	for (uint i = 0; i < CMD_END; i++) {
 
		const char *cmdname = GetCommandName(i);
 
@@ -486,12 +561,17 @@ NetworkRecvStatus ServerNetworkAdminSock
 
	p->Send_bool(false);
 
	this->SendPacket(p);
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send a command for logging purposes.
 
 * @param client_id The client executing the command.
 
 * @param cp The command that would be executed.
 
 */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging(ClientID client_id, const CommandPacket *cp)
 
{
 
	Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_LOGGING);
 

	
 
	p->Send_uint32(client_id);
 
	p->Send_uint8 (cp->company);
src/network/network_admin.h
Show inline comments
 
@@ -18,12 +18,13 @@
 
#include "core/tcp_listen.h"
 
#include "core/tcp_admin.h"
 

	
 
extern AdminIndex _redirect_console_to_admin;
 

	
 
class ServerNetworkAdminSocketHandler;
 
/** Pool with all admin connections. */
 
typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN> NetworkAdminSocketPool;
 
extern NetworkAdminSocketPool _networkadminsocket_pool;
 

	
 
/** Class for handling the server side of the game connection. */
 
class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
 
protected:
 
@@ -79,13 +80,23 @@ public:
 
	static const char *GetName()
 
	{
 
		return "admin";
 
	}
 
};
 

	
 
/**
 
 * Iterate over all the sockets from a given starting point.
 
 * @param var The variable to iterate with.
 
 * @param start The start of the iteration.
 
 */
 
#define FOR_ALL_ADMIN_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(ServerNetworkAdminSocketHandler, adminsocket_index, var, start)
 

	
 
/**
 
 * Iterate over all the sockets.
 
 * @param var The variable to iterate with.
 
 */
 
#define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
 

	
 
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
 
void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
 
void NetworkAdminClientQuit(ClientID client_id);
 
void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -27,36 +27,44 @@
 
#include "network.h"
 
#include "network_client.h"
 
#include "network_base.h"
 

	
 
#include "table/strings.h"
 

	
 
/* The draw buffer must be able to contain the chat message, client name and the "[All]" message,
 
/** The draw buffer must be able to contain the chat message, client name and the "[All]" message,
 
 * some spaces and possible translations of [All] to other languages. */
 
assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
 

	
 
/** Spacing between chat lines. */
 
static const uint NETWORK_CHAT_LINE_SPACING = 3;
 

	
 
/** Container for a message. */
 
struct ChatMessage {
 
	char message[DRAW_STRING_BUFFER];
 
	TextColour colour;
 
	uint32 remove_time;
 
	char message[DRAW_STRING_BUFFER]; ///< The action message.
 
	TextColour colour;  ///< The colour of the message.
 
	uint32 remove_time; ///< The time to remove the message.
 
};
 

	
 
/* used for chat window */
 
static ChatMessage *_chatmsg_list = NULL;
 
static bool _chatmessage_dirty = false;
 
static bool _chatmessage_visible = false;
 
static bool _chat_tab_completion_active;
 
static uint MAX_CHAT_MESSAGES = 0;
 
static ChatMessage *_chatmsg_list = NULL; ///< The actual chat message list.
 
static bool _chatmessage_dirty = false;   ///< Does the chat message need repainting?
 
static bool _chatmessage_visible = false; ///< Is a chat message visible.
 
static bool _chat_tab_completion_active;  ///< Whether tab completion is active.
 
static uint MAX_CHAT_MESSAGES = 0;        ///< The limit of chat messages to show.
 

	
 
/* The chatbox grows from the bottom so the coordinates are pixels from
 
 * the left and pixels from the bottom. The height is the maximum height */
 
/**
 
 * The chatbox grows from the bottom so the coordinates are pixels from
 
 * the left and pixels from the bottom. The height is the maximum height.
 
 */
 
static PointDimension _chatmsg_box;
 
static uint8 *_chatmessage_backup = NULL;
 
static uint8 *_chatmessage_backup = NULL; ///< Backup in case text is moved.
 

	
 
/**
 
 * Count the chat messages.
 
 * @return The number of chat messages.
 
 */
 
static inline uint GetChatMessageCount()
 
{
 
	uint i = 0;
 
	for (; i < MAX_CHAT_MESSAGES; i++) {
 
		if (_chatmsg_list[i].message[0] == '\0') break;
 
	}
 
@@ -116,12 +124,13 @@ void NetworkReInitChatBoxSize()
 
{
 
	_chatmsg_box.y       = 3 * FONT_HEIGHT_NORMAL;
 
	_chatmsg_box.height  = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING) + 2;
 
	_chatmessage_backup  = ReallocT(_chatmessage_backup, _chatmsg_box.width * _chatmsg_box.height * BlitterFactoryBase::GetCurrentBlitter()->GetBytesPerPixel());
 
}
 

	
 
/** Initialize all buffers of the chat visualisation. */
 
void NetworkInitChatMessage()
 
{
 
	MAX_CHAT_MESSAGES    = _settings_client.gui.network_chat_box_height;
 

	
 
	_chatmsg_list        = ReallocT(_chatmsg_list, _settings_client.gui.network_chat_box_height);
 
	_chatmsg_box.x       = 10;
 
@@ -255,13 +264,18 @@ void NetworkDrawChatMessage()
 
	_video_driver->MakeDirty(x, y, width, height);
 

	
 
	_chatmessage_visible = true;
 
	_chatmessage_dirty = false;
 
}
 

	
 

	
 
/**
 
 * Send an actual chat message.
 
 * @param buf The message to send.
 
 * @param type The type of destination.
 
 * @param dest The actual destination index.
 
 */
 
static void SendChat(const char *buf, DestType type, int dest)
 
{
 
	if (StrEmpty(buf)) return;
 
	if (!_network_server) {
 
		MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
 
	} else {
 
@@ -275,17 +289,24 @@ enum NetWorkChatWidgets {
 
	NWCW_BACKGROUND,
 
	NWCW_DESTINATION,
 
	NWCW_TEXTBOX,
 
	NWCW_SENDBUTTON,
 
};
 

	
 
/** Window to enter the chat message in. */
 
struct NetworkChatWindow : public QueryStringBaseWindow {
 
	DestType dtype;
 
	StringID dest_string;
 
	int dest;
 
	DestType dtype;       ///< The type of destination.
 
	StringID dest_string; ///< String representation of the destination.
 
	int dest;             ///< The identifier of the destination.
 

	
 
	/**
 
	 * Create a chat input window.
 
	 * @param desc Description of the looks of the window.
 
	 * @param type The type of destination.
 
	 * @param dest The actual destination index.
 
	 */
 
	NetworkChatWindow(const WindowDesc *desc, DestType type, int dest) : QueryStringBaseWindow(NETWORK_CHAT_LENGTH)
 
	{
 
		this->dtype   = type;
 
		this->dest    = dest;
 
		this->afilter = CS_ALPHANUMERAL;
 
		InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size);
 
@@ -539,12 +560,13 @@ struct NetworkChatWindow : public QueryS
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 
	{
 
		if (data == this->dest) delete this;
 
	}
 
};
 

	
 
/** The widgets of the chat window. */
 
static const NWidgetPart _nested_chat_window_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY, NWCW_CLOSE),
 
		NWidget(WWT_PANEL, COLOUR_GREY, NWCW_BACKGROUND),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_TEXT, COLOUR_GREY, NWCW_DESTINATION), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NULL, STR_NULL),
 
@@ -553,19 +575,26 @@ static const NWidgetPart _nested_chat_wi
 
				NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, NWCW_SENDBUTTON), SetMinimalSize(62, 12), SetPadding(1, 0, 1, 0), SetDataTip(STR_NETWORK_CHAT_SEND, STR_NULL),
 
			EndContainer(),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
/** The description of the chat window. */
 
static const WindowDesc _chat_window_desc(
 
	WDP_MANUAL, 640, 14, // x, y, width, height
 
	WC_SEND_NETWORK_MSG, WC_NONE,
 
	0,
 
	_nested_chat_window_widgets, lengthof(_nested_chat_window_widgets)
 
);
 

	
 

	
 
/**
 
 * Show the chat window.
 
 * @param type The type of destination.
 
 * @param dest The actual destination index.
 
 */
 
void ShowNetworkChatQueryWindow(DestType type, int dest)
 
{
 
	DeleteWindowByClass(WC_SEND_NETWORK_MSG);
 
	new NetworkChatWindow(&_chat_window_desc, type, dest);
 
}
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -2042,17 +2042,16 @@ struct NetworkClientListWindow : Window 
 

	
 
void ShowClientList()
 
{
 
	AllocateWindowDescFront<NetworkClientListWindow>(&_client_list_desc, 0);
 
}
 

	
 
/* Vars needed for the join-GUI */
 
NetworkJoinStatus _network_join_status;
 
uint8 _network_join_waiting;
 
uint32 _network_join_bytes;
 
uint32 _network_join_bytes_total;
 
NetworkJoinStatus _network_join_status; ///< The status of joining.
 
uint8 _network_join_waiting;            ///< The number of clients waiting in front of us.
 
uint32 _network_join_bytes;             ///< The number of bytes we already downloaded.
 
uint32 _network_join_bytes_total;       ///< The total number of bytes to download.
 

	
 
/** Widgets used for the join status window. */
 
enum NetworkJoinStatusWidgets {
 
	NJSW_BACKGROUND, ///< Background
 
	NJSW_CANCELOK,   ///< Cancel/OK button
 
};
src/network/network_internal.h
Show inline comments
 
@@ -49,13 +49,13 @@ extern bool _ddc_fastforward;
 
#else
 
#define _ddc_fastforward (false)
 
#endif /* DEBUG_DUMP_COMMANDS */
 

	
 
typedef class ServerNetworkGameSocketHandler NetworkClientSocket;
 

	
 

	
 
/** Status of the clients during joining. */
 
enum NetworkJoinStatus {
 
	NETWORK_JOIN_STATUS_CONNECTING,
 
	NETWORK_JOIN_STATUS_AUTHORIZING,
 
	NETWORK_JOIN_STATUS_WAITING,
 
	NETWORK_JOIN_STATUS_DOWNLOADING,
 
	NETWORK_JOIN_STATUS_PROCESSING,
src/network/network_server.cpp
Show inline comments
 
@@ -40,14 +40,16 @@
 
DECLARE_POSTFIX_INCREMENT(ClientID)
 
/** The identifier counter for new clients (is never decreased) */
 
static ClientID _network_client_id = CLIENT_ID_FIRST;
 

	
 
/** Make very sure the preconditions given in network_type.h are actually followed */
 
assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
 
/** Yes... */
 
assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
 

	
 
/** The pool with clients. */
 
NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
 
INSTANTIATE_POOL_METHODS(NetworkClientSocket)
 

	
 
/** Instantiate the listen sockets. */
 
template SocketList TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED>::sockets;
 

	
 
@@ -293,12 +295,16 @@ static void NetworkHandleCommandQueue(Ne
 

	
 
/***********
 
 * Sending functions
 
 *   DEF_SERVER_SEND_COMMAND has parameter: NetworkClientSocket *cs
 
 ************/
 

	
 
/**
 
 * Send the client information about a client.
 
 * @param ci The client to send information about.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo(NetworkClientInfo *ci)
 
{
 
	if (ci->client_id != INVALID_CLIENT_ID) {
 
		Packet *p = new Packet(PACKET_SERVER_CLIENT_INFO);
 
		p->Send_uint32(ci->client_id);
 
		p->Send_uint8 (ci->client_playas);
 
@@ -306,12 +312,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 

	
 
		this->SendPacket(p);
 
	}
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send the client information about the companies. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
 
{
 
	/* Fetch the latest version of the stats */
 
	NetworkCompanyStats company_stats[MAX_COMPANIES];
 
	NetworkPopulateCompanyStats(company_stats);
 

	
 
@@ -368,12 +375,16 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	p->Send_bool  (false);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send an error to the client, and close its connection.
 
 * @param error The error to disconnect for.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error)
 
{
 
	char str[100];
 
	Packet *p = new Packet(PACKET_SERVER_ERROR);
 

	
 
	p->Send_uint8(error);
 
@@ -410,12 +421,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	}
 

	
 
	/* The client made a mistake, so drop his connection now! */
 
	return this->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
 
}
 

	
 
/** Send the check for the NewGRFs. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_CHECK_NEWGRFS);
 
	const GRFConfig *c;
 
	uint grf_count = 0;
 

	
 
@@ -429,24 +441,26 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	}
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Request the game password. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword()
 
{
 
	/* Invalid packet when status is STATUS_AUTH_GAME or higher */
 
	if (this->status >= STATUS_AUTH_GAME) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
 

	
 
	this->status = STATUS_AUTH_GAME;
 

	
 
	Packet *p = new Packet(PACKET_SERVER_NEED_GAME_PASSWORD);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Request the company password. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword()
 
{
 
	/* Invalid packet when status is STATUS_AUTH_COMPANY or higher */
 
	if (this->status >= STATUS_AUTH_COMPANY) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
 

	
 
	this->status = STATUS_AUTH_COMPANY;
 
@@ -455,12 +469,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	p->Send_uint32(_settings_game.game_creation.generation_seed);
 
	p->Send_string(_settings_client.network.network_id);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send the client a welcome message with some basic information. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome()
 
{
 
	Packet *p;
 
	NetworkClientSocket *new_cs;
 

	
 
	/* Invalid packet when status is AUTH or higher */
 
@@ -482,12 +497,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		}
 
	}
 
	/* Also send the info of the server */
 
	return this->SendClientInfo(NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
 
}
 

	
 
/** Tell the client that its put in a waiting queue. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait()
 
{
 
	int waiting = 0;
 
	NetworkClientSocket *new_cs;
 
	Packet *p;
 

	
 
@@ -500,13 +516,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	p = new Packet(PACKET_SERVER_WAIT);
 
	p->Send_uint8(waiting);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/* This sends the map to the client */
 
/** This sends the map to the client */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
 
{
 
	static uint sent_packets; // How many packets we did send succecfully last time
 

	
 
	if (this->status < STATUS_AUTHORIZED) {
 
		/* Illegal call, return error and ignore the packet */
 
@@ -606,23 +622,27 @@ NetworkRecvStatus ServerNetworkGameSocke
 
				break;
 
		}
 
	}
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell that a client joined.
 
 * @param client_id The client that joined.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin(ClientID client_id)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_JOIN);
 

	
 
	p->Send_uint32(client_id);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 

	
 
/** Tell the client that they may run to a particular frame. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_FRAME);
 
	p->Send_uint32(_frame_counter);
 
	p->Send_uint32(_frame_counter_max);
 
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
 
@@ -639,12 +659,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	}
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Request the client to sync. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_SYNC);
 
	p->Send_uint32(_frame_counter);
 
	p->Send_uint32(_sync_seed_1);
 

	
 
@@ -652,24 +673,36 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	p->Send_uint32(_sync_seed_2);
 
#endif
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send a command to the client to execute.
 
 * @param cp The command to send.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacket *cp)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_COMMAND);
 

	
 
	this->NetworkGameSocketHandler::SendCommand(p, cp);
 
	p->Send_uint32(cp->frame);
 
	p->Send_bool  (cp->my_cmd);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send a chat message.
 
 * @param action The action associated with the message.
 
 * @param client_id The origin of the chat message.
 
 * @param self_send Whether we did send the message.
 
 * @param msg The actual message.
 
 * @param data Arbitrary extra data.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_CHAT);
 

	
 
	p->Send_uint8 (action);
 
	p->Send_uint32(client_id);
 
@@ -678,76 +711,99 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	p->Send_uint64(data);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the client another client quit with an error.
 
 * @param client_id The client that quit.
 
 * @param errorno The reason the client quit.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit(ClientID client_id, NetworkErrorCode errorno)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_ERROR_QUIT);
 

	
 
	p->Send_uint32(client_id);
 
	p->Send_uint8 (errorno);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell the client another client quit.
 
 * @param client_id The client that quit.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit(ClientID client_id)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_QUIT);
 

	
 
	p->Send_uint32(client_id);
 

	
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Tell the client we're shutting down. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_SHUTDOWN);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Tell the client we're starting a new game. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_NEWGAME);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Send the result of a console action.
 
 * @param colour The colour of the result.
 
 * @param command The command that was executed.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16 colour, const char *command)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_RCON);
 

	
 
	p->Send_uint16(colour);
 
	p->Send_string(command);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/**
 
 * Tell that a client moved to another company.
 
 * @param client_id The client that moved.
 
 * @param company_id The company the client moved to.
 
 */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove(ClientID client_id, CompanyID company_id)
 
{
 
	Packet *p = new Packet(PACKET_SERVER_MOVE);
 

	
 
	p->Send_uint32(client_id);
 
	p->Send_uint8(company_id);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send an update about the company password states. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_COMPANY_UPDATE);
 

	
 
	p->Send_uint16(_network_company_passworded);
 
	this->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send an update about the max company/spectator counts. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate()
 
{
 
	Packet *p = new Packet(PACKET_SERVER_CONFIG_UPDATE);
 

	
 
	p->Send_uint8(_settings_client.network.max_companies);
 
	p->Send_uint8(_settings_client.network.max_spectators);
 
@@ -1165,13 +1221,22 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	/* With those 2 values we can calculate the lag realtime */
 
	this->last_frame_server = _frame_counter;
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 

	
 

	
 
/**
 
 * Send an actual chat message.
 
 * @param action The action that's performed.
 
 * @param desttype The type of destination.
 
 * @param dest The actual destination index.
 
 * @param msg The actual message.
 
 * @param from_id The origin of the message.
 
 * @param data Arbitrary data.
 
 * @param from_admin Whether the origin is an admin or not.
 
 */
 
void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data, bool from_admin)
 
{
 
	NetworkClientSocket *cs;
 
	const NetworkClientInfo *ci, *ci_own, *ci_to;
 

	
 
	switch (desttype) {
 
@@ -1496,13 +1561,16 @@ void NetworkPopulateCompanyStats(Network
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[NETWORK_VEH_PLANE]++;
 
			if (s->facilities & FACIL_DOCK)       npi->num_station[NETWORK_VEH_SHIP]++;
 
		}
 
	}
 
}
 

	
 
/* Send a packet to all clients with updated info about this client_id */
 
/**
 
 * Send updated client info of a particular client.
 
 * @param client_id The client to send it for.
 
 */
 
void NetworkUpdateClientInfo(ClientID client_id)
 
{
 
	NetworkClientSocket *cs;
 
	NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 

	
 
	if (ci == NULL) return;
 
@@ -1513,27 +1581,28 @@ void NetworkUpdateClientInfo(ClientID cl
 
		cs->SendClientInfo(ci);
 
	}
 

	
 
	NetworkAdminClientUpdate(ci);
 
}
 

	
 
/* Check if we want to restart the map */
 
/** Check if we want to restart the map */
 
static void NetworkCheckRestartMap()
 
{
 
	if (_settings_client.network.restart_game_year != 0 && _cur_year >= _settings_client.network.restart_game_year) {
 
		DEBUG(net, 0, "Auto-restarting map. Year %d reached", _cur_year);
 

	
 
		StartNewGameWithoutGUI(GENERATE_NEW_SEED);
 
	}
 
}
 

	
 
/* Check if the server has autoclean_companies activated
 
    Two things happen:
 
      1) If a company is not protected, it is closed after 1 year (for example)
 
      2) If a company is protected, protection is disabled after 3 years (for example)
 
           (and item 1. happens a year later) */
 
/** Check if the server has autoclean_companies activated
 
 * Two things happen:
 
 *     1) If a company is not protected, it is closed after 1 year (for example)
 
 *     2) If a company is protected, protection is disabled after 3 years (for example)
 
 *          (and item 1. happens a year later)
 
 */
 
static void NetworkAutoCleanCompanies()
 
{
 
	const NetworkClientInfo *ci;
 
	const Company *c;
 
	bool clients_in_company[MAX_COMPANIES];
 
	int vehicles_in_company[MAX_COMPANIES];
 
@@ -1597,14 +1666,17 @@ static void NetworkAutoCleanCompanies()
 
			/* It is not empty, reset the date */
 
			_network_company_states[c->index].months_empty = 0;
 
		}
 
	}
 
}
 

	
 
/* This function changes new_name to a name that is unique (by adding #1 ...)
 
 *  and it returns true if that succeeded. */
 
/**
 
 * Check whether a name is unique, and otherwise try to make it unique.
 
 * @param new_name The name to check/modify.
 
 * @return True if an unique name was achieved.
 
 */
 
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH])
 
{
 
	bool found_name = false;
 
	uint number = 0;
 
	char original_name[NETWORK_CLIENT_NAME_LENGTH];
 

	
 
@@ -1680,23 +1752,29 @@ void NetworkServerSetCompanyPassword(Com
 
	}
 

	
 
	strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
 
	NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
 
}
 

	
 
/* Handle the local command-queue */
 
/**
 
 * Handle the command-queue of a socket.
 
 * @param cs The socket to handle the queue for.
 
 */
 
static void NetworkHandleCommandQueue(NetworkClientSocket *cs)
 
{
 
	CommandPacket *cp;
 
	while ((cp = cs->outgoing_queue.Pop()) != NULL) {
 
		cs->SendCommand(cp);
 
		free(cp);
 
	}
 
}
 

	
 
/* This is called every tick if this is a _network_server */
 
/**
 
 * This is called every tick if this is a _network_server
 
 * @param send_frame Whether to send the frame to the clients.
 
 */
 
void NetworkServer_Tick(bool send_frame)
 
{
 
	NetworkClientSocket *cs;
 
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 
	bool send_sync = false;
 
#endif
 
@@ -1814,12 +1892,13 @@ void NetworkServerDailyLoop()
 
 */
 
const char *ServerNetworkGameSocketHandler::GetClientIP()
 
{
 
	return this->client_address.GetHostname();
 
}
 

	
 
/** Show the status message of all clients on the console. */
 
void NetworkServerShowStatusToConsole()
 
{
 
	static const char * const stat_str[] = {
 
		"inactive",
 
		"checking NewGRFs",
 
		"authorizing (server password)",
 
@@ -1857,12 +1936,17 @@ void NetworkServerSendConfigUpdate()
 

	
 
	FOR_ALL_CLIENT_SOCKETS(cs) {
 
		if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) cs->SendConfigUpdate();
 
	}
 
}
 

	
 
/**
 
 * Tell that a particular company is (not) passworded.
 
 * @param company_id The company that got/removed the password.
 
 * @param passworded Whether the password was received or removed.
 
 */
 
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded)
 
{
 
	if (NetworkCompanyIsPassworded(company_id) == passworded) return;
 

	
 
	SB(_network_company_passworded, company_id, 1, !!passworded);
 
	SetWindowClassesDirty(WC_COMPANY);
 
@@ -1906,33 +1990,48 @@ void NetworkServerDoMove(ClientID client
 
	NetworkUpdateClientInfo(client_id);
 

	
 
	NetworkAction action = (company_id == COMPANY_SPECTATOR) ? NETWORK_ACTION_COMPANY_SPECTATOR : NETWORK_ACTION_COMPANY_JOIN;
 
	NetworkServerSendChat(action, DESTTYPE_BROADCAST, 0, "", client_id, company_id + 1);
 
}
 

	
 
/**
 
 * Send an rcon reply to the client.
 
 * @param client_id The identifier of the client.
 
 * @param colour_code The colour of the text.
 
 * @param string The actual reply.
 
 */
 
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string)
 
{
 
	NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code, string);
 
}
 

	
 
static void NetworkServerSendError(ClientID client_id, NetworkErrorCode error)
 
{
 
	NetworkClientSocket::GetByClientID(client_id)->SendError(error);
 
}
 

	
 
/**
 
 * Kick a single client.
 
 * @param client_id The client to kick.
 
 */
 
void NetworkServerKickClient(ClientID client_id)
 
{
 
	if (client_id == CLIENT_ID_SERVER) return;
 
	NetworkServerSendError(client_id, NETWORK_ERROR_KICKED);
 
	NetworkClientSocket::GetByClientID(client_id)->SendError(NETWORK_ERROR_KICKED);
 
}
 

	
 
/**
 
 * Ban, or kick, everyone joined from the given client's IP.
 
 * @param client_id The client to check for.
 
 * @param ban Whether to ban or kick.
 
 */
 
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
 
{
 
	return NetworkServerKickOrBanIP(NetworkClientSocket::GetByClientID(client_id)->GetClientIP(), ban);
 
}
 

	
 
/**
 
 * Kick or ban someone based on an IP address.
 
 * @param ip The IP address/range to ban/kick.
 
 * @param ban Whether to ban or just kick.
 
 */
 
uint NetworkServerKickOrBanIP(const char *ip, bool ban)
 
{
 
	/* Add address to ban-list */
 
	if (ban) *_network_ban_list.Append() = strdup(ip);
 

	
 
	uint n = 0;
 
@@ -1947,12 +2046,17 @@ uint NetworkServerKickOrBanIP(const char
 
		}
 
	}
 

	
 
	return n;
 
}
 

	
 
/**
 
 * Check whether a particular company has clients.
 
 * @param company The company to check.
 
 * @return True if at least one client is joined to the company.
 
 */
 
bool NetworkCompanyHasClients(CompanyID company)
 
{
 
	const NetworkClientInfo *ci;
 
	FOR_ALL_CLIENT_INFOS(ci) {
 
		if (ci->client_playas == company) return true;
 
	}
src/network/network_server.h
Show inline comments
 
@@ -16,13 +16,15 @@
 

	
 
#include "network_internal.h"
 
#include "core/tcp_listen.h"
 
#include "../thread/thread.h"
 

	
 
class ServerNetworkGameSocketHandler;
 
/** Make the code look slightliy nicer/simpler. */
 
typedef ServerNetworkGameSocketHandler NetworkClientSocket;
 
/** Pool with all client sockets. */
 
typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS, PT_NCLIENT> NetworkClientSocketPool;
 
extern NetworkClientSocketPool _networkclientsocket_pool;
 

	
 
/** Class for handling the server side of the game connection. */
 
class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
 
protected:
 
@@ -122,13 +124,23 @@ public:
 
	static ServerNetworkGameSocketHandler *GetByClientID(ClientID client_id);
 
};
 

	
 
void NetworkServer_Tick(bool send_frame);
 
void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed = true);
 

	
 
/**
 
 * Iterate over all the sockets from a given starting point.
 
 * @param var The variable to iterate with.
 
 * @param start The start of the iteration.
 
 */
 
#define FOR_ALL_CLIENT_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientSocket, clientsocket_index, var, start)
 

	
 
/**
 
 * Iterate over all the sockets.
 
 * @param var The variable to iterate with.
 
 */
 
#define FOR_ALL_CLIENT_SOCKETS(var) FOR_ALL_CLIENT_SOCKETS_FROM(var, 0)
 

	
 
#else /* ENABLE_NETWORK */
 
/* Network function stubs when networking is disabled */
 

	
 
static inline void NetworkServerMonthlyLoop() {}
0 comments (0 inline, 0 general)