IP address bans are now time limited and will be removed automatically (minimum duration: 1 hour).

This commit is contained in:
lotodore
2009-06-18 21:32:01 +00:00
parent 9ed8368700
commit 993c2529c3
4 changed files with 52 additions and 14 deletions
+18 -4
View File
@@ -23,17 +23,19 @@
#include <boost/regex.hpp>
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <map>
#include <string>
class ServerBanManager
class ServerBanManager : public boost::enable_shared_from_this<ServerBanManager>
{
public:
ServerBanManager();
ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService);
virtual ~ServerBanManager();
void BanPlayerRegex(const std::string &playerRegex);
void BanIPAddress(const std::string &ipAddress);
void BanIPAddress(const std::string &ipAddress, unsigned durationHours);
bool UnBan(unsigned banId);
void GetBanList(std::list<std::string> &list) const;
void ClearBanList();
@@ -42,8 +44,20 @@ public:
bool IsIPAddressBanned(const std::string &ipAddress) const;
protected:
struct TimedIPAddress
{
TimedIPAddress(const std::string &i, boost::asio::io_service &s)
: ipAddress(i), timer(s) {}
std::string ipAddress;
boost::asio::deadline_timer timer;
};
void TimerRemoveIPBan(const boost::system::error_code &ec, unsigned timerId, boost::shared_ptr<TimedIPAddress> item);
boost::shared_ptr<boost::asio::io_service> m_ioService;
typedef std::map<unsigned, boost::regex> RegexMap;
typedef std::map<unsigned, std::string> IPAddressMap;
typedef std::map<unsigned, boost::shared_ptr<TimedIPAddress> > IPAddressMap;
unsigned GetNextBanId();