refactor(CORE/scripts): Clearer error when script unassigned or alrea… (#2576)
This commit is contained in:
@@ -65,103 +65,6 @@ template class ScriptRegistry<GameEventScript>;
|
|||||||
|
|
||||||
#include "ScriptMgrMacros.h"
|
#include "ScriptMgrMacros.h"
|
||||||
|
|
||||||
// This is the global static registry of scripts.
|
|
||||||
/*template<class TScript>
|
|
||||||
class ScriptRegistry
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef std::map<uint32, TScript*> ScriptMap;
|
|
||||||
typedef typename ScriptMap::iterator ScriptMapIterator;
|
|
||||||
|
|
||||||
// The actual list of scripts. This will be accessed concurrently, so it must not be modified
|
|
||||||
// after server startup.
|
|
||||||
static ScriptMap ScriptPointerList;
|
|
||||||
|
|
||||||
static void AddScript(TScript* const script)
|
|
||||||
{
|
|
||||||
ASSERT(script);
|
|
||||||
|
|
||||||
// See if the script is using the same memory as another script. If this happens, it means that
|
|
||||||
// someone forgot to allocate new memory for a script.
|
|
||||||
for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
|
|
||||||
{
|
|
||||||
if (it->second == script)
|
|
||||||
{
|
|
||||||
sLog->outError("Script '%s' has same memory pointer as '%s'.",
|
|
||||||
script->GetName().c_str(), it->second->GetName().c_str());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (script->IsDatabaseBound())
|
|
||||||
{
|
|
||||||
// Get an ID for the script. An ID only exists if it's a script that is assigned in the database
|
|
||||||
// through a script name (or similar).
|
|
||||||
uint32 id = sObjectMgr->GetScriptId(script->GetName().c_str());
|
|
||||||
if (id)
|
|
||||||
{
|
|
||||||
// Try to find an existing script.
|
|
||||||
bool existing = false;
|
|
||||||
for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
|
|
||||||
{
|
|
||||||
// If the script names match...
|
|
||||||
if (it->second->GetName() == script->GetName())
|
|
||||||
{
|
|
||||||
// ... It exists.
|
|
||||||
existing = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the script isn't assigned -> assign it!
|
|
||||||
if (!existing)
|
|
||||||
{
|
|
||||||
ScriptPointerList[id] = script;
|
|
||||||
sScriptMgr->IncrementScriptCount();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If the script is already assigned -> delete it!
|
|
||||||
sLog->outError("Script '%s' already assigned with the same script name, so the script can't work.",
|
|
||||||
script->GetName().c_str());
|
|
||||||
|
|
||||||
ABORT(); // Error that should be fixed ASAP.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The script uses a script name from database, but isn't assigned to anything.
|
|
||||||
if (script->GetName().find("example") == std::string::npos && script->GetName().find("Smart") == std::string::npos)
|
|
||||||
sLog->outErrorDb("Script named '%s' does not have a script name assigned in database.",
|
|
||||||
script->GetName().c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// We're dealing with a code-only script; just add it.
|
|
||||||
ScriptPointerList[_scriptIdCounter++] = script;
|
|
||||||
sScriptMgr->IncrementScriptCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets a script by its ID (assigned by ObjectMgr).
|
|
||||||
static TScript* GetScriptById(uint32 id)
|
|
||||||
{
|
|
||||||
ScriptMapIterator it = ScriptPointerList.find(id);
|
|
||||||
if (it != ScriptPointerList.end())
|
|
||||||
return it->second;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Counter used for code-only scripts.
|
|
||||||
static uint32 _scriptIdCounter;
|
|
||||||
};*/
|
|
||||||
|
|
||||||
ScriptMgr::ScriptMgr()
|
ScriptMgr::ScriptMgr()
|
||||||
: _scriptCount(0), _scheduledScripts(0)
|
: _scriptCount(0), _scheduledScripts(0)
|
||||||
{
|
{
|
||||||
@@ -294,7 +197,7 @@ void ScriptMgr::CheckIfScriptsInDatabaseExist()
|
|||||||
!ScriptRegistry<BGScript>::GetScriptById(sid) &&
|
!ScriptRegistry<BGScript>::GetScriptById(sid) &&
|
||||||
!ScriptRegistry<SpellSC>::GetScriptById(sid) &&
|
!ScriptRegistry<SpellSC>::GetScriptById(sid) &&
|
||||||
!ScriptRegistry<GroupScript>::GetScriptById(sid))
|
!ScriptRegistry<GroupScript>::GetScriptById(sid))
|
||||||
sLog->outErrorDb("Script named '%s' is assigned in database, but has no code!", (*itr).c_str());
|
sLog->outErrorDb("Script named '%s' is assigned in the database, but has no code!", (*itr).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1606,7 +1606,7 @@ class ScriptRegistry
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the script is already assigned -> delete it!
|
// If the script is already assigned -> delete it!
|
||||||
sLog->outError("Script '%s' already assigned with the same script name, so the script can't work.",
|
sLog->outError("Script named '%s' is already assigned (two or more scripts have the same name), so the script can't work, aborting...",
|
||||||
script->GetName().c_str());
|
script->GetName().c_str());
|
||||||
|
|
||||||
ABORT(); // Error that should be fixed ASAP.
|
ABORT(); // Error that should be fixed ASAP.
|
||||||
@@ -1616,7 +1616,7 @@ class ScriptRegistry
|
|||||||
{
|
{
|
||||||
// The script uses a script name from database, but isn't assigned to anything.
|
// The script uses a script name from database, but isn't assigned to anything.
|
||||||
if (script->GetName().find("Smart") == std::string::npos)
|
if (script->GetName().find("Smart") == std::string::npos)
|
||||||
sLog->outErrorDb("Script named '%s' does not have a script name assigned in database.",
|
sLog->outErrorDb("Script named '%s' is not assigned in the database.",
|
||||||
script->GetName().c_str());
|
script->GetName().c_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user