[9650] Some corpse related clean ups.

Old bones remove code anyway was dead, so remove it.

Signed-off-by: hunuza <hunuza@gmail.com>
This commit is contained in:
hunuza 2010-03-31 16:40:13 +02:00
parent 8b87c7ec97
commit 6750ce9185
19 changed files with 34 additions and 207 deletions

View file

@ -267,4 +267,12 @@ bool Corpse::IsFriendlyTo( Unit const* unit ) const
return owner->IsFriendlyTo(unit);
else
return true;
}
}
bool Corpse::IsExpired(time_t t) const
{
if(m_type == CORPSE_BONES)
return m_time < t - 60*MINUTE;
else
return m_time < t - 3*DAY;
}

View file

@ -91,6 +91,8 @@ class Corpse : public WorldObject
GridReference<Corpse> &GetGridRef() { return m_gridRef; }
bool isActiveObject() const { return false; }
bool IsExpired(time_t t) const;
private:
GridReference<Corpse> m_gridRef;

View file

@ -1,86 +0,0 @@
/*
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file
\ingroup world
*/
#include "Log.h"
#include "Database/DatabaseEnv.h"
#include "Database/DatabaseImpl.h"
#include "Platform/Define.h"
#include "MapManager.h"
#include "ObjectAccessor.h"
#include "GlobalEvents.h"
#include "ObjectGuid.h"
#include "Corpse.h"
static void CorpsesEraseCallBack(QueryResult *result, bool bones)
{
if(!result)
return;
do
{
Field *fields = result->Fetch();
uint32 guidlow = fields[0].GetUInt32();
float positionX = fields[1].GetFloat();
float positionY = fields[2].GetFloat();
uint32 mapid = fields[3].GetUInt32();
uint64 player_guid = MAKE_NEW_GUID(fields[4].GetUInt32(), 0, HIGHGUID_PLAYER);
uint64 guid = MAKE_NEW_GUID(guidlow, 0, HIGHGUID_CORPSE);
sLog.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones?"bones":"corpse"),guidlow,positionX,positionY,mapid);
/// Resurrectable - convert corpses to bones
if(!bones)
{
if(!sObjectAccessor.ConvertCorpseForPlayer(player_guid))
{
sLog.outDebug("Corpse %u not found in world or bones creating forbidden. Delete from DB.",guidlow);
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
}
else
///- or delete bones
{
sMapMgr.RemoveBonesFromMap(mapid, guid, positionX, positionY);
///- remove bones from the database
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
}
} while (result->NextRow());
delete result;
}
/// Handle periodic erase of corpses and bones
static void CorpsesErase(bool bones,uint32 delay)
{
///- Get the list of eligible corpses/bones to be removed
//No SQL injection (uint32 and enum)
CharacterDatabase.AsyncPQuery(&CorpsesEraseCallBack, bones, "SELECT guid,position_x,position_y,map,player FROM corpse WHERE time < (UNIX_TIMESTAMP()+'%u') AND corpse_type %s '0'", delay, (bones ? "=" : "<>"));
}
/// not thread guarded variant for call from other thread
void CorpsesErase()
{
CorpsesErase(true, 20*MINUTE);
CorpsesErase(false,3*DAY);
}

View file

@ -1,29 +0,0 @@
/*
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/// \addtogroup world
/// @{
/// \file
#ifndef __GLOBALEVENTS_H
#define __GLOBALEVENTS_H
void CorpsesErase();
void HandleCorpsesErase(void*);
#endif
/// @}

View file

@ -41,7 +41,6 @@
#include <iostream>
#include <fstream>
#include <map>
#include "GlobalEvents.h"
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
@ -4200,7 +4199,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult* result, int32 limit)
/// Triggering corpses expire check in world
bool ChatHandler::HandleServerCorpsesCommand(const char* /*args*/)
{
CorpsesErase();
sObjectAccessor.RemoveOldCorpses();
return true;
}

View file

@ -124,8 +124,6 @@ libmangosgame_a_SOURCES = \
GameEventMgr.h \
GameObject.cpp \
GameObject.h \
GlobalEvents.cpp \
GlobalEvents.h \
GMTicketHandler.cpp \
GMTicketMgr.cpp \
GMTicketMgr.h \

View file

@ -765,42 +765,6 @@ void Map::Remove(Player *player, bool remove)
DeleteFromWorld(player);
}
bool Map::RemoveBones(uint64 guid, float x, float y)
{
if (IsRemovalGrid(x, y))
{
Corpse* corpse = ObjectAccessor::GetCorpseInMap(guid,GetId());
if (!corpse)
return false;
CellPair p = MaNGOS::ComputeCellPair(x,y);
if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP )
{
sLog.outError("Map::RemoveBones: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord);
return false;
}
CellPair q = MaNGOS::ComputeCellPair(corpse->GetPositionX(),corpse->GetPositionY());
if(q.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || q.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP )
{
sLog.outError("Map::RemoveBones: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", corpse->GetGUIDLow(), corpse->GetTypeId(), corpse->GetPositionX(), corpse->GetPositionY(), q.x_coord, q.y_coord);
return false;
}
int32 dx = int32(p.x_coord) - int32(q.x_coord);
int32 dy = int32(p.y_coord) - int32(q.y_coord);
if (dx <= -2 || dx >= 2 || dy <= -2 || dy >= 2)
return false;
if(corpse && corpse->GetTypeId() == TYPEID_CORPSE && corpse->GetType() == CORPSE_BONES)
corpse->DeleteBonesFromWorld();
else
return false;
}
return true;
}
template<class T>
void
Map::Remove(T *obj, bool remove)

View file

@ -361,8 +361,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
void AddObjectToRemoveList(WorldObject *obj);
virtual bool RemoveBones(uint64 guid, float x, float y);
void UpdateObjectVisibility(WorldObject* obj, Cell cell, CellPair cellpair);
void UpdatePlayerVisibility(Player* player, Cell cell, CellPair cellpair);
void UpdateObjectsVisibilityFor(Player* player, Cell cell, CellPair cellpair);

View file

@ -76,18 +76,6 @@ void MapInstanced::RemoveAllObjectsInRemoveList()
Map::RemoveAllObjectsInRemoveList();
}
bool MapInstanced::RemoveBones(uint64 guid, float x, float y)
{
bool remove_result = false;
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
{
remove_result = remove_result || i->second->RemoveBones(guid, x, y);
}
return remove_result || Map::RemoveBones(guid,x,y);
}
void MapInstanced::UnloadAll(bool pForce)
{
// Unload instanced maps

View file

@ -35,7 +35,6 @@ class MANGOS_DLL_DECL MapInstanced : public Map
// functions overwrite Map versions
void Update(const uint32&);
void RemoveAllObjectsInRemoveList();
bool RemoveBones(uint64 guid, float x, float y);
void UnloadAll(bool pForce);
Map* CreateInstance(const uint32 mapId, Player * player);

View file

@ -249,16 +249,6 @@ void MapManager::DeleteInstance(uint32 mapid, uint32 instanceId)
((MapInstanced*)m)->DestroyInstance(instanceId);
}
void MapManager::RemoveBonesFromMap(uint32 mapid, uint64 guid, float x, float y)
{
bool remove_result = _createBaseMap(mapid)->RemoveBones(guid, x, y);
if (!remove_result)
{
sLog.outDebug("Bones %u not found in world. Delete from DB also.", GUID_LOPART(guid));
}
}
void
MapManager::Update(uint32 diff)
{

View file

@ -121,7 +121,6 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
TransportMap m_TransportsByMap;
bool CanPlayerEnter(uint32 mapid, Player* player);
void RemoveBonesFromMap(uint32 mapid, uint64 guid, float x, float y);
uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
void InitMaxInstanceId();
void InitializeVisibilityDistanceInfo();

View file

@ -258,6 +258,22 @@ ObjectAccessor::ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia)
return bones;
}
void ObjectAccessor::RemoveOldCorpses()
{
time_t now = time(NULL);
Player2CorpsesMapType::iterator next;
for(Player2CorpsesMapType::iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); itr = next)
{
next = itr;
++next;
if(!itr->second->IsExpired(now))
continue;
ConvertCorpseForPlayer(itr->first);
}
}
/// Define the static member of HashMapHolder
template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap;

View file

@ -117,6 +117,7 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor,
void AddCorpse(Corpse* corpse);
void AddCorpsesToGrid(GridPair const& gridpair,GridType& grid,Map* map);
Corpse* ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia = false);
void RemoveOldCorpses();
// For call from Player/Corpse AddToWorld/RemoveFromWorld only
void AddObject(Corpse *object) { HashMapHolder<Corpse>::Insert(object); }

View file

@ -51,7 +51,6 @@
#include "BattleGroundMgr.h"
#include "TemporarySummon.h"
#include "VMapFactory.h"
#include "GlobalEvents.h"
#include "GameEventMgr.h"
#include "PoolManager.h"
#include "Database/DatabaseImpl.h"
@ -894,8 +893,8 @@ void World::SetInitialWorldSettings()
uint32 realm_zone = getConfig(CONFIG_UINT32_REALM_ZONE);
loginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID);
///- Remove the bones after a restart
CharacterDatabase.Execute("DELETE FROM corpse WHERE corpse_type = '0'");
///- Remove the bones (they should not exist in DB though) and old corpses after a restart
CharacterDatabase.PExecute("DELETE FROM corpse WHERE corpse_type = '0' OR time < (UNIX_TIMESTAMP()-'%u')", 3*DAY);
///- Load the DBC files
sLog.outString("Initialize data stores...");
@ -1233,8 +1232,7 @@ void World::SetInitialWorldSettings()
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS);
m_timers[WUPDATE_UPTIME].SetInterval(m_configUint32Values[CONFIG_UINT32_UPTIME_UPDATE]*MINUTE*IN_MILLISECONDS);
//Update "uptime" table based on configuration entry in minutes.
m_timers[WUPDATE_CORPSES].SetInterval(20*MINUTE*IN_MILLISECONDS);
//erase corpses every 20 minutes
m_timers[WUPDATE_CORPSES].SetInterval(3*HOUR*IN_MILLISECONDS);
//to set mailtimer to return mails every day between 4 and 5 am
//mailtimer is increased when updating auctions
@ -1417,7 +1415,7 @@ void World::Update(uint32 diff)
{
m_timers[WUPDATE_CORPSES].Reset();
CorpsesErase();
sObjectAccessor.RemoveOldCorpses();
}
///- Process Game events when necessary

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9649"
#define REVISION_NR "9650"
#endif // __REVISION_NR_H__

View file

@ -394,7 +394,6 @@
<ClCompile Include="..\..\src\game\FollowerReference.cpp" />
<ClCompile Include="..\..\src\game\GameEventMgr.cpp" />
<ClCompile Include="..\..\src\game\GameObject.cpp" />
<ClCompile Include="..\..\src\game\GlobalEvents.cpp" />
<ClCompile Include="..\..\src\game\GMTicketHandler.cpp" />
<ClCompile Include="..\..\src\game\GMTicketMgr.cpp" />
<ClCompile Include="..\..\src\game\GossipDef.cpp" />
@ -543,7 +542,6 @@
<ClInclude Include="..\..\src\game\Formulas.h" />
<ClInclude Include="..\..\src\game\GameEventMgr.h" />
<ClInclude Include="..\..\src\game\GameObject.h" />
<ClInclude Include="..\..\src\game\GlobalEvents.h" />
<ClInclude Include="..\..\src\game\GMTicketMgr.h" />
<ClInclude Include="..\..\src\game\GossipDef.h" />
<ClInclude Include="..\..\src\game\GridDefines.h" />

View file

@ -1469,14 +1469,6 @@
RelativePath="..\..\src\game\DBCStructure.h"
>
</File>
<File
RelativePath="..\..\src\game\GlobalEvents.cpp"
>
</File>
<File
RelativePath="..\..\src\game\GlobalEvents.h"
>
</File>
<File
RelativePath="..\..\src\game\Opcodes.cpp"
>

View file

@ -1470,14 +1470,6 @@
RelativePath="..\..\src\game\DBCStructure.h"
>
</File>
<File
RelativePath="..\..\src\game\GlobalEvents.cpp"
>
</File>
<File
RelativePath="..\..\src\game\GlobalEvents.h"
>
</File>
<File
RelativePath="..\..\src\game\Opcodes.cpp"
>