# tcp_admin.h

Go to the documentation of this file.

    00001 /* $Id: tcp_admin.h 23052 2011-10-22 20:54:23Z rubidium $ */
    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   ADMIN_CRR_END
    00105 };
    00106
    00107 #define DECLARE_ADMIN_RECEIVE_COMMAND(type) virtual NetworkRecvStatus NetworkPacketReceive_## type ##_command(Packet *p)
    00108 #define DEF_ADMIN_RECEIVE_COMMAND(cls, type) NetworkRecvStatus cls ##NetworkAdminSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p)
    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
    00123   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_JOIN);
    00124
    00128   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_QUIT);
    00129
    00135   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY);
    00136
    00144   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_POLL);
    00145
    00153   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_CHAT);
    00154
    00159   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_RCON);
    00160
    00164   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_FULL);
    00165
    00169   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_BANNED);
    00170
    00175   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_ERROR);
    00176
    00184   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_PROTOCOL);
    00185
    00198   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_WELCOME);
    00199
    00203   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_NEWGAME);
    00204
    00208   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN);
    00209
    00214   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_DATE);
    00215
    00220   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_JOIN);
    00221
    00231   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_INFO);
    00232
    00239   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_UPDATE);
    00240
    00245   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_QUIT);
    00246
    00252   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_ERROR);
    00253
    00258   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_NEW);
    00259
    00270   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_INFO);
    00271
    00285   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_UPDATE);
    00286
    00292   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_REMOVE);
    00293
    00308   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
    00309
    00324   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_STATS);
    00325
    00334   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CHAT);
    00335
    00341   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_RCON);
    00342
    00348   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CONSOLE);
    00349
    00365   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CMD_NAMES);
    00366
    00385   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CMD_LOGGING);
    00386
    00387   NetworkRecvStatus HandlePacket(Packet *p);
    00388 public:
    00389   NetworkRecvStatus CloseConnection(bool error = true);
    00390
    00391   NetworkAdminSocketHandler(SOCKET s);
    00392   ~NetworkAdminSocketHandler();
    00393
    00394   NetworkRecvStatus ReceivePackets();
    00395
    00396   const char *ReceiveCommand(Packet *p, struct CommandPacket *cp);
    00397   void SendCommand(Packet *p, const struct CommandPacket *cp);
    00398
    00403   AdminStatus GetAdminStatus() const
    00404   {
    00405     return this->status;
    00406   }
    00407 };
    00408
    00409 #endif /* ENABLE_NETWORK */
    00410
    00411 #endif /* NETWORK_CORE_TCP_ADMIN_H */