TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SupportMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 SupportMgr_h__
19 #define SupportMgr_h__
20 
21 #include "ObjectMgr.h"
22 #include "Player.h"
23 #include "TicketPackets.h"
24 
25 class ChatHandler;
26 
27 // from blizzard lua
29 {
32 };
33 
35 {
42 };
43 
45 {
49 };
50 
52 
54 {
55 public:
56  Ticket();
57  Ticket(Player* player);
58  virtual ~Ticket();
59 
60  bool IsClosed() const { return !_closedBy.IsEmpty(); }
61  bool IsFromPlayer(ObjectGuid guid) const { return guid == _playerGuid; }
62  bool IsAssigned() const { return !_assignedTo.IsEmpty(); }
63  bool IsAssignedTo(ObjectGuid guid) const { return guid == _assignedTo; }
64  bool IsAssignedNotTo(ObjectGuid guid) const { return IsAssigned() && !IsAssignedTo(guid); }
65 
66  uint32 GetId() const { return _id; }
67  ObjectGuid GetPlayerGuid() const { return _playerGuid; }
68  Player* GetPlayer() const { return ObjectAccessor::FindConnectedPlayer(_playerGuid); }
69  std::string GetPlayerName() const
70  {
71  std::string name;
72  if (!_playerGuid.IsEmpty())
73  ObjectMgr::GetPlayerNameByGUID(_playerGuid, name);
74 
75  return name;
76  }
78  ObjectGuid GetAssignedToGUID() const { return _assignedTo; }
79  std::string GetAssignedToName() const
80  {
81  std::string name;
82  if (!_assignedTo.IsEmpty())
83  ObjectMgr::GetPlayerNameByGUID(_assignedTo, name);
84 
85  return name;
86  }
87  std::string const& GetComment() const { return _comment; }
88 
89  virtual void SetAssignedTo(ObjectGuid guid, bool /*isAdmin*/ = false) { _assignedTo = guid; }
90  virtual void SetUnassigned() { _assignedTo.Clear(); }
91  void SetClosedBy(ObjectGuid value) { _closedBy = value; }
92  void SetComment(std::string const& comment) { _comment = comment; }
93  void SetPosition(uint32 mapId, G3D::Vector3& pos)
94  {
95  _mapId = mapId;
96  _pos = pos;
97  }
98 
99  virtual void LoadFromDB(Field* fields) = 0;
100  virtual void SaveToDB() const = 0;
101  virtual void DeleteFromDB() = 0;
102 
103  void TeleportTo(Player* player) const;
104 
105  virtual std::string FormatViewMessageString(ChatHandler& handler, bool detailed = false) const = 0;
106  virtual std::string FormatViewMessageString(ChatHandler& handler, const char* szClosedName, const char* szAssignedToName, const char* szUnassignedName, const char* szDeletedName) const;
107 
108 protected:
114  ObjectGuid _closedBy; // 0 = Open, -1 = Console, playerGuid = player abandoned ticket, other = GM who closed it.
116  std::string _comment;
117 };
118 
120 {
121 public:
122  BugTicket();
123  BugTicket(Player* player);
124  ~BugTicket();
125 
126  std::string const& GetNote() const { return _note; }
127 
128  void SetFacing(float facing) { _facing = facing; }
129  void SetNote(std::string const& note) { _note = note; }
130 
131  void LoadFromDB(Field* fields) override;
132  void SaveToDB() const override;
133  void DeleteFromDB() override;
134 
136  std::string FormatViewMessageString(ChatHandler& handler, bool detailed = false) const override;
137 
138 private:
139  float _facing;
140  std::string _note;
141 };
142 
144 {
145 public:
146  ComplaintTicket();
147  ComplaintTicket(Player* player);
148  ~ComplaintTicket();
149 
150  ObjectGuid GetTargetCharacterGuid() const { return _targetCharacterGuid; }
151  GMSupportComplaintType GetComplaintType() const { return _complaintType; }
152  std::string const& GetNote() const { return _note; }
153 
154  void SetFacing(float facing) { _facing = facing; }
155  void SetTargetCharacterGuid(ObjectGuid targetCharacterGuid)
156  {
157  _targetCharacterGuid = targetCharacterGuid;
158  }
159  void SetComplaintType(GMSupportComplaintType type) { _complaintType = type; }
160  void SetChatLog(ChatLog const& log) { _chatLog = log; }
161  void SetNote(std::string const& note) { _note = note; }
162 
163  void LoadFromDB(Field* fields) override;
164  void LoadChatLineFromDB(Field* fields);
165  void SaveToDB() const override;
166  void DeleteFromDB() override;
167 
169  std::string FormatViewMessageString(ChatHandler& handler, bool detailed = false) const override;
170 
171 private:
172  float _facing;
176  std::string _note;
177 };
178 
180 {
181 public:
183  SuggestionTicket(Player* player);
184  ~SuggestionTicket();
185 
186  std::string const& GetNote() const { return _note; }
187  void SetNote(std::string const& note) { _note = note; }
188 
189  void SetFacing(float facing) { _facing = facing; }
190 
191  void LoadFromDB(Field* fields) override;
192  void SaveToDB() const override;
193  void DeleteFromDB() override;
194 
196  std::string FormatViewMessageString(ChatHandler& handler, bool detailed = false) const override;
197 
198 private:
199  float _facing;
200  std::string _note;
201 };
202 
203 typedef std::map<uint32, BugTicket*> BugTicketList;
204 typedef std::map<uint32, ComplaintTicket*> ComplaintTicketList;
205 typedef std::map<uint32, SuggestionTicket*> SuggestionTicketList;
206 
208 {
209 private:
210  SupportMgr();
211  ~SupportMgr();
212 
213 public:
214  static SupportMgr* instance();
215 
216  template<typename T>
217  T* GetTicket(uint32 ticketId);
218 
220  {
222  for (auto const& c : _complaintTicketList)
223  if (c.second->GetPlayerGuid() == playerGuid)
224  ret.insert(c);
225 
226  return ret;
227  }
228 
229  void Initialize();
230 
231  bool GetSupportSystemStatus() const { return _supportSystemStatus; }
232  bool GetTicketSystemStatus() const { return _supportSystemStatus && _ticketSystemStatus; }
233  bool GetBugSystemStatus() const { return _supportSystemStatus && _bugSystemStatus; }
234  bool GetComplaintSystemStatus() const { return _supportSystemStatus && _complaintSystemStatus; }
235  bool GetSuggestionSystemStatus() const { return _supportSystemStatus && _suggestionSystemStatus; }
236  uint64 GetLastChange() const { return _lastChange; }
237  template<typename T>
238  uint32 GetOpenTicketCount() const;
239 
240  void SetSupportSystemStatus(bool status) { _supportSystemStatus = status; }
241  void SetTicketSystemStatus(bool status) { _ticketSystemStatus = status; }
242  void SetBugSystemStatus(bool status) { _bugSystemStatus = status; }
243  void SetComplaintSystemStatus(bool status) { _complaintSystemStatus = status; }
244  void SetSuggestionSystemStatus(bool status) { _suggestionSystemStatus = status; }
245 
246  void LoadBugTickets();
247  void LoadComplaintTickets();
248  void LoadSuggestionTickets();
249 
250  void AddTicket(BugTicket* ticket);
251  void AddTicket(ComplaintTicket* ticket);
252  void AddTicket(SuggestionTicket* ticket);
253 
254  template<typename T>
255  void RemoveTicket(uint32 ticketId);
256 
257  template<typename T>
258  void CloseTicket(uint32 ticketId, ObjectGuid closedBy);
259 
260  template<typename T>
261  void ResetTickets();
262 
263  template<typename T>
264  void ShowList(ChatHandler& handler) const;
265 
266  template<typename T>
267  void ShowList(ChatHandler& handler, bool onlineOnly) const;
268 
269  template<typename T>
270  void ShowClosedList(ChatHandler& handler) const;
271 
272  void UpdateLastChange() { _lastChange = uint64(time(nullptr)); }
273 
274  uint32 GenerateBugId() { return ++_lastBugId; }
275  uint32 GenerateComplaintId() { return ++_lastComplaintId; }
276  uint32 GenerateSuggestionId() { return ++_lastSuggestionId; }
277 
278 private:
294 };
295 
296 #define sSupportMgr SupportMgr::instance()
297 
298 #endif // SupportMgr_h__
Definition: SupportMgr.h:39
bool IsClosed() const
Definition: SupportMgr.h:60
bool GetSupportSystemStatus() const
Definition: SupportMgr.h:231
SuggestionTicketList _suggestionTicketList
Definition: SupportMgr.h:286
std::string const & GetComment() const
Definition: SupportMgr.h:87
Definition: SupportMgr.h:179
uint32 _id
Definition: SupportMgr.h:109
void SetNote(std::string const &note)
Definition: SupportMgr.h:161
Definition: SupportMgr.h:47
Definition: SupportMgr.h:143
float _facing
Definition: SupportMgr.h:199
void SetTargetCharacterGuid(ObjectGuid targetCharacterGuid)
Definition: SupportMgr.h:155
Definition: SupportMgr.h:53
uint64 _lastChange
Definition: SupportMgr.h:290
ObjectGuid GetAssignedToGUID() const
Definition: SupportMgr.h:78
void SetChatLog(ChatLog const &log)
Definition: SupportMgr.h:160
GMTicketSystemStatus
Definition: SupportMgr.h:28
void UpdateLastChange()
Definition: SupportMgr.h:272
ObjectGuid _closedBy
Definition: SupportMgr.h:114
Definition: SupportMgr.h:207
bool _supportSystemStatus
Definition: SupportMgr.h:279
bool GetComplaintSystemStatus() const
Definition: SupportMgr.h:234
ObjectGuid GetTargetCharacterGuid() const
Definition: SupportMgr.h:150
Class used to access individual fields of database query result.
Definition: Field.h:56
void LoadFromDB()
Definition: AddonMgr.cpp:40
SupportSpamType
Definition: SupportMgr.h:44
virtual void SetAssignedTo(ObjectGuid guid, bool=false)
Definition: SupportMgr.h:89
TC_SHARED_API::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions,::google::protobuf::internal::EnumTypeTraits< ::bgs::protocol::LogOption,::bgs::protocol::LogOption_IsValid >, 14, false > log
bool IsFromPlayer(ObjectGuid guid) const
Definition: SupportMgr.h:61
virtual void LoadFromDB(Field *fields)=0
void SetSupportSystemStatus(bool status)
Definition: SupportMgr.h:240
bool _bugSystemStatus
Definition: SupportMgr.h:281
ComplaintTicketList GetComplaintsByPlayerGuid(ObjectGuid playerGuid) const
Definition: SupportMgr.h:219
bool GetBugSystemStatus() const
Definition: SupportMgr.h:233
bool GetTicketSystemStatus() const
Definition: SupportMgr.h:232
Definition: SupportMgr.h:46
Definition: SupportMgr.h:36
bool _ticketSystemStatus
Definition: SupportMgr.h:280
uint64_t uint64
Definition: g3dmath.h:170
bool GetSuggestionSystemStatus() const
Definition: SupportMgr.h:235
uint32 GenerateComplaintId()
Definition: SupportMgr.h:275
Definition: SupportMgr.h:37
ObjectGuid _assignedTo
Definition: SupportMgr.h:115
uint32 _lastBugId
Definition: SupportMgr.h:287
std::string _note
Definition: SupportMgr.h:176
std::string _note
Definition: SupportMgr.h:200
Definition: Vector3.h:58
uint32 GetId() const
Definition: SupportMgr.h:66
uint32 GenerateSuggestionId()
Definition: SupportMgr.h:276
void SetPosition(uint32 mapId, G3D::Vector3 &pos)
Definition: SupportMgr.h:93
std::string const & GetNote() const
Definition: SupportMgr.h:126
std::string const & GetNote() const
Definition: SupportMgr.h:186
uint32 _openSuggestionTicketCount
Definition: SupportMgr.h:293
float _facing
Definition: SupportMgr.h:139
Definition: SupportMgr.h:31
std::map< uint32, BugTicket * > BugTicketList
Definition: SupportMgr.h:203
std::map< uint32, ComplaintTicket * > ComplaintTicketList
Definition: SupportMgr.h:204
Player * GetPlayer() const
Definition: SupportMgr.h:68
void SetSuggestionSystemStatus(bool status)
Definition: SupportMgr.h:244
ComplaintTicketList _complaintTicketList
Definition: SupportMgr.h:285
std::string GetPlayerName() const
Definition: SupportMgr.h:69
GMSupportComplaintType _complaintType
Definition: SupportMgr.h:174
Definition: SupportMgr.h:119
uint32 GenerateBugId()
Definition: SupportMgr.h:274
uint64 _createTime
Definition: SupportMgr.h:113
void SetTicketSystemStatus(bool status)
Definition: SupportMgr.h:241
uint32_t uint32
Definition: Define.h:150
void SetNote(std::string const &note)
Definition: SupportMgr.h:129
static void Initialize(PCASC_SALSA20 pState, LPBYTE pbKey, DWORD cbKeyLength, LPBYTE pbVector)
Definition: CascDecrypt.cpp:81
uint64_t uint64
Definition: Define.h:149
uint16_t uint16
Definition: Define.h:151
uint16 _mapId
Definition: SupportMgr.h:111
ObjectGuid _playerGuid
Definition: SupportMgr.h:110
std::string _comment
Definition: SupportMgr.h:116
Definition: SupportMgr.h:30
uint32 _lastSuggestionId
Definition: SupportMgr.h:289
virtual void SetUnassigned()
Definition: SupportMgr.h:90
void SetFacing(float facing)
Definition: SupportMgr.h:128
GMSupportComplaintType GetComplaintType() const
Definition: SupportMgr.h:151
virtual void SaveToDB() const =0
uint32 _lastComplaintId
Definition: SupportMgr.h:288
float _facing
Definition: SupportMgr.h:172
uint32 _openBugTicketCount
Definition: SupportMgr.h:291
static bool GetPlayerNameByGUID(ObjectGuid const &guid, std::string &name)
Definition: ObjectMgr.cpp:2258
Definition: Chat.h:56
void SetBugSystemStatus(bool status)
Definition: SupportMgr.h:242
Definition: SupportMgr.h:41
bool _complaintSystemStatus
Definition: SupportMgr.h:282
Player * GetAssignedPlayer() const
Definition: SupportMgr.h:77
Definition: SupportMgr.h:48
#define TC_GAME_API
Definition: Define.h:134
virtual void DeleteFromDB()=0
BugTicketList _bugTicketList
Definition: SupportMgr.h:284
virtual std::string FormatViewMessageString(ChatHandler &handler, bool detailed=false) const =0
std::map< uint32, SuggestionTicket * > SuggestionTicketList
Definition: SupportMgr.h:205
void SetComplaintType(GMSupportComplaintType type)
Definition: SupportMgr.h:159
uint64 GetLastChange() const
Definition: SupportMgr.h:236
const FieldDescriptor value
Definition: descriptor.h:1522
Definition: ObjectGuid.h:189
std::string _note
Definition: SupportMgr.h:140
void SetComment(std::string const &comment)
Definition: SupportMgr.h:92
ChatLog _chatLog
Definition: SupportMgr.h:175
std::string const & GetNote() const
Definition: SupportMgr.h:152
bool IsAssignedNotTo(ObjectGuid guid) const
Definition: SupportMgr.h:64
void SetFacing(float facing)
Definition: SupportMgr.h:189
void SetClosedBy(ObjectGuid value)
Definition: SupportMgr.h:91
GMSupportComplaintType
Definition: SupportMgr.h:34
void SetFacing(float facing)
Definition: SupportMgr.h:154
G3D::Vector3 _pos
Definition: SupportMgr.h:112
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
void SetComplaintSystemStatus(bool status)
Definition: SupportMgr.h:243
ObjectGuid GetPlayerGuid() const
Definition: SupportMgr.h:67
ObjectGuid _targetCharacterGuid
Definition: SupportMgr.h:173
bool IsAssignedTo(ObjectGuid guid) const
Definition: SupportMgr.h:63
bool _suggestionSystemStatus
Definition: SupportMgr.h:283
bool IsAssigned() const
Definition: SupportMgr.h:62
std::string GetAssignedToName() const
Definition: SupportMgr.h:79
uint32 _openComplaintTicketCount
Definition: SupportMgr.h:292
void SetNote(std::string const &note)
Definition: SupportMgr.h:187