root/trunk/src/game/GlobalEvents.cpp @ 37

Revision 2, 2.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19/** \file
20    \ingroup world
21*/
22
23#include "Log.h"
24#include "Database/DatabaseEnv.h"
25#include "Platform/Define.h"
26#include "MapManager.h"
27#include "ObjectAccessor.h"
28#include "GlobalEvents.h"
29#include "ObjectDefines.h"
30#include "Corpse.h"
31
32/// Handle periodic erase of corpses and bones
33static void CorpsesErase(bool bones,uint32 delay)
34{
35    ///- Get the list of eligible corpses/bones to be removed
36    //No SQL injection (uint32 and enum)
37    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 ? "=" : "<>") );
38
39    if(result)
40    {
41        do
42        {
43            Field *fields = result->Fetch();
44            uint32 guidlow = fields[0].GetUInt32();
45            float positionX = fields[1].GetFloat();
46            float positionY = fields[2].GetFloat();
47            uint32 mapid    = fields[3].GetUInt32();
48            uint64 player_guid = MAKE_NEW_GUID(fields[4].GetUInt32(), 0, HIGHGUID_PLAYER);
49
50            uint64 guid = MAKE_NEW_GUID(guidlow, 0, HIGHGUID_CORPSE);
51
52            sLog.outDebug("[Global event] Removing %s %u (X:%f Y:%f Map:%u).",(bones?"bones":"corpse"),guidlow,positionX,positionY,mapid);
53
54            /// Resurrectable - convert corpses to bones
55            if(!bones)
56            {
57                if(!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid))
58                {
59                    sLog.outDebug("Corpse %u not found in world. Delete from DB.",guidlow);
60                    CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
61                }
62            }
63            else
64                ///- or delete bones
65            {
66                MapManager::Instance().RemoveBonesFromMap(mapid, guid, positionX, positionY);
67
68                ///- remove bones from the database
69                CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
70            }
71        } while (result->NextRow());
72
73        delete result;
74    }
75}
76
77/// not thread guarded variant for call from other thread
78void CorpsesErase()
79{
80    CorpsesErase(true, 20*MINUTE);
81    CorpsesErase(false,3*DAY);
82}
Note: See TracBrowser for help on using the browser.