Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Core/Scripting): Add new hooks for Ticket #21238

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/game/Handlers/TicketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
58 changes: 58 additions & 0 deletions src/server/game/Scripting/ScriptDefines/TicketScript.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "TicketScript.h"
#include "ScriptMgr.h"
#include "ScriptMgrMacros.h"

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)
{
CALL_ENABLED_HOOKS(TicketScript, TICKETHOOK_ON_UPDATE_TICKET, script->OnTicketUpdate(player, ticket));
}

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<uint16> 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<TicketScript>::AddScript(this, std::move(enabledHooks));
}

template class AC_GAME_API ScriptRegistry<TicketScript>;
50 changes: 50 additions & 0 deletions src/server/game/Scripting/ScriptDefines/TicketScript.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef SCRIPT_OBJECT_TICKET_SCRIPT_H_
#define SCRIPT_OBJECT_TICKET_SCRIPT_H_

#include "ScriptObject.h"
#include "TicketMgr.h"
#include <vector>

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<uint16> enabledHooks = std::vector<uint16>());

public:
[[nodiscard]] bool IsDatabaseBound() const override { return false; }

virtual void OnTicketCreate(Player* /*player*/, GmTicket* /*ticket*/) { }
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*/) { }
};

#endif
5 changes: 4 additions & 1 deletion src/server/game/Scripting/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void ScriptMgr::Initialize()
ScriptRegistry<PlayerScript>::InitEnabledHooksIfNeeded(PLAYERHOOK_END);
ScriptRegistry<ServerScript>::InitEnabledHooksIfNeeded(SERVERHOOK_END);
ScriptRegistry<SpellSC>::InitEnabledHooksIfNeeded(ALLSPELLHOOK_END);
ScriptRegistry<TicketScript>::InitEnabledHooksIfNeeded(TICKETHOOK_END);
ScriptRegistry<UnitScript>::InitEnabledHooksIfNeeded(UNITHOOK_END);
ScriptRegistry<WorldObjectScript>::InitEnabledHooksIfNeeded(WORLDOBJECTHOOK_END);
ScriptRegistry<WorldScript>::InitEnabledHooksIfNeeded(WORLDHOOK_END);
Expand Down Expand Up @@ -145,6 +146,7 @@ void ScriptMgr::Unload()
SCR_CLEAR<ServerScript>();
SCR_CLEAR<SpellSC>();
SCR_CLEAR<SpellScriptLoader>();
SCR_CLEAR<TicketScript>();
SCR_CLEAR<TransportScript>();
SCR_CLEAR<UnitScript>();
SCR_CLEAR<VehicleScript>();
Expand Down Expand Up @@ -224,7 +226,8 @@ void ScriptMgr::CheckIfScriptsInDatabaseExist()
!ScriptRegistry<CommandSC>::GetScriptById(sid) &&
!ScriptRegistry<ArenaScript>::GetScriptById(sid) &&
!ScriptRegistry<GroupScript>::GetScriptById(sid) &&
!ScriptRegistry<DatabaseScript>::GetScriptById(sid))
!ScriptRegistry<DatabaseScript>::GetScriptById(sid) &&
!ScriptRegistry<TicketScript>::GetScriptById(sid))
{
LOG_ERROR("sql.sql", "Script named '{}' is assigned in the database, but has no code!", scriptName);
}
Expand Down
8 changes: 8 additions & 0 deletions src/server/game/Scripting/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ class ScriptMgr

void OnLootMoney(Player* player, uint32 gold);

public: /* TicketScript */

void OnTicketCreate(Player* player, GmTicket* ticket);
void OnTicketUpdate(Player* player, GmTicket* ticket);
void OnTicketClose(Player* player, GmTicket* ticket);
void OnTicketStatusUpdate(Player* player, GmTicket* ticket);
void OnTicketResolve(Player* player, GmTicket* ticket);

private:
uint32 _scriptCount;

Expand Down
1 change: 1 addition & 0 deletions src/server/game/Scripting/ScriptObjectFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SpellCastTargets;
class SpellInfo;
class SpellScript;
class TempSummon;
class TicketMgr;
class Transport;
class Unit;
class Vehicle;
Expand Down
11 changes: 10 additions & 1 deletion src/server/game/Tickets/TicketMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -375,6 +378,8 @@ void TicketMgr::CloseTicket(uint32 ticketId, ObjectGuid source)
if (source)
--_openTicketCount;
ticket->SaveToDB(trans);

sScriptMgr->OnTicketClose(ticket->GetPlayer(), ticket);
}
}

Expand All @@ -398,6 +403,8 @@ void TicketMgr::ResolveAndCloseTicket(uint32 ticketId, ObjectGuid source)
if (source)
--_openTicketCount;
ticket->SaveToDB(trans);

sScriptMgr->OnTicketResolve(ticket->GetPlayer(), ticket);
}
}

Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/server/game/Tickets/TicketMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
18 changes: 9 additions & 9 deletions src/server/scripts/Commands/cs_ticket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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())
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Loading