2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-04-13 07:04:56 -04:00
|
|
|
#include "Protocol/Authenticator.h"
|
2013-09-27 12:14:26 -04:00
|
|
|
#include "HTTPServer/HTTPServer.h"
|
2014-02-04 17:39:57 -05:00
|
|
|
#include "Defines.h"
|
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 cThread;
|
|
|
|
class cMonsterConfig;
|
|
|
|
class cGroupManager;
|
|
|
|
class cCraftingRecipes;
|
|
|
|
class cFurnaceRecipe;
|
|
|
|
class cWebAdmin;
|
|
|
|
class cPluginManager;
|
|
|
|
class cServer;
|
|
|
|
class cWorld;
|
|
|
|
class cPlayer;
|
2014-02-15 17:16:44 -05:00
|
|
|
class cCommandOutputCallback;
|
|
|
|
class cCompositeChat;
|
2013-06-29 11:30:05 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
typedef cItemCallback<cPlayer> cPlayerListCallback;
|
|
|
|
typedef cItemCallback<cWorld> cWorldListCallback;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
/// The root of the object hierarchy
|
2013-01-11 23:46:01 -05:00
|
|
|
class cRoot // tolua_export
|
|
|
|
{ // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-10-23 05:06:39 -04:00
|
|
|
static cRoot * Get() { return s_Root; } // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cRoot(void);
|
|
|
|
~cRoot();
|
|
|
|
|
|
|
|
void Start(void);
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
cServer * GetServer(void) { return m_Server; } // tolua_export
|
|
|
|
cWorld * GetDefaultWorld(void); // tolua_export
|
|
|
|
cWorld * GetWorld(const AString & a_WorldName); // tolua_export
|
2013-12-11 06:39:13 -05:00
|
|
|
cWorld * CreateAndInitializeWorld(const AString & a_WorldName); // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
/// Calls the callback for each world; returns true if the callback didn't abort (return true)
|
|
|
|
bool ForEachWorld(cWorldListCallback & a_Callback); // >> Exported in ManualBindings <<
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
/// Writes chunkstats, for each world and totals, to the output callback
|
|
|
|
void LogChunkStats(cCommandOutputCallback & a_Output);
|
2012-08-15 08:08:11 -04:00
|
|
|
|
2012-11-20 16:28:43 -05:00
|
|
|
int GetPrimaryServerVersion(void) const { return m_PrimaryServerVersion; } // tolua_export
|
|
|
|
void SetPrimaryServerVersion(int a_Version) { m_PrimaryServerVersion = a_Version; } // tolua_export
|
|
|
|
|
2013-10-23 05:06:39 -04:00
|
|
|
cMonsterConfig * GetMonsterConfig(void) { return m_MonsterConfig; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cGroupManager * GetGroupManager (void) { return m_GroupManager; } // tolua_export
|
|
|
|
cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export
|
2013-11-22 06:26:06 -05:00
|
|
|
cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // Exported in ManualBindings.cpp with quite a different signature
|
2013-11-22 10:50:03 -05:00
|
|
|
|
|
|
|
/// Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel
|
|
|
|
static int GetFurnaceFuelBurnTime(const cItem & a_Fuel); // tolua_export
|
|
|
|
|
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; }
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
|
/// Executes a console command through the cServer class; does special handling for "stop" and "restart".
|
|
|
|
void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
/// Kicks the user, no matter in what world they are. Used from cAuthenticator
|
|
|
|
void KickUser(int a_ClientID, const AString & a_Reason);
|
|
|
|
|
|
|
|
/// Called by cAuthenticator to auth the specified user
|
2014-04-13 07:04:56 -04:00
|
|
|
void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-11 14:16:41 -04:00
|
|
|
/// Executes commands queued in the command queue
|
|
|
|
void TickCommands(void);
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
/// Returns the number of chunks loaded
|
|
|
|
int GetTotalChunkCount(void); // tolua_export
|
|
|
|
|
|
|
|
/// Saves all chunks in all worlds
|
2013-02-15 08:00:59 -05:00
|
|
|
void SaveAllChunks(void); // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-02-05 12:10:08 -05:00
|
|
|
/// Reloads all the groups
|
|
|
|
void ReloadGroups(void); // tolua_export
|
2013-08-17 17:58:37 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
/// Calls the callback for each player in all worlds
|
2012-08-22 19:05:12 -04:00
|
|
|
bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
|
|
|
|
|
|
|
/// Finds a player from a partial or complete player name and calls the callback - case-insensitive
|
|
|
|
bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
2014-02-05 18:24:02 -05:00
|
|
|
|
2013-10-08 14:12:34 -04:00
|
|
|
// tolua_begin
|
|
|
|
|
2014-02-04 17:39:57 -05: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);
|
|
|
|
void BroadcastChatInfo (const AString & a_Message) { BroadcastChat(a_Message, mtInformation); }
|
|
|
|
void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(a_Message, mtFailure); }
|
|
|
|
void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(a_Message, mtSuccess); }
|
|
|
|
void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(a_Message, mtWarning); }
|
|
|
|
void BroadcastChatFatal (const AString & a_Message) { BroadcastChat(a_Message, mtFailure); }
|
|
|
|
void BroadcastChatJoin (const AString & a_Message) { BroadcastChat(a_Message, mtJoin); }
|
|
|
|
void BroadcastChatLeave (const AString & a_Message) { BroadcastChat(a_Message, mtLeave); }
|
|
|
|
void BroadcastChatDeath (const AString & a_Message) { BroadcastChat(a_Message, mtDeath); }
|
2014-02-15 17:16:44 -05:00
|
|
|
void BroadcastChat (const cCompositeChat & a_Message);
|
2014-02-04 17:39:57 -05:00
|
|
|
|
2013-02-15 08:00:59 -05: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);
|
|
|
|
|
|
|
|
/// Returns the amount of virtual RAM used, in KiB. Returns a negative number on error
|
|
|
|
static int GetVirtualRAMUsage(void);
|
|
|
|
|
|
|
|
/// Returns the amount of virtual RAM used, in KiB. Returns a negative number on error
|
|
|
|
static int GetPhysicalRAMUsage(void);
|
|
|
|
|
|
|
|
// tolua_end
|
2013-02-15 08:00:59 -05: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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AString m_Command;
|
|
|
|
cCommandOutputCallback * m_Output;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
typedef std::map<AString, cWorld *> WorldMap;
|
|
|
|
typedef std::vector<cCommand> cCommandQueue;
|
|
|
|
|
2013-10-23 05:06:39 -04:00
|
|
|
/// The version of the protocol that is primary for the server (reported in the server list). All versions are still supported.
|
|
|
|
int m_PrimaryServerVersion;
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
cWorld * m_pDefaultWorld;
|
2013-04-27 17:05:34 -04:00
|
|
|
WorldMap m_WorldsByName;
|
2012-07-15 16:07:38 -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
|
|
|
|
|
|
|
cThread * m_InputThread;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cServer * m_Server;
|
|
|
|
cMonsterConfig * m_MonsterConfig;
|
|
|
|
|
|
|
|
cGroupManager * m_GroupManager;
|
|
|
|
cCraftingRecipes * m_CraftingRecipes;
|
|
|
|
cFurnaceRecipe * m_FurnaceRecipe;
|
|
|
|
cWebAdmin * m_WebAdmin;
|
|
|
|
cPluginManager * m_PluginManager;
|
|
|
|
cAuthenticator m_Authenticator;
|
2013-09-27 12:14:26 -04:00
|
|
|
cHTTPServer m_HTTPServer;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cMCLogger * m_Log;
|
|
|
|
|
|
|
|
bool m_bStop;
|
|
|
|
bool m_bRestart;
|
|
|
|
|
2013-04-27 17:05:34 -04:00
|
|
|
void LoadGlobalSettings();
|
|
|
|
|
|
|
|
/// Loads the worlds from settings.ini, creates the worldmap
|
2013-10-26 13:47:12 -04:00
|
|
|
void LoadWorlds(cIniFile & IniFile);
|
2013-04-27 17:05:34 -04:00
|
|
|
|
|
|
|
/// Starts each world's life
|
|
|
|
void StartWorlds(void);
|
|
|
|
|
|
|
|
/// Stops each world's threads, so that it's safe to unload them
|
|
|
|
void StopWorlds(void);
|
|
|
|
|
|
|
|
/// Unloads all worlds from memory
|
|
|
|
void UnloadWorlds(void);
|
|
|
|
|
|
|
|
/// Does the actual work of executing a command
|
|
|
|
void DoExecuteConsoleCommand(const AString & a_Cmd);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
static void InputThread(void* a_Params);
|
2013-06-29 11:30:05 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
static cRoot* s_Root;
|
2013-01-11 23:46:01 -05:00
|
|
|
}; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|