Anope IRC Services  Version 2.0
os_session.h
Go to the documentation of this file.
1 #ifndef OS_SESSION_H
2 #define OS_SESSION_H
3 
4 struct Session
5 {
6  cidr addr; /* A cidr (sockaddrs + len) representing this session */
7  unsigned count; /* Number of clients with this host */
8  unsigned hits; /* Number of subsequent kills for a host */
9 
10  Session(const sockaddrs &ip, int len) : addr(ip, len), count(1), hits(0) { }
11 };
12 
14 {
15  Anope::string mask; /* Hosts to which this exception applies */
16  unsigned limit; /* Session limit for exception */
17  Anope::string who; /* Nick of person who added the exception */
18  Anope::string reason; /* Reason for exception's addition */
19  time_t time; /* When this exception was added */
20  time_t expires; /* Time when it expires. 0 == no expiry */
21 
22  Exception() : Serializable("Exception") { }
23  void Serialize(Serialize::Data &data) const anope_override;
25 };
26 
27 class SessionService : public Service
28 {
29  public:
30  typedef TR1NS::unordered_map<cidr, Session *, cidr::hash> SessionMap;
31  typedef std::vector<Exception *> ExceptionVector;
32 
33  SessionService(Module *m) : Service(m, "SessionService", "session") { }
34 
35  virtual Exception *CreateException() = 0;
36 
37  virtual void AddException(Exception *e) = 0;
38 
39  virtual void DelException(Exception *e) = 0;
40 
41  virtual Exception *FindException(User *u) = 0;
42 
43  virtual Exception *FindException(const Anope::string &host) = 0;
44 
45  virtual ExceptionVector &GetExceptions() = 0;
46 
47  virtual Session *FindSession(const Anope::string &ip) = 0;
48 
49  virtual SessionMap &GetSessions() = 0;
50 };
51 
52 static ServiceReference<SessionService> session_service("SessionService", "session");
53 
55 {
56  data["mask"] << this->mask;
57  data["limit"] << this->limit;
58  data["who"] << this->who;
59  data["reason"] << this->reason;
60  data["time"] << this->time;
61  data["expires"] << this->expires;
62 }
63 
65 {
66  if (!session_service)
67  return NULL;
68 
69  Exception *ex;
70  if (obj)
72  else
73  ex = new Exception;
74  data["mask"] >> ex->mask;
75  data["limit"] >> ex->limit;
76  data["who"] >> ex->who;
77  data["reason"] >> ex->reason;
78  data["time"] >> ex->time;
79  data["expires"] >> ex->expires;
80 
81  if (!obj)
82  session_service->AddException(ex);
83  return ex;
84 }
85 
86 #endif
87 
virtual void DelException(Exception *e)=0
unsigned count
Definition: os_session.h:7
time_t time
Definition: os_session.h:19
Session(const sockaddrs &ip, int len)
Definition: os_session.h:10
unsigned limit
Definition: os_session.h:16
virtual Session * FindSession(const Anope::string &ip)=0
virtual ExceptionVector & GetExceptions()=0
Definition: users.h:34
virtual SessionMap & GetSessions()=0
cidr addr
Definition: os_session.h:6
Definition: sockets.h:87
SessionService(Module *m)
Definition: os_session.h:33
virtual void AddException(Exception *e)=0
virtual Exception * CreateException()=0
std::vector< Exception * > ExceptionVector
Definition: os_session.h:31
virtual Exception * FindException(User *u)=0
TR1NS::unordered_map< cidr, Session *, cidr::hash > SessionMap
Definition: os_session.h:30
time_t expires
Definition: os_session.h:20
#define anope_override
Definition: services.h:56
Anope::string who
Definition: os_session.h:17
unsigned hits
Definition: os_session.h:8
T anope_dynamic_static_cast(O ptr)
Definition: anope.h:774
Anope::string mask
Definition: os_session.h:15
static Serializable * Unserialize(Serializable *obj, Serialize::Data &data)
Definition: os_session.h:64
Anope::string reason
Definition: os_session.h:18
void Serialize(Serialize::Data &data) const anope_override
Definition: os_session.h:54
static ServiceReference< SessionService > session_service("SessionService","session")