summaryrefslogtreecommitdiff
path: root/include/modules/os_session.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-05 03:30:08 -0400
committerAdam <Adam@anope.org>2013-05-05 03:30:08 -0400
commit57c2b65f08c9c0658003a74a32c6506829e12b0b (patch)
tree49883b790ed9f7cd395e0c6f2f62cc946d743635 /include/modules/os_session.h
parenta118946e657b8a137502ff60c1f21c608cb44495 (diff)
Move module header files to include/modules to fix naming conflicts with system headers
Diffstat (limited to 'include/modules/os_session.h')
-rw-r--r--include/modules/os_session.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/include/modules/os_session.h b/include/modules/os_session.h
new file mode 100644
index 000000000..f3077d0ac
--- /dev/null
+++ b/include/modules/os_session.h
@@ -0,0 +1,85 @@
+#ifndef OS_SESSION_H
+#define OS_SESSION_H
+
+struct Session
+{
+ cidr addr; /* A cidr (sockaddrs + len) representing this session */
+ unsigned count; /* Number of clients with this host */
+ unsigned hits; /* Number of subsequent kills for a host */
+
+ Session(const Anope::string &ip, int len) : addr(ip, len), count(1), hits(0) { }
+};
+
+struct Exception : Serializable
+{
+ Anope::string mask; /* Hosts to which this exception applies */
+ unsigned limit; /* Session limit for exception */
+ Anope::string who; /* Nick of person who added the exception */
+ Anope::string reason; /* Reason for exception's addition */
+ time_t time; /* When this exception was added */
+ time_t expires; /* Time when it expires. 0 == no expiry */
+
+ Exception() : Serializable("Exception") { }
+ void Serialize(Serialize::Data &data) const anope_override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &data);
+};
+
+class SessionService : public Service
+{
+ public:
+ typedef std::tr1::unordered_map<cidr, Session *, cidr::hash> SessionMap;
+ typedef std::vector<Exception *> ExceptionVector;
+
+ SessionService(Module *m) : Service(m, "SessionService", "session") { }
+
+ virtual void AddException(Exception *e) = 0;
+
+ virtual void DelException(Exception *e) = 0;
+
+ virtual Exception *FindException(User *u) = 0;
+
+ virtual Exception *FindException(const Anope::string &host) = 0;
+
+ virtual ExceptionVector &GetExceptions() = 0;
+
+ virtual Session *FindSession(const Anope::string &ip) = 0;
+
+ virtual SessionMap &GetSessions() = 0;
+};
+
+static ServiceReference<SessionService> session_service("SessionService", "session");
+
+void Exception::Serialize(Serialize::Data &data) const
+{
+ data["mask"] << this->mask;
+ data["limit"] << this->limit;
+ data["who"] << this->who;
+ data["reason"] << this->reason;
+ data["time"] << this->time;
+ data["expires"] << this->expires;
+}
+
+Serializable* Exception::Unserialize(Serializable *obj, Serialize::Data &data)
+{
+ if (!session_service)
+ return NULL;
+
+ Exception *ex;
+ if (obj)
+ ex = anope_dynamic_static_cast<Exception *>(obj);
+ else
+ ex = new Exception;
+ data["mask"] >> ex->mask;
+ data["limit"] >> ex->limit;
+ data["who"] >> ex->who;
+ data["reason"] >> ex->reason;
+ data["time"] >> ex->time;
+ data["expires"] >> ex->expires;
+
+ if (!obj)
+ session_service->AddException(ex);
+ return ex;
+}
+
+#endif
+