From f26eee227373d775f84842f57d3df1e81ae971d8 Mon Sep 17 00:00:00 2001 From: iThorgrim Date: Wed, 22 Jan 2025 17:52:04 +0100 Subject: [PATCH 1/6] feat(Core/Scripting): Add new hooks for Ticket --- src/server/game/Handlers/TicketHandler.cpp | 10 ++++ .../ScriptDefines/AllScriptsObjects.h | 1 + .../Scripting/ScriptDefines/TicketScript.cpp | 59 +++++++++++++++++++ .../Scripting/ScriptDefines/TicketScript.h | 51 ++++++++++++++++ src/server/game/Scripting/ScriptMgr.cpp | 5 +- src/server/game/Scripting/ScriptMgr.h | 8 +++ src/server/game/Scripting/ScriptObjectFwd.h | 1 + 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/server/game/Scripting/ScriptDefines/TicketScript.cpp create mode 100644 src/server/game/Scripting/ScriptDefines/TicketScript.h diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index 6d53bf95b73396..c4c0effaf0a46c 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -20,6 +20,7 @@ #include "Language.h" #include "Opcodes.h" #include "Player.h" +#include "ScriptMgr.h" #include "TicketMgr.h" #include "Util.h" #include "World.h" @@ -120,6 +121,8 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName(), ticket->GetId()); + sScriptMgr->OnCreateTicket(GetPlayer(), ticket); + response = GMTICKET_RESPONSE_CREATE_SUCCESS; } @@ -148,8 +151,11 @@ void WorldSession::HandleGMTicketUpdateOpcode(WorldPacket& recv_data) ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETUPDATED, GetPlayer()->GetName(), ticket->GetId()); response = GMTICKET_RESPONSE_UPDATE_SUCCESS; + + sScriptMgr->OnTicketUpdate(GetPlayer(), ticket, message); } + WorldPacket data(SMSG_GMTICKET_UPDATETEXT, 4); data << uint32(response); SendPacket(&data); @@ -167,6 +173,8 @@ void WorldSession::HandleGMTicketDeleteOpcode(WorldPacket& /*recv_data*/) sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID()); sTicketMgr->SendTicket(this, nullptr); + + sScriptMgr->OnTicketClose(GetPlayer(), ticket); } } @@ -296,5 +304,7 @@ void WorldSession::HandleGMResponseResolve(WorldPacket& /*recvPacket*/) sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID()); sTicketMgr->SendTicket(this, nullptr); + + sScriptMgr->OnTicketResolve(GetPlayer(), ticket); } } diff --git a/src/server/game/Scripting/ScriptDefines/AllScriptsObjects.h b/src/server/game/Scripting/ScriptDefines/AllScriptsObjects.h index aad81c0700762c..9196c32845efd4 100644 --- a/src/server/game/Scripting/ScriptDefines/AllScriptsObjects.h +++ b/src/server/game/Scripting/ScriptDefines/AllScriptsObjects.h @@ -58,6 +58,7 @@ #include "PlayerScript.h" #include "ServerScript.h" #include "SpellScriptLoader.h" +#include "TicketScript.h" #include "TransportScript.h" #include "UnitScript.h" #include "VehicleScript.h" diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp new file mode 100644 index 00000000000000..c0c812260c1635 --- /dev/null +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp @@ -0,0 +1,59 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "TicketScript.h" +#include "ScriptMgr.h" +#include "ScriptMgrMacros.h" + +void ScriptMgr::OnCreateTicket(Player* player, GmTicket* ticket) +{ + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_CREATE_TICKET, script->OnCreateTicket(player, ticket)); +} + +void ScriptMgr::OnTicketUpdate(Player* player, GmTicket* ticket, std::string message) +{ + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_UPDATE_TICKET, script->OnTicketUpdate(player, ticket, message)); +} + +void ScriptMgr::OnTicketClose(Player* player, GmTicket* ticket) +{ + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_CLOSE_TICKET, script->OnTicketClose(player, ticket)); +} + +void ScriptMgr::OnTicketStatusUpdate(Player* player, GmTicket* ticket) +{ + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_STATUS_UPDATE_TICKET, script->OnTicketStatusUpdate(player, ticket)); +} + +void ScriptMgr::OnTicketResolve(Player* player, GmTicket* ticket) +{ + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_RESOLVE_TICKET, script->OnTicketResolve(player, ticket)); +} + +TicketScript::TicketScript(const char* name, std::vector enabledHooks) +: ScriptObject(name, SERVERHOOK_END) +{ + // If empty - enable all available hooks. + if (enabledHooks.empty()) + for (uint16 i = 0; i < SERVERHOOK_END; ++i) + enabledHooks.emplace_back(i); + + ScriptRegistry::AddScript(this, std::move(enabledHooks)); +} + +template class AC_GAME_API ScriptRegistry; + diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.h b/src/server/game/Scripting/ScriptDefines/TicketScript.h new file mode 100644 index 00000000000000..58a84fd99d0da4 --- /dev/null +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.h @@ -0,0 +1,51 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SCRIPT_OBJECT_TICKET_SCRIPT_H_ +#define SCRIPT_OBJECT_TICKET_SCRIPT_H_ + +#include "ScriptObject.h" +#include "TicketMgr.h" +#include + +enum TicketHook +{ + TICKETHOOK_ON_CREATE_TICKET, + TICKETHOOK_ON_UPDATE_TICKET, + TICKETHOOK_ON_CLOSE_TICKET, + TICKETHOOK_ON_STATUS_UPDATE_TICKET, + TICKETHOOK_ON_RESOLVE_TICKET, + TICKETHOOK_END +}; + +class TicketScript : public ScriptObject +{ +protected: + TicketScript(const char* name, std::vector enabledHooks = std::vector()); + +public: + [[nodiscard]] bool IsDatabaseBound() const override { return false; } + + virtual void OnCreateTicket(Player* /*player*/, GmTicket* /*ticket*/) { } + virtual void OnTicketUpdate(Player* /*player*/, GmTicket* /*ticket*/, std::string /*message*/) { } + virtual void OnTicketClose(Player* /*player*/, GmTicket* /*ticket*/) { } + virtual void OnTicketStatusUpdate(Player* /*player*/, GmTicket* /*ticket*/) { } + virtual void OnTicketResolve(Player* /*player*/, GmTicket* /*ticket*/) { } +}; + +#endif + diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 83af4d8512aac1..3a78145cab24b4 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -98,6 +98,7 @@ void ScriptMgr::Initialize() ScriptRegistry::InitEnabledHooksIfNeeded(PLAYERHOOK_END); ScriptRegistry::InitEnabledHooksIfNeeded(SERVERHOOK_END); ScriptRegistry::InitEnabledHooksIfNeeded(ALLSPELLHOOK_END); + ScriptRegistry::InitEnabledHooksIfNeeded(TICKETHOOK_END); ScriptRegistry::InitEnabledHooksIfNeeded(UNITHOOK_END); ScriptRegistry::InitEnabledHooksIfNeeded(WORLDOBJECTHOOK_END); ScriptRegistry::InitEnabledHooksIfNeeded(WORLDHOOK_END); @@ -145,6 +146,7 @@ void ScriptMgr::Unload() SCR_CLEAR(); SCR_CLEAR(); SCR_CLEAR(); + SCR_CLEAR(); SCR_CLEAR(); SCR_CLEAR(); SCR_CLEAR(); @@ -224,7 +226,8 @@ void ScriptMgr::CheckIfScriptsInDatabaseExist() !ScriptRegistry::GetScriptById(sid) && !ScriptRegistry::GetScriptById(sid) && !ScriptRegistry::GetScriptById(sid) && - !ScriptRegistry::GetScriptById(sid)) + !ScriptRegistry::GetScriptById(sid) && + !ScriptRegistry::GetScriptById(sid)) { LOG_ERROR("sql.sql", "Script named '{}' is assigned in the database, but has no code!", scriptName); } diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 44382936a4d7fa..5db3a5471335fa 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -699,6 +699,14 @@ class ScriptMgr void OnLootMoney(Player* player, uint32 gold); +public: /* TicketScript */ + + void OnCreateTicket(Player* player, GmTicket* ticket); + void OnTicketUpdate(Player* player, GmTicket* ticket, std::string message); + void OnTicketClose(Player* player, GmTicket* ticket); + void OnTicketStatusUpdate(Player* player, GmTicket* ticket); + void OnTicketResolve(Player* player, GmTicket* ticket); + private: uint32 _scriptCount; diff --git a/src/server/game/Scripting/ScriptObjectFwd.h b/src/server/game/Scripting/ScriptObjectFwd.h index a7a899e02846e7..04b658b2759d39 100644 --- a/src/server/game/Scripting/ScriptObjectFwd.h +++ b/src/server/game/Scripting/ScriptObjectFwd.h @@ -67,6 +67,7 @@ class SpellCastTargets; class SpellInfo; class SpellScript; class TempSummon; +class TicketMgr; class Transport; class Unit; class Vehicle; From 3723fe0b9740b41c85e522f234666699f3c624e4 Mon Sep 17 00:00:00 2001 From: iThorgrim Date: Wed, 22 Jan 2025 17:58:02 +0100 Subject: [PATCH 2/6] Fix(Core/Script): Fix whitespace --- src/server/game/Handlers/TicketHandler.cpp | 1 - src/server/game/Scripting/ScriptDefines/TicketScript.cpp | 1 - src/server/game/Scripting/ScriptDefines/TicketScript.h | 1 - 3 files changed, 3 deletions(-) diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index c4c0effaf0a46c..462e4c5cdd9c1e 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -155,7 +155,6 @@ void WorldSession::HandleGMTicketUpdateOpcode(WorldPacket& recv_data) sScriptMgr->OnTicketUpdate(GetPlayer(), ticket, message); } - WorldPacket data(SMSG_GMTICKET_UPDATETEXT, 4); data << uint32(response); SendPacket(&data); diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp index c0c812260c1635..3def05c2285969 100644 --- a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp @@ -56,4 +56,3 @@ TicketScript::TicketScript(const char* name, std::vector enabledHooks) } template class AC_GAME_API ScriptRegistry; - diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.h b/src/server/game/Scripting/ScriptDefines/TicketScript.h index 58a84fd99d0da4..a19af43e6fae3e 100644 --- a/src/server/game/Scripting/ScriptDefines/TicketScript.h +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.h @@ -48,4 +48,3 @@ class TicketScript : public ScriptObject }; #endif - From 8f501605337be9edb2f7dc7b97aed0e8a9a703b6 Mon Sep 17 00:00:00 2001 From: iThorgrim Date: Wed, 22 Jan 2025 17:59:08 +0100 Subject: [PATCH 3/6] Fix name for OnTicketCreate --- src/server/game/Handlers/TicketHandler.cpp | 2 +- src/server/game/Scripting/ScriptDefines/TicketScript.cpp | 4 ++-- src/server/game/Scripting/ScriptMgr.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index 462e4c5cdd9c1e..f26308b7a7b33a 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -121,7 +121,7 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName(), ticket->GetId()); - sScriptMgr->OnCreateTicket(GetPlayer(), ticket); + sScriptMgr->OnTicketCreate(GetPlayer(), ticket); response = GMTICKET_RESPONSE_CREATE_SUCCESS; } diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp index 3def05c2285969..ef60b91acd53af 100644 --- a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp @@ -19,9 +19,9 @@ #include "ScriptMgr.h" #include "ScriptMgrMacros.h" -void ScriptMgr::OnCreateTicket(Player* player, GmTicket* ticket) +void ScriptMgr::OnTicketCreate(Player* player, GmTicket* ticket) { - CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_CREATE_TICKET, script->OnCreateTicket(player, ticket)); + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_CREATE_TICKET, script->OnTicketCreate(player, ticket)); } void ScriptMgr::OnTicketUpdate(Player* player, GmTicket* ticket, std::string message) diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 5db3a5471335fa..42a5fc38548103 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -701,7 +701,7 @@ class ScriptMgr public: /* TicketScript */ - void OnCreateTicket(Player* player, GmTicket* ticket); + void OnTicketCreate(Player* player, GmTicket* ticket); void OnTicketUpdate(Player* player, GmTicket* ticket, std::string message); void OnTicketClose(Player* player, GmTicket* ticket); void OnTicketStatusUpdate(Player* player, GmTicket* ticket); From 5061ec2aa2fbfd878498960f388d4fa14257ec73 Mon Sep 17 00:00:00 2001 From: iThorgrim Date: Wed, 22 Jan 2025 18:11:12 +0100 Subject: [PATCH 4/6] Fix name for OnTicketCreate --- src/server/game/Scripting/ScriptDefines/TicketScript.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.h b/src/server/game/Scripting/ScriptDefines/TicketScript.h index a19af43e6fae3e..80819a83e178d4 100644 --- a/src/server/game/Scripting/ScriptDefines/TicketScript.h +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.h @@ -40,7 +40,7 @@ class TicketScript : public ScriptObject public: [[nodiscard]] bool IsDatabaseBound() const override { return false; } - virtual void OnCreateTicket(Player* /*player*/, GmTicket* /*ticket*/) { } + virtual void OnTicketCreate(Player* /*player*/, GmTicket* /*ticket*/) { } virtual void OnTicketUpdate(Player* /*player*/, GmTicket* /*ticket*/, std::string /*message*/) { } virtual void OnTicketClose(Player* /*player*/, GmTicket* /*ticket*/) { } virtual void OnTicketStatusUpdate(Player* /*player*/, GmTicket* /*ticket*/) { } From c95fe8f5b0b6d10554f96641f2c7edeccd393d65 Mon Sep 17 00:00:00 2001 From: iThorgrim Date: Wed, 22 Jan 2025 18:53:17 +0100 Subject: [PATCH 5/6] Fix: Update Hook and UpdateLastChange() signature --- src/server/game/Handlers/TicketHandler.cpp | 11 +---------- .../Scripting/ScriptDefines/TicketScript.cpp | 4 ++-- .../Scripting/ScriptDefines/TicketScript.h | 2 +- src/server/game/Scripting/ScriptMgr.h | 2 +- src/server/game/Tickets/TicketMgr.cpp | 11 ++++++++++- src/server/game/Tickets/TicketMgr.h | 2 +- src/server/scripts/Commands/cs_ticket.cpp | 18 +++++++++--------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index f26308b7a7b33a..eb6243b215f09b 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -20,7 +20,6 @@ #include "Language.h" #include "Opcodes.h" #include "Player.h" -#include "ScriptMgr.h" #include "TicketMgr.h" #include "Util.h" #include "World.h" @@ -117,12 +116,10 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) ticket->SetChatLog(times, chatLog); sTicketMgr->AddTicket(ticket); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName(), ticket->GetId()); - sScriptMgr->OnTicketCreate(GetPlayer(), ticket); - response = GMTICKET_RESPONSE_CREATE_SUCCESS; } @@ -151,8 +148,6 @@ void WorldSession::HandleGMTicketUpdateOpcode(WorldPacket& recv_data) ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETUPDATED, GetPlayer()->GetName(), ticket->GetId()); response = GMTICKET_RESPONSE_UPDATE_SUCCESS; - - sScriptMgr->OnTicketUpdate(GetPlayer(), ticket, message); } WorldPacket data(SMSG_GMTICKET_UPDATETEXT, 4); @@ -172,8 +167,6 @@ void WorldSession::HandleGMTicketDeleteOpcode(WorldPacket& /*recv_data*/) sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID()); sTicketMgr->SendTicket(this, nullptr); - - sScriptMgr->OnTicketClose(GetPlayer(), ticket); } } @@ -303,7 +296,5 @@ void WorldSession::HandleGMResponseResolve(WorldPacket& /*recvPacket*/) sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID()); sTicketMgr->SendTicket(this, nullptr); - - sScriptMgr->OnTicketResolve(GetPlayer(), ticket); } } diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp index ef60b91acd53af..af5cca73d72961 100644 --- a/src/server/game/Scripting/ScriptDefines/TicketScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.cpp @@ -24,9 +24,9 @@ void ScriptMgr::OnTicketCreate(Player* player, GmTicket* ticket) CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_CREATE_TICKET, script->OnTicketCreate(player, ticket)); } -void ScriptMgr::OnTicketUpdate(Player* player, GmTicket* ticket, std::string message) +void ScriptMgr::OnTicketUpdate(Player* player, GmTicket* ticket) { - CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_UPDATE_TICKET, script->OnTicketUpdate(player, ticket, message)); + CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_UPDATE_TICKET, script->OnTicketUpdate(player, ticket)); } void ScriptMgr::OnTicketClose(Player* player, GmTicket* ticket) diff --git a/src/server/game/Scripting/ScriptDefines/TicketScript.h b/src/server/game/Scripting/ScriptDefines/TicketScript.h index 80819a83e178d4..504fa483c684e8 100644 --- a/src/server/game/Scripting/ScriptDefines/TicketScript.h +++ b/src/server/game/Scripting/ScriptDefines/TicketScript.h @@ -41,7 +41,7 @@ class TicketScript : public ScriptObject [[nodiscard]] bool IsDatabaseBound() const override { return false; } virtual void OnTicketCreate(Player* /*player*/, GmTicket* /*ticket*/) { } - virtual void OnTicketUpdate(Player* /*player*/, GmTicket* /*ticket*/, std::string /*message*/) { } + virtual void OnTicketUpdate(Player* /*player*/, GmTicket* /*ticket*/) { } virtual void OnTicketClose(Player* /*player*/, GmTicket* /*ticket*/) { } virtual void OnTicketStatusUpdate(Player* /*player*/, GmTicket* /*ticket*/) { } virtual void OnTicketResolve(Player* /*player*/, GmTicket* /*ticket*/) { } diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 42a5fc38548103..51a3f4a370ae9d 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -702,7 +702,7 @@ class ScriptMgr public: /* TicketScript */ void OnTicketCreate(Player* player, GmTicket* ticket); - void OnTicketUpdate(Player* player, GmTicket* ticket, std::string message); + void OnTicketUpdate(Player* player, GmTicket* ticket); void OnTicketClose(Player* player, GmTicket* ticket); void OnTicketStatusUpdate(Player* player, GmTicket* ticket); void OnTicketResolve(Player* player, GmTicket* ticket); diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index e4d2d94df3a179..cacff3a38e459b 100644 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -25,6 +25,7 @@ #include "Log.h" #include "Opcodes.h" #include "Player.h" +#include "ScriptMgr.h" #include "World.h" #include "WorldPacket.h" #include "WorldSession.h" @@ -364,6 +365,8 @@ void TicketMgr::AddTicket(GmTicket* ticket) ++_openTicketCount; CharacterDatabaseTransaction trans = CharacterDatabaseTransaction(nullptr); ticket->SaveToDB(trans); + + sScriptMgr->OnTicketCreate(ticket->GetPlayer(), ticket); } void TicketMgr::CloseTicket(uint32 ticketId, ObjectGuid source) @@ -375,6 +378,8 @@ void TicketMgr::CloseTicket(uint32 ticketId, ObjectGuid source) if (source) --_openTicketCount; ticket->SaveToDB(trans); + + sScriptMgr->OnTicketClose(ticket->GetPlayer(), ticket); } } @@ -398,6 +403,8 @@ void TicketMgr::ResolveAndCloseTicket(uint32 ticketId, ObjectGuid source) if (source) --_openTicketCount; ticket->SaveToDB(trans); + + sScriptMgr->OnTicketResolve(ticket->GetPlayer(), ticket); } } @@ -438,7 +445,9 @@ void TicketMgr::SendTicket(WorldSession* session, GmTicket* ticket) const session->SendPacket(&data); } -void TicketMgr::UpdateLastChange() +void TicketMgr::UpdateLastChange(GmTicket* ticket) { _lastChange = GameTime::GetGameTime().count(); + + sScriptMgr->OnTicketUpdate(ticket->GetPlayer(), ticket); } diff --git a/src/server/game/Tickets/TicketMgr.h b/src/server/game/Tickets/TicketMgr.h index aa2369bd789c28..d3455671660feb 100644 --- a/src/server/game/Tickets/TicketMgr.h +++ b/src/server/game/Tickets/TicketMgr.h @@ -230,7 +230,7 @@ class TicketMgr void SetStatus(bool status) { _status = status; } uint64 GetLastChange() const { return _lastChange; } - void UpdateLastChange(); + void UpdateLastChange(GmTicket* ticket); uint32 GenerateTicketId() { return ++_lastTicketId; } uint32 GetOpenTicketCount() const { return _openTicketCount; } diff --git a/src/server/scripts/Commands/cs_ticket.cpp b/src/server/scripts/Commands/cs_ticket.cpp index bef6f6f13ad612..166b0fa446f2d2 100644 --- a/src/server/scripts/Commands/cs_ticket.cpp +++ b/src/server/scripts/Commands/cs_ticket.cpp @@ -117,7 +117,7 @@ class ticket_commandscript : public CommandScript CharacterDatabaseTransaction trans = CharacterDatabaseTransaction(nullptr); ticket->SetAssignedTo(targetGuid, AccountMgr::IsAdminAccount(targetGmLevel)); ticket->SaveToDB(trans); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); std::string msg = ticket->FormatMessageString(*handler, nullptr, target.c_str(), nullptr, nullptr); handler->SendGlobalGMSysMessage(msg.c_str()); @@ -143,7 +143,7 @@ class ticket_commandscript : public CommandScript } sTicketMgr->ResolveAndCloseTicket(ticket->GetId(), player ? player->GetGUID() : ObjectGuid::Empty); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); std::string msg = ticket->FormatMessageString(*handler, player ? player->GetName().c_str() : "Console", nullptr, nullptr, nullptr); handler->SendGlobalGMSysMessage(msg.c_str()); @@ -182,7 +182,7 @@ class ticket_commandscript : public CommandScript CharacterDatabaseTransaction trans = CharacterDatabaseTransaction(nullptr); ticket->SetComment(comment.data()); ticket->SaveToDB(trans); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); std::string const assignedName = ticket->GetAssignedToName(); std::string msg = ticket->FormatMessageString(*handler, assignedName.empty() ? nullptr : assignedName.c_str(), nullptr, nullptr, nullptr); @@ -237,7 +237,7 @@ class ticket_commandscript : public CommandScript std::string msg = ticket->FormatMessageString(*handler, nullptr, nullptr, nullptr, nullptr); msg += handler->PGetParseString(LANG_COMMAND_TICKETCOMPLETED, gm ? gm->GetName().c_str() : "Console"); handler->SendGlobalGMSysMessage(msg.c_str()); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); return true; } @@ -260,7 +260,7 @@ class ticket_commandscript : public CommandScript handler->SendGlobalGMSysMessage(msg.c_str()); sTicketMgr->RemoveTicket(ticket->GetId()); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); if (Player* player = ticket->GetPlayer()) { @@ -287,7 +287,7 @@ class ticket_commandscript : public CommandScript if (Player* player = ticket->GetPlayer()) sTicketMgr->SendTicket(player->GetSession(), ticket); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); return true; } @@ -373,7 +373,7 @@ class ticket_commandscript : public CommandScript CharacterDatabaseTransaction trans = CharacterDatabaseTransaction(nullptr); ticket->SetUnassigned(); ticket->SaveToDB(trans); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); std::string msg = ticket->FormatMessageString(*handler, nullptr, assignedTo.c_str(), handler->GetSession() ? handler->GetSession()->GetPlayer()->GetName().c_str() : "Console", nullptr); @@ -464,7 +464,7 @@ class ticket_commandscript : public CommandScript ticket->AppendResponse("\n"); ticket->AppendResponse(response); ticket->SaveToDB(trans); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); std::string msg = ticket->FormatMessageString(*handler, nullptr, nullptr, nullptr, nullptr); msg += handler->PGetParseString(LANG_COMMAND_TICKETRESPONSEAPPENDED, response); @@ -505,7 +505,7 @@ class ticket_commandscript : public CommandScript CharacterDatabaseTransaction trans = CharacterDatabaseTransaction(nullptr); ticket->DeleteResponse(); ticket->SaveToDB(trans); - sTicketMgr->UpdateLastChange(); + sTicketMgr->UpdateLastChange(ticket); std::string msg = ticket->FormatMessageString(*handler, nullptr, nullptr, nullptr, nullptr); msg += handler->PGetParseString(LANG_COMMAND_TICKETRESPONSEDELETED, player ? player->GetName() : "Console"); From f71215d9612d5b6528402e0b63814f5eca1281ed Mon Sep 17 00:00:00 2001 From: iThorgrim Date: Wed, 22 Jan 2025 19:02:19 +0100 Subject: [PATCH 6/6] Fix action warning about whitespace --- src/server/game/Tickets/TicketMgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index cacff3a38e459b..89af0474be6219 100644 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -448,6 +448,6 @@ void TicketMgr::SendTicket(WorldSession* session, GmTicket* ticket) const void TicketMgr::UpdateLastChange(GmTicket* ticket) { _lastChange = GameTime::GetGameTime().count(); - + sScriptMgr->OnTicketUpdate(ticket->GetPlayer(), ticket); }