From 6dc0eddef4e743352c36ea8d90f684f8fd424559 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Fri, 12 Jun 2015 01:56:58 +0200 Subject: Added basic antiflood. Release round admin when he is leaving, but he can regain it in a specified time. --- ClientInfo.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'ClientInfo.hpp') diff --git a/ClientInfo.hpp b/ClientInfo.hpp index e2c7864..8099b59 100644 --- a/ClientInfo.hpp +++ b/ClientInfo.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include enum ClientInterface { @@ -30,6 +31,8 @@ public: QString pcName = ""; bool activated = false; + QList antiFloodList; + QString target = ""; ManagementConnection management; @@ -52,7 +55,7 @@ public: ClientInfo ret; ret.interface = Clonk; ret.nick = nick; - ret.nick = pcName; + ret.pcName = pcName; ret.CUID = CUID; ret.activated = activated; return ret; @@ -84,8 +87,26 @@ public: return !operator==(other); } + inline bool operator<(const ClientInfo& other) const + { + return toString() < other.toString(); + } + inline QString toString() const { return interface == Auto ? "~auto~" : interface == Management ? management.name + " {CLI}" : (!nick.isEmpty() ? nick + (interface == Clonk ? " (" + pcName + ")" : " [IRC]") : ""); } + + inline bool floodCheck(int maxCount, int floodTimeSecs, QDateTime newDateTime = QDateTime::currentDateTime()) + { + foreach(const QDateTime& dateTime, antiFloodList) + { + if(dateTime.secsTo(newDateTime) > floodTimeSecs) + { + antiFloodList.removeAll(dateTime); + } + } + antiFloodList.push_back(newDateTime); + return antiFloodList.size() > maxCount; + } }; -- cgit v1.2.3-54-g00ecf