Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
TicketInfo.cpp
Go to the documentation of this file.
1
2/*
3* This file is part of Project SkyFire https://www.projectskyfire.org.
4* See LICENSE.md file for Copyright information
5*/
6
7#include "Chat.h"
8#include "Common.h"
9#include "DatabaseEnv.h"
10#include "Language.h"
11#include "Log.h"
12#include "Opcodes.h"
13#include "Player.h"
14#include "TicketInfo.h"
15#include "TicketMgr.h"
16#include "World.h"
17#include "WorldPacket.h"
18#include "WorldSession.h"
19
21// @ TicketInfo
22// Stores all common data needed for a Ticket : id, mapid, createtime, closedby, assignedTo, Position
23
25
26TicketInfo::TicketInfo(Player* player) : _ticketId(0), _ticketCreateTime(time(NULL)), _mapId(0), _playerGuid(player->GetGUID()), _closedBy(0), _assignedTo(0) { }
27
29
30void TicketInfo::TeleportTo(Player* player) const
31{
32 player->TeleportTo(_mapId, _pos.x, _pos.y, _pos.z, 0.0f, 0);
33}
34
36{
37 std::string name;
38 if (!_assignedTo)
39 sObjectMgr->GetPlayerNameByGUID(_assignedTo, name);
40
41 return name;
42}
43
44void TicketInfo::SetPosition(uint32 MapID, G3D::Vector3 pos)
45{
46 _mapId = MapID;
47 _pos = pos;
48}
49
51// GM ticket
52
56
64
66
74
75void GmTicket::SetChatLog(std::list<uint32> time, std::string const& log)
76{
77 std::stringstream ss(log);
78 std::stringstream newss;
79 std::string line;
80 while (std::getline(ss, line) && !time.empty())
81 {
82 newss << secsToTimeString(time.front()) << ": " << line << "\n";
83 time.pop_front();
84 }
85
86 _chatLog = newss.str();
87}
88
89void GmTicket::SetMessage(std::string const& message)
90{
91 _message = message;
92 _lastModifiedTime = uint64(time(NULL));
93}
94
95void GmTicket::SetGmAction(bool needResponse, bool haveTicket)
96{
97 _needResponse = needResponse;
98 _haveTicket = haveTicket;
99}
100
102{
103 uint8 index = 0;
104 _ticketId = fields[index].GetUInt32();
105 _playerGuid = MAKE_NEW_GUID(fields[++index].GetUInt64(), 0, HIGHGUID_PLAYER);
106 _playerName = fields[++index].GetString();
107 _message = fields[++index].GetString();
108 _ticketCreateTime = fields[++index].GetUInt32();
109 _mapId = fields[++index].GetUInt16();
110 _pos.x = fields[++index].GetFloat();
111 _pos.y = fields[++index].GetFloat();
112 _pos.z = fields[++index].GetFloat();
113 _lastModifiedTime = fields[++index].GetUInt32();
114
115 int64 closedBy = fields[++index].GetInt64();
116 int64 assignedTo = fields[++index].GetUInt64();
117
118 _closedBy = closedBy < 0 ? 0 : MAKE_NEW_GUID(uint64(closedBy), 0, HIGHGUID_PLAYER);
119 _assignedTo = assignedTo < 0 ? 0 : MAKE_NEW_GUID(assignedTo, 0, HIGHGUID_PLAYER);
120
121 _comment = fields[++index].GetString();
122 _response = fields[++index].GetString();
123 _completed = fields[++index].GetBool();
124 _escalatedStatus = GMTicketEscalationStatus(fields[++index].GetUInt8());
125 _viewed = fields[++index].GetUInt8();
126 _haveTicket = fields[++index].GetBool();
127}
128
130{
131 uint8 index = 0;
132 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_TICKET);
133 stmt->setUInt32(index, _ticketId);
134 stmt->setUInt64(++index, GUID_LOPART(_playerGuid));
135 stmt->setString(++index, _playerName);
136 stmt->setString(++index, _message);
137 stmt->setUInt32(++index, _ticketCreateTime);
138 stmt->setUInt16(++index, _mapId);
139 stmt->setFloat(++index, _pos.x);
140 stmt->setFloat(++index, _pos.y);
141 stmt->setFloat(++index, _pos.z);
142 stmt->setUInt32(++index, uint32(_lastModifiedTime));
143 stmt->setInt64(++index, GUID_LOPART(_closedBy));
144 stmt->setUInt64(++index, GUID_LOPART(_assignedTo));
145 stmt->setString(++index, _comment);
146 stmt->setString(++index, _response);
147 stmt->setBool(++index, _completed);
148 stmt->setUInt8(++index, uint8(_escalatedStatus));
149 stmt->setBool(++index, _viewed);
150 stmt->setBool(++index, _haveTicket);
151
152 CharacterDatabase.ExecuteOrAppend(trans, stmt);
153}
154
156{
157 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GM_TICKET);
158 stmt->setUInt32(0, _ticketId);
159 CharacterDatabase.Execute(stmt);
160}
161
162std::string TicketInfo::FormatMessageString(ChatHandler& handler, const char* szClosedName, const char* szAssignedToName, const char* szUnassignedName, const char* szDeletedName) const
163{
164 std::stringstream ss;
167 if (szClosedName)
168 ss << handler.PGetParseString(LANG_COMMAND_TICKETCLOSED, szClosedName);
169 if (szAssignedToName)
170 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, szAssignedToName);
171 if (szUnassignedName)
172 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTUNASSIGNED, szUnassignedName);
173 if (szDeletedName)
174 ss << handler.PGetParseString(LANG_COMMAND_TICKETDELETED, szDeletedName);
175 return ss.str();
176}
177
178std::string GmTicket::FormatMessageString(ChatHandler& handler, bool detailed) const
179{
180 time_t curTime = time(NULL);
181 Player* player = GetPlayer();
182
183 std::stringstream ss;
185 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTNAME, player ? player->GetName().c_str() : "NULL");
186 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _ticketCreateTime, true, false)).c_str());
187 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGE, (secsToTimeString(curTime - _lastModifiedTime, true, false)).c_str());
188
189 std::string name;
190 if (sObjectMgr->GetPlayerNameByGUID(_assignedTo, name))
191 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, name.c_str());
192
193 if (detailed)
194 {
196 if (!_comment.empty())
198 if (!_response.empty())
200 }
201 return ss.str();
202}
203
204std::string GmTicket::FormatMessageString(ChatHandler& handler, const char* szClosedName, const char* szAssignedToName, const char* szUnassignedName, const char* szDeletedName) const
205{
206 std::stringstream ss;
209 if (szClosedName)
210 ss << handler.PGetParseString(LANG_COMMAND_TICKETCLOSED, szClosedName);
211 if (szAssignedToName)
212 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, szAssignedToName);
213 if (szUnassignedName)
214 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTUNASSIGNED, szUnassignedName);
215 if (szDeletedName)
216 ss << handler.PGetParseString(LANG_COMMAND_TICKETDELETED, szDeletedName);
217 return ss.str();
218}
219
221// BugTicket System
222
224
225BugTicket::BugTicket(Player* player, WorldPacket& bugPacket) : TicketInfo(player), _Orientation(0.0f)
226{
227 _ticketId = sTicketMgr->GenerateBugId();
228
229 bugPacket >> _pos.x;
230 bugPacket >> _pos.y;
231 bugPacket >> _pos.z;
232 bugPacket >> _Orientation;
233 bugPacket >> _mapId;
234 uint8 lenNote = bugPacket.ReadBits(10);
235 _bugnote = bugPacket.ReadString(lenNote);
236}
237
239
241{
242 uint8 index = 0;
243 _ticketId = fields[index].GetUInt32();
244 _playerGuid = MAKE_NEW_GUID(fields[++index].GetUInt64(), 0, HIGHGUID_PLAYER);
245 _bugnote = fields[++index].GetString();
246 _ticketCreateTime = fields[++index].GetUInt32();
247 _mapId = fields[++index].GetUInt32();
248 _pos.x = fields[++index].GetFloat();
249 _pos.y = fields[++index].GetFloat();
250 _pos.z = fields[++index].GetFloat();
251 _Orientation = fields[++index].GetFloat();
252
253 int64 closedBy = fields[++index].GetInt64();
254 int64 assignedTo = fields[++index].GetUInt64();
255
256 _closedBy = closedBy < 0 ? 0 : MAKE_NEW_GUID(uint64(closedBy), 0, HIGHGUID_PLAYER);
257 _assignedTo = assignedTo < 0 ? 0 : MAKE_NEW_GUID(assignedTo, 0, HIGHGUID_PLAYER);
258
259 _comment = fields[++index].GetString();
260}
261
263{
264 uint8 index = 0;
265 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_BUG);
266 stmt->setUInt32(index, _ticketId);
267 stmt->setUInt32(++index, GUID_LOPART(_playerGuid));
268 stmt->setString(++index, _bugnote);
269 stmt->setUInt32(++index, _mapId);
270 stmt->setFloat(++index, _pos.x);
271 stmt->setFloat(++index, _pos.y);
272 stmt->setFloat(++index, _pos.z);
273 stmt->setFloat(++index, _Orientation);
274 stmt->setUInt32(++index, GUID_LOPART(_closedBy));
275 stmt->setUInt32(++index, GUID_LOPART(_assignedTo));
276 stmt->setString(++index, _comment);
277
278 CharacterDatabase.ExecuteOrAppend(trans, stmt);
279}
280
282{
283 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GM_BUG);
284 stmt->setUInt32(0, _ticketId);
285 CharacterDatabase.Execute(stmt);
286}
287
288std::string BugTicket::FormatMessageString(ChatHandler& handler, bool detailed) const
289{
290 time_t curTime = time(NULL);
291 Player* player = GetPlayer();
292
293 std::stringstream ss;
295 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTNAME, player ? player->GetName().c_str() : "NULL");
296 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _ticketCreateTime, true, false)).c_str());
297
298 std::string name;
299 if (sObjectMgr->GetPlayerNameByGUID(_assignedTo, name))
300 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, name.c_str());
301
302 if (detailed)
303 {
305 if (!_comment.empty())
307 }
308 return ss.str();
309}
310
312// SuggestTicket System
313
315
317{
318 _ticketId = sTicketMgr->GenerateSuggestId();
319
320 suggestPacket >> _pos.x;
321 suggestPacket >> _pos.y;
322 suggestPacket >> _pos.z;
323 suggestPacket >> _Orientation;
324 suggestPacket >> _mapId;
325 uint8 lenNote = suggestPacket.ReadBits(10);
326 _suggestnote = suggestPacket.ReadString(lenNote);
327}
328
330
332{
333 uint8 index = 0;
334 _ticketId = fields[index].GetUInt32();
335 _playerGuid = MAKE_NEW_GUID(fields[++index].GetUInt64(), 0, HIGHGUID_PLAYER);
336 _suggestnote = fields[++index].GetString();
337 _ticketCreateTime = fields[++index].GetUInt32();
338 _mapId = fields[++index].GetUInt32();
339 _pos.x = fields[++index].GetFloat();
340 _pos.y = fields[++index].GetFloat();
341 _pos.z = fields[++index].GetFloat();
342 _Orientation = fields[++index].GetFloat();
343
344 int64 closedBy = fields[++index].GetInt64();
345 int64 assignedTo = fields[++index].GetUInt64();
346
347 _closedBy = closedBy < 0 ? 0 : MAKE_NEW_GUID(uint64(closedBy), 0, HIGHGUID_PLAYER);
348 _assignedTo = assignedTo < 0 ? 0 : MAKE_NEW_GUID(assignedTo, 0, HIGHGUID_PLAYER);
349 _comment = fields[++index].GetString();
350}
351
353{
354 uint8 index = 0;
355 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_SUGGEST);
356 stmt->setUInt32(index, _ticketId);
357 stmt->setUInt32(++index, GUID_LOPART(_playerGuid));
358 stmt->setString(++index, _suggestnote);
359 stmt->setUInt32(++index, _mapId);
360 stmt->setFloat(++index, _pos.x);
361 stmt->setFloat(++index, _pos.y);
362 stmt->setFloat(++index, _pos.z);
363 stmt->setFloat(++index, _Orientation);
364 stmt->setUInt32(++index, GUID_LOPART(_closedBy));
365 stmt->setUInt32(++index, GUID_LOPART(_assignedTo));
366 stmt->setString(++index, _comment);
367
368 CharacterDatabase.ExecuteOrAppend(trans, stmt);
369}
370
372{
373 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GM_SUGGEST);
374 stmt->setUInt32(0, _ticketId);
375 CharacterDatabase.Execute(stmt);
376}
377
378std::string SuggestTicket::FormatMessageString(ChatHandler& handler, bool detailed) const
379{
380 time_t curTime = time(NULL);
381 Player* player = GetPlayer();
382
383 std::stringstream ss;
385 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTNAME, player ? player->GetName().c_str() : "NULL");
386 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _ticketCreateTime, true, false)).c_str());
387
388 std::string name;
389 if (sObjectMgr->GetPlayerNameByGUID(_assignedTo, name))
390 ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, name.c_str());
391
392 if (detailed)
393 {
395 if (!_comment.empty())
397 }
398 return ss.str();
399}
@ CHAR_REP_GM_SUGGEST
@ CHAR_DEL_GM_BUG
@ CHAR_REP_GM_BUG
@ CHAR_DEL_GM_SUGGEST
@ CHAR_REP_GM_TICKET
@ CHAR_DEL_GM_TICKET
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
std::int64_t int64
Definition Define.h:72
@ LANG_COMMAND_TICKETLISTGUID
Definition Language.h:1052
@ LANG_COMMAND_TICKETCLOSED
Definition Language.h:1038
@ LANG_COMMAND_TICKETDELETED
Definition Language.h:1039
@ LANG_COMMAND_TICKETLISTCOMMENT
Definition Language.h:1058
@ LANG_COMMAND_TICKETLISTAGE
Definition Language.h:1054
@ LANG_COMMAND_TICKETLISTRESPONSE
Definition Language.h:1064
@ LANG_COMMAND_TICKETLISTASSIGNEDTO
Definition Language.h:1055
@ LANG_COMMAND_TICKETLISTAGECREATE
Definition Language.h:1060
@ LANG_COMMAND_TICKETLISTUNASSIGNED
Definition Language.h:1056
@ LANG_COMMAND_TICKETLISTMESSAGE
Definition Language.h:1057
@ LANG_COMMAND_TICKETLISTNAME
Definition Language.h:1053
uint32 GUID_LOPART(uint64 x)
@ HIGHGUID_PLAYER
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
#define sObjectMgr
Definition ObjectMgr.h:1617
GMTicketEscalationStatus
Definition TicketInfo.h:42
@ TICKET_IN_ESCALATION_QUEUE
Definition TicketInfo.h:45
@ TICKET_UNASSIGNED
Definition TicketInfo.h:43
GMTicketOpenedByGMStatus
Definition TicketInfo.h:51
#define sTicketMgr
Definition TicketMgr.h:117
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
Definition Transaction.h:42
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition Util.cpp:127
std::string _bugnote
Definition TicketInfo.h:189
void SaveToDB(SQLTransaction &trans) const OVERRIDE
void DeleteFromDB() OVERRIDE
void LoadFromDB(Field *fields) OVERRIDE
float _Orientation
Definition TicketInfo.h:188
std::string FormatMessageString(ChatHandler &handler, bool detailed=false) const OVERRIDE
uint32 ReadBits(size_t bits)
Definition ByteBuffer.h:198
std::string ReadString(size_t length)
Definition ByteBuffer.h:565
std::string PGetParseString(int32 entry,...) const
Definition Chat.cpp:57
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
std::string GetString() const
Definition Field.h:228
int64 GetInt64() const
Definition Field.h:159
uint64 GetUInt64() const
Definition Field.h:141
uint16 GetUInt16() const
Definition Field.h:69
float GetFloat() const
Definition Field.h:177
bool GetBool() const
Definition Field.h:21
uint32 GetUInt32() const
Definition Field.h:105
void SetUnassigned() override
bool _viewed
Definition TicketInfo.h:160
std::string _chatLog
Definition TicketInfo.h:165
bool _completed
Definition TicketInfo.h:159
void SetGmAction(bool needResponse, bool haveTicket)
GMTicketEscalationStatus _escalatedStatus
Definition TicketInfo.h:157
std::string _message
Definition TicketInfo.h:163
void SetMessage(std::string const &message)
std::string FormatMessageString(ChatHandler &handler, bool detailed=false) const override
std::string _response
Definition TicketInfo.h:164
void DeleteFromDB() OVERRIDE
bool _needResponse
Definition TicketInfo.h:161
GMTicketOpenedByGMStatus _openedByGmStatus
Definition TicketInfo.h:158
void SetChatLog(std::list< uint32 > time, std::string const &log)
bool _haveTicket
Definition TicketInfo.h:162
void LoadFromDB(Field *fields) OVERRIDE
uint64 _lastModifiedTime
Definition TicketInfo.h:156
void SaveToDB(SQLTransaction &trans) const OVERRIDE
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Definition Player.cpp:2090
void setBool(const uint8 index, const bool value)
void setFloat(const uint8 index, const float value)
void setString(const uint8 index, const std::string &value)
void setInt64(const uint8 index, const int64 value)
void setUInt16(const uint8 index, const uint16 value)
void setUInt64(const uint8 index, const uint64 value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
std::string _suggestnote
Definition TicketInfo.h:213
void SaveToDB(SQLTransaction &trans) const OVERRIDE
void DeleteFromDB() OVERRIDE
void LoadFromDB(Field *fields) OVERRIDE
float _Orientation
Definition TicketInfo.h:212
std::string FormatMessageString(ChatHandler &handler, bool detailed=false) const OVERRIDE
G3D::Vector3 _pos
Definition TicketInfo.h:119
std::string GetAssignedToName() const
virtual std::string FormatMessageString(ChatHandler &handler, bool detailed=false) const =0
uint32 _mapId
Definition TicketInfo.h:113
uint64 _assignedTo
Definition TicketInfo.h:116
uint64 _playerGuid
Definition TicketInfo.h:114
virtual ~TicketInfo()
void TeleportTo(Player *player) const
uint32 _ticketId
Definition TicketInfo.h:111
void SetPosition(uint32 MapID, G3D::Vector3 pos)
uint32 _ticketCreateTime
Definition TicketInfo.h:112
Player * GetPlayer() const
Definition TicketInfo.h:90
std::string _comment
Definition TicketInfo.h:117
std::string _playerName
Definition TicketInfo.h:118
uint64 _closedBy
Definition TicketInfo.h:115
std::string const & GetName() const
Definition Object.h:664
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41