OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NETWORK_CORE_TCP_ADMIN_H
11#define NETWORK_CORE_TCP_ADMIN_H
12
13#include "os_abstraction.h"
14#include "tcp.h"
15
66
67template <> struct IsEnumPacketType<PacketAdminType> {
68 static constexpr bool value = true;
69};
70
72enum class AdminStatus : uint8_t {
76};
77
92
104
113
116protected:
117 std::string admin_name{};
118 std::string admin_version{};
120
122
131 virtual NetworkRecvStatus ReceiveAdminJoin(Packet &p);
132
138 virtual NetworkRecvStatus ReceiveAdminQuit(Packet &p);
139
148
158 virtual NetworkRecvStatus ReceiveAdminPoll(Packet &p);
159
169 virtual NetworkRecvStatus ReceiveAdminChat(Packet &p);
170
181
189
196 virtual NetworkRecvStatus ReceiveAdminGameScript(Packet &p);
197
204 virtual NetworkRecvStatus ReceiveAdminPing(Packet &p);
205
218 virtual NetworkRecvStatus ReceiveAdminJoinSecure(Packet &p);
219
231
237 virtual NetworkRecvStatus ReceiveServerFull(Packet &p);
238
244 virtual NetworkRecvStatus ReceiveServerBanned(Packet &p);
245
252 virtual NetworkRecvStatus ReceiveServerError(Packet &p);
253
263 virtual NetworkRecvStatus ReceiveServerProtocol(Packet &p);
264
279 virtual NetworkRecvStatus ReceiveServerWelcome(Packet &p);
280
286 virtual NetworkRecvStatus ReceiveServerNewGame(Packet &p);
287
293 virtual NetworkRecvStatus ReceiveServerShutdown(Packet &p);
294
301 virtual NetworkRecvStatus ReceiveServerDate(Packet &p);
302
310
323
333
341
350
358
372
389
398
416
434
445 virtual NetworkRecvStatus ReceiveServerChat(Packet &p);
446
455
463 virtual NetworkRecvStatus ReceiveServerConsole(Packet &p);
464
483
503
514
523
530 virtual NetworkRecvStatus ReceiveServerPong(Packet &p);
531
539
541public:
542 NetworkRecvStatus CloseConnection(bool error = true) override;
543
549
551
557 {
558 return this->status;
559 }
560};
561
562#endif /* NETWORK_CORE_TCP_ADMIN_H */
Enum-as-bit-set wrapper.
virtual NetworkRecvStatus ReceiveServerCompanyUpdate(Packet &p)
Company information of a specific company: uint8_t ID of the company.
virtual NetworkRecvStatus ReceiveServerError(Packet &p)
An error was caused by this admin connection (connection gets closed).
virtual NetworkRecvStatus ReceiveServerCompanyEconomy(Packet &p)
Economy update of a specific company: uint8_t ID of the company.
virtual NetworkRecvStatus ReceiveServerConsole(Packet &p)
Send what would be printed on the server's console also into the admin network.
virtual NetworkRecvStatus ReceiveAdminPoll(Packet &p)
Poll the server for certain updates, an invalid poll (e.g.
virtual NetworkRecvStatus ReceiveAdminJoinSecure(Packet &p)
Join the admin network using a secure authentication method: string Name of the application being use...
virtual NetworkRecvStatus ReceiveServerPong(Packet &p)
Send a ping-reply (pong) to the admin that sent us the ping packet.
NetworkRecvStatus HandlePacket(Packet &p)
Handle the given packet, i.e.
Definition tcp_admin.cpp:34
virtual NetworkRecvStatus ReceiveAdminUpdateFrequency(Packet &p)
Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16_t Up...
virtual NetworkRecvStatus ReceiveServerCompanyRemove(Packet &p)
Notification about a removed company (e.g.
virtual NetworkRecvStatus ReceiveServerChat(Packet &p)
Send chat from the game into the admin network: uint8_t Action such as NetworkAction::ChatClient (see...
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Definition tcp_admin.cpp:23
virtual NetworkRecvStatus ReceiveServerCompanyInfo(Packet &p)
Company information on a specific company: uint8_t ID of the company.
virtual NetworkRecvStatus ReceiveServerEnableEncryption(Packet &p)
Indication to the client that authentication is complete and encryption has to be used from here on f...
virtual NetworkRecvStatus ReceiveServerProtocol(Packet &p)
Inform a just joined admin about the protocol specifics: uint8_t Protocol version.
virtual NetworkRecvStatus ReceiveServerClientJoin(Packet &p)
Notification of a new client: uint32_t ID of the new client.
NetworkAdminSocketHandler(SOCKET s)
Create the admin handler for the given socket.
Definition tcp_admin.h:548
virtual NetworkRecvStatus ReceiveAdminRemoteConsoleCommand(Packet &p)
Execute a command on the servers console: string Command to be executed.
virtual NetworkRecvStatus ReceiveServerCompanyNew(Packet &p)
Notification of a new company: uint8_t ID of the new company.
virtual NetworkRecvStatus ReceiveServerClientError(Packet &p)
Notification about a client error (and thus the clients disconnection).
virtual NetworkRecvStatus ReceiveServerCompanyStatistics(Packet &p)
Company statistics on stations and vehicles: uint8_t ID of the company.
virtual NetworkRecvStatus ReceiveServerCommandLogging(Packet &p)
Send incoming command packets to the admin network.
AdminStatus GetAdminStatus() const
Get the status of the admin.
Definition tcp_admin.h:556
virtual NetworkRecvStatus ReceiveServerClientInfo(Packet &p)
Client information of a specific client: uint32_t ID of the client.
virtual NetworkRecvStatus ReceiveServerAuthenticationRequest(Packet &p)
Server requests authentication challenge from the admin.
virtual NetworkRecvStatus ReceiveAdminQuit(Packet &p)
Notification to the server that this admin is quitting.
virtual NetworkRecvStatus ReceiveAdminAuthenticationResponse(Packet &p)
Admin responds to PacketAdminType::ServerAuthenticationRequest with the appropriate data given the ag...
virtual NetworkRecvStatus ReceiveServerClientUpdate(Packet &p)
Client update details on a specific client (e.g.
virtual NetworkRecvStatus ReceiveServerRemoteConsoleCommandEnd(Packet &p)
Notify the admin connection that the rcon command has finished.
NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type)
Helper for logging receiving invalid packets.
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
Definition tcp_admin.cpp:95
AdminStatus status
Status of this admin.
Definition tcp_admin.h:119
virtual NetworkRecvStatus ReceiveServerWelcome(Packet &p)
Welcome a connected admin to the game: string Name of the Server.
virtual NetworkRecvStatus ReceiveAdminGameScript(Packet &p)
Send a JSON string to the current active GameScript.
virtual NetworkRecvStatus ReceiveServerNewGame(Packet &p)
Notification about a newgame.
std::string admin_version
Version string of the admin.
Definition tcp_admin.h:118
virtual NetworkRecvStatus ReceiveServerBanned(Packet &p)
The source IP address is banned (connection gets closed).
virtual NetworkRecvStatus ReceiveServerClientQuit(Packet &p)
Notification about a client leaving the game.
virtual NetworkRecvStatus ReceiveServerFull(Packet &p)
The server is full (connection gets closed).
virtual NetworkRecvStatus ReceiveServerShutdown(Packet &p)
Notification about the server shutting down.
virtual NetworkRecvStatus ReceiveAdminJoin(Packet &p)
Join the admin network using an unsecured password exchange: string Unsecured password the server is ...
virtual NetworkRecvStatus ReceiveAdminPing(Packet &p)
Ping the server, requiring the server to reply with a pong packet.
virtual NetworkRecvStatus ReceiveAdminExternalChat(Packet &p)
Send chat from the external source: string Name of the source this message came from.
virtual NetworkRecvStatus ReceiveServerCommandNames(Packet &p)
Send DoCommand names to the bot upon request only.
virtual NetworkRecvStatus ReceiveAdminChat(Packet &p)
Send chat as the server: uint8_t Action such as NetworkAction::ChatClient (see NetworkAction).
std::string admin_name
Name of the admin.
Definition tcp_admin.h:117
virtual NetworkRecvStatus ReceiveServerDate(Packet &p)
Send the current date of the game: uint32_t Current game date.
virtual NetworkRecvStatus ReceiveServerRemoteConsoleCommand(Packet &p)
Result of an rcon command: uint16_t Colour as it would be used on the server or a client.
NetworkTCPSocketHandler(SOCKET s=INVALID_SOCKET)
Construct a socket handler for a TCP connection.
Definition tcp.h:64
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition core.h:19
Includes and/or implementations for the network stuff.
static constexpr bool value
This is an enumeration of a PacketType.
Definition tcp_admin.h:68
Trait to mark an enumeration as a PacketType.
Definition packet.h:32
Basic functions to receive and send TCP packets.
PacketAdminType
Enum with types of TCP packets specific to the admin network.
Definition tcp_admin.h:21
@ ServerCompanyNew
The server tells the admin that a new company has started.
Definition tcp_admin.h:48
@ ServerDate
The server tells the admin what the current game date is.
Definition tcp_admin.h:42
@ ServerCommandLoggingOld
Used to be the type ID of PacketAdminType::ServerCommandLogging in NETWORK_GAME_ADMIN_VERSION 1.
Definition tcp_admin.h:58
@ AdminRemoteConsoleCommand
The admin sends a remote console command.
Definition tcp_admin.h:27
@ ServerAuthenticationRequest
The server gives the admin the used authentication method and required parameters.
Definition tcp_admin.h:63
@ ServerClientInfo
The server gives the admin information about a client.
Definition tcp_admin.h:44
@ ServerShutdown
The server tells the admin its shutting down.
Definition tcp_admin.h:40
@ ServerCompanyRemove
The server tells the admin that a company was removed.
Definition tcp_admin.h:51
@ ServerCommandNames
The server sends out the names of the DoCommands to the admins.
Definition tcp_admin.h:57
@ ServerCompanyEconomy
The server gives the admin some economy related company information.
Definition tcp_admin.h:52
@ AdminPing
The admin sends a ping to the server, expecting a ping-reply (PONG) packet.
Definition tcp_admin.h:29
@ ServerClientQuit
The server tells the admin that a client quit.
Definition tcp_admin.h:46
@ ServerPong
The server replies to a ping request from the admin.
Definition tcp_admin.h:61
@ ServerClientJoin
The server tells the admin that a client has joined.
Definition tcp_admin.h:43
@ ServerFull
The server tells the admin it cannot accept the admin.
Definition tcp_admin.h:34
@ ServerClientError
The server tells the admin that a client caused an error.
Definition tcp_admin.h:47
@ ServerCompanyInfo
The server gives the admin information about a company.
Definition tcp_admin.h:49
@ ServerBanned
The server tells the admin it is banned.
Definition tcp_admin.h:35
@ ServerError
The server tells the admin an error has occurred.
Definition tcp_admin.h:36
@ AdminJoinSecure
The admin announces and starts a secure authentication handshake.
Definition tcp_admin.h:31
@ AdminJoin
The admin announces and authenticates itself to the server using an unsecured passwords.
Definition tcp_admin.h:22
@ ServerGameScript
The server gives the admin information from the GameScript in JSON.
Definition tcp_admin.h:59
@ AdminGameScript
The admin sends a JSON string for the GameScript.
Definition tcp_admin.h:28
@ ServerConsole
The server gives the admin the data that got printed to its console.
Definition tcp_admin.h:56
@ AdminExternalChat
The admin sends a chat message from external source.
Definition tcp_admin.h:30
@ AdminAuthenticationResponse
The admin responds to the authentication request.
Definition tcp_admin.h:32
@ ServerCommandLogging
The server gives the admin copies of incoming command packets.
Definition tcp_admin.h:62
@ ServerClientUpdate
The server gives the admin an information update on a client.
Definition tcp_admin.h:45
@ ServerCompanyStatistics
The server gives the admin some statistics about a company.
Definition tcp_admin.h:53
@ ServerRemoteConsoleCommandEnd
The server indicates that the remote console command has completed.
Definition tcp_admin.h:60
@ ServerRemoteConsoleCommand
The server's reply to a remote console command.
Definition tcp_admin.h:55
@ ServerWelcome
The server welcomes the admin to a game.
Definition tcp_admin.h:38
@ ServerCompanyUpdate
The server gives the admin an information update on a company.
Definition tcp_admin.h:50
@ ServerChat
The server received a chat message and relays it.
Definition tcp_admin.h:54
@ AdminChat
The admin sends a chat message to be distributed.
Definition tcp_admin.h:26
@ ServerProtocol
The server tells the admin its protocol version.
Definition tcp_admin.h:37
@ AdminQuit
The admin tells the server that it is quitting.
Definition tcp_admin.h:23
@ ServerEnableEncryption
The server tells that authentication has completed and requests to enable encryption with the keys of...
Definition tcp_admin.h:64
@ AdminPoll
The admin explicitly polls for a piece of information.
Definition tcp_admin.h:25
@ ServerNewGame
The server tells the admin its going to start a new game.
Definition tcp_admin.h:39
AdminUpdateType
Update types an admin can register a frequency for.
Definition tcp_admin.h:79
@ Gamescript
The admin would like to have gamescript messages.
Definition tcp_admin.h:89
@ CompanyInfo
Updates about the generic information of companies.
Definition tcp_admin.h:82
@ CompanyEconomy
Updates about the economy of companies.
Definition tcp_admin.h:83
@ Date
Updates about the date of the game.
Definition tcp_admin.h:80
@ Chat
The admin would like to have chat messages.
Definition tcp_admin.h:85
@ CmdLogging
The admin would like to have DoCommand information.
Definition tcp_admin.h:88
@ CmdNames
The admin would like a list of all DoCommand names.
Definition tcp_admin.h:87
@ End
Must ALWAYS be on the end of this list!! (period).
Definition tcp_admin.h:90
@ CompanyStats
Updates about the statistics of companies.
Definition tcp_admin.h:84
@ Console
The admin would like to have console messages.
Definition tcp_admin.h:86
@ ClientInfo
Updates about the information of clients.
Definition tcp_admin.h:81
EnumBitSet< AdminUpdateFrequency, uint8_t > AdminUpdateFrequencies
Bitset of chosen update frequencies.
Definition tcp_admin.h:103
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition tcp_admin.h:106
@ Autoclean
The company is removed due to autoclean.
Definition tcp_admin.h:108
@ Bankrupt
The company went belly-up.
Definition tcp_admin.h:109
@ Manual
The company is manually removed.
Definition tcp_admin.h:107
AdminUpdateFrequency
Update frequencies an admin can register.
Definition tcp_admin.h:94
@ Automatic
The admin gets information about this when it changes.
Definition tcp_admin.h:101
@ Annually
The admin gets information about this on a yearly basis.
Definition tcp_admin.h:100
@ Weekly
The admin gets information about this on a weekly basis.
Definition tcp_admin.h:97
@ Poll
The admin can poll this.
Definition tcp_admin.h:95
@ Monthly
The admin gets information about this on a monthly basis.
Definition tcp_admin.h:98
@ Quarterly
The admin gets information about this on a quarterly basis.
Definition tcp_admin.h:99
@ Daily
The admin gets information about this on a daily basis.
Definition tcp_admin.h:96
AdminStatus
Status of an admin.
Definition tcp_admin.h:72
@ Inactive
The admin is not connected nor active.
Definition tcp_admin.h:73
@ Active
The admin is active.
Definition tcp_admin.h:75
@ Authenticate
The admin is connected and working on authentication.
Definition tcp_admin.h:74