Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 committed Sep 2, 2024
1 parent 8056ca6 commit 6e0d722
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/lua/modules/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,22 @@ 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> 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) {
Module module = it.second;
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) :
Expand Down
2 changes: 1 addition & 1 deletion src/lua/modules/modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Modules final : public BaseEvents {
return inject<Modules>();
}

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:
Expand Down
14 changes: 6 additions & 8 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 6e0d722

Please sign in to comment.