[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / GMTicketMgr.h
blobb6c0d15e8b69b34f70fa0f6016374709d874875f
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 #ifndef _GMTICKETMGR_H
20 #define _GMTICKETMGR_H
22 #include "Policies/Singleton.h"
23 #include "Database/DatabaseEnv.h"
24 #include "Util.h"
25 #include <map>
27 class GMTicket
29 public:
30 explicit GMTicket()
34 GMTicket(uint32 guid, const std::string& text, const std::string& responsetext, time_t update) : m_guid(guid), m_text(text), m_responseText(responsetext), m_lastUpdate(update)
39 const char* GetText() const
41 return m_text.c_str();
44 const char* GetResponse() const
46 return m_responseText.c_str();
49 uint64 GetLastUpdate() const
51 return m_lastUpdate;
54 void SetText(const char* text)
56 m_text = text ? text : "";
57 m_lastUpdate = time(NULL);
59 std::string escapedString = m_text;
60 CharacterDatabase.escape_string(escapedString);
61 CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", escapedString.c_str(), m_guid);
64 void SetResponseText(const char* text)
66 m_responseText = text ? text : "";
67 m_lastUpdate = time(NULL);
69 std::string escapedString = m_responseText;
70 CharacterDatabase.escape_string(escapedString);
71 CharacterDatabase.PExecute("UPDATE character_ticket SET response_text = '%s' WHERE guid = '%u'", escapedString.c_str(), m_guid);
74 bool HasResponse() { return !m_responseText.empty(); }
76 void DeleteFromDB() const
78 CharacterDatabase.PExecute("DELETE FROM character_ticket WHERE guid = '%u' LIMIT 1", m_guid);
81 void SaveToDB() const
83 CharacterDatabase.BeginTransaction();
84 DeleteFromDB();
86 std::string escapedString = m_text;
87 CharacterDatabase.escape_string(escapedString);
89 std::string escapedString2 = m_responseText;
90 CharacterDatabase.escape_string(escapedString2);
92 CharacterDatabase.PExecute("INSERT INTO character_ticket (guid, ticket_text, response_text) VALUES ('%u', '%s', '%s')", m_guid, escapedString.c_str(), escapedString2.c_str());
93 CharacterDatabase.CommitTransaction();
95 private:
96 uint32 m_guid;
97 std::string m_text;
98 std::string m_responseText;
99 time_t m_lastUpdate;
101 typedef std::map<uint32, GMTicket> GMTicketMap;
103 class GMTicketMgr
105 public:
106 GMTicketMgr() { }
107 ~GMTicketMgr() { }
109 void LoadGMTickets();
111 GMTicket* GetGMTicket(uint32 guid)
113 GMTicketMap::iterator itr = m_GMTicketMap.find(guid);
114 if(itr == m_GMTicketMap.end())
115 return NULL;
116 return &(itr->second);
119 size_t GetTicketCount() const
121 return m_GMTicketMap.size();
124 void Delete(uint32 guid)
126 GMTicketMap::iterator itr = m_GMTicketMap.find(guid);
127 if(itr == m_GMTicketMap.end())
128 return;
129 itr->second.DeleteFromDB();
130 m_GMTicketMap.erase(itr);
133 void DeleteAll();
135 void Create(uint32 guid, const char* text)
137 GMTicket t = GMTicket(guid, text, "", time(NULL));
138 t.SaveToDB();
139 m_GMTicketMap[guid] = t;
141 private:
142 GMTicketMap m_GMTicketMap;
145 #define sTicketMgr MaNGOS::Singleton<GMTicketMgr>::Instance()
146 #endif