# network_admin.h

Go to the documentation of this file.

    00001 /* $Id: network_admin.h 23623 2011-12-19 21:00:32Z truebrain $ */
    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
    00012 #ifndef NETWORK_ADMIN_H
    00013 #define NETWORK_ADMIN_H
    00014
    00015 #ifdef ENABLE_NETWORK
    00016
    00017 #include "network_internal.h"
    00018 #include "core/tcp_listen.h"
    00019 #include "core/tcp_admin.h"
    00020
    00021 extern AdminIndex _redirect_console_to_admin;
    00022
    00023 class ServerNetworkAdminSocketHandler;
    00025 typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN> NetworkAdminSocketPool;
    00026 extern NetworkAdminSocketPool _networkadminsocket_pool;
    00027
    00029 class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
    00030 protected:
    00031   virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
    00032   virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
    00033   virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
    00034   virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
    00035   virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
    00036   virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
    00037   virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
    00038
    00039   NetworkRecvStatus SendProtocol();
    00040 public:
    00041   AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END];
    00042   uint32 realtime_connect;
    00043   NetworkAddress address;
    00044
    00045   ServerNetworkAdminSocketHandler(SOCKET s);
    00046   ~ServerNetworkAdminSocketHandler();
    00047
    00048   NetworkRecvStatus SendError(NetworkErrorCode error);
    00049   NetworkRecvStatus SendWelcome();
    00050   NetworkRecvStatus SendNewGame();
    00051   NetworkRecvStatus SendShutdown();
    00052
    00053   NetworkRecvStatus SendDate();
    00054   NetworkRecvStatus SendClientJoin(ClientID client_id);
    00055   NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci);
    00056   NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci);
    00057   NetworkRecvStatus SendClientQuit(ClientID client_id);
    00058   NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error);
    00059   NetworkRecvStatus SendCompanyNew(CompanyID company_id);
    00060   NetworkRecvStatus SendCompanyInfo(const Company *c);
    00061   NetworkRecvStatus SendCompanyUpdate(const Company *c);
    00062   NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
    00063   NetworkRecvStatus SendCompanyEconomy();
    00064   NetworkRecvStatus SendCompanyStats();
    00065
    00066   NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
    00067   NetworkRecvStatus SendRcon(uint16 colour, const char *command);
    00068   NetworkRecvStatus SendConsole(const char *origin, const char *command);
    00069   NetworkRecvStatus SendGameScript(const char *json);
    00070   NetworkRecvStatus SendCmdNames();
    00071   NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp);
    00072
    00073   static void Send();
    00074   static void AcceptConnection(SOCKET s, const NetworkAddress &address);
    00075   static bool AllowConnection();
    00076   static void WelcomeAll();
    00077
    00082   static const char *GetName()
    00083   {
    00084     return "admin";
    00085   }
    00086 };
    00087
    00093 #define FOR_ALL_ADMIN_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(ServerNetworkAdminSocketHandler, adminsocket_index, var, start)
    00094
    00099 #define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
    00100
    00105 #define FOR_ALL_ACTIVE_ADMIN_SOCKETS(var) \
    00106   FOR_ALL_ADMIN_SOCKETS(var) \
    00107     if (var->GetAdminStatus() == ADMIN_STATUS_ACTIVE)
    00108
    00109 void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
    00110 void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
    00111 void NetworkAdminClientQuit(ClientID client_id);
    00112 void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
    00113 void NetworkAdminCompanyInfo(const Company *company, bool new_company);
    00114 void NetworkAdminCompanyUpdate(const Company *company);
    00115 void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
    00116
    00117 void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
    00118 void NetworkAdminUpdate(AdminUpdateFrequency freq);
    00119 void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
    00120 void NetworkAdminConsole(const char *origin, const char *string);
    00121 void NetworkAdminGameScript(const char *json);
    00122 void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp);
    00123
    00124 #endif /* ENABLE_NETWORK */
    00125 #endif /* NETWORK_ADMIN_H */