OregonCore  revision 3611e8a-git
Your Favourite TBC server
TicketHandler.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 "Language.h"
19 #include "ObjectAccessor.h"
20 #include "WorldPacket.h"
21 #include "Common.h"
22 #include "Log.h"
23 #include "ObjectAccessor.h"
24 #include "Player.h"
25 #include "Chat.h"
26 #include "TicketMgr.h"
27 #include "World.h"
28 
30 {
31  // Let's see if we have a ticket already, if so don't create a new one
32  if (ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID()))
33  {
35  data << uint32(1); // You already have an open ticket.
36  SendPacket (&data);
37  return;
38  }
39 
40  uint32 map;
41  float x, y, z;
42  std::string ticketText = "";
43  std::string ticketText2 = "";
44  GM_Ticket* ticket = new GM_Ticket;
45 
47 
48  // recv Data
49  //@todo Add map coordinates to tickets.
50  recv_data >> map;
51  recv_data >> x;
52  recv_data >> y;
53  recv_data >> z;
54  recv_data >> ticketText;
55 
56  // get additional data, rarely used
57  recv_data >> ticketText2;
58 
59  // assign values
60  ticket->name = GetPlayer()->GetName();
61  ticket->guid = ticketmgr.GenerateTicketID();
62  ticket->playerGuid = GetPlayer()->GetGUID();
63  ticket->message = ticketText;
64  ticket->createtime = time(NULL);
65  ticket->map = map;
66  ticket->pos_x = x;
67  ticket->pos_y = y;
68  ticket->pos_z = z;
69  ticket->timestamp = time(NULL);
70  ticket->closed = 0;
71  ticket->assignedToGM = 0;
72  ticket->comment = "";
73  ticket->escalated = false;
74  ticket->viewed = false;
75 
76  // remove ticket by player, shouldn't happen
77  ticketmgr.RemoveGMTicketByPlayer(GetPlayer()->GetGUID(), GetPlayer()->GetGUID());
78 
79  // add ticket
80  ticketmgr.AddGMTicket(ticket, false);
81 
82  // Response - no errors
83  data << uint32(2);
84 
85  // Send ticket creation
86  SendPacket(&data);
87 
88  sWorld.SendGMText(LANG_COMMAND_TICKETNEW, ticket->name.c_str(), ticket->guid);
89 
90 }
91 
93 {
94  std::string message = "";
95  time_t t = time(NULL);
96 
98 
99  // recv Data
100  recv_data >> message;
101 
102  // Update Ticket
103  GM_Ticket* ticket = ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());
104 
105  // Check if player has a GM Ticket yet
106  if (!ticket)
107  {
108  // Response - error couldnt find existing Ticket
109  data << uint32(1);
110 
111  // Send packet
112  SendPacket(&data);
113  return;
114  }
115 
116  ticket->message = message;
117  ticket->timestamp = (uint32)t;
118 
119  ticketmgr.UpdateGMTicket(ticket);
120 
121  // Response - no errors
122  data << uint32(2);
123 
124  // Send packet
125  SendPacket(&data);
126 
127  sWorld.SendGMText(LANG_COMMAND_TICKETUPDATED, GetPlayer()->GetName(), ticket->guid);
128 
129 }
130 
132 {
133  // NO recv_data, NO packet check size
134 
135  GM_Ticket* ticket = ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());
136 
137  // CHeck for Ticket
138  if (ticket)
139  {
140  // Remove Tickets from Player
141 
142  // Response - no errors
144  data << uint32(9);
145  // Send Packet
146  SendPacket(&data);
147 
148  sWorld.SendGMText(LANG_COMMAND_TICKETPLAYERABANDON, GetPlayer()->GetName(), ticket->guid);
149  ticketmgr.RemoveGMTicketByPlayer(GetPlayer()->GetGUID(), GetPlayer()->GetGUID());
150  }
151 }
152 
154 {
155  // NO recv_data NO packet size check
156 
158 
159  // get Current Ticket
160  GM_Ticket* ticket = ticketmgr.GetGMTicketByPlayer(GetPlayer()->GetGUID());
161 
162  // check for existing ticket
163  if (!ticket)
164  {
165  data << uint32(10);
166  // send packet
167  SendPacket(&data);
168  return;
169  }
170 
171  // Send current Ticket
172  data << uint32(6); // unk ?
173  data << ticket->message.c_str();
174  data << uint8(0x7); // ticket category
175  data << float(0); // tickets in queue?
176  data << float(0); // if > "tickets in queue" then "We are currently experiencing a high volume of petitions."
177  data << float(ticket->viewed ? GMTICKET_OPENEDBYGM_STATUS_NOT_OPENED : GMTICKET_OPENEDBYGM_STATUS_OPENED); // 0 - "Your ticket will be serviced soon", 1 - "Wait time currently unavailable"
178  if (ticket->escalated)
179  {
180  data << uint8(2); // if == 2 and next field == 1 then "Your ticket has been escalated"
181  data << uint8(1); // const
182  }
183  else
184  {
185  data << uint8(0); // ticket is not assigned
186  data << uint8(0);
187  }
188 
189  SendPacket(&data);
190 
191 }
192 
194 {
195  uint64 nextSurveyID = ticketmgr.GetNextSurveyID();
196  uint32 x;
197  recv_data >> x; // answer range? (6 = 0-5?)
198 
199  // @todo columns for "playerguid" "playername" and possibly "gm" after `surveyid` but how do we retrieve after ticket deletion?
200  // first we must get in basic template so each answer can be inserted to the same field since they are not handled all at once
201  CharacterDatabase.PExecute("INSERT INTO gm_surveys (surveyid) VALUES ('" UI64FMTD "')", nextSurveyID);
202 
203  uint8 result[10];
204  memset(result, 0, sizeof(result));
205  for (int i = 0; i < 10; ++i)
206  {
207  uint32 questionID;
208  recv_data >> questionID; // GMSurveyQuestions.dbc
209  if (!questionID)
210  break;
211 
212  uint8 value;
213  std::string unk_text;
214  recv_data >> value; // answer
215  recv_data >> unk_text; // always empty
216 
217  result[i] = value;
218  // if anyone has a better programming method be my guest. this is the only way I see to prevent multiple rows
219  if (questionID == 28)
220  CharacterDatabase.PExecute("UPDATE gm_surveys SET AppropriateAnswer = '%u' WHERE surveyid = " UI64FMTD ";", value, nextSurveyID);
221  if (questionID == 29)
222  CharacterDatabase.PExecute("UPDATE gm_surveys SET Understandability = '%u' WHERE surveyid = " UI64FMTD ";", value, nextSurveyID);
223  if (questionID == 30)
224  CharacterDatabase.PExecute("UPDATE gm_surveys SET GMRating = '%u' WHERE surveyid = " UI64FMTD ";", value, nextSurveyID);
225  if (questionID == 31)
226  CharacterDatabase.PExecute("UPDATE gm_surveys SET ResponseTime = '%u' WHERE surveyid = " UI64FMTD ";", value, nextSurveyID);
227  if (questionID == 32)
228  CharacterDatabase.PExecute("UPDATE gm_surveys SET OverallGMExperience = '%u' WHERE surveyid = " UI64FMTD ";", value, nextSurveyID);
229  }
230 
231  std::string comment;
232  recv_data >> comment; // additional comment
234  CharacterDatabase.PExecute("UPDATE gm_surveys SET comment = '%s' WHERE surveyid = " UI64FMTD ";", comment.c_str(), nextSurveyID);
235 }
236 
238 {
239  // NO recv_data NO packet size check
240 
242 
243  // Response - System is working Fine
244 
245  // No need for checks, ticket system is active
246  // in case of disactivity, this should be set to (0)
247 
248  data << uint32(1);
249 
250 
251  // Send Packet
252  SendPacket(&data);
253 }
254 
bool viewed
Definition: TicketMgr.h:49
void HandleGMTicketCreateOpcode(WorldPacket &recvPacket)
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
Player * GetPlayer() const
Definition: WorldSession.h:104
bool escalated
Definition: TicketMgr.h:48
float pos_z
Definition: TicketMgr.h:40
void HandleGMTicketDeleteOpcode(WorldPacket &recvPacket)
void SendPacket(WorldPacket const *packet)
uint32 map
Definition: TicketMgr.h:41
ACE_UINT8 uint8
Definition: Define.h:73
#define UI64FMTD
Definition: Common.h:149
uint64 assignedToGM
Definition: TicketMgr.h:46
uint64 timestamp
Definition: TicketMgr.h:44
std::string name
Definition: TicketMgr.h:37
std::string comment
Definition: TicketMgr.h:47
etc mysql my cnf *Then change max_allowed_packet to a bigger value
uint64 closed
Definition: TicketMgr.h:45
float pos_y
Definition: TicketMgr.h:39
uint64 playerGuid
Definition: TicketMgr.h:36
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
const char * GetName() const
Definition: Object.h:692
ACE_UINT64 uint64
Definition: Define.h:70
void HandleGMSurveySubmit(WorldPacket &recvPacket)
uint64 guid
Definition: TicketMgr.h:35
uint64 createtime
Definition: TicketMgr.h:43
#define sWorld
Definition: World.h:860
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
void HandleGMTicketGetTicketOpcode(WorldPacket &recvPacket)
void HandleGMTicketUpdateOpcode(WorldPacket &recvPacket)
ACE_UINT32 uint32
Definition: Define.h:71
std::string message
Definition: TicketMgr.h:42
float pos_x
Definition: TicketMgr.h:38
#define ticketmgr
Definition: TicketMgr.h:94
void HandleGMTicketSystemStatusOpcode(WorldPacket &recvPacket)
const uint64 & GetGUID() const
Definition: Object.h:156