mirror of
https://github.com/minetest/minetest.git
synced 2024-12-02 04:23:45 +01:00
Cleanup ban.cpp/h (#15496)
Make BanManager more const correctly Delete unused includes
This commit is contained in:
parent
7cc5a6ec68
commit
e9080f91f2
@ -7,11 +7,11 @@
|
||||
#include <fstream>
|
||||
#include "threading/mutex_auto_lock.h"
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/string.h"
|
||||
#include "threading/thread.h"
|
||||
#include "exceptions.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user