fix(Server/Scripting): Remove packet copy from server script hooks (#25063)

Co-authored-by: Benjamin Jackson <38561765+heyitsbench@users.noreply.github.com>
Co-authored-by: Andrew <47818697+Nyeriah@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Takenbacon
2026-03-13 12:04:24 -07:00
committed by GitHub
parent 0550b7778b
commit 7b1355f15e
2 changed files with 8 additions and 12 deletions
@@ -50,9 +50,7 @@ bool ScriptMgr::CanPacketSend(WorldSession* session, WorldPacket const& packet)
if (ScriptRegistry<ServerScript>::ScriptPointerList.empty()) if (ScriptRegistry<ServerScript>::ScriptPointerList.empty())
return true; return true;
WorldPacket copy(packet); CALL_ENABLED_BOOLEAN_HOOKS(ServerScript, SERVERHOOK_CAN_PACKET_SEND, !script->CanPacketSend(session, packet));
CALL_ENABLED_BOOLEAN_HOOKS(ServerScript, SERVERHOOK_CAN_PACKET_SEND, !script->CanPacketSend(session, copy));
} }
bool ScriptMgr::CanPacketReceive(WorldSession* session, WorldPacket const& packet) bool ScriptMgr::CanPacketReceive(WorldSession* session, WorldPacket const& packet)
@@ -60,9 +58,7 @@ bool ScriptMgr::CanPacketReceive(WorldSession* session, WorldPacket const& packe
if (ScriptRegistry<ServerScript>::ScriptPointerList.empty()) if (ScriptRegistry<ServerScript>::ScriptPointerList.empty())
return true; return true;
WorldPacket copy(packet); CALL_ENABLED_BOOLEAN_HOOKS(ServerScript, SERVERHOOK_CAN_PACKET_RECEIVE, !script->CanPacketReceive(session, packet));
CALL_ENABLED_BOOLEAN_HOOKS(ServerScript, SERVERHOOK_CAN_PACKET_RECEIVE, !script->CanPacketReceive(session, copy));
} }
ServerScript::ServerScript(const char* name, std::vector<uint16> enabledHooks) ServerScript::ServerScript(const char* name, std::vector<uint16> enabledHooks)
@@ -53,23 +53,23 @@ public:
virtual void OnSocketClose(std::shared_ptr<WorldSocket> const& /*socket*/) { } virtual void OnSocketClose(std::shared_ptr<WorldSocket> const& /*socket*/) { }
/** /**
* @brief This hook called when a packet is sent to a client. The packet object is a copy of the original packet, so reading and modifying it is safe. * @brief This hook is called when a packet is sent to a client.
* *
* @param session Contains information about the WorldSession * @param session Contains information about the WorldSession
* @param packet Contains information about the WorldPacket * @param packet Contains information about the WorldPacket
* @return True if you want to continue sending the packet, false if you want to disallow sending the packet * @return True if you want to continue sending the packet, false if you want to disallow sending the packet
*/ */
[[nodiscard]] virtual bool CanPacketSend(WorldSession* /*session*/, WorldPacket& /*packet*/) { return true; } [[nodiscard]] virtual bool CanPacketSend(WorldSession* /*session*/, WorldPacket const& /*packet*/) { return true; }
/** /**
* @brief Called when a (valid) packet is received by a client. The packet object is a copy of the original packet, so * @brief Called when a (valid) packet is received by a client.
* reading and modifying it is safe. Make sure to check WorldSession pointer before usage, it might be null in case of auth packets * Make sure to check WorldSession pointer before usage, it might be null in case of auth packets
* *
* @param session Contains information about the WorldSession * @param session Contains information about the WorldSession
* @param packet Contains information about the WorldPacket * @param packet Contains information about the WorldPacket
* @return True if you want to continue receive the packet, false if you want to disallow receive the packet * @return True if you want to continue receiving the packet, false if you want to disallow receiving the packet
*/ */
[[nodiscard]] virtual bool CanPacketReceive(WorldSession* /*session*/, WorldPacket& /*packet*/) { return true; } [[nodiscard]] virtual bool CanPacketReceive(WorldSession* /*session*/, WorldPacket const& /*packet*/) { return true; }
}; };
#endif #endif