OpenTTD Source: ClientNetworkGameSocketHandler Class Reference

OpenTTD Source 13.2.1

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:

## Public Member Functions
| ClientNetworkGameSocketHandler (SOCKET s, const std::string &connection_string)
| Create a new socket for the client side of the game connection. More...
| ~ClientNetworkGameSocketHandler ()
| Clear whatever we assigned.
NetworkRecvStatus | CloseConnection (NetworkRecvStatus status) override
| Close the network connection due to the given status. More...
void | ClientError (NetworkRecvStatus res)
| Handle an error coming from the client side. More...
Public Member Functions inherited from ZeroedMemoryAllocator
void * | operator new (size_t size)
| Memory allocator for a single class instance. More...
void * | operator new[] (size_t size)
| Memory allocator for an array of class instances. More...
void | operator delete (void *ptr)
| Memory release for a single class instance. More...
void | operator delete[] (void *ptr)
| Memory release for an array of class instances. More...
Public Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus | CloseConnection (bool error=true) override
| Functions to help ReceivePacket/SendPacket a bit A socket can make errors. More...
void | SetInfo (NetworkClientInfo *info)
| Sets the client info for this socket handler. More...
NetworkClientInfo * | GetInfo () const
| Gets the client info of this socket handler. More...
NetworkRecvStatus | ReceivePackets ()
| Do the actual receiving of packets. More...
const char * | ReceiveCommand (Packet *p, CommandPacket *cp)
| Receives a command from the network. More...
void | SendCommand (Packet *p, const CommandPacket *cp)
| Sends a command over the network. More...
Public Member Functions inherited from NetworkTCPSocketHandler
bool | IsConnected () const
| Whether this socket is currently bound to a socket. More...
void | CloseSocket ()
| Close the actual socket of the connection. More...
virtual void | SendPacket (Packet *packet)
| This function puts the packet in the send-queue and it is send as soon as possible. More...
SendPacketsState | SendPackets (bool closing_down=false)
| Sends all the buffered packets out for this client. More...
virtual Packet * | ReceivePacket ()
| Receives a packet for the given client. More...
bool | CanSendReceive ()
| Check whether this socket can send or receive something. More...
bool | HasSendQueue ()
| Whether there is something pending in the send queue. More...
| NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
| Construct a socket handler for a TCP connection. More...
Public Member Functions inherited from NetworkSocketHandler
| NetworkSocketHandler ()
| Create a new unbound socket.
virtual | ~NetworkSocketHandler ()
| Close the socket when destructing the socket handler.
void | MarkClosed ()
| Mark the connection as closed. More...
bool | HasClientQuit () const
| Whether the current client connected to the socket has quit. More...
void | Reopen ()
| Reopen the socket so we can send/receive stuff again.

## Static Public Member Functions
static NetworkRecvStatus | SendJoin ()
| Make sure the server ID length is the same as a md5 hash. More...
static NetworkRecvStatus | SendCommand (const CommandPacket *cp)
| Send a command to the server. More...
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 std::string &password)
| Set the game password as requested. More...
static NetworkRecvStatus | SendCompanyPassword (const std::string &password)
| Set the company password as requested. More...
static NetworkRecvStatus | SendChat (NetworkAction action, DestType type, int dest, const std::string &msg, int64 data)
| Send a chat-packet over the network.
static NetworkRecvStatus | SendSetPassword (const std::string &password)
| Tell the server that we like to change the password of the company. More...
static NetworkRecvStatus | SendSetName (const std::string &name)
| Tell the server that we like to change the name of the client. More...
static NetworkRecvStatus | SendRCon (const std::string &password, const std::string &command)
| Send a console command. More...
static NetworkRecvStatus | SendMove (CompanyID company, const std::string &password)
| Ask the server to move us. More...
static bool | IsConnected ()
| Check whether the client is actually connected (and in the game). More...
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. More...
static bool | GameLoop ()
| Actual game loop for the client. More...

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

## 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 = nullptr
| This is us! More...

## Private Types
enum | ServerStatus { STATUS_INACTIVE, 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
std::string | connection_string
| Address we are connected to.
struct PacketReader * | savegame
| 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. More...

## 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.
std::chrono::steady_clock::time_point | last_packet
| Time we received the last frame.
Data Fields inherited from NetworkTCPSocketHandler
SOCKET | sock
| The socket currently connected to.
bool | writable
| Can we write to this socket?

## Detailed Description

Class for handling the client side of the game connection.

Definition at line 16 of file network_client.h.

## Member Enumeration Documentation

## ◆ ServerStatus

enum ClientNetworkGameSocketHandler::ServerStatus
| private

Status of the connection with the server.

Enumerator
STATUS_INACTIVE | The client is not connected nor active.
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 23 of file network_client.h.

## Constructor & Destructor Documentation

## ◆ ClientNetworkGameSocketHandler()

ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler | ( | SOCKET | s,
|  | const std::string & | connection_string
| ) |  |

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

Parameters

  s | The socket to connect with.

Definition at line 144 of file network_client.cpp.

References my_client.

## Member Function Documentation

## ◆ CheckConnection()

void ClientNetworkGameSocketHandler::CheckConnection | ( |  | ) |
| protected

Check the connection's state, i.e.

is the connection still up?

Definition at line 1132 of file network_client.cpp.

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

Referenced by Send().

## ◆ ClientError()

void ClientNetworkGameSocketHandler::ClientError | ( | NetworkRecvStatus | res | ) |

Handle an error coming from the client side.

Parameters

  res | The "error" that happened.

Definition at line 186 of file network_client.cpp.

References _networking, CloseConnection(), CloseWindowById(), NetworkSocketHandler::MarkClosed(), NETWORK_RECV_STATUS_CLOSE_QUERY, NETWORK_RECV_STATUS_DESYNC, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.

Referenced by Receive().

## ◆ CloseConnection()

NetworkRecvStatus ClientNetworkGameSocketHandler::CloseConnection | ( | NetworkRecvStatus | status | ) |
| overridevirtual

Close the network connection due to the given status.

Parameters

  status | The reason the connection got closed.

Implements NetworkGameSocketHandler.

Definition at line 160 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, CSleep(), Debug, NetworkSocketHandler::HasClientQuit(), MILLISECONDS_PER_TICK, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPackets(), NetworkTCPSocketHandler::sock, and status.

Referenced by ClientError(), and NetworkClose().

## ◆ GameLoop()

bool ClientNetworkGameSocketHandler::GameLoop | ( |  | ) |
| static

Actual game loop for the client.

Returns
  Whether everything went okay, or not.

Definition at line 263 of file network_client.cpp.

References _frame_counter, _random, _sync_frame, _sync_seed_1, NetworkExecuteLocalCommandQueue, Randomizer::state, and StateGameLoop().

## ◆ IsConnected()

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 520 of file network_client.cpp.

References my_client, status, and STATUS_ACTIVE.

Referenced by DEF_CONSOLE_HOOK().

## ◆ Receive()

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 238 of file network_client.cpp.

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

Referenced by NetworkReceive().

## ◆ Receive_SERVER_BANNED()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED | ( | Packet * | p | ) |
| overrideprotectedvirtual

Notification that the client trying to join is banned.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 541 of file network_client.cpp.

References INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_BANNED, ShowErrorMessage(), and WL_CRITICAL.

## ◆ Receive_SERVER_CHAT()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 919 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, NetworkClientInfo::GetByClientID(), NETWORK_CHAT_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(), status, and STATUS_ACTIVE.

## ◆ Receive_SERVER_CHECK_NEWGRFS()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 654 of file network_client.cpp.

References BSWAP32(), Debug, DeserializeGRFIdentifier(), 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, Packet::Recv_uint8(), SendNewGRFsOk(), ShowErrorMessage(), status, STATUS_JOIN, and WL_CRITICAL.

## ◆ Receive_SERVER_CLIENT_INFO()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO | ( | Packet * | p | ) |
| overrideprotectedvirtual

Send information about a client: uint32 ID of the client (always unique on a server.

1 = server, 0 is invalid). uint8 ID of the company the client is playing as (255 for spectators). string Name of the client.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 552 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, and Packet::Recv_uint32().

## ◆ Receive_SERVER_COMMAND()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

uint32 ID of the command (see command.h). Command specific buffer with encoded parameters of variable length. The content differs per command and can change without notification. uint8 ID of the callback. uint32 Frame of execution.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 900 of file network_client.cpp.

References CommandQueue::Append(), CC_WARNING, CommandPacket::frame, IConsolePrint(), 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.

## ◆ Receive_SERVER_COMPANY_UPDATE()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1119 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.

## ◆ Receive_SERVER_CONFIG_UPDATE()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

uint8 Maximum number of spectators allowed.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1109 of file network_client.cpp.

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

## ◆ Receive_SERVER_ERROR()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 608 of file network_client.cpp.

References lengthof.

## ◆ Receive_SERVER_ERROR_QUIT()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 984 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, NetworkClientInfo::GetByClientID(), NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_uint32(), status, and STATUS_AUTHORIZED.

## ◆ Receive_SERVER_EXTERNAL_CHAT()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT | ( | Packet * | p | ) |
| overrideprotectedvirtual

Sends a chat-packet for external source to the client: string Name of the source this message came from.

uint16 TextColour to use for the message. string Name of the user who sent the messsage. string Message (max NETWORK_CHAT_LENGTH).

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 968 of file network_client.cpp.

References IsValidConsoleColour(), NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_string(), Packet::Recv_uint16(), status, and STATUS_ACTIVE.

## ◆ Receive_SERVER_FRAME()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 850 of file network_client.cpp.

References _frame_counter, _frame_counter_max, _frame_counter_server, _network_first_time, _sync_frame, _sync_seed_1, Packet::CanReadFromPacket(), DAY_TICKS, Debug, last_ack_frame, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), SendAck(), status, STATUS_ACTIVE, and token.

## ◆ Receive_SERVER_FULL()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL | ( | Packet * | p | ) |
| overrideprotectedvirtual

Notification that the server is full.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 533 of file network_client.cpp.

References INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_FULL, ShowErrorMessage(), and WL_CRITICAL.

## ◆ Receive_SERVER_JOIN()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1021 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, NetworkClientInfo::GetByClientID(), NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_uint32(), status, and STATUS_AUTHORIZED.

## ◆ Receive_SERVER_MAP_BEGIN()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 747 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, Packet::Recv_uint32(), savegame, status, and STATUS_MAP.

## ◆ Receive_SERVER_MAP_DATA()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 778 of file network_client.cpp.

References _network_join_bytes, PacketReader::AddPacket(), NETWORK_RECV_STATUS_MALFORMED_PACKET, savegame, status, and STATUS_MAP.

## ◆ Receive_SERVER_MAP_DONE()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE | ( | Packet * | p | ) |
| overrideprotectedvirtual

Sends that all data of the map are sent to the client:

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 792 of file network_client.cpp.

References _network_join_status, NETWORK_RECV_STATUS_MALFORMED_PACKET, savegame, status, and STATUS_MAP.

## ◆ Receive_SERVER_MAP_SIZE()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE | ( | Packet * | p | ) |
| overrideprotectedvirtual

Sends the size of the map to the client.

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 767 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.

## ◆ Receive_SERVER_MOVE()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE | ( | Packet * | p | ) |
| overrideprotectedvirtual

Move a client from one company into another: uint32 ID of the client.

uint8 ID of the new company.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1081 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_uint32(), status, and STATUS_AUTHORIZED.

## ◆ Receive_SERVER_NEED_COMPANY_PASSWORD()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

string Network ID of the server.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 701 of file network_client.cpp.

References _network_join, _password_server_id, NetworkJoinInfo::company_password, NetworkSocketHandler::HasClientQuit(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_SERVER_ID_LENGTH, Packet::Recv_string(), Packet::Recv_uint32(), SendCompanyPassword(), status, and STATUS_AUTH_COMPANY.

## ◆ Receive_SERVER_NEED_GAME_PASSWORD()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 687 of file network_client.cpp.

References _network_join, NETWORK_RECV_STATUS_MALFORMED_PACKET, SendGamePassword(), NetworkJoinInfo::server_password, status, and STATUS_AUTH_GAME.

## ◆ Receive_SERVER_NEWGAME()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1050 of file network_client.cpp.

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

## ◆ Receive_SERVER_QUIT()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1001 of file network_client.cpp.

References NetworkGameSocketHandler::client_id, NetworkClientInfo::GetByClientID(), NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_uint32(), status, and STATUS_AUTHORIZED.

## ◆ Receive_SERVER_RCON()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_RCON | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

string Output of the RCon command

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1067 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.

## ◆ Receive_SERVER_SHUTDOWN()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN | ( | Packet * | p | ) |
| overrideprotectedvirtual

Let the clients know that the server is closing.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1037 of file network_client.cpp.

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

## ◆ Receive_SERVER_SYNC()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SYNC | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 887 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.

## ◆ Receive_SERVER_WAIT()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WAIT | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 734 of file network_client.cpp.

References _network_join_status, NETWORK_RECV_STATUS_MALFORMED_PACKET, status, and STATUS_MAP_WAIT.

## ◆ Receive_SERVER_WELCOME()

NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_WELCOME | ( | Packet * | p | ) |
| overrideprotectedvirtual

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

uint32 Generation seed. string Network ID of the server.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 719 of file network_client.cpp.

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

## ◆ SendCommand()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand | ( | const CommandPacket * | cp | ) |
| static

Send a command to the server.

Parameters

  cp | The command to send.

Definition at line 417 of file network_client.cpp.

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

Referenced by NetworkSendCommand().

## ◆ SendCompanyPassword()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword | ( | const std::string & | password | ) |
| static

Set the company password as requested.

Parameters

  password | The company password.

Definition at line 374 of file network_client.cpp.

References _password_game_seed, _password_server_id, GenerateCompanyPasswordHash(), my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_COMPANY_PASSWORD, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

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

## ◆ SendGamePassword()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendGamePassword | ( | const std::string & | password | ) |
| static

Set the game password as requested.

Parameters

  password | The game password.

Definition at line 362 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().

## ◆ SendJoin()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin | ( |  | ) |
| static

Make sure the server ID length is the same as a md5 hash.

Tell the server we would like to join.

Definition at line 334 of file network_client.cpp.

References _network_join_status, my_client, status, and STATUS_JOIN.

Referenced by NetworkClient_Connected().

## ◆ SendMove()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove | ( | CompanyID | company,
|  | const std::string & | password
| ) |  |
| static

Ask the server to move us.

Parameters

  company | The company to move to.
  password | The password of the company to move to.

Definition at line 507 of file network_client.cpp.

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

Referenced by NetworkClientRequestMove().

## ◆ SendRCon()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon | ( | const std::string & | pass,
|  | const std::string & | command
| ) |  |
| static

Send a console command.

Parameters

  pass | The password for the remote command.
  command | The actual command.

Definition at line 493 of file network_client.cpp.

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

Referenced by NetworkClientSendRcon().

## ◆ SendSetName()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetName | ( | const std::string & | name | ) |
| static

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

Parameters

  name | The new name.

Definition at line 468 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().

## ◆ SendSetPassword()

NetworkRecvStatus ClientNetworkGameSocketHandler::SendSetPassword | ( | const std::string & | password | ) |
| static

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

Parameters

  password | The new password.

Definition at line 455 of file network_client.cpp.

References _password_game_seed, _password_server_id, 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

## ◆ NetworkClose

void NetworkClose | ( | bool | close_admins | ) |
| friend

Close current connections.

Parameters

  close_admins | Whether the admin connections have to be closed as well.

Definition at line 578 of file network.cpp.

## Field Documentation

## ◆ my_client

ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = nullptr
| staticprotected

This is us!

Our client's connection.

Definition at line 41 of file network_client.h.

Referenced by ClientNetworkGameSocketHandler(), IsConnected(), NetworkClose(), NetworkExecuteLocalCommandQueue(), Receive(), Send(), SendAck(), SendChat(), SendCommand(), SendCompanyPassword(), SendError(), SendGamePassword(), SendGetMap(), SendJoin(), SendMapOk(), SendMove(), SendNewGRFsOk(), SendQuit(), SendRCon(), SendSetName(), SendSetPassword(), and ~ClientNetworkGameSocketHandler().

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

- src/network/network_client.h
- src/network/network_client.cpp