Skip to content

Commit 13ae9e5

Browse files
authored
fix: suppress get byte log (#3185)
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.
1 parent f2750bb commit 13ae9e5

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/server/network/message/networkmessage.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ int32_t NetworkMessage::decodeHeader() {
4545
}
4646

4747
// Simply read functions for incoming message
48-
uint8_t NetworkMessage::getByte(const std::source_location &location /*= std::source_location::current()*/) {
48+
uint8_t NetworkMessage::getByte(bool suppresLog /*= false*/, const std::source_location &location /*= std::source_location::current()*/) {
4949
// Check if there is at least 1 byte to read
5050
if (!canRead(1)) {
51-
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());
51+
if (!suppresLog) {
52+
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());
53+
}
5254
return {};
5355
}
5456

@@ -113,7 +115,7 @@ Position NetworkMessage::getPosition() {
113115
Position pos;
114116
pos.x = get<uint16_t>();
115117
pos.y = get<uint16_t>();
116-
pos.z = getByte();
118+
pos.z = getByte(true);
117119
return pos;
118120
}
119121

src/server/network/message/networkmessage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class NetworkMessage {
3434
}
3535

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

3939
uint8_t getPreviousByte();
4040

src/server/network/protocol/protocolgame.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,14 +1713,14 @@ void ProtocolGame::parseSetOutfit(NetworkMessage &msg) {
17131713
}
17141714

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

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

@@ -1967,16 +1967,16 @@ void ProtocolGame::parsePlayerBuyOnShop(NetworkMessage &msg) {
19671967
auto id = msg.get<uint16_t>();
19681968
uint8_t count = msg.getByte();
19691969
uint16_t amount = oldProtocol ? static_cast<uint16_t>(msg.getByte()) : msg.get<uint16_t>();
1970-
bool ignoreCap = msg.getByte() != 0;
1971-
bool inBackpacks = msg.getByte() != 0;
1970+
bool ignoreCap = msg.getByte(true) != 0;
1971+
bool inBackpacks = msg.getByte(true) != 0;
19721972
g_game().playerBuyItem(player->getID(), id, count, amount, ignoreCap, inBackpacks);
19731973
}
19741974

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

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

21772177
uint8_t slot = msg.getByte();
21782178
uint8_t action = msg.getByte();
2179-
bool upgrade = msg.getByte() != 0;
2179+
bool upgrade = msg.getByte(true) != 0;
21802180
auto raceId = msg.get<uint16_t>();
21812181

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

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

0 commit comments

Comments
 (0)