From e9080f91f28af50a649c146ea34c371ef19affc3 Mon Sep 17 00:00:00 2001 From: wrrrzr <161970349+wrrrzr@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:52:13 +0300 Subject: [PATCH] Cleanup ban.cpp/h (#15496) Make BanManager more const correctly Delete unused includes --- src/server/ban.cpp | 13 ++++++------- src/server/ban.h | 13 +++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/server/ban.cpp b/src/server/ban.cpp index 737f5a57e..e63c4708f 100644 --- a/src/server/ban.cpp +++ b/src/server/ban.cpp @@ -7,11 +7,11 @@ #include #include "threading/mutex_auto_lock.h" #include -#include #include "util/strfnd.h" #include "util/string.h" #include "log.h" #include "filesys.h" +#include "exceptions.h" BanManager::BanManager(const std::string &banfilepath): m_banfilepath(banfilepath) @@ -68,13 +68,13 @@ void BanManager::save() m_modified = false; } -bool BanManager::isIpBanned(const std::string &ip) +bool BanManager::isIpBanned(const std::string &ip) const { MutexAutoLock lock(m_mutex); return m_ips.find(ip) != m_ips.end(); } -std::string BanManager::getBanDescription(const std::string &ip_or_name) +std::string BanManager::getBanDescription(const std::string &ip_or_name) const { MutexAutoLock lock(m_mutex); std::string s; @@ -88,10 +88,10 @@ std::string BanManager::getBanDescription(const std::string &ip_or_name) return s; } -std::string BanManager::getBanName(const std::string &ip) +std::string BanManager::getBanName(const std::string &ip) const { MutexAutoLock lock(m_mutex); - StringMap::iterator it = m_ips.find(ip); + StringMap::const_iterator it = m_ips.find(ip); if (it == m_ips.end()) return ""; return it->second; @@ -118,9 +118,8 @@ void BanManager::remove(const std::string &ip_or_name) } -bool BanManager::isModified() +bool BanManager::isModified() const { MutexAutoLock lock(m_mutex); return m_modified; } - diff --git a/src/server/ban.h b/src/server/ban.h index 146f3210a..4acd58fba 100644 --- a/src/server/ban.h +++ b/src/server/ban.h @@ -5,9 +5,6 @@ #pragma once #include "util/string.h" -#include "threading/thread.h" -#include "exceptions.h" -#include #include #include @@ -18,16 +15,16 @@ public: ~BanManager(); void load(); void save(); - bool isIpBanned(const std::string &ip); + bool isIpBanned(const std::string &ip) const; // Supplying ip_or_name = "" lists all bans. - std::string getBanDescription(const std::string &ip_or_name); - std::string getBanName(const std::string &ip); + std::string getBanDescription(const std::string &ip_or_name) const; + std::string getBanName(const std::string &ip) const; void add(const std::string &ip, const std::string &name); void remove(const std::string &ip_or_name); - bool isModified(); + bool isModified() const; private: - std::mutex m_mutex; + mutable std::mutex m_mutex; std::string m_banfilepath = ""; StringMap m_ips; bool m_modified = false;