OpenTTD
network_admin.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef NETWORK_ADMIN_H
13 #define NETWORK_ADMIN_H
14 
15 #include "network_internal.h"
16 #include "core/tcp_listen.h"
17 #include "core/tcp_admin.h"
18 
20 
25 
27 class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
28 protected:
37 
39  NetworkRecvStatus SendPong(uint32 d1);
40 public:
44 
47 
52 
55  NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci);
65 
66  NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
67  NetworkRecvStatus SendRcon(uint16 colour, const char *command);
68  NetworkRecvStatus SendConsole(const char *origin, const char *command);
69  NetworkRecvStatus SendGameScript(const char *json);
72  NetworkRecvStatus SendRconEnd(const char *command);
73 
74  static void Send();
75  static void AcceptConnection(SOCKET s, const NetworkAddress &address);
76  static bool AllowConnection();
77  static void WelcomeAll();
78 
83  static const char *GetName()
84  {
85  return "admin";
86  }
87 };
88 
94 #define FOR_ALL_ADMIN_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(ServerNetworkAdminSocketHandler, adminsocket_index, var, start)
95 
100 #define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
101 
106 #define FOR_ALL_ACTIVE_ADMIN_SOCKETS(var) \
107  FOR_ALL_ADMIN_SOCKETS(var) \
108  if (var->GetAdminStatus() == ADMIN_STATUS_ACTIVE)
109 
110 void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
112 void NetworkAdminClientQuit(ClientID client_id);
113 void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
114 void NetworkAdminCompanyInfo(const Company *company, bool new_company);
115 void NetworkAdminCompanyUpdate(const Company *company);
117 
118 void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
120 void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
121 void NetworkAdminConsole(const char *origin, const char *string);
122 void NetworkAdminGameScript(const char *json);
123 void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp);
124 
125 #endif /* NETWORK_ADMIN_H */
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Container for all information known about a client.
Definition: network_base.h:25
NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci)
Send an update for some client&#39;s information.
Internal entity of a packet.
Definition: packet.h:42
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition: tcp_admin.h:103
static void WelcomeAll()
Send a Welcome packet to all connected admins.
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
Pool< ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN > NetworkAdminSocketPool
Pool with all admin connections.
Definition: network_admin.h:21
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:102
NetworkRecvStatus SendWelcome()
Send a welcome message to the admin.
Template for TCP listeners.
Definition: tcp_listen.h:30
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
Distribute CommandPacket details over the admin network for logging purposes.
static void Send()
Send the packets for the server sockets.
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:29
void NetworkAdminConsole(const char *origin, const char *string)
Send console to the admin network (if they did opt in for the respective update). ...
static void AcceptConnection(SOCKET s, const NetworkAddress &address)
Handle the acception of a connection.
void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
Notify the admin network of a client update (if they did opt in for the respective update)...
uint32 realtime_connect
Time of connection.
Definition: network_admin.h:42
ClientID
&#39;Unique&#39; identifier to be given to clients
Definition: network_type.h:41
void NetworkAdminUpdate(AdminUpdateFrequency freq)
Send (push) updates to the admin network as they have registered for these updates.
AdminUpdateFrequency
Update frequencies an admin can register.
Definition: tcp_admin.h:91
NetworkRecvStatus SendConsole(const char *origin, const char *command)
Send console output of other clients.
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Tell the admin that a company got removed.
NetworkRecvStatus SendDate()
Tell the admin the date.
NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p) override
Notification to the server that this admin is quitting.
NetworkRecvStatus SendCompanyEconomy()
Send economic information of all companies.
NetworkRecvStatus SendRcon(uint16 colour, const char *command)
Send the reply of an rcon command.
NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
Send an initial set of data from some client&#39;s information.
AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]
Admin requested update intervals.
Definition: network_admin.h:41
NetworkRecvStatus SendClientQuit(ClientID client_id)
Tell the admin that a client quit.
~ServerNetworkAdminSocketHandler()
Clear everything related to this admin.
NetworkRecvStatus SendRconEnd(const char *command)
Send a notification indicating the rcon command has completed.
NetworkRecvStatus SendClientJoin(ClientID client_id)
Tell the admin that a client joined.
Basic functions to listen for TCP connections.
NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p) override
Join the admin network: string Password the server is expecting for this network. ...
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
NetworkRecvStatus Receive_ADMIN_PING(Packet *p) override
Ping the server, requiring the server to reply with a pong packet.
NetworkRecvStatus SendNewGame()
Tell the admin we started a new game.
NetworkRecvStatus SendCmdNames()
Send the names of the commands.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:24
NetworkRecvStatus SendCompanyUpdate(const Company *c)
Send an update about a company.
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string)
Pass the rcon reply to the admin.
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client=false)
Notify the admin network of a new client (if they did opt in for the respective update).
NetworkRecvStatus SendCompanyInfo(const Company *c)
Send the admin some information about a company.
NetworkRecvStatus Receive_ADMIN_RCON(Packet *p) override
Execute a command on the servers console: string Command to be executed.
static bool AllowConnection()
Whether a connection is allowed or not at this moment.
Base class for all PoolItems.
Definition: pool_type.hpp:146
uint8 AdminIndex
Indices into the admin tables.
Definition: network_type.h:51
Base class for all pools.
Definition: pool_type.hpp:83
NetworkRecvStatus SendError(NetworkErrorCode error)
Send an error to the admin.
void NetworkAdminCompanyInfo(const Company *company, bool new_company)
Notify the admin network of company details.
NetworkRecvStatus SendProtocol()
Send the protocol version to the admin.
NetworkAdminSocketPool _networkadminsocket_pool
The pool with sockets/clients.
NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error)
Tell the admin that a client made an error.
Variables and function used internally.
NetworkRecvStatus SendGameScript(const char *json)
Send GameScript JSON output.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:114
ServerNetworkAdminSocketHandler(SOCKET s)
Create a new socket for the server side of the admin network.
Class for handling the server side of the game connection.
Definition: network_admin.h:27
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_admin.h:87
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data=0, bool from_admin=false)
Send chat to the admin network (if they did opt in for the respective update).
void NetworkAdminGameScript(const char *json)
Send GameScript JSON to the admin network (if they did opt in for the respective update).
Main socket handler for admin related connections.
Definition: tcp_admin.h:112
void NetworkAdminClientQuit(ClientID client_id)
Notify the admin network that a client quit (if they have opt in for the respective update)...
NetworkRecvStatus SendCompanyStats()
Send statistics about the companies.
NetworkRecvStatus Receive_ADMIN_POLL(Packet *p) override
Poll the server for certain updates, an invalid poll (e.g.
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
Send a chat message.
Everything we need to know about a command to be able to execute it.
NetworkRecvStatus SendShutdown()
Tell the admin we&#39;re shutting down.
Basic functions to receive and send TCP packets to and from the admin network.
static const char * GetName()
Get the name used by the listener.
Definition: network_admin.h:83
NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp)
Send a command for logging purposes.
void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code)
Notify the admin network of a client error (if they have opt in for the respective update)...
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Notify the admin network of a company to be removed (including the reason why).
NetworkRecvStatus SendCompanyNew(CompanyID company_id)
Tell the admin that a new company was founded.
NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p) override
Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16 Upda...
NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p) override
Send chat as the server: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
DestType
Destination of our chat messages.
Definition: network_type.h:80
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:87
NetworkRecvStatus SendPong(uint32 d1)
Send ping-reply (pong) to admin.
NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p) override
Send a JSON string to the current active GameScript.
NetworkAddress address
Address of the admin.
Definition: network_admin.h:43