# NetworkAdminSocketHandler Class Reference

Main socket handler for admin related connections. More...

`#include <tcp_admin.h>`

Inheritance diagram for NetworkAdminSocketHandler:

## Public Member Functions
NetworkRecvStatus | CloseConnection (bool error=true)
| Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just means the packet has to be dropped.
| NetworkAdminSocketHandler (SOCKET s)
NetworkRecvStatus | ReceivePackets ()
| Do the actual receiving of packets.
const char * | ReceiveCommand (Packet *p, struct CommandPacket *cp)
void | SendCommand (Packet *p, const struct CommandPacket *cp)
## Protected Member Functions
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_ADMIN_JOIN)
| Join the admin network: string Password the server is expecting for this network.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_ADMIN_QUIT)
| Notification to the server that this admin is quitting.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY)
| Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16 Update type (see AdminUpdateType).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_ADMIN_POLL)
| Poll the server for certain updates, an invalid poll (e.g.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_ADMIN_CHAT)
| Send chat as the server: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_ADMIN_RCON)
| Execute a command on the servers console: string Command to be executed.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_FULL)
| The server is full (connection gets closed).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_BANNED)
| The source IP address is banned (connection gets closed).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_ERROR)
| An error was caused by this admin connection (connection gets closed).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_PROTOCOL)
| Inform a just joined admin about the protocol specifics: uint8 Protocol version.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_WELCOME)
| Welcome a connected admin to the game: string Name of the Server (e.g.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_NEWGAME)
| Notification about a newgame.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_SHUTDOWN)
| Notification about the server shutting down.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_DATE)
| Send the current date of the game: uint32 Current game date.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CLIENT_JOIN)
| Notification of a new client: uint32 ID of the new client.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CLIENT_INFO)
| Client information of a specific client: uint32 ID of the client.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CLIENT_UPDATE)
| Client update details on a specific client (e.g.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CLIENT_QUIT)
| Notification about a client leaving the game.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CLIENT_ERROR)
| Notification about a client error (and thus the clients disconnection).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_COMPANY_NEW)
| Notification of a new company: uint8 ID of the new company.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_COMPANY_INFO)
| Company information on a specific company: uint8 ID of the company.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_COMPANY_UPDATE)
| Company information of a specific company: uint8 ID of the company.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_COMPANY_REMOVE)
| Notification about a removed company (e.g.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_COMPANY_ECONOMY)
| Economy update of a specific company: uint8 ID of the company.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_COMPANY_STATS)
| Company statistics on stations and vehicles: uint8 ID of the company.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CHAT)
| Send chat from the game into the admin network: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_RCON)
| Result of an rcon command: uint16 Colour as it would be used on the server or a client.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CONSOLE)
| Send what would be printed on the server's console also into the admin network.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CMD_NAMES)
| Send DoCommand names to the bot upon request only.
| DECLARE_ADMIN_RECEIVE_COMMAND (ADMIN_PACKET_SERVER_CMD_LOGGING)
| Send incoming command packets to the admin network.
NetworkRecvStatus | HandlePacket (Packet *p)
| Handle the given packet, i.e.
## Protected Attributes
char | admin_name [NETWORK_CLIENT_NAME_LENGTH]
| Name of the admin.
char | admin_version [NETWORK_REVISION_LENGTH]
| Version string of the admin.
AdminStatus | status
| Status of this admin.

## Detailed Description

Main socket handler for admin related connections.

Definition at line 109 of file tcp_admin.h.

## Member Function Documentation

NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection | ( | bool | error = `true` | ) | `[virtual]`

Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just means the packet has to be dropped.

Parameters:

  | error | Whether we quit under an error condition or not.

Returns:
  new status of the connection.

Reimplemented from NetworkTCPSocketHandler.

Definition at line 31 of file tcp_admin.cpp.

References NETWORK_RECV_STATUS_CONN_LOST.

Referenced by HandlePacket(), NetworkClose(), and ServerNetworkAdminSocketHandler::Send().

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CMD_LOGGING |  | ) | `[protected]`

Send incoming command packets to the admin network.

This is for logging purposes only.

NOTICE: Data provided with this packet is not stable and will not be treated as such. Do not rely on IDs or names to be constant across different versions / revisions of OpenTTD. Data provided in this packet is for logging purposes only.

uint32 ID of the client sending the command. uint8 ID of the company (0..MAX_COMPANIES-1). uint16 ID of the command. uint32 P1 (variable data passed to the command). uint32 P2 (variable data passed to the command). uint32 Tile where this is taking place. string Text passed to the command. uint32 Frame of execution.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CMD_NAMES |  | ) | `[protected]`

Send DoCommand names to the bot upon request only.

Multiple of these packets can follow each other in order to provide all known DoCommand names.

NOTICE: Data provided with this packet is not stable and will not be treated as such. Do not rely on IDs or names to be constant across different versions / revisions of OpenTTD. Data provided in this packet is for logging purposes only.

These three fields are repeated until the packet is full: bool Data to follow. uint16 ID of the DoCommand. string Name of DoCommand.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CONSOLE |  | ) | `[protected]`

Send what would be printed on the server's console also into the admin network.

string The origin of the text, e.g. "console" for console, or "net" for network related (debug) messages. string Text as found on the console of the server.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_RCON |  | ) | `[protected]`

Result of an rcon command: uint16 Colour as it would be used on the server or a client.

string Output of the executed command.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CHAT |  | ) | `[protected]`

Send chat from the game into the admin network: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).

uint8 Destination type such as DESTTYPE_BROADCAST (see DestType). uint32 ID of the client who sent this message. string Message. uint64 Money (only when it is a 'give money' action).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_COMPANY_STATS |  | ) | `[protected]`

Company statistics on stations and vehicles: uint8 ID of the company.

uint16 Number of trains. uint16 Number of lorries. uint16 Number of busses. uint16 Number of planes. uint16 Number of ships. uint16 Number of train stations. uint16 Number of lorry stations. uint16 Number of bus stops. uint16 Number of airports and heliports. uint16 Number of harbours.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_COMPANY_ECONOMY |  | ) | `[protected]`

Economy update of a specific company: uint8 ID of the company.

uint64 Money. uint64 Loan. uint64 Income. uint64 Company value (last quarter). uint16 Performance (last quarter). uint16 Delivered cargo (last quarter). uint64 Company value (previous quarter). uint16 Performance (previous quarter). uint16 Delivered cargo (previous quarter).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_COMPANY_REMOVE |  | ) | `[protected]`

Notification about a removed company (e.g.

due to banrkuptcy). uint8 ID of the company. uint8 Reason for being removed (see AdminCompanyRemoveReason).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_COMPANY_UPDATE |  | ) | `[protected]`

Company information of a specific company: uint8 ID of the company.

string Name of the company. string Name of the companies manager. uint8 Main company colour. bool Company is password protected. uint8 Quarters of bankruptcy. uint8 Owner of share 1. uint8 Owner of share 2. uint8 Owner of share 3. uint8 Owner of share 4.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_COMPANY_INFO |  | ) | `[protected]`

Company information on a specific company: uint8 ID of the company.

string Name of the company. string Name of the companies manager. uint8 Main company colour. bool Company is password protected. uint32 Year the company was inaugurated. bool Company is an AI.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CLIENT_ERROR |  | ) | `[protected]`

Notification about a client error (and thus the clients disconnection).

uint32 ID of the client that made the error. uint8 Error the client made (see NetworkErrorCode).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CLIENT_QUIT |  | ) | `[protected]`

Notification about a client leaving the game.

uint32 ID of the client that just left.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CLIENT_UPDATE |  | ) | `[protected]`

Client update details on a specific client (e.g.

after rename or move): uint32 ID of the client. string Name of the client. uint8 ID of the company the client is playing as (255 for spectators).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_CLIENT_INFO |  | ) | `[protected]`

Client information of a specific client: uint32 ID of the client.

string Network address of the client. string Name of the client. uint8 Language of the client. uint32 Date the client joined the game. uint8 ID of the company the client is playing as (255 for spectators).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_WELCOME |  | ) | `[protected]`

Welcome a connected admin to the game: string Name of the Server (e.g.

as advertised to master server). string OpenTTD version string. bool Server is dedicated. string Name of the Map. uint32 Random seed of the Map. uint8 Landscape of the Map. uint32 Start date of the Map. uint16 Map width. uint16 Map height.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_PROTOCOL |  | ) | `[protected]`

Inform a just joined admin about the protocol specifics: uint8 Protocol version.

bool Further protocol data follows (repeats through all update packet types). uint16 Update packet type. uint16 Frequencies allowed for this update packet (bitwise).

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_SERVER_ERROR |  | ) | `[protected]`

An error was caused by this admin connection (connection gets closed).

uint8 NetworkErrorCode the error caused.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_ADMIN_CHAT |  | ) | `[protected]`

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

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

Reimplemented in ServerNetworkAdminSocketHandler.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_ADMIN_POLL |  | ) | `[protected]`

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

not existent id) gets silently dropped: uint8 AdminUpdateType the server should answer for, only if AdminUpdateFrequency ADMIN_FREQUENCY_POLL is advertised in the PROTOCOL packet. uint32 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.

Reimplemented in ServerNetworkAdminSocketHandler.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY |  | ) | `[protected]`

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

uint16 Update frequency (see AdminUpdateFrequency), setting ADMIN_FREQUENCY_POLL is always ignored.

Reimplemented in ServerNetworkAdminSocketHandler.

NetworkAdminSocketHandler::DECLARE_ADMIN_RECEIVE_COMMAND | ( | ADMIN_PACKET_ADMIN_JOIN |  | ) | `[protected]`

Join the admin network: string 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.

Reimplemented in ServerNetworkAdminSocketHandler.

NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket | ( | Packet * | p | ) | `[protected]`

Handle the given packet, i.e.

pass it to the right parser receive command.

Parameters:

  | p | the packet to handle.

Returns:
  NetworkRecvStatus of handling.

Definition at line 48 of file tcp_admin.cpp.

References ADMIN_COMMAND, admin_name, ADMIN_PACKET_ADMIN_CHAT, ADMIN_PACKET_ADMIN_JOIN, ADMIN_PACKET_ADMIN_POLL, ADMIN_PACKET_ADMIN_QUIT, ADMIN_PACKET_ADMIN_RCON, ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY, ADMIN_PACKET_SERVER_BANNED, ADMIN_PACKET_SERVER_CHAT, ADMIN_PACKET_SERVER_CLIENT_ERROR, ADMIN_PACKET_SERVER_CLIENT_INFO, ADMIN_PACKET_SERVER_CLIENT_JOIN, ADMIN_PACKET_SERVER_CLIENT_QUIT, ADMIN_PACKET_SERVER_CLIENT_UPDATE, ADMIN_PACKET_SERVER_CMD_LOGGING, ADMIN_PACKET_SERVER_CMD_NAMES, ADMIN_PACKET_SERVER_COMPANY_ECONOMY, ADMIN_PACKET_SERVER_COMPANY_INFO, ADMIN_PACKET_SERVER_COMPANY_NEW, ADMIN_PACKET_SERVER_COMPANY_REMOVE, ADMIN_PACKET_SERVER_COMPANY_STATS, ADMIN_PACKET_SERVER_COMPANY_UPDATE, ADMIN_PACKET_SERVER_CONSOLE, ADMIN_PACKET_SERVER_DATE, ADMIN_PACKET_SERVER_ERROR, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_NEWGAME, ADMIN_PACKET_SERVER_PROTOCOL, ADMIN_PACKET_SERVER_RCON, ADMIN_PACKET_SERVER_SHUTDOWN, ADMIN_PACKET_SERVER_WELCOME, admin_version, CloseConnection(), DEBUG, NetworkSocketHandler::HasClientQuit(), INVALID_ADMIN_PACKET, and NETWORK_RECV_STATUS_MALFORMED_PACKET.

Referenced by ReceivePackets().

NetworkRecvStatus NetworkAdminSocketHandler::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 105 of file tcp_admin.cpp.

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

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

- src/network/core/tcp_admin.h
- src/network/core/tcp_admin.cpp