[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / GMTicketMgr.cpp
blobe843e48c8720c0c8ec3250a59c9ce0e753ee09d1
1 /*
2 * Copyright (C) 2005-2008 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 "ProgressBar.h"
25 #include "Policies/SingletonImp.h"
26 #include "Player.h"
27 #include "ObjectDefines.h"
29 INSTANTIATE_SINGLETON_1(GMTicketMgr);
31 void GMTicketMgr::LoadGMTickets()
33 m_GMTicketMap.clear(); // For reload case
35 QueryResult *result = CharacterDatabase.Query(
36 // 0 1 2
37 "SELECT guid, ticket_text,UNIX_TIMESTAMP(ticket_lastchange) FROM character_ticket");
39 if( !result )
41 barGoLink bar( 1 );
43 bar.step();
45 sLog.outString();
46 sLog.outString(">> Loaded `character_ticket`, table is empty.");
47 return;
50 barGoLink bar( result->GetRowCount() );
52 uint32 count = 0;
56 bar.step();
58 Field* fields = result->Fetch();
60 uint32 guid = fields[0].GetUInt32();
61 m_GMTicketMap[guid] = GMTicket(guid, fields[1].GetCppString(), time_t(fields[2].GetUInt64()));
62 ++count;
64 } while (result->NextRow());
65 delete result;
67 sLog.outString();
68 sLog.outString( ">> Loaded %d GM tickets", count );
71 void GMTicketMgr::DeleteAll()
73 for(GMTicketMap::iterator itr = m_GMTicketMap.begin(); itr != m_GMTicketMap.end(); ++itr)
75 if(Player* owner = objmgr.GetPlayer(MAKE_NEW_GUID(itr->first,0,HIGHGUID_PLAYER)))
76 owner->GetSession()->SendGMTicketGetTicket(0x0A,0);
78 CharacterDatabase.PExecute("DELETE FROM character_ticket");
79 m_GMTicketMap.clear();