summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-28 15:46:15 -0400
committerAdam <Adam@anope.org>2011-09-10 02:05:00 -0400
commit700a585b1bb38a9dc0ac3e749083250d405488f8 (patch)
tree8af306bd60778815fe5a137590d3b888213ad231 /include
parent62752db4c49a8679b51d5996003fd3a23c2a3f2d (diff)
Allow modules to add their own channel levels
Diffstat (limited to 'include')
-rw-r--r--include/access.h59
-rw-r--r--include/anope.h22
-rw-r--r--include/extern.h2
-rw-r--r--include/modules.h8
-rw-r--r--include/regchannel.h24
-rw-r--r--include/services.h2
6 files changed, 70 insertions, 47 deletions
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<Privilege> 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<Privilege> &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<ChanAccess *>
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
@@ -259,6 +259,28 @@ namespace Anope
}
/**
+ * 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.
*/
inline string substr(size_type pos = 0, size_type n = npos) const { return string(this->_string.substr(pos, n)); }
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<Anope::string> &);
/**** 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<ChannelInfoFlag,
std::vector<ChanAccess *> access; /* List of authorized users */
std::vector<AutoKick *> akick; /* List of users to kickban */
std::vector<BadWord *> badwords; /* List of badwords */
+ std::map<Anope::string, int16> levels;
public:
typedef std::multimap<ChannelModeName, ModeLock> ModeList;
@@ -134,7 +135,6 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
time_t last_topic_time; /* Time */
int16 bantype;
- int16 levels[CA_SIZE];
MemoInfo memos;
@@ -345,6 +345,28 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* and after uplink sync
*/
void RestoreTopic();
+
+ /** Get the level for a privilege
+ * @param priv The privilege name
+ * @return the level
+ * @throws CoreException if priv is not a valid privilege
+ */
+ int16 GetLevel(const Anope::string &priv);
+
+ /** Set the level for a privilege
+ * @param priv The privilege priv
+ * @param level The new level
+ */
+ void SetLevel(const Anope::string &priv, int16 level);
+
+ /** Remove a privilege from the channel
+ * @param priv The privilege
+ */
+ void RemoveLevel(const Anope::string &priv);
+
+ /** Clear all privileges from the channel
+ */
+ void ClearLevels();
};
/** A timer used to keep the BotServ bot/ChanServ in the channel
diff --git a/include/services.h b/include/services.h
index d6db4e9ed..3a7ff65c2 100644
--- a/include/services.h
+++ b/include/services.h
@@ -98,6 +98,8 @@ extern int strncasecmp(const char *, const char *, size_t);
#undef toupper
#define tolower tolower_
#define toupper toupper_
+extern int toupper(char);
+extern int tolower(char);
/** This definition is used as shorthand for the various classes
* and functions needed to make a module loadable by the OS.