[10503] Move *_respawn tables to characters DB.

This allow have in `mangos` DB only world static state data.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
zergtmn 2010-09-19 00:41:32 +04:00 committed by VladimirMangos
parent c5b0593855
commit 20f4a16f01
12 changed files with 102 additions and 107 deletions

View file

@ -288,8 +288,8 @@ BattleGround::~BattleGround()
if (GetInstanceID()) // not spam by useless queries in case BG templates
{
// delete creature and go respawn times
WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE instance = '%u'",GetInstanceID());
WorldDatabase.PExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'",GetInstanceID());
CharacterDatabase.PExecute("DELETE FROM creature_respawn WHERE instance = '%u'", GetInstanceID());
CharacterDatabase.PExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", GetInstanceID());
// delete instance from db
CharacterDatabase.PExecute("DELETE FROM instance WHERE id = '%u'",GetInstanceID());
// remove from battlegrounds

View file

@ -169,7 +169,7 @@ void InstanceResetScheduler::LoadResetTimes()
delete result;
// update reset time for normal instances with the max creature respawn time + X hours
result = WorldDatabase.Query("SELECT MAX(respawntime), instance FROM creature_respawn WHERE instance > 0 GROUP BY instance");
result = CharacterDatabase.Query("SELECT MAX(respawntime), instance FROM creature_respawn WHERE instance > 0 GROUP BY instance");
if( result )
{
do
@ -482,52 +482,13 @@ void InstanceSaveManager::CleanupInstances()
_DelHelper(CharacterDatabase, "character_instance.guid, instance", "character_instance", "LEFT JOIN instance ON character_instance.instance = instance.id WHERE instance.id IS NULL");
_DelHelper(CharacterDatabase, "group_instance.leaderGuid, instance", "group_instance", "LEFT JOIN instance ON group_instance.instance = instance.id WHERE instance.id IS NULL");
// creature_respawn and gameobject_respawn are in another database
// first, obtain total instance set
std::set<uint32> InstanceSet;
QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance");
if( result )
{
do
{
Field *fields = result->Fetch();
InstanceSet.insert(fields[0].GetUInt32());
}
while (result->NextRow());
delete result;
}
// creature_respawn
result = WorldDatabase.Query("SELECT DISTINCT(instance) FROM creature_respawn WHERE instance <> 0");
if( result )
{
do
{
Field *fields = result->Fetch();
if(InstanceSet.find(fields[0].GetUInt32()) == InstanceSet.end())
WorldDatabase.DirectPExecute("DELETE FROM creature_respawn WHERE instance = '%u'", fields[0].GetUInt32());
}
while (result->NextRow());
delete result;
}
// gameobject_respawn
result = WorldDatabase.Query("SELECT DISTINCT(instance) FROM gameobject_respawn WHERE instance <> 0");
if( result )
{
do
{
Field *fields = result->Fetch();
if(InstanceSet.find(fields[0].GetUInt32()) == InstanceSet.end())
WorldDatabase.DirectPExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", fields[0].GetUInt32());
}
while (result->NextRow());
delete result;
}
// clean unused respawn data
CharacterDatabase.DirectExecute("DELETE FROM creature_respawn WHERE instance <> 0 AND instance NOT IN (SELECT id FROM instance)");
CharacterDatabase.DirectExecute("DELETE FROM gameobject_respawn WHERE instance <> 0 AND instance NOT IN (SELECT id FROM instance)");
bar.step();
sLog.outString();
sLog.outString( ">> Initialized %u instances", (uint32)InstanceSet.size());
sLog.outString( ">> Instances cleaned up");
}
void InstanceSaveManager::PackInstances()
@ -563,8 +524,8 @@ void InstanceSaveManager::PackInstances()
if (*i != InstanceNumber)
{
// remap instance id
WorldDatabase.PExecute("UPDATE creature_respawn SET instance = '%u' WHERE instance = '%u'", InstanceNumber, *i);
WorldDatabase.PExecute("UPDATE gameobject_respawn SET instance = '%u' WHERE instance = '%u'", InstanceNumber, *i);
CharacterDatabase.PExecute("UPDATE creature_respawn SET instance = '%u' WHERE instance = '%u'", InstanceNumber, *i);
CharacterDatabase.PExecute("UPDATE gameobject_respawn SET instance = '%u' WHERE instance = '%u'", InstanceNumber, *i);
CharacterDatabase.PExecute("UPDATE corpse SET instance = '%u' WHERE instance = '%u'", InstanceNumber, *i);
CharacterDatabase.PExecute("UPDATE character_instance SET instance = '%u' WHERE instance = '%u'", InstanceNumber, *i);
CharacterDatabase.PExecute("UPDATE instance SET id = '%u' WHERE id = '%u'", InstanceNumber, *i);

View file

@ -1557,11 +1557,11 @@ void ObjectMgr::RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data
void ObjectMgr::LoadCreatureRespawnTimes()
{
// remove outdated data
WorldDatabase.DirectExecute("DELETE FROM creature_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
CharacterDatabase.DirectExecute("DELETE FROM creature_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
uint32 count = 0;
QueryResult *result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM creature_respawn");
QueryResult *result = CharacterDatabase.Query("SELECT guid, respawntime, instance FROM creature_respawn");
if(!result)
{
@ -1599,11 +1599,11 @@ void ObjectMgr::LoadCreatureRespawnTimes()
void ObjectMgr::LoadGameobjectRespawnTimes()
{
// remove outdated data
WorldDatabase.DirectExecute("DELETE FROM gameobject_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
CharacterDatabase.DirectExecute("DELETE FROM gameobject_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())");
uint32 count = 0;
QueryResult *result = WorldDatabase.Query("SELECT guid,respawntime,instance FROM gameobject_respawn");
QueryResult *result = CharacterDatabase.Query("SELECT guid, respawntime, instance FROM gameobject_respawn");
if(!result)
{
@ -7184,9 +7184,9 @@ void ObjectMgr::LoadWeatherZoneChances()
void ObjectMgr::SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t)
{
mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)] = t;
WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE guid = '%u' AND instance = '%u'", loguid, instance);
CharacterDatabase.PExecute("DELETE FROM creature_respawn WHERE guid = '%u' AND instance = '%u'", loguid, instance);
if(t)
WorldDatabase.PExecute("INSERT INTO creature_respawn VALUES ( '%u', '" UI64FMTD "', '%u' )", loguid, uint64(t), instance);
CharacterDatabase.PExecute("INSERT INTO creature_respawn VALUES ( '%u', '" UI64FMTD "', '%u' )", loguid, uint64(t), instance);
}
void ObjectMgr::DeleteCreatureData(uint32 guid)
@ -7202,9 +7202,9 @@ void ObjectMgr::DeleteCreatureData(uint32 guid)
void ObjectMgr::SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t)
{
mGORespawnTimes[MAKE_PAIR64(loguid,instance)] = t;
WorldDatabase.PExecute("DELETE FROM gameobject_respawn WHERE guid = '%u' AND instance = '%u'", loguid, instance);
CharacterDatabase.PExecute("DELETE FROM gameobject_respawn WHERE guid = '%u' AND instance = '%u'", loguid, instance);
if(t)
WorldDatabase.PExecute("INSERT INTO gameobject_respawn VALUES ( '%u', '" UI64FMTD "', '%u' )", loguid, uint64(t), instance);
CharacterDatabase.PExecute("INSERT INTO gameobject_respawn VALUES ( '%u', '" UI64FMTD "', '%u' )", loguid, uint64(t), instance);
}
void ObjectMgr::DeleteRespawnTimeForInstance(uint32 instance)
@ -7229,8 +7229,8 @@ void ObjectMgr::DeleteRespawnTimeForInstance(uint32 instance)
mCreatureRespawnTimes.erase(itr);
}
WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE instance = '%u'", instance);
WorldDatabase.PExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", instance);
CharacterDatabase.PExecute("DELETE FROM creature_respawn WHERE instance = '%u'", instance);
CharacterDatabase.PExecute("DELETE FROM gameobject_respawn WHERE instance = '%u'", instance);
}
void ObjectMgr::DeleteGOData(uint32 guid)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10502"
#define REVISION_NR "10503"
#endif // __REVISION_NR_H__

View file

@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_10332_02_characters_pet_aura"
#define REVISION_DB_MANGOS "required_10500_01_mangos_scripts"
#define REVISION_DB_CHARACTERS "required_10503_02_characters_gameobject_respawn"
#define REVISION_DB_MANGOS "required_10503_04_mangos_gameobject_respawn"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__