OpenTTD Source 20260421-master-gc2fbc6fdeb
ServerNetworkGameSocketHandler Class Reference

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

#include <network_server.h>

Inheritance diagram for ServerNetworkGameSocketHandler:
NetworkGameSocketHandler TCPListenHandler< ServerNetworkGameSocketHandler, PacketGameType, PacketGameType::ServerFull, PacketGameType::ServerBanned > NetworkTCPSocketHandler NetworkSocketHandler

Public Types

enum  ClientStatus : uint8_t {
  STATUS_INACTIVE , STATUS_AUTH_GAME , STATUS_IDENTIFY , STATUS_NEWGRFS_CHECK ,
  STATUS_AUTHORIZED , STATUS_MAP_WAIT , STATUS_MAP , STATUS_DONE_MAP ,
  STATUS_PRE_ACTIVE , STATUS_ACTIVE , STATUS_END
}
 Status of a client. More...

Public Member Functions

 ServerNetworkGameSocketHandler (ClientPoolID index, SOCKET s)
 Create a new socket for the server side of the game connection.
 ~ServerNetworkGameSocketHandler () override
 Clear everything related to this client.
std::unique_ptr< PacketReceivePacket () override
 Receives a packet for the given client.
NetworkRecvStatus CloseConnection (NetworkRecvStatus status) override
 Close the network connection due to the given status.
std::string GetClientName () const
 Get the name of the client, if the user did not send it yet, Client ID is used.
void CheckNextClientToSendMap (NetworkClientSocket *ignore_cs=nullptr)
 Find the next candidate for joining, and start the joining process for that client.
NetworkRecvStatus SendWait ()
 Tell the client that its put in a waiting queue.
NetworkRecvStatus SendMap ()
 This sends the map to the client.
NetworkRecvStatus SendErrorQuit (ClientID client_id, NetworkErrorCode errorno)
 Tell the client another client quit with an error.
NetworkRecvStatus SendQuit (ClientID client_id)
 Tell the client another client quit.
NetworkRecvStatus SendShutdown ()
 Tell the client we're shutting down.
NetworkRecvStatus SendNewGame ()
 Tell the client we're starting a new game.
NetworkRecvStatus SendRConResult (uint16_t colour, std::string_view command)
 Send the result of a console action.
NetworkRecvStatus SendMove (ClientID client_id, CompanyID company_id)
 Tell that a client moved to another company.
NetworkRecvStatus SendClientInfo (NetworkClientInfo *ci)
 Send the client information about a client.
NetworkRecvStatus SendError (NetworkErrorCode error, std::string_view reason={})
 Send an error to the client, and close its connection.
NetworkRecvStatus SendChat (NetworkAction action, ClientID client_id, bool self_send, std::string_view msg, int64_t data)
 Send a chat message.
NetworkRecvStatus SendExternalChat (std::string_view source, TextColour colour, std::string_view user, std::string_view msg)
 Send a chat message from external source.
NetworkRecvStatus SendJoin (ClientID client_id)
 Tell that a client joined.
NetworkRecvStatus SendFrame ()
 Tell the client that they may run to a particular frame.
NetworkRecvStatus SendSync ()
 Request the client to sync.
NetworkRecvStatus SendCommand (const CommandPacket &cp)
 Send a command to the client to execute.
NetworkRecvStatus SendConfigUpdate ()
 Send an update about the max company/spectator counts.
std::string_view GetClientIP ()
 Get the IP address/hostname of the connected client.
std::string_view GetPeerPublicKey () const
 Get the public key of our peer.
Public Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus CloseConnection (bool error=true) override
 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.
std::optional< std::string_view > ReceiveCommand (Packet &p, CommandPacket &cp)
 Receives a command from the network.
void SendCommand (Packet &p, const CommandPacket &cp)
 Sends a command over the network.
bool IsPendingDeletion () const
 Is this pending for deletion and as such should not be accessed anymore.
void DeferDeletion ()
 Mark this socket handler for deletion, once iterating the socket handlers is done.
Public Member Functions inherited from NetworkTCPSocketHandler
bool IsConnected () const
 Whether this socket is currently bound to a socket.
void CloseSocket ()
 Close the actual socket of the connection.
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.
SendPacketsState SendPackets (bool closing_down=false)
 Sends all the buffered packets out for this 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.
 ~NetworkTCPSocketHandler () override
 Close the socket.
Public Member Functions inherited from NetworkSocketHandler
 NetworkSocketHandler ()=default
 Create a new unbound socket.
virtual ~NetworkSocketHandler ()=default
 Ensure the destructor of the sub classes are called as well.
void MarkClosed ()
 Mark the connection as closed.
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.

Static Public Member Functions

static void Send ()
 Send the packets for the server sockets.
static void AcceptConnection (SOCKET s, const NetworkAddress &address)
 Handle the accepting of a connection to the server.
static bool AllowConnection ()
 Whether an connection is allowed or not at this moment.
static std::string_view GetName ()
 Get the name used by the listener.
static ServerNetworkGameSocketHandlerGetByClientID (ClientID client_id)
 Return the client state given it's client-identifier.
Static Public Member Functions inherited from NetworkGameSocketHandler
static void ProcessDeferredDeletions ()
 Actually delete the socket handlers that were marked for deletion.
Static Public Member Functions inherited from TCPListenHandler< ServerNetworkGameSocketHandler, PacketGameType, PacketGameType::ServerFull, PacketGameType::ServerBanned >
static bool ValidateClient (SOCKET s, NetworkAddress &address)
 Check whether this client is allowed to connect, by both the banlist and maximum client count.
static void AcceptClient (SOCKET ls)
 Accepts clients from the sockets.
static bool Receive ()
 Handle the receiving of packets.
static bool Listen (uint16_t port)
 Listen on a particular port.
static void CloseListeners ()
 Close the sockets we're listening on.

Data Fields

uint8_t lag_test = 0
 Byte used for lag-testing the client.
uint8_t last_token = 0
 The last random token we did send to verify the client is listening.
uint32_t last_token_frame = 0
 The last frame we received the right token.
ClientStatus status = STATUS_INACTIVE
 Status of this client.
CommandQueue outgoing_queue {}
 The command-queue awaiting delivery; conceptually more a bucket to gather commands in, after which the whole bucket is sent to the client.
size_t receive_limit = 0
 Amount of bytes that we can receive at this moment.
std::shared_ptr< struct PacketWritersavegame = nullptr
 Writer used to write the savegame.
NetworkAddress client_address {}
 IP-address of the client (so they can be banned).
Data Fields inherited from NetworkGameSocketHandler
ClientID client_id = INVALID_CLIENT_ID
 Client identifier.
uint32_t last_frame = 0
 Last frame we have executed.
uint32_t last_frame_server = 0
 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 = INVALID_SOCKET
 The socket currently connected to.
bool writable = false
 Can we write to this socket?

Protected Member Functions

NetworkRecvStatus ReceiveClientJoin (Packet &p) override
 Try to join the server: string OpenTTD revision (norev0000 if no revision).
NetworkRecvStatus ReceiveClientIdentify (Packet &p) override
 The client tells the server about the identity of the client: string Name of the client (max NETWORK_NAME_LENGTH).
NetworkRecvStatus ReceiveClientGameInfo (Packet &p) override
 Request game information.
NetworkRecvStatus ReceiveClientAuthenticationResponse (Packet &p) override
 Send the response to the authentication request: 32 * uint8_t Public key of the client.
NetworkRecvStatus ReceiveClientGetMap (Packet &p) override
 Request the map from the server.
NetworkRecvStatus ReceiveClientMapOk (Packet &p) override
 Tell the server that we are done receiving/loading the map.
NetworkRecvStatus ReceiveClientAck (Packet &p) override
 Tell the server we are done with this frame: uint32_t Current frame counter of the client.
NetworkRecvStatus ReceiveClientCommand (Packet &p) override
 Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1).
NetworkRecvStatus ReceiveClientChat (Packet &p) override
 Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction).
NetworkRecvStatus ReceiveClientSetName (Packet &p) override
 Gives the client a new name: string New name of the client.
NetworkRecvStatus ReceiveClientQuit (Packet &p) override
 The client is quitting the game.
NetworkRecvStatus ReceiveClientError (Packet &p) override
 The client made an error and is quitting the game.
NetworkRecvStatus ReceiveClientRemoteConsoleCommand (Packet &p) override
 Send an RCon command to the server: string RCon password.
NetworkRecvStatus ReceiveClientNewGRFsChecked (Packet &p) override
 Tell the server that we have the required GRFs.
NetworkRecvStatus ReceiveClientMove (Packet &p) override
 Request the server to move this client into another company: uint8_t ID of the company the client wants to join.
NetworkRecvStatus SendGameInfo ()
 Send the client information about the server.
NetworkRecvStatus SendNewGRFCheck ()
 Send the check for the NewGRFs.
NetworkRecvStatus SendWelcome ()
 Send the client a welcome message with some basic information.
NetworkRecvStatus SendAuthRequest ()
 Request the game password.
NetworkRecvStatus SendEnableEncryption ()
 Notify the client that the authentication has completed and tell that for the remainder of this socket encryption is enabled.
Protected Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus ReceiveInvalidPacket (PacketGameType type)
 Helper for logging receiving invalid packets.
virtual NetworkRecvStatus ReceiveServerFull (Packet &p)
 Notification that the server is full.
virtual NetworkRecvStatus ReceiveServerBanned (Packet &p)
 Notification that the client trying to join is banned.
virtual NetworkRecvStatus ReceiveServerError (Packet &p)
 The client made an error: uint8_t Error code caused (see NetworkErrorCode).
virtual NetworkRecvStatus ReceiveServerGameInfo (Packet &p)
 Sends information about the game.
virtual NetworkRecvStatus ReceiveServerClientInfo (Packet &p)
 Send information about a client: uint32_t ID of the client (always unique on a server.
virtual NetworkRecvStatus ReceiveServerAuthenticationRequest (Packet &p)
 Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to use.
virtual NetworkRecvStatus ReceiveServerEnableEncryption (Packet &p)
 Indication to the client that authentication is complete and encryption has to be used from here on forward.
virtual NetworkRecvStatus ReceiveServerWelcome (Packet &p)
 The client is joined and ready to receive their map: uint32_t Own client ID.
virtual NetworkRecvStatus ReceiveServerWaitForMap (Packet &p)
 Notification that another client is currently receiving the map: uint8_t Number of clients waiting in front of you.
virtual NetworkRecvStatus ReceiveServerMapBegin (Packet &p)
 Sends that the server will begin with sending the map to the client: uint32_t Current frame.
virtual NetworkRecvStatus ReceiveServerMapSize (Packet &p)
 Sends the size of the map to the client.
virtual NetworkRecvStatus ReceiveServerMapData (Packet &p)
 Sends the data of the map to the client: Contains a part of the map (until max size of packet).
virtual NetworkRecvStatus ReceiveServerMapDone (Packet &p)
 Sends that all data of the map are sent to the client:
virtual NetworkRecvStatus ReceiveServerClientJoined (Packet &p)
 A client joined (PacketGameType::ClientMapOk), what usually directly follows is a PacketGameType::ServerClientInfo: uint32_t ID of the client that just joined the game.
virtual NetworkRecvStatus ReceiveServerFrame (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).
virtual NetworkRecvStatus ReceiveServerSync (Packet &p)
 Sends a sync-check to the client: uint32_t Frame counter.
virtual NetworkRecvStatus ReceiveServerCommand (Packet &p)
 Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
virtual NetworkRecvStatus ReceiveServerChat (Packet &p)
 Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
virtual NetworkRecvStatus ReceiveServerExternalChat (Packet &p)
 Sends a chat-packet for external source to the client: string Name of the source this message came from.
virtual NetworkRecvStatus ReceiveServerQuit (Packet &p)
 Notification that a client left the game: uint32_t ID of the client.
virtual NetworkRecvStatus ReceiveServerErrorQuit (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.
virtual NetworkRecvStatus ReceiveServerShutdown (Packet &p)
 Let the clients know that the server is closing.
virtual NetworkRecvStatus ReceiveServerNewGame (Packet &p)
 Let the clients know that the server is loading a new map.
virtual NetworkRecvStatus ReceiveServerRemoteConsoleCommand (Packet &p)
 Send the result of an issues RCon command back to the client: uint16_t Colour code.
virtual NetworkRecvStatus ReceiveServerCheckNewGRFs (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.
virtual NetworkRecvStatus ReceiveServerMove (Packet &p)
 Move a client from one company into another: uint32_t ID of the client.
virtual NetworkRecvStatus ReceiveServerConfigurationUpdate (Packet &p)
 Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
NetworkRecvStatus HandlePacket (Packet &p)
 Handle the given packet, i.e.
 NetworkGameSocketHandler (SOCKET s)
 Create a new socket for the game connection.

Protected Attributes

std::unique_ptr< class NetworkAuthenticationServerHandlerauthentication_handler = nullptr
 The handler for the authentication.
std::string peer_public_key {}
 The public key of our client.
Protected Attributes inherited from NetworkSocketHandler
std::unique_ptr< class NetworkEncryptionHandlerreceive_encryption_handler = nullptr
 The handler for decrypting received packets.
std::unique_ptr< class NetworkEncryptionHandlersend_encryption_handler = nullptr
 The handler for encrypting sent packets.

Detailed Description

Class for handling the server side of the game connection.

Definition at line 24 of file network_server.h.

Member Enumeration Documentation

◆ ClientStatus

Status of a client.

Enumerator
STATUS_INACTIVE 

The client is not connected nor active.

STATUS_AUTH_GAME 

The client is authorizing with game (server) password.

STATUS_IDENTIFY 

The client is identifying itself.

STATUS_NEWGRFS_CHECK 

The client is checking NewGRFs.

STATUS_AUTHORIZED 

The client is authorized.

STATUS_MAP_WAIT 

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

STATUS_MAP 

The client is downloading the map.

STATUS_DONE_MAP 

The client has downloaded the map.

STATUS_PRE_ACTIVE 

The client is catching up the delayed frames.

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 53 of file network_server.h.

Constructor & Destructor Documentation

◆ ServerNetworkGameSocketHandler()

ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler ( ClientPoolID index,
SOCKET s )

◆ ~ServerNetworkGameSocketHandler()

ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler ( )
override

Member Function Documentation

◆ AcceptConnection()

void ServerNetworkGameSocketHandler::AcceptConnection ( SOCKET s,
const NetworkAddress & address )
static

Handle the accepting of a connection to the server.

Parameters
sThe socket of the new connection.
addressThe address of the peer.

Definition at line 578 of file network.cpp.

References _network_clients_connected, client_address, InvalidateWindowData(), ServerNetworkGameSocketHandler(), and WC_CLIENT_LIST.

Referenced by ClientNetworkCoordinatorSocketHandler::ConnectSuccess().

◆ AllowConnection()

bool ServerNetworkGameSocketHandler::AllowConnection ( )
static

Whether an connection is allowed or not at this moment.

Returns
true if the connection is allowed.

Definition at line 292 of file network_server.cpp.

References _network_clients_connected, MAX_CLIENTS, and Pool< NetworkClientSocket, ClientPoolID, 8, PoolType::NetworkClient >::MAX_SIZE.

◆ CheckNextClientToSendMap()

void ServerNetworkGameSocketHandler::CheckNextClientToSendMap ( NetworkClientSocket * ignore_cs = nullptr)

Find the next candidate for joining, and start the joining process for that client.

Parameters
ignore_csA client to ignore while searching.

Definition at line 546 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NetworkGameSocketHandler::GetInfo(), NetworkClientInfo::join_date, SendMap(), status, STATUS_AUTHORIZED, and STATUS_MAP_WAIT.

Referenced by CloseConnection(), and SendMap().

◆ CloseConnection()

◆ GetByClientID()

ServerNetworkGameSocketHandler * ServerNetworkGameSocketHandler::GetByClientID ( ClientID client_id)
static

Return the client state given it's client-identifier.

Parameters
client_idthe ClientID to search for
Returns
return a pointer to the corresponding NetworkClientSocket struct or nullptr when not found

Definition at line 154 of file network.cpp.

References NetworkGameSocketHandler::client_id, and ServerNetworkGameSocketHandler().

◆ GetClientIP()

std::string_view ServerNetworkGameSocketHandler::GetClientIP ( )

Get the IP address/hostname of the connected client.

Returns
The IP address.

Definition at line 1980 of file network_server.cpp.

References client_address.

Referenced by ReceiveClientMapOk().

◆ GetClientName()

std::string ServerNetworkGameSocketHandler::GetClientName ( ) const

Get the name of the client, if the user did not send it yet, Client ID is used.

Returns
The name of a the client.

Definition at line 2165 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, and NetworkGameSocketHandler::GetInfo().

Referenced by CloseConnection(), ReceiveClientError(), ReceiveClientMapOk(), ReceiveClientQuit(), and SendError().

◆ GetName()

std::string_view ServerNetworkGameSocketHandler::GetName ( )
inlinestatic

Get the name used by the listener.

Returns
the name to show in debug logs and the like.

Definition at line 113 of file network_server.h.

Referenced by CloseConnection(), ClientNetworkCoordinatorSocketHandler::ConnectSuccess(), and ReceiveClientMapOk().

◆ GetPeerPublicKey()

std::string_view ServerNetworkGameSocketHandler::GetPeerPublicKey ( ) const
inline

Get the public key of our peer.

Returns
The public key of our client.

Definition at line 124 of file network_server.h.

◆ ReceiveClientAck()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientAck ( Packet & p)
overrideprotectedvirtual

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 PacketGameType::ServerFrame packet.

Parameters
pThe packet that was just received.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1249 of file network_server.cpp.

References _frame_counter, NetworkGameSocketHandler::client_id, Ticks::DAY_TICKS, Debug, IConsoleCmdExec(), NetworkGameSocketHandler::last_frame, NetworkGameSocketHandler::last_frame_server, last_token, last_token_frame, NETWORK_RECV_STATUS_OKAY, NotAuthorized, Packet::Recv_uint32(), Packet::Recv_uint8(), SendError(), status, STATUS_ACTIVE, STATUS_AUTHORIZED, and STATUS_PRE_ACTIVE.

◆ ReceiveClientAuthenticationResponse()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientAuthenticationResponse ( Packet & p)
overrideprotectedvirtual

◆ ReceiveClientChat()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientChat ( Packet & p)
overrideprotectedvirtual

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

uint8_t ID of the destination type (see NetworkChatDestinationType). 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.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1433 of file network_server.cpp.

References CC_WARNING, ChatBroadcast, ChatClient, ChatTeam, NetworkClientInfo::client_id, NetworkGameSocketHandler::client_id, Debug, NetworkGameSocketHandler::GetInfo(), IConsolePrint(), NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkServerSendChat(), NotAuthorized, NotExpected, Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint64(), Packet::Recv_uint8(), SendError(), status, and STATUS_PRE_ACTIVE.

◆ ReceiveClientCommand()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientCommand ( Packet & p)
overrideprotectedvirtual

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). <var> 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.
Returns
The state the network should have.

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

Reimplemented from NetworkGameSocketHandler.

Definition at line 1108 of file network_server.cpp.

References _settings_client, CC_WARNING, Cheater, Client, NetworkClientInfo::client_id, NetworkGameSocketHandler::client_id, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, ClientID, CommandPacket::cmd, CommandPacket::company, COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, CompanyAllowListControl, CompanyControl, CompanyMismatch, CommandPacket::data, Debug, GetCommandFlags(), NetworkGameSocketHandler::GetInfo(), NetworkSocketHandler::HasClientQuit(), IConsolePrint(), NetworkGameSocketHandler::incoming_queue, NetworkGameSocketHandler::info, Kicked, NETWORK_RECV_STATUS_CLIENT_QUIT, NETWORK_RECV_STATUS_OKAY, NetworkServerSendChat(), New, NotExpected, NetworkGameSocketHandler::ReceiveCommand(), SendError(), Server, ServerMessage, Spectator, status, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TooManyCommands.

◆ ReceiveClientError()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientError ( Packet & p)
overrideprotectedvirtual

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.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1194 of file network_server.cpp.

References CC_DEFAULT, NetworkGameSocketHandler::client_id, ClientLeave, CloseConnection(), Debug, GetClientName(), GetNetworkErrorMsg(), GetString(), NetworkSocketHandler::HasClientQuit(), NETWORK_RECV_STATUS_CLIENT_QUIT, NetworkAdminClientError(), NetworkTextMessage(), Packet::Recv_uint8(), status, and STATUS_AUTHORIZED.

◆ ReceiveClientGameInfo()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientGameInfo ( Packet & p)
overrideprotectedvirtual

Request game information.

Parameters
pThe packet that was just received.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 879 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, and SendGameInfo().

◆ ReceiveClientGetMap()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientGetMap ( Packet & p)
overrideprotectedvirtual

Request the map from the server.

Parameters
pThe packet that was just received.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1041 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NetworkSocketHandler::HasClientQuit(), NotAuthorized, SendError(), SendMap(), SendWait(), status, STATUS_MAP, and STATUS_MAP_WAIT.

◆ ReceiveClientIdentify()

◆ ReceiveClientJoin()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientJoin ( Packet & p)
overrideprotectedvirtual

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.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 898 of file network_server.cpp.

References _network_game_info, _settings_client, NetworkGameSocketHandler::client_id, Debug, IsNetworkCompatibleVersion(), NETWORK_REVISION_LENGTH, NotExpected, Packet::Recv_string(), Packet::Recv_uint32(), SendAuthRequest(), SendError(), ServerFull, status, STATUS_INACTIVE, and WrongRevision.

◆ ReceiveClientMapOk()

◆ ReceiveClientMove()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientMove ( Packet & p)
overrideprotectedvirtual

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.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1524 of file network_server.cpp.

References CompanyProperties::allow_any, CompanyProperties::allow_list, NetworkGameSocketHandler::client_id, COMPANY_SPECTATOR, NetworkAuthorizedKeys::Contains(), Debug, Company::IsValidHumanID(), NETWORK_RECV_STATUS_OKAY, NetworkServerDoMove(), NotExpected, Packet::Recv_uint8(), SendError(), status, and STATUS_ACTIVE.

◆ ReceiveClientNewGRFsChecked()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientNewGRFsChecked ( Packet & p)
overrideprotectedvirtual

Tell the server that we have the required GRFs.

Parameters
pThe packet that was just received.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 886 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NotExpected, SendError(), SendWelcome(), status, and STATUS_NEWGRFS_CHECK.

◆ ReceiveClientQuit()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientQuit ( Packet & p)
overrideprotectedvirtual

The client is quitting the game.

Parameters
pThe packet that was just received.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1225 of file network_server.cpp.

References CC_DEFAULT, NetworkGameSocketHandler::client_id, ClientLeave, CloseConnection(), Debug, GetClientName(), NetworkSocketHandler::HasClientQuit(), NETWORK_RECV_STATUS_CLIENT_QUIT, NetworkAdminClientQuit(), NetworkTextMessage(), status, and STATUS_AUTHORIZED.

◆ ReceiveClientRemoteConsoleCommand()

NetworkRecvStatus ServerNetworkGameSocketHandler::ReceiveClientRemoteConsoleCommand ( Packet & p)
overrideprotectedvirtual

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

string Command to be executed.

Parameters
pThe packet that was just received.
Returns
The state the network should have.

Reimplemented from NetworkGameSocketHandler.

Definition at line 1498 of file network_server.cpp.

References _rcon_authorized_key_handler, _redirect_console_to_client, _settings_client, NetworkGameSocketHandler::client_id, Debug, IConsoleCmdExec(), INVALID_CLIENT_ID, NETWORK_PASSWORD_LENGTH, NETWORK_RCONCOMMAND_LENGTH, NETWORK_RECV_STATUS_OKAY, NotExpected, Packet::Recv_string(), SendError(), status, and STATUS_ACTIVE.

◆ ReceiveClientSetName()

◆ ReceivePacket()

std::unique_ptr< Packet > ServerNetworkGameSocketHandler::ReceivePacket ( )
overridevirtual

Receives a packet for the given client.

Returns
The received packet (or nullptr when it didn't receive one)

Reimplemented from NetworkTCPSocketHandler.

Definition at line 224 of file network_server.cpp.

References receive_limit, and NetworkTCPSocketHandler::ReceivePacket().

◆ Send()

void ServerNetworkGameSocketHandler::Send ( )
static

Send the packets for the server sockets.

Definition at line 305 of file network_server.cpp.

References SPS_CLOSED, and STATUS_MAP.

Referenced by NetworkSend().

◆ SendAuthRequest()

◆ SendChat()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat ( NetworkAction action,
ClientID client_id,
bool self_send,
std::string_view msg,
int64_t data )

Send a chat message.

Parameters
actionThe action associated with the message.
client_idThe origin of the chat message.
self_sendWhether we did send the message.
msgThe actual message.
dataArbitrary extra data.
Returns
The new state the network.

Definition at line 718 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), ServerChat, status, STATUS_PRE_ACTIVE, and to_underlying().

◆ SendClientInfo()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo ( NetworkClientInfo * ci)

Send the client information about a client.

Parameters
ciThe client to send information about.
Returns
The new state the network.

Definition at line 328 of file network_server.cpp.

References NetworkClientInfo::client_id, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, Debug, INVALID_CLIENT_ID, NETWORK_RECV_STATUS_OKAY, NetworkClientInfo::public_key, NetworkTCPSocketHandler::SendPacket(), and ServerClientInfo.

Referenced by SendWelcome().

◆ SendCommand()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand ( const CommandPacket & cp)

Send a command to the client to execute.

Parameters
cpThe command to send.
Returns
The new state the network.

Definition at line 695 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, CommandPacket::cmd, Debug, CommandPacket::frame, CommandPacket::my_cmd, NETWORK_RECV_STATUS_OKAY, NetworkGameSocketHandler::SendCommand(), NetworkTCPSocketHandler::SendPacket(), and ServerCommand.

◆ SendConfigUpdate()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate ( )

Send an update about the max company/spectator counts.

Returns
The new state the network.

Definition at line 863 of file network_server.cpp.

References _settings_client, NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerConfigurationUpdate.

Referenced by ReceiveClientMapOk().

◆ SendEnableEncryption()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendEnableEncryption ( )
protected

Notify the client that the authentication has completed and tell that for the remainder of this socket encryption is enabled.

Returns
The new state the network.

Definition at line 474 of file network_server.cpp.

References authentication_handler, NetworkGameSocketHandler::client_id, CloseConnection(), Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), ServerEnableEncryption, status, and STATUS_AUTH_GAME.

Referenced by ReceiveClientAuthenticationResponse().

◆ SendError()

◆ SendErrorQuit()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit ( ClientID client_id,
NetworkErrorCode errorno )

Tell the client another client quit with an error.

Parameters
client_idThe client that quit.
errornoThe reason the client quit.
Returns
The new state the network.

Definition at line 767 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), ServerErrorQuit, and to_underlying().

◆ SendExternalChat()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat ( std::string_view source,
TextColour colour,
std::string_view user,
std::string_view msg )

Send a chat message from external source.

Parameters
sourceName of the source this message came from.
colourTextColour to use for the message.
userName of the user who sent the message.
msgThe actual message.
Returns
The new state the network.

Definition at line 744 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), ServerExternalChat, status, and STATUS_PRE_ACTIVE.

◆ SendFrame()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame ( )

Tell the client that they may run to a particular frame.

Returns
The new state the network.

Definition at line 649 of file network_server.cpp.

References _frame_counter, _frame_counter_max, _sync_seed_1, last_token, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerFrame.

Referenced by ReceiveClientMapOk().

◆ SendGameInfo()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendGameInfo ( )
protected

Send the client information about the server.

Returns
The new state the network.

Definition at line 348 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, GetCurrentNetworkServerGameInfo(), NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), SerializeNetworkGameInfo(), ServerGameInfo, and TCP_MTU.

Referenced by ReceiveClientGameInfo().

◆ SendJoin()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin ( ClientID client_id)

Tell that a client joined.

Parameters
client_idThe client that joined.
Returns
The new state the network.

Definition at line 633 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerClientJoined.

◆ SendMap()

◆ SendMove()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove ( ClientID client_id,
CompanyID company_id )

Tell that a client moved to another company.

Parameters
client_idThe client that moved.
company_idThe company the client moved to.
Returns
The new state the network.

Definition at line 847 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerMove.

◆ SendNewGame()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame ( )

Tell the client we're starting a new game.

Returns
The new state the network.

Definition at line 814 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerNewGame.

◆ SendNewGRFCheck()

◆ SendQuit()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit ( ClientID client_id)

Tell the client another client quit.

Parameters
client_idThe client that quit.
Returns
The new state the network.

Definition at line 785 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerQuit.

◆ SendRConResult()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult ( uint16_t colour,
std::string_view command )

Send the result of a console action.

Parameters
colourThe colour of the result.
commandThe command that was executed.
Returns
The new state the network.

Definition at line 829 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerRemoteConsoleCommand.

◆ SendShutdown()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown ( )

Tell the client we're shutting down.

Returns
The new state the network.

Definition at line 801 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerShutdown.

◆ SendSync()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync ( )

Request the client to sync.

Returns
The new state the network.

Definition at line 675 of file network_server.cpp.

References _frame_counter, _sync_seed_1, NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), and ServerSync.

Referenced by ReceiveClientMapOk().

◆ SendWait()

NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait ( )

Tell the client that its put in a waiting queue.

Returns
The new state the network.

Definition at line 524 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, Debug, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), ServerWaitForMap, and STATUS_MAP_WAIT.

Referenced by ReceiveClientGetMap().

◆ SendWelcome()

Field Documentation

◆ authentication_handler

std::unique_ptr<class NetworkAuthenticationServerHandler> ServerNetworkGameSocketHandler::authentication_handler = nullptr
protected

The handler for the authentication.

Definition at line 26 of file network_server.h.

Referenced by ReceiveClientAuthenticationResponse(), SendAuthRequest(), and SendEnableEncryption().

◆ client_address

NetworkAddress ServerNetworkGameSocketHandler::client_address {}

IP-address of the client (so they can be banned).

Definition at line 75 of file network_server.h.

Referenced by AcceptConnection(), and GetClientIP().

◆ lag_test

uint8_t ServerNetworkGameSocketHandler::lag_test = 0

Byte used for lag-testing the client.

Definition at line 67 of file network_server.h.

◆ last_token

uint8_t ServerNetworkGameSocketHandler::last_token = 0

The last random token we did send to verify the client is listening.

Definition at line 68 of file network_server.h.

Referenced by ReceiveClientAck(), and SendFrame().

◆ last_token_frame

uint32_t ServerNetworkGameSocketHandler::last_token_frame = 0

The last frame we received the right token.

Definition at line 69 of file network_server.h.

Referenced by ReceiveClientAck().

◆ outgoing_queue

CommandQueue ServerNetworkGameSocketHandler::outgoing_queue {}

The command-queue awaiting delivery; conceptually more a bucket to gather commands in, after which the whole bucket is sent to the client.

Definition at line 71 of file network_server.h.

◆ peer_public_key

std::string ServerNetworkGameSocketHandler::peer_public_key {}
protected

The public key of our client.

Definition at line 27 of file network_server.h.

Referenced by ReceiveClientAuthenticationResponse(), and ReceiveClientIdentify().

◆ receive_limit

size_t ServerNetworkGameSocketHandler::receive_limit = 0

Amount of bytes that we can receive at this moment.

Definition at line 72 of file network_server.h.

Referenced by ReceivePacket(), and ServerNetworkGameSocketHandler().

◆ savegame

std::shared_ptr<struct PacketWriter> ServerNetworkGameSocketHandler::savegame = nullptr

Writer used to write the savegame.

Definition at line 74 of file network_server.h.

Referenced by CloseConnection(), SendMap(), and ~ServerNetworkGameSocketHandler().

◆ status


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