# tcp_admin.h

Go to the documentation of this file.

    00001 /* $Id: tcp_admin.h 25588 2013-07-11 20:31:39Z planetmaker $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00014 #ifndef NETWORK_CORE_TCP_ADMIN_H
    00015 #define NETWORK_CORE_TCP_ADMIN_H
    00016
    00017 #include "os_abstraction.h"
    00018 #include "tcp.h"
    00019 #include "../network_type.h"
    00020 #include "../../core/pool_type.hpp"
    00021
    00022 #ifdef ENABLE_NETWORK
    00023
    00028 enum PacketAdminType {
    00029   ADMIN_PACKET_ADMIN_JOIN,
    00030   ADMIN_PACKET_ADMIN_QUIT,
    00031   ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY,
    00032   ADMIN_PACKET_ADMIN_POLL,
    00033   ADMIN_PACKET_ADMIN_CHAT,
    00034   ADMIN_PACKET_ADMIN_RCON,
    00035   ADMIN_PACKET_ADMIN_GAMESCRIPT,
    00036   ADMIN_PACKET_ADMIN_PING,
    00037
    00038   ADMIN_PACKET_SERVER_FULL = 100,
    00039   ADMIN_PACKET_SERVER_BANNED,
    00040   ADMIN_PACKET_SERVER_ERROR,
    00041   ADMIN_PACKET_SERVER_PROTOCOL,
    00042   ADMIN_PACKET_SERVER_WELCOME,
    00043   ADMIN_PACKET_SERVER_NEWGAME,
    00044   ADMIN_PACKET_SERVER_SHUTDOWN,
    00045
    00046   ADMIN_PACKET_SERVER_DATE,
    00047   ADMIN_PACKET_SERVER_CLIENT_JOIN,
    00048   ADMIN_PACKET_SERVER_CLIENT_INFO,
    00049   ADMIN_PACKET_SERVER_CLIENT_UPDATE,
    00050   ADMIN_PACKET_SERVER_CLIENT_QUIT,
    00051   ADMIN_PACKET_SERVER_CLIENT_ERROR,
    00052   ADMIN_PACKET_SERVER_COMPANY_NEW,
    00053   ADMIN_PACKET_SERVER_COMPANY_INFO,
    00054   ADMIN_PACKET_SERVER_COMPANY_UPDATE,
    00055   ADMIN_PACKET_SERVER_COMPANY_REMOVE,
    00056   ADMIN_PACKET_SERVER_COMPANY_ECONOMY,
    00057   ADMIN_PACKET_SERVER_COMPANY_STATS,
    00058   ADMIN_PACKET_SERVER_CHAT,
    00059   ADMIN_PACKET_SERVER_RCON,
    00060   ADMIN_PACKET_SERVER_CONSOLE,
    00061   ADMIN_PACKET_SERVER_CMD_NAMES,
    00062   ADMIN_PACKET_SERVER_CMD_LOGGING,
    00063   ADMIN_PACKET_SERVER_GAMESCRIPT,
    00064   ADMIN_PACKET_SERVER_RCON_END,
    00065   ADMIN_PACKET_SERVER_PONG,
    00066
    00067   INVALID_ADMIN_PACKET = 0xFF,
    00068 };
    00069
    00071 enum AdminStatus {
    00072   ADMIN_STATUS_INACTIVE,
    00073   ADMIN_STATUS_ACTIVE,
    00074   ADMIN_STATUS_END,
    00075 };
    00076
    00078 enum AdminUpdateType {
    00079   ADMIN_UPDATE_DATE,
    00080   ADMIN_UPDATE_CLIENT_INFO,
    00081   ADMIN_UPDATE_COMPANY_INFO,
    00082   ADMIN_UPDATE_COMPANY_ECONOMY,
    00083   ADMIN_UPDATE_COMPANY_STATS,
    00084   ADMIN_UPDATE_CHAT,
    00085   ADMIN_UPDATE_CONSOLE,
    00086   ADMIN_UPDATE_CMD_NAMES,
    00087   ADMIN_UPDATE_CMD_LOGGING,
    00088   ADMIN_UPDATE_GAMESCRIPT,
    00089   ADMIN_UPDATE_END,
    00090 };
    00091
    00093 enum AdminUpdateFrequency {
    00094   ADMIN_FREQUENCY_POLL      = 0x01,
    00095   ADMIN_FREQUENCY_DAILY     = 0x02,
    00096   ADMIN_FREQUENCY_WEEKLY    = 0x04,
    00097   ADMIN_FREQUENCY_MONTHLY   = 0x08,
    00098   ADMIN_FREQUENCY_QUARTERLY = 0x10,
    00099   ADMIN_FREQUENCY_ANUALLY   = 0x20,
    00100   ADMIN_FREQUENCY_AUTOMATIC = 0x40,
    00101 };
    00102 DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequency)
    00103
    00104
    00105 enum AdminCompanyRemoveReason {
    00106   ADMIN_CRR_MANUAL,
    00107   ADMIN_CRR_AUTOCLEAN,
    00108   ADMIN_CRR_BANKRUPT,
    00109
    00110   ADMIN_CRR_END,
    00111 };
    00112
    00114 class NetworkAdminSocketHandler : public NetworkTCPSocketHandler {
    00115 protected:
    00116   char admin_name[NETWORK_CLIENT_NAME_LENGTH];
    00117   char admin_version[NETWORK_REVISION_LENGTH];
    00118   AdminStatus status;
    00119
    00120   NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type);
    00121
    00130   virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
    00131
    00137   virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
    00138
    00146   virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
    00147
    00157   virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
    00158
    00168   virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
    00169
    00176   virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
    00177
    00184   virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
    00185
    00192   virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
    00193
    00199   virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
    00200
    00206   virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
    00207
    00214   virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
    00215
    00225   virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet *p);
    00226
    00241   virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
    00242
    00248   virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
    00249
    00255   virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
    00256
    00263   virtual NetworkRecvStatus Receive_SERVER_DATE(Packet *p);
    00264
    00271   virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet *p);
    00272
    00284   virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
    00285
    00294   virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet *p);
    00295
    00302   virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet *p);
    00303
    00311   virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet *p);
    00312
    00319   virtual NetworkRecvStatus Receive_SERVER_COMPANY_NEW(Packet *p);
    00320
    00333   virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
    00334
    00350   virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
    00351
    00359   virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet *p);
    00360
    00377   virtual NetworkRecvStatus Receive_SERVER_COMPANY_ECONOMY(Packet *p);
    00378
    00395   virtual NetworkRecvStatus Receive_SERVER_COMPANY_STATS(Packet *p);
    00396
    00407   virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
    00408
    00416   virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
    00417
    00425   virtual NetworkRecvStatus Receive_SERVER_CONSOLE(Packet *p);
    00426
    00444   virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet *p);
    00445
    00466   virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet *p);
    00467
    00474   virtual NetworkRecvStatus Receive_SERVER_PONG(Packet *p);
    00475
    00482   virtual NetworkRecvStatus Receive_SERVER_RCON_END(Packet *p);
    00483
    00484   NetworkRecvStatus HandlePacket(Packet *p);
    00485 public:
    00486   NetworkRecvStatus CloseConnection(bool error = true);
    00487
    00488   NetworkAdminSocketHandler(SOCKET s);
    00489   ~NetworkAdminSocketHandler();
    00490
    00491   NetworkRecvStatus ReceivePackets();
    00492
    00497   AdminStatus GetAdminStatus() const
    00498   {
    00499     return this->status;
    00500   }
    00501 };
    00502
    00503 #endif /* ENABLE_NETWORK */
    00504
    00505 #endif /* NETWORK_CORE_TCP_ADMIN_H */