AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
TicketMgr Class Reference

#include "TicketMgr.h"

Public Member Functions

void LoadTickets ()
 
void LoadSurveys ()
 
GmTicketGetTicket (uint32 ticketId)
 
GmTicketGetTicketByPlayer (ObjectGuid playerGuid)
 
GmTicketGetOldestOpenTicket ()
 
void AddTicket (GmTicket *ticket)
 
void CloseTicket (uint32 ticketId, ObjectGuid source=ObjectGuid::Empty)
 
void ResolveAndCloseTicket (uint32 ticketId, ObjectGuid source)
 
void RemoveTicket (uint32 ticketId)
 
bool GetStatus () const
 
void SetStatus (bool status)
 
uint64 GetLastChange () const
 
void UpdateLastChange ()
 
uint32 GenerateTicketId ()
 
uint32 GetOpenTicketCount () const
 
uint32 GetNextSurveyID ()
 
void Initialize ()
 
void ResetTickets ()
 
void ShowList (ChatHandler &handler, bool onlineOnly) const
 
void ShowClosedList (ChatHandler &handler) const
 
void ShowEscalatedList (ChatHandler &handler) const
 
void SendTicket (WorldSession *session, GmTicket *ticket) const
 

Static Public Member Functions

static TicketMgrinstance ()
 

Protected Member Functions

void _RemoveTicket (uint32 ticketId, int64 source=-1, bool permanently=false)
 

Protected Attributes

GmTicketList _ticketList
 
bool _status
 
uint32 _lastTicketId
 
uint32 _lastSurveyId
 
uint32 _openTicketCount
 
uint64 _lastChange
 

Private Member Functions

 TicketMgr ()
 
 ~TicketMgr ()
 

Detailed Description

Constructor & Destructor Documentation

◆ TicketMgr()

TicketMgr::TicketMgr ( )
private
Seconds GetGameTime()
Definition: GameTime.cpp:38
bool _status
Definition: TicketMgr.h:253
uint32 _lastTicketId
Definition: TicketMgr.h:254
uint32 _openTicketCount
Definition: TicketMgr.h:256
uint32 _lastSurveyId
Definition: TicketMgr.h:255
uint64 _lastChange
Definition: TicketMgr.h:257

◆ ~TicketMgr()

TicketMgr::~TicketMgr ( )
private
267{
268 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
269 delete itr->second;
270}
GmTicketList _ticketList
Definition: TicketMgr.h:251

References _ticketList.

Member Function Documentation

◆ _RemoveTicket()

void TicketMgr::_RemoveTicket ( uint32  ticketId,
int64  source = -1,
bool  permanently = false 
)
protected

◆ AddTicket()

void TicketMgr::AddTicket ( GmTicket ticket)
361{
362 _ticketList[ticket->GetId()] = ticket;
363 if (!ticket->IsClosed())
366 ticket->SaveToDB(trans);
367}
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:69
bool IsClosed() const
Definition: TicketMgr.h:94
void SaveToDB(CharacterDatabaseTransaction trans) const
Definition: TicketMgr.cpp:78
uint32 GetId() const
Definition: TicketMgr.h:101

References _openTicketCount, _ticketList, GmTicket::GetId(), GmTicket::IsClosed(), and GmTicket::SaveToDB().

◆ CloseTicket()

void TicketMgr::CloseTicket ( uint32  ticketId,
ObjectGuid  source = ObjectGuid::Empty 
)
370{
371 if (GmTicket* ticket = GetTicket(ticketId))
372 {
374 ticket->SetClosedBy(source);
375 if (source)
377 ticket->SaveToDB(trans);
378 }
379}
Definition: TicketMgr.h:88
GmTicket * GetTicket(uint32 ticketId)
Definition: TicketMgr.h:197

References _openTicketCount, and GetTicket().

◆ GenerateTicketId()

uint32 TicketMgr::GenerateTicketId ( )
inline
235{ return ++_lastTicketId; }

References _lastTicketId.

◆ GetLastChange()

uint64 TicketMgr::GetLastChange ( ) const
inline
232{ return _lastChange; }

References _lastChange.

◆ GetNextSurveyID()

uint32 TicketMgr::GetNextSurveyID ( )
inline
237{ return ++_lastSurveyId; }

References _lastSurveyId.

◆ GetOldestOpenTicket()

GmTicket * TicketMgr::GetOldestOpenTicket ( )
inline
216 {
217 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
218 if (itr->second && !itr->second->IsClosed() && !itr->second->IsCompleted())
219 return itr->second;
220
221 return nullptr;
222 }

References _ticketList.

◆ GetOpenTicketCount()

uint32 TicketMgr::GetOpenTicketCount ( ) const
inline
236{ return _openTicketCount; }

References _openTicketCount.

◆ GetStatus()

bool TicketMgr::GetStatus ( ) const
inline
229{ return _status; }

References _status.

◆ GetTicket()

GmTicket * TicketMgr::GetTicket ( uint32  ticketId)
inline
198 {
199 GmTicketList::iterator itr = _ticketList.find(ticketId);
200 if (itr != _ticketList.end())
201 return itr->second;
202
203 return nullptr;
204 }

References _ticketList.

Referenced by CloseTicket(), RemoveTicket(), and ResolveAndCloseTicket().

◆ GetTicketByPlayer()

GmTicket * TicketMgr::GetTicketByPlayer ( ObjectGuid  playerGuid)
inline
207 {
208 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
209 if (itr->second && itr->second->IsFromPlayer(playerGuid) && !itr->second->IsClosed())
210 return itr->second;
211
212 return nullptr;
213 }

References _ticketList.

◆ Initialize()

void TicketMgr::Initialize ( )
278{ SetStatus(sWorld->getBoolConfig(CONFIG_ALLOW_TICKETS)); }
@ CONFIG_ALLOW_TICKETS
Definition: IWorld.h:135
#define sWorld
Definition: World.h:443
void SetStatus(bool status)
Definition: TicketMgr.h:230

References CONFIG_ALLOW_TICKETS, SetStatus(), and sWorld.

◆ instance()

TicketMgr * TicketMgr::instance ( )
static
273{
274 static TicketMgr instance;
275 return &instance;
276}
Definition: TicketMgr.h:186
static TicketMgr * instance()
Definition: TicketMgr.cpp:272

References instance().

Referenced by instance().

◆ LoadSurveys()

void TicketMgr::LoadSurveys ( )
348{
349 // we don't actually load anything into memory here as there's no reason to
350 _lastSurveyId = 0;
351
352 uint32 oldMSTime = getMSTime();
353 if (QueryResult result = CharacterDatabase.Query("SELECT MAX(surveyId) FROM gm_survey"))
354 _lastSurveyId = (*result)[0].Get<uint32>();
355
356 LOG_INFO("server.loading", ">> Loaded GM Survey count from database in {} ms", GetMSTimeDiffToNow(oldMSTime));
357 LOG_INFO("server.loading", " ");
358}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint32_t uint32
Definition: Define.h:107
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

References _lastSurveyId, CharacterDatabase, getMSTime(), GetMSTimeDiffToNow(), and LOG_INFO.

◆ LoadTickets()

void TicketMgr::LoadTickets ( )
302{
303 uint32 oldMSTime = getMSTime();
304
305 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
306 delete itr->second;
307 _ticketList.clear();
308
309 _lastTicketId = 0;
311
313 PreparedQueryResult result = CharacterDatabase.Query(stmt);
314 if (!result)
315 {
316 LOG_WARN("server.loading", ">> Loaded 0 GM tickets. DB table `gm_ticket` is empty!");
317
318 return;
319 }
320
321 uint32 count = 0;
322 do
323 {
324 Field* fields = result->Fetch();
325 GmTicket* ticket = new GmTicket();
326 if (!ticket->LoadFromDB(fields))
327 {
328 delete ticket;
329 continue;
330 }
331 if (!ticket->IsClosed())
333
334 // Update max ticket id if necessary
335 uint32 id = ticket->GetId();
336 if (_lastTicketId < id)
337 _lastTicketId = id;
338
339 _ticketList[id] = ticket;
340 ++count;
341 } while (result->NextRow());
342
343 LOG_INFO("server.loading", ">> Loaded {} GM tickets in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
344 LOG_INFO("server.loading", " ");
345}
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
@ CHAR_SEL_GM_TICKETS
Definition: CharacterDatabase.h:260
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
Definition: PreparedStatement.h:157
Class used to access individual fields of database query result.
Definition: Field.h:98
bool LoadFromDB(Field *fields)
Definition: TicketMgr.cpp:49

References _lastTicketId, _openTicketCount, _ticketList, CHAR_SEL_GM_TICKETS, CharacterDatabase, GmTicket::GetId(), getMSTime(), GetMSTimeDiffToNow(), GmTicket::IsClosed(), GmTicket::LoadFromDB(), LOG_INFO, and LOG_WARN.

◆ RemoveTicket()

void TicketMgr::RemoveTicket ( uint32  ticketId)
382{
383 if (GmTicket* ticket = GetTicket(ticketId))
384 {
385 ticket->DeleteFromDB();
386 _ticketList.erase(ticketId);
387 delete ticket;
388 }
389}

References _ticketList, and GetTicket().

◆ ResetTickets()

void TicketMgr::ResetTickets ( )
281{
282 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end();)
283 {
284 if (itr->second->IsClosed())
285 {
286 uint32 ticketId = itr->second->GetId();
287 ++itr;
288 sTicketMgr->RemoveTicket(ticketId);
289 }
290 else
291 ++itr;
292 }
293
294 _lastTicketId = 0;
295
297
298 CharacterDatabase.Execute(stmt);
299}
#define sTicketMgr
Definition: TicketMgr.h:260
@ CHAR_DEL_ALL_GM_TICKETS
Definition: CharacterDatabase.h:263

References _lastTicketId, _ticketList, CHAR_DEL_ALL_GM_TICKETS, CharacterDatabase, and sTicketMgr.

◆ ResolveAndCloseTicket()

void TicketMgr::ResolveAndCloseTicket ( uint32  ticketId,
ObjectGuid  source 
)
392{
393 if (GmTicket* ticket = GetTicket(ticketId))
394 {
396 ticket->SetClosedBy(source);
397 ticket->SetResolvedBy(source);
398 if (source)
400 ticket->SaveToDB(trans);
401 }
402}

References _openTicketCount, and GetTicket().

◆ SendTicket()

void TicketMgr::SendTicket ( WorldSession session,
GmTicket ticket 
) const
430{
431 WorldPacket data(SMSG_GMTICKET_GETTICKET, (ticket ? (4 + 4 + 1 + 4 + 4 + 4 + 1 + 1) : 4));
432
433 if (ticket)
434 ticket->WritePacket(data);
435 else
437
438 session->SendPacket(&data);
439}
@ GMTICKET_STATUS_DEFAULT
Definition: TicketMgr.h:37
@ SMSG_GMTICKET_GETTICKET
Definition: Opcodes.h:560
Definition: WorldPacket.h:26
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214
void WritePacket(WorldPacket &data) const
Definition: TicketMgr.cpp:115

References GMTICKET_STATUS_DEFAULT, WorldSession::SendPacket(), SMSG_GMTICKET_GETTICKET, and GmTicket::WritePacket().

◆ SetStatus()

void TicketMgr::SetStatus ( bool  status)
inline
230{ _status = status; }

References _status.

Referenced by Initialize().

◆ ShowClosedList()

void TicketMgr::ShowClosedList ( ChatHandler handler) const
414{
416 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
417 if (itr->second->IsClosed())
418 handler.SendSysMessage(itr->second->FormatMessageString(handler).c_str());
419}
@ LANG_COMMAND_TICKETSHOWCLOSEDLIST
Definition: Language.h:1022
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159

References _ticketList, LANG_COMMAND_TICKETSHOWCLOSEDLIST, and ChatHandler::SendSysMessage().

◆ ShowEscalatedList()

void TicketMgr::ShowEscalatedList ( ChatHandler handler) const
422{
424 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
425 if (!itr->second->IsClosed() && itr->second->GetEscalatedStatus() == TICKET_IN_ESCALATION_QUEUE)
426 handler.SendSysMessage(itr->second->FormatMessageString(handler).c_str());
427}
@ LANG_COMMAND_TICKETSHOWESCALATEDLIST
Definition: Language.h:1037
@ TICKET_IN_ESCALATION_QUEUE
Definition: TicketMgr.h:59

References _ticketList, LANG_COMMAND_TICKETSHOWESCALATEDLIST, ChatHandler::SendSysMessage(), and TICKET_IN_ESCALATION_QUEUE.

◆ ShowList()

void TicketMgr::ShowList ( ChatHandler handler,
bool  onlineOnly 
) const
405{
407 for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
408 if (!itr->second->IsClosed() && !itr->second->IsCompleted())
409 if (!onlineOnly || itr->second->GetPlayer())
410 handler.SendSysMessage(itr->second->FormatMessageString(handler).c_str());
411}
@ LANG_COMMAND_TICKETSHOWONLINELIST
Definition: Language.h:1021
@ LANG_COMMAND_TICKETSHOWLIST
Definition: Language.h:1020

References _ticketList, LANG_COMMAND_TICKETSHOWLIST, LANG_COMMAND_TICKETSHOWONLINELIST, and ChatHandler::SendSysMessage().

◆ UpdateLastChange()

void TicketMgr::UpdateLastChange ( )
442{
444}

References _lastChange, and GameTime::GetGameTime().

Member Data Documentation

◆ _lastChange

uint64 TicketMgr::_lastChange
protected

Referenced by GetLastChange(), and UpdateLastChange().

◆ _lastSurveyId

uint32 TicketMgr::_lastSurveyId
protected

Referenced by GetNextSurveyID(), and LoadSurveys().

◆ _lastTicketId

uint32 TicketMgr::_lastTicketId
protected

◆ _openTicketCount

uint32 TicketMgr::_openTicketCount
protected

◆ _status

bool TicketMgr::_status
protected

Referenced by GetStatus(), and SetStatus().

◆ _ticketList