From 700a585b1bb38a9dc0ac3e749083250d405488f8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 28 Aug 2011 15:46:15 -0400 Subject: Allow modules to add their own channel levels --- include/access.h | 59 +++++++++++++++++----------------------------------- include/anope.h | 22 ++++++++++++++++++++ include/extern.h | 2 -- include/modules.h | 8 +++---- include/regchannel.h | 24 ++++++++++++++++++++- include/services.h | 2 ++ 6 files changed, 70 insertions(+), 47 deletions(-) (limited to 'include') diff --git a/include/access.h b/include/access.h index 0c730c9ff..6557d40c6 100644 --- a/include/access.h +++ b/include/access.h @@ -1,45 +1,24 @@ #ifndef ACCESS_H #define ACCESS_H -enum ChannelAccess +struct Privilege { - 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 + Anope::string name; + Anope::string desc; + + Privilege(const Anope::string &n, const Anope::string &d); + bool operator==(const Privilege &other); +}; + +class PrivilegeManager +{ + static std::vector privs; + public: + static void AddPrivilege(Privilege p, int pos = -1, int def = 0); + static void RemovePrivilege(Privilege &p); + static Privilege *FindPrivilege(const Anope::string &name); + static void Init(); + static std::vector &GetPrivileges(); }; class ChanAccess; @@ -65,7 +44,7 @@ class CoreExport ChanAccess ChanAccess(AccessProvider *p); virtual ~ChanAccess(); virtual bool Matches(User *u, NickCore *nc) = 0; - virtual bool HasPriv(ChannelAccess priv) = 0; + virtual bool HasPriv(const Anope::string &name) = 0; virtual Anope::string Serialize() = 0; virtual void Unserialize(const Anope::string &data) = 0; @@ -82,7 +61,7 @@ class CoreExport AccessGroup : public std::vector NickCore *nc; bool SuperAdmin, Founder; AccessGroup(); - bool HasPriv(ChannelAccess priv) const; + bool HasPriv(const Anope::string &priv) const; ChanAccess *Highest() const; bool operator>(const AccessGroup &other) const; bool operator<(const AccessGroup &other) const; diff --git a/include/anope.h b/include/anope.h index 5eeee0a04..3eec3d4e4 100644 --- a/include/anope.h +++ b/include/anope.h @@ -258,6 +258,28 @@ namespace Anope return new_string; } + /** + * Get the string in lowercase. + */ + inline string lower() + { + Anope::string new_string = *this; + for (size_type i = 0; i < new_string.length(); ++i) + new_string[i] = tolower(new_string[i]); + return new_string; + } + + /** + * Get the string in uppercase. + */ + inline string upper() + { + Anope::string new_string = *this; + for (size_type i = 0; i < new_string.length(); ++i) + new_string[i] = toupper(new_string[i]); + return new_string; + } + /** * Get a substring of the string. */ diff --git a/include/extern.h b/include/extern.h index b62997aad..4b15d81ac 100644 --- a/include/extern.h +++ b/include/extern.h @@ -152,8 +152,6 @@ E bool OnError(const Anope::string &, const std::vector &); /**** misc.c ****/ E bool IsFile(const Anope::string &filename); -E int toupper(char); -E int tolower(char); E time_t dotime(const Anope::string &s); E Anope::string duration(const time_t &seconds, NickCore *nc = NULL); diff --git a/include/modules.h b/include/modules.h index a34b7f64d..f76a1f58a 100644 --- a/include/modules.h +++ b/include/modules.h @@ -662,10 +662,10 @@ class CoreExport Module : public Extensible /** Called when a level for a channel is changed * @param u The user changing the level * @param ci The channel the level was changed on - * @param pos The level position, can be -1 for resetting levels + * @param priv The privilege changed * @param what The new level */ - virtual void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what) { } + virtual void OnLevelChange(User *u, ChannelInfo *ci, const Anope::string &priv, int16 what) { } /** Called when a channel is dropped * @param chname The channel name @@ -751,14 +751,14 @@ class CoreExport Module : public Extensible * @param priv The privilege being checked for * @return EVENT_ALLOW for yes, EVENT_STOP to stop all processing */ - virtual EventReturn OnCheckPriv(ChanAccess *access, ChannelAccess priv) { return EVENT_CONTINUE; } + virtual EventReturn OnCheckPriv(ChanAccess *access, const Anope::string &priv) { return EVENT_CONTINUE; } /** Check whether an access group has a privilege * @param group The group * @param priv The privilege * @return MOD_ALLOW to allow, MOD_STOP to stop */ - virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, ChannelAccess priv) { return EVENT_CONTINUE; } + virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) { return EVENT_CONTINUE; } /** Called when a nick is dropped * @param u The user dropping the nick diff --git a/include/regchannel.h b/include/regchannel.h index 71136a73b..1d071fb0f 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -103,6 +103,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags access; /* List of authorized users */ std::vector akick; /* List of users to kickban */ std::vector badwords; /* List of badwords */ + std::map levels; public: typedef std::multimap ModeList; @@ -134,7 +135,6 @@ class CoreExport ChannelInfo : public Extensible, public Flags