# 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
    00036   ADMIN_PACKET_SERVER_FULL = 100,
    00037   ADMIN_PACKET_SERVER_BANNED,
    00038   ADMIN_PACKET_SERVER_ERROR,
    00039   ADMIN_PACKET_SERVER_PROTOCOL,
    00040   ADMIN_PACKET_SERVER_WELCOME,
    00041   ADMIN_PACKET_SERVER_NEWGAME,
    00042   ADMIN_PACKET_SERVER_SHUTDOWN,
    00043
    00044   ADMIN_PACKET_SERVER_DATE,
    00045   ADMIN_PACKET_SERVER_CLIENT_JOIN,
    00046   ADMIN_PACKET_SERVER_CLIENT_INFO,
    00047   ADMIN_PACKET_SERVER_CLIENT_UPDATE,
    00048   ADMIN_PACKET_SERVER_CLIENT_QUIT,
    00049   ADMIN_PACKET_SERVER_CLIENT_ERROR,
    00050   ADMIN_PACKET_SERVER_COMPANY_NEW,
    00051   ADMIN_PACKET_SERVER_COMPANY_INFO,
    00052   ADMIN_PACKET_SERVER_COMPANY_UPDATE,
    00053   ADMIN_PACKET_SERVER_COMPANY_REMOVE,
    00054   ADMIN_PACKET_SERVER_COMPANY_ECONOMY,
    00055   ADMIN_PACKET_SERVER_COMPANY_STATS,
    00056   ADMIN_PACKET_SERVER_CHAT,
    00057   ADMIN_PACKET_SERVER_RCON,
    00058   ADMIN_PACKET_SERVER_CONSOLE,
    00059   ADMIN_PACKET_SERVER_CMD_NAMES,
    00060   ADMIN_PACKET_SERVER_CMD_LOGGING,
    00061
    00062   INVALID_ADMIN_PACKET = 0xFF,
    00063 };
    00064
    00066 enum AdminStatus {
    00067   ADMIN_STATUS_INACTIVE,
    00068   ADMIN_STATUS_ACTIVE,
    00069   ADMIN_STATUS_END
    00070 };
    00071
    00073 enum AdminUpdateType {
    00074   ADMIN_UPDATE_DATE,
    00075   ADMIN_UPDATE_CLIENT_INFO,
    00076   ADMIN_UPDATE_COMPANY_INFO,
    00077   ADMIN_UPDATE_COMPANY_ECONOMY,
    00078   ADMIN_UPDATE_COMPANY_STATS,
    00079   ADMIN_UPDATE_CHAT,
    00080   ADMIN_UPDATE_CONSOLE,
    00081   ADMIN_UPDATE_CMD_NAMES,
    00082   ADMIN_UPDATE_CMD_LOGGING,
    00083   ADMIN_UPDATE_END
    00084 };
    00085
    00087 enum AdminUpdateFrequency {
    00088   ADMIN_FREQUENCY_POLL      = 0x01,
    00089   ADMIN_FREQUENCY_DAILY     = 0x02,
    00090   ADMIN_FREQUENCY_WEEKLY    = 0x04,
    00091   ADMIN_FREQUENCY_MONTHLY   = 0x08,
    00092   ADMIN_FREQUENCY_QUARTERLY = 0x10,
    00093   ADMIN_FREQUENCY_ANUALLY   = 0x20,
    00094   ADMIN_FREQUENCY_AUTOMATIC = 0x40,
    00095 };
    00096 DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequency)
    00097
    00098
    00099 enum AdminCompanyRemoveReason {
    00100   ADMIN_CRR_MANUAL,
    00101   ADMIN_CRR_AUTOCLEAN,
    00102   ADMIN_CRR_BANKRUPT
    00103 };
    00104
    00106 class NetworkAdminSocketHandler : public NetworkTCPSocketHandler {
    00107 protected:
    00108   char admin_name[NETWORK_CLIENT_NAME_LENGTH];
    00109   char admin_version[NETWORK_REVISION_LENGTH];
    00110   AdminStatus status;
    00111
    00112   NetworkRecvStatus ReceiveInvalidPacket(PacketAdminType type);
    00113
    00122   virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
    00123
    00129   virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
    00130
    00138   virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
    00139
    00149   virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
    00150
    00160   virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
    00161
    00168   virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
    00169
    00175   virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
    00176
    00182   virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
    00183
    00190   virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
    00191
    00201   virtual NetworkRecvStatus Receive_SERVER_PROTOCOL(Packet *p);
    00202
    00217   virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
    00218
    00224   virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
    00225
    00231   virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
    00232
    00239   virtual NetworkRecvStatus Receive_SERVER_DATE(Packet *p);
    00240
    00247   virtual NetworkRecvStatus Receive_SERVER_CLIENT_JOIN(Packet *p);
    00248
    00260   virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
    00261
    00270   virtual NetworkRecvStatus Receive_SERVER_CLIENT_UPDATE(Packet *p);
    00271
    00278   virtual NetworkRecvStatus Receive_SERVER_CLIENT_QUIT(Packet *p);
    00279
    00287   virtual NetworkRecvStatus Receive_SERVER_CLIENT_ERROR(Packet *p);
    00288
    00295   virtual NetworkRecvStatus Receive_SERVER_COMPANY_NEW(Packet *p);
    00296
    00309   virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
    00310
    00326   virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
    00327
    00335   virtual NetworkRecvStatus Receive_SERVER_COMPANY_REMOVE(Packet *p);
    00336
    00353   virtual NetworkRecvStatus Receive_SERVER_COMPANY_ECONOMY(Packet *p);
    00354
    00371   virtual NetworkRecvStatus Receive_SERVER_COMPANY_STATS(Packet *p);
    00372
    00383   virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
    00384
    00392   virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
    00393
    00401   virtual NetworkRecvStatus Receive_SERVER_CONSOLE(Packet *p);
    00402
    00420   virtual NetworkRecvStatus Receive_SERVER_CMD_NAMES(Packet *p);
    00421
    00442   virtual NetworkRecvStatus Receive_SERVER_CMD_LOGGING(Packet *p);
    00443
    00444   NetworkRecvStatus HandlePacket(Packet *p);
    00445 public:
    00446   NetworkRecvStatus CloseConnection(bool error = true);
    00447
    00448   NetworkAdminSocketHandler(SOCKET s);
    00449   ~NetworkAdminSocketHandler();
    00450
    00451   NetworkRecvStatus ReceivePackets();
    00452 };
    00453
    00454 #endif /* ENABLE_NETWORK */
    00455
    00456 #endif /* NETWORK_CORE_TCP_ADMIN_H */