Core: Fixed occasional wrong order of async operations at respawn time saving. Closes issue #5239.

DB schema: Sorted out a discrepancy in respawn time column format.

--HG--
branch : trunk
This commit is contained in:
Xanadu
2010-12-23 05:49:23 +01:00
parent 66b4c8003c
commit cfa26522ad
10 changed files with 79 additions and 33 deletions
@@ -1577,7 +1577,7 @@ void Battleground::SpawnBGCreature(uint32 type, uint32 respawntime)
{
//obj->Respawn(); // bugged
obj->SetRespawnTime(0);
sObjectMgr->SaveCreatureRespawnTime(obj->GetGUIDLow(), GetInstanceID(), 0);
sObjectMgr->RemoveCreatureRespawnTime(obj->GetGUIDLow(), GetInstanceID());
map->Add(obj);
}
}
@@ -1396,7 +1396,7 @@ void Creature::DeleteFromDB()
return;
}
sObjectMgr->SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
sObjectMgr->RemoveCreatureRespawnTime(m_DBTableGuid, GetInstanceId());
sObjectMgr->DeleteCreatureData(m_DBTableGuid);
SQLTransaction trans = WorldDatabase.BeginTransaction();
@@ -1587,7 +1587,7 @@ void Creature::Respawn(bool force)
if (getDeathState() == DEAD)
{
if (m_DBTableGuid)
sObjectMgr->SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0);
sObjectMgr->RemoveCreatureRespawnTime(m_DBTableGuid, GetInstanceId());
sLog.outStaticDebug("Respawning...");
m_respawnTime = 0;
@@ -742,7 +742,7 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
if (m_respawnTime && m_respawnTime <= time(NULL))
{
m_respawnTime = 0;
sObjectMgr->SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
sObjectMgr->RemoveGORespawnTime(m_DBTableGuid, GetInstanceId());
}
}
}
@@ -760,7 +760,7 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
void GameObject::DeleteFromDB()
{
sObjectMgr->SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
sObjectMgr->RemoveGORespawnTime(m_DBTableGuid, GetInstanceId());
sObjectMgr->DeleteGOData(m_DBTableGuid);
WorldDatabase.PExecute("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
WorldDatabase.PExecute("DELETE FROM game_event_gameobject WHERE guid = '%u'", m_DBTableGuid);
@@ -853,7 +853,7 @@ void GameObject::Respawn()
if (m_spawnedByDefault && m_respawnTime > 0)
{
m_respawnTime = time(NULL);
sObjectMgr->SaveGORespawnTime(m_DBTableGuid,GetInstanceId(),0);
sObjectMgr->RemoveGORespawnTime(m_DBTableGuid, GetInstanceId());
}
}
+57 -19
View File
@@ -1842,9 +1842,9 @@ void ObjectMgr::LoadGameobjectRespawnTimes()
{
uint32 oldMSTime = getMSTime();
// remove outdated data
PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GAMEOBJECT_RESPAWN_TIMES);
CharacterDatabase.Execute(stmt);
// Remove outdated data
PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_EXPIRED_GO_RESPAWN_TIMES);
CharacterDatabase.DirectExecute(stmt);
uint32 count = 0;
@@ -7459,26 +7459,40 @@ void ObjectMgr::LoadNPCSpellClickSpells()
void ObjectMgr::SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t)
{
// This function can be Called from various map threads concurrently
if (!t)
{
// Delete only
RemoveCreatureRespawnTime(loguid, instance);
return;
}
// This function can be called from various map threads concurrently
{
m_CreatureRespawnTimesMtx.acquire();
mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)] = t;
mCreatureRespawnTimes[MAKE_PAIR64(loguid, instance)] = t;
m_CreatureRespawnTimesMtx.release();
}
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CRESPAWNTIME);
PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_CREATURE_RESPAWN_TIME);
stmt->setUInt32(0, loguid);
stmt->setUInt64(1, uint64(t));
stmt->setUInt32(2, instance);
CharacterDatabase.Execute(stmt);
}
void ObjectMgr::RemoveCreatureRespawnTime(uint32 loguid, uint32 instance)
{
// This function can be called from various map threads concurrently
{
m_CreatureRespawnTimesMtx.acquire();
mCreatureRespawnTimes[MAKE_PAIR64(loguid, instance)] = 0;
m_CreatureRespawnTimesMtx.release();
}
PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CREATURE_RESPAWN_TIME);
stmt->setUInt32(0, loguid);
stmt->setUInt32(1, instance);
CharacterDatabase.Execute(stmt);
if (t)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_CRESPAWNTIME);
stmt->setUInt32(0, loguid);
stmt->setUInt64(1, uint64(t));
stmt->setUInt32(2, instance);
CharacterDatabase.Execute(stmt);
}
}
void ObjectMgr::DeleteCreatureData(uint32 guid)
@@ -7493,16 +7507,40 @@ void ObjectMgr::DeleteCreatureData(uint32 guid)
void ObjectMgr::SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t)
{
if (!t)
{
// Delete only
RemoveGORespawnTime(loguid, instance);
return;
}
// This function can be called from different map threads concurrently
{
m_GORespawnTimesMtx.acquire();
mGORespawnTimes[MAKE_PAIR64(loguid,instance)] = t;
mGORespawnTimes[MAKE_PAIR64(loguid, instance)] = t;
m_GORespawnTimesMtx.release();
}
CharacterDatabase.PExecute("DELETE FROM gameobject_respawn WHERE guid = '%u' AND instance = '%u'", loguid, instance);
if (t)
CharacterDatabase.PExecute("INSERT INTO gameobject_respawn VALUES ('%u', '" UI64FMTD "', '%u')", loguid, uint64(t), instance);
PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GO_RESPAWN_TIME);
stmt->setUInt32(0, loguid);
stmt->setUInt64(1, uint64(t));
stmt->setUInt32(2, instance);
CharacterDatabase.Execute(stmt);
}
void ObjectMgr::RemoveGORespawnTime(uint32 loguid, uint32 instance)
{
// This function can be called from different map threads concurrently
{
m_GORespawnTimesMtx.acquire();
mGORespawnTimes[MAKE_PAIR64(loguid, instance)] = 0;
m_GORespawnTimesMtx.release();
}
PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GO_RESPAWN_TIME);
stmt->setUInt32(0, loguid);
stmt->setUInt32(1, instance);
CharacterDatabase.Execute(stmt);
}
void ObjectMgr::DeleteRespawnTimeForInstance(uint32 instance)
+2
View File
@@ -1079,12 +1079,14 @@ class ObjectMgr
return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)];
}
void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
void RemoveCreatureRespawnTime(uint32 loguid, uint32 instance);
time_t GetGORespawnTime(uint32 loguid, uint32 instance)
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_GORespawnTimesMtx, 0);
return mGORespawnTimes[MAKE_PAIR64(loguid,instance)];
}
void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
void RemoveGORespawnTime(uint32 loguid, uint32 instance);
void DeleteRespawnTimeForInstance(uint32 instance);
// grid objects