[9545] Rename ObjectDefines.h -> ObjectGuid.h
[getmangos.git] / src / game / GMTicketMgr.cpp
blob8166f290a4eafa1ebda8fbc4d87b6dbe712b4403
1 /*
2 * Copyright (C) 2005-2010 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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "Database/SQLStorage.h"
22 #include "GMTicketMgr.h"
23 #include "ObjectMgr.h"
24 #include "ObjectGuid.h"
25 #include "ProgressBar.h"
26 #include "Policies/SingletonImp.h"
27 #include "Player.h"
28 #include "ObjectGuid.h"
30 INSTANTIATE_SINGLETON_1(GMTicketMgr);
32 void GMTicketMgr::LoadGMTickets()
34 m_GMTicketMap.clear(); // For reload case
36 QueryResult *result = CharacterDatabase.Query(
37 // 0 1 2 3
38 "SELECT guid, ticket_text, response_text, UNIX_TIMESTAMP(ticket_lastchange) FROM character_ticket");
40 if( !result )
42 barGoLink bar( 1 );
44 bar.step();
46 sLog.outString();
47 sLog.outString(">> Loaded `character_ticket`, table is empty.");
48 return;
51 barGoLink bar( (int)result->GetRowCount() );
53 uint32 count = 0;
57 bar.step();
59 Field* fields = result->Fetch();
61 uint32 guid = fields[0].GetUInt32();
62 m_GMTicketMap[guid] = GMTicket(guid, fields[1].GetCppString(), fields[2].GetCppString(), time_t(fields[3].GetUInt64()));
63 ++count;
65 } while (result->NextRow());
66 delete result;
68 sLog.outString();
69 sLog.outString( ">> Loaded %d GM tickets", count );
72 void GMTicketMgr::DeleteAll()
74 for(GMTicketMap::const_iterator itr = m_GMTicketMap.begin(); itr != m_GMTicketMap.end(); ++itr)
76 if(Player* owner = sObjectMgr.GetPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER)))
77 owner->GetSession()->SendGMTicketGetTicket(0x0A, 0);
79 CharacterDatabase.PExecute("DELETE FROM character_ticket");
80 m_GMTicketMap.clear();