summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-11-20 21:45:30 -0500
committerAdam <Adam@anope.org>2010-12-12 19:35:27 -0500
commit246f44b9888161aecefc81f0ff17ddd893287e3c (patch)
treeb89607a9ad9c91914f292fc54cc32213a8d9f5c4 /include
parenta85112172d842aa74aa5531788d383328d153e74 (diff)
Added cs_mode, rewrote the old list mode code, and added CIDR support
Diffstat (limited to 'include')
-rw-r--r--include/channels.h56
-rw-r--r--include/extern.h16
-rw-r--r--include/language.h29
-rw-r--r--include/modes.h20
-rw-r--r--include/modules.h14
-rw-r--r--include/regchannel.h63
-rw-r--r--include/services.h35
-rw-r--r--include/sockets.h12
-rw-r--r--include/users.h4
9 files changed, 118 insertions, 131 deletions
diff --git a/include/channels.h b/include/channels.h
index 54a85426b..cf4d97df3 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -64,13 +64,12 @@ enum ChannelFlags
class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
{
+ public:
+ typedef std::multimap<ChannelModeName, Anope::string> ModeList;
private:
/** A map of channel modes with their parameters set on this channel
*/
- std::map<ChannelModeName, Anope::string> Params;
-
- /* Modes set on the channel */
- Flags<ChannelModeName, CMODE_END * 2> modes;
+ ModeList modes;
public:
/** Default constructor
@@ -87,10 +86,6 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
ChannelInfo *ci; /* Corresponding ChannelInfo */
time_t creation_time; /* When channel was created */
- EList *bans;
- EList *excepts;
- EList *invites;
-
/* List of users in the channel */
CUserList users;
@@ -146,16 +141,18 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
*/
bool HasUserStatus(User *u, ChannelModeName Name) const;
- /** See if the channel has any modes at all
- * @return true or false
- */
- inline bool HasModes() const { return modes.FlagCount(); }
-
/** See if a channel has a mode
* @param Name The mode name
- * @return true or false
+ * @return The number of modes set
+ * @param param The optional mode param
*/
- bool HasMode(ChannelModeName Name) const;
+ size_t HasMode(ChannelModeName Name, const Anope::string &param = "");
+
+ /** Get a list of modes on a channel
+ * @param Name A mode name to get the list of
+ * @return a pair of iterators for the beginning and end of the list
+ */
+ std::pair<ModeList::iterator, ModeList::iterator> GetModeList(ChannelModeName Name);
/** Set a mode internally on a channel, this is not sent out to the IRCd
* @param cm The mode
@@ -205,30 +202,6 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
*/
void RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param = "", bool EnforceMLock = true);
- /** Clear all the modes from the channel
- * @param bi The client unsetting the modes
- * @param internal Only remove the modes internally
- */
- void ClearModes(BotInfo *bi = NULL, bool internal = false);
-
- /** Clear all the bans from the channel
- * @param bi The client unsetting the modes
- * @param internal Only remove the modes internally
- */
- void ClearBans(BotInfo *bi = NULL, bool internal = false);
-
- /** Clear all the excepts from the channel
- * @param bi The client unsetting the modes
- * @param internal Only remove the modes internally
- */
- void ClearExcepts(BotInfo *bi = NULL, bool internal = false);
-
- /** Clear all the invites from the channel
- * @param bi The client unsetting the modes
- * @param internal Only remove the modes internally
- */
- void ClearInvites(BotInfo *bi = NULL, bool internal = false);
-
/** Get a param from the channel
* @param Name The mode
* @param Target a string to put the param into
@@ -236,11 +209,6 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
*/
bool GetParam(ChannelModeName Name, Anope::string &Target) const;
- /** Check if a mode is set and has a param
- * @param Name The mode
- */
- bool HasParam(ChannelModeName Name) const;
-
/** 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
diff --git a/include/extern.h b/include/extern.h
index b8bcb5be3..bd951ee5e 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -75,18 +75,6 @@ E void MassChannelModes(BotInfo *bi, const Anope::string &modes);
E void chan_set_correct_modes(User *user, Channel *c, int give_modes);
-E Entry *entry_create(const Anope::string &mask);
-E Entry *entry_add(EList *list, const Anope::string &mask);
-E void entry_delete(EList *list, Entry *e);
-E EList *list_create();
-E int entry_match(Entry *e, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip);
-E int entry_match_mask(Entry *e, const Anope::string &mask, uint32 ip);
-E Entry *elist_match(EList *list, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip);
-E Entry *elist_match_mask(EList *list, const Anope::string &mask, uint32 ip);
-E Entry *elist_match_user(EList *list, User *u);
-E Entry *elist_find_mask(EList *list, const Anope::string &mask);
-E long get_memuse(EList *list);
-
inline BotInfo *whosends(ChannelInfo *ci)
{
if (!ci || !ci->bi || !ci->c || !ci->botflags.HasFlag(BS_SYMBIOSIS) || !ci->c->FindUser(ci->bi))
@@ -272,9 +260,7 @@ E bool str_is_cidr(const Anope::string &str, uint32 &ip, uint32 &mask, Anope::st
/**** modes.cpp ****/
/* Number of generic modes we support */
E unsigned GenericChannelModes, GenericUserModes;
-E Flags<ChannelModeName, CMODE_END * 2> DefMLockOn;
-E Flags<ChannelModeName, CMODE_END * 2> DefMLockOff;
-E std::map<ChannelModeName, Anope::string> DefMLockParams;
+E std::multimap<ChannelModeName, ModeLock> def_mode_locks;
E void SetDefaultMLock(ServerConfig *config);
/**** nickserv.c ****/
diff --git a/include/language.h b/include/language.h
index 0b1c60f2c..634b840dd 100644
--- a/include/language.h
+++ b/include/language.h
@@ -274,7 +274,6 @@ enum LanguageString
CHAN_LEVEL_INVITE,
CHAN_LEVEL_AKICK,
CHAN_LEVEL_SET,
- CHAN_LEVEL_CLEAR,
CHAN_LEVEL_UNBAN,
CHAN_LEVEL_OPDEOP,
CHAN_LEVEL_ACCESS_LIST,
@@ -300,6 +299,7 @@ enum LanguageString
CHAN_LEVEL_BANME,
CHAN_LEVEL_BAN,
CHAN_LEVEL_TOPIC,
+ CHAN_LEVEL_MODE,
CHAN_LEVEL_INFO,
CHAN_LEVEL_AUTOOWNER,
CHAN_LEVEL_OWNER,
@@ -555,13 +555,8 @@ enum LanguageString
CHAN_UNBANNED,
CHAN_UNBANNED_OTHER,
CHAN_TOPIC_SYNTAX,
- CHAN_CLEAR_SYNTAX,
- CHAN_CLEARED_BANS,
- CHAN_CLEARED_EXCEPTS,
- CHAN_CLEARED_MODES,
- CHAN_CLEARED_OPS,
+ CHAN_CLEARUSERS_SYNTAX,
CHAN_CLEARED_USERS,
- CHAN_CLEARED_INVITES,
CHAN_CLONED,
CHAN_CLONED_ACCESS,
CHAN_CLONED_AKICK,
@@ -597,6 +592,15 @@ enum LanguageString
CHAN_DEOWNER_SYNTAX,
CHAN_KICK_SYNTAX,
CHAN_BAN_SYNTAX,
+ CHAN_MODE_SYNTAX,
+ CHAN_MODE_LOCK_UNKNOWN,
+ CHAN_MODE_LOCK_MISSING_PARAM,
+ CHAN_MODE_LOCK_NONE,
+ CHAN_MODE_LOCK_HEADER,
+ CHAN_MODE_LOCKED,
+ CHAN_MODE_NOT_LOCKED,
+ CHAN_MODE_UNLOCKED,
+ CHAN_MODE_LIST_FMT,
MEMO_HAVE_NEW_MEMO,
MEMO_HAVE_NEW_MEMOS,
MEMO_TYPE_READ_LAST,
@@ -931,9 +935,6 @@ enum LanguageString
OPER_OLINE_SYNTAX,
OPER_OLINE_SUCCESS,
OPER_OLINE_IRCOP,
- OPER_CLEARMODES_SYNTAX,
- OPER_CLEARMODES_DONE,
- OPER_CLEARMODES_ALL_DONE,
OPER_KICK_SYNTAX,
OPER_SVSNICK_SYNTAX,
OPER_SVSNICK_NEWNICK,
@@ -1266,7 +1267,7 @@ enum LanguageString
CHAN_HELP_CMD_AKICK,
CHAN_HELP_CMD_DROP,
CHAN_HELP_CMD_BAN,
- CHAN_HELP_CMD_CLEAR,
+ CHAN_HELP_CMD_CLEARUSERS,
CHAN_HELP_CMD_DEVOICE,
CHAN_HELP_CMD_GETKEY,
CHAN_HELP_CMD_INFO,
@@ -1287,6 +1288,7 @@ enum LanguageString
CHAN_HELP_CMD_PROTECT,
CHAN_HELP_CMD_DEOP,
CHAN_HELP_CMD_CLONE,
+ CHAN_HELP_CMD_MODE,
CHAN_HELP,
CHAN_HELP_EXPIRES,
CHAN_HELP_REGISTER,
@@ -1358,9 +1360,10 @@ enum LanguageString
CHAN_HELP_KICK,
CHAN_HELP_BAN,
CHAN_HELP_TOPIC,
- CHAN_HELP_CLEAR,
+ CHAN_HELP_CLEARUSERS,
CHAN_HELP_GETKEY,
CHAN_HELP_CLONE,
+ CHAN_HELP_MODE,
CHAN_SERVADMIN_HELP,
CHAN_SERVADMIN_HELP_DROP,
CHAN_SERVADMIN_HELP_SET_NOEXPIRE,
@@ -1403,7 +1406,6 @@ enum LanguageString
OPER_HELP_CMD_STAFF,
OPER_HELP_CMD_MODE,
OPER_HELP_CMD_KICK,
- OPER_HELP_CMD_CLEARMODES,
OPER_HELP_CMD_AKILL,
OPER_HELP_CMD_SNLINE,
OPER_HELP_CMD_SQLINE,
@@ -1442,7 +1444,6 @@ enum LanguageString
OPER_HELP_MODE,
OPER_HELP_UMODE,
OPER_HELP_OLINE,
- OPER_HELP_CLEARMODES,
OPER_HELP_KICK,
OPER_HELP_SVSNICK,
OPER_HELP_AKILL,
diff --git a/include/modes.h b/include/modes.h
index 299d1a2db..ce0281cd0 100644
--- a/include/modes.h
+++ b/include/modes.h
@@ -185,17 +185,17 @@ class CoreExport ChannelModeList : public ChannelMode
*/
virtual bool IsValid(const Anope::string &mask) const { return true; }
- /** Add the mask to the channel, this should be overridden
+ /** Called when a mask is added to a channel
* @param chan The channel
* @param mask The mask
*/
- virtual void AddMask(Channel *chan, const Anope::string &mask) { }
+ virtual void OnAdd(Channel *chan, const Anope::string &mask) { }
- /** Delete the mask from the channel, this should be overridden
+ /** Called when a mask is removed from a channel
* @param chan The channel
* @param mask The mask
*/
- virtual void DelMask(Channel *chan, const Anope::string &mask) { }
+ virtual void OnDel(Channel *chan, const Anope::string &mask) { }
};
@@ -254,9 +254,9 @@ class CoreExport ChannelModeBan : public ChannelModeList
public:
ChannelModeBan(char modeChar) : ChannelModeList(CMODE_BAN, "CMODE_BAN", modeChar) { }
- void AddMask(Channel *chan, const Anope::string &mask);
+ void OnAdd(Channel *chan, const Anope::string &mask);
- void DelMask(Channel *chan, const Anope::string &mask);
+ void OnDel(Channel *chan, const Anope::string &mask);
};
/** Channel mode +e
@@ -266,9 +266,9 @@ class CoreExport ChannelModeExcept : public ChannelModeList
public:
ChannelModeExcept(char modeChar) : ChannelModeList(CMODE_EXCEPT, "CMODE_EXCEPT", modeChar) { }
- void AddMask(Channel *chan, const Anope::string &mask);
+ void OnAdd(Channel *chan, const Anope::string &mask);
- void DelMask(Channel *chan, const Anope::string &mask);
+ void OnDel(Channel *chan, const Anope::string &mask);
};
/** Channel mode +I
@@ -278,9 +278,9 @@ class CoreExport ChannelModeInvex : public ChannelModeList
public:
ChannelModeInvex(char modeChar) : ChannelModeList(CMODE_INVITEOVERRIDE, "CMODE_INVITEOVERRIDE", modeChar) { }
- void AddMask(Channel *chan, const Anope::string &mask);
+ void OnAdd(Channel *chan, const Anope::string &mask);
- void DelMask(Channel *chan, const Anope::string &mask);
+ void OnDel(Channel *chan, const Anope::string &mask);
};
diff --git a/include/modules.h b/include/modules.h
index 481b5180b..be5c14447 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -991,20 +991,18 @@ class CoreExport Module : public Extensible
virtual void OnUserModeAdd(UserMode *um) { }
/** Called when a mode is about to be mlocked
- * @param ci The channel
- * @param Name The mode being mlocked
- * @param status true if its being mlocked +, false for -
- * @param param The param, if there is one and if status is true
+ * @param ci The channel the mode is being locked on
+ * @param lock The mode lock
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
*/
- virtual EventReturn OnMLock(ChannelInfo *ci, ChannelModeName Name, bool status, const Anope::string &param) { return EVENT_CONTINUE; }
+ virtual EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) { return EVENT_CONTINUE; }
/** Called when a mode is about to be unlocked
- * @param ci The channel
- * @param Name The mode being mlocked
+ * @param ci The channel the mode is being unlocked from
+ * @param mode The mode being unlocked
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock.
*/
- virtual EventReturn OnUnMLock(ChannelInfo *ci, ChannelModeName Name) { return EVENT_CONTINUE; }
+ virtual EventReturn OnUnMLock(ChannelInfo *ci, ChannelMode *mode, const Anope::string &param) { return EVENT_CONTINUE; }
/** Called after a module is loaded
* @param u The user loading the module, can be NULL
diff --git a/include/regchannel.h b/include/regchannel.h
index 1300b9cf4..dd47a88fc 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -62,15 +62,26 @@ enum ChannelInfoFlag
CI_END
};
+struct ModeLock
+{
+ bool set;
+ ChannelModeName name;
+ Anope::string param;
+ Anope::string setter;
+ time_t created;
+
+ ModeLock(bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime) : set(s), name(n), param(p), setter(se), created(c) { }
+};
+
class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, CI_END>
{
private:
- std::map<ChannelModeName, Anope::string> Params; /* Map of parameters by mode name for mlock */
+ typedef std::multimap<ChannelModeName, ModeLock> ModeList;
+ private:
std::vector<ChanAccess *> access; /* List of authorized users */
std::vector<AutoKick *> akick; /* List of users to kickban */
std::vector<BadWord *> badwords; /* List of badwords */
- Flags<ChannelModeName, CMODE_END * 2> mlock_on; /* Modes mlocked on */
- Flags<ChannelModeName, CMODE_END * 2> mlock_off; /* Modes mlocked off */
+ ModeList mode_locks;
public:
/** Default constructor
@@ -241,51 +252,51 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
void LoadMLock();
/** Check if a mode is mlocked
- * @param Name The mode
+ * @param mode The mode
+ * @param An optional param
* @param status True to check mlock on, false for mlock off
* @return true on success, false on fail
*/
- bool HasMLock(ChannelModeName Name, bool status) const;
+ bool HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const;
/** Set a mlock
- * @param Name The mode
+ * @param mode The mode
* @param status True for mlock on, false for mlock off
* @param param An optional param arg for + mlocked modes
+ * @param setter Who is setting the mlock
+ * @param created When the mlock was created
* @return true on success, false on failure (module blocking)
*/
- bool SetMLock(ChannelModeName Name, bool status, const Anope::string &param = "");
+ bool SetMLock(ChannelMode *mode, bool status, const Anope::string &param = "", const Anope::string &setter = "", time_t created = Anope::CurTime);
/** Remove a mlock
- * @param Name The mode
- * @return true on success, false on failure (module blcoking)
+ * @param mode The mode
+ * @param param The param of the mode, required if it is a list or status mode
+ * @return true on success, false on failure
*/
- bool RemoveMLock(ChannelModeName Name);
+ bool RemoveMLock(ChannelMode *mode, const Anope::string &param = "");
/** Clear all mlocks on the channel
*/
void ClearMLock();
- /** Get the number of mlocked modes for this channel
- * @param status true for mlock on, false for mlock off
- * @return The number of mlocked modes
- */
- size_t GetMLockCount(bool status) const;
-
- /** Get a param from the channel
- * @param Name The mode
- * @param Target a string to put the param into
- * @return true on success
+ /** Get all of the mlocks for this channel
+ * @return The mlocks
*/
- bool GetParam(ChannelModeName Name, Anope::string &Target) const;
+ const std::multimap<ChannelModeName, ModeLock> &GetMLock() const;
- /** Check if a mode is set and has a param
- * @param Name The mode
+ /** Get a list of modes on a channel
+ * @param Name The mode name to get a list of
+ * @return a pair of iterators for the beginning and end of the list
*/
- bool HasParam(ChannelModeName Name) const;
+ std::pair<ModeList::iterator, ModeList::iterator> GetModeList(ChannelModeName Name);
- /** Clear all the params from the channel
+ /** Get details for a specific mlock
+ * @param name The mode name
+ * @param An optional param to match with
+ * @return The MLock, if any
*/
- void ClearParams();
+ ModeLock *GetMLock(ChannelModeName name, const Anope::string &param = "");
/** Check whether a user is permitted to be on this channel
* @param u The user
diff --git a/include/services.h b/include/services.h
index 38abf931f..4d2401883 100644
--- a/include/services.h
+++ b/include/services.h
@@ -453,9 +453,6 @@ struct IRCDVar
int svsmode_ucmode; /* Can remove User Channel Modes with SVSMODE */
int sglineenforce;
int ts6; /* ircd is TS6 */
- int cidrchanbei; /* channel bans/excepts/invites support CIDR (syntax: +b *!*@192.168.0.0/15)
- * 0 for no support, 1 for strict cidr support, anything else
- * for ircd specific support (nefarious only cares about first /mask) */
const char *globaltldprefix; /* TLD prefix used for Global */
unsigned maxmodes; /* Max modes to send per line */
};
@@ -636,7 +633,6 @@ enum ChannelAccess
CA_AUTOVOICE,
CA_OPDEOP, /* ChanServ commands OP and DEOP */
CA_ACCESS_LIST,
- CA_CLEAR,
CA_NOJOIN, /* Maximum */
CA_ACCESS_CHANGE,
CA_MEMO,
@@ -662,6 +658,7 @@ enum ChannelAccess
CA_BANME,
CA_BAN,
CA_TOPIC,
+ CA_MODE,
CA_INFO,
CA_AUTOOWNER,
CA_OWNER,
@@ -756,7 +753,7 @@ struct LevelInfo
enum EntryType
{
ENTRYTYPE_NONE,
- ENTRYTYPE_CIDR4,
+ ENTRYTYPE_CIDR,
ENTRYTYPE_NICK_WILD,
ENTRYTYPE_NICK,
ENTRYTYPE_USER_WILD,
@@ -767,17 +764,27 @@ enum EntryType
class Entry : public Flags<EntryType>
{
+ Anope::string mask;
+
public:
- Entry *next, *prev;
- uint32 cidr_ip; /* IP mask for CIDR matching */
- uint32 cidr_mask; /* Netmask for CIDR matching */
- Anope::string nick, user, host, mask;
-};
+ unsigned char cidr_len;
+ Anope::string nick, user, host;
-struct EList
-{
- Entry *entries;
- int32 count;
+ /** Constructor
+ * @param _host A full nick!ident@host/cidr mask
+ */
+ Entry(const Anope::string &_host);
+
+ /** Get the banned mask for this entry
+ * @return The mask
+ */
+ const Anope::string GetMask();
+
+ /** Check if this entry matches a user
+ * @param u The user
+ * @return true on match
+ */
+ bool Matches(User *u) const;
};
/*************************************************************************/
diff --git a/include/sockets.h b/include/sockets.h
index a24e346d7..c9e5bfed0 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -80,6 +80,18 @@ union CoreExport sockaddrs
void ntop(int type, const void *src);
};
+class CoreExport cidr
+{
+ sockaddrs addr;
+ Anope::string cidr_ip;
+ unsigned char cidr_len;
+ public:
+ cidr(const Anope::string &ip);
+ cidr(const Anope::string &ip, unsigned char len);
+ Anope::string mask() const;
+ bool match(sockaddrs &other);
+};
+
class SocketException : public CoreException
{
public:
diff --git a/include/users.h b/include/users.h
index 6aed13548..d9f47792f 100644
--- a/include/users.h
+++ b/include/users.h
@@ -139,6 +139,10 @@ class CoreExport User : public Extensible
*/
Anope::string GetMask() const;
+ /** Get the full display mask (nick!vident@vhost/chost)
+ */
+ Anope::string GetDisplayedMask() const;
+
/** Updates the realname of the user record.
*/
void SetRealname(const Anope::string &realname);