1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(__INCLUDE_ServerBannedh_INCLUDE__)
22 #define __INCLUDE_ServerBannedh_INCLUDE__
23 
24 #include <set>
25 #include <map>
26 #include <list>
27 #include <lang/LangString.h>
28 #include <time.h>
29 
30 class ServerBanned
31 {
32 public:
33 	ServerBanned();
34 	virtual ~ServerBanned();
35 
36 	enum BannedType
37 	{
38 		NotBanned,
39 		Banned,
40 		Muted,
41 		Flagged
42 	};
43 	struct BannedEntry
44 	{
45 		time_t bantime;
46 		LangString name;
47 		std::string uniqueid;
48 		std::string SUI;
49 		std::string adminname;
50 		std::string reason;
51 		BannedType type;
52 	};
53 	struct BannedRange
54 	{
55 		unsigned int mask;
56 		std::map<unsigned int, BannedEntry> ips;
57 	};
58 
59 	std::list<BannedRange> &getBannedIps();
60 	BannedType getBanned(const char *unqiueid, const char *SUI);
61 	BannedType getBanned(unsigned int ip);
62 	void addBanned(unsigned int ip,
63 		const LangString &name,
64 		const char *uniqueId,
65 		const char *SUI,
66 		BannedType type,
67 		const char *adminname,
68 		const char *reason);
69 	bool save();
70 	bool load(bool force = false);
71 
72 	static const char *getBannedTypeStr(BannedType type);
73 
74 protected:
75 	std::list<BannedRange> bannedIps_;
76 	std::map<std::string, BannedEntry> bannedIds_;
77 	std::map<std::string, BannedEntry> bannedSUIs_;
78 	time_t lastReadTime_;
79 
80 	void addBannedEntry(unsigned int ip, unsigned int mask,
81 		const LangString &name, const char *unqiueId, const char *SUid, unsigned int bantime,
82 		BannedType type, const char *adminname, const char *reason);
83 
84 };
85 
86 #endif // __INCLUDE_ServerBannedh_INCLUDE__
87 
88