OpenTTD: src/network/network_admin.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 */