[229] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2008 Trinity |
---|
| 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 | #include "Common.h" |
---|
| 22 | #include "Database/DatabaseEnv.h" |
---|
| 23 | #include "Database/SQLStorage.h" |
---|
| 24 | #include "GMTicketMgr.h" |
---|
| 25 | #include "ObjectMgr.h" |
---|
| 26 | #include "ProgressBar.h" |
---|
| 27 | #include "Policies/SingletonImp.h" |
---|
| 28 | #include "Player.h" |
---|
| 29 | #include "ObjectDefines.h" |
---|
| 30 | |
---|
| 31 | INSTANTIATE_SINGLETON_1(GMTicketMgr); |
---|
| 32 | |
---|
| 33 | void GMTicketMgr::LoadGMTickets() |
---|
| 34 | { |
---|
| 35 | m_GMTicketMap.clear(); // For reload case |
---|
| 36 | |
---|
| 37 | QueryResult *result = CharacterDatabase.Query( |
---|
| 38 | // 0 1 2 |
---|
| 39 | "SELECT guid, ticket_text,UNIX_TIMESTAMP(ticket_lastchange) FROM character_ticket"); |
---|
| 40 | |
---|
| 41 | if( !result ) |
---|
| 42 | { |
---|
| 43 | barGoLink bar( 1 ); |
---|
| 44 | |
---|
| 45 | bar.step(); |
---|
| 46 | |
---|
| 47 | sLog.outString(); |
---|
| 48 | sLog.outString(">> Loaded `character_ticket`, table is empty."); |
---|
| 49 | return; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | barGoLink bar( result->GetRowCount() ); |
---|
| 53 | |
---|
| 54 | uint32 count = 0; |
---|
| 55 | |
---|
| 56 | do |
---|
| 57 | { |
---|
| 58 | bar.step(); |
---|
| 59 | |
---|
| 60 | Field* fields = result->Fetch(); |
---|
| 61 | |
---|
| 62 | uint32 guid = fields[0].GetUInt32(); |
---|
| 63 | m_GMTicketMap[guid] = GMTicket(guid, fields[1].GetCppString(), time_t(fields[2].GetUInt64())); |
---|
| 64 | ++count; |
---|
| 65 | |
---|
| 66 | } while (result->NextRow()); |
---|
| 67 | delete result; |
---|
| 68 | |
---|
| 69 | sLog.outString(); |
---|
| 70 | sLog.outString( ">> Loaded %d GM tickets", count ); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void GMTicketMgr::DeleteAll() |
---|
| 74 | { |
---|
| 75 | for(GMTicketMap::iterator itr = m_GMTicketMap.begin(); itr != m_GMTicketMap.end(); ++itr) |
---|
| 76 | { |
---|
| 77 | if(Player* owner = objmgr.GetPlayer(MAKE_NEW_GUID(itr->first,0,HIGHGUID_PLAYER))) |
---|
| 78 | owner->GetSession()->SendGMTicketGetTicket(0x0A,0); |
---|
| 79 | } |
---|
| 80 | CharacterDatabase.PExecute("DELETE FROM character_ticket"); |
---|
| 81 | m_GMTicketMap.clear(); |
---|
| 82 | } |
---|