# tcp_admin.h

Go to the documentation of this file.

    00001 /* $Id$ */
    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
    00037   ADMIN_PACKET_SERVER_FULL = 100,
    00038   ADMIN_PACKET_SERVER_BANNED,
    00039   ADMIN_PACKET_SERVER_ERROR,
    00040   ADMIN_PACKET_SERVER_PROTOCOL,
    00041   ADMIN_PACKET_SERVER_WELCOME,
    00042   ADMIN_PACKET_SERVER_NEWGAME,
    00043   ADMIN_PACKET_SERVER_SHUTDOWN,
    00044
    00045   ADMIN_PACKET_SERVER_DATE,
    00046   ADMIN_PACKET_SERVER_CLIENT_JOIN,
    00047   ADMIN_PACKET_SERVER_CLIENT_INFO,
    00048   ADMIN_PACKET_SERVER_CLIENT_UPDATE,
    00049   ADMIN_PACKET_SERVER_CLIENT_QUIT,
    00050   ADMIN_PACKET_SERVER_CLIENT_ERROR,
    00051   ADMIN_PACKET_SERVER_COMPANY_NEW,
    00052   ADMIN_PACKET_SERVER_COMPANY_INFO,
    00053   ADMIN_PACKET_SERVER_COMPANY_UPDATE,
    00054   ADMIN_PACKET_SERVER_COMPANY_REMOVE,
    00055   ADMIN_PACKET_SERVER_COMPANY_ECONOMY,
    00056   ADMIN_PACKET_SERVER_COMPANY_STATS,
    00057   ADMIN_PACKET_SERVER_CHAT,
    00058   ADMIN_PACKET_SERVER_RCON,
    00059   ADMIN_PACKET_SERVER_CONSOLE,
    00060   ADMIN_PACKET_SERVER_CMD_NAMES,
    00061   ADMIN_PACKET_SERVER_CMD_LOGGING,
    00062   ADMIN_PACKET_SERVER_GAMESCRIPT,
    00063
    00064   INVALID_ADMIN_PACKET = 0xFF,
    00065 };
    00066
    00068 enum AdminStatus {
    00069   ADMIN_STATUS_INACTIVE,
    00070   ADMIN_STATUS_ACTIVE,
    00071   ADMIN_STATUS_END,
    00072 };
    00073
    00075 enum AdminUpdateType {
    00076   ADMIN_UPDATE_DATE,
    00077   ADMIN_UPDATE_CLIENT_INFO,
    00078   ADMIN_UPDATE_COMPANY_INFO,
    00079   ADMIN_UPDATE_COMPANY_ECONOMY,
    00080   ADMIN_UPDATE_COMPANY_STATS,
    00081   ADMIN_UPDATE_CHAT,
    00082   ADMIN_UPDATE_CONSOLE,
    00083   ADMIN_UPDATE_CMD_NAMES,
    00084   ADMIN_UPDATE_CMD_LOGGING,
    00085   ADMIN_UPDATE_GAMESCRIPT,
    00086   ADMIN_UPDATE_END,
    00087 };
    00088
    00090 enum AdminUpdateFrequency {
    00091   ADMIN_FREQUENCY_POLL      = 0x01,
    00092   ADMIN_FREQUENCY_DAILY     = 0x02,
    00093   ADMIN_FREQUENCY_WEEKLY    = 0x04,
    00094   ADMIN_FREQUENCY_MONTHLY   = 0x08,
    00095   ADMIN_FREQUENCY_QUARTERLY = 0x10,
    00096   ADMIN_FREQUENCY_ANUALLY   = 0x20,
    00097   ADMIN_FREQUENCY_AUTOMATIC = 0x40,
    00098 };
    00099 DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequency)
    00100
    00101
    00102 enum AdminCompanyRemoveReason {
    00103   ADMIN_CRR_MANUAL,
    00104   ADMIN_CRR_AUTOCLEAN,
    00105   ADMIN_CRR_BANKRUPT,
    00106
    00107   ADMIN_CRR_END,
    00108 };
    00109
    00111 class NetworkAdminSocketHandler : public NetworkTCPSocketHandler {
    00112 protected:
    00113   char admin_name[NETWORK_CLIENT_NAME_LENGTH];
    00114   char admin_version[NETWORK_REVISION_LENGTH];
    00115   AdminStatus status;
    00116
    00117   NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type);
    00118
    00127   virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
    00128
    00134   virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
    00135
    00143   virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
    00144
    00154   virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
    00155
    00165   virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
    00166
    00173   virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
    00174
    00181   virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
    00182
    00188   virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
    00189
    00195   virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
    00196
    00203   virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
    00204
    00214   virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet *p);
    00215
    00230   virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
    00231
    00237   virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
    00238
    00244   virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
    00245
    00252   virtual NetworkRecvStatus Receive_SERVER_DATE(Packet *p);
    00253
    00260   virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet *p);
    00261
    00273   virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
    00274
    00283   virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet *p);
    00284
    00291   virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet *p);
    00292
    00300   virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet *p);
    00301
    00308   virtual NetworkRecvStatus Receive_SERVER_COMPANY_NEW(Packet *p);
    00309
    00322   virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
    00323
    00339   virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
    00340
    00348   virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet *p);
    00349
    00366   virtual NetworkRecvStatus Receive_SERVER_COMPANY_ECONOMY(Packet *p);
    00367
    00384   virtual NetworkRecvStatus Receive_SERVER_COMPANY_STATS(Packet *p);
    00385
    00396   virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
    00397
    00405   virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
    00406
    00414   virtual NetworkRecvStatus Receive_SERVER_CONSOLE(Packet *p);
    00415
    00433   virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet *p);
    00434
    00455   virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet *p);
    00456
    00457   NetworkRecvStatus HandlePacket(Packet *p);
    00458 public:
    00459   NetworkRecvStatus CloseConnection(bool error = true);
    00460
    00461   NetworkAdminSocketHandler(SOCKET s);
    00462   ~NetworkAdminSocketHandler();
    00463
    00464   NetworkRecvStatus ReceivePackets();
    00465
    00470   AdminStatus GetAdminStatus() const
    00471   {
    00472     return this->status;
    00473   }
    00474 };
    00475
    00476 #endif /* ENABLE_NETWORK */
    00477
    00478 #endif /* NETWORK_CORE_TCP_ADMIN_H */