1
0

Fixed crash on restart

This commit is contained in:
Tiger Wang 2014-12-21 14:31:20 +00:00
parent d4c9daddb8
commit 0d6672bf5d
2 changed files with 14 additions and 5 deletions

View File

@ -135,8 +135,9 @@ void cRoot::Start(void)
} }
LOG("Starting server..."); LOG("Starting server...");
m_MojangAPI = new cMojangAPI;
bool ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true); bool ShouldAuthenticate = IniFile.GetValueSetB("Authentication", "Authenticate", true);
m_MojangAPI.Start(IniFile, ShouldAuthenticate); // Mojang API needs to be started before plugins, so that plugins may use it for DB upgrades on server init m_MojangAPI->Start(IniFile, ShouldAuthenticate); // Mojang API needs to be started before plugins, so that plugins may use it for DB upgrades on server init
if (!m_Server->InitServer(IniFile, ShouldAuthenticate)) if (!m_Server->InitServer(IniFile, ShouldAuthenticate))
{ {
IniFile.WriteFile("settings.ini"); IniFile.WriteFile("settings.ini");
@ -149,7 +150,7 @@ void cRoot::Start(void)
LOGD("Loading settings..."); LOGD("Loading settings...");
m_RankManager.reset(new cRankManager()); m_RankManager.reset(new cRankManager());
m_RankManager->Initialize(m_MojangAPI); m_RankManager->Initialize(*m_MojangAPI);
m_CraftingRecipes = new cCraftingRecipes; m_CraftingRecipes = new cCraftingRecipes;
m_FurnaceRecipe = new cFurnaceRecipe(); m_FurnaceRecipe = new cFurnaceRecipe();
@ -196,7 +197,7 @@ void cRoot::Start(void)
} }
#endif #endif
LOG("Startup complete, took %ld ms!", static_cast<long int>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - BeginTime).count())); LOG("Startup complete, took %ldms!", static_cast<long int>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - BeginTime).count()));
#ifdef _WIN32 #ifdef _WIN32
EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button
#endif #endif
@ -213,21 +214,28 @@ void cRoot::Start(void)
// Stop the server: // Stop the server:
m_WebAdmin->Stop(); m_WebAdmin->Stop();
LOG("Shutting down server..."); LOG("Shutting down server...");
m_Server->Shutdown(); m_Server->Shutdown();
delete m_MojangAPI; m_MojangAPI = nullptr;
LOGD("Shutting down deadlock detector..."); LOGD("Shutting down deadlock detector...");
dd.Stop(); dd.Stop();
LOGD("Stopping world threads..."); LOGD("Stopping world threads...");
StopWorlds(); StopWorlds();
LOGD("Stopping authenticator..."); LOGD("Stopping authenticator...");
m_Authenticator.Stop(); m_Authenticator.Stop();
LOGD("Freeing MonsterConfig..."); LOGD("Freeing MonsterConfig...");
delete m_MonsterConfig; m_MonsterConfig = nullptr; delete m_MonsterConfig; m_MonsterConfig = nullptr;
delete m_WebAdmin; m_WebAdmin = nullptr; delete m_WebAdmin; m_WebAdmin = nullptr;
LOGD("Unloading recipes..."); LOGD("Unloading recipes...");
delete m_FurnaceRecipe; m_FurnaceRecipe = nullptr; delete m_FurnaceRecipe; m_FurnaceRecipe = nullptr;
delete m_CraftingRecipes; m_CraftingRecipes = nullptr; delete m_CraftingRecipes; m_CraftingRecipes = nullptr;
LOGD("Unloading worlds..."); LOGD("Unloading worlds...");
UnloadWorlds(); UnloadWorlds();
@ -238,6 +246,7 @@ void cRoot::Start(void)
LOG("Cleaning up..."); LOG("Cleaning up...");
delete m_Server; m_Server = nullptr; delete m_Server; m_Server = nullptr;
LOG("Shutdown successful!"); LOG("Shutdown successful!");
} }

View File

@ -86,7 +86,7 @@ public:
cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; } cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; } cMojangAPI & GetMojangAPI (void) { return *m_MojangAPI; }
cRankManager * GetRankManager (void) { return m_RankManager.get(); } cRankManager * GetRankManager (void) { return m_RankManager.get(); }
/** Queues a console command for execution through the cServer class. /** Queues a console command for execution through the cServer class.
@ -191,7 +191,7 @@ private:
cWebAdmin * m_WebAdmin; cWebAdmin * m_WebAdmin;
cPluginManager * m_PluginManager; cPluginManager * m_PluginManager;
cAuthenticator m_Authenticator; cAuthenticator m_Authenticator;
cMojangAPI m_MojangAPI; cMojangAPI * m_MojangAPI;
std::unique_ptr<cRankManager> m_RankManager; std::unique_ptr<cRankManager> m_RankManager;