Skip to content

Commit

Permalink
Cleanup ban.cpp/h (minetest#15496)
Browse files Browse the repository at this point in the history
Make BanManager more const correctly
Delete unused includes
  • Loading branch information
wrrrzr authored Dec 1, 2024
1 parent 7cc5a6e commit e9080f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
13 changes: 6 additions & 7 deletions src/server/ban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

13 changes: 5 additions & 8 deletions src/server/ban.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#pragma once

#include "util/string.h"
#include "threading/thread.h"
#include "exceptions.h"
#include <map>
#include <string>
#include <mutex>

Expand All @@ -18,16 +15,16 @@ class BanManager
~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;
Expand Down

0 comments on commit e9080f9

Please sign in to comment.