2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
|
#include "Root.h"
|
|
|
|
|
#include "Server.h"
|
|
|
|
|
#include "World.h"
|
|
|
|
|
#include "WebAdmin.h"
|
|
|
|
|
#include "FurnaceRecipe.h"
|
|
|
|
|
#include "GroupManager.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
#include "CraftingRecipes.h"
|
2013-12-08 06:17:54 -05:00
|
|
|
|
#include "Bindings/PluginManager.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
|
#include "MonsterConfig.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
|
#include "Entities/Player.h"
|
2012-09-29 09:59:32 -04:00
|
|
|
|
#include "Blocks/BlockHandler.h"
|
|
|
|
|
#include "Items/ItemHandler.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
|
#include "Chunk.h"
|
2012-10-31 15:54:42 -04:00
|
|
|
|
#include "Protocol/ProtocolRecognizer.h" // for protocol version constants
|
2013-06-29 11:30:05 -04:00
|
|
|
|
#include "CommandOutput.h"
|
2013-08-14 16:39:12 -04:00
|
|
|
|
#include "DeadlockDetect.h"
|
2013-09-29 16:37:50 -04:00
|
|
|
|
#include "OSSupport/Timer.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-11-27 02:27:19 -05:00
|
|
|
|
#include "inifile/iniFile.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-10-08 14:12:34 -04:00
|
|
|
|
#ifdef _WIN32
|
2013-12-22 15:03:58 -05:00
|
|
|
|
#include "conio.h"
|
2013-10-08 14:12:34 -04:00
|
|
|
|
#include <psapi.h>
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
#endif
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-12-22 15:03:58 -05:00
|
|
|
|
extern bool g_TERMINATE_EVENT_RAISED;
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-08 14:12:34 -04:00
|
|
|
|
cRoot* cRoot::s_Root = NULL;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-20 13:10:07 -05:00
|
|
|
|
cRoot::cRoot(void) :
|
|
|
|
|
m_PrimaryServerVersion(cProtocolRecognizer::PROTO_VERSION_LATEST),
|
|
|
|
|
m_pDefaultWorld(NULL),
|
|
|
|
|
m_InputThread(NULL),
|
|
|
|
|
m_Server(NULL),
|
|
|
|
|
m_MonsterConfig(NULL),
|
|
|
|
|
m_GroupManager(NULL),
|
|
|
|
|
m_CraftingRecipes(NULL),
|
|
|
|
|
m_FurnaceRecipe(NULL),
|
|
|
|
|
m_WebAdmin(NULL),
|
|
|
|
|
m_PluginManager(NULL),
|
|
|
|
|
m_Log(NULL),
|
|
|
|
|
m_bStop(false),
|
|
|
|
|
m_bRestart(false)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
s_Root = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cRoot::~cRoot()
|
|
|
|
|
{
|
|
|
|
|
s_Root = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 06:38:15 -04:00
|
|
|
|
void cRoot::InputThread(void * a_Params)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-08-18 06:38:15 -04:00
|
|
|
|
cRoot & self = *(cRoot*)a_Params;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
|
cLogCommandOutputCallback Output;
|
|
|
|
|
|
2013-12-22 15:03:58 -05:00
|
|
|
|
while (!self.m_bStop && !self.m_bRestart && !g_TERMINATE_EVENT_RAISED && std::cin.good())
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-12-07 17:35:24 -05:00
|
|
|
|
AString Command;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
std::getline(std::cin, Command);
|
2013-07-24 16:25:27 -04:00
|
|
|
|
if (!Command.empty())
|
2013-12-07 17:35:24 -05:00
|
|
|
|
{
|
|
|
|
|
self.ExecuteConsoleCommand(TrimString(Command), Output);
|
2013-07-24 16:25:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-22 15:03:58 -05:00
|
|
|
|
|
|
|
|
|
if (g_TERMINATE_EVENT_RAISED || !std::cin.good())
|
2013-07-24 16:25:27 -04:00
|
|
|
|
{
|
2013-12-22 15:03:58 -05:00
|
|
|
|
// We have come here because the std::cin has received an EOF / a terminate signal has been sent, and the server is still running; stop the server:
|
2013-07-24 16:25:27 -04:00
|
|
|
|
self.m_bStop = true;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-11 09:15:59 -05:00
|
|
|
|
void cRoot::Start(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-12-22 15:03:58 -05:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
HWND hwnd = GetConsoleWindow();
|
|
|
|
|
HMENU hmenu = GetSystemMenu(hwnd, FALSE);
|
|
|
|
|
EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-08-14 16:39:12 -04:00
|
|
|
|
cDeadlockDetect dd;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
delete m_Log;
|
|
|
|
|
m_Log = new cMCLogger();
|
|
|
|
|
|
|
|
|
|
m_bStop = false;
|
|
|
|
|
while (!m_bStop)
|
|
|
|
|
{
|
2013-10-07 04:45:42 -04:00
|
|
|
|
cTimer Time;
|
|
|
|
|
long long mseconds = Time.GetNowTime();
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
m_bRestart = false;
|
|
|
|
|
|
|
|
|
|
LoadGlobalSettings();
|
|
|
|
|
|
|
|
|
|
LOG("Creating new server instance...");
|
|
|
|
|
m_Server = new cServer();
|
|
|
|
|
|
2012-11-11 09:23:47 -05:00
|
|
|
|
LOG("Reading server config...");
|
2013-10-25 05:15:44 -04:00
|
|
|
|
cIniFile IniFile;
|
|
|
|
|
if (!IniFile.ReadFile("settings.ini"))
|
2012-11-10 10:13:09 -05:00
|
|
|
|
{
|
2013-11-04 16:51:24 -05:00
|
|
|
|
LOGWARN("Regenerating settings.ini, all settings will be reset");
|
|
|
|
|
IniFile.AddHeaderComment(" This is the main server configuration");
|
|
|
|
|
IniFile.AddHeaderComment(" Most of the settings here can be configured using the webadmin interface, if enabled in webadmin.ini");
|
2014-02-07 06:07:22 -05:00
|
|
|
|
IniFile.AddHeaderComment(" See: http://wiki.mc-server.org/doku.php?id=configure:settings.ini for further configuration help");
|
2012-11-10 10:13:09 -05:00
|
|
|
|
}
|
2013-11-04 16:51:24 -05:00
|
|
|
|
|
2012-11-11 09:15:59 -05:00
|
|
|
|
m_PrimaryServerVersion = IniFile.GetValueI("Server", "PrimaryServerVersion", 0);
|
|
|
|
|
if (m_PrimaryServerVersion == 0)
|
|
|
|
|
{
|
|
|
|
|
m_PrimaryServerVersion = cProtocolRecognizer::PROTO_VERSION_LATEST;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Make a note in the log that the primary server version is explicitly set in the ini file
|
2013-11-04 16:51:24 -05:00
|
|
|
|
LOGINFO("Primary server version set explicitly to %d.", m_PrimaryServerVersion);
|
2012-11-11 09:15:59 -05:00
|
|
|
|
}
|
2012-10-31 15:54:42 -04:00
|
|
|
|
|
2012-11-11 09:23:47 -05:00
|
|
|
|
LOG("Starting server...");
|
|
|
|
|
if (!m_Server->InitServer(IniFile))
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGERROR("Failure starting server, aborting...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-05 17:08:16 -04:00
|
|
|
|
m_WebAdmin = new cWebAdmin();
|
|
|
|
|
m_WebAdmin->Init();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Loading settings...");
|
2013-08-05 09:24:23 -04:00
|
|
|
|
m_GroupManager = new cGroupManager();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
m_CraftingRecipes = new cCraftingRecipes;
|
2013-08-05 09:24:23 -04:00
|
|
|
|
m_FurnaceRecipe = new cFurnaceRecipe();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Loading worlds...");
|
2013-10-26 11:08:28 -04:00
|
|
|
|
LoadWorlds(IniFile);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Loading plugin manager...");
|
2013-02-15 08:00:59 -05:00
|
|
|
|
m_PluginManager = new cPluginManager();
|
2013-11-04 16:51:24 -05:00
|
|
|
|
m_PluginManager->ReloadPluginsNow(IniFile);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Loading MonsterConfig...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
m_MonsterConfig = new cMonsterConfig;
|
|
|
|
|
|
|
|
|
|
// This sets stuff in motion
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Starting Authenticator...");
|
2013-10-26 11:08:28 -04:00
|
|
|
|
m_Authenticator.Start(IniFile);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Starting worlds...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
StartWorlds();
|
|
|
|
|
|
2013-11-30 16:14:47 -05:00
|
|
|
|
if (IniFile.GetValueSetB("DeadlockDetect", "Enabled", true))
|
|
|
|
|
{
|
|
|
|
|
LOGD("Starting deadlock detector...");
|
|
|
|
|
dd.Start(IniFile.GetValueSetI("DeadlockDetect", "IntervalSec", 20));
|
|
|
|
|
}
|
2013-08-14 16:39:12 -04:00
|
|
|
|
|
2013-11-30 16:14:47 -05:00
|
|
|
|
IniFile.WriteFile("settings.ini");
|
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Finalising startup...");
|
2013-03-04 16:13:08 -05:00
|
|
|
|
m_Server->Start();
|
2013-10-05 17:08:16 -04:00
|
|
|
|
|
|
|
|
|
m_WebAdmin->Start();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-03-04 16:13:08 -05:00
|
|
|
|
#if !defined(ANDROID_NDK)
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Starting InputThread...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" );
|
2013-03-04 16:13:08 -05:00
|
|
|
|
m_InputThread->Start( false ); // We should NOT wait? Otherwise we can<61>t stop the server from other threads than the input thread
|
|
|
|
|
#endif
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-09-29 16:37:50 -04:00
|
|
|
|
long long finishmseconds = Time.GetNowTime();
|
|
|
|
|
finishmseconds -= mseconds;
|
2013-09-28 15:36:01 -04:00
|
|
|
|
|
2014-01-28 10:28:55 -05:00
|
|
|
|
LOG("Startup complete, took %lld ms!", finishmseconds);
|
2013-12-22 15:03:58 -05:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button
|
|
|
|
|
#endif
|
2013-09-28 15:36:01 -04:00
|
|
|
|
|
2013-12-22 15:03:58 -05:00
|
|
|
|
while (!m_bStop && !m_bRestart && !g_TERMINATE_EVENT_RAISED) // These are modified by external threads
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-03-04 16:13:08 -05:00
|
|
|
|
cSleep::MilliSleep(1000);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 15:03:58 -05:00
|
|
|
|
if (g_TERMINATE_EVENT_RAISED)
|
|
|
|
|
{
|
|
|
|
|
m_bStop = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 16:13:08 -05:00
|
|
|
|
#if !defined(ANDROID_NDK)
|
|
|
|
|
delete m_InputThread; m_InputThread = NULL;
|
|
|
|
|
#endif
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2014-02-07 06:26:41 -05:00
|
|
|
|
// Stop the server:
|
|
|
|
|
m_WebAdmin->Stop();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
LOG("Shutting down server...");
|
2013-08-14 16:39:12 -04:00
|
|
|
|
m_Server->Shutdown();
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Shutting down deadlock detector...");
|
2013-08-14 16:39:12 -04:00
|
|
|
|
dd.Stop();
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Stopping world threads...");
|
2012-07-15 16:07:38 -04:00
|
|
|
|
StopWorlds();
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Stopping authenticator...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
m_Authenticator.Stop();
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Freeing MonsterConfig...");
|
2013-08-14 16:39:12 -04:00
|
|
|
|
delete m_MonsterConfig; m_MonsterConfig = NULL;
|
|
|
|
|
delete m_WebAdmin; m_WebAdmin = NULL;
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Unloading recipes...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
delete m_FurnaceRecipe; m_FurnaceRecipe = NULL;
|
|
|
|
|
delete m_CraftingRecipes; m_CraftingRecipes = NULL;
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Forgetting groups...");
|
2013-12-22 15:03:58 -05:00
|
|
|
|
delete m_GroupManager; m_GroupManager = NULL;
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Unloading worlds...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
UnloadWorlds();
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOGD("Stopping plugin manager...");
|
2013-02-05 14:57:22 -05:00
|
|
|
|
delete m_PluginManager; m_PluginManager = NULL;
|
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
cItemHandler::Deinit();
|
|
|
|
|
cBlockHandler::Deinit();
|
|
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOG("Cleaning up...");
|
2013-12-22 15:03:58 -05:00
|
|
|
|
delete m_Server; m_Server = NULL;
|
2013-09-28 15:36:01 -04:00
|
|
|
|
LOG("Shutdown successful!");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 15:03:58 -05:00
|
|
|
|
delete m_Log; m_Log = NULL;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::LoadGlobalSettings()
|
|
|
|
|
{
|
2012-10-06 16:04:58 -04:00
|
|
|
|
// Nothing needed yet
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-26 13:47:12 -04:00
|
|
|
|
void cRoot::LoadWorlds(cIniFile & IniFile)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
// First get the default world
|
|
|
|
|
AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world");
|
2012-08-22 07:22:26 -04:00
|
|
|
|
m_pDefaultWorld = new cWorld( DefaultWorldName.c_str() );
|
|
|
|
|
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
// Then load the other worlds
|
|
|
|
|
unsigned int KeyNum = IniFile.FindKey("Worlds");
|
|
|
|
|
unsigned int NumWorlds = IniFile.GetNumValues( KeyNum );
|
|
|
|
|
if (NumWorlds <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 16:51:24 -05:00
|
|
|
|
bool FoundAdditionalWorlds = false;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
for (unsigned int i = 0; i < NumWorlds; i++)
|
|
|
|
|
{
|
|
|
|
|
AString ValueName = IniFile.GetValueName(KeyNum, i );
|
|
|
|
|
if (ValueName.compare("World") != 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
AString WorldName = IniFile.GetValue(KeyNum, i );
|
|
|
|
|
if (WorldName.empty())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-11-04 16:51:24 -05:00
|
|
|
|
FoundAdditionalWorlds = true;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
cWorld* NewWorld = new cWorld( WorldName.c_str() );
|
2012-08-22 07:22:26 -04:00
|
|
|
|
m_WorldsByName[ WorldName ] = NewWorld;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
} // for i - Worlds
|
2013-11-04 16:51:24 -05:00
|
|
|
|
|
|
|
|
|
if (!FoundAdditionalWorlds)
|
|
|
|
|
{
|
2013-11-07 17:33:46 -05:00
|
|
|
|
if (IniFile.GetKeyComment("Worlds", 0) != " World=secondworld")
|
|
|
|
|
{
|
|
|
|
|
IniFile.AddKeyComment("Worlds", " World=secondworld");
|
|
|
|
|
}
|
2013-11-04 16:51:24 -05:00
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 06:39:13 -05:00
|
|
|
|
cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName)
|
|
|
|
|
{
|
|
|
|
|
if (m_WorldsByName[a_WorldName] != NULL)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
cWorld* NewWorld = new cWorld(a_WorldName.c_str());
|
|
|
|
|
m_WorldsByName[a_WorldName] = NewWorld;
|
|
|
|
|
NewWorld->Start();
|
|
|
|
|
NewWorld->InitializeSpawn();
|
2013-12-11 10:19:38 -05:00
|
|
|
|
m_PluginManager->CallHookWorldStarted(*NewWorld);
|
2013-12-11 06:39:13 -05:00
|
|
|
|
return NewWorld;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
void cRoot::StartWorlds(void)
|
|
|
|
|
{
|
2013-08-11 14:16:41 -04:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-08-11 14:16:41 -04:00
|
|
|
|
itr->second->Start();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
itr->second->InitializeSpawn();
|
2013-12-11 06:39:13 -05:00
|
|
|
|
m_PluginManager->CallHookWorldStarted(*itr->second);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 16:07:38 -04:00
|
|
|
|
void cRoot::StopWorlds(void)
|
|
|
|
|
{
|
2013-08-11 14:16:41 -04:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr)
|
2012-07-15 16:07:38 -04:00
|
|
|
|
{
|
2013-08-11 14:16:41 -04:00
|
|
|
|
itr->second->Stop();
|
2012-07-15 16:07:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
void cRoot::UnloadWorlds(void)
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
m_pDefaultWorld = NULL;
|
|
|
|
|
for( WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
delete itr->second;
|
|
|
|
|
}
|
2012-08-22 07:22:26 -04:00
|
|
|
|
m_WorldsByName.clear();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cWorld* cRoot::GetDefaultWorld()
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
return m_pDefaultWorld;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cWorld* cRoot::GetWorld( const AString & a_WorldName )
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
WorldMap::iterator itr = m_WorldsByName.find( a_WorldName );
|
|
|
|
|
if( itr != m_WorldsByName.end() )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return itr->second;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cRoot::ForEachWorld(cWorldListCallback & a_Callback)
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-06-19 16:31:21 -04:00
|
|
|
|
++itr2;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
if (a_Callback.Item(itr->second))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-11 14:16:41 -04:00
|
|
|
|
void cRoot::TickCommands(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-04-27 17:05:34 -04:00
|
|
|
|
// Execute any pending commands:
|
2013-06-29 11:30:05 -04:00
|
|
|
|
cCommandQueue PendingCommands;
|
2013-04-27 17:05:34 -04:00
|
|
|
|
{
|
|
|
|
|
cCSLock Lock(m_CSPendingCommands);
|
|
|
|
|
std::swap(PendingCommands, m_PendingCommands);
|
|
|
|
|
}
|
2013-06-29 11:30:05 -04:00
|
|
|
|
for (cCommandQueue::iterator itr = PendingCommands.begin(), end = PendingCommands.end(); itr != end; ++itr)
|
2013-04-27 17:05:34 -04:00
|
|
|
|
{
|
2013-06-29 11:30:05 -04:00
|
|
|
|
ExecuteConsoleCommand(itr->m_Command, *(itr->m_Output));
|
2013-04-27 17:05:34 -04:00
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
|
void cRoot::QueueExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output)
|
|
|
|
|
{
|
|
|
|
|
// Some commands are built-in:
|
|
|
|
|
if (a_Cmd == "stop")
|
|
|
|
|
{
|
|
|
|
|
m_bStop = true;
|
|
|
|
|
}
|
|
|
|
|
else if (a_Cmd == "restart")
|
|
|
|
|
{
|
|
|
|
|
m_bRestart = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Put the command into a queue (Alleviates FS #363):
|
|
|
|
|
cCSLock Lock(m_CSPendingCommands);
|
|
|
|
|
m_PendingCommands.push_back(cCommand(a_Cmd, &a_Output));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::QueueExecuteConsoleCommand(const AString & a_Cmd)
|
2013-04-27 17:05:34 -04:00
|
|
|
|
{
|
2013-04-27 17:14:31 -04:00
|
|
|
|
// Some commands are built-in:
|
|
|
|
|
if (a_Cmd == "stop")
|
|
|
|
|
{
|
|
|
|
|
m_bStop = true;
|
|
|
|
|
}
|
|
|
|
|
else if (a_Cmd == "restart")
|
|
|
|
|
{
|
|
|
|
|
m_bRestart = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 17:05:34 -04:00
|
|
|
|
// Put the command into a queue (Alleviates FS #363):
|
|
|
|
|
cCSLock Lock(m_CSPendingCommands);
|
2013-06-29 11:30:05 -04:00
|
|
|
|
m_PendingCommands.push_back(cCommand(a_Cmd, new cLogCommandDeleteSelfOutputCallback));
|
2013-04-27 17:05:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
|
void cRoot::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-06-29 11:30:05 -04:00
|
|
|
|
// Some commands are built-in:
|
|
|
|
|
if (a_Cmd == "stop")
|
|
|
|
|
{
|
|
|
|
|
m_bStop = true;
|
|
|
|
|
}
|
|
|
|
|
else if (a_Cmd == "restart")
|
|
|
|
|
{
|
|
|
|
|
m_bRestart = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
|
LOG("Executing console command: \"%s\"", a_Cmd.c_str());
|
2013-06-29 11:30:05 -04:00
|
|
|
|
m_Server->ExecuteConsoleCommand(a_Cmd, a_Output);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::KickUser(int a_ClientID, const AString & a_Reason)
|
|
|
|
|
{
|
|
|
|
|
m_Server->KickUser(a_ClientID, a_Reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::AuthenticateUser(int a_ClientID)
|
|
|
|
|
{
|
|
|
|
|
m_Server->AuthenticateUser(a_ClientID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cRoot::GetTotalChunkCount(void)
|
|
|
|
|
{
|
|
|
|
|
int res = 0;
|
2012-08-22 07:22:26 -04:00
|
|
|
|
for ( WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
res += itr->second->GetNumChunks();
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::SaveAllChunks(void)
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-11-15 04:13:32 -05:00
|
|
|
|
itr->second->QueueSaveAllChunks();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-05 12:10:08 -05:00
|
|
|
|
void cRoot::ReloadGroups(void)
|
|
|
|
|
{
|
|
|
|
|
m_GroupManager->LoadGroups();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-15 17:26:19 -05:00
|
|
|
|
void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix)
|
2013-08-17 17:58:37 -04:00
|
|
|
|
{
|
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
|
|
|
|
{
|
2014-02-15 17:26:19 -05:00
|
|
|
|
itr->second->BroadcastChat(a_Message, NULL, a_ChatPrefix);
|
2013-08-17 17:58:37 -04:00
|
|
|
|
} // for itr - m_WorldsByName[]
|
2014-02-15 17:16:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::BroadcastChat(const cCompositeChat & a_Message)
|
|
|
|
|
{
|
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
|
|
|
|
{
|
|
|
|
|
itr->second->BroadcastChat(a_Message);
|
|
|
|
|
} // for itr - m_WorldsByName[]
|
2013-08-17 17:58:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback)
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-06-19 16:31:21 -04:00
|
|
|
|
++itr2;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
if (!itr->second->ForEachPlayer(a_Callback))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-15 08:08:11 -04:00
|
|
|
|
|
2012-08-22 19:05:12 -04:00
|
|
|
|
bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback)
|
|
|
|
|
{
|
|
|
|
|
class cCallback : public cPlayerListCallback
|
|
|
|
|
{
|
2013-12-20 13:10:07 -05:00
|
|
|
|
unsigned m_BestRating;
|
|
|
|
|
unsigned m_NameLength;
|
|
|
|
|
const AString m_PlayerName;
|
2012-08-22 19:05:12 -04:00
|
|
|
|
|
|
|
|
|
cPlayerListCallback & m_Callback;
|
|
|
|
|
virtual bool Item (cPlayer * a_pPlayer)
|
|
|
|
|
{
|
2013-12-20 13:10:07 -05:00
|
|
|
|
unsigned int Rating = RateCompareString (m_PlayerName, a_pPlayer->GetName());
|
|
|
|
|
if ((Rating > 0) && (Rating >= m_BestRating))
|
2012-08-22 19:05:12 -04:00
|
|
|
|
{
|
2013-12-20 13:10:07 -05:00
|
|
|
|
m_BestMatch = a_pPlayer;
|
|
|
|
|
if (Rating > m_BestRating)
|
|
|
|
|
{
|
|
|
|
|
m_NumMatches = 0;
|
|
|
|
|
}
|
|
|
|
|
m_BestRating = Rating;
|
|
|
|
|
++m_NumMatches;
|
2012-08-22 19:05:12 -04:00
|
|
|
|
}
|
2013-12-20 13:10:07 -05:00
|
|
|
|
if (Rating == m_NameLength) // Perfect match
|
2012-08-22 19:05:12 -04:00
|
|
|
|
{
|
2013-11-10 16:58:14 -05:00
|
|
|
|
return true;
|
2012-08-22 19:05:12 -04:00
|
|
|
|
}
|
2013-11-10 16:58:14 -05:00
|
|
|
|
return false;
|
2012-08-22 19:05:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
2013-12-20 13:10:07 -05:00
|
|
|
|
cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback) :
|
|
|
|
|
m_BestRating(0),
|
|
|
|
|
m_NameLength(a_PlayerName.length()),
|
|
|
|
|
m_PlayerName(a_PlayerName),
|
2013-12-21 10:38:37 -05:00
|
|
|
|
m_Callback(a_Callback),
|
2013-12-20 13:10:07 -05:00
|
|
|
|
m_BestMatch(NULL),
|
|
|
|
|
m_NumMatches(0)
|
2012-08-22 19:05:12 -04:00
|
|
|
|
{}
|
|
|
|
|
|
2013-12-20 13:10:07 -05:00
|
|
|
|
cPlayer * m_BestMatch;
|
|
|
|
|
unsigned m_NumMatches;
|
2012-08-22 19:05:12 -04:00
|
|
|
|
} Callback (a_PlayerName, a_Callback);
|
|
|
|
|
ForEachPlayer( Callback );
|
|
|
|
|
|
2013-12-20 13:10:07 -05:00
|
|
|
|
if (Callback.m_NumMatches == 1)
|
2012-08-22 19:05:12 -04:00
|
|
|
|
{
|
2013-12-20 13:10:07 -05:00
|
|
|
|
return a_Callback.Item(Callback.m_BestMatch);
|
2012-08-22 19:05:12 -04:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
|
AString cRoot::GetProtocolVersionTextFromInt(int a_ProtocolVersion)
|
|
|
|
|
{
|
|
|
|
|
return cProtocolRecognizer::GetVersionTextFromInt(a_ProtocolVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-08 14:12:34 -04:00
|
|
|
|
int cRoot::GetVirtualRAMUsage(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
PROCESS_MEMORY_COUNTERS_EX pmc;
|
|
|
|
|
if (GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS *)&pmc, sizeof(pmc)))
|
|
|
|
|
{
|
|
|
|
|
return (int)(pmc.PrivateUsage / 1024);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
// Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
|
|
|
|
|
std::ifstream StatFile("/proc/self/status");
|
|
|
|
|
if (!StatFile.good())
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
while (StatFile.good())
|
|
|
|
|
{
|
|
|
|
|
AString Line;
|
|
|
|
|
std::getline(StatFile, Line);
|
|
|
|
|
if (strncmp(Line.c_str(), "VmSize:", 7) == 0)
|
|
|
|
|
{
|
|
|
|
|
int res = atoi(Line.c_str() + 8);
|
|
|
|
|
return (res == 0) ? -1 : res; // If parsing failed, return -1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
#elif defined (__APPLE__)
|
|
|
|
|
// Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
|
|
|
|
|
struct task_basic_info t_info;
|
|
|
|
|
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
|
|
|
|
|
|
|
|
|
|
if (KERN_SUCCESS == task_info(
|
|
|
|
|
mach_task_self(),
|
|
|
|
|
TASK_BASIC_INFO,
|
|
|
|
|
(task_info_t)&t_info,
|
|
|
|
|
&t_info_count
|
|
|
|
|
))
|
|
|
|
|
{
|
|
|
|
|
return (int)(t_info.virtual_size / 1024);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
#else
|
|
|
|
|
LOGINFO("%s: Unknown platform, cannot query memory usage", __FUNCTION__);
|
|
|
|
|
return -1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cRoot::GetPhysicalRAMUsage(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
PROCESS_MEMORY_COUNTERS pmc;
|
|
|
|
|
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
|
|
|
|
|
{
|
|
|
|
|
return (int)(pmc.WorkingSetSize / 1024);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
// Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
|
|
|
|
|
std::ifstream StatFile("/proc/self/status");
|
|
|
|
|
if (!StatFile.good())
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
while (StatFile.good())
|
|
|
|
|
{
|
|
|
|
|
AString Line;
|
|
|
|
|
std::getline(StatFile, Line);
|
2014-01-01 04:18:56 -05:00
|
|
|
|
if (strncmp(Line.c_str(), "VmRSS:", 6) == 0)
|
2013-10-08 14:12:34 -04:00
|
|
|
|
{
|
2014-01-01 04:18:56 -05:00
|
|
|
|
int res = atoi(Line.c_str() + 7);
|
2013-10-08 14:12:34 -04:00
|
|
|
|
return (res == 0) ? -1 : res; // If parsing failed, return -1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
#elif defined (__APPLE__)
|
|
|
|
|
// Code adapted from http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
|
|
|
|
|
struct task_basic_info t_info;
|
|
|
|
|
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
|
|
|
|
|
|
|
|
|
|
if (KERN_SUCCESS == task_info(
|
|
|
|
|
mach_task_self(),
|
|
|
|
|
TASK_BASIC_INFO,
|
|
|
|
|
(task_info_t)&t_info,
|
|
|
|
|
&t_info_count
|
|
|
|
|
))
|
|
|
|
|
{
|
|
|
|
|
return (int)(t_info.resident_size / 1024);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
#else
|
|
|
|
|
LOGINFO("%s: Unknown platform, cannot query memory usage", __FUNCTION__);
|
|
|
|
|
return -1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
|
void cRoot::LogChunkStats(cCommandOutputCallback & a_Output)
|
2012-08-15 08:08:11 -04:00
|
|
|
|
{
|
|
|
|
|
int SumNumValid = 0;
|
|
|
|
|
int SumNumDirty = 0;
|
|
|
|
|
int SumNumInLighting = 0;
|
|
|
|
|
int SumNumInGenerator = 0;
|
|
|
|
|
int SumMem = 0;
|
2012-08-22 07:22:26 -04:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
2012-08-15 08:08:11 -04:00
|
|
|
|
{
|
|
|
|
|
cWorld * World = itr->second;
|
|
|
|
|
int NumInGenerator = World->GetGeneratorQueueLength();
|
|
|
|
|
int NumInSaveQueue = World->GetStorageSaveQueueLength();
|
|
|
|
|
int NumInLoadQueue = World->GetStorageLoadQueueLength();
|
|
|
|
|
int NumValid = 0;
|
|
|
|
|
int NumDirty = 0;
|
|
|
|
|
int NumInLighting = 0;
|
|
|
|
|
World->GetChunkStats(NumValid, NumDirty, NumInLighting);
|
2013-06-29 11:30:05 -04:00
|
|
|
|
a_Output.Out("World %s:", World->GetName().c_str());
|
|
|
|
|
a_Output.Out(" Num loaded chunks: %d", NumValid);
|
|
|
|
|
a_Output.Out(" Num dirty chunks: %d", NumDirty);
|
|
|
|
|
a_Output.Out(" Num chunks in lighting queue: %d", NumInLighting);
|
|
|
|
|
a_Output.Out(" Num chunks in generator queue: %d", NumInGenerator);
|
|
|
|
|
a_Output.Out(" Num chunks in storage load queue: %d", NumInLoadQueue);
|
|
|
|
|
a_Output.Out(" Num chunks in storage save queue: %d", NumInSaveQueue);
|
2012-08-15 08:08:11 -04:00
|
|
|
|
int Mem = NumValid * sizeof(cChunk);
|
2013-06-29 11:30:05 -04:00
|
|
|
|
a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024));
|
|
|
|
|
a_Output.Out(" Per-chunk memory size breakdown:");
|
|
|
|
|
a_Output.Out(" block types: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024);
|
|
|
|
|
a_Output.Out(" block metadata: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
|
|
|
|
|
a_Output.Out(" block lighting: %6d bytes (%3d KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
|
|
|
|
|
a_Output.Out(" heightmap: %6d bytes (%3d KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024);
|
|
|
|
|
a_Output.Out(" biomemap: %6d bytes (%3d KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024);
|
2012-08-15 08:08:11 -04:00
|
|
|
|
int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap);
|
2013-06-29 11:30:05 -04:00
|
|
|
|
a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024);
|
2012-08-15 08:08:11 -04:00
|
|
|
|
SumNumValid += NumValid;
|
|
|
|
|
SumNumDirty += NumDirty;
|
|
|
|
|
SumNumInLighting += NumInLighting;
|
|
|
|
|
SumNumInGenerator += NumInGenerator;
|
|
|
|
|
SumMem += Mem;
|
|
|
|
|
}
|
2013-06-29 11:30:05 -04:00
|
|
|
|
a_Output.Out("Totals:");
|
|
|
|
|
a_Output.Out(" Num loaded chunks: %d", SumNumValid);
|
|
|
|
|
a_Output.Out(" Num dirty chunks: %d", SumNumDirty);
|
|
|
|
|
a_Output.Out(" Num chunks in lighting queue: %d", SumNumInLighting);
|
|
|
|
|
a_Output.Out(" Num chunks in generator queue: %d", SumNumInGenerator);
|
|
|
|
|
a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (SumMem + 1023) / 1024, (SumMem + 1024 * 1024 - 1) / (1024 * 1024));
|
2012-08-15 08:08:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-22 10:50:03 -05:00
|
|
|
|
|
|
|
|
|
int cRoot::GetFurnaceFuelBurnTime(const cItem & a_Fuel)
|
|
|
|
|
{
|
|
|
|
|
cFurnaceRecipe * FR = Get()->GetFurnaceRecipe();
|
|
|
|
|
return FR->GetBurnTime(a_Fuel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|