forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathban.h
47 lines (37 loc) · 1.01 KB
/
ban.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.
#ifndef FS_BAN_H
#define FS_BAN_H
#include "connection.h"
struct BanInfo
{
std::string bannedBy;
std::string reason;
time_t expiresAt;
};
struct ConnectBlock
{
constexpr ConnectBlock(uint64_t lastAttempt, uint64_t blockTime, uint32_t count) :
lastAttempt(lastAttempt), blockTime(blockTime), count(count)
{}
uint64_t lastAttempt;
uint64_t blockTime;
uint32_t count;
};
using IpConnectMap = std::map<Connection::Address, ConnectBlock>;
class Ban
{
public:
bool acceptConnection(const Connection::Address& clientIP);
private:
IpConnectMap ipConnectMap;
std::recursive_mutex lock;
};
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);
};
#endif // FS_BAN_H