2010-10-17 17:31:03 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file network_admin.h Server part of the admin network protocol. */
|
|
|
|
|
|
|
|
#ifndef NETWORK_ADMIN_H
|
|
|
|
#define NETWORK_ADMIN_H
|
|
|
|
|
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
|
|
|
|
#include "network_internal.h"
|
|
|
|
#include "core/tcp_listen.h"
|
|
|
|
#include "core/tcp_admin.h"
|
|
|
|
|
2010-10-17 17:41:52 +00:00
|
|
|
extern AdminIndex _redirect_console_to_admin;
|
|
|
|
|
2010-10-17 17:31:03 +00:00
|
|
|
class ServerNetworkAdminSocketHandler;
|
2011-05-05 16:24:48 +00:00
|
|
|
/** Pool with all admin connections. */
|
2011-02-19 23:05:47 +00:00
|
|
|
typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN> NetworkAdminSocketPool;
|
2010-10-17 17:31:03 +00:00
|
|
|
extern NetworkAdminSocketPool _networkadminsocket_pool;
|
|
|
|
|
|
|
|
/** Class for handling the server side of the game connection. */
|
|
|
|
class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
|
|
|
|
protected:
|
2011-05-01 11:01:57 +00:00
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
|
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
|
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
|
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
|
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
|
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
|
2011-12-19 21:00:32 +00:00
|
|
|
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
|
2010-10-17 17:31:03 +00:00
|
|
|
|
|
|
|
NetworkRecvStatus SendProtocol();
|
|
|
|
public:
|
2010-10-17 17:36:23 +00:00
|
|
|
AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]; ///< Admin requested update intervals.
|
2010-10-17 17:33:46 +00:00
|
|
|
uint32 realtime_connect; ///< Time of connection.
|
2010-10-17 17:31:03 +00:00
|
|
|
NetworkAddress address; ///< Address of the admin.
|
|
|
|
|
|
|
|
ServerNetworkAdminSocketHandler(SOCKET s);
|
|
|
|
~ServerNetworkAdminSocketHandler();
|
|
|
|
|
|
|
|
NetworkRecvStatus SendError(NetworkErrorCode error);
|
|
|
|
NetworkRecvStatus SendWelcome();
|
|
|
|
NetworkRecvStatus SendNewGame();
|
|
|
|
NetworkRecvStatus SendShutdown();
|
2010-10-17 17:40:18 +00:00
|
|
|
|
2010-10-17 17:36:59 +00:00
|
|
|
NetworkRecvStatus SendDate();
|
2010-10-17 17:37:26 +00:00
|
|
|
NetworkRecvStatus SendClientJoin(ClientID client_id);
|
2011-11-04 22:32:21 +00:00
|
|
|
NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci);
|
2010-10-17 17:37:26 +00:00
|
|
|
NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci);
|
|
|
|
NetworkRecvStatus SendClientQuit(ClientID client_id);
|
|
|
|
NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error);
|
2010-10-17 17:37:45 +00:00
|
|
|
NetworkRecvStatus SendCompanyNew(CompanyID company_id);
|
|
|
|
NetworkRecvStatus SendCompanyInfo(const Company *c);
|
|
|
|
NetworkRecvStatus SendCompanyUpdate(const Company *c);
|
|
|
|
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
|
2010-10-17 17:38:16 +00:00
|
|
|
NetworkRecvStatus SendCompanyEconomy();
|
2010-10-17 17:38:41 +00:00
|
|
|
NetworkRecvStatus SendCompanyStats();
|
2010-10-17 17:31:03 +00:00
|
|
|
|
2010-10-17 17:40:18 +00:00
|
|
|
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
|
2010-10-17 17:41:52 +00:00
|
|
|
NetworkRecvStatus SendRcon(uint16 colour, const char *command);
|
2010-10-17 17:43:01 +00:00
|
|
|
NetworkRecvStatus SendConsole(const char *origin, const char *command);
|
2011-12-19 21:00:32 +00:00
|
|
|
NetworkRecvStatus SendGameScript(const char *json);
|
2010-12-30 18:14:37 +00:00
|
|
|
NetworkRecvStatus SendCmdNames();
|
|
|
|
NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp);
|
2010-10-17 17:40:18 +00:00
|
|
|
|
2010-10-17 17:31:03 +00:00
|
|
|
static void Send();
|
|
|
|
static void AcceptConnection(SOCKET s, const NetworkAddress &address);
|
|
|
|
static bool AllowConnection();
|
|
|
|
static void WelcomeAll();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name used by the listener.
|
|
|
|
* @return the name to show in debug logs and the like.
|
|
|
|
*/
|
|
|
|
static const char *GetName()
|
|
|
|
{
|
|
|
|
return "admin";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-05 16:24:48 +00:00
|
|
|
/**
|
|
|
|
* Iterate over all the sockets from a given starting point.
|
|
|
|
* @param var The variable to iterate with.
|
|
|
|
* @param start The start of the iteration.
|
|
|
|
*/
|
2010-10-17 17:31:03 +00:00
|
|
|
#define FOR_ALL_ADMIN_SOCKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(ServerNetworkAdminSocketHandler, adminsocket_index, var, start)
|
2011-05-05 16:24:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over all the sockets.
|
|
|
|
* @param var The variable to iterate with.
|
|
|
|
*/
|
2010-10-17 17:31:03 +00:00
|
|
|
#define FOR_ALL_ADMIN_SOCKETS(var) FOR_ALL_ADMIN_SOCKETS_FROM(var, 0)
|
|
|
|
|
2011-09-15 18:28:39 +00:00
|
|
|
/**
|
|
|
|
* Iterate over all the active sockets.
|
|
|
|
* @param var The variable to iterate with.
|
|
|
|
*/
|
|
|
|
#define FOR_ALL_ACTIVE_ADMIN_SOCKETS(var) \
|
|
|
|
FOR_ALL_ADMIN_SOCKETS(var) \
|
|
|
|
if (var->GetAdminStatus() == ADMIN_STATUS_ACTIVE)
|
|
|
|
|
2011-04-22 16:03:13 +00:00
|
|
|
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client = false);
|
2010-10-17 17:37:26 +00:00
|
|
|
void NetworkAdminClientUpdate(const NetworkClientInfo *ci);
|
|
|
|
void NetworkAdminClientQuit(ClientID client_id);
|
|
|
|
void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code);
|
2010-10-17 17:37:45 +00:00
|
|
|
void NetworkAdminCompanyInfo(const Company *company, bool new_company);
|
|
|
|
void NetworkAdminCompanyUpdate(const Company *company);
|
|
|
|
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
|
2010-10-17 17:40:18 +00:00
|
|
|
|
|
|
|
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
|
2010-10-17 17:36:23 +00:00
|
|
|
void NetworkAdminUpdate(AdminUpdateFrequency freq);
|
2011-01-03 12:01:41 +00:00
|
|
|
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
|
2010-10-17 17:43:01 +00:00
|
|
|
void NetworkAdminConsole(const char *origin, const char *string);
|
2011-12-19 21:00:32 +00:00
|
|
|
void NetworkAdminGameScript(const char *json);
|
2010-12-30 18:14:37 +00:00
|
|
|
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp);
|
2010-10-17 17:36:23 +00:00
|
|
|
|
2010-10-17 17:31:03 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
#endif /* NETWORK_ADMIN_H */
|