network_server.cpp File Reference

Server part of the network protocol. More...

#include "../stdafx.h"
#include "../debug.h"
#include "../strings_func.h"
#include "../date_func.h"
#include "network_server.h"
#include "network_udp.h"
#include "network.h"
#include "network_base.h"
#include "../console_func.h"
#include "../company_base.h"
#include "../command_func.h"
#include "../saveload/saveload.h"
#include "../station_base.h"
#include "../genworld.h"
#include "../fileio_func.h"
#include "../company_func.h"
#include "../company_gui.h"
#include "../window_func.h"
#include "../roadveh.h"
#include "../rev.h"
#include "table/strings.h"

Go to the source code of this file.

Typedefs

typedef NetworkRecvStatus NetworkServerPacket (NetworkClientSocket *cs, Packet *p)

Functions

static void NetworkHandleCommandQueue (NetworkClientSocket *cs)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_CLIENT_INFO (NetworkClientSocket *cs, NetworkClientInfo *ci)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_COMPANY_INFO)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_ERROR (NetworkClientSocket *cs, NetworkErrorCode error)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_CHECK_NEWGRFS (NetworkClientSocket *cs)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_NEED_PASSWORD (NetworkClientSocket *cs, NetworkPasswordType type)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_WELCOME)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_WAIT)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_MAP)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_JOIN (NetworkClientSocket *cs, ClientID client_id)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_FRAME)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_SYNC)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_COMMAND (NetworkClientSocket *cs, const CommandPacket *cp)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_CHAT (NetworkClientSocket *cs, NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_ERROR_QUIT (NetworkClientSocket *cs, ClientID client_id, NetworkErrorCode errorno)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_QUIT (NetworkClientSocket *cs, ClientID client_id)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_SHUTDOWN)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_NEWGAME)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_RCON (NetworkClientSocket *cs, uint16 colour, const char *command)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_MOVE (NetworkClientSocket *cs, ClientID client_id, CompanyID company_id)
DEF_SERVER_SEND_COMMAND_PARAM() PACKET_SERVER_COMPANY_UPDATE (NetworkClientSocket *cs)
 DEF_SERVER_SEND_COMMAND (PACKET_SERVER_CONFIG_UPDATE)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_COMPANY_INFO)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_NEWGRFS_CHECKED)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_JOIN)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_PASSWORD)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_GETMAP)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_MAP_OK)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_COMMAND)
 The client has done a command and wants us to handle it.
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_ERROR)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_QUIT)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_ACK)
void NetworkServerSendChat (NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_CHAT)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_SET_PASSWORD)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_SET_NAME)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_RCON)
 DEF_SERVER_RECEIVE_COMMAND (PACKET_CLIENT_MOVE)
 assert_compile (lengthof(_network_server_packet)==PACKET_END)
void NetworkPopulateCompanyStats (NetworkCompanyStats *stats)
 Populate the company stats.
void NetworkUpdateClientInfo (ClientID client_id)
static void NetworkCheckRestartMap ()
static void NetworkAutoCleanCompanies ()
bool NetworkFindName (char new_name[NETWORK_CLIENT_NAME_LENGTH])
bool NetworkServerChangeClientName (ClientID client_id, const char *new_name)
 Change the client name of the given client.
void NetworkServer_ReadPackets (NetworkClientSocket *cs)
void NetworkServer_Tick (bool send_frame)
void NetworkServerYearlyLoop ()
void NetworkServerMonthlyLoop ()
void NetworkServerChangeOwner (Owner current_owner, Owner new_owner)
const char * GetClientIP (NetworkClientInfo *ci)
void NetworkServerShowStatusToConsole ()
void NetworkServerSendConfigUpdate ()
 Send Config Update.
void NetworkServerUpdateCompanyPassworded (CompanyID company_id, bool passworded)
void NetworkServerDoMove (ClientID client_id, CompanyID company_id)
 Handle the tid-bits of moving a client from one company to another.
void NetworkServerSendRcon (ClientID client_id, ConsoleColour colour_code, const char *string)
void NetworkServerSendError (ClientID client_id, NetworkErrorCode error)
void NetworkServerKickClient (ClientID client_id)
void NetworkServerBanIP (const char *banip)
bool NetworkCompanyHasClients (CompanyID company)

Variables

static NetworkServerPacket *const _network_server_packet []

Detailed Description

Server part of the network protocol.

Definition in file network_server.cpp.


Function Documentation

DEF_SERVER_RECEIVE_COMMAND ( PACKET_CLIENT_COMMAND   ) 

The client has done a command and wants us to handle it.

Parameters:
*cs the connected client that has sent the command
*p the packet in which the command was sent

Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs to match the company in the packet. If it doesn't, the client has done something pretty naughty (or a bug), and will be kicked

Todo:
CMD_COMPANY_CTRL with p1 = 0 announces a new company to the server. To give the company the correct ID, the server injects p2 and executes the command. Any other p1 is prohibited. Pretty ugly and should be redone together with its function.
See also:
CmdCompanyCtrl()

Definition at line 855 of file network_server.cpp.

References _settings_client, CommandContainer::callback, NetworkClientSocket::client_id, NetworkClientInfo::client_id, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, CommandContainer::cmd, CMD_COMPANY_CTRL, CMD_SERVER, CMD_SPECTATOR, CommandPacket::company, COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, DESTTYPE_CLIENT, CommandPacket::frame, GetCommandFlags(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), NetworkSocketHandler::HasClientQuit(), IConsolePrintF(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NetworkSettings::max_companies, CommandPacket::my_cmd, ClientSettings::network, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_RECV_STATUS_OKAY, NetworkAddCommandQueue(), CommandPacket::next, CommandContainer::p1, CommandContainer::p2, NetworkClientSocket::Recv_Command(), NetworkClientSocket::status, STATUS_DONE_MAP, and STATUS_MAP.

void NetworkPopulateCompanyStats ( NetworkCompanyStats stats  ) 
bool NetworkServerChangeClientName ( ClientID  client_id,
const char *  new_name 
)

Change the client name of the given client.

Parameters:
client_id the client to change the name of
new_name the new name for the client
Returns:
true iff the name was changed

Definition at line 1532 of file network_server.cpp.

References NetworkClientInfo::client_name, lastof, NetworkFindClientInfoFromClientID(), and strecpy().

void NetworkServerDoMove ( ClientID  client_id,
CompanyID  company_id 
)

Handle the tid-bits of moving a client from one company to another.

Parameters:
client_id id of the client we want to move.
company_id id of the company we want to move the client to.
Returns:
void

Definition at line 1749 of file network_server.cpp.

References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, DESTTYPE_BROADCAST, NetworkFindClientInfoFromClientID(), NetworkFindClientStateFromClientID(), and SetLocalCompany().

Referenced by CompanyWindow::OnClick().


Generated on Wed Mar 3 23:32:34 2010 for OpenTTD by  doxygen 1.6.1