* Corpse related cleanup (author: Hunuza)
* Avoid saving of the corpse in arenas (author: VladimirMangos) --HG-- branch : trunk
This commit is contained in:
@@ -40,7 +40,6 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include "GlobalEvents.h"
|
||||
#include "OutdoorPvPMgr.h"
|
||||
#include "Transport.h"
|
||||
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
|
||||
@@ -3822,7 +3821,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 li
|
||||
return false;
|
||||
}
|
||||
|
||||
int i =0;
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
@@ -3863,7 +3862,7 @@ bool ChatHandler::LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 li
|
||||
/// Triggering corpses expire check in world
|
||||
bool ChatHandler::HandleServerCorpsesCommand(const char* /*args*/)
|
||||
{
|
||||
CorpsesErase();
|
||||
sObjectAccessor.RemoveOldCorpses();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,3 +217,10 @@ bool Corpse::isVisibleForInState(Player const* u, bool inVisibleList) const
|
||||
return IsInWorld() && u->IsInWorld() && IsWithinDistInMap(u->m_seer, World::GetMaxVisibleDistanceForObject() + (inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,8 @@ class Corpse : public WorldObject, public GridObject<Corpse>
|
||||
void Whisper(int32 textId,uint64 receiver) { MonsterWhisper(textId,receiver); }
|
||||
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
|
||||
|
||||
bool IsExpired(time_t t) const;
|
||||
|
||||
private:
|
||||
CorpseType m_type;
|
||||
time_t m_time;
|
||||
|
||||
@@ -4834,10 +4834,8 @@ void Player::CreateCorpse()
|
||||
}
|
||||
}
|
||||
|
||||
// we don't SaveToDB for players in battlegrounds so don't do it for corpses either
|
||||
const MapEntry *entry = sMapStore.LookupEntry(corpse->GetMapId());
|
||||
ASSERT(entry);
|
||||
if (entry->map_type != MAP_BATTLEGROUND)
|
||||
// we do not need to save corpses for BG/arenas
|
||||
if (!GetMap()->IsBattleGroundOrArena())
|
||||
corpse->SaveToDB();
|
||||
|
||||
// register for player, but not show
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
||||
*
|
||||
* 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 "DatabaseEnv.h"
|
||||
#include "DatabaseImpl.h"
|
||||
#include "Define.h"
|
||||
#include "MapManager.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "GlobalEvents.h"
|
||||
#include "ObjectDefines.h"
|
||||
#include "Corpse.h"
|
||||
|
||||
static void CorpsesEraseCallBack(QueryResult_AutoPtr 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());
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
||||
*
|
||||
* 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
|
||||
/// @}
|
||||
|
||||
@@ -343,6 +343,22 @@ Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool /*insign
|
||||
*/
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectAccessor::Update(uint32 /*diff*/)
|
||||
{
|
||||
UpdateDataMapType update_players;
|
||||
|
||||
@@ -252,6 +252,7 @@ class ObjectAccessor
|
||||
void AddCorpse(Corpse* corpse);
|
||||
void AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map);
|
||||
Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);
|
||||
void RemoveOldCorpses();
|
||||
|
||||
typedef ACE_Thread_Mutex LockType;
|
||||
|
||||
|
||||
@@ -823,19 +823,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 = sObjectAccessor.GetObjectInWorld(GetId(), x, y, guid, (Corpse*)NULL);
|
||||
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)
|
||||
|
||||
@@ -390,8 +390,6 @@ class Map : public GridRefManager<NGridType>
|
||||
void AddObjectToSwitchList(WorldObject *obj, bool on);
|
||||
virtual void DelayedUpdate(const uint32 diff);
|
||||
|
||||
virtual bool RemoveBones(uint64 guid, float x, float y);
|
||||
|
||||
void UpdateObjectVisibility(WorldObject* obj, Cell cell, CellPair cellpair);
|
||||
void UpdateObjectsVisibilityFor(Player* player, Cell cell, CellPair cellpair);
|
||||
|
||||
|
||||
@@ -87,18 +87,6 @@ void MapInstanced::RelocationNotify()
|
||||
}
|
||||
*/
|
||||
|
||||
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()
|
||||
{
|
||||
// Unload instanced maps
|
||||
|
||||
@@ -38,7 +38,6 @@ class MapInstanced : public Map
|
||||
void Update(const uint32&);
|
||||
void DelayedUpdate(const uint32 diff);
|
||||
//void RelocationNotify();
|
||||
bool RemoveBones(uint64 guid, float x, float y);
|
||||
void UnloadAll();
|
||||
bool CanEnter(Player* player);
|
||||
|
||||
|
||||
@@ -256,16 +256,6 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck)
|
||||
return player->Satisfy(objmgr.GetAccessRequirement(mapid, targetDifficulty), mapid, true);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
i_timer.Update(diff);
|
||||
|
||||
@@ -140,7 +140,6 @@ class MapManager
|
||||
TransportNPCMap m_TransportNPCMap;
|
||||
|
||||
bool CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck = false);
|
||||
void RemoveBonesFromMap(uint32 mapid, uint64 guid, float x, float y);
|
||||
uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
|
||||
void InitMaxInstanceId();
|
||||
void InitializeVisibilityDistanceInfo();
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
#include "AuctionHouseBot.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
#include "VMapFactory.h"
|
||||
#include "GlobalEvents.h"
|
||||
#include "GameEventMgr.h"
|
||||
#include "PoolMgr.h"
|
||||
#include "DatabaseImpl.h"
|
||||
@@ -1284,8 +1283,8 @@ void World::SetInitialWorldSettings()
|
||||
uint32 realm_zone = getConfig(CONFIG_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...");
|
||||
@@ -1655,7 +1654,7 @@ void World::SetInitialWorldSettings()
|
||||
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS);
|
||||
m_timers[WUPDATE_UPTIME].SetInterval(m_configs[CONFIG_UPTIME_UPDATE]*MINUTE*IN_MILLISECONDS);
|
||||
//Update "uptime" table based on configuration entry in minutes.
|
||||
m_timers[WUPDATE_CORPSES].SetInterval(20*MINUTE*IN_MILLISECONDS);
|
||||
m_timers[WUPDATE_CORPSES].SetInterval(3 * HOUR * IN_MILLISECONDS);
|
||||
//erase corpses every 20 minutes
|
||||
m_timers[WUPDATE_CLEANDB].SetInterval(m_configs[CONFIG_LOGDB_CLEARINTERVAL]*MINUTE*IN_MILLISECONDS);
|
||||
// clean logs table every 14 days by default
|
||||
@@ -2004,7 +2003,7 @@ void World::Update(uint32 diff)
|
||||
{
|
||||
m_timers[WUPDATE_CORPSES].Reset();
|
||||
|
||||
CorpsesErase();
|
||||
sObjectAccessor.RemoveOldCorpses();
|
||||
}
|
||||
|
||||
///- Process Game events when necessary
|
||||
|
||||
@@ -1263,14 +1263,6 @@
|
||||
<Filter
|
||||
Name="Globals"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\src\server\game\Globals\GlobalEvents.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\server\game\Globals\GlobalEvents.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\server\game\Globals\ObjectAccessor.cpp"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user