Core/Scripts: log ScriptNames assigned in database without core script

(cherry picked from commit cc4ebdbe05)
This commit is contained in:
joschiwald
2014-12-05 23:55:06 +01:00
parent 2e757f8198
commit 5b93a6b392
4 changed files with 86 additions and 47 deletions

View File

@@ -34,6 +34,12 @@
#include "WorldPacket.h"
#include "WorldSession.h"
// namespace
// {
UnusedScriptContainer UnusedScripts;
UnusedScriptNamesContainer UnusedScriptNames;
// }
// This is the global static registry of scripts.
template<class TScript>
class ScriptRegistry
@@ -89,6 +95,12 @@ class ScriptRegistry
{
ScriptPointerList[id] = script;
sScriptMgr->IncrementScriptCount();
#ifdef SCRIPTS
UnusedScriptNamesContainer::iterator itr = std::lower_bound(UnusedScriptNames.begin(), UnusedScriptNames.end(), script->GetName());
if (itr != UnusedScriptNames.end() && *itr == script->GetName())
UnusedScriptNames.erase(itr);
#endif
}
else
{
@@ -106,8 +118,7 @@ class ScriptRegistry
// Avoid calling "delete script;" because we are currently in the script constructor
// In a valid scenario this will not happen because every script has a name assigned in the database
// If that happens, it's acceptable to just leak a few bytes
UnusedScripts.push_back(script);
return;
}
}
@@ -189,6 +200,15 @@ void ScriptMgr::Initialize()
FillSpellSummary();
AddScripts();
#ifdef SCRIPTS
for (std::string const& scriptName : UnusedScriptNames)
{
TC_LOG_ERROR("sql.sql", "ScriptName '%s' exists in database, but no core script found!", scriptName.c_str());
}
#endif
UnloadUnusedScripts();
TC_LOG_INFO("server.loading", ">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime));
}
@@ -229,10 +249,19 @@ void ScriptMgr::Unload()
#undef SCR_CLEAR
UnloadUnusedScripts();
delete[] SpellSummary;
delete[] UnitAI::AISpellInfo;
}
void ScriptMgr::UnloadUnusedScripts()
{
for (size_t i = 0; i < UnusedScripts.size(); ++i)
delete UnusedScripts[i];
UnusedScripts.clear();
}
void ScriptMgr::LoadDatabase()
{
sScriptSystemMgr->LoadScriptWaypoints();