Skip to content

Commit

Permalink
fix: suppress get byte log (#3185)
Browse files Browse the repository at this point in the history
Resolves #3153

This simple "suppress" the "getByte" log, some locations send "0" by
default, so we don't need to send log in these locations.
  • Loading branch information
dudantas authored Dec 21, 2024
1 parent f2750bb commit 13ae9e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/server/network/message/networkmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ int32_t NetworkMessage::decodeHeader() {
}

// Simply read functions for incoming message
uint8_t NetworkMessage::getByte(const std::source_location &location /*= std::source_location::current()*/) {
uint8_t NetworkMessage::getByte(bool suppresLog /*= false*/, const std::source_location &location /*= std::source_location::current()*/) {
// Check if there is at least 1 byte to read
if (!canRead(1)) {
g_logger().error("[{}] Not enough data to read a byte. Current position: {}, Length: {}. Called line {}:{} in {}", __FUNCTION__, info.position, info.length, location.line(), location.column(), location.function_name());
if (!suppresLog) {
g_logger().error("[{}] Not enough data to read a byte. Current position: {}, Length: {}. Called line {}:{} in {}", __FUNCTION__, info.position, info.length, location.line(), location.column(), location.function_name());
}
return {};
}

Expand Down Expand Up @@ -113,7 +115,7 @@ Position NetworkMessage::getPosition() {
Position pos;
pos.x = get<uint16_t>();
pos.y = get<uint16_t>();
pos.z = getByte();
pos.z = getByte(true);
return pos;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/network/message/networkmessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NetworkMessage {
}

// simply read functions for incoming message
uint8_t getByte(const std::source_location &location = std::source_location::current());
uint8_t getByte(bool suppresLog = false, const std::source_location &location = std::source_location::current());

uint8_t getPreviousByte();

Expand Down
16 changes: 8 additions & 8 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,14 +1713,14 @@ void ProtocolGame::parseSetOutfit(NetworkMessage &msg) {
}

void ProtocolGame::parseToggleMount(NetworkMessage &msg) {
bool mount = msg.getByte() != 0;
bool mount = msg.getByte(true) != 0;
g_game().playerToggleMount(player->getID(), mount);
}

void ProtocolGame::parseApplyImbuement(NetworkMessage &msg) {
uint8_t slot = msg.getByte();
auto imbuementId = msg.get<uint32_t>();
bool protectionCharm = msg.getByte() != 0x00;
bool protectionCharm = msg.getByte(true) != 0x00;
g_game().playerApplyImbuement(player->getID(), imbuementId, slot, protectionCharm);
}

Expand Down Expand Up @@ -1967,16 +1967,16 @@ void ProtocolGame::parsePlayerBuyOnShop(NetworkMessage &msg) {
auto id = msg.get<uint16_t>();
uint8_t count = msg.getByte();
uint16_t amount = oldProtocol ? static_cast<uint16_t>(msg.getByte()) : msg.get<uint16_t>();
bool ignoreCap = msg.getByte() != 0;
bool inBackpacks = msg.getByte() != 0;
bool ignoreCap = msg.getByte(true) != 0;
bool inBackpacks = msg.getByte(true) != 0;
g_game().playerBuyItem(player->getID(), id, count, amount, ignoreCap, inBackpacks);
}

void ProtocolGame::parsePlayerSellOnShop(NetworkMessage &msg) {
auto id = msg.get<uint16_t>();
uint8_t count = std::max(msg.getByte(), (uint8_t)1);
uint16_t amount = oldProtocol ? static_cast<uint16_t>(msg.getByte()) : msg.get<uint16_t>();
bool ignoreEquipped = msg.getByte() != 0;
bool ignoreEquipped = msg.getByte(true) != 0;

g_game().playerSellItem(player->getID(), id, count, amount, ignoreEquipped);
}
Expand Down Expand Up @@ -2010,7 +2010,7 @@ void ProtocolGame::parseEditVip(NetworkMessage &msg) {
auto guid = msg.get<uint32_t>();
const std::string description = msg.getString();
uint32_t icon = std::min<uint32_t>(10, msg.get<uint32_t>()); // 10 is max icon in 9.63
bool notify = msg.getByte() != 0;
bool notify = msg.getByte(true) != 0;
uint8_t groupsAmount = msg.getByte();
for (uint8_t i = 0; i < groupsAmount; ++i) {
uint8_t groupId = msg.getByte();
Expand Down Expand Up @@ -2176,7 +2176,7 @@ void ProtocolGame::parseTaskHuntingAction(NetworkMessage &msg) {

uint8_t slot = msg.getByte();
uint8_t action = msg.getByte();
bool upgrade = msg.getByte() != 0;
bool upgrade = msg.getByte(true) != 0;
auto raceId = msg.get<uint16_t>();

if (!g_configManager().getBoolean(TASK_HUNTING_ENABLED)) {
Expand Down Expand Up @@ -3141,7 +3141,7 @@ void ProtocolGame::parseMarketCreateOffer(NetworkMessage &msg) {

auto amount = msg.get<uint16_t>();
uint64_t price = oldProtocol ? static_cast<uint64_t>(msg.get<uint32_t>()) : msg.get<uint64_t>();
bool anonymous = (msg.getByte() != 0);
bool anonymous = (msg.getByte(true) != 0);
if (amount > 0 && price > 0) {
g_game().playerCreateMarketOffer(player->getID(), type, itemId, amount, price, itemTier, anonymous);
}
Expand Down

0 comments on commit 13ae9e5

Please sign in to comment.