Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | 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]

Public Member Functions

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 BroadcastPlayerListsHeaderFooter (const cCompositeChat &a_Header, const cCompositeChat &a_Footer)
 Broadcast playerlist header and footer 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...
 
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)
 
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)
 
cRankManagerGetRankManager (void)
 
cRecipeMapperGetRecipeMapper (void)
 
cServerGetServer (void)
 
int GetServerUpTime (void)
 Returns the up time of the server in seconds. More...
 
size_t GetTotalChunkCount (void)
 Returns the number of chunks loaded. 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)
 Queues a console command for execution through the cServer class. More...
 
void QueueExecuteConsoleCommand (const AString &a_Cmd, cCommandOutputCallback &a_Output)
 Queues a console command for execution through the cServer class. More...
 
bool Run (cSettingsRepositoryInterface &a_OverridesRepo)
 Run the server. More...
 
void SaveAllChunks (void)
 Saves all chunks in all worlds. More...
 
void SaveAllChunksNow (void)
 Saves all chunks in all worlds synchronously (waits until dirty chunks have been sent to the ChunkStorage queue before returning) 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...
 
 ~cRoot ()
 

Static Public Member Functions

static cRootGet ()
 
static int GetFurnaceFuelBurnTime (const cItem &a_Fuel)
 Returns the (read-write) storage for registered block types. 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...
 
static void Restart ()
 Interrupts the server and restarts it, as if "/restart" was typed in the console. More...
 
static void Stop ()
 Interrupts the server and stops it, as if "/stop" typed in the console. 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...
 

Private Types

enum class  NextState { Run , Restart , Stop }
 States that the global cRoot can be in. More...
 
typedef std::map< AString, cWorldWorldMap
 

Private Member Functions

void HandleInput ()
 Blocking reads and processes console input. More...
 
void LoadGlobalSettings ()
 The storage for all registered block types. 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...
 

Static Private Member Functions

static void TransitionNextState (NextState a_NextState)
 Performs run state transition, enforcing guarantees about state transitions. More...
 

Private Attributes

cAuthenticator m_Authenticator
 
std::unique_ptr< cBrewingRecipesm_BrewingRecipes
 
cCraftingRecipesm_CraftingRecipes
 
cFurnaceRecipem_FurnaceRecipe
 
cHTTPServer m_HTTPServer
 
cMojangAPIm_MojangAPI
 
cMonsterConfigm_MonsterConfig
 
cWorldm_pDefaultWorld
 
cPluginManagerm_PluginManager
 
std::unique_ptr< cRankManagerm_RankManager
 
std::unique_ptr< cRecipeMapperm_RecipeMapper
 
cServerm_Server
 
cWebAdminm_WebAdmin
 
WorldMap m_WorldsByName
 

Static Private Attributes

static std::atomic< NextStates_NextState
 Indicates the next action of cRoot, whether to run, stop or restart. More...
 
static cRoots_Root
 
static cEvent s_StopEvent
 

Detailed Description

The root of the object hierarchy.

Definition at line 49 of file Root.h.

Member Typedef Documentation

◆ WorldMap

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

Definition at line 205 of file Root.h.

Member Enumeration Documentation

◆ NextState

enum cRoot::NextState
strongprivate

States that the global cRoot can be in.

You can transition freely between Run and Restart, but the server unconditionally terminates in Stop.

Enumerator
Run 
Restart 
Stop 

Definition at line 198 of file Root.h.

Constructor & Destructor Documentation

◆ cRoot()

cRoot::cRoot ( void  )

Definition at line 75 of file Root.cpp.

◆ ~cRoot()

cRoot::~cRoot ( )

Definition at line 94 of file Root.cpp.

Member Function Documentation

◆ BroadcastChat() [1/2]

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 657 of file Root.cpp.

◆ BroadcastChat() [2/2]

void cRoot::BroadcastChat ( const cCompositeChat a_Message)

Definition at line 669 of file Root.cpp.

◆ BroadcastChatDeath()

void cRoot::BroadcastChatDeath ( const AString a_Message)
inline

Definition at line 174 of file Root.h.

◆ BroadcastChatFailure()

void cRoot::BroadcastChatFailure ( const AString a_Message)
inline

Definition at line 175 of file Root.h.

◆ BroadcastChatFatal()

void cRoot::BroadcastChatFatal ( const AString a_Message)
inline

Definition at line 176 of file Root.h.

◆ BroadcastChatInfo()

void cRoot::BroadcastChatInfo ( const AString a_Message)
inline

Definition at line 177 of file Root.h.

◆ BroadcastChatJoin()

void cRoot::BroadcastChatJoin ( const AString a_Message)
inline

Definition at line 178 of file Root.h.

◆ BroadcastChatLeave()

void cRoot::BroadcastChatLeave ( const AString a_Message)
inline

Definition at line 179 of file Root.h.

◆ BroadcastChatSuccess()

void cRoot::BroadcastChatSuccess ( const AString a_Message)
inline

Definition at line 180 of file Root.h.

◆ BroadcastChatWarning()

void cRoot::BroadcastChatWarning ( const AString a_Message)
inline

Definition at line 181 of file Root.h.

◆ BroadcastPlayerListsAddPlayer()

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

Broadcast playerlist addition through all worlds.

Definition at line 621 of file Root.cpp.

◆ BroadcastPlayerListsHeaderFooter()

void cRoot::BroadcastPlayerListsHeaderFooter ( const cCompositeChat a_Header,
const cCompositeChat a_Footer 
)

Broadcast playerlist header and footer through all worlds.

Definition at line 645 of file Root.cpp.

◆ BroadcastPlayerListsRemovePlayer()

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

Broadcast playerlist removal through all worlds.

Definition at line 633 of file Root.cpp.

◆ DoWithPlayer()

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 763 of file Root.cpp.

◆ DoWithPlayerByUUID()

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

Finds the player over his uuid and calls the callback.

Definition at line 747 of file Root.cpp.

◆ FindAndDoWithPlayer()

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 697 of file Root.cpp.

◆ ForEachPlayer()

bool cRoot::ForEachPlayer ( cPlayerListCallback  a_Callback)

Calls the callback for each player in all worlds.

Definition at line 681 of file Root.cpp.

◆ ForEachWorld()

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 480 of file Root.cpp.

◆ Get()

static cRoot* cRoot::Get ( void  )
inlinestatic

Definition at line 52 of file Root.h.

◆ GetAuthenticator()

cAuthenticator& cRoot::GetAuthenticator ( void  )
inline

Definition at line 112 of file Root.h.

◆ GetBrewingRecipes()

cBrewingRecipes* cRoot::GetBrewingRecipes ( void  )
inline

Definition at line 95 of file Root.h.

◆ GetCraftingRecipes()

cCraftingRecipes* cRoot::GetCraftingRecipes ( void  )
inline

Definition at line 92 of file Root.h.

◆ GetDefaultWorld()

cWorld * cRoot::GetDefaultWorld ( void  )

Definition at line 455 of file Root.cpp.

◆ GetFurnaceFuelBurnTime()

int cRoot::GetFurnaceFuelBurnTime ( const cItem a_Fuel)
static

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

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

Definition at line 973 of file Root.cpp.

◆ GetFurnaceRecipe()

cFurnaceRecipe* cRoot::GetFurnaceRecipe ( void  )
inline

Definition at line 94 of file Root.h.

◆ GetMojangAPI()

cMojangAPI& cRoot::GetMojangAPI ( void  )
inline

Definition at line 113 of file Root.h.

◆ GetMonsterConfig()

cMonsterConfig* cRoot::GetMonsterConfig ( void  )
inline

Definition at line 90 of file Root.h.

◆ GetPhysicalRAMUsage()

int cRoot::GetPhysicalRAMUsage ( void  )
static

Returns the amount of virtual RAM used, in KiB.

Returns a negative number on error

Definition at line 840 of file Root.cpp.

◆ GetPlayerTabCompletionMultiWorld()

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 983 of file Root.cpp.

◆ GetPluginManager()

cPluginManager* cRoot::GetPluginManager ( void  )
inline

Definition at line 111 of file Root.h.

◆ GetProtocolVersionTextFromInt()

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 779 of file Root.cpp.

◆ GetRankManager()

cRankManager* cRoot::GetRankManager ( void  )
inline

Definition at line 114 of file Root.h.

◆ GetRecipeMapper()

cRecipeMapper* cRoot::GetRecipeMapper ( void  )
inline

Definition at line 93 of file Root.h.

◆ GetServer()

cServer* cRoot::GetServer ( void  )
inline

Definition at line 71 of file Root.h.

◆ GetServerUpTime()

int cRoot::GetServerUpTime ( void  )
inline

Returns the up time of the server in seconds.

Definition at line 78 of file Root.h.

◆ GetTotalChunkCount()

size_t cRoot::GetTotalChunkCount ( void  )

Returns the number of chunks loaded.

Definition at line 559 of file Root.cpp.

◆ GetVirtualRAMUsage()

int cRoot::GetVirtualRAMUsage ( void  )
static

Returns the amount of virtual RAM used, in KiB.

Returns a negative number on error

Definition at line 788 of file Root.cpp.

◆ GetWebAdmin()

cWebAdmin* cRoot::GetWebAdmin ( void  )
inline

Definition at line 110 of file Root.h.

◆ GetWorld()

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 465 of file Root.cpp.

◆ HandleInput()

void cRoot::HandleInput ( )
private

Blocking reads and processes console input.

Definition at line 999 of file Root.cpp.

◆ KickUser()

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 550 of file Root.cpp.

◆ LoadGlobalSettings()

void cRoot::LoadGlobalSettings ( )
private

The storage for all registered block types.

Definition at line 277 of file Root.cpp.

◆ LoadWorlds()

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 286 of file Root.cpp.

◆ LogChunkStats()

void cRoot::LogChunkStats ( cCommandOutputCallback a_Output)

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

Definition at line 923 of file Root.cpp.

◆ QueueExecuteConsoleCommand() [1/2]

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 540 of file Root.cpp.

◆ QueueExecuteConsoleCommand() [2/2]

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 496 of file Root.cpp.

◆ Restart()

void cRoot::Restart ( void  )
static

Interrupts the server and restarts it, as if "/restart" was typed in the console.

Definition at line 268 of file Root.cpp.

◆ Run()

bool cRoot::Run ( cSettingsRepositoryInterface a_OverridesRepo)

Run the server.

Returns true if we should restart, false to quit.

Definition at line 103 of file Root.cpp.

◆ SaveAllChunks()

void cRoot::SaveAllChunks ( void  )

Saves all chunks in all worlds.

Definition at line 573 of file Root.cpp.

◆ SaveAllChunksNow()

void cRoot::SaveAllChunksNow ( void  )

Saves all chunks in all worlds synchronously (waits until dirty chunks have been sent to the ChunkStorage queue before returning)

Definition at line 585 of file Root.cpp.

◆ SendPlayerLists()

void cRoot::SendPlayerLists ( cPlayer a_DestPlayer)

Send playerlist of all worlds to player.

Definition at line 609 of file Root.cpp.

◆ SetSavingEnabled()

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 597 of file Root.cpp.

◆ StartWorlds()

void cRoot::StartWorlds ( cDeadlockDetect a_DeadlockDetect)
private

Starts each world's life.

Definition at line 428 of file Root.cpp.

◆ Stop()

void cRoot::Stop ( void  )
static

Interrupts the server and stops it, as if "/stop" typed in the console.

Definition at line 259 of file Root.cpp.

◆ StopWorlds()

void cRoot::StopWorlds ( cDeadlockDetect a_DeadlockDetect)
private

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

Definition at line 443 of file Root.cpp.

◆ TransitionNextState()

void cRoot::TransitionNextState ( NextState  a_NextState)
staticprivate

Performs run state transition, enforcing guarantees about state transitions.

Definition at line 1051 of file Root.cpp.

Member Data Documentation

◆ m_Authenticator

cAuthenticator cRoot::m_Authenticator
private

Definition at line 227 of file Root.h.

◆ m_BrewingRecipes

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

Definition at line 224 of file Root.h.

◆ m_CraftingRecipes

cCraftingRecipes* cRoot::m_CraftingRecipes
private

Definition at line 221 of file Root.h.

◆ m_FurnaceRecipe

cFurnaceRecipe* cRoot::m_FurnaceRecipe
private

Definition at line 223 of file Root.h.

◆ m_HTTPServer

cHTTPServer cRoot::m_HTTPServer
private

Definition at line 232 of file Root.h.

◆ m_MojangAPI

cMojangAPI* cRoot::m_MojangAPI
private

Definition at line 228 of file Root.h.

◆ m_MonsterConfig

cMonsterConfig* cRoot::m_MonsterConfig
private

Definition at line 219 of file Root.h.

◆ m_pDefaultWorld

cWorld* cRoot::m_pDefaultWorld
private

Definition at line 213 of file Root.h.

◆ m_PluginManager

cPluginManager* cRoot::m_PluginManager
private

Definition at line 226 of file Root.h.

◆ m_RankManager

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

Definition at line 230 of file Root.h.

◆ m_RecipeMapper

std::unique_ptr<cRecipeMapper> cRoot::m_RecipeMapper
private

Definition at line 222 of file Root.h.

◆ m_Server

cServer* cRoot::m_Server
private

Definition at line 218 of file Root.h.

◆ m_SettingsFilename

AString cRoot::m_SettingsFilename

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

Definition at line 56 of file Root.h.

◆ m_StartTime

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

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

Definition at line 108 of file Root.h.

◆ m_WebAdmin

cWebAdmin* cRoot::m_WebAdmin
private

Definition at line 225 of file Root.h.

◆ m_WorldsByName

WorldMap cRoot::m_WorldsByName
private

Definition at line 214 of file Root.h.

◆ s_NextState

std::atomic<NextState> cRoot::s_NextState
staticprivate

Indicates the next action of cRoot, whether to run, stop or restart.

Definition at line 252 of file Root.h.

◆ s_Root

cRoot* cRoot::s_Root
staticprivate

Definition at line 249 of file Root.h.

◆ s_StopEvent

cEvent cRoot::s_StopEvent
staticprivate

Definition at line 216 of file Root.h.


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