OpenTTD: src/network/core/tcp_admin.h Source File

OpenTTD

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

- File List
- Globals

tcp_admin.h
Go to the documentation of this file.
1 /* $Id: tcp_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
14 #ifndef NETWORK_CORE_TCP_ADMIN_H
15 #define NETWORK_CORE_TCP_ADMIN_H
16
17 #include "os_abstraction.h"
18 #include "tcp.h"
19 #include "../network_type.h"
20 #include "../../core/pool_type.hpp"
21
22 #ifdef ENABLE_NETWORK
23
28 enum PacketAdminType {
29 ADMIN_PACKET_ADMIN_JOIN,
30 ADMIN_PACKET_ADMIN_QUIT,
31 ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY,
32 ADMIN_PACKET_ADMIN_POLL,
33 ADMIN_PACKET_ADMIN_CHAT,
34 ADMIN_PACKET_ADMIN_RCON,
35 ADMIN_PACKET_ADMIN_GAMESCRIPT,
36 ADMIN_PACKET_ADMIN_PING,
37
38 ADMIN_PACKET_SERVER_FULL = 100,
39 ADMIN_PACKET_SERVER_BANNED,
40 ADMIN_PACKET_SERVER_ERROR,
41 ADMIN_PACKET_SERVER_PROTOCOL,
42 ADMIN_PACKET_SERVER_WELCOME,
43 ADMIN_PACKET_SERVER_NEWGAME,
44 ADMIN_PACKET_SERVER_SHUTDOWN,
45
46 ADMIN_PACKET_SERVER_DATE,
47 ADMIN_PACKET_SERVER_CLIENT_JOIN,
48 ADMIN_PACKET_SERVER_CLIENT_INFO,
49 ADMIN_PACKET_SERVER_CLIENT_UPDATE,
50 ADMIN_PACKET_SERVER_CLIENT_QUIT,
51 ADMIN_PACKET_SERVER_CLIENT_ERROR,
52 ADMIN_PACKET_SERVER_COMPANY_NEW,
53 ADMIN_PACKET_SERVER_COMPANY_INFO,
54 ADMIN_PACKET_SERVER_COMPANY_UPDATE,
55 ADMIN_PACKET_SERVER_COMPANY_REMOVE,
56 ADMIN_PACKET_SERVER_COMPANY_ECONOMY,
57 ADMIN_PACKET_SERVER_COMPANY_STATS,
58 ADMIN_PACKET_SERVER_CHAT,
59 ADMIN_PACKET_SERVER_RCON,
60 ADMIN_PACKET_SERVER_CONSOLE,
61 ADMIN_PACKET_SERVER_CMD_NAMES,
62 ADMIN_PACKET_SERVER_CMD_LOGGING,
63 ADMIN_PACKET_SERVER_GAMESCRIPT,
64 ADMIN_PACKET_SERVER_RCON_END,
65 ADMIN_PACKET_SERVER_PONG,
66
67 INVALID_ADMIN_PACKET = 0xFF,
68 };
69
71 enum AdminStatus {
72 ADMIN_STATUS_INACTIVE,
73 ADMIN_STATUS_ACTIVE,
74 ADMIN_STATUS_END,
75 };
76
78 enum AdminUpdateType {
79 ADMIN_UPDATE_DATE,
80 ADMIN_UPDATE_CLIENT_INFO,
81 ADMIN_UPDATE_COMPANY_INFO,
82 ADMIN_UPDATE_COMPANY_ECONOMY,
83 ADMIN_UPDATE_COMPANY_STATS,
84 ADMIN_UPDATE_CHAT,
85 ADMIN_UPDATE_CONSOLE,
86 ADMIN_UPDATE_CMD_NAMES,
87 ADMIN_UPDATE_CMD_LOGGING,
88 ADMIN_UPDATE_GAMESCRIPT,
89 ADMIN_UPDATE_END,
90 };
91
93 enum AdminUpdateFrequency {
94 ADMIN_FREQUENCY_POLL = 0x01,
95 ADMIN_FREQUENCY_DAILY = 0x02,
96 ADMIN_FREQUENCY_WEEKLY = 0x04,
97 ADMIN_FREQUENCY_MONTHLY = 0x08,
98 ADMIN_FREQUENCY_QUARTERLY = 0x10,
99 ADMIN_FREQUENCY_ANUALLY = 0x20,
100 ADMIN_FREQUENCY_AUTOMATIC = 0x40,
101 };
102 DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequency)
103
104
105 enum AdminCompanyRemoveReason {
106 ADMIN_CRR_MANUAL,
107 ADMIN_CRR_AUTOCLEAN,
108 ADMIN_CRR_BANKRUPT,
109
110 ADMIN_CRR_END,
111 };
112
114 class NetworkAdminSocketHandler : public NetworkTCPSocketHandler {
115 protected:
116 char admin_name[NETWORK_CLIENT_NAME_LENGTH];
117 char admin_version[NETWORK_REVISION_LENGTH];
118 AdminStatus status;
119
120 NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type);
121
130 virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
131
137 virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
138
146 virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
147
157 virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
158
168 virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
169
176 virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
177
184 virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
185
192 virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
193
199 virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
200
206 virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
207
214 virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
215
225 virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet *p);
226
241 virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
242
248 virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
249
255 virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
256
263 virtual NetworkRecvStatus Receive_SERVER_DATE(Packet *p);
264
271 virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet *p);
272
284 virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
285
294 virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet *p);
295
302 virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet *p);
303
311 virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet *p);
312
319 virtual NetworkRecvStatus Receive_SERVER_COMPANY_NEW(Packet *p);
320
333 virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
334
350 virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
351
359 virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet *p);
360
377 virtual NetworkRecvStatus Receive_SERVER_COMPANY_ECONOMY(Packet *p);
378
395 virtual NetworkRecvStatus Receive_SERVER_COMPANY_STATS(Packet *p);
396
407 virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
408
416 virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
417
425 virtual NetworkRecvStatus Receive_SERVER_CONSOLE(Packet *p);
426
444 virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet *p);
445
466 virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet *p);
467
474 virtual NetworkRecvStatus Receive_SERVER_PONG(Packet *p);
475
482 virtual NetworkRecvStatus Receive_SERVER_RCON_END(Packet *p);
483
484 NetworkRecvStatus HandlePacket(Packet *p);
485 public:
486 NetworkRecvStatus CloseConnection(bool error = true);
487
488 NetworkAdminSocketHandler(SOCKET s);
489 ~NetworkAdminSocketHandler();
490
491 NetworkRecvStatus ReceivePackets();
492
497 AdminStatus GetAdminStatus() const
498 {
499 return this->status;
500 }
501 };
502
503 #endif /* ENABLE_NETWORK */
504
505 #endif /* NETWORK_CORE_TCP_ADMIN_H */