From 6750ce9185fdfa9c3be49d154d34e59be4a2e99a Mon Sep 17 00:00:00 2001 From: hunuza Date: Wed, 31 Mar 2010 16:40:13 +0200 Subject: [PATCH] [9650] Some corpse related clean ups. Old bones remove code anyway was dead, so remove it. Signed-off-by: hunuza --- src/game/Corpse.cpp | 10 ++++- src/game/Corpse.h | 2 + src/game/GlobalEvents.cpp | 86 ------------------------------------- src/game/GlobalEvents.h | 29 ------------- src/game/Level2.cpp | 3 +- src/game/Makefile.am | 2 - src/game/Map.cpp | 36 ---------------- src/game/Map.h | 2 - src/game/MapInstanced.cpp | 12 ------ src/game/MapInstanced.h | 1 - src/game/MapManager.cpp | 10 ----- src/game/MapManager.h | 1 - src/game/ObjectAccessor.cpp | 16 +++++++ src/game/ObjectAccessor.h | 1 + src/game/World.cpp | 10 ++--- src/shared/revision_nr.h | 2 +- win/VC100/game.vcxproj | 2 - win/VC80/game.vcproj | 8 ---- win/VC90/game.vcproj | 8 ---- 19 files changed, 34 insertions(+), 207 deletions(-) delete mode 100644 src/game/GlobalEvents.cpp delete mode 100644 src/game/GlobalEvents.h diff --git a/src/game/Corpse.cpp b/src/game/Corpse.cpp index e04ca300a..3beb2bda6 100644 --- a/src/game/Corpse.cpp +++ b/src/game/Corpse.cpp @@ -267,4 +267,12 @@ bool Corpse::IsFriendlyTo( Unit const* unit ) const return owner->IsFriendlyTo(unit); else return true; -} \ No newline at end of file +} + +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; +} diff --git a/src/game/Corpse.h b/src/game/Corpse.h index 4cbeb6d79..e01523850 100644 --- a/src/game/Corpse.h +++ b/src/game/Corpse.h @@ -91,6 +91,8 @@ class Corpse : public WorldObject GridReference &GetGridRef() { return m_gridRef; } bool isActiveObject() const { return false; } + + bool IsExpired(time_t t) const; private: GridReference m_gridRef; diff --git a/src/game/GlobalEvents.cpp b/src/game/GlobalEvents.cpp deleted file mode 100644 index 910c68f2b..000000000 --- a/src/game/GlobalEvents.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2005-2010 MaNGOS - * - * 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); -} diff --git a/src/game/GlobalEvents.h b/src/game/GlobalEvents.h deleted file mode 100644 index 563375852..000000000 --- a/src/game/GlobalEvents.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2005-2010 MaNGOS - * - * 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 -/// @} diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 462ae23c1..a10259c89 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -41,7 +41,6 @@ #include #include #include -#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; } diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 39d6982e1..abce5db3b 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -124,8 +124,6 @@ libmangosgame_a_SOURCES = \ GameEventMgr.h \ GameObject.cpp \ GameObject.h \ - GlobalEvents.cpp \ - GlobalEvents.h \ GMTicketHandler.cpp \ GMTicketMgr.cpp \ GMTicketMgr.h \ diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 4586ebc86..0ec96ec2c 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -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 void Map::Remove(T *obj, bool remove) diff --git a/src/game/Map.h b/src/game/Map.h index 30d34dd0b..a73cdee90 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -361,8 +361,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, 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); diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp index 19e74eabd..16516413e 100644 --- a/src/game/MapInstanced.cpp +++ b/src/game/MapInstanced.cpp @@ -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 diff --git a/src/game/MapInstanced.h b/src/game/MapInstanced.h index df2bb9834..79dca285b 100644 --- a/src/game/MapInstanced.h +++ b/src/game/MapInstanced.h @@ -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); diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 3240a05b7..f493605aa 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -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) { diff --git a/src/game/MapManager.h b/src/game/MapManager.h index a72e30185..c07a7c11a 100644 --- a/src/game/MapManager.h +++ b/src/game/MapManager.h @@ -121,7 +121,6 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singletonsecond->IsExpired(now)) + continue; + + ConvertCorpseForPlayer(itr->first); + } +} + /// Define the static member of HashMapHolder template UNORDERED_MAP< uint64, T* > HashMapHolder::m_objectMap; diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index e704f10fe..2853d6097 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -117,6 +117,7 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton::Insert(object); } diff --git a/src/game/World.cpp b/src/game/World.cpp index 29957cb89..5924b0f0c 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -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 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index fd7738aec..f42f7ecac 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9649" + #define REVISION_NR "9650" #endif // __REVISION_NR_H__ diff --git a/win/VC100/game.vcxproj b/win/VC100/game.vcxproj index 7f9ba21ae..d4f3331f8 100644 --- a/win/VC100/game.vcxproj +++ b/win/VC100/game.vcxproj @@ -394,7 +394,6 @@ - @@ -543,7 +542,6 @@ - diff --git a/win/VC80/game.vcproj b/win/VC80/game.vcproj index 49835dc06..e7f36ea12 100644 --- a/win/VC80/game.vcproj +++ b/win/VC80/game.vcproj @@ -1469,14 +1469,6 @@ RelativePath="..\..\src\game\DBCStructure.h" > - - - - diff --git a/win/VC90/game.vcproj b/win/VC90/game.vcproj index d0dea11a7..db84c571b 100644 --- a/win/VC90/game.vcproj +++ b/win/VC90/game.vcproj @@ -1470,14 +1470,6 @@ RelativePath="..\..\src\game\DBCStructure.h" > - - - -