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

improve: improvement in receiving the bytes used in modules #2870

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
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)) {
Copy link
Contributor

@dudantas dudantas Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check: recvbyte != 0xD3 is still necessary? Because this byte is checked in another place (in the outfit window)

outfitModule->executeOnRecvbyte(player, msg);

Copy link
Contributor Author

@luanluciano93 luanluciano93 Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In "recvbyte != 0xD3" the byte is not sent to executeOnRecvbyte and within the "case" it will also not reach executeOnRecvbyt, only within parseSetOutfit, as it already is, so the change does not change the functioning of this part.

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
Loading