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"
|
2012-09-23 18:09:57 -04:00
|
|
|
|
#include "PluginManager.h"
|
|
|
|
|
#include "MonsterConfig.h"
|
|
|
|
|
#include "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
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2012-08-16 02:47:09 -04:00
|
|
|
|
#ifdef USE_SQUIRREL
|
|
|
|
|
#include "squirrelbindings/SquirrelFunctions.h"
|
|
|
|
|
#include "squirrelbindings/SquirrelBindings.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
#include "../iniFile/iniFile.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cRoot* cRoot::s_Root = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cRoot::cRoot()
|
2012-08-22 07:22:26 -04:00
|
|
|
|
: m_Server( NULL )
|
|
|
|
|
, m_MonsterConfig( NULL )
|
|
|
|
|
, m_GroupManager( NULL )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
, m_CraftingRecipes(NULL)
|
2012-08-22 07:22:26 -04:00
|
|
|
|
, m_FurnaceRecipe( NULL )
|
|
|
|
|
, m_WebAdmin( NULL )
|
|
|
|
|
, m_PluginManager( NULL )
|
|
|
|
|
, m_Log( NULL )
|
2012-06-14 09:06:06 -04:00
|
|
|
|
, m_bStop( false )
|
|
|
|
|
, m_bRestart( false )
|
2012-08-22 07:22:26 -04:00
|
|
|
|
, m_InputThread( NULL )
|
|
|
|
|
, m_pDefaultWorld( NULL )
|
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
|
|
|
|
|
2012-08-18 06:38:15 -04:00
|
|
|
|
while (!(self.m_bStop || self.m_bRestart))
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
|
|
|
|
std::string Command;
|
|
|
|
|
std::getline(std::cin, Command);
|
2013-02-15 08:00:59 -05:00
|
|
|
|
self.ExecuteConsoleCommand(Command);
|
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
|
|
|
|
{
|
|
|
|
|
delete m_Log;
|
|
|
|
|
m_Log = new cMCLogger();
|
|
|
|
|
|
|
|
|
|
m_bStop = false;
|
|
|
|
|
while (!m_bStop)
|
|
|
|
|
{
|
|
|
|
|
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...");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
cIniFile IniFile("settings.ini");
|
2012-11-11 09:23:47 -05:00
|
|
|
|
if (!IniFile.ReadFile())
|
2012-11-10 10:13:09 -05:00
|
|
|
|
{
|
2012-11-11 09:23:47 -05:00
|
|
|
|
LOGINFO("settings.ini inaccessible, using settings.example.ini for defaults!");
|
2012-11-10 10:13:09 -05:00
|
|
|
|
IniFile.Path("settings.example.ini");
|
|
|
|
|
IniFile.ReadFile();
|
|
|
|
|
IniFile.Path("settings.ini");
|
|
|
|
|
}
|
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
|
|
|
|
|
LOGINFO("settings.ini: [Server].PrimaryServerVersion set to %d.", m_PrimaryServerVersion);
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2012-11-11 09:15:59 -05:00
|
|
|
|
LOGERROR("Failed to start server, shutting down.");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
IniFile.WriteFile();
|
|
|
|
|
|
|
|
|
|
cIniFile WebIniFile("webadmin.ini");
|
2012-11-16 17:06:12 -05:00
|
|
|
|
if (!WebIniFile.ReadFile())
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2012-11-16 17:06:12 -05:00
|
|
|
|
LOGINFO("webadmin.ini inaccessible, using webadmin.example.ini for defaults!");
|
|
|
|
|
WebIniFile.Path("webadmin.example.ini");
|
|
|
|
|
WebIniFile.ReadFile();
|
|
|
|
|
WebIniFile.Path("webadmin.ini");
|
|
|
|
|
WebIniFile.WriteFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (WebIniFile.GetValueB("WebAdmin", "Enabled", false ))
|
|
|
|
|
{
|
|
|
|
|
LOG("Creating WebAdmin...");
|
|
|
|
|
m_WebAdmin = new cWebAdmin(8080);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG("Loading settings...");
|
|
|
|
|
m_GroupManager = new cGroupManager();
|
|
|
|
|
m_CraftingRecipes = new cCraftingRecipes;
|
|
|
|
|
m_FurnaceRecipe = new cFurnaceRecipe();
|
|
|
|
|
|
|
|
|
|
LOG("Loading worlds...");
|
|
|
|
|
LoadWorlds();
|
|
|
|
|
|
|
|
|
|
LOG("Loading plugin manager...");
|
2013-02-15 08:00:59 -05:00
|
|
|
|
m_PluginManager = new cPluginManager();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
m_PluginManager->ReloadPluginsNow();
|
|
|
|
|
|
|
|
|
|
LOG("Loading MonsterConfig...");
|
|
|
|
|
m_MonsterConfig = new cMonsterConfig;
|
|
|
|
|
|
|
|
|
|
// This sets stuff in motion
|
|
|
|
|
LOG("Starting Authenticator...");
|
|
|
|
|
m_Authenticator.Start();
|
|
|
|
|
|
|
|
|
|
LOG("Starting worlds...");
|
|
|
|
|
StartWorlds();
|
|
|
|
|
|
|
|
|
|
LOG("Starting server...");
|
2013-03-04 16:13:08 -05:00
|
|
|
|
m_Server->Start();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
2013-03-04 16:13:08 -05:00
|
|
|
|
#if !defined(ANDROID_NDK)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
LOG("Starting InputThread...");
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
LOG("Initialization done, server running now.");
|
2013-03-04 16:13:08 -05:00
|
|
|
|
while (!m_bStop && !m_bRestart) // 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-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
|
|
|
|
|
|
|
|
|
// Deallocate stuffs
|
|
|
|
|
LOG("Shutting down server...");
|
2013-03-04 16:13:08 -05:00
|
|
|
|
m_Server->Shutdown(); // This waits for threads to stop and d/c clients
|
2012-07-15 16:07:38 -04:00
|
|
|
|
LOG("Stopping world threads...");
|
|
|
|
|
StopWorlds();
|
2012-06-14 09:06:06 -04:00
|
|
|
|
LOG("Stopping authenticator...");
|
|
|
|
|
m_Authenticator.Stop();
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
|
|
|
|
|
2012-08-16 02:47:09 -04:00
|
|
|
|
#ifdef USE_SQUIRREL
|
2012-07-15 16:36:34 -04:00
|
|
|
|
CloseSquirrelVM();
|
|
|
|
|
#endif
|
2012-06-14 09:06:06 -04:00
|
|
|
|
LOG("Freeing MonsterConfig...");
|
|
|
|
|
delete m_MonsterConfig; m_MonsterConfig = 0;
|
|
|
|
|
LOG("Stopping WebAdmin...");
|
|
|
|
|
delete m_WebAdmin; m_WebAdmin = 0;
|
|
|
|
|
LOG("Unloading recipes...");
|
|
|
|
|
delete m_FurnaceRecipe; m_FurnaceRecipe = NULL;
|
|
|
|
|
delete m_CraftingRecipes; m_CraftingRecipes = NULL;
|
|
|
|
|
LOG("Forgetting groups...");
|
|
|
|
|
delete m_GroupManager; m_GroupManager = 0;
|
|
|
|
|
LOG("Unloading worlds...");
|
|
|
|
|
UnloadWorlds();
|
2012-07-15 16:36:34 -04:00
|
|
|
|
|
2013-02-05 14:57:22 -05:00
|
|
|
|
LOG("Stopping plugin manager...");
|
|
|
|
|
delete m_PluginManager; m_PluginManager = NULL;
|
|
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
|
cItemHandler::Deinit();
|
|
|
|
|
cBlockHandler::Deinit();
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
LOG("Destroying server...");
|
|
|
|
|
//delete HeartBeat; HeartBeat = 0;
|
|
|
|
|
delete m_Server; m_Server = 0;
|
|
|
|
|
LOG("Shutdown done.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete m_Log; m_Log = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::LoadGlobalSettings()
|
|
|
|
|
{
|
2012-10-06 16:04:58 -04:00
|
|
|
|
// Nothing needed yet
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::LoadWorlds(void)
|
|
|
|
|
{
|
|
|
|
|
cIniFile IniFile("settings.ini"); IniFile.ReadFile();
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::StartWorlds(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
|
|
|
|
{
|
|
|
|
|
itr->second->InitializeSpawn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 16:07:38 -04:00
|
|
|
|
void cRoot::StopWorlds(void)
|
|
|
|
|
{
|
2012-08-22 07:22:26 -04:00
|
|
|
|
for( WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr )
|
2012-07-15 16:07:38 -04:00
|
|
|
|
{
|
|
|
|
|
itr->second->StopThreads();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-02-15 08:00:59 -05:00
|
|
|
|
void cRoot::TickWorlds(float a_Dt)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-04-27 17:05:34 -04:00
|
|
|
|
// Execute any pending commands:
|
|
|
|
|
AStringVector PendingCommands;
|
|
|
|
|
{
|
|
|
|
|
cCSLock Lock(m_CSPendingCommands);
|
|
|
|
|
std::swap(PendingCommands, m_PendingCommands);
|
|
|
|
|
}
|
|
|
|
|
for (AStringVector::iterator itr = PendingCommands.begin(), end = PendingCommands.end(); itr != end; ++itr)
|
|
|
|
|
{
|
|
|
|
|
DoExecuteConsoleCommand(*itr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tick the worlds:
|
2013-02-15 08:00:59 -05:00
|
|
|
|
for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-15 08:00:59 -05:00
|
|
|
|
itr->second->Tick(a_Dt);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
|
void cRoot::ExecuteConsoleCommand(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);
|
|
|
|
|
m_PendingCommands.push_back(a_Cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cRoot::DoExecuteConsoleCommand(const AString & a_Cmd)
|
2012-06-14 09:06:06 -04:00
|
|
|
|
{
|
2013-02-15 08:00:59 -05:00
|
|
|
|
LOG("Executing console command: \"%s\"", a_Cmd.c_str());
|
|
|
|
|
m_Server->ExecuteConsoleCommand(a_Cmd);
|
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
|
|
|
|
{
|
|
|
|
|
itr->second->SaveAllChunks();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
unsigned int BestRating;
|
|
|
|
|
unsigned int NameLength;
|
|
|
|
|
const AString PlayerName;
|
|
|
|
|
|
|
|
|
|
cPlayerListCallback & m_Callback;
|
|
|
|
|
virtual bool Item (cPlayer * a_pPlayer)
|
|
|
|
|
{
|
|
|
|
|
unsigned int Rating = RateCompareString (PlayerName, a_pPlayer->GetName());
|
|
|
|
|
if (Rating > 0 && Rating >= BestRating)
|
|
|
|
|
{
|
|
|
|
|
BestMatch = a_pPlayer;
|
|
|
|
|
if( Rating > BestRating ) NumMatches = 0;
|
|
|
|
|
BestRating = Rating;
|
|
|
|
|
++NumMatches;
|
|
|
|
|
}
|
|
|
|
|
if (Rating == NameLength) // Perfect match
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback)
|
|
|
|
|
: m_Callback( a_Callback )
|
|
|
|
|
, BestMatch( NULL )
|
|
|
|
|
, BestRating( 0 )
|
|
|
|
|
, NumMatches( 0 )
|
|
|
|
|
, NameLength( a_PlayerName.length() )
|
|
|
|
|
, PlayerName( a_PlayerName )
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
cPlayer * BestMatch;
|
|
|
|
|
unsigned int NumMatches;
|
|
|
|
|
} Callback (a_PlayerName, a_Callback);
|
|
|
|
|
ForEachPlayer( Callback );
|
|
|
|
|
|
|
|
|
|
if (Callback.NumMatches == 1)
|
|
|
|
|
{
|
|
|
|
|
return a_Callback.Item (Callback.BestMatch);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
|
AString cRoot::GetProtocolVersionTextFromInt(int a_ProtocolVersion)
|
|
|
|
|
{
|
|
|
|
|
return cProtocolRecognizer::GetVersionTextFromInt(a_ProtocolVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-15 08:08:11 -04:00
|
|
|
|
void cRoot::LogChunkStats(void)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
LOG("World %s:", World->GetName().c_str());
|
|
|
|
|
LOG(" Num loaded chunks: %d", NumValid);
|
|
|
|
|
LOG(" Num dirty chunks: %d", NumDirty);
|
|
|
|
|
LOG(" Num chunks in lighting queue: %d", NumInLighting);
|
|
|
|
|
LOG(" Num chunks in generator queue: %d", NumInGenerator);
|
|
|
|
|
LOG(" Num chunks in storage load queue: %d", NumInLoadQueue);
|
|
|
|
|
LOG(" Num chunks in storage save queue: %d", NumInSaveQueue);
|
|
|
|
|
int Mem = NumValid * sizeof(cChunk);
|
|
|
|
|
LOG(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024));
|
|
|
|
|
LOG(" Per-chunk memory size breakdown:");
|
|
|
|
|
LOG(" block types: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024);
|
|
|
|
|
LOG(" block metadata: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
|
|
|
|
|
LOG(" block lighting: %6d bytes (%3d KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024);
|
|
|
|
|
LOG(" heightmap: %6d bytes (%3d KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024);
|
|
|
|
|
LOG(" biomemap: %6d bytes (%3d KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024);
|
|
|
|
|
int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap);
|
|
|
|
|
LOG(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024);
|
|
|
|
|
SumNumValid += NumValid;
|
|
|
|
|
SumNumDirty += NumDirty;
|
|
|
|
|
SumNumInLighting += NumInLighting;
|
|
|
|
|
SumNumInGenerator += NumInGenerator;
|
|
|
|
|
SumMem += Mem;
|
|
|
|
|
}
|
|
|
|
|
LOG("Totals:");
|
|
|
|
|
LOG(" Num loaded chunks: %d", SumNumValid);
|
|
|
|
|
LOG(" Num dirty chunks: %d", SumNumDirty);
|
|
|
|
|
LOG(" Num chunks in lighting queue: %d", SumNumInLighting);
|
|
|
|
|
LOG(" Num chunks in generator queue: %d", SumNumInGenerator);
|
|
|
|
|
LOG(" Memory used by chunks: %d KiB (%d MiB)", (SumMem + 1023) / 1024, (SumMem + 1024 * 1024 - 1) / (1024 * 1024));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|