TrinityCore
Loading...
Searching...
No Matches
TicketMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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#ifndef _TICKETMGR_H
19#define _TICKETMGR_H
20
21#include "ObjectGuid.h"
22#include "DatabaseEnvFwd.h"
23#include <map>
24
25class ChatHandler;
26class Player;
27class WorldPacket;
28class WorldSession;
29
30// from blizzard lua
36
42
52
53// from Blizzard LUA:
54// GMTICKET_ASSIGNEDTOGM_STATUS_NOT_ASSIGNED = 0; -- ticket is not currently assigned to a gm
55// GMTICKET_ASSIGNEDTOGM_STATUS_ASSIGNED = 1; -- ticket is assigned to a normal gm
56// GMTICKET_ASSIGNEDTOGM_STATUS_ESCALATED = 2; -- ticket is in the escalation queue
57// 3 is a custom value and should never actually be sent
65
66// from blizzard lua
68{
69 GMTICKET_OPENEDBYGM_STATUS_NOT_OPENED = 0, // ticket has never been opened by a gm
70 GMTICKET_OPENEDBYGM_STATUS_OPENED = 1 // ticket has been opened by a gm
71};
72
82
89
91{
92public:
93 GmTicket();
94 GmTicket(Player* player);
95 ~GmTicket();
96
97 bool IsClosed() const { return _type != TICKET_TYPE_OPEN; }
98 bool IsCompleted() const { return _completed; }
99 bool IsFromPlayer(ObjectGuid guid) const { return guid == _playerGuid; }
100 bool IsAssigned() const { return !_assignedTo.IsEmpty(); }
101 bool IsAssignedTo(ObjectGuid guid) const { return guid == _assignedTo; }
102 bool IsAssignedNotTo(ObjectGuid guid) const { return IsAssigned() && !IsAssignedTo(guid); }
103
104 uint32 GetId() const { return _id; }
105 Player* GetPlayer() const;
106 std::string const& GetPlayerName() const { return _playerName; }
107 std::string const& GetMessage() const { return _message; }
108 Player* GetAssignedPlayer() const;
109 ObjectGuid GetAssignedToGUID() const { return _assignedTo; }
110 std::string GetAssignedToName() const;
111 uint64 GetLastModifiedTime() const { return _lastModifiedTime; }
112 GMTicketEscalationStatus GetEscalatedStatus() const { return _escalatedStatus; }
113
114 void SetEscalatedStatus(GMTicketEscalationStatus escalatedStatus) { _escalatedStatus = escalatedStatus; }
115 void SetAssignedTo(ObjectGuid guid, bool isAdmin)
116 {
117 _assignedTo = guid;
118 if (isAdmin && _escalatedStatus == TICKET_IN_ESCALATION_QUEUE)
119 _escalatedStatus = TICKET_ESCALATED_ASSIGNED;
120 else if (_escalatedStatus == TICKET_UNASSIGNED)
121 _escalatedStatus = TICKET_ASSIGNED;
122 }
123 void SetClosedBy(ObjectGuid value) { _closedBy = value; _type = TICKET_TYPE_CLOSED; }
124 void SetResolvedBy(ObjectGuid value) { _resolvedBy = value; }
125 void SetCompleted() { _completed = true; }
126 void SetMessage(std::string const& message);
127 void SetComment(std::string const& comment) { _comment = comment; }
128 void SetViewed() { _viewed = true; }
129 void SetUnassigned();
130 void SetPosition(uint32 mapId, float x, float y, float z);
131 void SetGmAction(uint32 needResponse, bool needMoreHelp);
132
133 void AppendResponse(std::string const& response) { _response += response; }
134
135 bool LoadFromDB(Field* fields);
136 void SaveToDB(CharacterDatabaseTransaction trans) const;
137 void DeleteFromDB();
138
139 void WritePacket(WorldPacket& data) const;
140 void SendResponse(WorldSession* session) const;
141
142 void TeleportTo(Player* player) const;
143 std::string FormatMessageString(ChatHandler& handler, bool detailed = false) const;
144 std::string FormatMessageString(ChatHandler& handler, char const* szClosedName, char const* szAssignedToName, char const* szUnassignedName, char const* szDeletedName, char const* szCompletedName) const;
145
146 void SetChatLog(std::list<uint32> time, std::string const& log);
147 std::string const& GetChatLog() const { return _chatLog; }
148
149private:
151 TicketType _type; // 0 = Open, 1 = Closed, 2 = Character deleted
153 std::string _playerName;
154 float _posX;
155 float _posY;
156 float _posZ;
158 std::string _message;
161 ObjectGuid _closedBy; // 0 = Open or Closed by Console (if type = 1), playerGuid = GM who closed it or player abandoned ticket or read the GM response message.
162 ObjectGuid _resolvedBy; // 0 = Open or Resolved by Console (if type = 1), playerGuid = GM who resolved it by closing or completing the ticket.
164 std::string _comment;
170 std::string _response;
171 std::string _chatLog; // No need to store in db, will be refreshed every session client side
172};
173typedef std::map<uint32, GmTicket*> GmTicketList;
174
176{
177private:
178 TicketMgr();
179 ~TicketMgr();
180
181public:
182 static TicketMgr* instance();
183
184 void LoadTickets();
185 void LoadSurveys();
186
188 {
189 GmTicketList::iterator itr = _ticketList.find(ticketId);
190 if (itr != _ticketList.end())
191 return itr->second;
192
193 return nullptr;
194 }
195
197 {
198 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
199 if (itr->second && itr->second->IsFromPlayer(playerGuid) && !itr->second->IsClosed())
200 return itr->second;
201
202 return nullptr;
203 }
204
206 {
207 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
208 if (itr->second && !itr->second->IsClosed() && !itr->second->IsCompleted())
209 return itr->second;
210
211 return nullptr;
212 }
213
214 void AddTicket(GmTicket* ticket);
215 void CloseTicket(uint32 ticketId, ObjectGuid source);
216 void ResolveAndCloseTicket(uint32 ticketId, ObjectGuid source); // used when GM resolves a ticket by simply closing it
217 void RemoveTicket(uint32 ticketId);
218
219 bool GetStatus() const { return _status; }
220 void SetStatus(bool status) { _status = status; }
221
222 uint64 GetLastChange() const { return _lastChange; }
223 void UpdateLastChange();
224
225 uint32 GenerateTicketId() { return ++_lastTicketId; }
226 uint32 GetOpenTicketCount() const { return _openTicketCount; }
227 uint32 GetNextSurveyID() { return ++_lastSurveyId; }
228
229 void Initialize();
230 void ResetTickets();
231
232 void ShowList(ChatHandler& handler, bool onlineOnly) const;
233 void ShowClosedList(ChatHandler& handler) const;
234 void ShowEscalatedList(ChatHandler& handler) const;
235
236 void SendTicket(WorldSession* session, GmTicket* ticket) const;
237
238private:
240
246};
247
248#define sTicketMgr TicketMgr::instance()
249
250#endif // _TICKETMGR_H
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:114
uint64_t uint64
Definition Define.h:132
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
static void SaveToDB(QuestPool const &pool, CharacterDatabaseTransaction trans)
TicketType
Definition TicketMgr.h:84
@ TICKET_TYPE_OPEN
Definition TicketMgr.h:85
@ TICKET_TYPE_CHARACTER_DELETED
Definition TicketMgr.h:87
@ TICKET_TYPE_CLOSED
Definition TicketMgr.h:86
GMTicketSystemStatus
Definition TicketMgr.h:32
@ GMTICKET_QUEUE_STATUS_ENABLED
Definition TicketMgr.h:34
@ GMTICKET_QUEUE_STATUS_DISABLED
Definition TicketMgr.h:33
std::map< uint32, GmTicket * > GmTicketList
Definition TicketMgr.h:173
GMTicketEscalationStatus
Definition TicketMgr.h:59
@ TICKET_ESCALATED_ASSIGNED
Definition TicketMgr.h:63
@ TICKET_IN_ESCALATION_QUEUE
Definition TicketMgr.h:62
@ TICKET_UNASSIGNED
Definition TicketMgr.h:60
@ TICKET_ASSIGNED
Definition TicketMgr.h:61
LagReportType
Definition TicketMgr.h:74
@ LAG_REPORT_TYPE_MAIL
Definition TicketMgr.h:77
@ LAG_REPORT_TYPE_LOOT
Definition TicketMgr.h:75
@ LAG_REPORT_TYPE_SPELL
Definition TicketMgr.h:80
@ LAG_REPORT_TYPE_AUCTION_HOUSE
Definition TicketMgr.h:76
@ LAG_REPORT_TYPE_MOVEMENT
Definition TicketMgr.h:79
@ LAG_REPORT_TYPE_CHAT
Definition TicketMgr.h:78
GMTicketStatus
Definition TicketMgr.h:38
@ GMTICKET_STATUS_DEFAULT
Definition TicketMgr.h:40
@ GMTICKET_STATUS_HASTEXT
Definition TicketMgr.h:39
GMTicketResponse
Definition TicketMgr.h:44
@ GMTICKET_RESPONSE_CREATE_ERROR
Definition TicketMgr.h:47
@ GMTICKET_RESPONSE_ALREADY_EXIST
Definition TicketMgr.h:45
@ GMTICKET_RESPONSE_CREATE_SUCCESS
Definition TicketMgr.h:46
@ GMTICKET_RESPONSE_TICKET_DELETED
Definition TicketMgr.h:50
@ GMTICKET_RESPONSE_UPDATE_SUCCESS
Definition TicketMgr.h:48
@ GMTICKET_RESPONSE_UPDATE_ERROR
Definition TicketMgr.h:49
GMTicketOpenedByGMStatus
Definition TicketMgr.h:68
@ GMTICKET_OPENEDBYGM_STATUS_NOT_OPENED
Definition TicketMgr.h:69
@ GMTICKET_OPENEDBYGM_STATUS_OPENED
Definition TicketMgr.h:70
Class used to access individual fields of database query result.
Definition Field.h:92
ObjectGuid GetAssignedToGUID() const
Definition TicketMgr.h:109
ObjectGuid _playerGuid
Definition TicketMgr.h:152
std::string const & GetMessage() const
Definition TicketMgr.h:107
bool _viewed
Definition TicketMgr.h:167
bool IsAssignedTo(ObjectGuid guid) const
Definition TicketMgr.h:101
bool IsAssigned() const
Definition TicketMgr.h:100
std::string const & GetPlayerName() const
Definition TicketMgr.h:106
ObjectGuid _resolvedBy
Definition TicketMgr.h:162
void SetViewed()
Definition TicketMgr.h:128
bool IsClosed() const
Definition TicketMgr.h:97
TicketType _type
Definition TicketMgr.h:151
float _posZ
Definition TicketMgr.h:156
std::string _chatLog
Definition TicketMgr.h:171
bool _completed
Definition TicketMgr.h:165
GMTicketEscalationStatus _escalatedStatus
Definition TicketMgr.h:166
std::string _message
Definition TicketMgr.h:158
std::string const & GetChatLog() const
Definition TicketMgr.h:147
ObjectGuid _assignedTo
Definition TicketMgr.h:163
void SetResolvedBy(ObjectGuid value)
Definition TicketMgr.h:124
void SetClosedBy(ObjectGuid value)
Definition TicketMgr.h:123
ObjectGuid _closedBy
Definition TicketMgr.h:161
bool IsFromPlayer(ObjectGuid guid) const
Definition TicketMgr.h:99
void SetAssignedTo(ObjectGuid guid, bool isAdmin)
Definition TicketMgr.h:115
void AppendResponse(std::string const &response)
Definition TicketMgr.h:133
std::string _response
Definition TicketMgr.h:170
uint64 GetLastModifiedTime() const
Definition TicketMgr.h:111
std::string _comment
Definition TicketMgr.h:164
bool IsCompleted() const
Definition TicketMgr.h:98
bool _needResponse
Definition TicketMgr.h:168
bool _needMoreHelp
Definition TicketMgr.h:169
void SetCompleted()
Definition TicketMgr.h:125
float _posY
Definition TicketMgr.h:155
uint16 _mapId
Definition TicketMgr.h:157
std::string _playerName
Definition TicketMgr.h:153
void SetComment(std::string const &comment)
Definition TicketMgr.h:127
uint32 _id
Definition TicketMgr.h:150
uint32 GetId() const
Definition TicketMgr.h:104
float _posX
Definition TicketMgr.h:154
uint64 _createTime
Definition TicketMgr.h:159
bool IsAssignedNotTo(ObjectGuid guid) const
Definition TicketMgr.h:102
uint64 _lastModifiedTime
Definition TicketMgr.h:160
GMTicketEscalationStatus GetEscalatedStatus() const
Definition TicketMgr.h:112
void SetEscalatedStatus(GMTicketEscalationStatus escalatedStatus)
Definition TicketMgr.h:114
bool _status
Definition TicketMgr.h:241
uint32 _lastTicketId
Definition TicketMgr.h:242
GmTicket * GetOldestOpenTicket()
Definition TicketMgr.h:205
GmTicketList _ticketList
Definition TicketMgr.h:239
void SetStatus(bool status)
Definition TicketMgr.h:220
uint32 _openTicketCount
Definition TicketMgr.h:244
uint32 _lastSurveyId
Definition TicketMgr.h:243
uint32 GetNextSurveyID()
Definition TicketMgr.h:227
GmTicket * GetTicket(uint32 ticketId)
Definition TicketMgr.h:187
uint64 _lastChange
Definition TicketMgr.h:245
uint32 GenerateTicketId()
Definition TicketMgr.h:225
GmTicket * GetTicketByPlayer(ObjectGuid playerGuid)
Definition TicketMgr.h:196
bool GetStatus() const
Definition TicketMgr.h:219
uint64 GetLastChange() const
Definition TicketMgr.h:222
uint32 GetOpenTicketCount() const
Definition TicketMgr.h:226
Player session in the World.