2 * Copyright (C) 2005-2009 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 #ifndef _GMTICKETMGR_H
20 #define _GMTICKETMGR_H
22 #include "Policies/Singleton.h"
23 #include "Database/DatabaseEnv.h"
34 GMTicket(uint32 guid
, const std::string
& text
, time_t update
) : m_guid(guid
), m_text(text
), m_lastUpdate(update
)
39 const char* GetText() const
41 return m_text
.c_str();
44 uint64
GetLastUpdate() const
49 void SetText(const char* text
)
51 m_text
= text
? text
: "";
52 m_lastUpdate
= time(NULL
);
54 std::string escapedString
= m_text
;
55 CharacterDatabase
.escape_string(escapedString
);
56 CharacterDatabase
.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", escapedString
.c_str(), m_guid
);
59 void DeleteFromDB() const
61 CharacterDatabase
.PExecute("DELETE FROM character_ticket WHERE guid = '%u' LIMIT 1", m_guid
);
66 CharacterDatabase
.BeginTransaction();
69 std::string escapedString
= m_text
;
70 CharacterDatabase
.escape_string(escapedString
);
72 CharacterDatabase
.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid
, escapedString
.c_str());
73 CharacterDatabase
.CommitTransaction();
80 typedef std::map
<uint32
, GMTicket
> GMTicketMap
;
90 GMTicket
* GetGMTicket(uint32 guid
)
92 GMTicketMap::iterator itr
= m_GMTicketMap
.find(guid
);
93 if(itr
== m_GMTicketMap
.end())
95 return &(itr
->second
);
98 size_t GetTicketCount() const
100 return m_GMTicketMap
.size();
103 void Delete(uint32 guid
)
105 GMTicketMap::iterator itr
= m_GMTicketMap
.find(guid
);
106 if(itr
== m_GMTicketMap
.end())
108 itr
->second
.DeleteFromDB();
109 m_GMTicketMap
.erase(itr
);
114 void Create(uint32 guid
, const char* text
)
116 GMTicket t
= GMTicket(guid
, text
, time(NULL
));
118 m_GMTicketMap
[guid
] = t
;
121 GMTicketMap m_GMTicketMap
;
124 #define ticketmgr MaNGOS::Singleton<GMTicketMgr>::Instance()