1 | /* |
---|
2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
3 | * |
---|
4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | /** \file |
---|
22 | \ingroup world |
---|
23 | */ |
---|
24 | |
---|
25 | #include "Log.h" |
---|
26 | #include "Database/DatabaseEnv.h" |
---|
27 | #include "Platform/Define.h" |
---|
28 | #include "MapManager.h" |
---|
29 | #include "ObjectAccessor.h" |
---|
30 | #include "GlobalEvents.h" |
---|
31 | #include "ObjectDefines.h" |
---|
32 | #include "Corpse.h" |
---|
33 | |
---|
34 | /// Handle periodic erase of corpses and bones |
---|
35 | static void CorpsesErase(bool bones,uint32 delay) |
---|
36 | { |
---|
37 | ///- Get the list of eligible corpses/bones to be removed |
---|
38 | //No SQL injection (uint32 and enum) |
---|
39 | QueryResult *result = CharacterDatabase.PQuery("SELECT guid,position_x,position_y,map,player FROM corpse WHERE UNIX_TIMESTAMP()-time > '%u' AND corpse_type %s '0'", delay, (bones ? "=" : "<>") ); |
---|
40 | |
---|
41 | if(result) |
---|
42 | { |
---|
43 | do |
---|
44 | { |
---|
45 | Field *fields = result->Fetch(); |
---|
46 | uint32 guidlow = fields[0].GetUInt32(); |
---|
47 | float positionX = fields[1].GetFloat(); |
---|
48 | float positionY = fields[2].GetFloat(); |
---|
49 | uint32 mapid = fields[3].GetUInt32(); |
---|
50 | uint64 player_guid = MAKE_NEW_GUID(fields[4].GetUInt32(), 0, HIGHGUID_PLAYER); |
---|
51 | |
---|
52 | uint64 guid = MAKE_NEW_GUID(guidlow, 0, HIGHGUID_CORPSE); |
---|
53 | |
---|
54 | sLog.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones?"bones":"corpse"),guidlow,positionX,positionY,mapid); |
---|
55 | |
---|
56 | /// Resurrectable - convert corpses to bones |
---|
57 | if(!bones) |
---|
58 | { |
---|
59 | if(!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid)) |
---|
60 | { |
---|
61 | sLog.outDebug("Corpse %u not found in world. Delete from DB.",guidlow); |
---|
62 | CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow); |
---|
63 | } |
---|
64 | } |
---|
65 | else |
---|
66 | ///- or delete bones |
---|
67 | { |
---|
68 | MapManager::Instance().RemoveBonesFromMap(mapid, guid, positionX, positionY); |
---|
69 | |
---|
70 | ///- remove bones from the database |
---|
71 | CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow); |
---|
72 | } |
---|
73 | } while (result->NextRow()); |
---|
74 | |
---|
75 | delete result; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | /// not thread guarded variant for call from other thread |
---|
80 | void CorpsesErase() |
---|
81 | { |
---|
82 | CorpsesErase(true, 20*MINUTE); |
---|
83 | CorpsesErase(false,3*DAY); |
---|
84 | } |
---|