2017-09-02 03:45:06 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
2020-07-14 12:57:30 -04:00
|
|
|
#include "BlockTypeRegistry.h"
|
2014-02-04 17:39:57 -05:00
|
|
|
#include "Defines.h"
|
2017-09-11 17:20:49 -04:00
|
|
|
#include "FunctionRef.h"
|
2020-07-14 12:57:30 -04:00
|
|
|
#include "HTTP/HTTPServer.h"
|
|
|
|
#include "Protocol/Authenticator.h"
|
|
|
|
#include "Protocol/MojangAPI.h"
|
2014-08-08 17:12:22 -04:00
|
|
|
#include "RankManager.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
// fwd:
|
2020-04-03 02:57:01 -04:00
|
|
|
class cItem;
|
2012-06-14 09:06:06 -04:00
|
|
|
class cMonsterConfig;
|
2015-09-24 04:48:33 -04:00
|
|
|
class cBrewingRecipes;
|
2012-06-14 09:06:06 -04:00
|
|
|
class cCraftingRecipes;
|
2020-07-14 12:56:42 -04:00
|
|
|
class cRecipeMapper;
|
2012-06-14 09:06:06 -04:00
|
|
|
class cFurnaceRecipe;
|
|
|
|
class cWebAdmin;
|
|
|
|
class cPluginManager;
|
|
|
|
class cServer;
|
|
|
|
class cWorld;
|
|
|
|
class cPlayer;
|
2014-02-15 17:16:44 -05:00
|
|
|
class cCommandOutputCallback;
|
|
|
|
class cCompositeChat;
|
2015-05-14 10:47:51 -04:00
|
|
|
class cSettingsRepositoryInterface;
|
2017-01-17 16:38:04 -05:00
|
|
|
class cDeadlockDetect;
|
2017-08-25 08:43:18 -04:00
|
|
|
class cUUID;
|
2020-01-02 09:11:49 -05:00
|
|
|
class BlockTypePalette;
|
2020-01-03 11:31:13 -05:00
|
|
|
class ProtocolPalettes;
|
2013-06-29 11:30:05 -04:00
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
using cPlayerListCallback = cFunctionRef<bool(cPlayer &)>;
|
|
|
|
using cWorldListCallback = cFunctionRef<bool(cWorld &)>;
|
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-06-11 16:20:04 -04:00
|
|
|
/** The root of the object hierarchy */
|
2014-07-17 10:33:09 -04:00
|
|
|
// tolua_begin
|
|
|
|
class cRoot
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2014-07-17 10:33:09 -04:00
|
|
|
static cRoot * Get() { return s_Root; }
|
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-01 11:28:45 -04:00
|
|
|
static bool m_TerminateEventRaised;
|
2015-03-31 09:50:03 -04:00
|
|
|
static bool m_RunAsService;
|
2014-10-01 11:28:45 -04:00
|
|
|
|
2017-02-22 08:10:32 -05:00
|
|
|
/** which ini file to load settings from, default is settings.ini */
|
|
|
|
AString m_SettingsFilename;
|
2014-10-01 11:28:45 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cRoot(void);
|
|
|
|
~cRoot();
|
|
|
|
|
2015-06-17 10:38:00 -04:00
|
|
|
void Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2016-02-04 09:06:37 -05:00
|
|
|
/** Stops the server, as if "/stop" was typed in the console. */
|
|
|
|
void StopServer();
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
// tolua_begin
|
|
|
|
cServer * GetServer(void) { return m_Server; }
|
|
|
|
cWorld * GetDefaultWorld(void);
|
2014-07-20 05:46:45 -04:00
|
|
|
|
2016-02-08 05:06:14 -05:00
|
|
|
/** Returns a pointer to the world specified. If no world of that name exists, returns a nullptr. */
|
|
|
|
cWorld * GetWorld(const AString & a_WorldName);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
|
|
|
/** Returns the up time of the server in seconds */
|
|
|
|
int GetServerUpTime(void)
|
|
|
|
{
|
|
|
|
return static_cast<int>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - m_StartTime).count());
|
|
|
|
}
|
2014-07-17 10:33:09 -04:00
|
|
|
// tolua_end
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Calls the callback for each world; returns true if the callback didn't abort (return true) */
|
2017-09-11 17:20:49 -04:00
|
|
|
bool ForEachWorld(cWorldListCallback a_Callback); // >> Exported in ManualBindings <<
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Writes chunkstats, for each world and totals, to the output callback */
|
2013-06-29 11:30:05 -04:00
|
|
|
void LogChunkStats(cCommandOutputCallback & a_Output);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2013-10-23 05:06:39 -04:00
|
|
|
cMonsterConfig * GetMonsterConfig(void) { return m_MonsterConfig; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export
|
2020-07-14 12:56:42 -04:00
|
|
|
cRecipeMapper * GetRecipeMapper(void) { return m_RecipeMapper.get(); }
|
2013-11-22 06:26:06 -05:00
|
|
|
cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // Exported in ManualBindings.cpp with quite a different signature
|
2015-09-24 04:48:33 -04:00
|
|
|
cBrewingRecipes * GetBrewingRecipes (void) { return m_BrewingRecipes.get(); } // Exported in ManualBindings.cpp
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2019-08-04 19:43:54 -04:00
|
|
|
/** Returns the (read-write) storage for registered block types. */
|
|
|
|
BlockTypeRegistry & GetBlockTypeRegistry() { return m_BlockTypeRegistry; }
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel */
|
2013-11-22 10:50:03 -05:00
|
|
|
static int GetFurnaceFuelBurnTime(const cItem & a_Fuel); // tolua_export
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2016-07-21 07:00:30 -04:00
|
|
|
/** Returns the completions for a player name across all worlds. Returns an
|
|
|
|
empty vector if none are found. */
|
|
|
|
AStringVector GetPlayerTabCompletionMultiWorld(const AString & a_Text);
|
|
|
|
|
2015-05-25 23:36:46 -04:00
|
|
|
/** The current time where the startup of the server has been completed */
|
|
|
|
std::chrono::steady_clock::time_point m_StartTime;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export
|
|
|
|
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
|
|
|
|
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
|
2014-12-21 09:31:20 -05:00
|
|
|
cMojangAPI & GetMojangAPI (void) { return *m_MojangAPI; }
|
2014-11-26 05:00:46 -05:00
|
|
|
cRankManager * GetRankManager (void) { return m_RankManager.get(); }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
/** Queues a console command for execution through the cServer class.
|
|
|
|
The command will be executed in the tick thread
|
|
|
|
The command's output will be written to the a_Output callback
|
|
|
|
"stop" and "restart" commands have special handling.
|
|
|
|
*/
|
|
|
|
void QueueExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
/** Queues a console command for execution through the cServer class.
|
|
|
|
The command will be executed in the tick thread
|
|
|
|
The command's output will be sent to console
|
|
|
|
"stop" and "restart" commands have special handling.
|
|
|
|
*/
|
|
|
|
void QueueExecuteConsoleCommand(const AString & a_Cmd); // tolua_export
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Executes a console command through the cServer class; does special handling for "stop" and "restart". */
|
2013-06-29 11:30:05 -04:00
|
|
|
void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Kicks the user, no matter in what world they are. Used from cAuthenticator */
|
2013-02-15 08:00:59 -05:00
|
|
|
void KickUser(int a_ClientID, const AString & a_Reason);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Called by cAuthenticator to auth the specified user */
|
2017-08-25 08:43:18 -04:00
|
|
|
void AuthenticateUser(int a_ClientID, const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Executes commands queued in the command queue */
|
2013-08-11 14:16:41 -04:00
|
|
|
void TickCommands(void);
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns the number of chunks loaded */
|
2020-07-14 12:57:30 -04:00
|
|
|
size_t GetTotalChunkCount(void); // tolua_export
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Saves all chunks in all worlds */
|
2013-02-15 08:00:59 -05:00
|
|
|
void SaveAllChunks(void); // tolua_export
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2017-09-07 08:41:16 -04:00
|
|
|
/** Sets whether saving chunks is enabled in all worlds (overrides however the worlds were already set) */
|
|
|
|
void SetSavingEnabled(bool a_SavingEnabled); // tolua_export
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Calls the callback for each player in all worlds */
|
2017-09-11 17:20:49 -04:00
|
|
|
bool ForEachPlayer(cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
2012-08-22 19:05:12 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Finds a player from a partial or complete player name and calls the callback - case-insensitive */
|
2017-09-11 17:20:49 -04:00
|
|
|
bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
2014-02-05 18:24:02 -05:00
|
|
|
|
2014-11-05 15:57:38 -05:00
|
|
|
/** Finds the player over his uuid and calls the callback */
|
2017-09-11 17:20:49 -04:00
|
|
|
bool DoWithPlayerByUUID(const cUUID & a_PlayerUUID, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2014-12-08 17:33:59 -05:00
|
|
|
/** Finds the player using it's complete username and calls the callback */
|
2017-09-11 17:20:49 -04:00
|
|
|
bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback a_Callback);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-05-28 16:17:21 -04:00
|
|
|
/** Send playerlist of all worlds to player */
|
|
|
|
void SendPlayerLists(cPlayer * a_DestPlayer);
|
|
|
|
|
2018-04-02 13:39:54 -04:00
|
|
|
/** Broadcast playerlist addition through all worlds */
|
2015-05-28 16:17:21 -04:00
|
|
|
void BroadcastPlayerListsAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
|
|
|
|
|
2018-04-02 13:39:54 -04:00
|
|
|
/** Broadcast playerlist removal through all worlds */
|
|
|
|
void BroadcastPlayerListsRemovePlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
|
|
|
|
|
2013-10-08 14:12:34 -04:00
|
|
|
// tolua_begin
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Sends a chat message to all connected clients (in all worlds) */
|
2014-02-15 17:26:19 -05:00
|
|
|
void BroadcastChat (const AString & a_Message, eMessageType a_ChatPrefix = mtCustom);
|
2014-10-01 06:44:28 -04:00
|
|
|
void BroadcastChat (const cCompositeChat & a_Message);
|
|
|
|
void BroadcastChatDeath (const AString & a_Message) { BroadcastChat(a_Message, mtDeath); }
|
2014-02-15 17:26:19 -05:00
|
|
|
void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(a_Message, mtFailure); }
|
|
|
|
void BroadcastChatFatal (const AString & a_Message) { BroadcastChat(a_Message, mtFailure); }
|
2014-10-01 06:44:28 -04:00
|
|
|
void BroadcastChatInfo (const AString & a_Message) { BroadcastChat(a_Message, mtInformation); }
|
2014-02-15 17:26:19 -05:00
|
|
|
void BroadcastChatJoin (const AString & a_Message) { BroadcastChat(a_Message, mtJoin); }
|
|
|
|
void BroadcastChatLeave (const AString & a_Message) { BroadcastChat(a_Message, mtLeave); }
|
2014-10-01 06:44:28 -04:00
|
|
|
void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(a_Message, mtSuccess); }
|
|
|
|
void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(a_Message, mtWarning); }
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API */
|
2013-10-08 14:12:34 -04:00
|
|
|
static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns the amount of virtual RAM used, in KiB. Returns a negative number on error */
|
2013-10-08 14:12:34 -04:00
|
|
|
static int GetVirtualRAMUsage(void);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns the amount of virtual RAM used, in KiB. Returns a negative number on error */
|
2013-10-08 14:12:34 -04:00
|
|
|
static int GetPhysicalRAMUsage(void);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2013-10-08 14:12:34 -04:00
|
|
|
// tolua_end
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
2013-06-29 11:30:05 -04:00
|
|
|
class cCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cCommand(const AString & a_Command, cCommandOutputCallback * a_Output) :
|
|
|
|
m_Command(a_Command),
|
|
|
|
m_Output(a_Output)
|
|
|
|
{
|
|
|
|
}
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
AString m_Command;
|
|
|
|
cCommandOutputCallback * m_Output;
|
|
|
|
} ;
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2020-07-14 12:57:30 -04:00
|
|
|
typedef std::map<AString, cWorld> WorldMap;
|
2013-06-29 11:30:05 -04:00
|
|
|
typedef std::vector<cCommand> cCommandQueue;
|
2013-10-23 05:06:39 -04:00
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
cWorld * m_pDefaultWorld;
|
2013-04-27 17:05:34 -04:00
|
|
|
WorldMap m_WorldsByName;
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2013-04-27 17:05:34 -04:00
|
|
|
cCriticalSection m_CSPendingCommands;
|
2013-06-29 11:30:05 -04:00
|
|
|
cCommandQueue m_PendingCommands;
|
2013-04-27 17:05:34 -04:00
|
|
|
|
2014-10-18 19:29:34 -04:00
|
|
|
std::thread m_InputThread;
|
2015-06-17 10:38:00 -04:00
|
|
|
cEvent m_StopEvent;
|
|
|
|
std::atomic_flag m_InputThreadRunFlag;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cServer * m_Server;
|
|
|
|
cMonsterConfig * m_MonsterConfig;
|
|
|
|
|
|
|
|
cCraftingRecipes * m_CraftingRecipes;
|
2020-07-14 12:56:42 -04:00
|
|
|
std::unique_ptr<cRecipeMapper> m_RecipeMapper;
|
2012-06-14 09:06:06 -04:00
|
|
|
cFurnaceRecipe * m_FurnaceRecipe;
|
2015-09-24 04:48:33 -04:00
|
|
|
std::unique_ptr<cBrewingRecipes> m_BrewingRecipes;
|
2012-06-14 09:06:06 -04:00
|
|
|
cWebAdmin * m_WebAdmin;
|
|
|
|
cPluginManager * m_PluginManager;
|
|
|
|
cAuthenticator m_Authenticator;
|
2014-12-21 09:31:20 -05:00
|
|
|
cMojangAPI * m_MojangAPI;
|
2014-11-26 05:00:46 -05:00
|
|
|
|
|
|
|
std::unique_ptr<cRankManager> m_RankManager;
|
|
|
|
|
2015-06-17 10:38:00 -04:00
|
|
|
cHTTPServer m_HTTPServer;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2019-08-04 19:43:54 -04:00
|
|
|
/** The storage for all registered block types. */
|
|
|
|
BlockTypeRegistry m_BlockTypeRegistry;
|
|
|
|
|
2015-06-11 16:20:04 -04:00
|
|
|
|
2013-04-27 17:05:34 -04:00
|
|
|
void LoadGlobalSettings();
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Loads the worlds from settings.ini, creates the worldmap */
|
2017-09-22 11:55:42 -04:00
|
|
|
void LoadWorlds(cDeadlockDetect & a_dd, cSettingsRepositoryInterface & a_Settings, bool a_IsNewIniFile);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Starts each world's life */
|
2017-01-17 16:38:04 -05:00
|
|
|
void StartWorlds(cDeadlockDetect & a_DeadlockDetect);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Stops each world's threads, so that it's safe to unload them */
|
2017-01-17 16:38:04 -05:00
|
|
|
void StopWorlds(cDeadlockDetect & a_DeadlockDetect);
|
2015-05-25 23:36:46 -04:00
|
|
|
|
2015-05-09 05:16:56 -04:00
|
|
|
static cRoot * s_Root;
|
2014-10-18 19:29:34 -04:00
|
|
|
|
2014-10-19 09:10:18 -04:00
|
|
|
static void InputThread(cRoot & a_Params);
|
2014-07-17 10:33:09 -04:00
|
|
|
}; // tolua_export
|