ban.h

main 59 lines · 1.7 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1/**
2 * The Forgotten Server - a free and open-source MMORPG server emulator
3 * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifndef FS_BAN_H_CADB975222D745F0BDA12D982F1006E3
21#define FS_BAN_H_CADB975222D745F0BDA12D982F1006E3
22
23struct BanInfo {
24 std::string bannedBy;
25 std::string reason;
26 time_t expiresAt;
27};
28
29struct ConnectBlock {
30 constexpr ConnectBlock(uint64_t lastAttempt, uint64_t blockTime, uint32_t count) :
31 lastAttempt(lastAttempt), blockTime(blockTime), count(count) {}
32
33 uint64_t lastAttempt;
34 uint64_t blockTime;
35 uint32_t count;
36};
37
38using IpConnectMap = std::map<uint32_t, ConnectBlock>;
39
40class Ban
41{
42 public:
43 bool acceptConnection(uint32_t clientIP);
44
45 private:
46 IpConnectMap ipConnectMap;
47 std::recursive_mutex lock;
48};
49
50class IOBan
51{
52 public:
53 static bool isAccountBanned(uint32_t accountId, BanInfo& banInfo);
54 static bool isIpBanned(uint32_t clientIP, BanInfo& banInfo);
55 static bool isPlayerNamelocked(uint32_t playerId);
56};
57
58#endif
59
Top