From a0985f59b695d29308a2c5ae982a144ce9168457 Mon Sep 17 00:00:00 2001 From: IntelligentQuantum Date: Sat, 21 Oct 2023 14:52:53 +0330 Subject: [PATCH] refactor(Scripts/Commands): convert cs_ticket to new system (#17547) Update cs_ticket.cpp --- src/server/scripts/Commands/cs_ticket.cpp | 141 +++++++--------------- 1 file changed, 42 insertions(+), 99 deletions(-) diff --git a/src/server/scripts/Commands/cs_ticket.cpp b/src/server/scripts/Commands/cs_ticket.cpp index 39b7c3780..8e29933bc 100644 --- a/src/server/scripts/Commands/cs_ticket.cpp +++ b/src/server/scripts/Commands/cs_ticket.cpp @@ -24,7 +24,6 @@ EndScriptData */ #include "AccountMgr.h" #include "Chat.h" -#include "Language.h" #include "ObjectMgr.h" #include "Opcodes.h" #include "Player.h" @@ -32,10 +31,6 @@ EndScriptData */ #include "ScriptMgr.h" #include "TicketMgr.h" -#if AC_COMPILER == AC_COMPILER_GNU -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - using namespace Acore::ChatCommands; class ticket_commandscript : public CommandScript @@ -47,48 +42,38 @@ public: { static ChatCommandTable ticketResponseCommandTable = { - { "append", SEC_GAMEMASTER, true, &HandleGMTicketResponseAppendCommand, "" }, - { "appendln", SEC_GAMEMASTER, true, &HandleGMTicketResponseAppendLnCommand, "" } + { "append", HandleGMTicketResponseAppendCommand, SEC_GAMEMASTER, Console::Yes }, + { "appendln", HandleGMTicketResponseAppendLnCommand, SEC_GAMEMASTER, Console::Yes } }; static ChatCommandTable ticketCommandTable = { - { "assign", SEC_GAMEMASTER, true, &HandleGMTicketAssignToCommand, "" }, - { "close", SEC_GAMEMASTER, true, &HandleGMTicketCloseByIdCommand, "" }, - { "closedlist", SEC_GAMEMASTER, true, &HandleGMTicketListClosedCommand, "" }, - { "comment", SEC_GAMEMASTER, true, &HandleGMTicketCommentCommand, "" }, - { "complete", SEC_GAMEMASTER, true, &HandleGMTicketCompleteCommand, "" }, - { "delete", SEC_ADMINISTRATOR, true, &HandleGMTicketDeleteByIdCommand, "" }, - { "escalate", SEC_GAMEMASTER, true, &HandleGMTicketEscalateCommand, "" }, - { "escalatedlist", SEC_GAMEMASTER, true, &HandleGMTicketListEscalatedCommand, "" }, - { "list", SEC_GAMEMASTER, true, &HandleGMTicketListCommand, "" }, - { "onlinelist", SEC_GAMEMASTER, true, &HandleGMTicketListOnlineCommand, "" }, - { "reset", SEC_CONSOLE, true, &HandleGMTicketResetCommand, "" }, - { "response", SEC_GAMEMASTER, true, nullptr, "", ticketResponseCommandTable }, - { "togglesystem", SEC_ADMINISTRATOR, true, &HandleToggleGMTicketSystem, "" }, - { "unassign", SEC_GAMEMASTER, true, &HandleGMTicketUnAssignCommand, "" }, - { "viewid", SEC_GAMEMASTER, true, &HandleGMTicketGetByIdCommand, "" }, - { "viewname", SEC_GAMEMASTER, true, &HandleGMTicketGetByNameCommand, "" } + { "assign", HandleGMTicketAssignToCommand, SEC_GAMEMASTER, Console::Yes }, + { "close", HandleGMTicketCloseByIdCommand, SEC_GAMEMASTER, Console::Yes }, + { "closedlist", HandleGMTicketListClosedCommand, SEC_GAMEMASTER, Console::Yes }, + { "comment", HandleGMTicketCommentCommand, SEC_GAMEMASTER, Console::Yes }, + { "complete", HandleGMTicketCompleteCommand, SEC_GAMEMASTER, Console::Yes }, + { "delete", HandleGMTicketDeleteByIdCommand, SEC_ADMINISTRATOR, Console::Yes }, + { "escalate", HandleGMTicketEscalateCommand, SEC_GAMEMASTER, Console::Yes }, + { "escalatedlist", HandleGMTicketListEscalatedCommand, SEC_GAMEMASTER, Console::Yes }, + { "list", HandleGMTicketListCommand, SEC_GAMEMASTER, Console::Yes }, + { "onlinelist", HandleGMTicketListOnlineCommand, SEC_GAMEMASTER, Console::Yes }, + { "reset", HandleGMTicketResetCommand, SEC_CONSOLE, Console::Yes }, + + { "response", ticketResponseCommandTable }, + { "togglesystem", HandleToggleGMTicketSystem, SEC_ADMINISTRATOR, Console::Yes }, + { "unassign", HandleGMTicketUnAssignCommand, SEC_GAMEMASTER, Console::Yes }, + { "viewid", HandleGMTicketGetByIdCommand, SEC_GAMEMASTER, Console::Yes }, + { "viewname", HandleGMTicketGetByNameCommand, SEC_GAMEMASTER, Console::Yes } }; static ChatCommandTable commandTable = { - { "ticket", SEC_GAMEMASTER, false, nullptr, "", ticketCommandTable } + { "ticket", ticketCommandTable } }; return commandTable; } - static bool HandleGMTicketAssignToCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketAssignToCommand(ChatHandler* handler, uint32 ticketId, std::string target) { - if (!*args) - return false; - - char* ticketIdStr = strtok((char*)args, " "); - uint32 ticketId = atoi(ticketIdStr); - - char* targetStr = strtok(nullptr, " "); - if (!targetStr) - return false; - - std::string target(targetStr); if (!normalizePlayerName(target)) return false; @@ -138,12 +123,8 @@ public: return true; } - static bool HandleGMTicketCloseByIdCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketCloseByIdCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - uint32 ticketId = atoi(args); GmTicket* ticket = sTicketMgr->GetTicket(ticketId); if (!ticket || ticket->IsClosed() || ticket->IsCompleted()) { @@ -177,14 +158,8 @@ public: return true; } - static bool HandleGMTicketCommentCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketCommentCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - char* ticketIdStr = strtok((char*)args, " "); - uint32 ticketId = atoi(ticketIdStr); - char* comment = strtok(nullptr, "\n"); if (!comment) return false; @@ -218,20 +193,14 @@ public: return true; } - static bool HandleGMTicketListClosedCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMTicketListClosedCommand(ChatHandler* handler) { sTicketMgr->ShowClosedList(*handler); return true; } - static bool HandleGMTicketCompleteCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketCompleteCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - char* ticketIdStr = strtok((char*)args, " "); - uint32 ticketId = atoi(ticketIdStr); - GmTicket* ticket = sTicketMgr->GetTicket(ticketId); if (!ticket || ticket->IsClosed() || ticket->IsCompleted()) { @@ -272,12 +241,8 @@ public: return true; } - static bool HandleGMTicketDeleteByIdCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketDeleteByIdCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - uint32 ticketId = atoi(args); GmTicket* ticket = sTicketMgr->GetTicket(ticketId); if (!ticket) { @@ -308,12 +273,8 @@ public: return true; } - static bool HandleGMTicketEscalateCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketEscalateCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - uint32 ticketId = atoi(args); GmTicket* ticket = sTicketMgr->GetTicket(ticketId); if (!ticket || ticket->IsClosed() || ticket->IsCompleted() || ticket->GetEscalatedStatus() != TICKET_UNASSIGNED) { @@ -330,25 +291,25 @@ public: return true; } - static bool HandleGMTicketListEscalatedCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMTicketListEscalatedCommand(ChatHandler* handler) { sTicketMgr->ShowEscalatedList(*handler); return true; } - static bool HandleGMTicketListCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMTicketListCommand(ChatHandler* handler) { sTicketMgr->ShowList(*handler, false); return true; } - static bool HandleGMTicketListOnlineCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMTicketListOnlineCommand(ChatHandler* handler) { sTicketMgr->ShowList(*handler, true); return true; } - static bool HandleGMTicketResetCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMTicketResetCommand(ChatHandler* handler) { if (sTicketMgr->GetOpenTicketCount()) { @@ -364,7 +325,7 @@ public: return true; } - static bool HandleToggleGMTicketSystem(ChatHandler* handler, char const* /*args*/) + static bool HandleToggleGMTicketSystem(ChatHandler* handler) { bool status = !sTicketMgr->GetStatus(); sTicketMgr->SetStatus(status); @@ -372,12 +333,8 @@ public: return true; } - static bool HandleGMTicketUnAssignCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketUnAssignCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - uint32 ticketId = atoi(args); GmTicket* ticket = sTicketMgr->GetTicket(ticketId); if (!ticket || ticket->IsClosed()) { @@ -425,12 +382,8 @@ public: return true; } - static bool HandleGMTicketGetByIdCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketGetByIdCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - uint32 ticketId = atoi(args); GmTicket* ticket = sTicketMgr->GetTicket(ticketId); if (!ticket || ticket->IsClosed() || ticket->IsCompleted()) { @@ -442,16 +395,12 @@ public: ticket->SetViewed(); ticket->SaveToDB(trans); - handler->SendSysMessage(ticket->FormatMessageString(*handler, true).c_str()); + handler->SendSysMessage(ticket->FormatMessageString(*handler, true)); return true; } - static bool HandleGMTicketGetByNameCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketGetByNameCommand(ChatHandler* handler, std::string name) { - if (!*args) - return false; - - std::string name(args); if (!normalizePlayerName(name)) return false; @@ -485,18 +434,12 @@ public: ticket->SetViewed(); ticket->SaveToDB(trans); - handler->SendSysMessage(ticket->FormatMessageString(*handler, true).c_str()); + handler->SendSysMessage(ticket->FormatMessageString(*handler, true)); return true; } - static bool _HandleGMTicketResponseAppendCommand(char const* args, bool newLine, ChatHandler* handler) + static bool _HandleGMTicketResponseAppendCommand(uint32 ticketId, bool newLine, ChatHandler* handler) { - if (!*args) - return false; - - char* ticketIdStr = strtok((char*)args, " "); - uint32 ticketId = atoi(ticketIdStr); - char* response = strtok(nullptr, "\n"); if (!response) return false; @@ -526,14 +469,14 @@ public: return true; } - static bool HandleGMTicketResponseAppendCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketResponseAppendCommand(ChatHandler* handler, uint32 ticketId) { - return _HandleGMTicketResponseAppendCommand(args, false, handler); + return _HandleGMTicketResponseAppendCommand(ticketId, false, handler); } - static bool HandleGMTicketResponseAppendLnCommand(ChatHandler* handler, char const* args) + static bool HandleGMTicketResponseAppendLnCommand(ChatHandler* handler, uint32 ticketId) { - return _HandleGMTicketResponseAppendCommand(args, true, handler); + return _HandleGMTicketResponseAppendCommand(ticketId, true, handler); } };