2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "Database/DatabaseEnv.h"
25 #include "Database/DatabaseImpl.h"
26 #include "Platform/Define.h"
27 #include "MapManager.h"
28 #include "ObjectAccessor.h"
29 #include "GlobalEvents.h"
30 #include "ObjectDefines.h"
33 static void CorpsesEraseCallBack(QueryResult
*result
, bool bones
)
40 Field
*fields
= result
->Fetch();
41 uint32 guidlow
= fields
[0].GetUInt32();
42 float positionX
= fields
[1].GetFloat();
43 float positionY
= fields
[2].GetFloat();
44 uint32 mapid
= fields
[3].GetUInt32();
45 uint64 player_guid
= MAKE_NEW_GUID(fields
[4].GetUInt32(), 0, HIGHGUID_PLAYER
);
47 uint64 guid
= MAKE_NEW_GUID(guidlow
, 0, HIGHGUID_CORPSE
);
49 sLog
.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones
?"bones":"corpse"),guidlow
,positionX
,positionY
,mapid
);
51 /// Resurrectable - convert corpses to bones
54 if(!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid
))
56 sLog
.outDebug("Corpse %u not found in world or bones creating forbidden. Delete from DB.",guidlow
);
57 CharacterDatabase
.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow
);
63 MapManager::Instance().RemoveBonesFromMap(mapid
, guid
, positionX
, positionY
);
65 ///- remove bones from the database
66 CharacterDatabase
.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow
);
68 } while (result
->NextRow());
73 /// Handle periodic erase of corpses and bones
74 static void CorpsesErase(bool bones
,uint32 delay
)
76 ///- Get the list of eligible corpses/bones to be removed
77 //No SQL injection (uint32 and enum)
78 CharacterDatabase
.AsyncPQuery(&CorpsesEraseCallBack
, bones
, "SELECT guid,position_x,position_y,map,player FROM corpse WHERE UNIX_TIMESTAMP()-time > '%u' AND corpse_type %s '0'", delay
, (bones
? "=" : "<>"));
81 /// not thread guarded variant for call from other thread
84 CorpsesErase(true, 20*MINUTE
);
85 CorpsesErase(false,3*DAY
);