# network_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
    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;
    00024 typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS> NetworkAdminSocketPool;
    00025 extern NetworkAdminSocketPool _networkadminsocket_pool;
    00026
    00028 class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
    00029 protected:
    00030   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_JOIN);
    00031   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_QUIT);
    00032   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY);
    00033   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_POLL);
    00034   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_CHAT);
    00035   DECLARE_ADMIN_RECEIVE_COMMAND(ADMIN_PACKET_ADMIN_RCON);
    00036
    00037   NetworkRecvStatus SendProtocol();
    00038 public:
    00039   AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END];
    00040   uint32 realtime_connect;
    00041   NetworkAddress address;
    00042
    00043   ServerNetworkAdminSocketHandler(SOCKET s);
    00044   ~ServerNetworkAdminSocketHandler();
    00045
    00046   NetworkRecvStatus SendError(NetworkErrorCode error);
    00047   NetworkRecvStatus SendWelcome();
    00048   NetworkRecvStatus SendNewGame();
    00049   NetworkRecvStatus SendShutdown();
    00050
    00051   NetworkRecvStatus SendDate();
    00052   NetworkRecvStatus SendClientJoin(ClientID client_id);
    00053   NetworkRecvStatus SendClientInfo(const NetworkClientInfo *ci);
    00054   NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci);
    00055   NetworkRecvStatus SendClientQuit(ClientID client_id);
    00056   NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error);
    00057   NetworkRecvStatus SendCompanyNew(CompanyID company_id);
    00058   NetworkRecvStatus SendCompanyInfo(const Company *c);
    00059   NetworkRecvStatus SendCompanyUpdate(const Company *c);
    00060   NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
    00061   NetworkRecvStatus SendCompanyEconomy();
    00062   NetworkRecvStatus SendCompanyStats();
    00063
    00064   NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
    00065   NetworkRecvStatus SendRcon(uint16 colour, const char *command);
    00066   NetworkRecvStatus SendConsole(const char *origin, const char *command);
    00067   NetworkRecvStatus SendCmdNames();
    00068   NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp);
    00069
    00070   static void Send();
    00071   static void AcceptConnection(SOCKET s, const NetworkAddress &address);
    00072   static bool AllowConnection();
    00073   static void WelcomeAll();
    00074
    00079   static const char *GetName()
    00080   {
    00081     return "admin";
    00082   }
    00083 };
    00084
    00085 #define FOR_ALL_ADMIN_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(ServerNetworkAdminSocketHandler, adminsocket_index, var, start)
    00086 #define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
    00087
    00088 void NetworkAdminClientInfo(const NetworkClientInfo *ci, bool new_client = false);
    00089 void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
    00090 void NetworkAdminClientQuit(ClientID client_id);
    00091 void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
    00092 void NetworkAdminCompanyInfo(const Company *company, bool new_company);
    00093 void NetworkAdminCompanyUpdate(const Company *company);
    00094 void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
    00095
    00096 void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
    00097 void NetworkAdminUpdate(AdminUpdateFrequency freq);
    00098 void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
    00099 void NetworkAdminConsole(const char *origin, const char *string);
    00100 void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp);
    00101
    00102 #endif /* ENABLE_NETWORK */
    00103 #endif /* NETWORK_ADMIN_H */