OpenTTD Source  20241108-master-g80f628063a
NetworkGameSocketHandler Class Referenceabstract

Base socket handler for all TCP sockets. More...

#include <tcp_game.h>

Inheritance diagram for NetworkGameSocketHandler:
NetworkTCPSocketHandler NetworkSocketHandler ClientNetworkGameSocketHandler QueryNetworkGameSocketHandler ServerNetworkGameSocketHandler

Public Member Functions

NetworkRecvStatus CloseConnection (bool error=true) override
 Functions to help ReceivePacket/SendPacket a bit A socket can make errors. More...
 
virtual NetworkRecvStatus CloseConnection (NetworkRecvStatus status)=0
 Close the network connection due to the given status. More...
 
void SetInfo (NetworkClientInfo *info)
 Sets the client info for this socket handler. More...
 
NetworkClientInfoGetInfo () 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...
 
bool IsPendingDeletion () const
 
void DeferDeletion ()
 
- 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 (std::unique_ptr< 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 std::unique_ptr< PacketReceivePacket ()
 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 ()=default
 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 void ProcessDeferredDeletions ()
 

Data Fields

ClientID client_id
 Client identifier.
 
uint32_t last_frame
 Last frame we have executed.
 
uint32_t 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?
 

Protected Member Functions

NetworkRecvStatus ReceiveInvalidPacket (PacketGameType type)
 Helper for logging receiving invalid packets. More...
 
virtual NetworkRecvStatus Receive_SERVER_FULL (Packet &p)
 Notification that the server is full. More...
 
virtual NetworkRecvStatus Receive_SERVER_BANNED (Packet &p)
 Notification that the client trying to join is banned. More...
 
virtual NetworkRecvStatus Receive_CLIENT_JOIN (Packet &p)
 Try to join the server: string OpenTTD revision (norev0000 if no revision). More...
 
virtual NetworkRecvStatus Receive_SERVER_ERROR (Packet &p)
 The client made an error: uint8_t Error code caused (see NetworkErrorCode). 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_SERVER_CLIENT_INFO (Packet &p)
 Send information about a client: uint32_t ID of the client (always unique on a server. More...
 
virtual NetworkRecvStatus Receive_CLIENT_IDENTIFY (Packet &p)
 The client tells the server about the identity of the client: string Name of the client (max NETWORK_NAME_LENGTH). More...
 
virtual NetworkRecvStatus Receive_SERVER_AUTH_REQUEST (Packet &p)
 Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to use. More...
 
virtual NetworkRecvStatus Receive_CLIENT_AUTH_RESPONSE (Packet &p)
 Send the response to the authentication request: 32 * uint8_t Public key of the client. More...
 
virtual NetworkRecvStatus Receive_SERVER_ENABLE_ENCRYPTION (Packet &p)
 Indication to the client that authentication is complete and encryption has to be used from here on forward. More...
 
virtual NetworkRecvStatus Receive_SERVER_WELCOME (Packet &p)
 The client is joined and ready to receive their map: uint32_t Own client ID. More...
 
virtual NetworkRecvStatus Receive_CLIENT_GETMAP (Packet &p)
 Request the map from the server. More...
 
virtual NetworkRecvStatus Receive_SERVER_WAIT (Packet &p)
 Notification that another client is currently receiving the map: uint8_t Number of clients waiting in front of you. More...
 
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN (Packet &p)
 Sends that the server will begin with sending the map to the client: uint32_t Current frame. More...
 
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE (Packet &p)
 Sends the size of the map to the client. More...
 
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). More...
 
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE (Packet &p)
 Sends that all data of the map are sent to the client: More...
 
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK (Packet &p)
 Tell the server that we are done receiving/loading the map. More...
 
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_t ID of the client that just joined the game. More...
 
virtual NetworkRecvStatus Receive_SERVER_FRAME (Packet &p)
 Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how far may the client walk before the server?) uint32_t General seed 1 (dependent on compile settings, not default). More...
 
virtual NetworkRecvStatus Receive_SERVER_SYNC (Packet &p)
 Sends a sync-check to the client: uint32_t Frame counter. More...
 
virtual NetworkRecvStatus Receive_CLIENT_ACK (Packet &p)
 Tell the server we are done with this frame: uint32_t Current frame counter of the client. More...
 
virtual NetworkRecvStatus Receive_CLIENT_COMMAND (Packet &p)
 Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1). More...
 
virtual NetworkRecvStatus Receive_SERVER_COMMAND (Packet &p)
 Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1). More...
 
virtual NetworkRecvStatus Receive_CLIENT_CHAT (Packet &p)
 Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction). More...
 
virtual NetworkRecvStatus Receive_SERVER_CHAT (Packet &p)
 Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction). More...
 
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT (Packet &p)
 Sends a chat-packet for external source to the client: string Name of the source this message came from. 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_SERVER_QUIT (Packet &p)
 Notification that a client left the game: uint32_t ID of the client. More...
 
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT (Packet &p)
 Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of the client that caused the error. More...
 
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN (Packet &p)
 Let the clients know that the server is closing. More...
 
virtual NetworkRecvStatus Receive_SERVER_NEWGAME (Packet &p)
 Let the clients know that the server is loading a new map. More...
 
virtual NetworkRecvStatus Receive_SERVER_RCON (Packet &p)
 Send the result of an issues RCon command back to the client: uint16_t Colour code. More...
 
virtual NetworkRecvStatus Receive_CLIENT_RCON (Packet &p)
 Send an RCon command to the server: string RCon password. More...
 
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS (Packet &p)
 Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is repeated this many times, i.e. More...
 
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED (Packet &p)
 Tell the server that we have the required GRFs. More...
 
virtual NetworkRecvStatus Receive_SERVER_MOVE (Packet &p)
 Move a client from one company into another: uint32_t ID of the client. More...
 
virtual NetworkRecvStatus Receive_CLIENT_MOVE (Packet &p)
 Request the server to move this client into another company: uint8_t ID of the company the client wants to join. More...
 
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE (Packet &p)
 Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed. More...
 
NetworkRecvStatus HandlePacket (Packet &p)
 Handle the given packet, i.e. More...
 
 NetworkGameSocketHandler (SOCKET s)
 Create a new socket for the game connection. More...
 

Private Attributes

NetworkClientInfoinfo
 Client info related to this socket.
 
bool is_pending_deletion = false
 Whether this socket is pending deletion.
 

Additional Inherited Members

- Protected Attributes inherited from NetworkSocketHandler
std::unique_ptr< class NetworkEncryptionHandlerreceive_encryption_handler
 The handler for decrypting received packets.
 
std::unique_ptr< class NetworkEncryptionHandlersend_encryption_handler
 The handler for encrypting sent packets.
 

Detailed Description

Base socket handler for all TCP sockets.

Definition at line 141 of file tcp_game.h.

Constructor & Destructor Documentation

◆ NetworkGameSocketHandler()

NetworkGameSocketHandler::NetworkGameSocketHandler ( SOCKET  s)
protected

Create a new socket for the game connection.

Parameters
sThe socket to connect with.

Definition at line 29 of file tcp_game.cpp.

References last_packet, and NetworkTCPSocketHandler::sock.

Member Function Documentation

◆ CloseConnection() [1/2]

NetworkRecvStatus NetworkGameSocketHandler::CloseConnection ( bool  error = true)
overridevirtual

Functions to help ReceivePacket/SendPacket a bit A socket can make errors.

When that happens this handles what to do. For clients: close connection and drop back to main-menu For servers: close connection and that is it

Returns
the new status

Reimplemented from NetworkTCPSocketHandler.

Definition at line 43 of file tcp_game.cpp.

References _network_server, _networking, _switch_mode, ClientNetworkEmergencySave(), INVALID_STRING_ID, NETWORK_RECV_STATUS_CLIENT_QUIT, NETWORK_RECV_STATUS_CONNECTION_LOST, ShowErrorMessage(), SM_MENU, and WL_CRITICAL.

Referenced by ClientNetworkGameSocketHandler::CheckConnection(), and HandlePacket().

◆ CloseConnection() [2/2]

virtual NetworkRecvStatus NetworkGameSocketHandler::CloseConnection ( NetworkRecvStatus  status)
pure virtual

Close the network connection due to the given status.

Parameters
statusThe reason the connection got closed.

Implemented in ServerNetworkGameSocketHandler, QueryNetworkGameSocketHandler, and ClientNetworkGameSocketHandler.

◆ GetInfo()

NetworkClientInfo* NetworkGameSocketHandler::GetInfo ( ) const
inline

Gets the client info of this socket handler.

Returns
The client info.

Definition at line 515 of file tcp_game.h.

References info.

Referenced by ServerNetworkGameSocketHandler::GetClientName(), ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().

◆ HandlePacket()

NetworkRecvStatus NetworkGameSocketHandler::HandlePacket ( Packet p)
protected

Handle the given packet, i.e.

pass it to the right parser receive command.

Parameters
pthe packet to handle
Returns
NetworkRecvStatus of handling.

Definition at line 64 of file tcp_game.cpp.

References client_id, CloseConnection(), Debug, NetworkSocketHandler::HasClientQuit(), last_packet, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_CLIENT_ACK, PACKET_CLIENT_AUTH_RESPONSE, PACKET_CLIENT_CHAT, PACKET_CLIENT_COMMAND, PACKET_CLIENT_ERROR, PACKET_CLIENT_GAME_INFO, PACKET_CLIENT_GETMAP, PACKET_CLIENT_IDENTIFY, PACKET_CLIENT_JOIN, PACKET_CLIENT_MAP_OK, PACKET_CLIENT_MOVE, PACKET_CLIENT_NEWGRFS_CHECKED, PACKET_CLIENT_QUIT, PACKET_CLIENT_RCON, PACKET_CLIENT_SET_NAME, PACKET_SERVER_AUTH_REQUEST, PACKET_SERVER_BANNED, PACKET_SERVER_CHAT, PACKET_SERVER_CHECK_NEWGRFS, PACKET_SERVER_CLIENT_INFO, PACKET_SERVER_COMMAND, PACKET_SERVER_CONFIG_UPDATE, PACKET_SERVER_ENABLE_ENCRYPTION, PACKET_SERVER_ERROR, PACKET_SERVER_ERROR_QUIT, PACKET_SERVER_EXTERNAL_CHAT, PACKET_SERVER_FRAME, PACKET_SERVER_FULL, PACKET_SERVER_GAME_INFO, PACKET_SERVER_JOIN, PACKET_SERVER_MAP_BEGIN, PACKET_SERVER_MAP_DATA, PACKET_SERVER_MAP_DONE, PACKET_SERVER_MAP_SIZE, PACKET_SERVER_MOVE, PACKET_SERVER_NEWGAME, PACKET_SERVER_QUIT, PACKET_SERVER_RCON, PACKET_SERVER_SHUTDOWN, PACKET_SERVER_SYNC, PACKET_SERVER_WAIT, PACKET_SERVER_WELCOME, Receive_CLIENT_ACK(), Receive_CLIENT_AUTH_RESPONSE(), Receive_CLIENT_CHAT(), Receive_CLIENT_COMMAND(), Receive_CLIENT_ERROR(), Receive_CLIENT_GAME_INFO(), Receive_CLIENT_GETMAP(), Receive_CLIENT_IDENTIFY(), Receive_CLIENT_JOIN(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_MOVE(), Receive_CLIENT_NEWGRFS_CHECKED(), Receive_CLIENT_QUIT(), Receive_CLIENT_RCON(), Receive_CLIENT_SET_NAME(), Receive_SERVER_AUTH_REQUEST(), Receive_SERVER_BANNED(), Receive_SERVER_CHAT(), Receive_SERVER_CHECK_NEWGRFS(), Receive_SERVER_CLIENT_INFO(), Receive_SERVER_COMMAND(), Receive_SERVER_CONFIG_UPDATE(), Receive_SERVER_ENABLE_ENCRYPTION(), Receive_SERVER_ERROR(), Receive_SERVER_ERROR_QUIT(), Receive_SERVER_EXTERNAL_CHAT(), Receive_SERVER_FRAME(), Receive_SERVER_FULL(), Receive_SERVER_GAME_INFO(), Receive_SERVER_JOIN(), Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), Receive_SERVER_MAP_SIZE(), Receive_SERVER_MOVE(), Receive_SERVER_NEWGAME(), Receive_SERVER_QUIT(), Receive_SERVER_RCON(), Receive_SERVER_SHUTDOWN(), Receive_SERVER_SYNC(), Receive_SERVER_WAIT(), Receive_SERVER_WELCOME(), and Packet::Recv_uint8().

Referenced by ReceivePackets().

◆ Receive_CLIENT_ACK()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ACK ( Packet p)
protectedvirtual

Tell the server we are done with this frame: uint32_t Current frame counter of the client.

uint8_t The random token that the server sent in the PACKET_SERVER_FRAME packet.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 178 of file tcp_game.cpp.

References PACKET_CLIENT_ACK, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_AUTH_RESPONSE()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_AUTH_RESPONSE ( Packet p)
protectedvirtual

Send the response to the authentication request: 32 * uint8_t Public key of the client.

16 * uint8_t Message authentication code. 8 * uint8_t Random message that got encoded and signed.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 165 of file tcp_game.cpp.

References PACKET_CLIENT_AUTH_RESPONSE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_CHAT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT ( Packet p)
protectedvirtual

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

uint8_t ID of the destination type (see DestType). uint32_t ID of the client or company (destination of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64_t data (used e.g. for 'give money' actions).

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 181 of file tcp_game.cpp.

References PACKET_CLIENT_CHAT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_COMMAND()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND ( Packet p)
protectedvirtual

Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1).

uint32_t 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_t ID of the callback.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 179 of file tcp_game.cpp.

References PACKET_CLIENT_COMMAND, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_ERROR()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR ( Packet p)
protectedvirtual

The client made an error and is quitting the game.

uint8_t Error of the code caused (see NetworkErrorCode).

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 186 of file tcp_game.cpp.

References PACKET_CLIENT_ERROR, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_GAME_INFO()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_INFO ( Packet p)
protectedvirtual

Request game information.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 160 of file tcp_game.cpp.

References PACKET_CLIENT_GAME_INFO, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_GETMAP()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GETMAP ( Packet p)
protectedvirtual

Request the map from the server.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 168 of file tcp_game.cpp.

References PACKET_CLIENT_GETMAP, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_IDENTIFY()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_IDENTIFY ( Packet p)
protectedvirtual

The client tells the server about the identity of the client: string Name of the client (max NETWORK_NAME_LENGTH).

uint8_t ID of the company to play as (1..MAX_COMPANIES, or COMPANY_SPECTATOR).

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 163 of file tcp_game.cpp.

References PACKET_CLIENT_IDENTIFY, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_JOIN()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN ( Packet p)
protectedvirtual

Try to join the server: string OpenTTD revision (norev0000 if no revision).

uint32_t NewGRF version (added in 1.2). string Name of the client (max NETWORK_NAME_LENGTH) (removed in 15). uint8_t ID of the company to play as (1..MAX_COMPANIES) (removed in 15). uint8_t ID of the clients Language (removed in 15). string Client's unique identifier (removed in 1.0).

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 158 of file tcp_game.cpp.

References PACKET_CLIENT_JOIN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_MAP_OK()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MAP_OK ( Packet p)
protectedvirtual

Tell the server that we are done receiving/loading the map.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 174 of file tcp_game.cpp.

References PACKET_CLIENT_MAP_OK, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_MOVE()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE ( Packet p)
protectedvirtual

Request the server to move this client into another company: uint8_t ID of the company the client wants to join.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 196 of file tcp_game.cpp.

References PACKET_CLIENT_MOVE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_NEWGRFS_CHECKED()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED ( Packet p)
protectedvirtual

Tell the server that we have the required GRFs.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 194 of file tcp_game.cpp.

References PACKET_CLIENT_NEWGRFS_CHECKED, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_QUIT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT ( Packet p)
protectedvirtual

The client is quitting the game.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 185 of file tcp_game.cpp.

References PACKET_CLIENT_QUIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_RCON()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_RCON ( Packet p)
protectedvirtual

Send an RCon command to the server: string RCon password.

string Command to be executed.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 192 of file tcp_game.cpp.

References PACKET_CLIENT_RCON, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_CLIENT_SET_NAME()

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME ( Packet p)
protectedvirtual

Gives the client a new name: string New name of the client.

Parameters
pThe packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 184 of file tcp_game.cpp.

References PACKET_CLIENT_SET_NAME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_AUTH_REQUEST()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_AUTH_REQUEST ( Packet p)
protectedvirtual

Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to use.

32 * uint8_t Public key of the server. 24 * uint8_t Nonce for the key exchange.

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 164 of file tcp_game.cpp.

References PACKET_SERVER_AUTH_REQUEST, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_BANNED()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED ( Packet p)
protectedvirtual

Notification that the client trying to join is banned.

Parameters
pThe packet that was just received.

Reimplemented in QueryNetworkGameSocketHandler, and ClientNetworkGameSocketHandler.

Definition at line 157 of file tcp_game.cpp.

References PACKET_SERVER_BANNED, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_CHAT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT ( Packet p)
protectedvirtual

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

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 182 of file tcp_game.cpp.

References PACKET_SERVER_CHAT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_CHECK_NEWGRFS()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS ( Packet p)
protectedvirtual

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

per GRF data). uint32_t GRF ID 16 * uint8_t MD5 checksum of the GRF

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 193 of file tcp_game.cpp.

References PACKET_SERVER_CHECK_NEWGRFS, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_CLIENT_INFO()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO ( Packet p)
protectedvirtual

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

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 162 of file tcp_game.cpp.

References PACKET_SERVER_CLIENT_INFO, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_COMMAND()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND ( Packet p)
protectedvirtual

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

uint32_t 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_t ID of the callback. uint32_t Frame of execution.

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 180 of file tcp_game.cpp.

References PACKET_SERVER_COMMAND, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_CONFIG_UPDATE()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE ( Packet p)
protectedvirtual

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

uint8_t Maximum number of spectators allowed.

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 197 of file tcp_game.cpp.

References PACKET_SERVER_CONFIG_UPDATE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_ENABLE_ENCRYPTION()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ENABLE_ENCRYPTION ( Packet p)
protectedvirtual

Indication to the client that authentication is complete and encryption has to be used from here on forward.

The encryption uses the shared keys generated by the last AUTH_REQUEST key exchange. 24 * uint8_t Nonce for encrypted connection.

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 166 of file tcp_game.cpp.

References PACKET_SERVER_ENABLE_ENCRYPTION, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_ERROR()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in QueryNetworkGameSocketHandler, and ClientNetworkGameSocketHandler.

Definition at line 159 of file tcp_game.cpp.

References PACKET_SERVER_ERROR, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_ERROR_QUIT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT ( Packet p)
protectedvirtual

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

uint8_t Code of the error caused (see NetworkErrorCode).

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 188 of file tcp_game.cpp.

References PACKET_SERVER_ERROR_QUIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_EXTERNAL_CHAT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT ( Packet p)
protectedvirtual

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

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 183 of file tcp_game.cpp.

References PACKET_SERVER_EXTERNAL_CHAT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_FRAME()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FRAME ( Packet p)
protectedvirtual

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

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 176 of file tcp_game.cpp.

References PACKET_SERVER_FRAME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_FULL()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL ( Packet p)
protectedvirtual

Notification that the server is full.

Parameters
pThe packet that was just received.

Reimplemented in QueryNetworkGameSocketHandler, and ClientNetworkGameSocketHandler.

Definition at line 156 of file tcp_game.cpp.

References PACKET_SERVER_FULL, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_GAME_INFO()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_GAME_INFO ( Packet p)
protectedvirtual

Sends information about the game.

Serialized NetworkGameInfo. See game_info.h for details.

Parameters
pThe packet that was just received.

Reimplemented in QueryNetworkGameSocketHandler.

Definition at line 161 of file tcp_game.cpp.

References PACKET_SERVER_GAME_INFO, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_JOIN()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_JOIN ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 175 of file tcp_game.cpp.

References PACKET_SERVER_JOIN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_MAP_BEGIN()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 170 of file tcp_game.cpp.

References PACKET_SERVER_MAP_BEGIN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_MAP_DATA()

NetworkRecvStatus NetworkGameSocketHandler::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 in ClientNetworkGameSocketHandler.

Definition at line 172 of file tcp_game.cpp.

References PACKET_SERVER_MAP_DATA, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_MAP_DONE()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DONE ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 173 of file tcp_game.cpp.

References PACKET_SERVER_MAP_DONE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_MAP_SIZE()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE ( Packet p)
protectedvirtual

Sends the size of the map to the client.

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 171 of file tcp_game.cpp.

References PACKET_SERVER_MAP_SIZE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_MOVE()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE ( Packet p)
protectedvirtual

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

uint8_t ID of the new company.

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 195 of file tcp_game.cpp.

References PACKET_SERVER_MOVE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_NEWGAME()

NetworkRecvStatus NetworkGameSocketHandler::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 in ClientNetworkGameSocketHandler.

Definition at line 190 of file tcp_game.cpp.

References PACKET_SERVER_NEWGAME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_QUIT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 187 of file tcp_game.cpp.

References PACKET_SERVER_QUIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_RCON()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_RCON ( Packet p)
protectedvirtual

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

string Output of the RCon command

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 191 of file tcp_game.cpp.

References PACKET_SERVER_RCON, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_SHUTDOWN()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN ( Packet p)
protectedvirtual

Let the clients know that the server is closing.

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 189 of file tcp_game.cpp.

References PACKET_SERVER_SHUTDOWN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_SYNC()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SYNC ( Packet p)
protectedvirtual

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

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 177 of file tcp_game.cpp.

References PACKET_SERVER_SYNC, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_WAIT()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WAIT ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 169 of file tcp_game.cpp.

References PACKET_SERVER_WAIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_SERVER_WELCOME()

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WELCOME ( Packet p)
protectedvirtual

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

Parameters
pThe packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 167 of file tcp_game.cpp.

References PACKET_SERVER_WELCOME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ ReceiveCommand()

const char * NetworkGameSocketHandler::ReceiveCommand ( Packet p,
CommandPacket cp 
)

Receives a command from the network.

Parameters
pthe packet to read from.
cpthe struct to write the data to.
Returns
an error message. When nullptr there has been no error.

Definition at line 363 of file network_command.cpp.

References CommandPacket::company.

Referenced by ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND().

◆ ReceiveInvalidPacket()

NetworkRecvStatus NetworkGameSocketHandler::ReceiveInvalidPacket ( PacketGameType  type)
protected

◆ ReceivePackets()

NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets ( )

Do the actual receiving of packets.

As long as HandlePacket returns OKAY packets are handled. Upon failure, or no more packets to process the last result of HandlePacket is returned.

Returns
NetworkRecvStatus of the last handled packet.

Definition at line 134 of file tcp_game.cpp.

References HandlePacket(), NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::ReceivePacket().

Referenced by ClientNetworkGameSocketHandler::Receive(), and QueryNetworkGameSocketHandler::Receive().

◆ SendCommand()

void NetworkGameSocketHandler::SendCommand ( Packet p,
const CommandPacket cp 
)

Sends a command over the network.

Parameters
pthe packet to send it in.
cpthe packet to actually send.

Definition at line 384 of file network_command.cpp.

References _cmd_dispatch, CommandPacket::callback, CommandPacket::cmd, CommandPacket::company, CommandPacket::data, Debug, CommandPacket::err_msg, FindCallbackIndex(), Packet::Send_buffer(), Packet::Send_uint16(), and Packet::Send_uint8().

Referenced by ServerNetworkGameSocketHandler::SendCommand().

◆ SetInfo()

void NetworkGameSocketHandler::SetInfo ( NetworkClientInfo info)
inline

Sets the client info for this socket handler.

Parameters
infoThe new client info.

Definition at line 505 of file tcp_game.h.

References info.


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