Update: Translations from eints
[openttd-github.git] / src / network / network_admin.h
blob4984ea68474e0687744beef8a513407f660fc504
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 */
8 /** @file network_admin.h Server part of the admin network protocol. */
10 #ifndef NETWORK_ADMIN_H
11 #define NETWORK_ADMIN_H
13 #include "network_internal.h"
14 #include "core/tcp_listen.h"
15 #include "core/tcp_admin.h"
17 extern AdminIndex _redirect_console_to_admin;
19 class ServerNetworkAdminSocketHandler;
20 /** Pool with all admin connections. */
21 typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN> NetworkAdminSocketPool;
22 extern NetworkAdminSocketPool _networkadminsocket_pool;
24 /** Class for handling the server side of the game connection. */
25 class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
26 private:
27 std::unique_ptr<NetworkAuthenticationServerHandler> authentication_handler; ///< The handler for the authentication.
28 protected:
29 NetworkRecvStatus Receive_ADMIN_JOIN(Packet &p) override;
30 NetworkRecvStatus Receive_ADMIN_QUIT(Packet &p) override;
31 NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet &p) override;
32 NetworkRecvStatus Receive_ADMIN_POLL(Packet &p) override;
33 NetworkRecvStatus Receive_ADMIN_CHAT(Packet &p) override;
34 NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet &p) override;
35 NetworkRecvStatus Receive_ADMIN_RCON(Packet &p) override;
36 NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet &p) override;
37 NetworkRecvStatus Receive_ADMIN_PING(Packet &p) override;
38 NetworkRecvStatus Receive_ADMIN_JOIN_SECURE(Packet &p) override;
39 NetworkRecvStatus Receive_ADMIN_AUTH_RESPONSE(Packet &p) override;
41 NetworkRecvStatus SendProtocol();
42 NetworkRecvStatus SendPong(uint32_t d1);
43 NetworkRecvStatus SendAuthRequest();
44 NetworkRecvStatus SendEnableEncryption();
45 public:
46 AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]; ///< Admin requested update intervals.
47 std::chrono::steady_clock::time_point connect_time; ///< Time of connection.
48 NetworkAddress address; ///< Address of the admin.
50 ServerNetworkAdminSocketHandler(SOCKET s);
51 ~ServerNetworkAdminSocketHandler();
53 NetworkRecvStatus SendError(NetworkErrorCode error);
54 NetworkRecvStatus SendWelcome();
55 NetworkRecvStatus SendNewGame();
56 NetworkRecvStatus SendShutdown();
58 NetworkRecvStatus SendDate();
59 NetworkRecvStatus SendClientJoin(ClientID client_id);
60 NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci);
61 NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci);
62 NetworkRecvStatus SendClientQuit(ClientID client_id);
63 NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error);
64 NetworkRecvStatus SendCompanyNew(CompanyID company_id);
65 NetworkRecvStatus SendCompanyInfo(const Company *c);
66 NetworkRecvStatus SendCompanyUpdate(const Company *c);
67 NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
68 NetworkRecvStatus SendCompanyEconomy();
69 NetworkRecvStatus SendCompanyStats();
71 NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data);
72 NetworkRecvStatus SendRcon(uint16_t colour, const std::string_view command);
73 NetworkRecvStatus SendConsole(const std::string_view origin, const std::string_view command);
74 NetworkRecvStatus SendGameScript(const std::string_view json);
75 NetworkRecvStatus SendCmdNames();
76 NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket &cp);
77 NetworkRecvStatus SendRconEnd(const std::string_view command);
79 static void Send();
80 static void AcceptConnection(SOCKET s, const NetworkAddress &address);
81 static bool AllowConnection();
82 static void WelcomeAll();
84 /**
85 * Get the name used by the listener.
86 * @return the name to show in debug logs and the like.
88 static const char *GetName()
90 return "admin";
93 struct ServerNetworkAdminSocketHandlerFilter {
94 bool operator() (size_t index) { return ServerNetworkAdminSocketHandler::Get(index)->GetAdminStatus() == ADMIN_STATUS_ACTIVE; }
97 /**
98 * Returns an iterable ensemble of all active admin sockets
99 * @param from index of the first socket to consider
100 * @return an iterable ensemble of all active admin sockets
102 static Pool::IterateWrapperFiltered<ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter> IterateActive(size_t from = 0)
104 return Pool::IterateWrapperFiltered<ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter>(from, ServerNetworkAdminSocketHandlerFilter{});
108 void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
109 void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
110 void NetworkAdminClientQuit(ClientID client_id);
111 void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
112 void NetworkAdminCompanyNew(const Company *company);
113 void NetworkAdminCompanyUpdate(const Company *company);
114 void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
116 void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data = 0, bool from_admin = false);
117 void NetworkAdminUpdate(AdminUpdateFrequency freq);
118 void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const std::string_view string);
119 void NetworkAdminConsole(const std::string_view origin, const std::string_view string);
120 void NetworkAdminGameScript(const std::string_view json);
121 void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket &cp);
123 #endif /* NETWORK_ADMIN_H */