# 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
    00105 #define DECLARE_ADMIN_RECEIVE_COMMAND(type) virtual NetworkRecvStatus NetworkPacketReceive_## type ##_command(Packet *p)
    00106 #define DEF_ADMIN_RECEIVE_COMMAND(cls, type) NetworkRecvStatus cls ##NetworkAdminSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p)
    00107
    00109 class NetworkAdminSocketHandler : public NetworkTCPSocketHandler {
    00110 protected:
    00111   char admin_name[NETWORK_CLIENT_NAME_LENGTH];
    00112   char admin_version[NETWORK_REVISION_LENGTH];
    00113   AdminStatus status;
    00114
    00121   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_JOIN);
    00122
    00126   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_QUIT);
    00127
    00133   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY);
    00134
    00142   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_POLL);
    00143
    00151   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_CHAT);
    00152
    00157   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_RCON);
    00158
    00162   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_FULL);
    00163
    00167   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_BANNED);
    00168
    00173   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_ERROR);
    00174
    00182   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_PROTOCOL);
    00183
    00196   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_WELCOME);
    00197
    00201   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_NEWGAME);
    00202
    00206   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_SHUTDOWN);
    00207
    00212   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_DATE);
    00213
    00218   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_JOIN);
    00219
    00229   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_INFO);
    00230
    00237   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_UPDATE);
    00238
    00243   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_QUIT);
    00244
    00250   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CLIENT_ERROR);
    00251
    00256   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_NEW);
    00257
    00268   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_INFO);
    00269
    00283   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_UPDATE);
    00284
    00290   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_REMOVE);
    00291
    00305   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
    00306
    00321   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_COMPANY_STATS);
    00322
    00331   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CHAT);
    00332
    00338   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_RCON);
    00339
    00345   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CONSOLE);
    00346
    00362   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CMD_NAMES);
    00363
    00382   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_SERVER_CMD_LOGGING);
    00383
    00384   NetworkRecvStatus HandlePacket(Packet *p);
    00385 public:
    00386   NetworkRecvStatus CloseConnection(bool error = true);
    00387
    00388   NetworkAdminSocketHandler(SOCKET s);
    00389   ~NetworkAdminSocketHandler();
    00390
    00391   NetworkRecvStatus ReceivePackets();
    00392
    00393   const char *ReceiveCommand(Packet *p, struct CommandPacket *cp);
    00394   void SendCommand(Packet *p, const struct CommandPacket *cp);
    00395 };
    00396
    00397 #endif /* ENABLE_NETWORK */
    00398
    00399 #endif /* NETWORK_CORE_TCP_ADMIN_H */