From 010beb52b1f3c697a07f9a130d2ed9335fe1cd98 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 3 May 2025 17:07:07 +0100 Subject: Store the setter and ts for all modes and try to restore them. This is mostly for preserving channel list mode info. --- include/account.h | 2 +- include/channels.h | 14 +++++++------- include/defs.h | 1 + include/modes.h | 23 +++++++++++++++++++---- include/modules.h | 4 ++-- include/protocol.h | 2 ++ include/users.h | 14 +++++++------- 7 files changed, 39 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/account.h b/include/account.h index be130ea95..947daeff6 100644 --- a/include/account.h +++ b/include/account.h @@ -151,7 +151,7 @@ public: /* The time this account was registered */ time_t registered = Anope::CurTime; MemoInfo memos; - std::map last_modes; + std::map last_modes; /* Nicknames registered that are grouped to this account. * for n in aliases, n->nc == this. diff --git a/include/channels.h b/include/channels.h index 9d1c5b738..155feadb2 100644 --- a/include/channels.h +++ b/include/channels.h @@ -36,7 +36,7 @@ class CoreExport Channel final static std::vector deleting; public: - typedef std::multimap ModeList; + typedef std::multimap ModeList; private: /** A map of channel modes with their parameters set on this channel */ @@ -148,10 +148,10 @@ public: /** Set a mode internally on a channel, this is not sent out to the IRCd * @param setter The setter * @param cm The mode - * @param param The param + * @param data Data about the mode. * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void SetModeInternal(MessageSource &source, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); + void SetModeInternal(MessageSource &source, ChannelMode *cm, const ModeData &data = {}, bool enforce_mlock = true); /** Remove a mode internally on a channel, this is not sent out to the IRCd * @param setter The Setter @@ -164,19 +164,19 @@ public: /** 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 data Data about the mode * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); + void SetMode(BotInfo *bi, ChannelMode *cm, const ModeData &data = {}, bool enforce_mlock = 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 data Data about the mode * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void SetMode(BotInfo *bi, const Anope::string &name, const Anope::string ¶m = "", bool enforce_mlock = true); + void SetMode(BotInfo *bi, const Anope::string &name, const ModeData &data = {}, bool enforce_mlock = true); /** Remove a mode from a channel * @param bi The client setting the modes diff --git a/include/defs.h b/include/defs.h index 2286a8e41..31de70c60 100644 --- a/include/defs.h +++ b/include/defs.h @@ -19,6 +19,7 @@ class ChanAccess; class Channel; class ChannelInfo; class ChannelStatus; +struct ModeData; struct ChanUserContainer; class ClientSocket; class Command; diff --git a/include/modes.h b/include/modes.h index db84a64fe..3052ab00b 100644 --- a/include/modes.h +++ b/include/modes.h @@ -33,6 +33,20 @@ enum ModeClass MC_USER }; +struct ModeData final +{ + Anope::string value; + Anope::string set_by; + time_t set_at; + + ModeData(const Anope::string &v = "", const Anope::string &s = "", time_t t = 0) + : value(v) + , set_by(s) + , set_at(t) + { + } +}; + /** This class is the basis of all modes in Anope */ class CoreExport Mode @@ -311,6 +325,7 @@ public: class CoreExport ModeManager final { public: + using Change = std::multimap>; /* Number of generic channel and user modes we are tracking */ static unsigned GenericChannelModes; @@ -378,18 +393,18 @@ public: * @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 + * @param data Data about the mode. */ - static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool set, const Anope::string ¶m = ""); + static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool set, const ModeData &data = {}); /** 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 + * @param data Data about the mode. */ - static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool set, const Anope::string ¶m = ""); + static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool set, const ModeData &data = {}); /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users */ diff --git a/include/modules.h b/include/modules.h index 7aaf5e2ab..03f5fe837 100644 --- a/include/modules.h +++ b/include/modules.h @@ -871,10 +871,10 @@ public: * @param c The channel * @param setter The user or server that is setting the mode * @param mode The mode - * @param param The mode param, if there is one + * @param data Data about the mode. * @return EVENT_STOP to make mlock/secureops etc checks not happen */ - virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) ATTR_NOT_NULL(2, 4) { throw NotImplementedException(); } + virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const ModeData &data) ATTR_NOT_NULL(2, 4) { throw NotImplementedException(); } /** Called when a mode is unset on a channel * @param c The channel diff --git a/include/protocol.h b/include/protocol.h index ec090090a..40312874d 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -195,8 +195,10 @@ public: */ virtual void SendSVSKill(const MessageSource &source, User *user, const Anope::string &msg); + virtual void SendMode(const MessageSource &source, Channel *chan, const ModeManager::Change &change); virtual void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector &values); + virtual void SendMode(const MessageSource &source, User *u, const ModeManager::Change &change); virtual void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector &values); /** Introduces a client to the rest of the network diff --git a/include/users.h b/include/users.h index 2a5823cc5..08fa339b2 100644 --- a/include/users.h +++ b/include/users.h @@ -39,7 +39,7 @@ class CoreExport User static std::list quitting_users; public: - typedef std::map ModeList; + typedef std::map ModeList; protected: Anope::string vident; Anope::string ident; @@ -261,9 +261,9 @@ public: /** Set a mode internally on the user, the IRCd is not informed * @param setter who/what is setting the mode * @param um The user mode - * @param Param The param, if there is one + * @param data Data about the mode. */ - void SetModeInternal(const MessageSource &setter, UserMode *um, const Anope::string ¶m = ""); + void SetModeInternal(const MessageSource &setter, UserMode *um, const ModeData &data = {}); /** Remove a mode internally on the user, the IRCd is not informed * @param setter who/what is setting the mode @@ -274,16 +274,16 @@ public: /** Set a mode on the user * @param bi The client setting the mode * @param um The user mode - * @param Param Optional param for the mode + * @param data Data about the mode */ - void SetMode(BotInfo *bi, UserMode *um, const Anope::string ¶m = ""); + void SetMode(BotInfo *bi, UserMode *um, const ModeData &data = {}); /** Set a mode on the user * @param bi The client setting the mode * @param name The mode name - * @param Param Optional param for the mode + * @param data Data about the mode */ - void SetMode(BotInfo *bi, const Anope::string &name, const Anope::string ¶m = ""); + void SetMode(BotInfo *bi, const Anope::string &name, const ModeData &data = {}); /** Remove a mode on the user * @param bi The client setting the mode -- cgit