access.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * (C) 2003-2012 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  *
00011  *
00012  */
00013 
00014 #ifndef ACCESS_H
00015 #define ACCESS_H
00016 
00017 #include "services.h"
00018 #include "anope.h"
00019 #include "serialize.h"
00020 #include "service.h"
00021 
00022 enum
00023 {
00024         ACCESS_INVALID = -10000,
00025         ACCESS_FOUNDER = 10001
00026 };
00027 
00028 struct CoreExport Privilege
00029 {
00030         Anope::string name;
00031         Anope::string desc;
00032         int rank;
00033 
00034         Privilege(const Anope::string &n, const Anope::string &d, int r);
00035         bool operator==(const Privilege &other) const;
00036 };
00037 
00038 class CoreExport PrivilegeManager
00039 {
00040         static std::vector<Privilege> privs;
00041  public:
00042         static void AddPrivilege(Privilege p);
00043         static void RemovePrivilege(Privilege &p);
00044         static Privilege *FindPrivilege(const Anope::string &name);
00045         static std::vector<Privilege> &GetPrivileges();
00046         static void ClearPrivileges();
00047 };
00048 
00049 
00050 class CoreExport AccessProvider : public Service
00051 {
00052  public:
00053         AccessProvider(Module *o, const Anope::string &n);
00054         virtual ~AccessProvider();
00055         virtual ChanAccess *Create() = 0;
00056 };
00057 
00058 class CoreExport ChanAccess : public Serializable
00059 {
00060  public:
00061         AccessProvider *provider;
00062         serialize_obj<ChannelInfo> ci;
00063         Anope::string mask;
00064         Anope::string creator;
00065         time_t last_seen;
00066         time_t created;
00067 
00068         ChanAccess(AccessProvider *p);
00069         virtual ~ChanAccess();
00070 
00071         const Anope::string serialize_name() const anope_override;
00072         Serialize::Data serialize() const anope_override;
00073         static Serializable* unserialize(Serializable *obj, Serialize::Data &);
00074 
00075         virtual bool Matches(const User *u, const NickCore *nc) const;
00076         virtual bool HasPriv(const Anope::string &name) const = 0;
00077         virtual Anope::string Serialize() const = 0;
00078         virtual void Unserialize(const Anope::string &data) = 0;
00079 
00080         bool operator>(const ChanAccess &other) const;
00081         bool operator<(const ChanAccess &other) const;
00082         bool operator>=(const ChanAccess &other) const;
00083         bool operator<=(const ChanAccess &other) const;
00084 };
00085 
00086 class CoreExport AccessGroup : public std::vector<ChanAccess *>
00087 {
00088  public:
00089         const ChannelInfo *ci;
00090         const NickCore *nc;
00091         bool SuperAdmin, Founder;
00092         AccessGroup();
00093         bool HasPriv(const Anope::string &priv) const;
00094         const ChanAccess *Highest() const;
00095         bool operator>(const AccessGroup &other) const;
00096         bool operator<(const AccessGroup &other) const;
00097         bool operator>=(const AccessGroup &other) const;
00098         bool operator<=(const AccessGroup &other) const;
00099 };
00100 
00101 #endif
00102