From 361e8779dda9f92840f715b10775eb2f622d1ce2 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 9 Oct 2024 22:44:04 -0300 Subject: [PATCH] fix: sonar checks --- src/creatures/players/livestream/livestream.cpp | 8 ++++---- src/server/network/protocol/protocolgame.cpp | 12 +++++------- src/server/network/protocol/protocollogin.cpp | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/creatures/players/livestream/livestream.cpp b/src/creatures/players/livestream/livestream.cpp index 9eb1503a902..19015942d39 100644 --- a/src/creatures/players/livestream/livestream.cpp +++ b/src/creatures/players/livestream/livestream.cpp @@ -85,7 +85,7 @@ const std::map> &Livestream::getLivestreamBan void Livestream::setBanViewer(const std::vector &bans) { // Remove banned viewers not in the new bans list auto removedCount = std::erase_if(m_bans, [&bans](const auto &ban) { - return std::ranges::find(bans.begin(), bans.end(), ban.first) == bans.end(); + return std::ranges::find(bans, ban.first) == bans.end(); }); g_logger().debug("[{}] removed {} banned viewers", __METHOD_NAME__, removedCount); @@ -1444,7 +1444,7 @@ void Livestream::removeViewer(const ProtocolGame_ptr &client, bool spy) { return; } - auto mit = std::ranges::find(m_mutes.begin(), m_mutes.end(), it->second.name); + auto mit = std::ranges::find(m_mutes, it->second.name); if (mit != m_mutes.end()) { m_mutes.erase(mit); } @@ -1539,7 +1539,7 @@ void Livestream::updateViewerName(const ProtocolGame_ptr &client, std::mapsecond.name, newName), TALKTYPE_CHANNEL_O, CHANNEL_LIVESTREAM); // Update the muted list with the new name if necessary - auto mit = std::ranges::find(m_mutes.begin(), m_mutes.end(), asLowerCaseString(sit->second.name)); + auto mit = std::ranges::find(m_mutes, asLowerCaseString(sit->second.name)); if (mit != m_mutes.end()) { (*mit) = asLowerCaseString(newName); } @@ -1558,7 +1558,7 @@ bool Livestream::isNameAvailable(const std::string &name) const { } void Livestream::handleChatMessage(const std::string &playerName, const ProtocolGame_ptr &client, const std::string &text) { - auto mit = std::ranges::find(m_mutes.begin(), m_mutes.end(), asLowerCaseString(playerName)); + auto mit = std::ranges::find(m_mutes, asLowerCaseString(playerName)); if (mit == m_mutes.end()) { sendChannelMessage(playerName, 0, text, TALKTYPE_CHANNEL_Y, CHANNEL_LIVESTREAM); } else { diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index a2a78f3bffe..1cfa0d96015 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -1989,7 +1989,7 @@ void ProtocolGame::parseSay(NetworkMessage &msg) { bool isLivestreamChannel = channelId == CHANNEL_LIVESTREAM; if (isLivestreamChannel) { g_dispatcher().addEvent( - [client = player->client, self = getThis(), text, channelId] { client->handle(self, text); }, "Livestream::handle" + [client = player->client, self = getThis(), text] { client->handle(self, text); }, "Livestream::handle" ); return; } @@ -9359,12 +9359,10 @@ void ProtocolGame::insertLivestreamCaster() { } void ProtocolGame::removeLivestreamCaster() { - for (const auto &it : getLivestreamCasters()) { - if (it.first == player) { - getLivestreamCasters().erase(player); - break; - } - } + auto &livestreamCasters = getLivestreamCasters(); + std::erase_if(livestreamCasters, [this](const auto &caster) { + return caster.first == player; + }); } void ProtocolGame::sendLivestreamViewerAppear(const std::shared_ptr &foundPlayer) { diff --git a/src/server/network/protocol/protocollogin.cpp b/src/server/network/protocol/protocollogin.cpp index c3c376cd07b..3a8e6242b3c 100644 --- a/src/server/network/protocol/protocollogin.cpp +++ b/src/server/network/protocol/protocollogin.cpp @@ -236,7 +236,7 @@ void ProtocolLogin::getLivestreamViewersList(const std::string &password) { uint8_t size = std::min(std::numeric_limits::max(), players.size()); output->addByte(size); - std::ranges::sort(players.begin(), players.end(), Player::sortByLivestreamViewerCount); + std::ranges::sort(players, Player::sortByLivestreamViewerCount); for (const auto &player : players) { output->addByte(uint8_t());