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 bool IsViewed() const { return _viewed; }
104
105 uint32 GetId() const { return _id; }
106 Player* GetPlayer() const;
107 std::string const& GetPlayerName() const { return _playerName; }
108 std::string const& GetMessage() const { return _message; }
109 bool GetNeedMoreHelp() const { return _needMoreHelp; }
110 Player* GetAssignedPlayer() const;
111 ObjectGuid GetAssignedToGUID() const { return _assignedTo; }
112 std::string GetAssignedToName() const;
113 uint64 GetLastModifiedTime() const { return _lastModifiedTime; }
114 GMTicketEscalationStatus GetEscalatedStatus() const { return _escalatedStatus; }
115
116 void SetEscalatedStatus(GMTicketEscalationStatus escalatedStatus) { _escalatedStatus = escalatedStatus; }
117 void SetAssignedTo(ObjectGuid guid, bool isAdmin)
118 {
119 _assignedTo = guid;
120 if (isAdmin && _escalatedStatus == TICKET_IN_ESCALATION_QUEUE)
121 _escalatedStatus = TICKET_ESCALATED_ASSIGNED;
122 else if (_escalatedStatus == TICKET_UNASSIGNED)
123 _escalatedStatus = TICKET_ASSIGNED;
124 }
125 void SetClosedBy(ObjectGuid value) { _closedBy = value; _type = TICKET_TYPE_CLOSED; }
126 void SetResolvedBy(ObjectGuid value) { _resolvedBy = value; }
127 void SetCompleted() { _completed = true; }
128 void SetMessage(std::string const& message);
129 void SetComment(std::string const& comment) { _comment = comment; }
130 void SetViewed() { _viewed = true; }
131 void SetUnassigned();
132 void SetPosition(uint32 mapId, float x, float y, float z);
133 void SetGmAction(uint32 needResponse, bool needMoreHelp);
134
135 void AppendResponse(std::string const& response) { _response += response; }
136
137 bool LoadFromDB(Field* fields);
138 void SaveToDB(CharacterDatabaseTransaction trans) const;
139 void DeleteFromDB();
140
141 void WritePacket(WorldPacket& data) const;
142 void SendResponse(WorldSession* session) const;
143
144 void TeleportTo(Player* player) const;
145 std::string FormatMessageString(ChatHandler& handler, bool detailed = false) const;
146 std::string FormatMessageString(ChatHandler& handler, char const* szClosedName, char const* szAssignedToName, char const* szUnassignedName, char const* szDeletedName, char const* szCompletedName) const;
147
148 void SetChatLog(std::list<uint32> time, std::string const& log);
149 std::string const& GetChatLog() const { return _chatLog; }
150
151private:
153 TicketType _type; // 0 = Open, 1 = Closed, 2 = Character deleted
155 std::string _playerName;
156 float _posX;
157 float _posY;
158 float _posZ;
160 std::string _message;
163 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.
164 ObjectGuid _resolvedBy; // 0 = Open or Resolved by Console (if type = 1), playerGuid = GM who resolved it by closing or completing the ticket.
166 std::string _comment;
172 std::string _response;
173 std::string _chatLog; // No need to store in db, will be refreshed every session client side
174};
175typedef std::map<uint32, GmTicket*> GmTicketList;
176
178{
179private:
180 TicketMgr();
181 ~TicketMgr();
182
183public:
184 static TicketMgr* instance();
185
186 void LoadTickets();
187 void LoadSurveys();
188
190 {
191 GmTicketList::iterator itr = _ticketList.find(ticketId);
192 if (itr != _ticketList.end())
193 return itr->second;
194
195 return nullptr;
196 }
197
199 {
200 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
201 if (itr->second && itr->second->IsFromPlayer(playerGuid) && !itr->second->IsClosed())
202 return itr->second;
203
204 return nullptr;
205 }
206
208 {
209 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
210 if (itr->second && !itr->second->IsClosed() && !itr->second->IsCompleted())
211 return itr->second;
212
213 return nullptr;
214 }
215
216 void AddTicket(GmTicket* ticket);
217 void CloseTicket(uint32 ticketId, ObjectGuid source);
218 void ResolveAndCloseTicket(uint32 ticketId, ObjectGuid source); // used when GM resolves a ticket by simply closing it
219 void RemoveTicket(uint32 ticketId);
220
221 bool GetStatus() const { return _status; }
222 void SetStatus(bool status) { _status = status; }
223
224 uint64 GetLastChange() const { return _lastChange; }
225 void UpdateLastChange();
226
227 uint32 GenerateTicketId() { return ++_lastTicketId; }
228 uint32 GetOpenTicketCount() const { return _openTicketCount; }
229 uint32 GetNextSurveyID() { return ++_lastSurveyId; }
230
231 void Initialize();
232 void ResetTickets();
233
234 void ShowList(ChatHandler& handler, bool onlineOnly) const;
235 void ShowClosedList(ChatHandler& handler) const;
236 void ShowEscalatedList(ChatHandler& handler) const;
237
238 void SendTicket(WorldSession* session, GmTicket* ticket) const;
239
240private:
242
248};
249
250#define sTicketMgr TicketMgr::instance()
251
252#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:175
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:111
ObjectGuid _playerGuid
Definition TicketMgr.h:154
std::string const & GetMessage() const
Definition TicketMgr.h:108
bool _viewed
Definition TicketMgr.h:169
bool IsAssignedTo(ObjectGuid guid) const
Definition TicketMgr.h:101
bool IsAssigned() const
Definition TicketMgr.h:100
std::string const & GetPlayerName() const
Definition TicketMgr.h:107
ObjectGuid _resolvedBy
Definition TicketMgr.h:164
void SetViewed()
Definition TicketMgr.h:130
bool GetNeedMoreHelp() const
Definition TicketMgr.h:109
bool IsClosed() const
Definition TicketMgr.h:97
TicketType _type
Definition TicketMgr.h:153
float _posZ
Definition TicketMgr.h:158
std::string _chatLog
Definition TicketMgr.h:173
bool _completed
Definition TicketMgr.h:167
GMTicketEscalationStatus _escalatedStatus
Definition TicketMgr.h:168
std::string _message
Definition TicketMgr.h:160
std::string const & GetChatLog() const
Definition TicketMgr.h:149
ObjectGuid _assignedTo
Definition TicketMgr.h:165
void WritePacket(WorldPacket &data) const
void SetResolvedBy(ObjectGuid value)
Definition TicketMgr.h:126
void SetClosedBy(ObjectGuid value)
Definition TicketMgr.h:125
ObjectGuid _closedBy
Definition TicketMgr.h:163
bool IsFromPlayer(ObjectGuid guid) const
Definition TicketMgr.h:99
void SetAssignedTo(ObjectGuid guid, bool isAdmin)
Definition TicketMgr.h:117
void AppendResponse(std::string const &response)
Definition TicketMgr.h:135
std::string _response
Definition TicketMgr.h:172
uint64 GetLastModifiedTime() const
Definition TicketMgr.h:113
std::string _comment
Definition TicketMgr.h:166
bool IsCompleted() const
Definition TicketMgr.h:98
bool _needResponse
Definition TicketMgr.h:170
bool _needMoreHelp
Definition TicketMgr.h:171
void SetCompleted()
Definition TicketMgr.h:127
float _posY
Definition TicketMgr.h:157
uint16 _mapId
Definition TicketMgr.h:159
std::string _playerName
Definition TicketMgr.h:155
void SetComment(std::string const &comment)
Definition TicketMgr.h:129
uint32 _id
Definition TicketMgr.h:152
uint32 GetId() const
Definition TicketMgr.h:105
float _posX
Definition TicketMgr.h:156
uint64 _createTime
Definition TicketMgr.h:161
bool IsAssignedNotTo(ObjectGuid guid) const
Definition TicketMgr.h:102
uint64 _lastModifiedTime
Definition TicketMgr.h:162
GMTicketEscalationStatus GetEscalatedStatus() const
Definition TicketMgr.h:114
void SetEscalatedStatus(GMTicketEscalationStatus escalatedStatus)
Definition TicketMgr.h:116
bool IsViewed() const
Definition TicketMgr.h:103
bool _status
Definition TicketMgr.h:243
uint32 _lastTicketId
Definition TicketMgr.h:244
GmTicket * GetOldestOpenTicket()
Definition TicketMgr.h:207
GmTicketList _ticketList
Definition TicketMgr.h:241
void SetStatus(bool status)
Definition TicketMgr.h:222
uint32 _openTicketCount
Definition TicketMgr.h:246
uint32 _lastSurveyId
Definition TicketMgr.h:245
uint32 GetNextSurveyID()
Definition TicketMgr.h:229
GmTicket * GetTicket(uint32 ticketId)
Definition TicketMgr.h:189
uint64 _lastChange
Definition TicketMgr.h:247
uint32 GenerateTicketId()
Definition TicketMgr.h:227
GmTicket * GetTicketByPlayer(ObjectGuid playerGuid)
Definition TicketMgr.h:198
bool GetStatus() const
Definition TicketMgr.h:221
uint64 GetLastChange() const
Definition TicketMgr.h:224
uint32 GetOpenTicketCount() const
Definition TicketMgr.h:228
Player session in the World.