Skip to content

Commit

Permalink
Move static IOBan methods to namespace (#4777)
Browse files Browse the repository at this point in the history
* Move IOBan to namespace from class with static methods

* Format
  • Loading branch information
ranisalt committed Sep 18, 2024
1 parent 416df19 commit 4cd6cbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/ban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "database.h"
#include "databasetasks.h"

const std::optional<BanInfo> IOBan::getAccountBanInfo(uint32_t accountId)
namespace IOBan {

const std::optional<BanInfo> getAccountBanInfo(uint32_t accountId)
{
Database& db = Database::getInstance();

Expand Down Expand Up @@ -43,7 +45,7 @@ const std::optional<BanInfo> IOBan::getAccountBanInfo(uint32_t accountId)
return banInfo;
}

const std::optional<BanInfo> IOBan::getIpBanInfo(const Connection::Address& clientIP)
const std::optional<BanInfo> getIpBanInfo(const Connection::Address& clientIP)
{
if (clientIP.is_unspecified()) {
return std::nullopt;
Expand Down Expand Up @@ -77,9 +79,11 @@ const std::optional<BanInfo> IOBan::getIpBanInfo(const Connection::Address& clie
return banInfo;
}

bool IOBan::isPlayerNamelocked(uint32_t playerId)
bool isPlayerNamelocked(uint32_t playerId)
{
return Database::getInstance()
.storeQuery(fmt::format("SELECT 1 FROM `player_namelocks` WHERE `player_id` = {:d}", playerId))
.get();
}

} // namespace IOBan
14 changes: 7 additions & 7 deletions src/ban.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

#include "connection.h"

namespace IOBan {

struct BanInfo
{
std::string bannedBy;
std::string reason;
time_t expiresAt;
};

class IOBan
{
public:
static const std::optional<BanInfo> getAccountBanInfo(uint32_t accountId);
static const std::optional<BanInfo> getIpBanInfo(const Connection::Address& clientIP);
static bool isPlayerNamelocked(uint32_t playerId);
};
const std::optional<BanInfo> getAccountBanInfo(uint32_t accountId);
const std::optional<BanInfo> getIpBanInfo(const Connection::Address& clientIP);
bool isPlayerNamelocked(uint32_t playerId);

}; // namespace IOBan

#endif // FS_BAN_H

0 comments on commit 4cd6cbe

Please sign in to comment.