Skip to content

Commit

Permalink
fix: sonar checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Oct 10, 2024
1 parent 8d5afaf commit 361e877
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/creatures/players/livestream/livestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const std::map<std::string, uint32_t, std::less<>> &Livestream::getLivestreamBan
void Livestream::setBanViewer(const std::vector<std::string> &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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1539,7 +1539,7 @@ void Livestream::updateViewerName(const ProtocolGame_ptr &client, std::map<Proto
sendChannelMessage("", 0, fmt::format("{} was renamed to {}.", sit->second.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);
}
Expand All @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<Player> &foundPlayer) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/network/protocol/protocollogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void ProtocolLogin::getLivestreamViewersList(const std::string &password) {

uint8_t size = std::min<size_t>(std::numeric_limits<uint8_t>::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());
Expand Down

0 comments on commit 361e877

Please sign in to comment.