OregonCore  revision 3611e8a-git
Your Favourite TBC server
TicketMgr.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "TicketMgr.h"
19 #include "World.h"
20 #include "ObjectMgr.h"
21 #include "Language.h"
22 #include "Player.h"
23 #include "Common.h"
24 #include "ObjectAccessor.h"
26 
28 {
29  for (GmTicketList::iterator i = GM_TicketList.begin(); i != GM_TicketList.end();)
30  {
31  if ((*i)->guid == ticketGuid)
32  return (*i);
33  ++i;
34  }
35  return NULL;
36 }
37 
39 {
40  for (GmTicketList::iterator i = GM_TicketList.begin(); i != GM_TicketList.end();)
41  {
42  if ((*i)->playerGuid == playerGuid && (*i)->closed == 0)
43  return (*i);
44  ++i;
45  }
46  return NULL;
47 }
48 
50 {
51  std::string pname = name;
52  if (!normalizePlayerName(pname))
53  return NULL;
54 
55  uint64 playerGuid = sObjectMgr.GetPlayerGUIDByName(pname.c_str());
56  if (!playerGuid)
57  return NULL;
58 
59  for (GmTicketList::iterator i = GM_TicketList.begin(); i != GM_TicketList.end();)
60  {
61  if ((*i)->playerGuid == playerGuid && (*i)->closed == 0)
62  return (*i);
63  ++i;
64  }
65  return NULL;
66 }
67 
68 void TicketMgr::AddGMTicket(GM_Ticket* ticket, bool startup)
69 {
70  ASSERT(ticket);
71  GM_TicketList.push_back(ticket);
72 
73  // save
74  if (!startup)
75  SaveGMTicket(ticket);
76 }
77 
79 {
80  for (GmTicketList::iterator i = GM_TicketList.begin(); i != GM_TicketList.end();)
81  {
82  if ((*i)->guid == ticketGuid)
83  i = GM_TicketList.erase(i);
84  else
85  ++i;
86  }
87 
88  // delete database record
89  CharacterDatabase.PExecute("DELETE FROM gm_tickets WHERE guid= '" UI64FMTD "'", ticketGuid);
90 }
91 
92 
94 {
95  // Delete all out of object holder
96  GM_TicketList.clear();
97 
98  QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT guid, playerGuid, name, message, createtime, map, posX, posY, posZ, timestamp, closed, assignedto, comment, escalated, viewed FROM gm_tickets");
99  GM_Ticket* ticket;
100 
101  if (!result)
102  {
103  ticketmgr.InitTicketID();
104  sLog.outString(">> GM Tickets table is empty, no tickets were loaded.");
105  return;
106  }
107 
108  // Assign values from SQL to the object holder
109  do
110  {
111  Field* fields = result->Fetch();
112  ticket = new GM_Ticket;
113  ticket->guid = fields[0].GetUInt64();
114  ticket->playerGuid = fields[1].GetUInt64();
115  ticket->name = fields[2].GetString();
116  ticket->message = fields[3].GetString();
117  ticket->createtime = fields[4].GetUInt64();
118  ticket->map = fields[5].GetUInt32();
119  ticket->pos_x = fields[6].GetFloat();
120  ticket->pos_y = fields[7].GetFloat();
121  ticket->pos_z = fields[8].GetFloat();
122  ticket->timestamp = fields[9].GetUInt64();
123  ticket->closed = fields[10].GetUInt64();
124  ticket->assignedToGM = fields[11].GetUInt64();
125  ticket->comment = fields[12].GetString();
126  ticket->escalated = fields[13].GetUInt64();
127  ticket->viewed = fields[14].GetBool();
128 
129  AddGMTicket(ticket, true);
130 
131  }
132  while (result->NextRow());
133 
134  sWorld.SendGMText(LANG_COMMAND_TICKETRELOAD, result->GetRowCount());
135 }
136 
138 {
139  // we don't actually load anything into memory here as there's no reason to
140  QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(surveyid) FROM gm_surveys");
141  if (result)
142  {
143  Field* fields = result->Fetch();
144  m_GMSurveyID = fields[0].GetUInt64();
145  }
146  else
147  m_GMSurveyID = 0;
148 
149  sLog.outString(">> Loaded GM Survey count from database.");
150 }
151 
152 void TicketMgr::RemoveGMTicket(uint64 ticketGuid, uint64 GMguid)
153 {
154  for (GmTicketList::iterator i = GM_TicketList.begin(); i != GM_TicketList.end();)
155  {
156  if ((*i)->guid == ticketGuid && (*i)->closed == 0)
157  {
158  (*i)->closed = GMguid;
159  SaveGMTicket((*i));
160  }
161  ++i;
162  }
163 }
164 
165 
167 {
168  for (GmTicketList::iterator i = GM_TicketList.begin(); i != GM_TicketList.end();)
169  {
170  if ((*i)->playerGuid == playerGuid && (*i)->closed == 0)
171  {
172  (*i)->closed = GMguid;
173  SaveGMTicket((*i));
174  }
175  ++i;
176  }
177 }
178 
180 {
181  std::string msg = ticket->message;
183  std::stringstream ss;
184  ss << "REPLACE INTO gm_tickets (guid, playerGuid, name, message, createtime, map, posX, posY, posZ, timestamp, closed, assignedto, comment, escalated, viewed) VALUES('";
185  ss << ticket->guid << "', '";
186  ss << ticket->playerGuid << "', '";
187  ss << ticket->name << "', '";
188  ss << msg << "', '" ;
189  ss << ticket->createtime << "', '";
190  ss << ticket->map << "', '";
191  ss << ticket->pos_x << "', '";
192  ss << ticket->pos_y << "', '";
193  ss << ticket->pos_z << "', '";
194  ss << ticket->timestamp << "', '";
195  ss << ticket->closed << "', '";
196  ss << ticket->assignedToGM << "', '";
197  ss << ticket->comment << "', '";
198  ss << ticket->escalated << "', '";
199  ss << (ticket->viewed ? 1 : 0) << "');";
201  CharacterDatabase.Execute(ss.str().c_str());
203 
204 }
205 
207 {
208  SaveGMTicket(ticket);
209 }
210 
212 {
213  QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT MAX(guid) FROM gm_tickets");
214  if (result)
215  m_ticketid = result->Fetch()[0].GetUInt64();
216 }
217 
219 {
220  return ++m_ticketid;
221 }
222 
void SaveGMTicket(GM_Ticket *ticket)
Definition: TicketMgr.cpp:179
void AddGMTicket(GM_Ticket *ticket, bool startup)
Definition: TicketMgr.cpp:68
bool BeginTransaction()
Definition: Database.cpp:533
Definition: Field.h:24
bool viewed
Definition: TicketMgr.h:49
bool Execute(const char *sql)
Definition: Database.cpp:420
#define sLog
Log class singleton.
Definition: Log.h:187
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
bool escalated
Definition: TicketMgr.h:48
uint64 m_ticketid
Definition: TicketMgr.h:89
float pos_z
Definition: TicketMgr.h:40
#define sObjectMgr
Definition: ObjectMgr.h:1285
bool CommitTransaction()
Definition: Database.cpp:551
const char * GetString() const
Definition: Field.h:41
uint32 map
Definition: TicketMgr.h:41
uint64 m_GMSurveyID
Definition: TicketMgr.h:90
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:225
#define UI64FMTD
Definition: Common.h:149
uint64 assignedToGM
Definition: TicketMgr.h:46
uint64 timestamp
Definition: TicketMgr.h:44
void LoadGMSurveys()
Definition: TicketMgr.cpp:137
std::string name
Definition: TicketMgr.h:37
void DeleteGMTicketPermanently(uint64 ticketGuid)
Definition: TicketMgr.cpp:78
INSTANTIATE_SINGLETON_1(TicketMgr)
void RemoveGMTicket(uint64 ticketGuid, uint64 GMguid)
Definition: TicketMgr.cpp:152
std::string comment
Definition: TicketMgr.h:47
GM_Ticket * GetGMTicketByPlayer(uint64 playerGuid)
Definition: TicketMgr.cpp:38
uint64 closed
Definition: TicketMgr.h:45
void LoadGMTickets()
Definition: TicketMgr.cpp:93
float pos_y
Definition: TicketMgr.h:39
uint64 playerGuid
Definition: TicketMgr.h:36
GmTicketList GM_TicketList
Definition: TicketMgr.h:65
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
uint64 GenerateTicketID()
Definition: TicketMgr.cpp:218
ACE_UINT64 uint64
Definition: Define.h:70
GM_Ticket * GetGMTicketByName(const char *name)
Definition: TicketMgr.cpp:49
uint64 guid
Definition: TicketMgr.h:35
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
void UpdateGMTicket(GM_Ticket *ticket)
Definition: TicketMgr.cpp:206
#define ASSERT
Definition: Errors.h:33
uint64 createtime
Definition: TicketMgr.h:43
#define sWorld
Definition: World.h:860
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
std::string message
Definition: TicketMgr.h:42
float pos_x
Definition: TicketMgr.h:38
#define ticketmgr
Definition: TicketMgr.h:94
void RemoveGMTicketByPlayer(uint64 playerGuid, uint64 GMguid)
Definition: TicketMgr.cpp:166
GM_Ticket * GetGMTicket(uint64 ticketGuid)
Definition: TicketMgr.cpp:27
void InitTicketID()
Definition: TicketMgr.cpp:211