summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-12-13 19:32:19 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2009-12-13 19:32:19 +0000
commita7ac6a0ac712892652da6dd8696b94d4c6d3ea84 (patch)
tree9bbcf49157cfda0577c34515cb44d4462818c1da /include
parent3a956c51be22f1b6f3b6808c9f56fb6b26c7dd1a (diff)
Added in a modestacker and rewrote almost all of the remaining old mode code
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2696 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'include')
-rw-r--r--include/extern.h8
-rw-r--r--include/modes.h508
-rw-r--r--include/services.h442
-rw-r--r--include/users.h72
4 files changed, 624 insertions, 406 deletions
diff --git a/include/extern.h b/include/extern.h
index c02ef22e2..7cc3f3050 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -39,7 +39,6 @@ E void kill_user(const char *source, const char *user, const char *reason);
E void bad_password(User * u);
E void sqline(char *mask, char *reason);
E void common_unban(ChannelInfo * ci, char *nick);
-E void common_svsmode(User * u, const char *modes, const char *arg);
/**** botserv.c ****/
@@ -79,14 +78,14 @@ E Channel *findchan(const char *chan);
E Channel *firstchan();
E Channel *nextchan();
+E void ChanSetInternalModes(Channel *c, int ac, const char **av);
+
E void chan_deluser(User * user, Channel * c);
E int is_on_chan(Channel * c, User * u);
E User *nc_on_chan(Channel * c, NickCore * nc);
E char *chan_get_modes(Channel * chan, int complete, int plus);
-E void chan_set_modes(const char *source, Channel * chan, int ac,
- const char **av, int check);
E int chan_get_user_status(Channel * chan, User * user);
E int chan_has_user_status(Channel * chan, User * user, int16 status);
@@ -102,7 +101,7 @@ E void do_kick(const char *source, int ac, const char **av);
E void do_part(const char *source, int ac, const char **av);
E void do_sjoin(const char *source, int ac, const char **av);
E void do_topic(const char *source, int ac, const char **av);
-E void do_mass_mode(char *modes);
+E void MassChannelModes(BotInfo *bi, const std::string &modes);
E void chan_set_correct_modes(User * user, Channel * c, int give_modes);
E void restore_unsynced_topics();
@@ -640,6 +639,7 @@ E int is_excepted_mask(ChannelInfo * ci, const char *mask);
E int match_usermask(const char *mask, User * user);
E char *create_mask(User * u);
+E void UserSetInternalModes(User *user, int ac, const char **av);
/******************************************************************************/
diff --git a/include/modes.h b/include/modes.h
new file mode 100644
index 000000000..34e3ce463
--- /dev/null
+++ b/include/modes.h
@@ -0,0 +1,508 @@
+/* Mode support
+ *
+ * Copyright (C) 2008-2009 Adam <Adam@anope.org>
+ * Copyright (C) 2008-2009 Anope Team <team@anope.org>
+ *
+ * Please read COPYING and README for further details.
+ *
+ *
+ * $Id$
+ *
+ */
+
+/** All of the valid user mode names
+ */
+enum UserModeName
+{
+ UMODE_BEGIN,
+
+ UMODE_SERV_ADMIN, UMODE_BOT, UMODE_CO_ADMIN, UMODE_FILTER, UMODE_HIDEOPER, UMODE_NETADMIN,
+ UMODE_REGPRIV, UMODE_PROTECTED, UMODE_NO_CTCP, UMODE_WEBTV, UMODE_WHOIS, UMODE_ADMIN, UMODE_DEAF,
+ UMODE_GLOBOPS, UMODE_HELPOP, UMODE_INVIS, UMODE_OPER, UMODE_PRIV, UMODE_GOD, UMODE_REGISTERED,
+ UMODE_SNOMASK, UMODE_VHOST, UMODE_WALLOPS, UMODE_CLOAK, UMODE_SSL, UMODE_CALLERID, UMODE_COMMONCHANS,
+ UMODE_HIDDEN, UMODE_STRIPCOLOR,
+
+ UMODE_END
+};
+
+/** All of the valid channel mode names
+ */
+enum ChannelModeName
+{
+ CMODE_BEGIN,
+
+ /* Channel modes */
+ CMODE_BLOCKCOLOR, CMODE_FLOOD, CMODE_INVITE, CMODE_KEY, CMODE_LIMIT, CMODE_MODERATED, CMODE_NOEXTERNAL,
+ CMODE_PRIVATE, CMODE_REGISTERED, CMODE_SECRET, CMODE_TOPIC, CMODE_AUDITORIUM, CMODE_SSL, CMODE_ADMINONLY,
+ CMODE_NOCTCP, CMODE_FILTER, CMODE_NOKNOCK, CMODE_REDIRECT, CMODE_REGMODERATED, CMODE_NONICK, CMODE_OPERONLY,
+ CMODE_NOKICK, CMODE_REGISTEREDONLY, CMODE_STRIPCOLOR, CMODE_NONOTICE, CMODE_NOINVITE, CMODE_ALLINVITE,
+ CMODE_BLOCKCAPS, CMODE_PERM, CMODE_NICKFLOOD, CMODE_JOINFLOOD,
+
+ /* b/e/I */
+ CMODE_BAN, CMODE_EXCEPT,
+ CMODE_INVITEOVERRIDE,
+
+ /* v/h/o/a/q */
+ CMODE_VOICE, CMODE_HALFOP, CMODE_OP,
+ CMODE_PROTECT, CMODE_OWNER,
+
+ CMODE_END
+};
+
+/** The different types of modes
+*/
+enum ModeType
+{
+ /* Regular mode */
+ MODE_REGULAR,
+ /* b/e/I */
+ MODE_LIST,
+ /* k/l etc */
+ MODE_PARAM,
+ /* v/h/o/a/q */
+ MODE_STATUS
+};
+
+
+/** This class is a user mode, all user modes use this/inherit from this
+ */
+class UserMode
+{
+ public:
+
+ /* Mode name */
+ UserModeName Name;
+ /* The mode char */
+ char ModeChar;
+ /* Mode type, regular or param */
+ ModeType Type;
+
+ /** Default constructor
+ * @param nName The mode name
+ */
+ UserMode(UserModeName mName);
+
+ /** Default destructor
+ */
+ virtual ~UserMode();
+};
+
+class UserModeParam : public UserMode
+{
+ public:
+ /** Default constructor
+ * @param mName The mode name
+ */
+ UserModeParam(UserModeName mName);
+
+ /** Check if the param is valid
+ * @param value The param
+ * @return true or false
+ */
+ virtual bool IsValid(const char *value) { return true; }
+};
+
+/** This class is a channel mode, all channel modes use this/inherit from this
+ */
+class CoreExport ChannelMode
+{
+ public:
+
+ /* Mode name */
+ ChannelModeName Name;
+ /* Type of mode this is */
+ ModeType Type;
+ /* The mode char */
+ char ModeChar;
+
+ /** Default constructor
+ * @param mName The mode name
+ */
+ ChannelMode(ChannelModeName mName);
+
+ /** Default destructor
+ */
+ virtual ~ChannelMode();
+
+ /** Can a user set this mode, used for mlock
+ * NOTE: User CAN be NULL, this is for checking if it can be locked with defcon
+ * @param u The user, or NULL
+ */
+ virtual bool CanSet(User *u) { return true; }
+};
+
+
+/** This is a mode for lists, eg b/e/I. These modes should inherit from this
+ */
+class CoreExport ChannelModeList : public ChannelMode
+{
+ public:
+
+ /** Default constructor
+ * @param mName The mode name
+ */
+ ChannelModeList(ChannelModeName mName);
+
+ /** Default destructor
+ */
+ virtual ~ChannelModeList();
+
+ /** Is the mask valid
+ * @param mask The mask
+ * @return true for yes, false for no
+ */
+ virtual bool IsValid(const char *mask) { return true; }
+
+ /** Add the mask to the channel, this should be overridden
+ * @param chan The channel
+ * @param mask The mask
+ */
+ virtual void AddMask(Channel *chan, const char *mask) { }
+
+ /** Delete the mask from the channel, this should be overridden
+ * @param chan The channel
+ * @param mask The mask
+ */
+ virtual void DelMask(Channel *chan, const char *mask) { }
+
+};
+
+/** This is a mode with a paramater, eg +k/l. These modes should use/inherit from this
+*/
+class CoreExport ChannelModeParam : public ChannelMode
+{
+ public:
+
+ /** Default constructor
+ * @param mName The mode name
+ * @param MinusArg true if this mode sends no arg when unsetting
+ */
+ ChannelModeParam(ChannelModeName mName, bool MinusArg = false);
+
+ /** Default destructor
+ */
+ virtual ~ChannelModeParam();
+
+ /* Should we send an arg when unsetting this mode? */
+ bool MinusNoArg;
+
+ /** Is the param valid
+ * @param value The param
+ * @return true for yes, false for no
+ */
+ virtual bool IsValid(const char *value) { return true; }
+};
+
+/** This is a mode that is a channel status, eg +v/h/o/a/q.
+*/
+class CoreExport ChannelModeStatus : public ChannelMode
+{
+ public:
+ /** CUS_ values, see below
+ */
+ int16 Status;
+ /* The symbol, eg @ % + */
+ char Symbol;
+
+ /** Default constructor
+ * @param mName The mode name
+ * @param mStatus A CUS_ value
+ * @param mSymbol The symbol for the mode, eg @ % +
+ * @param mProtectBotServ Should botserv clients reset this on themself if it gets unset?
+ */
+ ChannelModeStatus(ChannelModeName mName, int16 mStatus, char mSymbol, bool mProtectBotServ = false);
+
+ /** Default destructor
+ */
+ virtual ~ChannelModeStatus();
+
+ /* Should botserv protect itself with this mode? eg if someone -o's botserv it will +o */
+ bool ProtectBotServ;
+};
+
+/** Channel mode +b
+ */
+class CoreExport ChannelModeBan : public ChannelModeList
+{
+ public:
+ ChannelModeBan() : ChannelModeList(CMODE_BAN) { }
+
+ void AddMask(Channel *chan, const char *mask);
+
+ void DelMask(Channel *chan, const char *mask);
+};
+
+/** Channel mode +e
+ */
+class CoreExport ChannelModeExcept : public ChannelModeList
+{
+ public:
+ ChannelModeExcept() : ChannelModeList(CMODE_EXCEPT) { }
+
+ void AddMask(Channel *chan, const char *mask);
+
+ void DelMask(Channel *chan, const char *mask);
+};
+
+/** Channel mode +I
+ */
+class CoreExport ChannelModeInvite : public ChannelModeList
+{
+ public:
+ ChannelModeInvite() : ChannelModeList(CMODE_INVITEOVERRIDE) { }
+
+ void AddMask(Channel *chan, const char *mask);
+
+ void DelMask(Channel *chan, const char *mask);
+};
+
+
+/** Channel mode +k (key)
+ */
+class CoreExport ChannelModeKey : public ChannelModeParam
+{
+ public:
+ ChannelModeKey() : ChannelModeParam(CMODE_KEY) { }
+
+ bool IsValid(const char *value);
+};
+
+/** Channel mode +f (flood)
+ */
+class ChannelModeFlood : public ChannelModeParam
+{
+ public:
+ ChannelModeFlood() : ChannelModeParam(CMODE_FLOOD) { }
+
+ bool IsValid(const char *value);
+};
+
+/** This class is used for channel mode +A (Admin only)
+ * Only opers can mlock it
+ */
+class CoreExport ChannelModeAdmin : public ChannelMode
+{
+ public:
+ ChannelModeAdmin() : ChannelMode(CMODE_ADMINONLY) { }
+
+ /* Opers only */
+ bool CanSet(User *u);
+};
+
+/** This class is used for channel mode +O (Opers only)
+ * Only opers can mlock it
+ */
+class CoreExport ChannelModeOper : public ChannelMode
+{
+ public:
+ ChannelModeOper() : ChannelMode(CMODE_OPERONLY) { }
+
+ /* Opers only */
+ bool CanSet(User *u);
+};
+
+/** This class is used for channel mode +r (registered channel)
+ * No one may mlock r
+ */
+class CoreExport ChannelModeRegistered : public ChannelMode
+{
+ public:
+ ChannelModeRegistered() : ChannelMode(CMODE_REGISTERED) { }
+
+ /* No one mlocks +r */
+ bool CanSet(User *u);
+};
+
+enum StackerType
+{
+ ST_CHANNEL,
+ ST_USER
+};
+
+class StackerInfo
+{
+ public:
+ /* Modes to be added */
+ std::list<std::pair<void *, std::string> > AddModes;
+ /* Modes to be deleted */
+ std::list<std::pair<void *, std::string> > DelModes;
+ /* The type of object this stacker info is for */
+ StackerType Type;
+ /* Bot this is sent from */
+ BotInfo *bi;
+
+ /** Add a mode to this object
+ * @param Mode The mode
+ * @param Set true if setting, false if unsetting
+ * @param Param The param for the mode
+ */
+ void AddMode(void *Mode, bool Set, const std::string &Param);
+};
+
+/** This is mode manager
+ * It contains functions for adding modes to Anope so Anope can track them
+ * and do things such as MLOCK.
+ * This also contains a mode stacker that will combine multiple modes and set
+ * them on a channel all at once
+ */
+class CoreExport ModeManager
+{
+ protected:
+ /* List of pairs of user/channels and their stacker info */
+ static std::list<std::pair<void *, StackerInfo *> > StackerObjects;
+
+ /** Get the stacker info for an item, if one doesnt exist it is created
+ * @param Item The user/channel etc
+ * @return The stacker info
+ */
+ static StackerInfo *GetInfo(void *Item);
+
+ /** Build a list of mode strings to send to the IRCd from the mode stacker
+ * @param info The stacker info for a channel or user
+ * @return a list of strings
+ */
+ static std::list<std::string> BuildModeStrings(StackerInfo *info);
+
+ /** Add a mode to the stacker, internal use only
+ * @param bi The client to set the modes from
+ * @param u The user
+ * @param um The user mode
+ * @param Set Adding or removing?
+ * @param Param A param, if there is one
+ */
+ static void StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param);
+
+ /** Add a mode to the stacker, internal use only
+ * @param bi The client to set the modes from
+ * @param c The channel
+ * @param cm The channel mode
+ * @param Set Adding or removing?
+ * @param Param A param, if there is one
+ */
+ static void StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param);
+
+ /** Really add a mode to the stacker, internal use only
+ * @param bi The client to set the modes from
+ * @param Object The object, user/channel
+ * @param Mode The mode
+ * @param Set Adding or removing?
+ * @param Param A param, if there is one
+ * @param Type The type this is, user or channel
+ */
+ static void StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const std::string &Param, StackerType Type);
+
+ public:
+ /* User modes */
+ static std::map<char, UserMode *> UserModesByChar;
+ static std::map<UserModeName, UserMode *> UserModesByName;
+ /* Channel modes */
+ static std::map<char, ChannelMode *> ChannelModesByChar;
+ static std::map<ChannelModeName, ChannelMode *> ChannelModesByName;
+ /* Although there are two different maps for UserModes and ChannelModes
+ * the pointers in each are the same. This is used to increase
+ * efficiency.
+ */
+
+ /** Add a user mode to Anope
+ * @param Mode The mode
+ * @param um A UserMode or UserMode derived class
+ * @return true on success, false on error
+ */
+ static bool AddUserMode(char Mode, UserMode *um);
+
+ /** Add a channel mode to Anope
+ * @param Mode The mode
+ * @param cm A ChannelMode or ChannelMode derived class
+ * @return true on success, false on error
+ */
+ static bool AddChannelMode(char Mode, ChannelMode *cm);
+
+ /** Find a channel mode
+ * @param Mode The mode
+ * @return The mode class
+ */
+ static ChannelMode *FindChannelModeByChar(char Mode);
+
+ /** Find a user mode
+ * @param Mode The mode
+ * @return The mode class
+ */
+ static UserMode *FindUserModeByChar(char Mode);
+
+ /** Find a channel mode
+ * @param Mode The modename
+ * @return The mode class
+ */
+ static ChannelMode *FindChannelModeByName(ChannelModeName Name);
+
+ /** Find a user mode
+ * @param Mode The modename
+ * @return The mode class
+ */
+ static UserMode *FindUserModeByName(UserModeName Name);
+
+ /** Gets the channel mode char for a symbol (eg + returns v)
+ * @param Value The symbol
+ * @return The char
+ */
+ static char GetStatusChar(char Value);
+
+ /** Add a mode to the stacker to be set on a channel
+ * @param bi The client to set the modes from
+ * @param c The channel
+ * @param cm The channel mode
+ * @param Set true for setting, false for removing
+ * @param Param The param, if there is one
+ */
+ static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param = "");
+
+ /** Add a mode to the stacker to be set on a channel
+ * @param bi The client to set the modes from
+ * @param c The channel
+ * @param Name The channel mode name
+ * @param Set true for setting, false for removing
+ * @param Param The param, if there is one
+ */
+ static void StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const std::string &Param = "");
+
+ /** Add a mode to the stacker to be set on a channel
+ * @param bi The client to set the modes from
+ * @param c The channel
+ * @param Mode The mode char
+ * @param Set true for setting, false for removing
+ * @param Param The param, if there is one
+ */
+ static void StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const std::string &Param = "");
+
+ /** Add a mode to the stacker to be set on a user
+ * @param bi The client to set the modes from
+ * @param u The user
+ * @param um The user mode
+ * @param Set true for setting, false for removing
+ * @param param The param, if there is one
+ */
+ static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param = "");
+
+ /** Add a mode to the stacker to be set on a user
+ * @param bi The client to set the modes from
+ * @param u The user
+ * @param Name The user mode name
+ * @param Set true for setting, false for removing
+ * @param Param The param, if there is one
+ */
+ static void StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const std::string &Param = "");
+
+ /** Add a mode to the stacker to be set on a user
+ * @param bi The client to set the modes from
+ * @param u The user
+ * @param Mode The mode to be set
+ * @param Set true for setting, false for removing
+ * @param Param The param, if there is one
+ */
+ static void StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const std::string &Param = "");
+
+ /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users
+ */
+ static void ProcessModes();
+};
+
diff --git a/include/services.h b/include/services.h
index 30bd0e34b..190529987 100644
--- a/include/services.h
+++ b/include/services.h
@@ -485,44 +485,9 @@ typedef struct hostcore_ HostCore;
typedef struct exception_ Exception;
typedef struct session_ Session;
-enum UserModeName
-{
- UMODE_BEGIN,
-
- /* Usermodes */
- UMODE_SERV_ADMIN, UMODE_BOT, UMODE_CO_ADMIN, UMODE_FILTER, UMODE_HIDEOPER, UMODE_NETADMIN,
- UMODE_REGPRIV, UMODE_PROTECTED, UMODE_NO_CTCP, UMODE_WEBTV, UMODE_WHOIS, UMODE_ADMIN, UMODE_DEAF,
- UMODE_GLOBOPS, UMODE_HELPOP, UMODE_INVIS, UMODE_OPER, UMODE_PRIV, UMODE_GOD, UMODE_REGISTERED,
- UMODE_SNOMASK, UMODE_VHOST, UMODE_WALLOPS, UMODE_CLOAK, UMODE_SSL, UMODE_CALLERID, UMODE_COMMONCHANS,
- UMODE_HIDDEN, UMODE_STRIPCOLOR,
-
- UMODE_END
-};
-
-enum ChannelModeName
-{
- CMODE_BEGIN,
-
- /* Channel modes */
- CMODE_BLOCKCOLOR, CMODE_FLOOD, CMODE_INVITE, CMODE_KEY, CMODE_LIMIT, CMODE_MODERATED, CMODE_NOEXTERNAL,
- CMODE_PRIVATE, CMODE_REGISTERED, CMODE_SECRET, CMODE_TOPIC, CMODE_AUDITORIUM, CMODE_SSL, CMODE_ADMINONLY,
- CMODE_NOCTCP, CMODE_FILTER, CMODE_NOKNOCK, CMODE_REDIRECT, CMODE_REGMODERATED, CMODE_NONICK, CMODE_OPERONLY,
- CMODE_NOKICK, CMODE_REGISTEREDONLY, CMODE_STRIPCOLOR, CMODE_NONOTICE, CMODE_NOINVITE, CMODE_ALLINVITE,
- CMODE_BLOCKCAPS, CMODE_PERM, CMODE_NICKFLOOD, CMODE_JOINFLOOD,
-
- /* b/e/I */
- CMODE_BAN, CMODE_EXCEPT,
- CMODE_INVITEOVERRIDE,
-
- /* v/h/o/a/q */
- CMODE_VOICE, CMODE_HALFOP, CMODE_OP,
- CMODE_PROTECT, CMODE_OWNER,
-
- CMODE_END
-};
-
#include "bots.h"
#include "opertype.h"
+#include "modes.h"
/*************************************************************************/
@@ -538,7 +503,6 @@ struct ircdvars_ {
const char *botchanumode; /* Modes set when botserv joins a channel */
int svsnick; /* Supports SVSNICK */
int vhost; /* Supports vhost */
- const char *modeonunreg; /* Mode on Unregister */
int sgline; /* Supports SGline */
int sqline; /* Supports SQline */
int szline; /* Supports SZline */
@@ -985,51 +949,91 @@ class CoreExport Channel : public Extensible
*/
bool HasMode(ChannelModeName Name);
+ /** Set a mode internally on a channel, this is not sent out to the IRCd
+ * @param cm The mode
+ * @param param The param
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
+ */
+ void SetModeInternal(ChannelMode *cm, const std::string &param = "", bool EnforceMLock = true);
+
+ /** Remove a mode internally on a channel, this is not sent out to the IRCd
+ * @param cm The mode
+ * @param param The param
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
+ */
+ void RemoveModeInternal(ChannelMode *cm, const std::string &param = "", bool EnforceMLock = true);
+
+ /** Set a mode on a channel
+ * @param bi The client setting the modes
+ * @param cm The mode
+ * @param param Optional param arg for the mode
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
+ */
+ void SetMode(BotInfo *bi, ChannelMode *cm, const std::string &param = "", bool EnforceMLock = true);
+
/**
* Set a mode on a channel
+ * @param bi The client setting the modes
* @param Name The mode name
* @param param Optional param arg for the mode
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void SetMode(ChannelModeName Name, const std::string param = "");
+ void SetMode(BotInfo *bi, ChannelModeName Name, const std::string &param = "", bool EnforceMLock = true);
/**
* Set a mode on a channel
+ * @param bi The client setting the modes
* @param Mode The mode
* @param param Optional param arg for the mode
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
+ */
+ void SetMode(BotInfo *bi, char Mode, const std::string &param = "", bool EnforceMLock = true);
+
+ /** Remove a mode from a channel
+ * @param bi The client setting the modes
+ * @param cm The mode
+ * @param param Optional param arg for the mode
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void SetMode(char Mode, const std::string param = "");
+ void RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string &param = "", bool EnforceMLock = true);
/**
* Remove a mode from a channel
+ * @param bi The client setting the modes
* @param Name The mode name
+ * @param param Optional param arg for the mode
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void RemoveMode(ChannelModeName Name);
+ void RemoveMode(BotInfo *bi, ChannelModeName Name, const std::string &param = "", bool EnforceMLock = true);
/**
* Remove a mode from a channel
+ * @param bi The client setting the modes
* @param Mode The mode
+ * @param param Optional param arg for the mode
+ * @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void RemoveMode(char Mode);
+ void RemoveMode(BotInfo *bi, char Mode, const std::string &param = "", bool EnforceMLock = true);
/** Clear all the modes from the channel
- * @param client The client unsetting the modes
+ * @param bi The client unsetting the modes
*/
- void ClearModes(char *client = NULL);
+ void ClearModes(BotInfo *bi = NULL);
/** Clear all the bans from the channel
- * @param client The client unsetting the modes
+ * @param bi The client unsetting the modes
*/
- void ClearBans(char *client = NULL);
+ void ClearBans(BotInfo *bi = NULL);
/** Clear all the excepts from the channel
- * @param client The client unsetting the modes
+ * @param bi The client unsetting the modes
*/
- void ClearExcepts(char *client = NULL);
+ void ClearExcepts(BotInfo *bi = NULL);
/** Clear all the invites from the channel
- * @param client The client unsetting the modes
+ * @param bi The client unsetting the modes
*/
- void ClearInvites(char *client = NULL);
+ void ClearInvites(BotInfo *bi = NULL);
/** Get a param from the channel
* @param Name The mode
@@ -1042,6 +1046,13 @@ class CoreExport Channel : public Extensible
* @param Name The mode
*/
const bool HasParam(ChannelModeName Name);
+
+ /** Set a string of modes on the channel
+ * @param bi The client setting the modes
+ * @param EnforceMLock Should mlock be enforced on this mode change
+ * @param cmodes The modes to set
+ */
+ void SetModes(BotInfo *bi, bool EnforceMLock, const std::string &cmodes, ...);
};
/** Channelban type flags
@@ -1180,335 +1191,6 @@ struct exception_ {
/*************************************************************************/
-/** The different types of modes
-*/
-enum ModeType
-{
- /* Regular mode */
- MODE_REGULAR,
- /* b/e/I */
- MODE_LIST,
- /* k/l etc */
- MODE_PARAM,
- /* v/h/o/a/q */
- MODE_STATUS
-};
-
-/** This class is a user mode, all user modes use this/inherit from this
- */
-class UserMode
-{
- public:
-
- /* Mode name */
- UserModeName Name;
- /* The mode char */
- char ModeChar;
-
- /** Default constructor
- * @param nName The mode name
- */
- UserMode(UserModeName mName)
- {
- this->Name = mName;
- }
-
- /** Default destructor
- */
- virtual ~UserMode() { }
-};
-
-/** This class is a channel mode, all channel modes use this/inherit from this
- */
-class CoreExport ChannelMode
-{
- public:
-
- /* Mode name */
- ChannelModeName Name;
- /* Type of mode this is */
- ModeType Type;
- /* The mode char */
- char ModeChar;
-
- /** Default constructor
- * @param mName The mode name
- */
- ChannelMode(ChannelModeName mName)
- {
- this->Name = mName;
- this->Type = MODE_REGULAR;
- }
-
- /** Default destructor
- */
- virtual ~ChannelMode() { }
-
- /** Can a user set this mode, used for mlock
- * NOTE: User CAN be NULL, this is for checking if it can be locked with defcon
- * @param u The user, or NULL
- */
- virtual bool CanSet(User *u) { return true; }
-};
-
-/** This is a mode for lists, eg b/e/I. These modes should inherit from this
- */
-class CoreExport ChannelModeList : public ChannelMode
-{
- public:
-
- /** Default constructor
- * @param mName The mode name
- */
- ChannelModeList(ChannelModeName mName) : ChannelMode(mName)
- {
- this->Type = MODE_LIST;
- }
-
- /** Default destructor
- */
- virtual ~ChannelModeList() { }
-
- /** Is the mask valid
- * @param mask The mask
- * @return true for yes, false for no
- */
- virtual bool IsValid(const char *mask) { return true; }
-
- /** Add the mask to the channel, this should be overridden
- * @param chan The channel
- * @param mask The mask
- */
- virtual void AddMask(Channel *chan, const char *mask) { }
-
- /** Delete the mask from the channel, this should be overridden
- * @param chan The channel
- * @param mask The mask
- */
- virtual void DelMask(Channel *chan, const char *mask) { }
-
-};
-
-/** This is a mode with a paramater, eg +k/l. These modes should use/inherit from this
-*/
-class CoreExport ChannelModeParam : public ChannelMode
-{
- public:
-
- /** Default constructor
- * @param mName The mode name
- * @param MinusArg true if this mode sends no arg when unsetting
- */
- ChannelModeParam(ChannelModeName mName, bool MinusArg = false) : ChannelMode(mName)
- {
- this->Type = MODE_PARAM;
- MinusNoArg = MinusArg;
- }
-
- /** Default destructor
- */
- virtual ~ChannelModeParam() { }
-
- /* Should we send an arg when unsetting this mode? */
- bool MinusNoArg;
-
- /** Is the param valid
- * @param value The param
- * @return true for yes, false for no
- */
- virtual bool IsValid(const char *value) { return true; }
-};
-
-/** This is a mode that is a channel status, eg +v/h/o/a/q.
-*/
-class CoreExport ChannelModeStatus : public ChannelMode
-{
- public:
- /** CUS_ values, see below
- */
- int16 Status;
- /* The symbol, eg @ % + */
- char Symbol;
-
- /** Default constructor
- * @param mName The mode name
- * @param mStatus A CUS_ value
- * @param mSymbol The symbol for the mode, eg @ % +
- * @param mProtectBotServ Should botserv clients reset this on themself if it gets unset>
- */
- ChannelModeStatus(ChannelModeName mName, int16 mStatus, char mSymbol, bool mProtectBotServ = false) : ChannelMode(mName)
- {
- this->Type = MODE_STATUS;
- this->Status = mStatus;
- this->Symbol = mSymbol;
- this->ProtectBotServ = mProtectBotServ;
- }
-
- /** Default destructor
- */
- virtual ~ChannelModeStatus() { }
-
- /* Should botserv protect itself with this mode? eg if someone -o's botserv it will +o */
- bool ProtectBotServ;
-};
-
-/** This class manages modes, and has the ability to add channel and
- * user modes to Anope to track internally
- */
-class CoreExport ModeManager
-{
- public:
- /* User modes */
- static std::map<char, UserMode *> UserModesByChar;
- static std::map<UserModeName, UserMode *> UserModesByName;
- /* Channel modes */
- static std::map<char, ChannelMode *> ChannelModesByChar;
- static std::map<ChannelModeName, ChannelMode *> ChannelModesByName;
- /* Although there are two different maps for UserModes and ChannelModes
- * the pointers in each are the same. This is used to increase
- * efficiency.
- */
-
- /** Add a user mode to Anope
- * @param Mode The mode
- * @param um A UserMode or UserMode derived class
- * @return true on success, false on error
- */
- static bool AddUserMode(char Mode, UserMode *um);
-
- /** Add a channel mode to Anope
- * @param Mode The mode
- * @param cm A ChannelMode or ChannelMode derived class
- * @return true on success, false on error
- */
- static bool AddChannelMode(char Mode, ChannelMode *cm);
-
- /** Find a channel mode
- * @param Mode The mode
- * @return The mode class
- */
- static ChannelMode *FindChannelModeByChar(char Mode);
-
- /** Find a user mode
- * @param Mode The mode
- * @return The mode class
- */
- static UserMode *FindUserModeByChar(char Mode);
-
- /** Find a channel mode
- * @param Mode The modename
- * @return The mode class
- */
- static ChannelMode *FindChannelModeByName(ChannelModeName Name);
-
- /** Find a user mode
- * @param Mode The modename
- * @return The mode class
- */
- static UserMode *FindUserModeByName(UserModeName Name);
-
- /** Gets the channel mode char for a symbol (eg + returns v)
- * @param Value The symbol
- * @return The char
- */
- static char GetStatusChar(char Value);
-};
-
-/** Channel mode +b
- */
-class CoreExport ChannelModeBan : public ChannelModeList
-{
- public:
- ChannelModeBan() : ChannelModeList(CMODE_BAN) { }
-
- void AddMask(Channel *chan, const char *mask);
-
- void DelMask(Channel *chan, const char *mask);
-};
-
-/** Channel mode +e
- */
-class CoreExport ChannelModeExcept : public ChannelModeList
-{
- public:
- ChannelModeExcept() : ChannelModeList(CMODE_EXCEPT) { }
-
- void AddMask(Channel *chan, const char *mask);
-
- void DelMask(Channel *chan, const char *mask);
-};
-
-/** Channel mode +I
- */
-class CoreExport ChannelModeInvite : public ChannelModeList
-{
- public:
- ChannelModeInvite() : ChannelModeList(CMODE_INVITEOVERRIDE) { }
-
- void AddMask(Channel *chan, const char *mask);
-
- void DelMask(Channel *chan, const char *mask);
-};
-
-/** Channel mode +k (key)
- */
-class CoreExport ChannelModeKey : public ChannelModeParam
-{
- public:
- ChannelModeKey() : ChannelModeParam(CMODE_KEY) { }
-
- bool IsValid(const char *value);
-};
-
-/** Channel mode +f (flood)
- */
-class ChannelModeFlood : public ChannelModeParam
-{
- public:
- ChannelModeFlood() : ChannelModeParam(CMODE_FLOOD) { }
-
- bool IsValid(const char *value);
-};
-
-/** This class is used for channel mode +A (Admin only)
- * Only opers can mlock it
- */
-class CoreExport ChannelModeAdmin : public ChannelMode
-{
- public:
- ChannelModeAdmin() : ChannelMode(CMODE_ADMINONLY) { }
-
- /* Opers only */
- bool CanSet(User *u);
-};
-
-/** This class is used for channel mode +O (Opers only)
- * Only opers can mlock it
- */
-class CoreExport ChannelModeOper : public ChannelMode
-{
- public:
- ChannelModeOper() : ChannelMode(CMODE_OPERONLY) { }
-
- /* Opers only */
- bool CanSet(User *u);
-};
-
-/** This class is used for channel mode +r (registered channel)
- * No one may mlock r
- */
-class CoreExport ChannelModeRegistered : public ChannelMode
-{
- public:
- ChannelModeRegistered() : ChannelMode(CMODE_REGISTERED) { }
-
- /* No one mlocks +r */
- bool CanSet(User *u);
-};
-
-
-/*************************************************************************/
-
struct session_ {
Session *prev, *next;
char *host;
@@ -1639,6 +1321,7 @@ class CoreExport IRCDProto
private:
virtual void SendSVSKillInternal(const char *, const char *, const char *) = 0;
virtual void SendModeInternal(BotInfo *, const char *, const char *) = 0;
+ virtual void SendModeInternal(User *, const char *) = 0;
virtual void SendKickInternal(BotInfo *bi, const char *, const char *, const char *) = 0;
virtual void SendNoticeChanopsInternal(BotInfo *bi, const char *, const char *) = 0;
virtual void SendMessageInternal(BotInfo *bi, const char *dest, const char *buf);
@@ -1661,6 +1344,7 @@ class CoreExport IRCDProto
virtual void SendSVSKill(const char *source, const char *user, const char *fmt, ...);
virtual void SendSVSMode(User *, int, const char **) = 0;
virtual void SendMode(BotInfo *bi, const char *dest, const char *fmt, ...);
+ virtual void SendMode(User *u, const char *fmt, ...);
virtual void SendClientIntroduction(const char *, const char *, const char *, const char *, const char *, const char *uid) = 0;
virtual void SendKick(BotInfo *bi, const char *chan, const char *user, const char *fmt, ...);
virtual void SendNoticeChanops(BotInfo *bi, const char *dest, const char *fmt, ...);
@@ -1670,7 +1354,6 @@ class CoreExport IRCDProto
virtual void SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...);
virtual void SendGlobalNotice(BotInfo *bi, const char *dest, const char *msg);
virtual void SendGlobalPrivmsg(BotInfo *bi, const char *dest, const char *msg);
- virtual void SendBotOp(const char *, const char *) = 0;
/** XXX: This is a hack for NickServ enforcers. It is deprecated.
* If I catch any developer using this in new code, I will RIP YOUR BALLS OFF.
@@ -1707,7 +1390,6 @@ class CoreExport IRCDProto
virtual void SendSWhois(const char *, const char *, const char *) { }
virtual void SendEOB() { }
virtual void SendServer(Server *) = 0;
- virtual void ProcessUsermodes(User *, int, const char **) = 0;
virtual int IsNickValid(const char *) { return 1; }
virtual int IsChannelValid(const char *);
virtual void SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...);
diff --git a/include/users.h b/include/users.h
index aced32c20..d277704ad 100644
--- a/include/users.h
+++ b/include/users.h
@@ -23,6 +23,8 @@ class CoreExport User : public Extensible
std::string ident;
std::string uid;
bool OnAccess; /* If the user is on the access list of the nick theyre on */
+ std::bitset<128> modes; /* Bitset of mode names the user has set on them */
+ std::map<UserModeName, std::string> Params; /* Map of user modes and the params this user has */
public: // XXX: exposing a tiny bit too much
User *next, *prev;
@@ -37,7 +39,6 @@ class CoreExport User : public Extensible
Server *server; /* Server user is connected to */
time_t timestamp; /* Timestamp of the nick */
time_t my_signon; /* When did _we_ see the user? */
- std::bitset<128> modes;
NickCore *nc;
@@ -66,7 +67,6 @@ class CoreExport User : public Extensible
/** Destroy a user.
*/
~User();
-
/** Update the nickname of a user record accordingly, should be
* called from ircd protocol.
@@ -100,7 +100,6 @@ class CoreExport User : public Extensible
*/
const std::string &GetUID() const;
-
/** Update the displayed ident (username) of a user record.
* @param ident The new ident to give this user.
*/
@@ -161,26 +160,55 @@ class CoreExport User : public Extensible
* @param Name Mode name
* @return true or false
*/
- const bool HasMode(UserModeName Name) const;
-
- /** Set a mode on the user
- * @param Name The mode name
- */
- void SetMode(UserModeName Name);
-
- /* Set a mode on the user
- * @param ModeChar The mode char
- */
- void SetMode(char ModeChar);
-
- /** Remove a mode from the user
- * @param Name The mode name
- */
- void RemoveMode(UserModeName Name);
+ const bool HasMode(UserModeName Name) const;
+
+ /** Set a mode internally on the user, the IRCd is not informed
+ * @param um The user mode
+ * @param Param The param, if there is one
+ */
+ void SetModeInternal(UserMode *um, const std::string &Param = "");
+
+ /** Remove a mode internally on the user, the IRCd is not informed
+ * @param um The user mode
+ */
+ void RemoveModeInternal(UserMode *um);
+
+ /** Set a mode on the user
+ * @param um The user mode
+ * @param Param Optional param for the mode
+ */
+ void SetMode(UserMode *um, const std::string &Param = "");
+
+ /** Set a mode on the user
+ * @param Name The mode name
+ * @param Param Optional param for the mode
+ */
+ void SetMode(UserModeName Name, const std::string &Param = "");
+
+ /* Set a mode on the user
+ * @param ModeChar The mode char
+ * @param param Optional param for the mode
+ */
+ void SetMode(char ModeChar, const std::string &Param = "");
+
+ /** Remove a mode on the user
+ * @param um The user mode
+ */
+ void RemoveMode(UserMode *um);
/** Remove a mode from the user
- * @param ModeChar The mode char
- */
- void RemoveMode(char ModeChar);
+ * @param Name The mode name
+ */
+ void RemoveMode(UserModeName Name);
+
+ /** Remove a mode from the user
+ * @param ModeChar The mode char
+ */
+ void RemoveMode(char ModeChar);
+
+ /** Set a string of modes on a user
+ * @param modes The modes
+ */
+ void SetModes(const std::string &modes, ...);
};