OpenTTD

network_admin.h
Go to the documentation of this file.
1 /* $Id: network_admin.h 25588 2013-07-11 20:31:39Z planetmaker $ */
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 #ifdef ENABLE_NETWORK
16
17 #include "network_internal.h"
18 #include "core/tcp_listen.h"
19 #include "core/tcp_admin.h"
20
21 extern AdminIndex _redirect_console_to_admin;
22
23 class ServerNetworkAdminSocketHandler;
25 typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN> NetworkAdminSocketPool;
26 extern NetworkAdminSocketPool _networkadminsocket_pool;
27
29 class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
30 protected:
31 virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
32 virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
33 virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
34 virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
35 virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
36 virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
37 virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
38 virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
39
40 NetworkRecvStatus SendProtocol();
41 NetworkRecvStatus SendPong(uint32 d1);
42 public:
43 AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END];
44 uint32 realtime_connect;
45 NetworkAddress address;
46
47 ServerNetworkAdminSocketHandler(SOCKET s);
48 ~ServerNetworkAdminSocketHandler();
49
50 NetworkRecvStatus SendError(NetworkErrorCode error);
51 NetworkRecvStatus SendWelcome();
52 NetworkRecvStatus SendNewGame();
53 NetworkRecvStatus SendShutdown();
54
55 NetworkRecvStatus SendDate();
56 NetworkRecvStatus SendClientJoin(ClientID client_id);
57 NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci);
58 NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci);
59 NetworkRecvStatus SendClientQuit(ClientID client_id);
60 NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error);
61 NetworkRecvStatus SendCompanyNew(CompanyID company_id);
62 NetworkRecvStatus SendCompanyInfo(const Company *c);
63 NetworkRecvStatus SendCompanyUpdate(const Company *c);
64 NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
65 NetworkRecvStatus SendCompanyEconomy();
66 NetworkRecvStatus SendCompanyStats();
67
68 NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
69 NetworkRecvStatus SendRcon(uint16 colour, const char *command);
70 NetworkRecvStatus SendConsole(const char *origin, const char *command);
71 NetworkRecvStatus SendGameScript(const char *json);
72 NetworkRecvStatus SendCmdNames();
73 NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp);
74 NetworkRecvStatus SendRconEnd(const char *command);
75
76 static void Send();
77 static void AcceptConnection(SOCKET s, const NetworkAddress &address);
78 static bool AllowConnection();
79 static void WelcomeAll();
80
85 static const char *GetName()
86 {
87 return "admin";
88 }
89 };
90
96 #define FOR_ALL_ADMIN_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(ServerNetworkAdminSocketHandler, adminsocket_index, var, start)
97
102 #define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
103
108 #define FOR_ALL_ACTIVE_ADMIN_SOCKETS(var) \
109 FOR_ALL_ADMIN_SOCKETS(var) \
110 if (var->GetAdminStatus() == ADMIN_STATUS_ACTIVE)
111
112 void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
113 void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
114 void NetworkAdminClientQuit(ClientID client_id);
115 void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
116 void NetworkAdminCompanyInfo(const Company *company, bool new_company);
117 void NetworkAdminCompanyUpdate(const Company *company);
118 void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
119
120 void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
121 void NetworkAdminUpdate(AdminUpdateFrequency freq);
122 void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
123 void NetworkAdminConsole(const char *origin, const char *string);
124 void NetworkAdminGameScript(const char *json);
125 void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp);
126
127 #endif /* ENABLE_NETWORK */
128 #endif /* NETWORK_ADMIN_H */
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:27
ServerNetworkAdminSocketHandler::SendClientUpdate
NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci)
Send an update for some client&#39;s information.
Definition: network_admin.cpp:260
Packet
Internal entity of a packet.
Definition: packet.h:44
AdminCompanyRemoveReason
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition: tcp_admin.h:105
ServerNetworkAdminSocketHandler::WelcomeAll
static void WelcomeAll()
Send a Welcome packet to all connected admins.
Definition: network_admin.cpp:1010
_redirect_console_to_admin
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
Definition: network_admin.cpp:34
NetworkAdminCompanyUpdate
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
Definition: network_admin.cpp:909
NetworkAdminSocketPool
Pool< ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN > NetworkAdminSocketPool
Pool with all admin connections.
Definition: network_admin.h:23
NetworkErrorCode
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:104
ServerNetworkAdminSocketHandler::SendWelcome
NetworkRecvStatus SendWelcome()
Send a welcome message to the admin.
Definition: network_admin.cpp:170
TCPListenHandler
Template for TCP listeners.
Definition: tcp_listen.h:32
NetworkAdminCmdLogging
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
Distribute CommandPacket details over the admin network for logging purposes.
Definition: network_admin.cpp:995
ServerNetworkAdminSocketHandler::Send
static void Send()
Send the packets for the server sockets.
Definition: network_admin.cpp:99
NetworkAddress
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:31
NetworkAdminConsole
void NetworkAdminConsole(const char *origin, const char *string)
Send console to the admin network (if they did opt in for the respective update). ...
Definition: network_admin.cpp:966
ServerNetworkAdminSocketHandler::AcceptConnection
static void AcceptConnection(SOCKET s, const NetworkAddress &address)
Handle the acception of a connection.
Definition: network_admin.cpp:119
NetworkAdminClientUpdate
void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
Notify the admin network of a client update (if they did opt in for the respective update)...
Definition: network_admin.cpp:843
ServerNetworkAdminSocketHandler::realtime_connect
uint32 realtime_connect
Time of connection.
Definition: network_admin.h:44
NetworkAdminUpdate
void NetworkAdminUpdate(AdminUpdateFrequency freq)
Send (push) updates to the admin network as they have registered for these updates.
Definition: network_admin.cpp:1022
ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p)
Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16 Upda...
Definition: network_admin.cpp:704
AdminUpdateFrequency
AdminUpdateFrequency
Update frequencies an admin can register.
Definition: tcp_admin.h:93
ServerNetworkAdminSocketHandler::SendConsole
NetworkRecvStatus SendConsole(const char *origin, const char *command)
Send console output of other clients.
Definition: network_admin.cpp:566
ServerNetworkAdminSocketHandler::SendCompanyRemove
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Tell the admin that a company got removed.
Definition: network_admin.cpp:391
ServerNetworkAdminSocketHandler::SendDate
NetworkRecvStatus SendDate()
Tell the admin the date.
Definition: network_admin.cpp:207
ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p)
Join the admin network: string Password the server is expecting for this network. ...
Definition: network_admin.cpp:670
ServerNetworkAdminSocketHandler::SendCompanyEconomy
NetworkRecvStatus SendCompanyEconomy()
Send economic information of all companies.
Definition: network_admin.cpp:404
ServerNetworkAdminSocketHandler::SendRcon
NetworkRecvStatus SendRcon(uint16 colour, const char *command)
Send the reply of an rcon command.
Definition: network_admin.cpp:509
ServerNetworkAdminSocketHandler::SendClientInfo
NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
Send an initial set of data from some client&#39;s information.
Definition: network_admin.cpp:236
ServerNetworkAdminSocketHandler::update_frequency
AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]
Admin requested update intervals.
Definition: network_admin.h:43
ServerNetworkAdminSocketHandler::SendClientQuit
NetworkRecvStatus SendClientQuit(ClientID client_id)
Tell the admin that a client quit.
Definition: network_admin.cpp:277
ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p)
Send chat as the server: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
Definition: network_admin.cpp:790
ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p)
Send a JSON string to the current active GameScript.
Definition: network_admin.cpp:536
ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler
~ServerNetworkAdminSocketHandler()
Clear everything related to this admin.
Definition: network_admin.cpp:77
ServerNetworkAdminSocketHandler::SendRconEnd
NetworkRecvStatus SendRconEnd(const char *command)
Send a notification indicating the rcon command has completed.
Definition: network_admin.cpp:494
ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p)
Poll the server for certain updates, an invalid poll (e.g.
Definition: network_admin.cpp:722
ServerNetworkAdminSocketHandler::SendClientJoin
NetworkRecvStatus SendClientJoin(ClientID client_id)
Tell the admin that a client joined.
Definition: network_admin.cpp:221
tcp_listen.h
Basic functions to listen for TCP connections.
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
ServerNetworkAdminSocketHandler::SendNewGame
NetworkRecvStatus SendNewGame()
Tell the admin we started a new game.
Definition: network_admin.cpp:191
ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p)
Execute a command on the servers console: string Command to be executed.
Definition: network_admin.cpp:520
ServerNetworkAdminSocketHandler::SendCmdNames
NetworkRecvStatus SendCmdNames()
Send the names of the commands.
Definition: network_admin.cpp:614
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:26
ServerNetworkAdminSocketHandler::SendCompanyUpdate
NetworkRecvStatus SendCompanyUpdate(const Company *c)
Send an update about a company.
Definition: network_admin.cpp:357
NetworkServerSendAdminRcon
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string)
Pass the rcon reply to the admin.
Definition: network_admin.cpp:956
NetworkAdminClientInfo
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).
Definition: network_admin.cpp:826
ServerNetworkAdminSocketHandler::SendCompanyInfo
NetworkRecvStatus SendCompanyInfo(const Company *c)
Send the admin some information about a company.
Definition: network_admin.cpp:321
ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p)
Notification to the server that this admin is quitting.
Definition: network_admin.cpp:698
ServerNetworkAdminSocketHandler::AllowConnection
static bool AllowConnection()
Whether a connection is allowed or not at this moment.
Definition: network_admin.cpp:88
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:146
AdminIndex
uint8 AdminIndex
Indices into the admin tables.
Definition: network_type.h:53
Pool
Base class for all pools.
Definition: pool_type.hpp:83
ServerNetworkAdminSocketHandler::SendError
NetworkRecvStatus SendError(NetworkErrorCode error)
Send an error to the admin.
Definition: network_admin.cpp:133
NetworkAdminCompanyInfo
void NetworkAdminCompanyInfo(const Company *company, bool new_company)
Notify the admin network of company details.
Definition: network_admin.cpp:887
Company
Definition: company_base.h:110
ServerNetworkAdminSocketHandler::SendProtocol
NetworkRecvStatus SendProtocol()
Send the protocol version to the admin.
Definition: network_admin.cpp:150
_networkadminsocket_pool
NetworkAdminSocketPool _networkadminsocket_pool
The pool with sockets/clients.
ServerNetworkAdminSocketHandler::SendClientError
NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error)
Tell the admin that a client made an error.
Definition: network_admin.cpp:292
network_internal.h
Variables and function used internally.
ServerNetworkAdminSocketHandler::SendGameScript
NetworkRecvStatus SendGameScript(const char *json)
Send GameScript JSON output.
Definition: network_admin.cpp:587
ClientID
ClientID
&#39;Unique&#39; identifier to be given to clients
Definition: network_type.h:43
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:110
ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler
ServerNetworkAdminSocketHandler(SOCKET s)
Create a new socket for the server side of the admin network.
Definition: network_admin.cpp:67
ServerNetworkAdminSocketHandler
Class for handling the server side of the game connection.
Definition: network_admin.h:29
ADMIN_UPDATE_END
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_admin.h:89
NetworkAdminChat
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).
Definition: network_admin.cpp:938
NetworkAdminGameScript
void NetworkAdminGameScript(const char *json)
Send GameScript JSON to the admin network (if they did opt in for the respective update).
Definition: network_admin.cpp:980
NetworkAdminSocketHandler
Main socket handler for admin related connections.
Definition: tcp_admin.h:114
NetworkAdminClientQuit
void NetworkAdminClientQuit(ClientID client_id)
Notify the admin network that a client quit (if they have opt in for the respective update)...
Definition: network_admin.cpp:857
ServerNetworkAdminSocketHandler::SendCompanyStats
NetworkRecvStatus SendCompanyStats()
Send statistics about the companies.
Definition: network_admin.cpp:439
ServerNetworkAdminSocketHandler::SendChat
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
Send a chat message.
Definition: network_admin.cpp:476
CommandPacket
Everything we need to know about a command to be able to execute it.
Definition: network_internal.h:153
ServerNetworkAdminSocketHandler::SendShutdown
NetworkRecvStatus SendShutdown()
Tell the admin we&#39;re shutting down.
Definition: network_admin.cpp:199
tcp_admin.h
Basic functions to receive and send TCP packets to and from the admin network.
ServerNetworkAdminSocketHandler::GetName
static const char * GetName()
Get the name used by the listener.
Definition: network_admin.h:85
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
ServerNetworkAdminSocketHandler::SendCmdLogging
NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp)
Send a command for logging purposes.
Definition: network_admin.cpp:648
ServerNetworkAdminSocketHandler::Receive_ADMIN_PING
virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p)
Ping the server, requiring the server to reply with a pong packet.
Definition: network_admin.cpp:550
NetworkAdminClientError
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)...
Definition: network_admin.cpp:872
NetworkAdminCompanyRemove
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Notify the admin network of a company to be removed (including the reason why).
Definition: network_admin.cpp:926
ServerNetworkAdminSocketHandler::SendCompanyNew
NetworkRecvStatus SendCompanyNew(CompanyID company_id)
Tell the admin that a new company was founded.
Definition: network_admin.cpp:307
DestType
DestType
Destination of our chat messages.
Definition: network_type.h:82
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:89
ServerNetworkAdminSocketHandler::SendPong
NetworkRecvStatus SendPong(uint32 d1)
Send ping-reply (pong) to admin.
Definition: network_admin.cpp:603
ServerNetworkAdminSocketHandler::address
NetworkAddress address
Address of the admin.
Definition: network_admin.h:45