OpenTTD Source 20241224-master-gf74b0cf984
tcp_admin.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
12#ifndef NETWORK_CORE_TCP_ADMIN_H
13#define NETWORK_CORE_TCP_ADMIN_H
14
15#include "os_abstraction.h"
16#include "tcp.h"
17#include "../network_type.h"
18#include "../../core/pool_type.hpp"
19
71
79
94
106
107
115
118protected:
119 std::string admin_name;
120 std::string admin_version;
122
124
134
141
150
161
172
183
191
199
207
221
233
240
247
255
266
282
289
296
304
312
325
335
343
352
360
374
391
400
418
436
448
457
466
485
505
516
524
532
540
542public:
543 NetworkRecvStatus CloseConnection(bool error = true) override;
544
546
548
554 {
555 return this->status;
556 }
557};
558
559#endif /* NETWORK_CORE_TCP_ADMIN_H */
Main socket handler for admin related connections.
Definition tcp_admin.h:117
virtual NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet &p)
Send chat from the external source: string Name of the source this message came from.
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet &p)
Execute a command on the servers console: string Command to be executed.
virtual NetworkRecvStatus Receive_SERVER_AUTH_REQUEST(Packet &p)
Server requests authentication challenge from the admin.
virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet &p)
Notification about a client error (and thus the clients disconnection).
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p)
Welcome a connected admin to the game: string Name of the Server.
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_COMPANY_NEW(Packet &p)
Notification of a new company: uint8_t ID of the new company.
virtual NetworkRecvStatus Receive_SERVER_DATE(Packet &p)
Send the current date of the game: uint32_t Current game date.
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet &p)
Company information of a specific company: uint8_t ID of the company.
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.
NetworkRecvStatus HandlePacket(Packet &p)
Handle the given packet, i.e.
Definition tcp_admin.cpp:46
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet &p)
Send a JSON string to the current active GameScript.
virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet &p)
Send incoming command packets to the admin network.
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p)
Notification about the server shutting down.
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet &p)
An error was caused by this admin connection (connection gets closed).
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Definition tcp_admin.cpp:35
virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet &p)
Notification about a removed company (e.g.
virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet &p)
Client update details on a specific client (e.g.
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet &p)
The server is full (connection gets closed).
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet &p)
Notification to the server that this admin is quitting.
virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet &p)
Notification of a new client: uint32_t ID of the new client.
virtual NetworkRecvStatus Receive_ADMIN_AUTH_RESPONSE(Packet &p)
Admin responds to ADMIN_PACKET_SERVER_AUTH_REQUEST with the appropriate data given the agreed upon Ne...
virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet &p)
Notification about a client leaving the game.
AdminStatus GetAdminStatus() const
Get the status of the admin.
Definition tcp_admin.h:553
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet &p)
Poll the server for certain updates, an invalid poll (e.g.
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet &p)
Join the admin network using an unsecured password exchange: string Unsecured password the server is ...
virtual NetworkRecvStatus Receive_ADMIN_PING(Packet &p)
Ping the server, requiring the server to reply with a pong packet.
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet &p)
Send chat as the server: uint8_t Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
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_COMPANY_INFO(Packet &p)
Company information on a specific company: uint8_t ID of the company.
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_ENABLE_ENCRYPTION(Packet &p)
Indication to the client that authentication is complete and encryption has to be used from here on f...
virtual NetworkRecvStatus Receive_ADMIN_JOIN_SECURE(Packet &p)
Join the admin network using a secure authentication method: string Name of the application being use...
NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type)
Helper for logging receiving invalid packets.
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet &p)
Send DoCommand names to the bot upon request only.
AdminStatus status
Status of this admin.
Definition tcp_admin.h:121
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p)
Notification about a newgame.
std::string admin_version
Version string of the admin.
Definition tcp_admin.h:120
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet &p)
Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16_t Up...
virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet &p)
Inform a just joined admin about the protocol specifics: uint8_t Protocol version.
virtual NetworkRecvStatus Receive_SERVER_RCON_END(Packet &p)
Notify the admin connection that the rcon command has finished.
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 (se...
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet &p)
Client information of a specific client: uint32_t ID of the client.
std::string admin_name
Name of the admin.
Definition tcp_admin.h:119
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet &p)
The source IP address is banned (connection gets closed).
Base socket handler for all TCP sockets.
Definition tcp.h:31
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition core.h:23
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:35
Network stuff has many things that needs to be included and/or implemented by default.
Internal entity of a packet.
Definition packet.h:42
Basic functions to receive and send TCP packets.
PacketAdminType
Enum with types of TCP packets specific to the admin network.
Definition tcp_admin.h:24
@ ADMIN_PACKET_ADMIN_PING
The admin sends a ping to the server, expecting a ping-reply (PONG) packet.
Definition tcp_admin.h:32
@ ADMIN_PACKET_SERVER_CONSOLE
The server gives the admin the data that got printed to its console.
Definition tcp_admin.h:59
@ ADMIN_PACKET_SERVER_ENABLE_ENCRYPTION
The server tells that authentication has completed and requests to enable encryption with the keys of...
Definition tcp_admin.h:67
@ ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY
The admin tells the server the update frequency of a particular piece of information.
Definition tcp_admin.h:27
@ ADMIN_PACKET_SERVER_CLIENT_UPDATE
The server gives the admin an information update on a client.
Definition tcp_admin.h:48
@ ADMIN_PACKET_SERVER_COMPANY_STATS
The server gives the admin some statistics about a company.
Definition tcp_admin.h:56
@ ADMIN_PACKET_SERVER_COMPANY_ECONOMY
The server gives the admin some economy related company information.
Definition tcp_admin.h:55
@ ADMIN_PACKET_SERVER_GAMESCRIPT
The server gives the admin information from the GameScript in JSON.
Definition tcp_admin.h:62
@ ADMIN_PACKET_ADMIN_JOIN
The admin announces and authenticates itself to the server using an unsecured passwords.
Definition tcp_admin.h:25
@ ADMIN_PACKET_SERVER_CMD_LOGGING_OLD
Used to be the type ID of ADMIN_PACKET_SERVER_CMD_LOGGING in NETWORK_GAME_ADMIN_VERSION 1.
Definition tcp_admin.h:61
@ ADMIN_PACKET_SERVER_CLIENT_INFO
The server gives the admin information about a client.
Definition tcp_admin.h:47
@ ADMIN_PACKET_SERVER_CLIENT_ERROR
The server tells the admin that a client caused an error.
Definition tcp_admin.h:50
@ ADMIN_PACKET_ADMIN_GAMESCRIPT
The admin sends a JSON string for the GameScript.
Definition tcp_admin.h:31
@ ADMIN_PACKET_SERVER_AUTH_REQUEST
The server gives the admin the used authentication method and required parameters.
Definition tcp_admin.h:66
@ ADMIN_PACKET_SERVER_CHAT
The server received a chat message and relays it.
Definition tcp_admin.h:57
@ ADMIN_PACKET_SERVER_SHUTDOWN
The server tells the admin its shutting down.
Definition tcp_admin.h:43
@ ADMIN_PACKET_SERVER_RCON_END
The server indicates that the remote console command has completed.
Definition tcp_admin.h:63
@ ADMIN_PACKET_SERVER_WELCOME
The server welcomes the admin to a game.
Definition tcp_admin.h:41
@ ADMIN_PACKET_SERVER_COMPANY_REMOVE
The server tells the admin that a company was removed.
Definition tcp_admin.h:54
@ ADMIN_PACKET_SERVER_ERROR
The server tells the admin an error has occurred.
Definition tcp_admin.h:39
@ ADMIN_PACKET_ADMIN_QUIT
The admin tells the server that it is quitting.
Definition tcp_admin.h:26
@ ADMIN_PACKET_ADMIN_POLL
The admin explicitly polls for a piece of information.
Definition tcp_admin.h:28
@ ADMIN_PACKET_SERVER_NEWGAME
The server tells the admin its going to start a new game.
Definition tcp_admin.h:42
@ ADMIN_PACKET_SERVER_BANNED
The server tells the admin it is banned.
Definition tcp_admin.h:38
@ ADMIN_PACKET_SERVER_COMPANY_UPDATE
The server gives the admin an information update on a company.
Definition tcp_admin.h:53
@ ADMIN_PACKET_SERVER_PONG
The server replies to a ping request from the admin.
Definition tcp_admin.h:64
@ ADMIN_PACKET_SERVER_CLIENT_JOIN
The server tells the admin that a client has joined.
Definition tcp_admin.h:46
@ ADMIN_PACKET_ADMIN_CHAT
The admin sends a chat message to be distributed.
Definition tcp_admin.h:29
@ ADMIN_PACKET_SERVER_CMD_LOGGING
The server gives the admin copies of incoming command packets.
Definition tcp_admin.h:65
@ ADMIN_PACKET_SERVER_PROTOCOL
The server tells the admin its protocol version.
Definition tcp_admin.h:40
@ ADMIN_PACKET_ADMIN_JOIN_SECURE
The admin announces and starts a secure authentication handshake.
Definition tcp_admin.h:34
@ ADMIN_PACKET_SERVER_CLIENT_QUIT
The server tells the admin that a client quit.
Definition tcp_admin.h:49
@ INVALID_ADMIN_PACKET
An invalid marker for admin packets.
Definition tcp_admin.h:69
@ ADMIN_PACKET_SERVER_COMPANY_INFO
The server gives the admin information about a company.
Definition tcp_admin.h:52
@ ADMIN_PACKET_SERVER_CMD_NAMES
The server sends out the names of the DoCommands to the admins.
Definition tcp_admin.h:60
@ ADMIN_PACKET_SERVER_FULL
The server tells the admin it cannot accept the admin.
Definition tcp_admin.h:37
@ ADMIN_PACKET_ADMIN_RCON
The admin sends a remote console command.
Definition tcp_admin.h:30
@ ADMIN_PACKET_ADMIN_AUTH_RESPONSE
The admin responds to the authentication request.
Definition tcp_admin.h:35
@ ADMIN_PACKET_SERVER_DATE
The server tells the admin what the current game date is.
Definition tcp_admin.h:45
@ ADMIN_PACKET_SERVER_COMPANY_NEW
The server tells the admin that a new company has started.
Definition tcp_admin.h:51
@ ADMIN_PACKET_ADMIN_EXTERNAL_CHAT
The admin sends a chat message from external source.
Definition tcp_admin.h:33
@ ADMIN_PACKET_SERVER_RCON
The server's reply to a remove console command.
Definition tcp_admin.h:58
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition tcp_admin.h:108
@ ADMIN_CRR_BANKRUPT
The company went belly-up.
Definition tcp_admin.h:111
@ ADMIN_CRR_MANUAL
The company is manually removed.
Definition tcp_admin.h:109
@ ADMIN_CRR_AUTOCLEAN
The company is removed due to autoclean.
Definition tcp_admin.h:110
@ ADMIN_CRR_END
Sentinel for end.
Definition tcp_admin.h:113
AdminUpdateFrequency
Update frequencies an admin can register.
Definition tcp_admin.h:96
@ ADMIN_FREQUENCY_MONTHLY
The admin gets information about this on a monthly basis.
Definition tcp_admin.h:100
@ ADMIN_FREQUENCY_QUARTERLY
The admin gets information about this on a quarterly basis.
Definition tcp_admin.h:101
@ ADMIN_FREQUENCY_AUTOMATIC
The admin gets information about this when it changes.
Definition tcp_admin.h:103
@ ADMIN_FREQUENCY_ANUALLY
The admin gets information about this on a yearly basis.
Definition tcp_admin.h:102
@ ADMIN_FREQUENCY_WEEKLY
The admin gets information about this on a weekly basis.
Definition tcp_admin.h:99
@ ADMIN_FREQUENCY_DAILY
The admin gets information about this on a daily basis.
Definition tcp_admin.h:98
@ ADMIN_FREQUENCY_POLL
The admin can poll this.
Definition tcp_admin.h:97
AdminUpdateType
Update types an admin can register a frequency for.
Definition tcp_admin.h:81
@ ADMIN_UPDATE_DATE
Updates about the date of the game.
Definition tcp_admin.h:82
@ ADMIN_UPDATE_GAMESCRIPT
The admin would like to have gamescript messages.
Definition tcp_admin.h:91
@ ADMIN_UPDATE_COMPANY_INFO
Updates about the generic information of companies.
Definition tcp_admin.h:84
@ ADMIN_UPDATE_CONSOLE
The admin would like to have console messages.
Definition tcp_admin.h:88
@ ADMIN_UPDATE_CHAT
The admin would like to have chat messages.
Definition tcp_admin.h:87
@ ADMIN_UPDATE_COMPANY_STATS
Updates about the statistics of companies.
Definition tcp_admin.h:86
@ ADMIN_UPDATE_COMPANY_ECONOMY
Updates about the economy of companies.
Definition tcp_admin.h:85
@ ADMIN_UPDATE_END
Must ALWAYS be on the end of this list!! (period)
Definition tcp_admin.h:92
@ ADMIN_UPDATE_CLIENT_INFO
Updates about the information of clients.
Definition tcp_admin.h:83
@ ADMIN_UPDATE_CMD_NAMES
The admin would like a list of all DoCommand names.
Definition tcp_admin.h:89
@ ADMIN_UPDATE_CMD_LOGGING
The admin would like to have DoCommand information.
Definition tcp_admin.h:90
AdminStatus
Status of an admin.
Definition tcp_admin.h:73
@ ADMIN_STATUS_END
Must ALWAYS be on the end of this list!! (period)
Definition tcp_admin.h:77
@ ADMIN_STATUS_INACTIVE
The admin is not connected nor active.
Definition tcp_admin.h:74
@ ADMIN_STATUS_ACTIVE
The admin is active.
Definition tcp_admin.h:76
@ ADMIN_STATUS_AUTHENTICATE
The admin is connected and working on authentication.
Definition tcp_admin.h:75