2 * Copyright (C) 2005-2013 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
20 #include "Database/DatabaseEnv.h"
21 #include "SQLStorages.h"
22 #include "GMTicketMgr.h"
23 #include "ObjectMgr.h"
24 #include "ObjectGuid.h"
25 #include "ProgressBar.h"
26 #include "Policies/SingletonImp.h"
29 INSTANTIATE_SINGLETON_1(GMTicketMgr
);
31 void GMTicketMgr::LoadGMTickets()
33 m_GMTicketMap
.clear(); // For reload case
35 QueryResult
* result
= CharacterDatabase
.Query(
37 "SELECT guid, ticket_text, response_text, UNIX_TIMESTAMP(ticket_lastchange), ticket_id FROM character_ticket ORDER BY ticket_id ASC");
46 sLog
.outString(">> Loaded `character_ticket`, table is empty.");
50 BarGoLink
bar(result
->GetRowCount());
56 Field
* fields
= result
->Fetch();
58 uint32 guidlow
= fields
[0].GetUInt32();
62 ObjectGuid guid
= ObjectGuid(HIGHGUID_PLAYER
, guidlow
);
64 GMTicket
& ticket
= m_GMTicketMap
[guid
];
66 if (ticket
.GetPlayerGuid()) // already exist
68 CharacterDatabase
.PExecute("DELETE FROM character_ticket WHERE ticket_id = '%u'", fields
[4].GetUInt32());
72 ticket
.Init(guid
, fields
[1].GetCppString(), fields
[2].GetCppString(), time_t(fields
[3].GetUInt64()));
73 m_GMTicketListByCreatingOrder
.push_back(&ticket
);
76 while (result
->NextRow());
80 sLog
.outString(">> Loaded " SIZEFMTD
" GM tickets", GetTicketCount());
83 void GMTicketMgr::DeleteAll()
85 for (GMTicketMap::const_iterator itr
= m_GMTicketMap
.begin(); itr
!= m_GMTicketMap
.end(); ++itr
)
87 if (Player
* owner
= sObjectMgr
.GetPlayer(itr
->first
))
88 owner
->GetSession()->SendGMTicketGetTicket(0x0A);
90 CharacterDatabase
.Execute("DELETE FROM character_ticket");
91 m_GMTicketListByCreatingOrder
.clear();
92 m_GMTicketMap
.clear();