Exemple #1
0
    // 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;
    }
Exemple #2
0
        static void Add(TScript* script)
        {
            if (m_scripts.find(script->GetScriptName()) != m_scripts.end())
                Assert(true, FS("ScriptRegistry<T>::Add Script '%%%' is already in holder!", script->GetScriptName()));

            // Check pointer has?

            m_mutex.lock();
            m_scripts[script->GetScriptName()] = script;
            m_mutex.unlock();
        }
Exemple #3
0
QScriptValue ScriptMapToScriptValue(QScriptEngine* eng, const ScriptMap& map)
{
  QScriptValue a = eng->newObject();
  ScriptMap::const_iterator it(map.begin());
  for(; it != map.end(); ++it)
  {
    QString prop = it.key();
    prop.replace(' ', '_');
    a.setProperty(prop, qScriptValueFromValue(eng, it.value()));
  }
  return a;
}
Exemple #4
0
        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());

                        ASSERT(false); // 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();
            }
        }
        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)
                {
                    TC_LOG_ERROR("scripts", "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!
                        TC_LOG_ERROR("scripts", "Script '%s' already assigned with the same script name, so the script can't work.",
                            script->GetName().c_str());

                        ASSERT(false); // Error that should be fixed ASAP.
                    }
                }
                else
                {
                    // The script uses a script name from database, but isn't assigned to anything.
                    TC_LOG_ERROR("sql.sql", "Script named '%s' does not have a script name assigned in database.", script->GetName().c_str());

                    // 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

                    return;
                }
            }
            else
            {
                // We're dealing with a code-only script; just add it.
                ScriptPointerList[_scriptIdCounter++] = script;
                sScriptMgr->IncrementScriptCount();
            }
        }
Exemple #6
0
 static TScript* Get(std::string const& scriptName)
 {
     ScriptMap::iterator it = m_scripts.find(scriptName);
     return it != m_scripts.end() ? it->second : nullptr;
 }
Exemple #7
0
 static void Remove(TScript* script)
 {
     m_mutex.lock();
     m_scripts.erase(script->GetScriptName());
     m_mutex.unlock();
 }