OpenTTD
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | Private Types | Private Attributes | Friends
ClientNetworkGameSocketHandler Class Reference

Class for handling the client side of the game connection. More...

#include <network_client.h>

Inheritance diagram for ClientNetworkGameSocketHandler:
ZeroedMemoryAllocator NetworkGameSocketHandler NetworkTCPSocketHandler NetworkSocketHandler

Public Member Functions

 ClientNetworkGameSocketHandler (SOCKET s)
 Create a new socket for the client side of the game connection.
 ~ClientNetworkGameSocketHandler ()
 Clear whatever we assigned.
NetworkRecvStatus CloseConnection (NetworkRecvStatus status)
 Close the network connection due to the given status.
void ClientError (NetworkRecvStatus res)
 Handle an error coming from the client side.
- Public Member Functions inherited from ZeroedMemoryAllocator
void * operator new (size_t size)
 Memory allocator for a single class instance.
void * operator new[] (size_t size)
 Memory allocator for an array of class instances.
void operator delete (void *ptr)
 Memory release for a single class instance.
void operator delete[] (void *ptr)
 Memory release for an array of class instances.
- Public Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus CloseConnection (bool error=true)
 Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
void SetInfo (NetworkClientInfo *info)
 Sets the client info for this socket handler.
NetworkClientInfoGetInfo () const
 Gets the client info of this socket handler.
NetworkRecvStatus ReceivePackets ()
 Do the actual receiving of packets.
const char * ReceiveCommand (Packet *p, CommandPacket *cp)
 Receives a command from the network.
void SendCommand (Packet *p, const CommandPacket *cp)
 Sends a command over the network.
- Public Member Functions inherited from NetworkTCPSocketHandler
bool IsConnected () const
 Whether this socket is currently bound to a socket.
virtual void SendPacket (Packet *packet)
 This function puts the packet in the send-queue and it is send as soon as possible.
SendPacketsState SendPackets (bool closing_down=false)
 Sends all the buffered packets out for this client.
virtual PacketReceivePacket ()
 Receives a packet for the given client.
bool CanSendReceive ()
 Check whether this socket can send or receive something.
bool HasSendQueue ()
 Whether there is something pending in the send queue.
 NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
 Construct a socket handler for a TCP connection.
- Public Member Functions inherited from NetworkSocketHandler
 NetworkSocketHandler ()
 Create a new unbound socket.
virtual ~NetworkSocketHandler ()
 Close the socket when destructing the socket handler.
virtual void Close ()
 Really close the socket.
bool HasClientQuit () const
 Whether the current client connected to the socket has quit.
void Reopen ()
 Reopen the socket so we can send/receive stuff again.
void SendGRFIdentifier (Packet *p, const GRFIdentifier *grf)
 Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
void ReceiveGRFIdentifier (Packet *p, GRFIdentifier *grf)
 Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
void SendCompanyInformation (Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len=NETWORK_COMPANY_NAME_LENGTH)
 Package some generic company information into a packet.

Static Public Member Functions

static NetworkRecvStatus SendCompanyInformationQuery ()
 Query the server for company information.
static NetworkRecvStatus SendJoin ()
 Tell the server we would like to join.
static NetworkRecvStatus SendCommand (const CommandPacket *cp)
 Send a command to the server.
static NetworkRecvStatus SendError (NetworkErrorCode errorno)
 Send an error-packet over the network.
static NetworkRecvStatus SendQuit ()
 Tell the server we would like to quit.
static NetworkRecvStatus SendAck ()
 Send an acknowledgement from the server's ticks.
static NetworkRecvStatus SendGamePassword (const char *password)
 Set the game password as requested.
static NetworkRecvStatus SendCompanyPassword (const char *password)
 Set the company password as requested.
static NetworkRecvStatus SendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data)
 Send a chat-packet over the network.
static NetworkRecvStatus SendSetPassword (const char *password)
 Tell the server that we like to change the password of the company.
static NetworkRecvStatus SendSetName (const char *name)
 Tell the server that we like to change the name of the client.
static NetworkRecvStatus SendRCon (const char *password, const char *command)
 Send a console command.
static NetworkRecvStatus SendMove (CompanyID company, const char *password)
 Ask the server to move us.
static bool IsConnected ()
 Check whether the client is actually connected (and in the game).
static void Send ()
 Send the packets of this socket handler.
static bool Receive ()
 Check whether we received/can send some data from/to the server and when that's the case handle it appropriately.
static bool GameLoop ()
 Actual game loop for the client.

Protected Member Functions

virtual NetworkRecvStatus Receive_SERVER_FULL (Packet *p)
 Notification that the server is full.
virtual NetworkRecvStatus Receive_SERVER_BANNED (Packet *p)
 Notification that the client trying to join is banned.
virtual NetworkRecvStatus Receive_SERVER_ERROR (Packet *p)
 The client made an error: uint8 Error code caused (see NetworkErrorCode).
virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO (Packet *p)
 Sends information about the companies (one packet per company): uint8 Version of the structure of this packet (NETWORK_COMPANY_INFO_VERSION).
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO (Packet *p)
 Send information about a client: uint32 ID of the client (always unique on a server.
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD (Packet *p)
 Indication to the client that the server needs a game password.
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD (Packet *p)
 Indication to the client that the server needs a company password: uint32 Generation seed.
virtual NetworkRecvStatus Receive_SERVER_WELCOME (Packet *p)
 The client is joined and ready to receive his map: uint32 Own client ID.
virtual NetworkRecvStatus Receive_SERVER_WAIT (Packet *p)
 Notification that another client is currently receiving the map: uint8 Number of clients waiting in front of you.
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN (Packet *p)
 Sends that the server will begin with sending the map to the client: uint32 Current frame.
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE (Packet *p)
 Sends the size of the map to the client.
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA (Packet *p)
 Sends the data of the map to the client: Contains a part of the map (until max size of packet).
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE (Packet *p)
 Sends that all data of the map are sent to the client:
virtual NetworkRecvStatus Receive_SERVER_JOIN (Packet *p)
 A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32 ID of the client that just joined the game.
virtual NetworkRecvStatus Receive_SERVER_FRAME (Packet *p)
 Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far may the client walk before the server?) uint32 General seed 1 (dependent on compile settings, not default).
virtual NetworkRecvStatus Receive_SERVER_SYNC (Packet *p)
 Sends a sync-check to the client: uint32 Frame counter.
virtual NetworkRecvStatus Receive_SERVER_COMMAND (Packet *p)
 Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
virtual NetworkRecvStatus Receive_SERVER_CHAT (Packet *p)
 Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
virtual NetworkRecvStatus Receive_SERVER_QUIT (Packet *p)
 Notification that a client left the game: uint32 ID of the client.
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT (Packet *p)
 Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of the client that caused the error.
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN (Packet *p)
 Let the clients know that the server is closing.
virtual NetworkRecvStatus Receive_SERVER_NEWGAME (Packet *p)
 Let the clients know that the server is loading a new map.
virtual NetworkRecvStatus Receive_SERVER_RCON (Packet *p)
 Send the result of an issues RCon command back to the client: uint16 Colour code.
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS (Packet *p)
 Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repeated this many times, i.e.
virtual NetworkRecvStatus Receive_SERVER_MOVE (Packet *p)
 Move a client from one company into another: uint32 ID of the client.
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE (Packet *p)
 Update the clients knowledge of which company is password protected: uint16 Bitwise representation of each company.
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE (Packet *p)
 Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.
void CheckConnection ()
 Check the connection's state, i.e.
- Protected Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus ReceiveInvalidPacket (PacketGameType type)
 Helper for logging receiving invalid packets.
virtual NetworkRecvStatus Receive_CLIENT_JOIN (Packet *p)
 Try to join the server: string OpenTTD revision (norev000 if no revision).
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO (Packet *p)
 Request company information (in detail).
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD (Packet *p)
 Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD (Packet *p)
 Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).
virtual NetworkRecvStatus Receive_CLIENT_GETMAP (Packet *p)
 Request the map from the server.
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK (Packet *p)
 Tell the server that we are done receiving/loading the map.
virtual NetworkRecvStatus Receive_CLIENT_ACK (Packet *p)
 Tell the server we are done with this frame: uint32 Current frame counter of the client.
virtual NetworkRecvStatus Receive_CLIENT_COMMAND (Packet *p)
 Send a DoCommand to the Server: uint8 ID of the company (0..MAX_COMPANIES-1).
virtual NetworkRecvStatus Receive_CLIENT_CHAT (Packet *p)
 Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction).
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD (Packet *p)
 Set the password for the clients current company: string The password.
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME (Packet *p)
 Gives the client a new name: string New name of the client.
virtual NetworkRecvStatus Receive_CLIENT_QUIT (Packet *p)
 The client is quitting the game.
virtual NetworkRecvStatus Receive_CLIENT_ERROR (Packet *p)
 The client made an error and is quitting the game.
virtual NetworkRecvStatus Receive_CLIENT_RCON (Packet *p)
 Send an RCon command to the server: string RCon password.
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED (Packet *p)
 Tell the server that we have the required GRFs.
virtual NetworkRecvStatus Receive_CLIENT_MOVE (Packet *p)
 Request the server to move this client into another company: uint8 ID of the company the client wants to join.
NetworkRecvStatus HandlePacket (Packet *p)
 Handle the given packet, i.e.
 NetworkGameSocketHandler (SOCKET s)
 Create a new socket for the game connection.

Static Protected Member Functions

static NetworkRecvStatus SendNewGRFsOk ()
 Tell the server we got all the NewGRFs.
static NetworkRecvStatus SendGetMap ()
 Request the map from the server.
static NetworkRecvStatus SendMapOk ()
 Tell the server we received the complete map.

Static Protected Attributes

static
ClientNetworkGameSocketHandler
my_client = NULL
 This is us!

Private Types

enum  ServerStatus {
  STATUS_INACTIVE, STATUS_COMPANY_INFO, STATUS_JOIN, STATUS_NEWGRFS_CHECK,
  STATUS_AUTH_GAME, STATUS_AUTH_COMPANY, STATUS_AUTHORIZED, STATUS_MAP_WAIT,
  STATUS_MAP, STATUS_ACTIVE, STATUS_END
}
 Status of the connection with the server. More...

Private Attributes

struct PacketReadersavegame
 Packet reader for reading the savegame.
byte token
 The token we need to send back to the server to prove we're the right client.
ServerStatus status
 Status of the connection with the server.

Friends

void NetworkExecuteLocalCommandQueue ()
 Execute all commands on the local command queue that ought to be executed this frame.
void NetworkClose (bool close_admins)
 Close current connections.

Additional Inherited Members

- Data Fields inherited from NetworkGameSocketHandler
ClientID client_id
 Client identifier.
uint32 last_frame
 Last frame we have executed.
uint32 last_frame_server
 Last frame the server has executed.
CommandQueue incoming_queue
 The command-queue awaiting handling.
uint last_packet
 Time we received the last frame.

Detailed Description

Class for handling the client side of the game connection.

Definition at line 20 of file network_client.h.

Member Enumeration Documentation

Status of the connection with the server.

Enumerator:
STATUS_INACTIVE 

The client is not connected nor active.

STATUS_COMPANY_INFO 

We are trying to get company information.

STATUS_JOIN 

We are trying to join a server.

STATUS_NEWGRFS_CHECK 

Last action was checking NewGRFs.

STATUS_AUTH_GAME 

Last action was requesting game (server) password.

STATUS_AUTH_COMPANY 

Last action was requesting company password.

STATUS_AUTHORIZED 

The client is authorized at the server.

STATUS_MAP_WAIT 

The client is waiting as someone else is downloading the map.

STATUS_MAP 

The client is downloading the map.

STATUS_ACTIVE 

The client is active within in the game.

STATUS_END 

Must ALWAYS be on the end of this list!! (period)

Definition at line 26 of file network_client.h.

Constructor & Destructor Documentation

ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler ( SOCKET  s)

Create a new socket for the client side of the game connection.

Parameters
sThe socket to connect with.

Definition at line 126 of file network_client.cpp.

References my_client.

ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler ( )

Clear whatever we assigned.

Definition at line 133 of file network_client.cpp.

References my_client, and savegame.

Member Function Documentation

void ClientNetworkGameSocketHandler::CheckConnection ( )
protected

Check the connection's state, i.e.

is the connection still up?

Definition at line 1137 of file network_client.cpp.

References _realtime_tick, CloseConnection(), INVALID_STRING_ID, NetworkGameSocketHandler::last_packet, SetDParam(), ShowErrorMessage(), status, STATUS_AUTHORIZED, WL_CRITICAL, and WL_INFO.

Referenced by Send().

void ClientNetworkGameSocketHandler::ClientError ( NetworkRecvStatus  res)
NetworkRecvStatus ClientNetworkGameSocketHandler::CloseConnection ( NetworkRecvStatus  status)
virtual

Close the network connection due to the given status.

Parameters
statusThe reason the connection got closed.

Implements NetworkGameSocketHandler.

Definition at line 141 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, DEBUG, NetworkGameSocketHandler::GetInfo(), MILLISECONDS_PER_TICK, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPackets(), NetworkTCPSocketHandler::sock, and status.

Referenced by CheckConnection(), ClientError(), and NetworkClose().

bool ClientNetworkGameSocketHandler::GameLoop ( )
static

Actual game loop for the client.

Returns
Whether everything went okay, or not.

Definition at line 238 of file network_client.cpp.

References _date, _date_fract, _frame_counter, _network_first_time, _random, _sync_frame, _sync_seed_1, ClientError(), DEBUG, my_client, NETWORK_RECV_STATUS_DESYNC, NetworkExecuteLocalCommandQueue, SendAck(), Randomizer::state, and StateGameLoop().

bool ClientNetworkGameSocketHandler::IsConnected ( )
static

Check whether the client is actually connected (and in the game).

Returns
True when the client is connected.

Definition at line 512 of file network_client.cpp.

References my_client, status, and STATUS_ACTIVE.

Referenced by DEF_CONSOLE_HOOK().

bool ClientNetworkGameSocketHandler::Receive ( )
static

Check whether we received/can send some data from/to the server and when that's the case handle it appropriately.

Returns
true when everything went okay.

Definition at line 213 of file network_client.cpp.

References _networking, NetworkTCPSocketHandler::CanSendReceive(), ClientError(), my_client, NETWORK_RECV_STATUS_OKAY, and NetworkGameSocketHandler::ReceivePackets().

Referenced by NetworkReceive().

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED ( Packet p)
protectedvirtual

Notification that the client trying to join is banned.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 534 of file network_client.cpp.

References DeleteWindowById(), INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_BANNED, ShowErrorMessage(), WC_NETWORK_STATUS_WINDOW, WL_CRITICAL, and WN_NETWORK_STATUS_WINDOW_JOIN.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT ( Packet p)
protectedvirtual

Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).

uint32 ID of the client (origin of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64 data (used e.g. for 'give money' actions).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 940 of file network_client.cpp.

References _network_own_client_id, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_playas, NetworkClientInfo::GetByClientID(), GetDrawStringCompanyColour(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), lastof, NETWORK_CHAT_LENGTH, NETWORK_NAME_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_bool(), Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint64(), Packet::Recv_uint8(), seprintf(), SetDParam(), status, and STATUS_ACTIVE.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS ( Packet p)
protectedvirtual

Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repeated this many times, i.e.

per GRF data). uint32 GRF ID 16 * uint8 MD5 checksum of the GRF

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 678 of file network_client.cpp.

References BSWAP32(), DEBUG, FGCM_EXACT, FindGRFConfig(), GRFIdentifier::grfid, INVALID_STRING_ID, lastof, GRFIdentifier::md5sum, md5sumToString(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_NEWGRF_MISMATCH, NETWORK_RECV_STATUS_OKAY, NetworkSocketHandler::ReceiveGRFIdentifier(), Packet::Recv_uint8(), SendNewGRFsOk(), ShowErrorMessage(), status, STATUS_JOIN, and WL_CRITICAL.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO ( Packet p)
protectedvirtual
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND ( Packet p)
protectedvirtual

Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).

uint32 ID of the command (see command.h). uint32 P1 (free variable used in DoCommand). uint32 P2. uint32 Tile where this is taking place. string Text. uint8 ID of the callback. uint32 Frame of execution.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 921 of file network_client.cpp.

References CommandQueue::Append(), CC_ERROR, CommandPacket::frame, IConsolePrintF(), NetworkGameSocketHandler::incoming_queue, CommandPacket::my_cmd, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NetworkGameSocketHandler::ReceiveCommand(), Packet::Recv_bool(), Packet::Recv_uint32(), status, and STATUS_ACTIVE.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO ( Packet p)
protectedvirtual

Sends information about the companies (one packet per company): uint8 Version of the structure of this packet (NETWORK_COMPANY_INFO_VERSION).

bool Contains data (false marks the end of updates). uint8 ID of the company. string Name of the company. uint32 Year the company was inaugurated. uint64 Value. uint64 Money. uint64 Income. uint16 Performance (last quarter). bool Company is password protected. uint16 Number of trains. uint16 Number of lorries. uint16 Number of busses. uint16 Number of planes. uint16 Number of ships. uint16 Number of train stations. uint16 Number of lorry stations. uint16 Number of bus stops. uint16 Number of airports and heliports. uint16 Number of harbours. bool Company is an AI. string Client names (comma separated list)

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 543 of file network_client.cpp.

References NetworkCompanyStats::ai, NetworkCompanyInfo::clients, NetworkCompanyInfo::company_name, NetworkCompanyInfo::company_value, GetLobbyCompanyInfo(), NetworkSocketHandler::HasClientQuit(), NetworkCompanyInfo::inaugurated_year, NetworkCompanyInfo::income, MAX_COMPANIES, NetworkCompanyInfo::money, NETWORK_COMPANY_INFO_VERSION, NETWORK_RECV_STATUS_CLOSE_QUERY, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NetworkCompanyStats::num_station, NetworkCompanyStats::num_vehicle, NetworkCompanyInfo::performance, Packet::Recv_bool(), Packet::Recv_string(), Packet::Recv_uint16(), Packet::Recv_uint32(), Packet::Recv_uint64(), Packet::Recv_uint8(), SetWindowDirty(), status, STATUS_COMPANY_INFO, NetworkCompanyInfo::use_password, WC_NETWORK_WINDOW, and WN_NETWORK_WINDOW_LOBBY.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE ( Packet p)
protectedvirtual

Update the clients knowledge of which company is password protected: uint16 Bitwise representation of each company.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1124 of file network_client.cpp.

References _network_company_passworded, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint16(), SetWindowClassesDirty(), status, STATUS_ACTIVE, and WC_COMPANY.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE ( Packet p)
protectedvirtual

Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.

uint8 Maximum number of spectators allowed.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1114 of file network_client.cpp.

References NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint8(), status, and STATUS_ACTIVE.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR ( Packet p)
protectedvirtual

The client made an error: uint8 Error code caused (see NetworkErrorCode).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 640 of file network_client.cpp.

References DeleteWindowById(), error(), INVALID_STRING_ID, lengthof, NETWORK_RECV_STATUS_SERVER_ERROR, Packet::Recv_uint8(), ShowErrorMessage(), WC_NETWORK_STATUS_WINDOW, WL_CRITICAL, and WN_NETWORK_STATUS_WINDOW_JOIN.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT ( Packet p)
protectedvirtual

Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of the client that caused the error.

uint8 Code of the error caused (see NetworkErrorCode).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 992 of file network_client.cpp.

References CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkClientInfo::GetByClientID(), GetNetworkErrorMsg(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), SetWindowDirty(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME ( Packet p)
protectedvirtual

Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far may the client walk before the server?) uint32 General seed 1 (dependent on compile settings, not default).

uint32 General seed 2 (dependent on compile settings, not default). uint8 Random token to validate the client is actually listening (only occasionally present).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 875 of file network_client.cpp.

References _frame_counter, _frame_counter_max, _frame_counter_server, _network_first_time, _sync_frame, _sync_seed_1, DAY_TICKS, DEBUG, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::pos, Packet::Recv_uint32(), Packet::Recv_uint8(), SendAck(), Packet::size, status, STATUS_ACTIVE, and token.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL ( Packet p)
protectedvirtual

Notification that the server is full.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 525 of file network_client.cpp.

References DeleteWindowById(), INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_FULL, ShowErrorMessage(), WC_NETWORK_STATUS_WINDOW, WL_CRITICAL, and WN_NETWORK_STATUS_WINDOW_JOIN.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN ( Packet p)
protectedvirtual

A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32 ID of the client that just joined the game.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1029 of file network_client.cpp.

References CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkClientInfo::GetByClientID(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), SetWindowDirty(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN ( Packet p)
protectedvirtual

Sends that the server will begin with sending the map to the client: uint32 Current frame.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 773 of file network_client.cpp.

References _frame_counter, _frame_counter_max, _frame_counter_server, _network_join_bytes, _network_join_bytes_total, _network_join_status, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), savegame, SetWindowDirty(), status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA ( Packet p)
protectedvirtual

Sends the data of the map to the client: Contains a part of the map (until max size of packet).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 804 of file network_client.cpp.

References _network_join_bytes, PacketReader::AddPacket(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, savegame, SetWindowDirty(), status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN, and PacketReader::written_bytes.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE ( Packet p)
protectedvirtual
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE ( Packet p)
protectedvirtual

Sends the size of the map to the client.

uint32 Size of the (compressed) map (in bytes).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 793 of file network_client.cpp.

References _network_join_bytes_total, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), savegame, SetWindowDirty(), status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE ( Packet p)
protectedvirtual
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD ( Packet p)
protectedvirtual

Indication to the client that the server needs a company password: uint32 Generation seed.

string Network ID of the server.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 726 of file network_client.cpp.

References _network_join_company_password, NetworkSocketHandler::HasClientQuit(), NETWORK_COMPANY_PASSWORD, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_string(), Packet::Recv_uint32(), SendCompanyPassword(), status, STATUS_AUTH_COMPANY, and StrEmpty().

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD ( Packet p)
protectedvirtual

Indication to the client that the server needs a game password.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 711 of file network_client.cpp.

References _network_join_server_password, NETWORK_GAME_PASSWORD, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, SendGamePassword(), status, STATUS_AUTH_GAME, and StrEmpty().

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME ( Packet p)
protectedvirtual

Let the clients know that the server is loading a new map.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1056 of file network_client.cpp.

References _network_own_client_id, _network_reconnect, INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_ERROR, ShowErrorMessage(), status, STATUS_JOIN, and WL_CRITICAL.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT ( Packet p)
protectedvirtual

Notification that a client left the game: uint32 ID of the client.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1009 of file network_client.cpp.

References CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, DEBUG, NetworkClientInfo::GetByClientID(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), SetWindowDirty(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_RCON ( Packet p)
protectedvirtual

Send the result of an issues RCon command back to the client: uint16 Colour code.

string Output of the RCon command

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1071 of file network_client.cpp.

References IConsolePrint(), IsValidConsoleColour(), NETWORK_RCONCOMMAND_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_string(), Packet::Recv_uint16(), status, and STATUS_AUTHORIZED.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN ( Packet p)
protectedvirtual

Let the clients know that the server is closing.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1045 of file network_client.cpp.

References INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_ERROR, ShowErrorMessage(), status, STATUS_JOIN, and WL_CRITICAL.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC ( Packet p)
protectedvirtual

Sends a sync-check to the client: uint32 Frame counter.

uint32 General seed 1. uint32 General seed 2 (dependent on compile settings, not default).

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 908 of file network_client.cpp.

References _sync_frame, _sync_seed_1, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), status, and STATUS_ACTIVE.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT ( Packet p)
protectedvirtual

Notification that another client is currently receiving the map: uint8 Number of clients waiting in front of you.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 760 of file network_client.cpp.

References _network_join_status, _network_join_waiting, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint8(), SetWindowDirty(), status, STATUS_MAP_WAIT, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME ( Packet p)
protectedvirtual

The client is joined and ready to receive his map: uint32 Own client ID.

uint32 Generation seed. string Network ID of the server.

Parameters
pThe packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 745 of file network_client.cpp.

References _network_own_client_id, NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_string(), Packet::Recv_uint32(), SendGetMap(), status, and STATUS_AUTHORIZED.

void ClientNetworkGameSocketHandler::Send ( )
static

Send the packets of this socket handler.

Definition at line 228 of file network_client.cpp.

References CheckConnection(), my_client, and NetworkTCPSocketHandler::SendPackets().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendAck ( )
static
NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand ( const CommandPacket cp)
static

Send a command to the server.

Parameters
cpThe command to send.

Definition at line 409 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_COMMAND, and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkSendCommand().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyInformationQuery ( )
static
NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword ( const char *  password)
static
NetworkRecvStatus ClientNetworkGameSocketHandler::SendGamePassword ( const char *  password)
static

Set the game password as requested.

Parameters
passwordThe game password.

Definition at line 354 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_GAME_PASSWORD, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkJoinStatusWindow::OnQueryTextFinished(), and Receive_SERVER_NEED_GAME_PASSWORD().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendGetMap ( )
staticprotected

Request the map from the server.

Definition at line 375 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_GETMAP, NetworkTCPSocketHandler::SendPacket(), status, and STATUS_MAP_WAIT.

Referenced by Receive_SERVER_WELCOME().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin ( )
static
NetworkRecvStatus ClientNetworkGameSocketHandler::SendMapOk ( )
staticprotected

Tell the server we received the complete map.

Definition at line 385 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_MAP_OK, NetworkTCPSocketHandler::SendPacket(), status, and STATUS_ACTIVE.

Referenced by Receive_SERVER_MAP_DONE().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove ( CompanyID  company,
const char *  password 
)
static

Ask the server to move us.

Parameters
companyThe company to move to.
passwordThe password of the company to move to.

Definition at line 499 of file network_client.cpp.

References GenerateCompanyPasswordHash(), my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_MOVE, Packet::Send_string(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkClientRequestMove().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendNewGRFsOk ( )
staticprotected

Tell the server we got all the NewGRFs.

Definition at line 343 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_NEWGRFS_CHECKED, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_SERVER_CHECK_NEWGRFS().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon ( const char *  pass,
const char *  command 
)
static

Send a console command.

Parameters
passThe password for the remote command.
commandThe actual command.

Definition at line 485 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_RCON, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkClientSendRcon().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetName ( const char *  name)
static

Tell the server that we like to change the name of the client.

Parameters
nameThe new name.

Definition at line 460 of file network_client.cpp.

References my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_SET_NAME, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkUpdateClientName().

NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetPassword ( const char *  password)
static

Tell the server that we like to change the password of the company.

Parameters
passwordThe new password.

Definition at line 447 of file network_client.cpp.

References GenerateCompanyPasswordHash(), my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_SET_PASSWORD, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkClientSetCompanyPassword().

Friends And Related Function Documentation

void NetworkClose ( bool  close_admins)
friend

Close current connections.

Parameters
close_adminsWhether the admin connections have to be closed as well.

Definition at line 530 of file network.cpp.

Field Documentation

ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = NULL
staticprotected

The documentation for this class was generated from the following files: