From 6e0d7224d36feff8d01cc34fb7e521adcd46554e Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Sun, 1 Sep 2024 23:43:19 -0300 Subject: [PATCH] update --- src/lua/modules/modules.cpp | 10 ++++++---- src/lua/modules/modules.hpp | 2 +- src/server/network/protocol/protocolgame.cpp | 14 ++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index 8b79524ec2c..940cce7860f 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -77,10 +77,10 @@ Module* Modules::getEventByRecvbyte(uint8_t recvbyte, bool force) { return nullptr; } -void Modules::executeOnRecvbyte(uint32_t playerId, NetworkMessage &msg, uint8_t byte) const { - std::shared_ptr player = g_game().getPlayerByID(playerId); +bool Modules::executeOnRecvbyte(const uint32_t playerId, NetworkMessage &msg, const uint8_t byte) const { + const auto &player = g_game().getPlayerByID(playerId); if (!player) { - return; + return false; } for (auto &it : recvbyteList) { @@ -88,9 +88,11 @@ void Modules::executeOnRecvbyte(uint32_t playerId, NetworkMessage &msg, uint8_t if (module.getEventType() == MODULE_TYPE_RECVBYTE && module.getRecvbyte() == byte && player->canRunModule(module.getRecvbyte())) { player->setModuleDelay(module.getRecvbyte(), module.getDelay()); module.executeOnRecvbyte(player, msg); - return; + return true; } } + + return false; } Module::Module(LuaScriptInterface* interface) : diff --git a/src/lua/modules/modules.hpp b/src/lua/modules/modules.hpp index 6543138d515..4eb98a23b60 100644 --- a/src/lua/modules/modules.hpp +++ b/src/lua/modules/modules.hpp @@ -67,7 +67,7 @@ class Modules final : public BaseEvents { return inject(); } - void executeOnRecvbyte(uint32_t playerId, NetworkMessage &msg, uint8_t byte) const; + bool executeOnRecvbyte(const uint32_t playerId, NetworkMessage &msg, const uint8_t byte) const; Module* getEventByRecvbyte(uint8_t recvbyte, bool force); protected: diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 032b9b512d0..c01bba42bd2 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -928,11 +928,6 @@ void ProtocolGame::parsePacket(NetworkMessage &msg) { return; } - // Modules system - if (player && recvbyte != 0xD3) { - g_modules().executeOnRecvbyte(player->getID(), msg, recvbyte); - } - parsePacketFromDispatcher(msg, recvbyte); } @@ -1369,9 +1364,12 @@ void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyt // case 0xDF, 0xE0, 0xE1, 0xFB, 0xFC, 0xFD, 0xFE Premium Shop. default: - std::string hexString = fmt::format("0x{:02x}", recvbyte); - g_logger().debug("Player '{}' sent unknown packet header: hex[{}], decimal[{}]", player->getName(), asUpperCaseString(hexString), recvbyte); - break; + // Modules system + if (!g_modules().executeOnRecvbyte(player->getID(), msg, recvbyte)) { + std::string hexString = fmt::format("0x{:02x}", recvbyte); + g_logger().debug("Player '{}' sent unknown packet header: hex[{}], decimal[{}]", player->getName(), asUpperCaseString(hexString), recvbyte); + break; + } } }