summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-01 22:37:27 -0400
committerAdam <Adam@anope.org>2011-08-01 22:37:27 -0400
commitf7adc0b35b50f06706872a161f1c7476e6e6981e (patch)
tree91fbe281f2772136a327fd4fc4c64740d1ab65ab /include
parent710c02f3bd3581b7c5b3d48e7604756975219fc8 (diff)
Rewrote the access systems and added a flags access system
Diffstat (limited to 'include')
-rw-r--r--include/access.h91
-rw-r--r--include/extern.h10
-rw-r--r--include/modules.h20
-rw-r--r--include/regchannel.h69
-rw-r--r--include/services.h82
5 files changed, 120 insertions, 152 deletions
diff --git a/include/access.h b/include/access.h
new file mode 100644
index 000000000..69f8f4bc7
--- /dev/null
+++ b/include/access.h
@@ -0,0 +1,91 @@
+#ifndef ACCESS_H
+#define ACCESS_H
+
+enum ChannelAccess
+{
+ CA_ACCESS_LIST,
+ CA_NOKICK,
+ CA_FANTASIA,
+ CA_GREET,
+ CA_AUTOVOICE,
+ CA_VOICEME,
+ CA_VOICE,
+ CA_INFO,
+ CA_SAY,
+ CA_AUTOHALFOP,
+ CA_HALFOPME,
+ CA_HALFOP,
+ CA_KICK,
+ CA_SIGNKICK,
+ CA_BAN,
+ CA_TOPIC,
+ CA_MODE,
+ CA_GETKEY,
+ CA_INVITE,
+ CA_UNBAN,
+ CA_AUTOOP,
+ CA_OPDEOPME,
+ CA_OPDEOP,
+ CA_AUTOPROTECT,
+ CA_AKICK,
+ CA_BADWORDS,
+ CA_ASSIGN,
+ CA_MEMO,
+ CA_ACCESS_CHANGE,
+ CA_PROTECTME,
+ CA_PROTECT,
+ CA_SET,
+ CA_AUTOOWNER,
+ CA_OWNERME,
+ CA_OWNER,
+ CA_FOUNDER,
+ CA_SIZE
+};
+
+class ChanAccess;
+
+class AccessProvider : public Service
+{
+ public:
+ AccessProvider(Module *o, const Anope::string &n);
+ virtual ~AccessProvider();
+ virtual ChanAccess *Create() = 0;
+};
+
+class CoreExport ChanAccess
+{
+ public:
+ AccessProvider *provider;
+ ChannelInfo *ci;
+ Anope::string mask;
+ Anope::string creator;
+ time_t last_seen;
+ time_t created;
+
+ ChanAccess(AccessProvider *p);
+ virtual ~ChanAccess();
+ virtual bool Matches(User *u, NickCore *nc) = 0;
+ virtual bool HasPriv(ChannelAccess priv) = 0;
+ virtual Anope::string Serialize() = 0;
+ virtual void Unserialize(const Anope::string &data) = 0;
+
+ bool operator>(ChanAccess &other);
+ bool operator<(ChanAccess &other);
+ bool operator>=(ChanAccess &other);
+ bool operator<=(ChanAccess &other);
+};
+
+class AccessGroup : public std::vector<ChanAccess *>
+{
+ public:
+ AccessGroup();
+ bool HasPriv(ChannelAccess priv) const;
+ ChanAccess *Highest() const;
+ bool operator>(const AccessGroup &other) const;
+ bool operator<(const AccessGroup &other) const;
+ bool operator>=(const AccessGroup &other) const;
+ bool operator<=(const AccessGroup &other) const;
+};
+
+#endif
+
diff --git a/include/extern.h b/include/extern.h
index 18df923a8..0b90c6e14 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -42,8 +42,6 @@ E Channel *findchan(const Anope::string &chan);
E User *nc_on_chan(Channel *c, const NickCore *nc);
-E Anope::string get_xop_level(int level);
-
E void do_cmode(const Anope::string &source, const Anope::string &channel, const Anope::string &modes, const Anope::string &ts);
E void do_join(const Anope::string &source, const Anope::string &channels, const Anope::string &ts);
E void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason);
@@ -53,21 +51,13 @@ E void chan_set_correct_modes(User *user, Channel *c, int give_modes);
/**** chanserv.c ****/
-E LevelInfo levelinfo[];
-
-
-E void reset_levels(ChannelInfo *ci);
-
E void check_modes(Channel *c);
E ChannelInfo *cs_findchan(const Anope::string &chan);
-E int check_access(User *user, ChannelInfo *ci, int what);
E bool IsFounder(User *user, ChannelInfo *ci);
E void update_cs_lastseen(User *user, ChannelInfo *ci);
E int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret);
-E int levelinfo_maxwidth;
-
/**** config.c ****/
E ConfigurationFile services_conf;
diff --git a/include/modules.h b/include/modules.h
index 28627f506..baf437ff8 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -646,13 +646,6 @@ class CoreExport Module : public Extensible
*/
virtual void OnAccessDel(ChannelInfo *ci, User *u, ChanAccess *access) { }
- /** Called when access is changed
- * @param ci The channel
- * @param u The user who changed the access
- * @param u access The access changed
- */
- virtual void OnAccessChange(ChannelInfo *ci, User *u, ChanAccess *access) { }
-
/** Called when access is added
* @param ci The channel
* @param u The user who added the access
@@ -1029,7 +1022,7 @@ enum Implementation
I_OnNickUpdate,
/* ChanServ */
- I_OnChanForbidden, I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd, I_OnAccessChange,
+ I_OnChanForbidden, I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd,
I_OnAccessDel, I_OnAccessClear, I_OnLevelChange, I_OnChanRegistered, I_OnChanUnsuspend, I_OnDelChan, I_OnChannelCreate,
I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick,
I_OnChanInfo, I_OnFindChan,
@@ -1241,17 +1234,6 @@ class CallBack : public Timer
}
};
-class CoreExport Service : public Base
-{
- public:
- Module *owner;
- Anope::string name;
-
- Service(Module *o, const Anope::string &n);
-
- virtual ~Service();
-};
-
template<typename T>
class service_reference : public dynamic_reference<T>
{
diff --git a/include/regchannel.h b/include/regchannel.h
index 9c3d1c9b9..0a4a7827a 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -44,8 +44,6 @@ enum ChannelInfoFlag
CI_SIGNKICK,
/* Sign kicks if level is < than the one defined by the SIGNKIGK level */
CI_SIGNKICK_LEVEL,
- /* Uses XOP */
- CI_XOP,
/* Channel is suspended */
CI_SUSPENDED,
/* Channel still exists when emptied, this can be caused by setting a perm
@@ -61,20 +59,7 @@ enum ChannelInfoFlag
const Anope::string ChannelInfoFlagStrings[] = {
"BEGIN", "KEEPTOPIC", "SECUREOPS", "PRIVATE", "TOPICLOCK", "RESTRICTED",
"PEACE", "SECURE", "NO_EXPIRE", "MEMO_HARDMAX", "OPNOTICE", "SECUREFOUNDER",
- "SIGNKICK", "SIGNKICK_LEVEL", "XOP", "SUSPENDED", "PERSIST", ""
-};
-
-class CoreExport ChanAccess
-{
- Anope::string mask; /* Mask of the access entry */
- public:
- int16 level;
- NickCore *nc; /* NC of the entry, if the entry is a valid nickcore */
- time_t last_seen;
- Anope::string creator;
-
- ChanAccess(const Anope::string &umask);
- const Anope::string &GetMask();
+ "SIGNKICK", "SIGNKICK_LEVEL", "SUSPENDED", "PERSIST", ""
};
/** Flags for auto kick
@@ -117,9 +102,9 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
{
private:
typedef std::multimap<ChannelModeName, ModeLock> ModeList;
- private:
+
NickCore *founder; /* Channel founder */
- std::vector<ChanAccess *> access; /* List of authorized users */
+ std::vector<ChanAccess *> access; /* List of authorized users */
std::vector<AutoKick *> akick; /* List of users to kickban */
std::vector<BadWord *> badwords; /* List of badwords */
ModeList mode_locks;
@@ -151,17 +136,16 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
time_t last_topic_time; /* Time */
int16 bantype;
- int16 *levels; /* Access levels for commands */
+ int16 levels[CA_SIZE];
MemoInfo memos;
Channel *c; /* Pointer to channel record (if channel is currently in use) */
/* For BotServ */
-
BotInfo *bi; /* Bot used on this channel */
Flags<BotServFlag> botflags;
- int16 *ttb; /* Times to ban for each kicker */
+ int16 ttb[TTB_SIZE]; /* Times to ban for each kicker */
int16 capsmin, capspercent; /* For CAPS kicker */
int16 floodlines, floodsecs; /* For FLOOD kicker */
@@ -183,16 +167,9 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
BotInfo *WhoSends();
/** Add an entry to the channel access list
- *
- * @param mask The mask of the access entry
- * @param level The channel access level the user has on the channel
- * @param creator The user who added the access
- * @param last_seen When the user was last seen within the channel
- * @return The new access class
- *
- * Creates a new access list entry and inserts it into the access list.
+ * @param access The entry
*/
- ChanAccess *AddAccess(const Anope::string &mask, int16 level, const Anope::string &creator, int32 last_seen = 0);
+ void AddAccess(ChanAccess *access);
/** Get an entry from the channel access list by index
*
@@ -203,36 +180,16 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
*/
ChanAccess *GetAccess(unsigned index);
- /** Get an entry from the channel access list by User
+ /** Check if a user has a privilege on a channel
*
* @param u The User to find within the access list vector
- * @param level Optional channel access level to compare the access entries to
- * @return A ChanAccess struct corresponding to the User, or NULL if not found
- *
- * Retrieves an entry from the access list that matches the given User, optionally also matching a certain level.
+ * @param priv The privilege to check for.
+ * @return true if the user has the privilege
*/
- ChanAccess *GetAccess(User *u, int16 level = 0);
+ bool HasPriv(User *u, ChannelAccess priv);
- /** Get an entry from the channel access list by NickCore
- *
- * @param u The NickCore to find within the access list vector
- * @param level Optional channel access level to compare the access entries to
- * @return A ChanAccess struct corresponding to the NickCore, or NULL if not found
- *
- * Retrieves an entry from the access list that matches the given NickCore, optionally also matching a certain level.
- */
- ChanAccess *GetAccess(NickCore *nc, int16 level = 0);
-
- /** Get an entry from the channel access list by mask
- *
- * @param u The mask to find within the access list vector
- * @param level Optional channel access level to compare the access entries to
- * @param wildcard True to match using wildcards
- * @return A ChanAccess struct corresponding to the mask, or NULL if not found
- *
- * Retrieves an entry from the access list that matches the given mask, optionally also matching a certain level.
- */
- ChanAccess *GetAccess(const Anope::string &mask, int16 level = 0, bool wildcard = true);
+ AccessGroup AccessFor(User *u);
+ AccessGroup AccessFor(NickCore *nc);
/** Get the size of the accss vector for this channel
* @return The access vector size
diff --git a/include/services.h b/include/services.h
index 556e1d715..0eeafc0e9 100644
--- a/include/services.h
+++ b/include/services.h
@@ -345,6 +345,20 @@ template<typename T, size_t Size = 32> class Flags
}
};
+class Module;
+
+class CoreExport Service : public Base
+{
+ public:
+ Module *owner;
+ Anope::string name;
+
+ Service(Module *o, const Anope::string &n);
+
+ virtual ~Service();
+};
+
+
#include "sockets.h"
#include "socketengine.h"
#include "extensible.h"
@@ -562,28 +576,6 @@ class CoreExport HostInfo
const time_t GetTime() const;
};
-enum AccessLevel
-{
- /* Note that these two levels also serve as exclusive boundaries for valid
- * access levels. ACCESS_FOUNDER may be assumed to be strictly greater
- * than any valid access level, and ACCESS_INVALID may be assumed to be
- * strictly less than any valid access level. Also read below.
- */
- ACCESS_FOUNDER = 10001, /* Numeric level indicating founder access */
- ACCESS_INVALID = -10000, /* Used in levels[] for disabled settings */
- /* There is one exception to the above access levels: SuperAdmins will have
- * access level 10001. This level is never stored, however; it is only used
- * in comparison and to let SuperAdmins win from founders where needed
- */
- ACCESS_SUPERADMIN = 10002,
- /* Levels for xOP */
- ACCESS_VOP = 3,
- ACCESS_HOP = 4,
- ACCESS_AOP = 5,
- ACCESS_SOP = 10,
- ACCESS_QOP = 10000
-};
-
/** Flags for badwords
*/
enum BadWordType
@@ -605,51 +597,6 @@ struct BadWord
BadWordType type;
};
-/* Indices for cmd_access[]: */
-enum ChannelAccess
-{
- CA_INVITE,
- CA_AKICK,
- CA_SET, /* but not FOUNDER or PASSWORD */
- CA_UNBAN,
- CA_AUTOOP,
- CA_AUTOVOICE,
- CA_OPDEOP, /* ChanServ commands OP and DEOP */
- CA_ACCESS_LIST,
- CA_NOJOIN, /* Maximum */
- CA_ACCESS_CHANGE,
- CA_MEMO,
- CA_ASSIGN, /* BotServ ASSIGN command */
- CA_BADWORDS, /* BotServ BADWORDS command */
- CA_NOKICK, /* Not kicked by the bot */
- CA_FANTASIA,
- CA_SAY,
- CA_GREET,
- CA_VOICEME,
- CA_VOICE,
- CA_GETKEY,
- CA_AUTOHALFOP,
- CA_AUTOPROTECT,
- CA_OPDEOPME,
- CA_HALFOPME,
- CA_HALFOP,
- CA_PROTECTME,
- CA_PROTECT,
- CA_KICKME,
- CA_KICK,
- CA_SIGNKICK,
- CA_BANME,
- CA_BAN,
- CA_TOPIC,
- CA_MODE,
- CA_INFO,
- CA_AUTOOWNER,
- CA_OWNER,
- CA_OWNERME,
- CA_FOUNDER,
- CA_SIZE
-};
-
/* BotServ SET flags */
enum BotServFlag
{
@@ -716,6 +663,7 @@ enum
TTB_SIZE
};
+#include "access.h"
#include "regchannel.h"
/*************************************************************************/