2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// cServer.h
|
|
|
|
|
|
|
|
// Interfaces to the cServer object representing the network server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-01-05 17:06:17 -05:00
|
|
|
#include "RCONServer.h"
|
2015-01-24 14:17:00 -05:00
|
|
|
#include "OSSupport/IsThread.h"
|
|
|
|
#include "OSSupport/Network.h"
|
2014-01-05 17:06:17 -05:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4127)
|
|
|
|
#pragma warning(disable:4244)
|
|
|
|
#pragma warning(disable:4231)
|
|
|
|
#pragma warning(disable:4189)
|
|
|
|
#pragma warning(disable:4702)
|
|
|
|
#endif
|
|
|
|
|
2014-04-29 05:04:54 -04:00
|
|
|
#include "PolarSSL++/RsaPrivateKey.h"
|
2014-01-05 17:06:17 -05:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
// fwd:
|
2012-06-14 09:06:06 -04:00
|
|
|
class cPlayer;
|
|
|
|
class cClientHandle;
|
2015-01-24 14:17:00 -05:00
|
|
|
typedef SharedPtr<cClientHandle> cClientHandlePtr;
|
|
|
|
typedef std::list<cClientHandlePtr> cClientHandlePtrs;
|
|
|
|
typedef std::list<cClientHandle *> cClientHandles;
|
2014-07-14 14:49:31 -04:00
|
|
|
class cCommandOutputCallback;
|
2015-05-14 10:47:51 -04:00
|
|
|
class cSettingsRepositoryInterface;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2014-07-15 19:03:47 -04:00
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
// tolua_begin
|
|
|
|
class cServer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// tolua_end
|
2013-12-21 10:38:37 -05:00
|
|
|
|
|
|
|
virtual ~cServer() {}
|
2015-05-14 10:47:51 -04:00
|
|
|
bool InitServer(cSettingsRepositoryInterface & a_Settings, bool a_ShouldAuth);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-11 13:18:06 -04:00
|
|
|
// tolua_begin
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:18:06 -04:00
|
|
|
const AString & GetDescription(void) const {return m_Description; }
|
|
|
|
|
2017-01-03 13:57:31 -05:00
|
|
|
const AString & GetShutdownMessage(void) const { return m_ShutdownMessage; }
|
|
|
|
|
2013-08-11 13:18:06 -04:00
|
|
|
// Player counts:
|
2014-07-26 18:39:39 -04:00
|
|
|
int GetMaxPlayers(void) const { return m_MaxPlayers; }
|
2014-04-19 11:53:02 -04:00
|
|
|
int GetNumPlayers(void) const;
|
2013-08-11 13:18:06 -04:00
|
|
|
void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-12-08 17:33:59 -05:00
|
|
|
/** Check if the player is queued to be transferred to a World.
|
2014-12-09 06:06:25 -05:00
|
|
|
Returns true is Player is found in queue. */
|
2014-12-08 03:45:29 -05:00
|
|
|
bool IsPlayerInQueue(AString a_Username);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-12-11 08:34:09 -05:00
|
|
|
/** Can login more than once with same username.
|
2014-12-09 06:06:25 -05:00
|
|
|
Returns false if it is not allowed, true otherwise. */
|
|
|
|
bool DoesAllowMultiLogin(void) { return m_bAllowMultiLogin; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-11-04 16:51:24 -05:00
|
|
|
// Hardcore mode or not:
|
2014-07-26 18:39:39 -04:00
|
|
|
bool IsHardcore(void) const { return m_bIsHardcore; }
|
2013-11-04 16:51:24 -05:00
|
|
|
|
2013-08-12 01:55:53 -04:00
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-03-04 16:13:08 -05:00
|
|
|
bool Start(void);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-06-22 15:08:34 -04:00
|
|
|
bool Command(cClientHandle & a_Client, AString & a_Cmd);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Executes the console command, sends output through the specified callback */
|
2013-06-29 11:30:05 -04:00
|
|
|
void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Lists all available console commands and their helpstrings */
|
2013-11-13 09:56:40 -05:00
|
|
|
void PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output);
|
2013-02-15 08:00:59 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Binds the built-in console commands with the plugin manager */
|
2013-02-15 08:00:59 -05:00
|
|
|
static void BindBuiltInConsoleCommands(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 14:16:41 -04:00
|
|
|
void Shutdown(void);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
void KickUser(int a_ClientID, const AString & a_Reason);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-07-15 19:03:47 -04:00
|
|
|
/** Authenticates the specified user, called by cAuthenticator */
|
|
|
|
void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-11 13:46:27 -04:00
|
|
|
const AString & GetServerID(void) const { return m_ServerID; } // tolua_export
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-19 13:31:43 -05:00
|
|
|
/** Called by cClientHandle's destructor; stop m_SocketThreads from calling back into a_Client */
|
|
|
|
void ClientDestroying(const cClientHandle * a_Client);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Don't tick a_Client anymore, it will be ticked from its cPlayer instead */
|
2013-08-12 02:35:13 -04:00
|
|
|
void ClientMovedToWorld(const cClientHandle * a_Client);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Notifies the server that a player was created; the server uses this to adjust the number of players */
|
2013-08-14 04:24:34 -04:00
|
|
|
void PlayerCreated(const cPlayer * a_Player);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Notifies the server that a player is being destroyed; the server uses this to adjust the number of players */
|
2013-08-14 13:11:54 -04:00
|
|
|
void PlayerDestroying(const cPlayer * a_Player);
|
2014-01-07 10:31:06 -05:00
|
|
|
|
2014-01-10 15:31:05 -05:00
|
|
|
/** Returns base64 encoded favicon data (obtained from favicon.png) */
|
2014-01-07 11:53:40 -05:00
|
|
|
const AString & GetFaviconData(void) const { return m_FaviconData; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 05:04:54 -04:00
|
|
|
cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
|
2014-01-23 17:35:23 -05:00
|
|
|
const AString & GetPublicKeyDER(void) const { return m_PublicKeyDER; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-07-11 07:13:10 -04:00
|
|
|
/** Returns true if authentication has been turned on in server settings. */
|
2014-08-20 16:21:41 -04:00
|
|
|
bool ShouldAuthenticate(void) const { return m_ShouldAuthenticate; } // tolua_export
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-05-19 10:09:01 -04:00
|
|
|
/** Returns true if limit for number of block changes per tick by a player has been turned on in server settings. */
|
|
|
|
bool ShouldLimitPlayerBlockChanges(void) const { return m_ShouldLimitPlayerBlockChanges; }
|
|
|
|
|
2014-07-11 07:13:10 -04:00
|
|
|
/** Returns true if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found.
|
|
|
|
Loaded from the settings.ini [PlayerData].LoadOfflinePlayerData setting. */
|
|
|
|
bool ShouldLoadOfflinePlayerData(void) const { return m_ShouldLoadOfflinePlayerData; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-07-11 07:13:10 -04:00
|
|
|
/** Returns true if old-style playernames should be used to load data for players whose regular datafiles cannot be found.
|
|
|
|
This allows a seamless transition from name-based to UUID-based player storage.
|
|
|
|
Loaded from the settings.ini [PlayerData].LoadNamedPlayerData setting. */
|
|
|
|
bool ShouldLoadNamedPlayerData(void) const { return m_ShouldLoadNamedPlayerData; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-09-17 14:55:46 -04:00
|
|
|
/** Returns true if BungeeCord logins (that specify the player's UUID) are allowed.
|
|
|
|
Read from settings, admins should set this to true only when they chain to BungeeCord,
|
|
|
|
it makes the server vulnerable to identity theft through direct connections. */
|
|
|
|
bool ShouldAllowBungeeCord(void) const { return m_ShouldAllowBungeeCord; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2016-07-21 07:00:30 -04:00
|
|
|
/** Returns true if usernames should be completed across worlds. This is read
|
|
|
|
from the settings. */
|
|
|
|
bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; }
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
|
|
|
|
2014-07-17 13:13:23 -04:00
|
|
|
friend class cRoot; // so cRoot can create and destroy cServer
|
2015-01-24 14:17:00 -05:00
|
|
|
friend class cServerListenCallbacks; // Accessing OnConnectionAccepted()
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** The server tick thread takes care of the players who aren't yet spawned in a world */
|
2013-08-11 13:46:27 -04:00
|
|
|
class cTickThread :
|
|
|
|
public cIsThread
|
|
|
|
{
|
|
|
|
typedef cIsThread super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:46:27 -04:00
|
|
|
public:
|
|
|
|
cTickThread(cServer & a_Server);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:46:27 -04:00
|
|
|
protected:
|
|
|
|
cServer & m_Server;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:46:27 -04:00
|
|
|
// cIsThread overrides:
|
|
|
|
virtual void Execute(void) override;
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
/** The network sockets listening for client connections. */
|
|
|
|
cServerHandlePtrs m_ServerHandles;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
/** Protects m_Clients and m_ClientsToRemove against multithreaded access. */
|
|
|
|
cCriticalSection m_CSClients;
|
|
|
|
|
|
|
|
/** Clients that are connected to the server and not yet assigned to a cWorld. */
|
|
|
|
cClientHandlePtrs m_Clients;
|
|
|
|
|
|
|
|
/** Clients that have just been moved into a world and are to be removed from m_Clients in the next Tick(). */
|
|
|
|
cClientHandles m_ClientsToRemove;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
/** Protects m_PlayerCount against multithreaded access. */
|
|
|
|
mutable cCriticalSection m_CSPlayerCount;
|
|
|
|
|
|
|
|
/** Number of players currently playing in the server. */
|
|
|
|
int m_PlayerCount;
|
|
|
|
|
|
|
|
/** Protects m_PlayerCountDiff against multithreaded access. */
|
|
|
|
cCriticalSection m_CSPlayerCountDiff;
|
|
|
|
|
|
|
|
/** Adjustment to m_PlayerCount to be applied in the Tick thread. */
|
|
|
|
int m_PlayerCountDiff;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
int m_ClientViewDistance; // The default view distance for clients; settable in Settings.ini
|
|
|
|
|
2014-07-17 13:13:23 -04:00
|
|
|
bool m_bIsConnected; // true - connected false - not connected
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2015-12-30 09:31:42 -05:00
|
|
|
std::atomic<bool> m_bRestarting;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-23 17:35:23 -05:00
|
|
|
/** The private key used for the assymetric encryption start in the protocols */
|
2014-04-29 05:04:54 -04:00
|
|
|
cRsaPrivateKey m_PrivateKey;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-23 17:35:23 -05:00
|
|
|
/** Public key for m_PrivateKey, ASN1-DER-encoded */
|
|
|
|
AString m_PublicKeyDER;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-06-27 11:14:20 -04:00
|
|
|
cRCONServer m_RCONServer;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:18:06 -04:00
|
|
|
AString m_Description;
|
2017-01-03 13:57:31 -05:00
|
|
|
AString m_ShutdownMessage;
|
2014-01-07 10:40:59 -05:00
|
|
|
AString m_FaviconData;
|
2013-08-11 13:18:06 -04:00
|
|
|
int m_MaxPlayers;
|
2013-11-04 16:51:24 -05:00
|
|
|
bool m_bIsHardcore;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-11-29 03:36:15 -05:00
|
|
|
/** True - allow same username to login more than once False - only once */
|
2014-12-11 08:34:09 -05:00
|
|
|
bool m_bAllowMultiLogin;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:46:27 -04:00
|
|
|
cTickThread m_TickThread;
|
|
|
|
cEvent m_RestartEvent;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** The server ID used for client authentication */
|
2013-08-11 13:46:27 -04:00
|
|
|
AString m_ServerID;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** If true, players will be online-authenticated agains Mojang servers.
|
|
|
|
This setting is the same as the "online-mode" setting in Vanilla. */
|
|
|
|
bool m_ShouldAuthenticate;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-05-19 10:09:01 -04:00
|
|
|
/** True if limit for number of block changes per tick by a player should be enabled. */
|
|
|
|
bool m_ShouldLimitPlayerBlockChanges;
|
|
|
|
|
2014-07-11 07:13:10 -04:00
|
|
|
/** True if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found.
|
|
|
|
This allows transitions from an offline (no-auth) server to an online one.
|
|
|
|
Loaded from the settings.ini [PlayerData].LoadOfflinePlayerData setting. */
|
|
|
|
bool m_ShouldLoadOfflinePlayerData;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-07-11 07:13:10 -04:00
|
|
|
/** True if old-style playernames should be used to load data for players whose regular datafiles cannot be found.
|
|
|
|
This allows a seamless transition from name-based to UUID-based player storage.
|
|
|
|
Loaded from the settings.ini [PlayerData].LoadNamedPlayerData setting. */
|
|
|
|
bool m_ShouldLoadNamedPlayerData;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-09-17 14:55:46 -04:00
|
|
|
/** True if BungeeCord handshake packets (with player UUID) should be accepted. */
|
|
|
|
bool m_ShouldAllowBungeeCord;
|
2014-07-11 07:13:10 -04:00
|
|
|
|
2016-07-21 07:00:30 -04:00
|
|
|
/** True if usernames should be completed across worlds. */
|
|
|
|
bool m_ShouldAllowMultiWorldTabCompletion;
|
|
|
|
|
2015-01-24 14:17:00 -05:00
|
|
|
/** The list of ports on which the server should listen for connections.
|
|
|
|
Initialized in InitServer(), used in Start(). */
|
|
|
|
AStringVector m_Ports;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-03-04 16:13:08 -05:00
|
|
|
cServer(void);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Loads, or generates, if missing, RSA keys for protocol encryption */
|
2012-08-30 17:06:13 -04:00
|
|
|
void PrepareKeys(void);
|
2015-01-24 14:17:00 -05:00
|
|
|
|
|
|
|
/** Creates a new cClientHandle instance and adds it to the list of clients.
|
|
|
|
Returns the cClientHandle reinterpreted as cTCPLink callbacks. */
|
|
|
|
cTCPLink::cCallbacksPtr OnConnectionAccepted(const AString & a_RemoteIPAddress);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-08-11 13:46:27 -04:00
|
|
|
bool Tick(float a_Dt);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-01-28 17:53:07 -05:00
|
|
|
/** Ticks the clients in m_Clients, manages the list in respect to removing clients */
|
2013-08-13 16:45:29 -04:00
|
|
|
void TickClients(float a_Dt);
|
2014-07-17 13:13:23 -04:00
|
|
|
}; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|