diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2015-09-09 19:00:56 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2015-09-09 19:02:23 +0200 |
| commit | 8a6d4b06f2291c363f3dea17837ed20893852453 (patch) | |
| tree | c091375499e35eaa1810586454e0834c06e6c9b2 /src/ClientInfo.hpp | |
| parent | f554a27046f203e56a07baaf214d90834942e3f5 (diff) | |
| download | manager-8a6d4b06f2291c363f3dea17837ed20893852453.tar.gz manager-8a6d4b06f2291c363f3dea17837ed20893852453.zip | |
Cleanup repo with some directories
Diffstat (limited to 'src/ClientInfo.hpp')
| -rw-r--r-- | src/ClientInfo.hpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/ClientInfo.hpp b/src/ClientInfo.hpp new file mode 100644 index 0000000..8099b59 --- /dev/null +++ b/src/ClientInfo.hpp @@ -0,0 +1,112 @@ +#pragma once + +#include <QDateTime> +#include <QString> + +enum ClientInterface { + Auto = 0, + Clonk = 1, + IRC = 1 << 1, + Management = 1 << 2 +}; + + +class ManagementConnection { +public: + ManagementConnection() {} + ManagementConnection(QTcpSocket* socket, const QString& name = "") : socket(socket), name(name) {} + + QTcpSocket* socket = 0; + QString name = ""; +}; + +class ClientInfo +{ + +public: + ClientInterface interface = Clonk; + QString nick = ""; + + int CUID = 0; + QString pcName = ""; + bool activated = false; + + QList<QDateTime> antiFloodList; + + QString target = ""; + ManagementConnection management; + + + static inline ClientInfo ircClient(QString nick, QString target = "") + { + ClientInfo ret; + ret.interface = IRC; + ret.nick = nick; + if(target.isEmpty()) + { + target = nick; + } + ret.target = target; + return ret; + } + + static inline ClientInfo clonkClient(QString nick, QString pcName, int CUID, bool activated = false) + { + ClientInfo ret; + ret.interface = Clonk; + ret.nick = nick; + ret.pcName = pcName; + ret.CUID = CUID; + ret.activated = activated; + return ret; + } + + static inline ClientInfo managementClient(ManagementConnection conn) + { + ClientInfo ret; + ret.interface = Management; + ret.management = conn; + ret.nick = conn.name; + return ret; + } + + static inline ClientInfo autoClient() + { + ClientInfo ret; + ret.interface = Auto; + return ret; + } + + inline bool operator==(const ClientInfo& other) const + { + return other.interface == interface && other.nick == nick && (interface == Clonk ? other.pcName == pcName && other.CUID == CUID : true); + } + + inline bool operator!=(const ClientInfo& other) const + { + 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; + } +}; |
