Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
cRoot Class Reference

The root of the object hierarchy. More...

#include <Root.h>

Collaboration diagram for cRoot:
Collaboration graph
[legend]

Classes

class  cCommand
 

Public Member Functions

void AuthenticateUser (int a_ClientID, const AString &a_Name, const cUUID &a_UUID, const Json::Value &a_Properties)
 Called by cAuthenticator to auth the specified user. More...
 
void BroadcastChat (const AString &a_Message, eMessageType a_ChatPrefix=mtCustom)
 Sends a chat message to all connected clients (in all worlds) More...
 
void BroadcastChat (const cCompositeChat &a_Message)
 
void BroadcastChatDeath (const AString &a_Message)
 
void BroadcastChatFailure (const AString &a_Message)
 
void BroadcastChatFatal (const AString &a_Message)
 
void BroadcastChatInfo (const AString &a_Message)
 
void BroadcastChatJoin (const AString &a_Message)
 
void BroadcastChatLeave (const AString &a_Message)
 
void BroadcastChatSuccess (const AString &a_Message)
 
void BroadcastChatWarning (const AString &a_Message)
 
void BroadcastPlayerListsAddPlayer (const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr)
 Broadcast playerlist addition through all worlds. More...
 
void BroadcastPlayerListsRemovePlayer (const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr)
 Broadcast playerlist removal through all worlds. More...
 
 cRoot (void)
 
bool DoWithPlayer (const AString &a_PlayerName, cPlayerListCallback a_Callback)
 Finds the player using it's complete username and calls the callback. More...
 
bool DoWithPlayerByUUID (const cUUID &a_PlayerUUID, cPlayerListCallback a_Callback)
 Finds the player over his uuid and calls the callback. More...
 
void ExecuteConsoleCommand (const AString &a_Cmd, cCommandOutputCallback &a_Output)
 Executes a console command through the cServer class; does special handling for "stop" and "restart". More...
 
bool FindAndDoWithPlayer (const AString &a_PlayerName, cPlayerListCallback a_Callback)
 Finds a player from a partial or complete player name and calls the callback - case-insensitive. More...
 
bool ForEachPlayer (cPlayerListCallback a_Callback)
 Calls the callback for each player in all worlds. More...
 
bool ForEachWorld (cWorldListCallback a_Callback)
 Calls the callback for each world; returns true if the callback didn't abort (return true) More...
 
cAuthenticatorGetAuthenticator (void)
 
BlockTypeRegistryGetBlockTypeRegistry ()
 Returns the (read-write) storage for registered block types. More...
 
cBrewingRecipesGetBrewingRecipes (void)
 
cCraftingRecipesGetCraftingRecipes (void)
 
cWorldGetDefaultWorld (void)
 
cFurnaceRecipeGetFurnaceRecipe (void)
 
cMojangAPIGetMojangAPI (void)
 
cMonsterConfigGetMonsterConfig (void)
 
AStringVector GetPlayerTabCompletionMultiWorld (const AString &a_Text)
 Returns the completions for a player name across all worlds. More...
 
cPluginManagerGetPluginManager (void)
 
ProtocolPalettesGetProtocolPalettes () const
 Returns the per-protocol palettes manager. More...
 
cRankManagerGetRankManager (void)
 
cServerGetServer (void)
 
int GetServerUpTime (void)
 Returns the up time of the server in seconds. More...
 
int GetTotalChunkCount (void)
 Returns the number of chunks loaded. More...
 
const BlockTypePaletteGetUpgradeBlockTypePalette () const
 Returns the block type palette used for upgrading blocks from pre-1.13 data. More...
 
cWebAdminGetWebAdmin (void)
 
cWorldGetWorld (const AString &a_WorldName)
 Returns a pointer to the world specified. More...
 
void KickUser (int a_ClientID, const AString &a_Reason)
 Kicks the user, no matter in what world they are. More...
 
void LogChunkStats (cCommandOutputCallback &a_Output)
 Writes chunkstats, for each world and totals, to the output callback. More...
 
void QueueExecuteConsoleCommand (const AString &a_Cmd, cCommandOutputCallback &a_Output)
 Queues a console command for execution through the cServer class. More...
 
void QueueExecuteConsoleCommand (const AString &a_Cmd)
 Queues a console command for execution through the cServer class. More...
 
void SaveAllChunks (void)
 Saves all chunks in all worlds. More...
 
void SendPlayerLists (cPlayer *a_DestPlayer)
 Send playerlist of all worlds to player. More...
 
void SetSavingEnabled (bool a_SavingEnabled)
 Sets whether saving chunks is enabled in all worlds (overrides however the worlds were already set) More...
 
void Start (std::unique_ptr< cSettingsRepositoryInterface > a_OverridesRepo)
 
void StopServer ()
 Stops the server, as if "/stop" was typed in the console. More...
 
void TickCommands (void)
 Executes commands queued in the command queue. More...
 
 ~cRoot ()
 

Static Public Member Functions

static cRootGet ()
 
static int GetFurnaceFuelBurnTime (const cItem &a_Fuel)
 Returns the number of ticks for how long the item would fuel a furnace. More...
 
static int GetPhysicalRAMUsage (void)
 Returns the amount of virtual RAM used, in KiB. More...
 
static AString GetProtocolVersionTextFromInt (int a_ProtocolVersionNum)
 Returns the textual description of the protocol version: 49 -> "1.4.4". More...
 
static int GetVirtualRAMUsage (void)
 Returns the amount of virtual RAM used, in KiB. More...
 

Public Attributes

AString m_SettingsFilename
 which ini file to load settings from, default is settings.ini More...
 
std::chrono::steady_clock::time_point m_StartTime
 The current time where the startup of the server has been completed. More...
 

Static Public Attributes

static bool m_RunAsService = false
 If set to true, binary will attempt to run as a service on Windows. More...
 
static bool m_TerminateEventRaised = false
 If something has told the server to stop; checked periodically in cRoot. More...
 

Private Types

typedef std::vector< cCommandcCommandQueue
 
typedef std::map< AString, cWorld * > WorldMap
 

Private Member Functions

void DoExecuteConsoleCommand (const AString &a_Cmd)
 Does the actual work of executing a command. More...
 
void LoadGlobalSettings ()
 
void LoadPalettes (const AString &aProtocolFolder)
 Loads the upgrade palette and the per-protocol palettes. More...
 
void LoadWorlds (cDeadlockDetect &a_dd, cSettingsRepositoryInterface &a_Settings, bool a_IsNewIniFile)
 Loads the worlds from settings.ini, creates the worldmap. More...
 
void StartWorlds (cDeadlockDetect &a_DeadlockDetect)
 Starts each world's life. More...
 
void StopWorlds (cDeadlockDetect &a_DeadlockDetect)
 Stops each world's threads, so that it's safe to unload them. More...
 
void UnloadWorlds (void)
 Unloads all worlds from memory. More...
 

Static Private Member Functions

static void InputThread (cRoot &a_Params)
 

Private Attributes

cAuthenticator m_Authenticator
 
BlockTypeRegistry m_BlockTypeRegistry
 The storage for all registered block types. More...
 
std::unique_ptr< cBrewingRecipesm_BrewingRecipes
 
cCraftingRecipesm_CraftingRecipes
 
cCriticalSection m_CSPendingCommands
 
cFurnaceRecipem_FurnaceRecipe
 
cHTTPServer m_HTTPServer
 
std::thread m_InputThread
 
std::atomic_flag m_InputThreadRunFlag
 
cMojangAPIm_MojangAPI
 
cMonsterConfigm_MonsterConfig
 
cWorldm_pDefaultWorld
 
cCommandQueue m_PendingCommands
 
cPluginManagerm_PluginManager
 
std::unique_ptr< ProtocolPalettesm_ProtocolPalettes
 The per-protocol palettes manager. More...
 
std::unique_ptr< cRankManagerm_RankManager
 
cServerm_Server
 
cEvent m_StopEvent
 
std::unique_ptr< BlockTypePalettem_UpgradeBlockTypePalette
 The upgrade palette for pre-1.13 blocks. More...
 
cWebAdminm_WebAdmin
 
WorldMap m_WorldsByName
 

Static Private Attributes

static cRoots_Root = nullptr
 

Detailed Description

The root of the object hierarchy.

Definition at line 48 of file Root.h.

Member Typedef Documentation

typedef std::vector<cCommand> cRoot::cCommandQueue
private

Definition at line 215 of file Root.h.

typedef std::map<AString, cWorld *> cRoot::WorldMap
private

Definition at line 214 of file Root.h.

Constructor & Destructor Documentation

cRoot::cRoot ( void  )

Definition at line 55 of file Root.cpp.

cRoot::~cRoot ( )

Definition at line 75 of file Root.cpp.

Member Function Documentation

void cRoot::AuthenticateUser ( int  a_ClientID,
const AString a_Name,
const cUUID a_UUID,
const Json::Value &  a_Properties 
)

Called by cAuthenticator to auth the specified user.

Definition at line 747 of file Root.cpp.

void cRoot::BroadcastChat ( const AString a_Message,
eMessageType  a_ChatPrefix = mtCustom 
)

Sends a chat message to all connected clients (in all worlds)

Definition at line 830 of file Root.cpp.

void cRoot::BroadcastChat ( const cCompositeChat a_Message)

Definition at line 842 of file Root.cpp.

void cRoot::BroadcastChatDeath ( const AString a_Message)
inline

Definition at line 180 of file Root.h.

void cRoot::BroadcastChatFailure ( const AString a_Message)
inline

Definition at line 181 of file Root.h.

void cRoot::BroadcastChatFatal ( const AString a_Message)
inline

Definition at line 182 of file Root.h.

void cRoot::BroadcastChatInfo ( const AString a_Message)
inline

Definition at line 183 of file Root.h.

void cRoot::BroadcastChatJoin ( const AString a_Message)
inline

Definition at line 184 of file Root.h.

void cRoot::BroadcastChatLeave ( const AString a_Message)
inline

Definition at line 185 of file Root.h.

void cRoot::BroadcastChatSuccess ( const AString a_Message)
inline

Definition at line 186 of file Root.h.

void cRoot::BroadcastChatWarning ( const AString a_Message)
inline

Definition at line 187 of file Root.h.

void cRoot::BroadcastPlayerListsAddPlayer ( const cPlayer a_Player,
const cClientHandle a_Exclude = nullptr 
)

Broadcast playerlist addition through all worlds.

Definition at line 806 of file Root.cpp.

void cRoot::BroadcastPlayerListsRemovePlayer ( const cPlayer a_Player,
const cClientHandle a_Exclude = nullptr 
)

Broadcast playerlist removal through all worlds.

Definition at line 818 of file Root.cpp.

void cRoot::DoExecuteConsoleCommand ( const AString a_Cmd)
private

Does the actual work of executing a command.

bool cRoot::DoWithPlayer ( const AString a_PlayerName,
cPlayerListCallback  a_Callback 
)

Finds the player using it's complete username and calls the callback.

Definition at line 941 of file Root.cpp.

bool cRoot::DoWithPlayerByUUID ( const cUUID a_PlayerUUID,
cPlayerListCallback  a_Callback 
)

Finds the player over his uuid and calls the callback.

Definition at line 925 of file Root.cpp.

void cRoot::ExecuteConsoleCommand ( const AString a_Cmd,
cCommandOutputCallback a_Output 
)

Executes a console command through the cServer class; does special handling for "stop" and "restart".

Definition at line 715 of file Root.cpp.

bool cRoot::FindAndDoWithPlayer ( const AString a_PlayerName,
cPlayerListCallback  a_Callback 
)

Finds a player from a partial or complete player name and calls the callback - case-insensitive.

Definition at line 871 of file Root.cpp.

bool cRoot::ForEachPlayer ( cPlayerListCallback  a_Callback)

Calls the callback for each player in all worlds.

Definition at line 854 of file Root.cpp.

bool cRoot::ForEachWorld ( cWorldListCallback  a_Callback)

Calls the callback for each world; returns true if the callback didn't abort (return true)

Definition at line 656 of file Root.cpp.

static cRoot* cRoot::Get ( void  )
inlinestatic

Definition at line 51 of file Root.h.

cAuthenticator& cRoot::GetAuthenticator ( void  )
inline

Definition at line 115 of file Root.h.

BlockTypeRegistry& cRoot::GetBlockTypeRegistry ( )
inline

Returns the (read-write) storage for registered block types.

Definition at line 95 of file Root.h.

cBrewingRecipes* cRoot::GetBrewingRecipes ( void  )
inline

Definition at line 92 of file Root.h.

cCraftingRecipes* cRoot::GetCraftingRecipes ( void  )
inline

Definition at line 90 of file Root.h.

cWorld * cRoot::GetDefaultWorld ( void  )

Definition at line 632 of file Root.cpp.

int cRoot::GetFurnaceFuelBurnTime ( const cItem a_Fuel)
static

Returns the number of ticks for how long the item would fuel a furnace.

Returns zero if not a fuel

Definition at line 1120 of file Root.cpp.

cFurnaceRecipe* cRoot::GetFurnaceRecipe ( void  )
inline

Definition at line 91 of file Root.h.

cMojangAPI& cRoot::GetMojangAPI ( void  )
inline

Definition at line 116 of file Root.h.

cMonsterConfig* cRoot::GetMonsterConfig ( void  )
inline

Definition at line 88 of file Root.h.

int cRoot::GetPhysicalRAMUsage ( void  )
static

Returns the amount of virtual RAM used, in KiB.

Returns a negative number on error

Definition at line 1018 of file Root.cpp.

AStringVector cRoot::GetPlayerTabCompletionMultiWorld ( const AString a_Text)

Returns the completions for a player name across all worlds.

Returns an empty vector if none are found.

Definition at line 1130 of file Root.cpp.

cPluginManager* cRoot::GetPluginManager ( void  )
inline

Definition at line 114 of file Root.h.

ProtocolPalettes& cRoot::GetProtocolPalettes ( ) const
inline

Returns the per-protocol palettes manager.

Definition at line 101 of file Root.h.

AString cRoot::GetProtocolVersionTextFromInt ( int  a_ProtocolVersionNum)
static

Returns the textual description of the protocol version: 49 -> "1.4.4".

Provided specifically for Lua API

Definition at line 957 of file Root.cpp.

cRankManager* cRoot::GetRankManager ( void  )
inline

Definition at line 117 of file Root.h.

cServer* cRoot::GetServer ( void  )
inline

Definition at line 69 of file Root.h.

int cRoot::GetServerUpTime ( void  )
inline

Returns the up time of the server in seconds.

Definition at line 76 of file Root.h.

int cRoot::GetTotalChunkCount ( void  )

Returns the number of chunks loaded.

Definition at line 756 of file Root.cpp.

const BlockTypePalette& cRoot::GetUpgradeBlockTypePalette ( ) const
inline

Returns the block type palette used for upgrading blocks from pre-1.13 data.

Definition at line 98 of file Root.h.

int cRoot::GetVirtualRAMUsage ( void  )
static

Returns the amount of virtual RAM used, in KiB.

Returns a negative number on error

Definition at line 966 of file Root.cpp.

cWebAdmin* cRoot::GetWebAdmin ( void  )
inline

Definition at line 113 of file Root.h.

cWorld * cRoot::GetWorld ( const AString a_WorldName)

Returns a pointer to the world specified.

If no world of that name exists, returns a nullptr.

Definition at line 641 of file Root.cpp.

void cRoot::InputThread ( cRoot a_Params)
staticprivate

Definition at line 84 of file Root.cpp.

void cRoot::KickUser ( int  a_ClientID,
const AString a_Reason 
)

Kicks the user, no matter in what world they are.

Used from cAuthenticator

Definition at line 738 of file Root.cpp.

void cRoot::LoadGlobalSettings ( )
private

Definition at line 395 of file Root.cpp.

void cRoot::LoadPalettes ( const AString aProtocolFolder)
private

Loads the upgrade palette and the per-protocol palettes.

The aProtocolFolder is the path to the folder containing the per-protocol palettes.

Definition at line 404 of file Root.cpp.

void cRoot::LoadWorlds ( cDeadlockDetect a_dd,
cSettingsRepositoryInterface a_Settings,
bool  a_IsNewIniFile 
)
private

Loads the worlds from settings.ini, creates the worldmap.

Definition at line 446 of file Root.cpp.

void cRoot::LogChunkStats ( cCommandOutputCallback a_Output)

Writes chunkstats, for each world and totals, to the output callback.

Definition at line 1070 of file Root.cpp.

void cRoot::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 written to the a_Output callback "stop" and "restart" commands have special handling.

Definition at line 693 of file Root.cpp.

void cRoot::QueueExecuteConsoleCommand ( const AString a_Cmd)

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.

Definition at line 704 of file Root.cpp.

void cRoot::SaveAllChunks ( void  )

Saves all chunks in all worlds.

Definition at line 770 of file Root.cpp.

void cRoot::SendPlayerLists ( cPlayer a_DestPlayer)

Send playerlist of all worlds to player.

Definition at line 794 of file Root.cpp.

void cRoot::SetSavingEnabled ( bool  a_SavingEnabled)

Sets whether saving chunks is enabled in all worlds (overrides however the worlds were already set)

Definition at line 782 of file Root.cpp.

void cRoot::Start ( std::unique_ptr< cSettingsRepositoryInterface a_OverridesRepo)

Definition at line 134 of file Root.cpp.

void cRoot::StartWorlds ( cDeadlockDetect a_DeadlockDetect)
private

Starts each world's life.

Definition at line 592 of file Root.cpp.

void cRoot::StopServer ( )

Stops the server, as if "/stop" was typed in the console.

Definition at line 370 of file Root.cpp.

void cRoot::StopWorlds ( cDeadlockDetect a_DeadlockDetect)
private

Stops each world's threads, so that it's safe to unload them.

Definition at line 606 of file Root.cpp.

void cRoot::TickCommands ( void  )

Executes commands queued in the command queue.

Definition at line 675 of file Root.cpp.

void cRoot::UnloadWorlds ( void  )
private

Unloads all worlds from memory.

Definition at line 618 of file Root.cpp.

Member Data Documentation

cAuthenticator cRoot::m_Authenticator
private

Definition at line 235 of file Root.h.

BlockTypeRegistry cRoot::m_BlockTypeRegistry
private

The storage for all registered block types.

Definition at line 243 of file Root.h.

std::unique_ptr<cBrewingRecipes> cRoot::m_BrewingRecipes
private

Definition at line 232 of file Root.h.

cCraftingRecipes* cRoot::m_CraftingRecipes
private

Definition at line 230 of file Root.h.

cCriticalSection cRoot::m_CSPendingCommands
private

Definition at line 220 of file Root.h.

cFurnaceRecipe* cRoot::m_FurnaceRecipe
private

Definition at line 231 of file Root.h.

cHTTPServer cRoot::m_HTTPServer
private

Definition at line 240 of file Root.h.

std::thread cRoot::m_InputThread
private

Definition at line 223 of file Root.h.

std::atomic_flag cRoot::m_InputThreadRunFlag
private

Definition at line 225 of file Root.h.

cMojangAPI* cRoot::m_MojangAPI
private

Definition at line 236 of file Root.h.

cMonsterConfig* cRoot::m_MonsterConfig
private

Definition at line 228 of file Root.h.

cWorld* cRoot::m_pDefaultWorld
private

Definition at line 217 of file Root.h.

cCommandQueue cRoot::m_PendingCommands
private

Definition at line 221 of file Root.h.

cPluginManager* cRoot::m_PluginManager
private

Definition at line 234 of file Root.h.

std::unique_ptr<ProtocolPalettes> cRoot::m_ProtocolPalettes
private

The per-protocol palettes manager.

Definition at line 249 of file Root.h.

std::unique_ptr<cRankManager> cRoot::m_RankManager
private

Definition at line 238 of file Root.h.

bool cRoot::m_RunAsService = false
static

If set to true, binary will attempt to run as a service on Windows.

Definition at line 55 of file Root.h.

cServer* cRoot::m_Server
private

Definition at line 227 of file Root.h.

AString cRoot::m_SettingsFilename

which ini file to load settings from, default is settings.ini

Definition at line 58 of file Root.h.

std::chrono::steady_clock::time_point cRoot::m_StartTime

The current time where the startup of the server has been completed.

Definition at line 111 of file Root.h.

cEvent cRoot::m_StopEvent
private

Definition at line 224 of file Root.h.

bool cRoot::m_TerminateEventRaised = false
static

If something has told the server to stop; checked periodically in cRoot.

Definition at line 54 of file Root.h.

std::unique_ptr<BlockTypePalette> cRoot::m_UpgradeBlockTypePalette
private

The upgrade palette for pre-1.13 blocks.

Definition at line 246 of file Root.h.

cWebAdmin* cRoot::m_WebAdmin
private

Definition at line 233 of file Root.h.

WorldMap cRoot::m_WorldsByName
private

Definition at line 218 of file Root.h.

cRoot * cRoot::s_Root = nullptr
staticprivate

Definition at line 273 of file Root.h.


The documentation for this class was generated from the following files: