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

This commit is contained in:
joschiwald
2014-12-05 23:55:06 +01:00
parent 46b6971556
commit cc4ebdbe05
4 changed files with 87 additions and 48 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::const_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();

View File

@@ -872,6 +872,15 @@ class GroupScript : public ScriptObject
// Placed here due to ScriptRegistry::AddScript dependency.
#define sScriptMgr ScriptMgr::instance()
// namespace
// {
typedef std::vector<ScriptObject*> UnusedScriptContainer;
typedef std::list<std::string> UnusedScriptNamesContainer;
extern UnusedScriptContainer UnusedScripts;
extern UnusedScriptNamesContainer UnusedScriptNames;
// }
// Manages registration, loading, and execution of scripts.
class ScriptMgr
{
@@ -900,6 +909,7 @@ class ScriptMgr
public: /* Unloading */
void Unload();
void UnloadUnusedScripts();
public: /* SpellScriptLoader */