OpenTTD Source: ServerNetworkAdminSocketHandler Class Reference

OpenTTD Source 15.3

Data Structures | Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Private Attributes
ServerNetworkAdminSocketHandler Class Reference

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

`#include <network_admin.h>`

Inheritance diagram for ServerNetworkAdminSocketHandler:

## Data Structures
struct | ServerNetworkAdminSocketHandlerFilter

## Public Member Functions
| ServerNetworkAdminSocketHandler (SOCKET s)
| Sanity check.
| ~ServerNetworkAdminSocketHandler ()
| Clear everything related to this admin.
NetworkRecvStatus | SendError (NetworkErrorCode error)
| Send an error to the admin.
NetworkRecvStatus | SendWelcome ()
| Send a welcome message to the admin.
NetworkRecvStatus | SendNewGame ()
| Tell the admin we started a new game.
NetworkRecvStatus | SendShutdown ()
| Tell the admin we're shutting down.
NetworkRecvStatus | SendDate ()
| Tell the admin the date.
NetworkRecvStatus | SendClientJoin (ClientID client_id)
| Tell the admin that a client joined.
NetworkRecvStatus | SendClientInfo (const NetworkClientSocket *cs, const NetworkClientInfo *ci)
| Send an initial set of data from some client's information.
NetworkRecvStatus | SendClientUpdate (const NetworkClientInfo *ci)
| Send an update for some client's information.
NetworkRecvStatus | SendClientQuit (ClientID client_id)
| Tell the admin that a client quit.
NetworkRecvStatus | SendClientError (ClientID client_id, NetworkErrorCode error)
| Tell the admin that a client made an error.
NetworkRecvStatus | SendCompanyNew (CompanyID company_id)
| Tell the admin that a new company was founded.
NetworkRecvStatus | SendCompanyInfo (const Company *c)
| Send the admin some information about a company.
NetworkRecvStatus | SendCompanyUpdate (const Company *c)
| Send an update about a company.
NetworkRecvStatus | SendCompanyRemove (CompanyID company_id, AdminCompanyRemoveReason bcrr)
| Tell the admin that a company got removed.
NetworkRecvStatus | SendCompanyEconomy ()
| Send economic information of all companies.
NetworkRecvStatus | SendCompanyStats ()
| Send statistics about the companies.
NetworkRecvStatus | SendChat (NetworkAction action, DestType desttype, ClientID client_id, std::string_view msg, int64_t data)
| Send a chat message.
NetworkRecvStatus | SendRcon (uint16_t colour, std::string_view command)
| Send the reply of an rcon command.
NetworkRecvStatus | SendConsole (std::string_view origin, std::string_view command)
| Send console output of other clients.
NetworkRecvStatus | SendGameScript (std::string_view json)
| Send GameScript JSON output.
NetworkRecvStatus | SendCmdNames ()
| Send the names of the commands.
NetworkRecvStatus | SendCmdLogging (ClientID client_id, const CommandPacket &cp)
| Send a command for logging purposes.
NetworkRecvStatus | SendRconEnd (std::string_view command)
| Send a notification indicating the rcon command has completed.
Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >
void * | operator new (size_t size)
| Allocates space for new Titem.
void * | operator new (size_t size, Tindex index)
| Allocates space for new Titem with given index.
void * | operator new (size_t, void *ptr)
| Allocates space for new Titem at given memory address.
void | operator delete (void *p, size_t size)
| Marks Titem as free.
Public Member Functions inherited from NetworkAdminSocketHandler
NetworkRecvStatus | CloseConnection (bool error=true) override
| This will put this socket handler in a close state.
| NetworkAdminSocketHandler (SOCKET s)
| Create the admin handler for the given socket.
NetworkRecvStatus | ReceivePackets ()
| Do the actual receiving of packets.
AdminStatus | GetAdminStatus () const
| Get the status of the admin.
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.
virtual std::unique_ptr< Packet > | ReceivePacket ()
| Receives a packet for the given client.
bool | CanSendReceive ()
| Check whether this socket can send or receive something.
bool | HasSendQueue ()
| Whether there is something pending in the send queue.
| NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
| Construct a socket handler for a TCP connection.
Public Member Functions inherited from NetworkSocketHandler
| NetworkSocketHandler ()=default
| Create a new unbound socket.
virtual | ~NetworkSocketHandler ()=default
| Close the socket when destructing the socket handler.
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 acceptance of a connection.
static bool | AllowConnection ()
| Whether a connection is allowed or not at this moment.
static void | WelcomeAll ()
| Send a Welcome packet to all connected admins.
static std::string_view | GetName ()
| Get the name used by the listener.
static Pool::IterateWrapperFiltered< ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter > | IterateActive (size_t from=0)
| Returns an iterable ensemble of all active admin sockets.
Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >
static bool | CanAllocateItem (size_t n=1)
| Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static bool | CleaningPool ()
| Returns current state of pool cleaning - yes or no.
static bool | IsValidID (auto index)
| Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * | Get (auto index)
| Returns Titem with given index.
static Titem * | GetIfValid (auto index)
| Returns Titem with given index.
static size_t | GetPoolSize ()
| Returns first unused index.
static size_t | GetNumItems ()
| Returns number of valid items in the pool.
static void | PostDestructor (size_t index)
| Dummy function called after destructor of each member.
static Pool::IterateWrapper< Titem > | Iterate (size_t from=0)
| Returns an iterable ensemble of all valid Titem.
Static Public Member Functions inherited from TCPListenHandler< ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED >
static bool | ValidateClient (SOCKET s, NetworkAddress &address)
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
std::array< AdminUpdateFrequencies, ADMIN_UPDATE_END > | update_frequency {}
| Admin requested update intervals.
std::chrono::steady_clock::time_point | connect_time {}
| Time of connection.
NetworkAddress | address {}
| Address of the admin.
Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >
Tindex | index
| Index of this pool item.
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 | Receive_ADMIN_JOIN (Packet &p) override
| Join the admin network using an unsecured password exchange: string Unsecured password the server is expecting for this network.
NetworkRecvStatus | Receive_ADMIN_QUIT (Packet &p) override
| Notification to the server that this admin is quitting.
NetworkRecvStatus | Receive_ADMIN_UPDATE_FREQUENCY (Packet &p) override
| Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16_t Update type (see AdminUpdateType).
NetworkRecvStatus | Receive_ADMIN_POLL (Packet &p) override
| Poll the server for certain updates, an invalid poll (e.g.
NetworkRecvStatus | Receive_ADMIN_CHAT (Packet &p) override
| Send chat as the server: uint8_t Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
NetworkRecvStatus | Receive_ADMIN_EXTERNAL_CHAT (Packet &p) override
| Send chat from the external source: string Name of the source this message came from.
NetworkRecvStatus | Receive_ADMIN_RCON (Packet &p) override
| Execute a command on the servers console: string Command to be executed.
NetworkRecvStatus | Receive_ADMIN_GAMESCRIPT (Packet &p) override
| Send a JSON string to the current active GameScript.
NetworkRecvStatus | Receive_ADMIN_PING (Packet &p) override
| Ping the server, requiring the server to reply with a pong packet.
NetworkRecvStatus | Receive_ADMIN_JOIN_SECURE (Packet &p) override
| Join the admin network using a secure authentication method: string Name of the application being used to connect.
NetworkRecvStatus | Receive_ADMIN_AUTH_RESPONSE (Packet &p) override
| Admin responds to `ADMIN_PACKET_SERVER_AUTH_REQUEST` with the appropriate data given the agreed upon `NetworkAuthenticationMethod`.
NetworkRecvStatus | SendProtocol ()
| Send the protocol version to the admin.
NetworkRecvStatus | SendPong (uint32_t d1)
| Send ping-reply (pong) to admin.
NetworkRecvStatus | SendAuthRequest ()
NetworkRecvStatus | SendEnableEncryption ()
Protected Member Functions inherited from NetworkAdminSocketHandler
NetworkRecvStatus | ReceiveInvalidPacket (PacketAdminType type)
| Helper for logging receiving invalid packets.
virtual NetworkRecvStatus | Receive_SERVER_FULL (Packet &p)
| The server is full (connection gets closed).
virtual NetworkRecvStatus | Receive_SERVER_BANNED (Packet &p)
| The source IP address is banned (connection gets closed).
virtual NetworkRecvStatus | Receive_SERVER_ERROR (Packet &p)
| An error was caused by this admin connection (connection gets closed).
virtual NetworkRecvStatus | Receive_SERVER_PROTOCOL (Packet &p)
| Inform a just joined admin about the protocol specifics: uint8_t Protocol version.
virtual NetworkRecvStatus | Receive_SERVER_WELCOME (Packet &p)
| Welcome a connected admin to the game: string Name of the Server.
virtual NetworkRecvStatus | Receive_SERVER_NEWGAME (Packet &p)
| Notification about a newgame.
virtual NetworkRecvStatus | Receive_SERVER_SHUTDOWN (Packet &p)
| Notification about the server shutting down.
virtual NetworkRecvStatus | Receive_SERVER_DATE (Packet &p)
| Send the current date of the game: uint32_t Current game date.
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_JOIN (Packet &p)
| Notification of a new client: uint32_t ID of the new client.
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_INFO (Packet &p)
| Client information of a specific client: uint32_t ID of the client.
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_UPDATE (Packet &p)
| Client update details on a specific client (e.g.
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_QUIT (Packet &p)
| Notification about a client leaving the game.
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_ERROR (Packet &p)
| Notification about a client error (and thus the clients disconnection).
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_NEW (Packet &p)
| Notification of a new company: uint8_t ID of the new company.
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_INFO (Packet &p)
| Company information on a specific company: uint8_t ID of the company.
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_UPDATE (Packet &p)
| Company information of a specific company: uint8_t ID of the company.
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_REMOVE (Packet &p)
| Notification about a removed company (e.g.
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_ECONOMY (Packet &p)
| Economy update of a specific company: uint8_t ID of the company.
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_STATS (Packet &p)
| Company statistics on stations and vehicles: uint8_t ID of the company.
virtual NetworkRecvStatus | Receive_SERVER_CHAT (Packet &p)
| Send chat from the game into the admin network: uint8_t Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
virtual NetworkRecvStatus | Receive_SERVER_RCON (Packet &p)
| Result of an rcon command: uint16_t Colour as it would be used on the server or a client.
virtual NetworkRecvStatus | Receive_SERVER_CONSOLE (Packet &p)
| Send what would be printed on the server's console also into the admin network.
virtual NetworkRecvStatus | Receive_SERVER_CMD_NAMES (Packet &p)
| Send DoCommand names to the bot upon request only.
virtual NetworkRecvStatus | Receive_SERVER_CMD_LOGGING (Packet &p)
| Send incoming command packets to the admin network.
virtual NetworkRecvStatus | Receive_SERVER_AUTH_REQUEST (Packet &p)
| Server requests authentication challenge from the admin.
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.
virtual NetworkRecvStatus | Receive_SERVER_PONG (Packet &p)
| Send a ping-reply (pong) to the admin that sent us the ping packet.
virtual NetworkRecvStatus | Receive_SERVER_RCON_END (Packet &p)
| Notify the admin connection that the rcon command has finished.
NetworkRecvStatus | HandlePacket (Packet &p)
| Handle the given packet, i.e.

## Private Attributes
std::unique_ptr< NetworkAuthenticationServerHandler > | authentication_handler = nullptr
| The handler for the authentication.

## Additional Inherited Members
Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > | Pool
| Type of the pool this item is going to be part of.
Protected Attributes inherited from NetworkAdminSocketHandler
std::string | admin_name {}
| Name of the admin.
std::string | admin_version {}
| Version string of the admin.
AdminStatus | status = ADMIN_STATUS_INACTIVE
| Status of this admin.
Protected Attributes inherited from NetworkSocketHandler
std::unique_ptr< class NetworkEncryptionHandler > | receive_encryption_handler = nullptr
| The handler for decrypting received packets.
std::unique_ptr< class NetworkEncryptionHandler > | send_encryption_handler = nullptr
| The handler for encrypting sent packets.

## Detailed Description

Class for handling the server side of the game connection.

Definition at line 25 of file network_admin.h.

## Constructor & Destructor Documentation

## ◆ ServerNetworkAdminSocketHandler()

ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler | ( | SOCKET | s | ) |

Sanity check.

Create a new socket for the server side of the admin network.

Parameters

  s | The socket to connect with.

Definition at line 67 of file network_admin.cpp.

References ADMIN_STATUS_INACTIVE, connect_time, and NetworkAdminSocketHandler::status.

## ◆ ~ServerNetworkAdminSocketHandler()

ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler | ( |  | ) |

Clear everything related to this admin.

Definition at line 76 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_UPDATE_CONSOLE, NetworkAdminSocketHandler::admin_version, Automatic, Debug, DebugReconsiderSendRemoteMessages(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >::index, and update_frequency.

## Member Function Documentation

## ◆ AcceptConnection()

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

Handle the acceptance of a connection.

Parameters

  s | The socket of the new connection.
  address | The address of the peer.

Definition at line 116 of file network_admin.cpp.

References address.

## ◆ AllowConnection()

bool ServerNetworkAdminSocketHandler::AllowConnection | ( |  | ) |
| static

Whether a connection is allowed or not at this moment.

Returns
  Whether the connection is allowed.

Definition at line 91 of file network_admin.cpp.

References _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >::CanAllocateItem(), and ClientSettings::network.

## ◆ GetName()

static std::string_view ServerNetworkAdminSocketHandler::GetName | ( |  | ) |
| inlinestatic

Get the name used by the listener.

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

Definition at line 88 of file network_admin.h.

## ◆ IterateActive()

static Pool::IterateWrapperFiltered< ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter > ServerNetworkAdminSocketHandler::IterateActive | ( | size_t | from = `0` | ) |
| inlinestatic

Returns an iterable ensemble of all active admin sockets.

Parameters

  from | index of the first socket to consider

Returns
  an iterable ensemble of all active admin sockets

Definition at line 102 of file network_admin.h.

Referenced by DebugReconsiderSendRemoteMessages(), NetworkAdminChat(), NetworkAdminClientError(), NetworkAdminClientInfo(), NetworkAdminClientQuit(), NetworkAdminClientUpdate(), NetworkAdminCmdLogging(), NetworkAdminCompanyNew(), NetworkAdminCompanyRemove(), NetworkAdminCompanyUpdate(), NetworkAdminConsole(), NetworkAdminGameScript(), NetworkAdminUpdate(), NetworkDisconnect(), and WelcomeAll().

## ◆ Receive_ADMIN_AUTH_RESPONSE()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_AUTH_RESPONSE | ( | Packet & | p | ) |
| overrideprotectedvirtual

Admin responds to `ADMIN_PACKET_SERVER_AUTH_REQUEST` with the appropriate data given the agreed upon `NetworkAuthenticationMethod`.

With `NETWORK_AUTH_METHOD_X25519_PAKE` and `NETWORK_AUTH_METHOD_X25519_AUTHORIZED_KEY:` 32 * uint8_t Public key of the client. 16 * uint8_t Message authentication code (mac). 8 * uint8_t Encrypted message of the authentication (just random bytes).

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 845 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, NetworkAdminSocketHandler::admin_version, NetworkAuthenticationServerHandler::Authenticated, authentication_handler, Debug, NetworkAuthenticationServerHandler::NotAuthenticated, NetworkSocketHandler::receive_encryption_handler, NetworkAuthenticationServerHandler::RetryNextMethod, NetworkSocketHandler::send_encryption_handler, SendError(), SendProtocol(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_CHAT()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT | ( | Packet & | p | ) |
| overrideprotectedvirtual

Send chat as the server: uint8_t Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).

uint8_t Destination type such as DESTTYPE_BROADCAST (see DestType). uint32_t ID of the destination such as company or client id. string Message.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 746 of file network_admin.cpp.

References _network_own_client_id, NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, NetworkAdminSocketHandler::admin_version, Debug, NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkServerSendChat(), Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint8(), SendError(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_EXTERNAL_CHAT()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT | ( | Packet & | p | ) |
| overrideprotectedvirtual

Send chat from the external source: 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 message. string Message.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 772 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, NetworkAdminSocketHandler::admin_version, Debug, IsValidConsoleColour(), NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkServerSendExternalChat(), Packet::Recv_string(), Packet::Recv_uint16(), SendError(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_GAMESCRIPT()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT | ( | Packet & | p | ) |
| overrideprotectedvirtual

Send a JSON string to the current active GameScript.

json JSON string for the GameScript.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 501 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, NetworkAdminSocketHandler::admin_version, Debug, NETWORK_GAMESCRIPT_JSON_LENGTH, NETWORK_RECV_STATUS_OKAY, Game::NewEvent(), Packet::Recv_string(), SendError(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_JOIN()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN | ( | Packet & | p | ) |
| overrideprotectedvirtual

Join the admin network using an unsecured password exchange: string Unsecured password the server is expecting for this network.

string Name of the application being used to connect. string Version string of the application being used to connect.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 625 of file network_admin.cpp.

References _settings_client, NetworkAdminSocketHandler::admin_name, NetworkSettings::admin_password, ADMIN_STATUS_INACTIVE, NetworkAdminSocketHandler::admin_version, NetworkSettings::allow_insecure_admin_login, Debug, ClientSettings::network, NETWORK_CLIENT_NAME_LENGTH, NETWORK_PASSWORD_LENGTH, NETWORK_REVISION_LENGTH, Packet::Recv_string(), SendError(), SendProtocol(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_JOIN_SECURE()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN_SECURE | ( | Packet & | p | ) |
| overrideprotectedvirtual

Join the admin network using a secure authentication method: string Name of the application being used to connect.

string Version string of the application being used to connect. uint16_t Bitmask of supported authentication methods. See `NetworkAuthenticationMethod` for the supported methods.

The server will determine which of the authentication methods supplied by the client will be used. When there is no supported authentication method, an `ADMIN_PACKET_SERVER_ERROR` packet will be sent with `NETWORK_ERROR_NO_AUTHENTICATION_METHOD_AVAILABLE` as error.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 795 of file network_admin.cpp.

References _admin_authorized_key_handler(), _admin_password_provider(), NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_INACTIVE, NetworkAdminSocketHandler::admin_version, authentication_handler, NetworkAuthenticationServerHandler::Create(), Debug, NETWORK_CLIENT_NAME_LENGTH, NETWORK_REVISION_LENGTH, Packet::Recv_string(), Packet::Recv_uint16(), SendError(), NetworkAdminSocketHandler::status, and X25519_KeyExchangeOnly.

## ◆ Receive_ADMIN_PING()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING | ( | Packet & | p | ) |
| overrideprotectedvirtual

Ping the server, requiring the server to reply with a pong packet.

uint32_t Integer value to pass to the server, which is quoted in the reply.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 513 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, NetworkAdminSocketHandler::admin_version, Debug, Packet::Recv_uint32(), SendError(), SendPong(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_POLL()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL | ( | Packet & | p | ) |
| overrideprotectedvirtual

Poll the server for certain updates, an invalid poll (e.g.

not existent id) gets silently dropped: uint8_t AdminUpdateType the server should answer for, only if AdminUpdateFrequency::Poll is advertised in the PROTOCOL packet. Note integer type - see "Certain Packet Information" in docs/admin_network.md. uint32_t ID relevant to the packet type, e.g.

- the client ID for ADMIN_UPDATE_CLIENT_INFO. Use UINT32_MAX to show all clients.
- the company ID for ADMIN_UPDATE_COMPANY_INFO. Use UINT32_MAX to show all companies.
  Parameters

    p | The packet that was just received.

  Returns
    The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 680 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, ADMIN_UPDATE_CLIENT_INFO, ADMIN_UPDATE_CMD_NAMES, ADMIN_UPDATE_COMPANY_ECONOMY, ADMIN_UPDATE_COMPANY_INFO, ADMIN_UPDATE_COMPANY_STATS, ADMIN_UPDATE_DATE, NetworkAdminSocketHandler::admin_version, CLIENT_ID_SERVER, Debug, NetworkClientInfo::GetByClientID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), SendClientInfo(), SendCmdNames(), SendCompanyEconomy(), SendCompanyInfo(), SendCompanyStats(), SendDate(), SendError(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_QUIT()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT | ( | Packet & | p | ) |
| overrideprotectedvirtual

Notification to the server that this admin is quitting.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 654 of file network_admin.cpp.

References NetworkAdminSocketHandler::CloseConnection().

## ◆ Receive_ADMIN_RCON()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON | ( | Packet & | p | ) |
| overrideprotectedvirtual

Execute a command on the servers console: string Command to be executed.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 487 of file network_admin.cpp.

References _redirect_console_to_admin, NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, NetworkAdminSocketHandler::admin_version, Debug, IConsoleCmdExec(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >::index, NETWORK_RCONCOMMAND_LENGTH, Packet::Recv_string(), SendError(), SendRconEnd(), and NetworkAdminSocketHandler::status.

## ◆ Receive_ADMIN_UPDATE_FREQUENCY()

NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY | ( | Packet & | p | ) |
| overrideprotectedvirtual

Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16_t Update type (see AdminUpdateType).

Note integer type - see "Certain Packet Information" in docs/admin_network.md. uint16_t Update frequency (see AdminUpdateFrequency), setting AdminUpdateFrequency::Poll is always ignored.

Parameters

  p | The packet that was just received.

Returns
  The state the network should have.

Reimplemented from NetworkAdminSocketHandler.

Definition at line 660 of file network_admin.cpp.

References _admin_update_type_frequencies, NetworkAdminSocketHandler::admin_name, ADMIN_STATUS_AUTHENTICATE, ADMIN_UPDATE_CONSOLE, ADMIN_UPDATE_END, NetworkAdminSocketHandler::admin_version, Debug, DebugReconsiderSendRemoteMessages(), NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint16(), SendError(), NetworkAdminSocketHandler::status, and update_frequency.

## ◆ Send()

void ServerNetworkAdminSocketHandler::Send | ( |  | ) |
| static

Send the packets for the server sockets.

Definition at line 97 of file network_admin.cpp.

References ADMIN_AUTHORISATION_TIMEOUT(), ADMIN_STATUS_AUTHENTICATE, Debug, and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_networkadminsocket_pool >::Iterate().

## ◆ SendAuthRequest()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendAuthRequest | ( |  | ) |
| protected

Definition at line 820 of file network_admin.cpp.

## ◆ SendChat()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat | ( | NetworkAction | action,
|  | DestType | desttype,
|  | ClientID | client_id,
|  | std::string_view | msg,
|  | int64_t | data
| ) |  |

Send a chat message.

Parameters

  action | The action associated with the message.
  desttype | The destination type.
  client_id | The origin of the chat message.
  msg | The actual message.
  data | Arbitrary extra data.

Definition at line 443 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CHAT, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendClientError()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError | ( | ClientID | client_id,
|  | NetworkErrorCode | error
| ) |  |

Tell the admin that a client made an error.

Parameters

  client_id | The client that made the error.
  error | The error that was made.

Definition at line 292 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_ERROR, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendClientInfo()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo | ( | const NetworkClientSocket * | cs,
|  | const NetworkClientInfo * | ci
| ) |  |

Send an initial set of data from some client's information.

Parameters

  cs | The socket of the client.
  ci | The information about the client.

Definition at line 236 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_INFO, NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, NetworkClientInfo::join_date, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_POLL().

## ◆ SendClientJoin()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin | ( | ClientID | client_id | ) |

Tell the admin that a client joined.

Parameters

  client_id | The client that joined.

Definition at line 221 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_JOIN, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendClientQuit()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit | ( | ClientID | client_id | ) |

Tell the admin that a client quit.

Parameters

  client_id | The client that quit.

Definition at line 277 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_QUIT, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendClientUpdate()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate | ( | const NetworkClientInfo * | ci | ) |

Send an update for some client's information.

Parameters

  ci | The information about a client.

Definition at line 260 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_UPDATE, NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendCmdLogging()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging | ( | ClientID | client_id,
|  | const CommandPacket & | cp
| ) |  |

Send a command for logging purposes.

Parameters

  client_id | The client executing the command.
  cp | The command that would be executed.

Definition at line 606 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CMD_LOGGING, CommandPacket::cmd, CommandPacket::company, CommandPacket::data, CommandPacket::frame, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendCmdNames()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames | ( |  | ) |

Send the names of the commands.

Definition at line 572 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CMD_NAMES, CMD_END, GetCommandName(), NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_POLL().

## ◆ SendCompanyEconomy()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy | ( |  | ) |

Send economic information of all companies.

Definition at line 378 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_ECONOMY, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_POLL().

## ◆ SendCompanyInfo()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo | ( | const Company * | c | ) |

Send the admin some information about a company.

Parameters

  c | The company to send the information about.

Definition at line 321 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_INFO, CeilDiv(), CompanyProperties::colour, GetString(), CompanyProperties::inaugurated_year, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, CompanyProperties::is_ai, CompanyProperties::months_of_bankruptcy, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_POLL().

## ◆ SendCompanyNew()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew | ( | CompanyID | company_id | ) |

Tell the admin that a new company was founded.

Parameters

  company_id | The company that was founded.

Definition at line 307 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_NEW, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendCompanyRemove()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove | ( | CompanyID | company_id,
|  | AdminCompanyRemoveReason | acrr
| ) |  |

Tell the admin that a company got removed.

Parameters

  company_id | The company that got removed.
  acrr | The reason for removal, e.g. bankruptcy or merger.

Definition at line 365 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_REMOVE, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendCompanyStats()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats | ( |  | ) |

Send statistics about the companies.

Definition at line 409 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_STATS, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), NETWORK_RECV_STATUS_OKAY, NetworkGetCompanyStats(), and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_POLL().

## ◆ SendCompanyUpdate()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate | ( | const Company * | c | ) |

Send an update about a company.

Parameters

  c | The company to send the update of.

Definition at line 344 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_UPDATE, CeilDiv(), CompanyProperties::colour, GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, CompanyProperties::months_of_bankruptcy, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendConsole()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole | ( | std::string_view | origin,
|  | std::string_view | string
| ) |  |

Send console output of other clients.

Parameters

  origin | The origin of the string.
  string | The string that's put on the console.

Definition at line 529 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CONSOLE, COMPAT_MTU, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendDate()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate | ( |  | ) |

Tell the admin the date.

Definition at line 207 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_DATE, TimerGameCalendar::date, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_POLL().

## ◆ SendEnableEncryption()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendEnableEncryption | ( |  | ) |
| protected

Definition at line 834 of file network_admin.cpp.

## ◆ SendError()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError | ( | NetworkErrorCode | error | ) |

Send an error to the admin.

Parameters

  error | The error to send.

Definition at line 130 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_PACKET_SERVER_ERROR, NetworkAdminSocketHandler::admin_version, authentication_handler, NetworkAdminSocketHandler::CloseConnection(), Debug, GetNetworkErrorMsg(), GetString(), and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_AUTH_RESPONSE(), Receive_ADMIN_CHAT(), Receive_ADMIN_EXTERNAL_CHAT(), Receive_ADMIN_GAMESCRIPT(), Receive_ADMIN_JOIN(), Receive_ADMIN_JOIN_SECURE(), Receive_ADMIN_PING(), Receive_ADMIN_POLL(), Receive_ADMIN_RCON(), and Receive_ADMIN_UPDATE_FREQUENCY().

## ◆ SendGameScript()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript | ( | std::string_view | json | ) |

Send GameScript JSON output.

Parameters

  json | The JSON string.

Definition at line 550 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_GAMESCRIPT, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendNewGame()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame | ( |  | ) |

Tell the admin we started a new game.

Definition at line 191 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_NEWGAME, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendPong()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong | ( | uint32_t | d1 | ) |
| protected

Send ping-reply (pong) to admin.

Definition at line 561 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_PONG, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_PING().

## ◆ SendProtocol()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol | ( |  | ) |
| protected

Send the protocol version to the admin.

Definition at line 148 of file network_admin.cpp.

References _admin_update_type_frequencies, ADMIN_PACKET_SERVER_PROTOCOL, ADMIN_STATUS_ACTIVE, ADMIN_UPDATE_END, NETWORK_GAME_ADMIN_VERSION, NetworkTCPSocketHandler::SendPacket(), SendWelcome(), and NetworkAdminSocketHandler::status.

Referenced by Receive_ADMIN_AUTH_RESPONSE(), and Receive_ADMIN_JOIN().

## ◆ SendRcon()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon | ( | uint16_t | colour,
|  | std::string_view | result
| ) |  |

Send the reply of an rcon command.

Parameters

  colour | The colour of the text.
  result | The result of the command.

Definition at line 476 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_RCON, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendRconEnd()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd | ( | std::string_view | command | ) |

Send a notification indicating the rcon command has completed.

Parameters

  command | The original command sent.

Definition at line 461 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_RCON_END, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

Referenced by Receive_ADMIN_RCON().

## ◆ SendShutdown()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown | ( |  | ) |

Tell the admin we're shutting down.

Definition at line 199 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_SHUTDOWN, NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::SendPacket().

## ◆ SendWelcome()

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome | ( |  | ) |

Send a welcome message to the admin.

Definition at line 170 of file network_admin.cpp.

References _network_dedicated, _settings_client, _settings_game, ADMIN_PACKET_SERVER_WELCOME, TimerGameCalendar::ConvertYMDToDate(), GameSettings::game_creation, GameCreationSettings::generation_seed, GameCreationSettings::landscape, ClientSettings::network, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPacket(), NetworkSettings::server_name, Map::SizeX(), Map::SizeY(), GameCreationSettings::starting_year, and to_underlying().

Referenced by SendProtocol().

## ◆ WelcomeAll()

void ServerNetworkAdminSocketHandler::WelcomeAll | ( |  | ) |
| static

Send a Welcome packet to all connected admins.

Definition at line 1050 of file network_admin.cpp.

References IterateActive().

Referenced by NetworkOnGameStart().

## Field Documentation

## ◆ address

NetworkAddress ServerNetworkAdminSocketHandler::address {}

Address of the admin.

Definition at line 48 of file network_admin.h.

Referenced by AcceptConnection().

## ◆ authentication_handler

std::unique_ptr<NetworkAuthenticationServerHandler> ServerNetworkAdminSocketHandler::authentication_handler = nullptr
| private

The handler for the authentication.

Definition at line 27 of file network_admin.h.

Referenced by Receive_ADMIN_AUTH_RESPONSE(), Receive_ADMIN_JOIN_SECURE(), and SendError().

## ◆ connect_time

std::chrono::steady_clock::time_point ServerNetworkAdminSocketHandler::connect_time {}

Time of connection.

Definition at line 47 of file network_admin.h.

Referenced by ServerNetworkAdminSocketHandler().

## ◆ update_frequency

std::array<AdminUpdateFrequencies, ADMIN_UPDATE_END> ServerNetworkAdminSocketHandler::update_frequency {}

Admin requested update intervals.

Definition at line 46 of file network_admin.h.

Referenced by Receive_ADMIN_UPDATE_FREQUENCY(), and ~ServerNetworkAdminSocketHandler().

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

- src/network/network_admin.h
- src/network/network_admin.cpp