diff options
| author | leak <leakzx@googlemail.com> | 2011-05-02 21:59:57 +0200 | 
|---|---|---|
| committer | leak <leakzx@googlemail.com> | 2011-05-02 22:04:35 +0200 | 
| commit | d64c6ad55aa04fbf2f66c8012a1ec5679b1d0cd0 (patch) | |
| tree | 94e361b85da59056f39fb20df5beddf3583cf30b /src | |
| parent | ba578f6cfeb8fab2296f788006bbf8f2293494f8 (diff) | |
Core/Instances: Kill weird SQL generator function and fix cleaning of expired instances
Diffstat (limited to 'src')
| -rwxr-xr-x | src/server/game/Instances/InstanceSaveMgr.cpp | 37 | ||||
| -rwxr-xr-x | src/server/game/Instances/InstanceSaveMgr.h | 1 | 
2 files changed, 4 insertions, 34 deletions
diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index d75b3dd4d88..62cc1843d9f 100755 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -227,39 +227,14 @@ bool InstanceSave::UnloadIfEmpty()          return true;  } -void InstanceSaveManager::_DelHelper(const char *fields, const char *table, const char *queryTail, ...) -{ -    Tokens fieldTokens(fields, ','); -    ASSERT(fieldTokens.size() != 0); - -    va_list ap; -    char szQueryTail [MAX_QUERY_LEN]; -    va_start(ap, queryTail); -    vsnprintf(szQueryTail, MAX_QUERY_LEN, queryTail, ap); -    va_end(ap); - -    QueryResult result = CharacterDatabase.PQuery("SELECT %s FROM %s %s", fields, table, szQueryTail); -    if (result) -    { -        do -        { -            Field *fields = result->Fetch(); -            std::ostringstream ss; -            for (size_t i = 0; i < fieldTokens.size(); i++) -            { -                std::string fieldValue = fields[i].GetString(); -                CharacterDatabase.escape_string(fieldValue); -                ss << (i != 0 ? " AND " : "") << fieldTokens[i] << " = '" << fieldValue << "'"; -            } -            CharacterDatabase.DirectPExecute("DELETE FROM %s WHERE %s", table, ss.str().c_str()); -        } while (result->NextRow()); -    } -} -  void InstanceSaveManager::LoadInstances()  {      uint32 oldMSTime = getMSTime(); +    // Delete expired instances (Instance related spawns are removed in the following cleanup queries) +    CharacterDatabase.DirectExecute("DELETE i FROM instance i LEFT JOIN instance_reset ir ON mapid = map AND i.difficulty = ir.difficulty " +                                    "WHERE (i.resettime > 0 AND i.resettime < UNIX_TIMESTAMP()) OR (ir.resettime IS NOT NULL AND ir.resettime < UNIX_TIMESTAMP())"); +      // Delete invalid character_instance and group_instance references      CharacterDatabase.DirectExecute("DELETE ci.* FROM character_instance AS ci LEFT JOIN characters AS c ON ci.guid = c.guid WHERE c.guid IS NULL");      CharacterDatabase.DirectExecute("DELETE gi.* FROM group_instance     AS gi LEFT JOIN groups     AS g ON gi.guid = g.guid WHERE g.guid IS NULL"); @@ -386,10 +361,6 @@ void InstanceSaveManager::LoadResetTimes()          } while (result->NextRow());      } -    // clean expired instances, references to them will be deleted in CleanupInstances -    // must be done before calculating new reset times -    _DelHelper("id, map, instance.difficulty", "instance", "LEFT JOIN instance_reset ON mapid = map AND instance.difficulty =  instance_reset.difficulty WHERE (instance.resettime < '"UI64FMTD"' AND instance.resettime > '0') OR (NOT instance_reset.resettime IS NULL AND instance_reset.resettime < '"UI64FMTD"')",  (uint64)now, (uint64)now); -      ResetTimeMapDiffInstances::const_iterator in_itr;      // calculate new global reset times for expired instances and those that have never been reset yet diff --git a/src/server/game/Instances/InstanceSaveMgr.h b/src/server/game/Instances/InstanceSaveMgr.h index 810ff6efedb..2d2aeb3d38f 100755 --- a/src/server/game/Instances/InstanceSaveMgr.h +++ b/src/server/game/Instances/InstanceSaveMgr.h @@ -179,7 +179,6 @@ class InstanceSaveManager          void _ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, time_t resetTime);          void _ResetInstance(uint32 mapid, uint32 instanceId);          void _ResetSave(InstanceSaveHashMap::iterator &itr); -        void _DelHelper(const char *fields, const char *table, const char *queryTail, ...);          // used during global instance resets          bool lock_instLists;          // fast lookup by instance id  | 
