diff options
274 files changed, 3524 insertions, 3362 deletions
diff --git a/include/access.h b/include/access.h deleted file mode 100644 index 292e95228..000000000 --- a/include/access.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#pragma once - -#include "services.h" -#include "anope.h" -#include "serialize.h" -#include "service.h" - -enum -{ - ACCESS_INVALID = -10000, - ACCESS_FOUNDER = 10001 -}; - -/* A privilege, probably configured using a privilege{} block. Most - * commands require specific privileges to be executed. The AccessProvider - * backing each ChanAccess determines whether that ChanAccess has a given - * privilege. - */ -struct CoreExport Privilege -{ - Anope::string name; - Anope::string desc; - /* Rank relative to other privileges */ - int rank; - - Privilege(const Anope::string &name, const Anope::string &desc, int rank); - bool operator==(const Privilege &other) const; -}; - -class CoreExport PrivilegeManager -{ - static std::vector<Privilege> Privileges; - public: - static void AddPrivilege(Privilege p); - static void RemovePrivilege(Privilege &p); - static Privilege *FindPrivilege(const Anope::string &name); - static std::vector<Privilege> &GetPrivileges(); - static void ClearPrivileges(); -}; - -/* A provider of access. Only used for creating ChanAccesses, as - * they contain pure virtual functions. - */ -class CoreExport AccessProvider : public Service -{ - public: - AccessProvider(Module *owner, const Anope::string &name); - virtual ~AccessProvider(); - - /** Creates a new ChanAccess entry using this provider. - * @return The new entry - */ - virtual ChanAccess *Create() = 0; - - private: - static std::list<AccessProvider *> Providers; - public: - static const std::list<AccessProvider *>& GetProviders(); -}; - -/* Represents one entry of an access list on a channel. */ -class CoreExport ChanAccess : public Serializable -{ - public: - typedef std::multimap<const ChanAccess *, const ChanAccess *> Set; - /* shows the 'path' taken to determine if an access entry matches a user - * .first are access entries checked - * .second are access entries which match - */ - typedef std::pair<Set, Set> Path; - - /* The provider that created this access entry */ - AccessProvider *provider; - /* Channel this access entry is on */ - Serialize::Reference<ChannelInfo> ci; - /* account this access entry is for, if any */ - Serialize::Reference<NickCore> nc; - Anope::string mask; - Anope::string creator; - time_t last_seen; - time_t created; - - ChanAccess(AccessProvider *p); - virtual ~ChanAccess(); - - void Serialize(Serialize::Data &data) const override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); - - /** Check if this access entry matches the given user or account - * @param u The user - * @param nc The account - * @param p The path to the access object which matches will be put here - */ - virtual bool Matches(const User *u, const NickCore *nc, Path &p) const; - - /** Check if this access entry has the given privilege. - * @param name The privilege name - */ - virtual bool HasPriv(const Anope::string &name) const = 0; - - /** Serialize the access given by this access entry into a human - * readable form. chanserv/access will return a number, chanserv/xop - * will be AOP, SOP, etc. - */ - virtual Anope::string AccessSerialize() const = 0; - - /** Unserialize this access entry from the given data. This data - * will be fetched from AccessSerialize. - */ - virtual void AccessUnserialize(const Anope::string &data) = 0; - - /* Comparison operators to other Access entries */ - virtual bool operator>(const ChanAccess &other) const; - virtual bool operator<(const ChanAccess &other) const; - bool operator>=(const ChanAccess &other) const; - bool operator<=(const ChanAccess &other) const; -}; - -/* A group of access entries. This is used commonly, for example with ChannelInfo::AccessFor, - * to show what access a user has on a channel because users can match multiple access entries. - */ -class CoreExport AccessGroup : public std::vector<ChanAccess *> -{ - public: - /* Channel these access entries are on */ - const ChannelInfo *ci; - /* Path from these entries to other entries that they depend on */ - ChanAccess::Path path; - /* Account these entries affect, if any */ - const NickCore *nc; - /* super_admin always gets all privs. founder is a special case where ci->founder == nc */ - bool super_admin, founder; - - AccessGroup(); - - /** Check if this access group has a certain privilege. Eg, it - * will check every ChanAccess entry of this group for any that - * has the given privilege. - * @param priv The privilege - * @return true if any entry has the given privilege - */ - bool HasPriv(const Anope::string &priv) const; - - /** Get the "highest" access entry from this group of entries. - * The highest entry is determined by the entry that has the privilege - * with the highest rank (see Privilege::rank). - * @return The "highest" entry - */ - const ChanAccess *Highest() const; - - /* Comparison operators to other AccessGroups */ - bool operator>(const AccessGroup &other) const; - bool operator<(const AccessGroup &other) const; - bool operator>=(const AccessGroup &other) const; - bool operator<=(const AccessGroup &other) const; -}; - diff --git a/include/account.h b/include/account.h deleted file mode 100644 index 381047ac4..000000000 --- a/include/account.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#pragma once - -#include "extensible.h" -#include "serialize.h" -#include "anope.h" -#include "memo.h" -#include "base.h" - -typedef Anope::hash_map<NickAlias *> nickalias_map; -typedef Anope::hash_map<NickCore *> nickcore_map; - -extern CoreExport Serialize::Checker<nickalias_map> NickAliasList; -extern CoreExport Serialize::Checker<nickcore_map> NickCoreList; - -/* A registered nickname. - * It matters that Base is here before Extensible (it is inherited by Serializable) - */ -class CoreExport NickAlias : public Serializable, public Extensible -{ - Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_created; - - public: - Anope::string nick; - Anope::string last_quit; - Anope::string last_realname; - /* Last usermask this nick was seen on, eg user@host */ - Anope::string last_usermask; - /* Last uncloaked usermask, requires nickserv/auspex to see */ - Anope::string last_realhost; - time_t time_registered; - time_t last_seen; - /* Account this nick is tied to. Multiple nicks can be tied to a single account. */ - Serialize::Reference<NickCore> nc; - - /** Constructor - * @param nickname The nick - * @param nickcore The nickcore for this nick - */ - NickAlias(const Anope::string &nickname, NickCore *nickcore); - ~NickAlias(); - - void Serialize(Serialize::Data &data) const override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); - - /** Set a vhost for the user - * @param ident The ident - * @param host The host - * @param creator Who created the vhost - * @param time When the vhost was craated - */ - void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime); - - /** Remove a users vhost - **/ - void RemoveVhost(); - - /** Check if the user has a vhost - * @return true or false - */ - bool HasVhost() const; - - /** Retrieve the vhost ident - * @return the ident - */ - const Anope::string &GetVhostIdent() const; - - /** Retrieve the vhost host - * @return the host - */ - const Anope::string &GetVhostHost() const; - - /** Retrieve the vhost creator - * @return the creator - */ - const Anope::string &GetVhostCreator() const; - - /** Retrieve when the vhost was created - * @return the time it was created - */ - time_t GetVhostCreated() const; - - /** Finds a registered nick - * @param nick The nick to lookup - * @return the nick, if found - */ - static NickAlias *Find(const Anope::string &nick); -}; - -/* A registered account. Each account must have a NickAlias with the same nick as the - * account's display. - * It matters that Base is here before Extensible (it is inherited by Serializable) - */ -class CoreExport NickCore : public Serializable, public Extensible -{ - /* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */ - Serialize::Checker<std::map<ChannelInfo *, int> > chanaccess; - public: - /* Name of the account. Find(display)->nc == this. */ - Anope::string display; - /* User password in form of hashm:data */ - Anope::string pass; - Anope::string email; - /* Locale name of the language of the user. Empty means default language */ - Anope::string language; - /* Access list, contains user@host masks of users who get certain privileges based - * on if NI_SECURE is set and what (if any) kill protection is enabled. */ - std::vector<Anope::string> access; - MemoInfo memos; - std::map<Anope::string, Anope::string> last_modes; - - /* Nicknames registered that are grouped to this account. - * for n in aliases, n->nc == this. - */ - Serialize::Checker<std::vector<NickAlias *> > aliases; - - /* Set if this user is a services operattor. o->ot must exist. */ - Oper *o; - - /* Unsaved data */ - - /* Number of channels registered by this account */ - uint16_t channelcount; - /* Last time an email was sent to this user */ - time_t lastmail; - /* Users online now logged into this account */ - std::list<User *> users; - - /** Constructor - * @param display The display nick - */ - NickCore(const Anope::string &nickdisplay); - ~NickCore(); - - void Serialize(Serialize::Data &data) const override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); - - /** Changes the display for this account - * @param na The new display, must be grouped to this account. - */ - void SetDisplay(const NickAlias *na); - - /** Checks whether this account is a services oper or not. - * @return True if this account is a services oper, false otherwise. - */ - virtual bool IsServicesOper() const; - - /** Add an entry to the nick's access list - * - * @param entry The nick!ident@host entry to add to the access list - * - * Adds a new entry into the access list. - */ - void AddAccess(const Anope::string &entry); - - /** Get an entry from the nick's access list by index - * - * @param entry Index in the access list vector to retrieve - * @return The access list entry of the given index if within bounds, an empty string if the vector is empty or the index is out of bounds - * - * Retrieves an entry from the access list corresponding to the given index. - */ - Anope::string GetAccess(unsigned entry) const; - - /** Get the number of entries on the access list for this account. - */ - unsigned GetAccessCount() const; - - /** Find an entry in the nick's access list - * - * @param entry The nick!ident@host entry to search for - * @return True if the entry is found in the access list, false otherwise - * - * Search for an entry within the access list. - */ - bool FindAccess(const Anope::string &entry); - - /** Erase an entry from the nick's access list - * - * @param entry The nick!ident@host entry to remove - * - * Removes the specified access list entry from the access list. - */ - void EraseAccess(const Anope::string &entry); - - /** Clears the entire nick's access list - * - * Deletes all the memory allocated in the access list vector and then clears the vector. - */ - void ClearAccess(); - - /** Is the given user on this accounts access list? - * - * @param u The user - * - * @return true if the user is on the access list - */ - bool IsOnAccess(const User *u) const; - - /** Finds an account - * @param nick The account name to find - * @return The account, if it exists - */ - static NickCore* Find(const Anope::string &nick); - - void AddChannelReference(ChannelInfo *ci); - void RemoveChannelReference(ChannelInfo *ci); - void GetChannelReferences(std::deque<ChannelInfo *> &queue); -}; - -/* A request to check if an account/password is valid. These can exist for - * extended periods due to the time some authentication modules take. - */ -class CoreExport IdentifyRequest -{ - /* Owner of this request, used to cleanup requests if a module is unloaded - * while a reqyest us pending */ - Module *owner; - Anope::string account; - Anope::string password; - - std::set<Module *> holds; - bool dispatched; - bool success; - - static std::set<IdentifyRequest *> Requests; - - protected: - IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass); - virtual ~IdentifyRequest(); - - public: - /* One of these is called when the request goes through */ - virtual void OnSuccess() = 0; - virtual void OnFail() = 0; - - const Anope::string &GetAccount() const { return account; } - const Anope::string &GetPassword() const { return password; } - - /* Holds this request. When a request is held it must be Released later - * for the request to complete. Multiple modules may hold a request at any time, - * but the request is not complete until every module has released it. If you do not - * require holding this (eg, your password check is done in this thread and immediately) - * then you don't need to hold the request before Successing it. - * @param m The module holding this request - */ - void Hold(Module *m); - - /** Releases a held request - * @param m The module releaseing the hold - */ - void Release(Module *m); - - /** Called by modules when this IdentifyRequest has successeded successfully. - * If this request is behind held it must still be Released after calling this. - * @param m The module confirming authentication - */ - void Success(Module *m); - - /** Used to either finalize this request or marks - * it as dispatched and begins waiting for the module(s) - * that have holds to finish. - */ - void Dispatch(); - - static void ModuleUnload(Module *m); -}; diff --git a/include/anope.h b/include/anope.h index bb20299e4..845a2b1fb 100644 --- a/include/anope.h +++ b/include/anope.h @@ -441,13 +441,13 @@ namespace Anope */ extern CoreExport void Unhex(const string &src, string &dest); extern CoreExport void Unhex(const string &src, char *dest, size_t sz); - + /** Base 64 encode a string * @param src The string to encode * @param target Where the encoded string is placed */ extern CoreExport void B64Encode(const string &src, string &target); - + /** Base 64 decode a string * @param src The base64 encoded string * @param target The plain text result @@ -502,21 +502,21 @@ namespace Anope * @param nc The account to use language settings for to translate this string, if applicable * @return A human readable string, eg "1 minute" */ - extern CoreExport Anope::string Duration(time_t seconds, const NickCore *nc = NULL); + extern CoreExport Anope::string Duration(time_t seconds, const NickServ::Account *nc = NULL); /** Generates a human readable string of type "expires in ..." * @param expires time in seconds * @param nc The account to use language settings for to translate this string, if applicable * @return A human readable string, eg "expires in 5 days" */ - extern CoreExport Anope::string Expires(time_t seconds, const NickCore *nc = NULL); + extern CoreExport Anope::string Expires(time_t seconds, const NickServ::Account *nc = NULL); /** Converts a time in seconds (epoch) to a human readable format. * @param t The time * @param nc The account to use language settings for to translate this string, if applicable * @param short_output If true, the output is just a date (eg, "Apr 12 20:18:22 2009 MSD"), else it includes the date and how long ago/from now that date is, (eg "Apr 12 20:18:22 2009 MSD (1313 days, 9 hours, 32 minutes ago)" */ - extern CoreExport Anope::string strftime(time_t t, const NickCore *nc = NULL, bool short_output = false); + extern CoreExport Anope::string strftime(time_t t, const NickServ::Account *nc = NULL, bool short_output = false); /** Normalize buffer, stripping control characters and colors * @param A string to be parsed for control and color codes diff --git a/include/bots.h b/include/bots.h index 353be89cb..9a2c5d237 100644 --- a/include/bots.h +++ b/include/bots.h @@ -15,7 +15,7 @@ #include "commands.h" -typedef Anope::map<BotInfo *> botinfo_map; +typedef Anope::hash_map<BotInfo *> botinfo_map; extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID; @@ -23,7 +23,7 @@ extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID; class CoreExport BotInfo : public User, public Serializable { /* Channels this bot is assigned to */ - Serialize::Checker<std::set<ChannelInfo *> > channels; + Serialize::Checker<std::set<ChanServ::Channel *> > channels; public: time_t created; /* Last time this bot said something (via privmsg) */ @@ -68,19 +68,19 @@ class CoreExport BotInfo : public User, public Serializable /** Return the channels this bot is assigned to */ - const std::set<ChannelInfo *> &GetChannels() const; + const std::set<ChanServ::Channel *> &GetChannels() const; /** Assign this bot to a given channel, removing the existing assigned bot if one exists. * @param u The user assigning the bot, or NULL * @param ci The channel registration to assign the bot to. */ - void Assign(User *u, ChannelInfo *ci); + void Assign(User *u, ChanServ::Channel *ci); /** Remove this bot from a given channel. * @param u The user requesting the unassign, or NULL. * @param ci The channel registration to remove the bot from. */ - void UnAssign(User *u, ChannelInfo *ci); + void UnAssign(User *u, ChanServ::Channel *ci); /** Get the number of channels this bot is assigned to */ diff --git a/include/channels.h b/include/channels.h index e676bb924..3deadce5b 100644 --- a/include/channels.h +++ b/include/channels.h @@ -42,7 +42,7 @@ class CoreExport Channel : public Base, public Extensible /* Channel name */ Anope::string name; /* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */ - Serialize::Reference<ChannelInfo> ci; + Serialize::Reference<ChanServ::Channel> ci; /* When the channel was created */ time_t creation_time; /* If the channel has just been created in a netjoin */ @@ -163,7 +163,7 @@ class CoreExport Channel : public Base, public Extensible * @param param Optional param arg for 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(User *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); /** * Set a mode on a channel @@ -172,7 +172,7 @@ class CoreExport Channel : public Base, public Extensible * @param param Optional param arg for 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(User *bi, const Anope::string &name, const Anope::string ¶m = "", bool enforce_mlock = true); /** Remove a mode from a channel * @param bi The client setting the modes @@ -180,7 +180,7 @@ class CoreExport Channel : public Base, public Extensible * @param param Optional param arg for the mode * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); + void RemoveMode(User *bi, ChannelMode *cm, const Anope::string ¶m = "", bool enforce_mlock = true); /** * Remove a mode from a channel @@ -189,7 +189,7 @@ class CoreExport Channel : public Base, public Extensible * @param param Optional param arg for the mode * @param enforce_mlock true if mlocks should be enforced, false to override mlock */ - void RemoveMode(BotInfo *bi, const Anope::string &name, const Anope::string ¶m = "", bool enforce_mlock = true); + void RemoveMode(User *bi, const Anope::string &name, const Anope::string ¶m = "", bool enforce_mlock = true); /** Get a modes parameter for the channel * @param name The mode @@ -203,7 +203,7 @@ class CoreExport Channel : public Base, public Extensible * @param enforce_mlock Should mlock be enforced on this mode change * @param cmodes The modes to set */ - void SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...); + void SetModes(User *bi, bool enforce_mlock, const char *cmodes, ...); /** Set a string of modes internally on a channel * @param source The setter @@ -223,8 +223,9 @@ class CoreExport Channel : public Base, public Extensible * @param source The sender of the kick * @param nick The nick being kicked * @param reason The reason for the kick + * @return true if the kick was scucessful, false if a module blocked the kick or was otherwise unsuccessful */ - void KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason); + bool KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason); /** Kick a user from the channel * @param bi The sender, can be NULL for the service bot for this channel @@ -232,7 +233,7 @@ class CoreExport Channel : public Base, public Extensible * @param reason The reason for the kick * @return true if the kick was scucessful, false if a module blocked the kick */ - bool Kick(BotInfo *bi, User *u, const char *reason = NULL, ...); + bool Kick(User *bi, User *u, const char *reason = NULL, ...); /** Get all modes set on this channel, excluding status modes. * @return a map of modes and their optional parameters. diff --git a/include/commands.h b/include/commands.h index 2be64d00d..ac79267ae 100644 --- a/include/commands.h +++ b/include/commands.h @@ -45,7 +45,7 @@ struct CommandInfo struct CoreExport CommandReply { virtual ~CommandReply() { } - virtual void SendMessage(BotInfo *source, const Anope::string &msg) = 0; + virtual void SendMessage(const MessageSource &, const Anope::string &msg) anope_abstract; }; /* The source for a command */ @@ -57,7 +57,7 @@ class CoreExport CommandSource Reference<User> u; public: /* The account executing the command */ - Reference<NickCore> nc; + Reference<NickServ::Account> nc; /* Where the reply should go */ CommandReply *reply; /* Channel the command was executed on (fantasy) */ @@ -69,13 +69,13 @@ class CoreExport CommandSource /* The permission of the command being executed */ Anope::string permission; - CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply, BotInfo *bi); + CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *reply, BotInfo *bi); const Anope::string &GetNick() const; User *GetUser(); - NickCore *GetAccount(); - AccessGroup AccessFor(ChannelInfo *ci); - bool IsFounder(ChannelInfo *ci); + NickServ::Account *GetAccount(); + ChanServ::AccessGroup AccessFor(ChanServ::Channel *ci); + bool IsFounder(ChanServ::Channel *ci); void Reply(const char *message, ...); void Reply(const Anope::string &message); diff --git a/include/config.h b/include/config.h index 903c41120..3d0133409 100644 --- a/include/config.h +++ b/include/config.h @@ -12,8 +12,6 @@ #pragma once -#include "account.h" -#include "regchannel.h" #include "users.h" #include "opertype.h" #include <stack> diff --git a/include/defs.h b/include/defs.h index b53e512d6..4c1e9ce91 100644 --- a/include/defs.h +++ b/include/defs.h @@ -11,13 +11,16 @@ */ -class AccessGroup; class AutoKick; class BotInfo; -class ChanAccess; class Channel; -class ChannelInfo; class ChannelStatus; +namespace ChanServ +{ + class AccessGroup; + class ChanAccess; + class Channel; +} struct ChanUserContainer; class ClientSocket; class Command; @@ -25,16 +28,24 @@ class CommandSource; namespace Configuration { struct Conf; } class ConnectionSocket; class Entry; -class IdentifyRequest; class InfoFormatter; class IRCDProto; class ListenSocket; class Log; -class Memo; +class LogInfo; +namespace NickServ +{ + class Account; + class Nick; + class IdentifyRequest; +} +namespace MemoServ +{ + class Memo; + struct MemoInfo; +} class MessageSource; class Module; -class NickAlias; -class NickCore; class OperType; class ReferenceBase; class Regex; @@ -47,7 +58,6 @@ class XLine; class XLineManager; struct BadWord; struct Exception; -struct MemoInfo; struct ModeLock; struct Oper; namespace SASL { struct Message; } diff --git a/include/event.h b/include/event.h index aab854750..83d5a79e1 100644 --- a/include/event.h +++ b/include/event.h @@ -147,8 +147,9 @@ namespace Event * @param source The kicker * @param cu The user, channel, and status of the user being kicked * @param kickmsg The reason for the kick. + * @return EVENT_STOP to stop the kick, which can only be done if source is 'Me' or from me */ - virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) anope_abstract; + virtual EventReturn OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) anope_abstract; }; extern CoreExport EventHandlers<PreUserKicked> OnPreUserKicked; @@ -173,7 +174,7 @@ namespace Event * @param bi The bot being assigned. * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the assign. */ - virtual EventReturn OnPreBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) anope_abstract; + virtual EventReturn OnPreBotAssign(User *sender, ChanServ::Channel *ci, BotInfo *bi) anope_abstract; }; extern CoreExport EventHandlers<PreBotAssign> OnPreBotAssign; @@ -181,7 +182,7 @@ namespace Event { /** Called when a bot is assigned ot a channel */ - virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) anope_abstract; + virtual void OnBotAssign(User *sender, ChanServ::Channel *ci, BotInfo *bi) anope_abstract; }; extern CoreExport EventHandlers<BotAssign> OnBotAssign; @@ -192,7 +193,7 @@ namespace Event * @param ci The channel the bot is being removed from * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the unassign. */ - virtual EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) anope_abstract; + virtual EventReturn OnBotUnAssign(User *sender, ChanServ::Channel *ci) anope_abstract; }; extern CoreExport EventHandlers<BotUnAssign> OnBotUnAssign; @@ -297,19 +298,6 @@ namespace Event }; extern CoreExport EventHandlers<DelBot> OnDelBot; - struct CoreExport BotKick : Events - { - /** Called before a bot kicks a user - * @param bi The bot sending the kick - * @param c The channel the user is being kicked on - * @param u The user being kicked - * @param reason The reason - * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it - */ - virtual EventReturn OnBotKick(BotInfo *bi, Channel *c, User *u, const Anope::string &reason) anope_abstract; - }; - extern CoreExport EventHandlers<BotKick> OnBotKick; - struct CoreExport PrePartChannel : Events { /** Called before a user parts a channel @@ -492,7 +480,7 @@ namespace Event * @param source The source of the command * @param access The access entry that was removed */ - virtual void OnAccessDel(ChannelInfo *ci, CommandSource &source, ChanAccess *access) anope_abstract; + virtual void OnAccessDel(ChanServ::Channel *ci, CommandSource &source, ChanServ::ChanAccess *access) anope_abstract; }; extern CoreExport EventHandlers<AccessDel> OnAccessDel; @@ -503,7 +491,7 @@ namespace Event * @param source The source of the command * @param access The access changed */ - virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) anope_abstract; + virtual void OnAccessAdd(ChanServ::Channel *ci, CommandSource &source, ChanServ::ChanAccess *access) anope_abstract; }; extern CoreExport EventHandlers<AccessAdd> OnAccessAdd; @@ -513,7 +501,7 @@ namespace Event * @param ci The channel * @param u The user who cleared the access */ - virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) anope_abstract; + virtual void OnAccessClear(ChanServ::Channel *ci, CommandSource &source) anope_abstract; }; extern CoreExport EventHandlers<AccessClear> OnAccessClear; @@ -522,7 +510,7 @@ namespace Event /** Called when a channel is registered * @param ci The channel */ - virtual void OnChanRegistered(ChannelInfo *ci) anope_abstract; + virtual void OnChanRegistered(ChanServ::Channel *ci) anope_abstract; }; extern CoreExport EventHandlers<ChanRegistered> OnChanRegistered; @@ -532,7 +520,7 @@ namespace Event /** Called when a channel is being created, for any reason * @param ci The channel */ - virtual void OnCreateChan(ChannelInfo *ci) anope_abstract; + virtual void OnCreateChan(ChanServ::Channel *ci) anope_abstract; }; extern CoreExport EventHandlers<CreateChan> OnCreateChan; @@ -541,7 +529,7 @@ namespace Event /** Called when a channel is being deleted, for any reason * @param ci The channel */ - virtual void OnDelChan(ChannelInfo *ci) anope_abstract; + virtual void OnDelChan(ChanServ::Channel *ci) anope_abstract; }; extern CoreExport EventHandlers<DelChan> OnDelChan; @@ -586,7 +574,7 @@ namespace Event * @param priv The privilege being checked for * @return EVENT_ALLOW for yes, EVENT_STOP to stop all processing */ - virtual EventReturn OnCheckPriv(const ChanAccess *access, const Anope::string &priv) anope_abstract; + virtual EventReturn OnCheckPriv(const ChanServ::ChanAccess *access, const Anope::string &priv) anope_abstract; }; extern CoreExport EventHandlers<CheckPriv> OnCheckPriv; @@ -597,7 +585,7 @@ namespace Event * @param priv The privilege * @return MOD_ALLOW to allow, MOD_STOP to stop */ - virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) anope_abstract; + virtual EventReturn OnGroupCheckPriv(const ChanServ::AccessGroup *group, const Anope::string &priv) anope_abstract; }; extern CoreExport EventHandlers<GroupCheckPriv> OnGroupCheckPriv; @@ -633,7 +621,7 @@ namespace Event /** Called on delnick() * @ param na pointer to the nickalias */ - virtual void OnDelNick(NickAlias *na) anope_abstract; + virtual void OnDelNick(NickServ::Nick *na) anope_abstract; }; extern CoreExport EventHandlers<DelNick> OnDelNick; @@ -642,35 +630,35 @@ namespace Event /** Called when a nickcore is created * @param nc The nickcore */ - virtual void OnNickCoreCreate(NickCore *nc) anope_abstract; + virtual void OnNickCoreCreate(NickServ::Account *nc) anope_abstract; }; extern CoreExport EventHandlers<NickCoreCreate> OnNickCoreCreate; struct CoreExport DelCore : Events { /** Called on delcore() - * @param nc pointer to the NickCore + * @param nc pointer to the NickServ::Account */ - virtual void OnDelCore(NickCore *nc) anope_abstract; + virtual void OnDelCore(NickServ::Account *nc) anope_abstract; }; extern CoreExport EventHandlers<DelCore> OnDelCore; struct CoreExport ChangeCoreDisplay : Events { /** Called on change_core_display() - * @param nc pointer to the NickCore + * @param nc pointer to the NickServ::Account * @param newdisplay the new display */ - virtual void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) anope_abstract; + virtual void OnChangeCoreDisplay(NickServ::Account *nc, const Anope::string &newdisplay) anope_abstract; }; extern CoreExport EventHandlers<ChangeCoreDisplay> OnChangeCoreDisplay; struct CoreExport NickClearAccess : Events { - /** called from NickCore::ClearAccess() - * @param nc pointer to the NickCore + /** called from NickServ::Account::ClearAccess() + * @param nc pointer to the NickServ::Account */ - virtual void OnNickClearAccess(NickCore *nc) anope_abstract; + virtual void OnNickClearAccess(NickServ::Account *nc) anope_abstract; }; extern CoreExport EventHandlers<NickClearAccess> OnNickClearAccess; @@ -680,17 +668,17 @@ namespace Event * @param nc The nick * @param entry The entry */ - virtual void OnNickAddAccess(NickCore *nc, const Anope::string &entry) anope_abstract; + virtual void OnNickAddAccess(NickServ::Account *nc, const Anope::string &entry) anope_abstract; }; extern CoreExport EventHandlers<NickAddAccess> OnNickAddAccess; struct CoreExport NickEraseAccess : Events { - /** Called from NickCore::EraseAccess() - * @param nc pointer to the NickCore + /** Called from NickServ::Account::EraseAccess() + * @param nc pointer to the NickServ::Account * @param entry The access mask */ - virtual void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) anope_abstract; + virtual void OnNickEraseAccess(NickServ::Account *nc, const Anope::string &entry) anope_abstract; }; extern CoreExport EventHandlers<NickEraseAccess> OnNickEraseAccess; @@ -702,7 +690,7 @@ namespace Event * @param u The user trying to identify, if applicable. * @param req The login request */ - virtual void OnCheckAuthentication(User *u, IdentifyRequest *req) anope_abstract; + virtual void OnCheckAuthentication(User *u, NickServ::IdentifyRequest *req) anope_abstract; }; extern CoreExport EventHandlers<CheckAuthentication> OnCheckAuthentication; @@ -741,7 +729,7 @@ namespace Event /** Called when a vhost is set * @param na The nickalias of the vhost */ - virtual void OnSetVhost(NickAlias *na) anope_abstract; + virtual void OnSetVhost(NickServ::Nick *na) anope_abstract; }; extern CoreExport EventHandlers<SetVhost> OnSetVhost; @@ -943,7 +931,7 @@ namespace Event * @param give_modes If giving modes is desired * @param take_modes If taking modes is desired */ - virtual void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) anope_abstract; + virtual void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) anope_abstract; }; extern CoreExport EventHandlers<SetCorrectModes> OnSetCorrectModes; diff --git a/include/language.h b/include/language.h index 041f90b11..55726b8d6 100644 --- a/include/language.h +++ b/include/language.h @@ -24,7 +24,7 @@ namespace Language * and we detect a language file exists for at least one of the supported * languages for the module, then we add the module's domain (its name) * here. - * + * * When strings are translated they are checked against all domains. */ extern std::vector<Anope::string> Domains; @@ -52,7 +52,7 @@ namespace Language * @param string A string to translate * @return The translated string if count, else the original string */ - extern CoreExport const char *Translate(const NickCore *nc, const char *string); + extern CoreExport const char *Translate(const NickServ::Account *nc, const char *string); /** Translatesa string to the given language. * @param lang The language to translate to diff --git a/include/lists.h b/include/lists.h index 36e5ae30d..c40d97e7d 100644 --- a/include/lists.h +++ b/include/lists.h @@ -66,11 +66,11 @@ class CoreExport ListFormatter public: typedef std::map<Anope::string, Anope::string> ListEntry; private: - NickCore *nc; + NickServ::Account *nc; std::vector<Anope::string> columns; std::vector<ListEntry> entries; public: - ListFormatter(NickCore *nc); + ListFormatter(NickServ::Account *nc); ListFormatter &AddColumn(const Anope::string &name); void AddEntry(const ListEntry &entry); bool IsEmpty() const; @@ -81,11 +81,11 @@ class CoreExport ListFormatter */ class CoreExport InfoFormatter { - NickCore *nc; + NickServ::Account *nc; std::vector<std::pair<Anope::string, Anope::string> > replies; unsigned longest; public: - InfoFormatter(NickCore *nc); + InfoFormatter(NickServ::Account *nc); void Process(std::vector<Anope::string> &); Anope::string &operator[](const Anope::string &key); void AddOption(const Anope::string &opt); diff --git a/include/logger.h b/include/logger.h index 73180e66e..8ed316e94 100644 --- a/include/logger.h +++ b/include/logger.h @@ -57,7 +57,7 @@ class CoreExport Log /* For commands, the user executing the command, but might not always exist */ User *u; /* For commands, the account executing the command, but will not always exist */ - NickCore *nc; + NickServ::Account *nc; /* For commands, the command being executed */ Command *c; /* For commands, the command source */ @@ -65,7 +65,7 @@ class CoreExport Log /* Used for LOG_CHANNEL */ Channel *chan; /* For commands, the channel the command was executed on, will not always exist */ - const ChannelInfo *ci; + const ChanServ::Channel *ci; /* For LOG_SERVER */ Server *s; /* For LOG_MODULE */ @@ -78,7 +78,7 @@ class CoreExport Log Log(LogType type = LOG_NORMAL, const Anope::string &category = "", BotInfo *bi = NULL); /* LOG_COMMAND/OVERRIDE/ADMIN */ - Log(LogType type, CommandSource &source, Command *c, ChannelInfo *ci = NULL); + Log(LogType type, CommandSource &source, Command *c, ChanServ::Channel *ci = NULL); /* LOG_CHANNEL */ Log(User *u, Channel *c, const Anope::string &category = ""); diff --git a/include/mail.h b/include/mail.h index 2f59b5000..7ef5a265e 100644 --- a/include/mail.h +++ b/include/mail.h @@ -19,8 +19,8 @@ namespace Mail { - extern CoreExport bool Send(User *from, NickCore *to, BotInfo *service, const Anope::string &subject, const Anope::string &message); - extern CoreExport bool Send(NickCore *to, const Anope::string &subject, const Anope::string &message); + extern CoreExport bool Send(User *from, NickServ::Account *to, BotInfo *service, const Anope::string &subject, const Anope::string &message); + extern CoreExport bool Send(NickServ::Account *to, const Anope::string &subject, const Anope::string &message); extern CoreExport bool Validate(const Anope::string &email); /* A email message being sent */ diff --git a/include/memo.h b/include/memo.h deleted file mode 100644 index 103f00ca1..000000000 --- a/include/memo.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#pragma once - -#include "anope.h" -#include "serialize.h" - -class CoreExport Memo : public Serializable -{ - public: - bool unread; - bool receipt; - Memo(); - ~Memo(); - - void Serialize(Serialize::Data &data) const override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); - - Anope::string owner; - /* When it was sent */ - time_t time; - Anope::string sender; - Anope::string text; -}; - -/* Memo info structures. Since both nicknames and channels can have memos, - * we encapsulate memo data in a MemoInfo to make it easier to handle. - */ -struct CoreExport MemoInfo -{ - int16_t memomax; - Serialize::Checker<std::vector<Memo *> > memos; - std::vector<Anope::string> ignores; - - MemoInfo(); - Memo *GetMemo(unsigned index) const; - unsigned GetIndex(Memo *m) const; - void Del(unsigned index); - bool HasIgnore(User *u); - - static MemoInfo *GetMemoInfo(const Anope::string &targ, bool &is_chan); -}; - diff --git a/include/messages.h b/include/messages.h index 070fcb84f..58d32aaf5 100644 --- a/include/messages.h +++ b/include/messages.h @@ -23,21 +23,21 @@ namespace Message struct CoreExport Away : IRCDMessage { Away(Module *creator, const Anope::string &mname = "AWAY") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Capab : IRCDMessage { Capab(Module *creator, const Anope::string &mname = "CAPAB") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Error : IRCDMessage { Error(Module *creator, const Anope::string &mname = "ERROR") : IRCDMessage(creator, mname, 1) { } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; @@ -47,15 +47,15 @@ namespace Message void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Join : IRCDMessage { Join(Module *creator, const Anope::string &mname = "JOIN") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; - + typedef std::pair<ChannelStatus, User *> SJoinUser; - + /** Handle a SJOIN. * @param source The source of the SJOIN * @param chan The channel the users are joining to @@ -65,18 +65,18 @@ namespace Message */ static void SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users); }; - + struct CoreExport Kick : IRCDMessage { Kick(Module *creator, const Anope::string &mname = "KICK") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Kill : IRCDMessage { Kill(Module *creator, const Anope::string &mname = "KILL") : IRCDMessage(creator, mname, 2) { } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; @@ -86,14 +86,14 @@ namespace Message void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport MOTD : IRCDMessage { MOTD(Module *creator, const Anope::string &mname = "MOTD") : IRCDMessage(creator, mname, 1) { } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Notice : IRCDMessage { Notice(Module *creator, const Anope::string &mname = "NOTICE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } @@ -104,70 +104,70 @@ namespace Message struct CoreExport Part : IRCDMessage { Part(Module *creator, const Anope::string &mname = "PART") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Ping : IRCDMessage { Ping(Module *creator, const Anope::string &mname = "PING") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Privmsg : IRCDMessage { Privmsg(Module *creator, const Anope::string &mname = "PRIVMSG") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Quit : IRCDMessage { Quit(Module *creator, const Anope::string &mname = "QUIT") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport SQuit : IRCDMessage { SQuit(Module *creator, const Anope::string &mname = "SQUIT") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Stats : IRCDMessage { Stats(Module *creator, const Anope::string &mname = "STATS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Time : IRCDMessage { Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Topic : IRCDMessage { Topic(Module *creator, const Anope::string &mname = "TOPIC") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Version : IRCDMessage { Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; - + struct CoreExport Whois : IRCDMessage { Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override; }; diff --git a/include/modes.h b/include/modes.h index 279d1dbc1..e13470669 100644 --- a/include/modes.h +++ b/include/modes.h @@ -179,7 +179,7 @@ class CoreExport ChannelModeStatus : public ChannelMode /** constructor * @param name The mode name * @param mc The mode char - * @param msymbol The symbol for the mode, eg @ % + * @param msymbol The symbol for the mode, eg @ % * @param mlevel A level for the mode, which is usually determined by the PREFIX capab */ ChannelModeStatus(const Anope::string &name, char mc, char msymbol, short mlevel); @@ -333,7 +333,7 @@ class CoreExport ModeManager * @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 Anope::string ¶m = ""); + static void StackerAdd(User *bi, Channel *c, ChannelMode *cm, bool set, const Anope::string ¶m = ""); /** Add a mode to the stacker to be set on a user * @param bi The client to set the modes from @@ -342,7 +342,7 @@ class CoreExport ModeManager * @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 Anope::string ¶m = ""); + static void StackerAdd(User *bi, User *u, UserMode *um, bool set, const Anope::string ¶m = ""); /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users */ diff --git a/include/module.h b/include/module.h index 0efbb7334..bb7f1c815 100644 --- a/include/module.h +++ b/include/module.h @@ -11,8 +11,6 @@ #pragma once -#include "access.h" -#include "account.h" #include "anope.h" #include "base.h" #include "bots.h" @@ -26,13 +24,11 @@ #include "lists.h" #include "logger.h" #include "mail.h" -#include "memo.h" #include "messages.h" #include "modes.h" #include "modules.h" #include "opertype.h" #include "protocol.h" -#include "regchannel.h" #include "serialize.h" #include "servers.h" #include "service.h" @@ -44,3 +40,8 @@ #include "uplink.h" #include "users.h" #include "xline.h" + +#include "modules/chanserv.h" +#include "modules/nickserv.h" +#include "modules/botserv.h" +#include "modules/memoserv.h" diff --git a/include/modules/botserv.h b/include/modules/botserv.h new file mode 100644 index 000000000..09183b53a --- /dev/null +++ b/include/modules/botserv.h @@ -0,0 +1,22 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#pragma once + +namespace BotServ +{ + class BotServService : public Service + { + public: + BotServService(Module *m) : Service(m, "BotServService", "BotServ") + { + } + + }; + static ServiceReference<BotServService> service("BotServService", "BotServ"); +} diff --git a/include/modules/bs_badwords.h b/include/modules/bs_badwords.h index 390e502c0..ad75aa5bb 100644 --- a/include/modules/bs_badwords.h +++ b/include/modules/bs_badwords.h @@ -79,13 +79,13 @@ namespace Event * @param ci The channel * @param bw The badword */ - virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) anope_abstract; + virtual void OnBadWordAdd(ChanServ::Channel *ci, const BadWord *bw) anope_abstract; /** Called before a badword is deleted from a channel * @param ci The channel * @param bw The badword */ - virtual void OnBadWordDel(ChannelInfo *ci, const BadWord *bw) anope_abstract; + virtual void OnBadWordDel(ChanServ::Channel *ci, const BadWord *bw) anope_abstract; }; } diff --git a/include/modules/bs_info.h b/include/modules/bs_info.h index c9f360dfc..72180e312 100644 --- a/include/modules/bs_info.h +++ b/include/modules/bs_info.h @@ -13,7 +13,7 @@ namespace Event { /** Called when a user uses botserv/info on a bot or channel. */ - virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) anope_abstract; + virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) anope_abstract; }; extern CoreExport EventHandlers<BotInfoEvent> OnBotInfo; } diff --git a/include/modules/bs_kick.h b/include/modules/bs_kick.h index a783b6017..fed90346c 100644 --- a/include/modules/bs_kick.h +++ b/include/modules/bs_kick.h @@ -42,7 +42,7 @@ struct KickerData public: virtual ~KickerData() { } - virtual void Check(ChannelInfo *ci) = 0; + virtual void Check(ChanServ::Channel *ci) = 0; }; namespace Event @@ -54,7 +54,7 @@ namespace Event * @param ci Channel the ban is placed on * @param mask The mask being banned */ - virtual void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) anope_abstract; + virtual void OnBotBan(User *u, ChanServ::Channel *ci, const Anope::string &mask) anope_abstract; }; } diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h index 37a96e9e7..9170ea2d2 100644 --- a/include/modules/chanserv.h +++ b/include/modules/chanserv.h @@ -6,8 +6,89 @@ * */ +#pragma once + +#include "event.h" +#include "channels.h" +#include "modules/nickserv.h" +#include "modules/memoserv.h" +#include "bots.h" + namespace ChanServ { + static struct + { + Anope::string name; + Anope::string desc; + } descriptions[] = { + {"ACCESS_CHANGE", _("Allowed to modify the access list")}, + {"ACCESS_LIST", _("Allowed to view the access list")}, + {"AKICK", _("Allowed to use the AKICK command")}, + {"ASSIGN", _("Allowed to assign/unassign a bot")}, + {"AUTOHALFOP", _("Automatic halfop upon join")}, + {"AUTOOP", _("Automatic channel operator status upon join")}, + {"AUTOOWNER", _("Automatic owner upon join")}, + {"AUTOPROTECT", _("Automatic protect upon join")}, + {"AUTOVOICE", _("Automatic voice on join")}, + {"BADWORDS", _("Allowed to modify channel badwords list")}, + {"BAN", _("Allowed to ban users")}, + {"FANTASIA", _("Allowed to use fantasy commands")}, + {"FOUNDER", _("Allowed to issue commands restricted to channel founders")}, + {"GETKEY", _("Allowed to use GETKEY command")}, + {"GREET", _("Greet message displayed on join")}, + {"HALFOP", _("Allowed to (de)halfop users")}, + {"HALFOPME", _("Allowed to (de)halfop him/herself")}, + {"INFO", _("Allowed to get full INFO output")}, + {"INVITE", _("Allowed to use the INVITE command")}, + {"KICK", _("Allowed to use the KICK command")}, + {"MEMO", _("Allowed to read channel memos")}, + {"MODE", _("Allowed to use the MODE command")}, + {"NOKICK", _("Prevents users being kicked by Services")}, + {"OP", _("Allowed to (de)op users")}, + {"OPME", _("Allowed to (de)op him/herself")}, + {"OWNER", _("Allowed to (de)owner users")}, + {"OWNERME", _("Allowed to (de)owner him/herself")}, + {"PROTECT", _("Allowed to (de)protect users")}, + {"PROTECTME", _("Allowed to (de)protect him/herself")}, + {"SAY", _("Allowed to use SAY and ACT commands")}, + {"SET", _("Allowed to set channel settings")}, + {"SIGNKICK", _("No signed kick when SIGNKICK LEVEL is used")}, + {"TOPIC", _("Allowed to change channel topics")}, + {"UNBAN", _("Allowed to unban users")}, + {"VOICE", _("Allowed to (de)voice users")}, + {"VOICEME", _("Allowed to (de)voice him/herself")} + }; + + /* A privilege, probably configured using a privilege{} block. Most + * commands require specific privileges to be executed. The AccessProvider + * backing each ChanAccess determines whether that ChanAccess has a given + * privilege. + */ + struct CoreExport Privilege + { + Anope::string name; + Anope::string desc; + /* Rank relative to other privileges */ + int rank; + + Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r) + { + if (this->desc.empty()) + for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) + if (descriptions[j].name.equals_ci(name)) + this->desc = descriptions[j].desc; + } + + bool operator==(const Privilege &other) const + { + return this->name.equals_ci(other.name); + } + }; + + class Channel; + using registered_channel_map = Anope::hash_map<Channel *>; + + class AccessProvider; class ChanServService : public Service { public: @@ -15,13 +96,38 @@ namespace ChanServ { } + virtual Channel *Create(const Anope::string &name) anope_abstract; + virtual Channel *Create(const Channel &) anope_abstract; + virtual Channel *Find(const Anope::string &name) anope_abstract; + virtual registered_channel_map& GetChannels() anope_abstract; + /* Have ChanServ hold the channel, that is, join and set +nsti and wait * for a few minutes so no one can join or rejoin. */ - virtual void Hold(Channel *c) anope_abstract; + virtual void Hold(::Channel *c) anope_abstract; + + virtual void AddPrivilege(Privilege p) anope_abstract; + virtual void RemovePrivilege(Privilege &p) anope_abstract; + virtual Privilege *FindPrivilege(const Anope::string &name) anope_abstract; + virtual std::vector<Privilege> &GetPrivileges() anope_abstract; + virtual void ClearPrivileges() anope_abstract; + + virtual std::vector<AccessProvider *>& GetProviders() anope_abstract; + + virtual void Destruct(ChanAccess *) anope_abstract; + virtual void Serialize(const ChanAccess *, Serialize::Data &data) anope_abstract; + //XXX + typedef std::multimap<const ChanAccess *, const ChanAccess *> Set; + typedef std::pair<Set, Set> Path; + virtual bool Matches(const ChanAccess *, const User *u, const NickServ::Account *acc, Path &p) anope_abstract; }; static ServiceReference<ChanServService> service("ChanServService", "ChanServ"); + inline Channel *Find(const Anope::string name) + { + return service ? service->Find(name) : nullptr; + } + namespace Event { struct CoreExport PreChanExpire : Events @@ -30,7 +136,7 @@ namespace ChanServ * @param ci The channel * @param expire Set to true to allow the chan to expire */ - virtual void OnPreChanExpire(ChannelInfo *ci, bool &expire) anope_abstract; + virtual void OnPreChanExpire(Channel *ci, bool &expire) anope_abstract; }; static EventHandlersReference<PreChanExpire> OnPreChanExpire("OnPreChanExpire"); @@ -39,8 +145,491 @@ namespace ChanServ /** Called before a channel expires * @param ci The channel */ - virtual void OnChanExpire(ChannelInfo *ci) anope_abstract; + virtual void OnChanExpire(Channel *ci) anope_abstract; }; static EventHandlersReference<ChanExpire> OnChanExpire("OnChanExpire"); } + + /* It matters that Base is here before Extensible (it is inherited by Serializable) + */ + class CoreExport Channel : public Serializable, public Extensible + { + public: + /* channels who reference this one */ + Anope::map<int> references; + Serialize::Reference<NickServ::Account> founder; /* Channel founder */ + Serialize::Reference<NickServ::Account> successor; /* Who gets the channel if the founder nick is dropped or expires */ + Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */ + Serialize::Checker<std::vector<AutoKick *> > akick; /* List of users to kickban */ + Anope::map<int16_t> levels; + + Anope::string name; /* Channel name */ + Anope::string desc; + + time_t time_registered; + time_t last_used; + + Anope::string last_topic; /* The last topic that was set on this channel */ + Anope::string last_topic_setter; /* Setter */ + time_t last_topic_time; /* Time */ + + ::Channel::ModeList last_modes; /* The last modes set on this channel */ + + int16_t bantype; + + MemoServ::MemoInfo *memos = nullptr; + + ::Channel *c; /* Pointer to channel, if the channel exists */ + + /* For BotServ */ + Serialize::Reference<BotInfo> bi; /* Bot used on this channel */ + + time_t banexpire; /* Time bans expire in */ + + protected: + Channel() : Serializable("ChannelInfo"), access("ChanAccess"), akick("AutoKick") { } + + public: + /** Is the user the real founder? + * @param user The user + * @return true or false + */ + virtual bool IsFounder(const User *user) anope_abstract; + + /** Change the founder of the channek + * @params nc The new founder + */ + virtual void SetFounder(NickServ::Account *nc) anope_abstract; + + /** Get the founder of the channel + * @return The founder + */ + virtual NickServ::Account *GetFounder() const anope_abstract; + + virtual void SetSuccessor(NickServ::Account *nc) anope_abstract; + virtual NickServ::Account *GetSuccessor() const anope_abstract; + + /** Find which bot should send mode/topic/etc changes for this channel + * @return The bot + */ + virtual BotInfo *WhoSends() const anope_abstract; + + /** Add an entry to the channel access list + * @param access The entry + */ + virtual void AddAccess(ChanAccess *access) anope_abstract; + + /** Get an entry from the channel access list by index + * + * @param index The index in the access list vector + * @return A ChanAccess struct corresponding to the index given, or NULL if outside the bounds + * + * Retrieves an entry from the access list that matches the given index. + */ + virtual ChanAccess *GetAccess(unsigned index) const anope_abstract; + + /** Retrieve the access for a user or group in the form of a vector of access entries + * (as multiple entries can affect a single user). + */ + virtual AccessGroup AccessFor(const User *u) anope_abstract; + virtual AccessGroup AccessFor(const NickServ::Account *nc) anope_abstract; + + /** Get the size of the accss vector for this channel + * @return The access vector size + */ + virtual unsigned GetAccessCount() const anope_abstract; + + /** Get the number of access entries for this channel, + * including those that are on other channels. + */ + virtual unsigned GetDeepAccessCount() const anope_abstract; + + /** Erase an entry from the channel access list + * + * @param index The index in the access list vector + * + * @return The erased entry + */ + virtual ChanAccess *EraseAccess(unsigned index) anope_abstract; + + /** Clear the entire channel access list + * + * Clears the entire access list by deleting every item and then clearing the vector. + */ + virtual void ClearAccess() anope_abstract; + + /** Add an akick entry to the channel by NickServ::Account + * @param user The user who added the akick + * @param akicknc The nickcore being akicked + * @param reason The reason for the akick + * @param t The time the akick was added, defaults to now + * @param lu The time the akick was last used, defaults to never + */ + virtual AutoKick* AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) anope_abstract; + + /** Add an akick entry to the channel by reason + * @param user The user who added the akick + * @param mask The mask of the akick + * @param reason The reason for the akick + * @param t The time the akick was added, defaults to now + * @param lu The time the akick was last used, defaults to never + */ + virtual AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) anope_abstract; + + /** Get an entry from the channel akick list + * @param index The index in the akick vector + * @return The akick structure, or NULL if not found + */ + virtual AutoKick* GetAkick(unsigned index) const anope_abstract; + + /** Get the size of the akick vector for this channel + * @return The akick vector size + */ + virtual unsigned GetAkickCount() const anope_abstract; + + /** Erase an entry from the channel akick list + * @param index The index of the akick + */ + virtual void EraseAkick(unsigned index) anope_abstract; + + /** Clear the whole akick list + */ + virtual void ClearAkick() anope_abstract; + + /** Get the level for a privilege + * @param priv The privilege name + * @return the level + * @throws CoreException if priv is not a valid privilege + */ + virtual int16_t GetLevel(const Anope::string &priv) const anope_abstract; + + /** Set the level for a privilege + * @param priv The privilege priv + * @param level The new level + */ + virtual void SetLevel(const Anope::string &priv, int16_t level) anope_abstract; + + /** Remove a privilege from the channel + * @param priv The privilege + */ + virtual void RemoveLevel(const Anope::string &priv) anope_abstract; + + /** Clear all privileges from the channel + */ + virtual void ClearLevels() anope_abstract; + + /** Gets a ban mask for the given user based on the bantype + * of the channel. + * @param u The user + * @return A ban mask that affects the user + */ + virtual Anope::string GetIdealBan(User *u) const anope_abstract; + + virtual void AddChannelReference(const Anope::string &what) anope_abstract; + virtual void RemoveChannelReference(const Anope::string &what) anope_abstract; + virtual void GetChannelReferences(std::deque<Anope::string> &chans) anope_abstract; + }; + + enum + { + ACCESS_INVALID = -10000, + ACCESS_FOUNDER = 10001 + }; + + /* A provider of access. Only used for creating ChanAccesses, as + * they contain pure virtual functions. + */ + class CoreExport AccessProvider : public Service + { + public: + AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) + { + std::vector<AccessProvider *>& providers = service->GetProviders(); + providers.push_back(this); + } + + virtual ~AccessProvider() + { + std::vector<AccessProvider *>& providers = service->GetProviders(); + std::vector<AccessProvider *>::iterator it = std::find(providers.begin(), providers.end(), this); + if (it != providers.end()) + providers.erase(it); + } + + /** Creates a new ChanAccess entry using this provider. + * @return The new entry + */ + virtual ChanAccess *Create() anope_abstract; + }; + + /* Represents one entry of an access list on a channel. */ + class CoreExport ChanAccess : public Serializable + { + public: + typedef std::multimap<const ChanAccess *, const ChanAccess *> Set; + /* shows the 'path' taken to determine if an access entry matches a user + * .first are access entries checked + * .second are access entries which match + */ + typedef std::pair<Set, Set> Path; + + /* The provider that created this access entry */ + AccessProvider *provider; + /* Channel this access entry is on */ + Serialize::Reference<Channel> ci; + /* account this access entry is for, if any */ + Serialize::Reference<NickServ::Account> nc; + Anope::string mask; + Anope::string creator; + time_t last_seen; + time_t created; + + ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p) { } + + virtual ~ChanAccess() + { + service->Destruct(this); + } + + void Serialize(Serialize::Data &data) const override + { + service->Serialize(this, data); + } + + /** Check if this access entry matches the given user or account + * @param u The user + * @param nc The account + * @param p The path to the access object which matches will be put here + */ + virtual bool Matches(const User *u, const NickServ::Account *acc, Path &p) const + { + return service->Matches(this, u, acc, p); + } + + /** Check if this access entry has the given privilege. + * @param name The privilege name + */ + virtual bool HasPriv(const Anope::string &name) const anope_abstract; + + /** Serialize the access given by this access entry into a human + * readable form. chanserv/access will return a number, chanserv/xop + * will be AOP, SOP, etc. + */ + virtual Anope::string AccessSerialize() const anope_abstract; + + /** Unserialize this access entry from the given data. This data + * will be fetched from AccessSerialize. + */ + virtual void AccessUnserialize(const Anope::string &data) anope_abstract; + + /* Comparison operators to other Access entries */ + virtual bool operator>(const ChanAccess &other) const + { + const std::vector<Privilege> &privs = service->GetPrivileges(); + for (unsigned i = privs.size(); i > 0; --i) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + + return this_p && !other_p; + } + + return false; + } + + virtual bool operator<(const ChanAccess &other) const + { + const std::vector<Privilege> &privs = service->GetPrivileges(); + for (unsigned i = privs.size(); i > 0; --i) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + + return !this_p && other_p; + } + + return false; + } + + bool operator>=(const ChanAccess &other) const + { + return !(*this < other); + } + + bool operator<=(const ChanAccess &other) const + { + return !(*this > other); + } + }; + + /* A group of access entries. This is used commonly, for example with ChanServ::Channel::AccessFor, + * to show what access a user has on a channel because users can match multiple access entries. + */ + class CoreExport AccessGroup : public std::vector<ChanAccess *> + { + public: + /* Channel these access entries are on */ + const ChanServ::Channel *ci; + /* Path from these entries to other entries that they depend on */ + ChanAccess::Path path; + /* Account these entries affect, if any */ + const NickServ::Account *nc; + /* super_admin always gets all privs. founder is a special case where ci->founder == nc */ + bool super_admin, founder; + + AccessGroup() + { + this->ci = NULL; + this->nc = NULL; + this->super_admin = this->founder = false; + } + + private: + bool HasPriv(const ChanAccess *access, const Anope::string &name) const + { + EventReturn MOD_RESULT = ::Event::OnCheckPriv(&::Event::CheckPriv::OnCheckPriv, access, name); + if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name)) + { + typedef std::multimap<const ChanAccess *, const ChanAccess *> P; + std::pair<P::const_iterator, P::const_iterator> it = this->path.second.equal_range(access); + if (it.first != it.second) + /* check all of the paths for this entry */ + for (; it.first != it.second; ++it.first) + { + const ChanAccess *a = it.first->second; + /* if only one path fully matches then we are ok */ + if (HasPriv(a, name)) + return true; + } + else + /* entry is the end of a chain, all entries match, ok */ + return true; + } + + /* entry does not match or none of the chains fully match */ + return false; + } + + public: + /** Check if this access group has a certain privilege. Eg, it + * will check every ChanAccess entry of this group for any that + * has the given privilege. + * @param priv The privilege + * @return true if any entry has the given privilege + */ + bool HasPriv(const Anope::string &priv) const + { + if (this->super_admin) + return true; + else if (!ci || ci->GetLevel(priv) == ACCESS_INVALID) + return false; + + /* Privileges prefixed with auto are understood to be given + * automatically. Sometimes founders want to not automatically + * obtain privileges, so we will let them */ + bool auto_mode = !priv.find("AUTO"); + + /* Only grant founder privilege if this isn't an auto mode or if they don't match any entries in this group */ + if ((!auto_mode || this->empty()) && this->founder) + return true; + + EventReturn MOD_RESULT; + MOD_RESULT = ::Event::OnGroupCheckPriv(&::Event::GroupCheckPriv::OnGroupCheckPriv, this, priv); + if (MOD_RESULT != EVENT_CONTINUE) + return MOD_RESULT == EVENT_ALLOW; + + for (unsigned i = this->size(); i > 0; --i) + { + ChanAccess *access = this->at(i - 1); + + if (HasPriv(access, priv)) + return true; + } + + return false; + } + + /** Get the "highest" access entry from this group of entries. + * The highest entry is determined by the entry that has the privilege + * with the highest rank (see Privilege::rank). + * @return The "highest" entry + */ + const ChanAccess *Highest() const + { + ChanAccess *highest = NULL; + for (unsigned i = 0; i < this->size(); ++i) + if (highest == NULL || *this->at(i) > *highest) + highest = this->at(i); + return highest; + } + + /* Comparison operators to other AccessGroups */ + bool operator>(const AccessGroup &other) const + { + if (other.super_admin) + return false; + else if (this->super_admin) + return true; + else if (other.founder) + return false; + else if (this->founder) + return true; + + const std::vector<Privilege> &privs = service->GetPrivileges(); + for (unsigned i = privs.size(); i > 0; --i) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + + return this_p && !other_p; + } + + return false; + } + + bool operator<(const AccessGroup &other) const + { + if (this->super_admin) + return false; + else if (other.super_admin) + return true; + else if (this->founder) + return false; + else if (other.founder) + return true; + + const std::vector<Privilege> &privs = service->GetPrivileges(); + for (unsigned i = privs.size(); i > 0; --i) + { + bool this_p = this->HasPriv(privs[i - 1].name), + other_p = other.HasPriv(privs[i - 1].name); + + if (!this_p && !other_p) + continue; + + return !this_p && other_p; + } + + return false; + } + + bool operator>=(const AccessGroup &other) const + { + return !(*this < other); + } + + bool operator<=(const AccessGroup &other) const + { + return !(*this > other); + } + }; } diff --git a/include/modules/cs_access.h b/include/modules/cs_access.h index 8c6778799..877a98f02 100644 --- a/include/modules/cs_access.h +++ b/include/modules/cs_access.h @@ -17,6 +17,6 @@ namespace Event * @param priv The privilege changed * @param what The new level */ - virtual void OnLevelChange(CommandSource &source, ChannelInfo *ci, const Anope::string &priv, int16_t what) anope_abstract; + virtual void OnLevelChange(CommandSource &source, ChanServ::Channel *ci, const Anope::string &priv, int16_t what) anope_abstract; }; } diff --git a/include/modules/cs_akick.h b/include/modules/cs_akick.h index ab02985c1..08a72260f 100644 --- a/include/modules/cs_akick.h +++ b/include/modules/cs_akick.h @@ -7,6 +7,36 @@ * */ + /* AutoKick data. */ +class CoreExport AutoKick : public Serializable +{ + public: + /* Channel this autokick is on */ + Serialize::Reference<ChanServ::Channel> ci; + + Anope::string mask; + Serialize::Reference<NickServ::Account> nc; + + Anope::string reason; + Anope::string creator; + time_t addtime; + time_t last_used; + + protected: + AutoKick() : Serializable("AutoKick") { } + public: + virtual ~AutoKick() { } +}; + +class AutoKickService : public Service +{ + public: + AutoKickService(Module *o) : Service(o, "AutoKickService", "AutoKickService") { } + + virtual AutoKick* Create() anope_abstract; +}; +static ServiceReference<AutoKickService> akick("AutoKickService", "AutoKickService"); + namespace Event { struct CoreExport Akick : Events @@ -16,13 +46,13 @@ namespace Event * @param ci The channel * @param ak The akick */ - virtual void OnAkickAdd(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) anope_abstract; + virtual void OnAkickAdd(CommandSource &source, ChanServ::Channel *ci, const AutoKick *ak) anope_abstract; /** Called before removing an akick from a channel * @param source The source of the command * @param ci The channel * @param ak The akick */ - virtual void OnAkickDel(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) anope_abstract; + virtual void OnAkickDel(CommandSource &source, ChanServ::Channel *ci, const AutoKick *ak) anope_abstract; }; } diff --git a/include/modules/cs_drop.h b/include/modules/cs_drop.h index e2a9ace8a..49247b3cb 100644 --- a/include/modules/cs_drop.h +++ b/include/modules/cs_drop.h @@ -15,6 +15,6 @@ namespace Event * @param source The user dropping the channel * @param ci The channel */ - virtual EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) anope_abstract; + virtual EventReturn OnChanDrop(CommandSource &source, ChanServ::Channel *ci) anope_abstract; }; } diff --git a/include/modules/cs_info.h b/include/modules/cs_info.h index 7f0429387..7b19abd19 100644 --- a/include/modules/cs_info.h +++ b/include/modules/cs_info.h @@ -17,7 +17,7 @@ namespace Event * @param info Data to show the user requesting information * @param show_hidden true if we should show the user everything */ - virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) anope_abstract; + virtual void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) anope_abstract; }; } diff --git a/include/modules/cs_mode.h b/include/modules/cs_mode.h index 4c1dc5d55..61ef93f95 100644 --- a/include/modules/cs_mode.h +++ b/include/modules/cs_mode.h @@ -97,14 +97,14 @@ namespace Event * @param lock The mode lock * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock. */ - virtual EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_abstract; + virtual EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) anope_abstract; /** Called when a mode is about to be unlocked * @param ci The channel the mode is being unlocked from * @param lock The mode lock * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock. */ - virtual EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_abstract; + virtual EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) anope_abstract; }; } diff --git a/include/modules/cs_set.h b/include/modules/cs_set.h index 3ddf2f41c..355459f7c 100644 --- a/include/modules/cs_set.h +++ b/include/modules/cs_set.h @@ -18,7 +18,7 @@ namespace Event * @param setting The setting passed to the command. Probably ON/OFF. * @return EVENT_ALLOW to bypass access checks, EVENT_STOP to halt immediately. */ - virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) anope_abstract; + virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) anope_abstract; }; static EventHandlersReference<SetChannelOption> OnSetChannelOption("OnSetChannelOption"); } diff --git a/include/modules/dns.h b/include/modules/dns.h index e340c3f2b..d0cecf080 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -9,7 +9,7 @@ * Based on the original code of Services by Andy Church. * */ - + #ifndef DNS_H #define DNS_H @@ -53,7 +53,7 @@ namespace DNS QUERYFLAGS_Z = 0x70, QUERYFLAGS_RCODE = 0xF }; - + enum Error { ERROR_NONE, @@ -70,42 +70,42 @@ namespace DNS ERROR_NO_RECORDS, ERROR_INVALIDTYPE }; - + struct Question { Anope::string name; QueryType type; unsigned short qclass; - + Question() : type(QUERY_NONE), qclass(0) { } Question(const Anope::string &n, QueryType t, unsigned short c = 1) : name(n), type(t), qclass(c) { } - inline bool operator==(const Question & other) const { return name == other.name && type == other.type && qclass == other.qclass; } + inline bool operator==(const Question & other) const { return name == other.name && type == other.type && qclass == other.qclass; } struct hash { - size_t operator()(const Question &q) const + size_t operator()(const Question &q) const { return Anope::hash_ci()(q.name); } }; }; - + struct ResourceRecord : Question { unsigned int ttl; Anope::string rdata; time_t created; - + ResourceRecord(const Anope::string &n, QueryType t, unsigned short c = 1) : Question(n, t, c), ttl(0), created(Anope::CurTime) { } ResourceRecord(const Question &q) : Question(q), ttl(0), created(Anope::CurTime) { } }; - + struct Query { std::vector<Question> questions; std::vector<ResourceRecord> answers, authorities, additional; Error error; - + Query() : error(ERROR_NONE) { } Query(const Question &q) : error(ERROR_NONE) { questions.push_back(q); } }; @@ -123,14 +123,14 @@ namespace DNS virtual void Process(Request *req) = 0; virtual void RemoveRequest(Request *req) = 0; - + virtual bool HandlePacket(ReplySocket *s, const unsigned char *const data, int len, sockaddrs *from) = 0; - + virtual void UpdateSerial() = 0; virtual void Notify(const Anope::string &zone) = 0; virtual uint32_t GetSerial() const = 0; }; - + /** A DNS query. */ class Request : public Timer, public Question @@ -146,22 +146,22 @@ namespace DNS Request(Manager *mgr, Module *c, const Anope::string &addr, QueryType qt, bool cache = false) : Timer(0), Question(addr, qt), manager(mgr), use_cache(cache), id(0), creator(c) { } - + virtual ~Request() { manager->RemoveRequest(this); } - + /** Called when this request succeeds * @param r The query sent back from the nameserver */ virtual void OnLookupComplete(const Query *r) = 0; - + /** Called when this request fails or times out. * @param r The query sent back from the nameserver, check the error code. */ virtual void OnError(const Query *r) { } - + /** Used to time out the query, xalls OnError and lets the TimerManager * delete this request. */ @@ -173,7 +173,7 @@ namespace DNS this->OnError(&rr); } }; - + } // namespace DNS namespace Event @@ -189,7 +189,7 @@ namespace Event static EventHandlersReference<DnsRequest> OnDnsRequest("OnDnsRequest"); } - + #endif // DNS_H - - + + diff --git a/include/modules/fantasy.h b/include/modules/fantasy.h index a7944cef9..bb13b959d 100644 --- a/include/modules/fantasy.h +++ b/include/modules/fantasy.h @@ -18,7 +18,7 @@ namespace Event * @param params The params * @return EVENT_STOP to halt processing and not run the command, EVENT_ALLOW to allow the command to be executed */ - virtual EventReturn OnBotFantasy(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) anope_abstract; + virtual EventReturn OnBotFantasy(CommandSource &source, Command *c, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) anope_abstract; }; struct CoreExport BotNoFantasyAccess : Events @@ -30,6 +30,6 @@ namespace Event * @param params The params * @return EVENT_STOP to halt processing and not run the command, EVENT_ALLOW to allow the command to be executed */ - virtual EventReturn OnBotNoFantasyAccess(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) anope_abstract; + virtual EventReturn OnBotNoFantasyAccess(CommandSource &source, Command *c, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) anope_abstract; }; } diff --git a/include/modules/hs_del.h b/include/modules/hs_del.h index d4a5c7666..fdec23b21 100644 --- a/include/modules/hs_del.h +++ b/include/modules/hs_del.h @@ -13,6 +13,6 @@ namespace Event /** Called when a vhost is deleted * @param na The nickalias of the vhost */ - virtual void OnDeleteVhost(NickAlias *na) anope_abstract; + virtual void OnDeleteVhost(NickServ::Nick *na) anope_abstract; }; } diff --git a/include/modules/memoserv.h b/include/modules/memoserv.h index 4e5d67de6..99f34b6e9 100644 --- a/include/modules/memoserv.h +++ b/include/modules/memoserv.h @@ -6,6 +6,10 @@ * */ +#pragma once + +#include "module.h" + namespace MemoServ { class MemoServService : public Service @@ -18,26 +22,29 @@ namespace MemoServ MEMO_TOO_FAST, MEMO_TARGET_FULL }; - + MemoServService(Module *m) : Service(m, "MemoServService", "MemoServ") { } - + /** Sends a memo. * @param source The source of the memo, can be anythin. * @param target The target of the memo, nick or channel. * @param message Memo text * @param force true to force the memo, restrictions/delays etc are not checked */ - virtual MemoResult Send(const Anope::string &source, const Anope::string &target, const Anope::string &message, bool force = false) = 0; - + virtual MemoResult Send(const Anope::string &source, const Anope::string &target, const Anope::string &message, bool force = false) anope_abstract; + /** Check for new memos and notify the user if there are any * @param u The user */ - virtual void Check(User *u) = 0; + virtual void Check(User *u) anope_abstract; + + virtual Memo *CreateMemo() anope_abstract; + virtual MemoInfo *GetMemoInfo(const Anope::string &targ, bool &is_registered, bool &is_chan, bool create) anope_abstract; }; static ServiceReference<MemoServService> service("MemoServService", "MemoServ"); - + namespace Event { struct CoreExport MemoSend : Events @@ -51,7 +58,7 @@ namespace MemoServ virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) anope_abstract; }; static EventHandlersReference<MemoSend> OnMemoSend("OnMemoSend"); - + struct CoreExport MemoDel : Events { /** Called when a memo is deleted @@ -63,4 +70,41 @@ namespace MemoServ }; static EventHandlersReference<MemoDel> OnMemoDel("OnMemoDel"); } + + class Memo : public Serializable + { + public: + bool unread; + bool receipt; + protected: + Memo() : Serializable("Memo") { } + public: + + Anope::string owner; + /* When it was sent */ + time_t time; + Anope::string sender; + Anope::string text; + }; + + /* Memo info structures. Since both nicknames and channels can have memos, + * we encapsulate memo data in a MemoInfo to make it easier to handle. + */ + struct CoreExport MemoInfo + { + int16_t memomax = 0; + Serialize::Checker<std::vector<Memo *> > memos; + std::vector<Anope::string> ignores; + + MemoInfo() : memos("Memo") { } + virtual ~MemoInfo() { } + + virtual Memo *GetMemo(unsigned index) const anope_abstract; + + virtual unsigned GetIndex(Memo *m) const anope_abstract; + + virtual void Del(unsigned index) anope_abstract; + + virtual bool HasIgnore(User *u) anope_abstract; + }; } diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h index 0ede4130e..a55786ffb 100644 --- a/include/modules/nickserv.h +++ b/include/modules/nickserv.h @@ -7,8 +7,20 @@ * */ +#pragma once + +#include "event.h" +#include "service.h" + namespace NickServ { + class Nick; + class Account; + class IdentifyRequestListener; + + typedef Anope::hash_map<Nick *> nickalias_map; + typedef Anope::hash_map<Account *> nickcore_map; + class NickServService : public Service { public: @@ -17,11 +29,33 @@ namespace NickServ } virtual void Validate(User *u) anope_abstract; - virtual void Collide(User *u, NickAlias *na) anope_abstract; - virtual void Release(NickAlias *na) anope_abstract; + virtual void Collide(User *u, Nick *na) anope_abstract; + virtual void Release(Nick *na) anope_abstract; + + virtual IdentifyRequest *CreateIdentifyRequest(IdentifyRequestListener *l, Module *owner, const Anope::string &acc, const Anope::string &pass) anope_abstract; + virtual std::set<IdentifyRequest *>& GetIdentifyRequests() anope_abstract; + + virtual nickalias_map& GetNickList() anope_abstract; + virtual nickcore_map& GetAccountList() anope_abstract; + + virtual Nick *CreateNick(const Anope::string &nick, Account *acc) anope_abstract; + virtual Account *CreateAccount(const Anope::string &acc) anope_abstract; + + virtual Nick *FindNick(const Anope::string &nick) anope_abstract; + virtual Account *FindAccount(const Anope::string &acc) anope_abstract; }; static ServiceReference<NickServService> service("NickServService", "NickServ"); + inline Nick *FindNick(const Anope::string &nick) + { + return service ? service->FindNick(nick) : nullptr; + } + + inline Account *FindAccount(const Anope::string &account) + { + return service ? service->FindAccount(account) : nullptr; + } + namespace Event { struct CoreExport PreNickExpire : Events @@ -30,7 +64,7 @@ namespace NickServ * @param na The nick * @param expire Set to true to allow the nick to expire */ - virtual void OnPreNickExpire(NickAlias *na, bool &expire) anope_abstract; + virtual void OnPreNickExpire(Nick *na, bool &expire) anope_abstract; }; static EventHandlersReference<PreNickExpire> OnPreNickExpire("OnPreNickExpire"); @@ -39,7 +73,7 @@ namespace NickServ /** Called when a nick drops * @param na The nick */ - virtual void OnNickExpire(NickAlias *na) anope_abstract; + virtual void OnNickExpire(Nick *na) anope_abstract; }; static EventHandlersReference<NickExpire> OnNickExpire("OnNickExpire"); @@ -49,7 +83,7 @@ namespace NickServ * @param user The user registering the nick, of any * @param The nick */ - virtual void OnNickRegister(User *user, NickAlias *na) anope_abstract; + virtual void OnNickRegister(User *user, Nick *na) anope_abstract; }; static EventHandlersReference<NickRegister> OnNickRegister("OnNickRegister"); @@ -61,8 +95,250 @@ namespace NickServ * @param na The nick they are on * @return EVENT_STOP to force the user off of the nick */ - virtual EventReturn OnNickValidate(User *u, NickAlias *na) anope_abstract; + virtual EventReturn OnNickValidate(User *u, Nick *na) anope_abstract; }; static EventHandlersReference<NickValidate> OnNickValidate("OnNickValidate"); } + + /* A registered nickname. + * It matters that Base is here before Extensible (it is inherited by Serializable) + */ + class CoreExport Nick : public Serializable, public Extensible + { + protected: + Anope::string vhost_ident, vhost_host, vhost_creator; + time_t vhost_created; + + public: + Anope::string nick; + Anope::string last_quit; + Anope::string last_realname; + /* Last usermask this nick was seen on, eg user@host */ + Anope::string last_usermask; + /* Last uncloaked usermask, requires nickserv/auspex to see */ + Anope::string last_realhost; + time_t time_registered; + time_t last_seen; + /* Account this nick is tied to. Multiple nicks can be tied to a single account. */ + Serialize::Reference<Account> nc; + + protected: + Nick() : Serializable("NickAlias") { } + + public: + virtual ~Nick() { } + + /** Set a vhost for the user + * @param ident The ident + * @param host The host + * @param creator Who created the vhost + * @param time When the vhost was craated + */ + virtual void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime) anope_abstract; + + /** Remove a users vhost + **/ + virtual void RemoveVhost() anope_abstract; + + /** Check if the user has a vhost + * @return true or false + */ + virtual bool HasVhost() const anope_abstract; + + /** Retrieve the vhost ident + * @return the ident + */ + virtual const Anope::string &GetVhostIdent() const anope_abstract; + + /** Retrieve the vhost host + * @return the host + */ + virtual const Anope::string &GetVhostHost() const anope_abstract; + + /** Retrieve the vhost creator + * @return the creator + */ + virtual const Anope::string &GetVhostCreator() const anope_abstract; + + /** Retrieve when the vhost was created + * @return the time it was created + */ + virtual time_t GetVhostCreated() const anope_abstract; + }; + + /* A registered account. Each account must have a Nick with the same nick as the + * account's display. + * It matters that Base is here before Extensible (it is inherited by Serializable) + */ + class CoreExport Account : public Serializable, public Extensible + { + protected: + /* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */ + Serialize::Checker<std::map<ChanServ::Channel *, int> > chanaccess; + public: + /* Name of the account. Find(display)->nc == this. */ + Anope::string display; + /* User password in form of hashm:data */ + Anope::string pass; + Anope::string email; + /* Locale name of the language of the user. Empty means default language */ + Anope::string language; + /* Access list, contains user@host masks of users who get certain privileges based + * on if NI_SECURE is set and what (if any) kill protection is enabled. */ + std::vector<Anope::string> access; + MemoServ::MemoInfo *memos = nullptr; + std::map<Anope::string, Anope::string> last_modes; + + /* Nicknames registered that are grouped to this account. + * for n in aliases, n->nc == this. + */ + Serialize::Checker<std::vector<Nick *> > aliases; + + /* Set if this user is a services operattor. o->ot must exist. */ + Oper *o; + + /* Unsaved data */ + + /* Number of channels registered by this account */ + uint16_t channelcount; + /* Last time an email was sent to this user */ + time_t lastmail; + /* Users online now logged into this account */ + std::list<User *> users; + + protected: + /** Constructor + * @param display The display nick + */ + Account() : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias") { } + + public: + virtual ~Account() { } + + /** Changes the display for this account + * @param na The new display, must be grouped to this account. + */ + virtual void SetDisplay(const Nick *na) anope_abstract; + + /** Checks whether this account is a services oper or not. + * @return True if this account is a services oper, false otherwise. + */ + virtual bool IsServicesOper() const anope_abstract; + + /** Add an entry to the nick's access list + * + * @param entry The nick!ident@host entry to add to the access list + * + * Adds a new entry into the access list. + */ + virtual void AddAccess(const Anope::string &entry) anope_abstract; + + /** Get an entry from the nick's access list by index + * + * @param entry Index in the access list vector to retrieve + * @return The access list entry of the given index if within bounds, an empty string if the vector is empty or the index is out of bounds + * + * Retrieves an entry from the access list corresponding to the given index. + */ + virtual Anope::string GetAccess(unsigned entry) const anope_abstract; + + /** Get the number of entries on the access list for this account. + */ + virtual unsigned GetAccessCount() const anope_abstract; + + /** Find an entry in the nick's access list + * + * @param entry The nick!ident@host entry to search for + * @return True if the entry is found in the access list, false otherwise + * + * Search for an entry within the access list. + */ + virtual bool FindAccess(const Anope::string &entry) anope_abstract; + + /** Erase an entry from the nick's access list + * + * @param entry The nick!ident@host entry to remove + * + * Removes the specified access list entry from the access list. + */ + virtual void EraseAccess(const Anope::string &entry) anope_abstract; + + /** Clears the entire nick's access list + * + * Deletes all the memory allocated in the access list vector and then clears the vector. + */ + virtual void ClearAccess() anope_abstract; + + /** Is the given user on this accounts access list? + * + * @param u The user + * + * @return true if the user is on the access list + */ + virtual bool IsOnAccess(const User *u) const anope_abstract; + + virtual void AddChannelReference(ChanServ::Channel *ci) anope_abstract; + virtual void RemoveChannelReference(ChanServ::Channel *ci) anope_abstract; + virtual void GetChannelReferences(std::deque<ChanServ::Channel *> &queue) anope_abstract; + }; + + /* A request to check if an account/password is valid. These can exist for + * extended periods due to the time some authentication modules take. + */ + class CoreExport IdentifyRequest + { + protected: + /* Owner of this request, used to cleanup requests if a module is unloaded + * while a request us pending */ + Module *owner; + IdentifyRequestListener *l; + Anope::string account; + Anope::string password; + + std::set<Module *> holds; + bool dispatched = false; + bool success = false; + + IdentifyRequest(IdentifyRequestListener *li, Module *o, const Anope::string &acc, const Anope::string &pass) : owner(o), l(li), account(acc), password(pass) { } + public: + virtual ~IdentifyRequest() { } + + const Anope::string &GetAccount() const { return account; } + const Anope::string &GetPassword() const { return password; } + Module *GetOwner() const { return owner; } + + /* Holds this request. When a request is held it must be Released later + * for the request to complete. Multiple modules may hold a request at any time, + * but the request is not complete until every module has released it. If you do not + * require holding this (eg, your password check is done in this thread and immediately) + * then you don't need to hold the request before Successing it. + * @param m The module holding this request + */ + virtual void Hold(Module *m) anope_abstract; + + /** Releases a held request + * @param m The module releaseing the hold + */ + virtual void Release(Module *m) anope_abstract; + + /** Called by modules when this IdentifyRequest has successeded successfully. + * If this request is behind held it must still be Released after calling this. + * @param m The module confirming authentication + */ + virtual void Success(Module *m) anope_abstract; + + /** Used to either finalize this request or marks + * it as dispatched and begins waiting for the module(s) + * that have holds to finish. + */ + virtual void Dispatch() anope_abstract; + }; + + class IdentifyRequestListener + { + public: + virtual ~IdentifyRequestListener() { } + virtual void OnSuccess(IdentifyRequest *) anope_abstract; + virtual void OnFail(IdentifyRequest *) anope_abstract; + }; } diff --git a/include/modules/ns_cert.h b/include/modules/ns_cert.h index b0614b2e6..f464d7fde 100644 --- a/include/modules/ns_cert.h +++ b/include/modules/ns_cert.h @@ -66,7 +66,7 @@ class CertService : public Service public: CertService(Module *c) : Service(c, "CertService", "certs") { } - virtual NickCore* FindAccountFromCert(const Anope::string &cert) = 0; + virtual NickServ::Account* FindAccountFromCert(const Anope::string &cert) = 0; }; namespace Event @@ -77,18 +77,18 @@ namespace Event * @param nc The nick * @param entry The entry */ - virtual void OnNickAddCert(NickCore *nc, const Anope::string &entry) anope_abstract; + virtual void OnNickAddCert(NickServ::Account *nc, const Anope::string &entry) anope_abstract; - /** Called from NickCore::EraseCert() - * @param nc pointer to the NickCore + /** Called from NickServ::Account::EraseCert() + * @param nc pointer to the NickServ::Account * @param entry The fingerprint */ - virtual void OnNickEraseCert(NickCore *nc, const Anope::string &entry) anope_abstract; + virtual void OnNickEraseCert(NickServ::Account *nc, const Anope::string &entry) anope_abstract; - /** called from NickCore::ClearCert() - * @param nc pointer to the NickCore + /** called from NickServ::Account::ClearCert() + * @param nc pointer to the NickServ::Account */ - virtual void OnNickClearCert(NickCore *nc) anope_abstract; + virtual void OnNickClearCert(NickServ::Account *nc) anope_abstract; }; } diff --git a/include/modules/ns_drop.h b/include/modules/ns_drop.h index 2aef2b965..9217a924c 100644 --- a/include/modules/ns_drop.h +++ b/include/modules/ns_drop.h @@ -14,7 +14,7 @@ namespace Event * @param source The source of the command * @param na The nick */ - virtual void OnNickDrop(CommandSource &source, NickAlias *na) anope_abstract; + virtual void OnNickDrop(CommandSource &source, NickServ::Nick *na) anope_abstract; }; extern CoreExport EventHandlers<NickDrop> OnNickDrop; } diff --git a/include/modules/ns_group.h b/include/modules/ns_group.h index 8b3fa49f9..a254c4412 100644 --- a/include/modules/ns_group.h +++ b/include/modules/ns_group.h @@ -15,6 +15,6 @@ namespace Event * @param u The user grouping * @param target The target they're grouping to */ - virtual void OnNickGroup(User *u, NickAlias *target) anope_abstract; + virtual void OnNickGroup(User *u, NickServ::Nick *target) anope_abstract; }; } diff --git a/include/modules/ns_info.h b/include/modules/ns_info.h index 8fae2b536..dd593ce59 100644 --- a/include/modules/ns_info.h +++ b/include/modules/ns_info.h @@ -17,6 +17,6 @@ namespace Event * @param info Data to show the user requesting information * @param show_hidden true if we should show the user everything */ - virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_abstract; + virtual void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) anope_abstract; }; } diff --git a/include/modules/ns_set.h b/include/modules/ns_set.h index a45fa0b5e..b958b4cf5 100644 --- a/include/modules/ns_set.h +++ b/include/modules/ns_set.h @@ -18,7 +18,7 @@ namespace Event * @param setting The setting passed to the command. Probably ON/OFF. * @return EVENT_STOP to halt immediately */ - virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickCore *nc, const Anope::string &setting) anope_abstract; + virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickServ::Account *nc, const Anope::string &setting) anope_abstract; }; static EventHandlersReference<SetNickOption> OnSetNickOption("OnSetNickOption"); } diff --git a/include/modules/os_ignore.h b/include/modules/os_ignore.h index 2511d47b2..598122663 100644 --- a/include/modules/os_ignore.h +++ b/include/modules/os_ignore.h @@ -26,7 +26,7 @@ class IgnoreService : public Service { protected: IgnoreService(Module *c) : Service(c, "IgnoreService", "ignore") { } - + public: virtual void AddIgnore(IgnoreData *) = 0; diff --git a/include/modules/os_news.h b/include/modules/os_news.h index 458a5a82b..b076f62af 100644 --- a/include/modules/os_news.h +++ b/include/modules/os_news.h @@ -31,11 +31,11 @@ class NewsService : public Service NewsService(Module *m) : Service(m, "NewsService", "news") { } virtual NewsItem *CreateNewsItem() = 0; - + virtual void AddNewsItem(NewsItem *n) = 0; - + virtual void DelNewsItem(NewsItem *n) = 0; - + virtual std::vector<NewsItem *> &GetNewsList(NewsType t) = 0; }; diff --git a/include/modules/os_session.h b/include/modules/os_session.h index 91548a5c2..1c1966e06 100644 --- a/include/modules/os_session.h +++ b/include/modules/os_session.h @@ -40,7 +40,7 @@ class SessionService : public Service virtual Exception *FindException(User *u) = 0; - virtual Exception *FindException(const Anope::string &host) = 0; + virtual Exception *FindException(const Anope::string &host) = 0; virtual ExceptionVector &GetExceptions() = 0; diff --git a/include/modules/redis.h b/include/modules/redis.h index 941691a72..ae444e782 100644 --- a/include/modules/redis.h +++ b/include/modules/redis.h @@ -24,7 +24,7 @@ namespace Redis Reply() { Clear(); } ~Reply() { Clear(); } - + void Clear() { type = NOT_PARSED; diff --git a/include/modules/sasl.h b/include/modules/sasl.h index dbe6441e9..28bdb1ca6 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -33,7 +33,7 @@ namespace SASL virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) = 0; - virtual void Succeed(Session *, NickCore *) = 0; + virtual void Succeed(Session *, NickServ::Account *) = 0; virtual void Fail(Session *) = 0; virtual void SendMechs(Session *) = 0; virtual void DeleteSessions(Mechanism *, bool = false) = 0; @@ -73,32 +73,32 @@ namespace SASL } }; - class IdentifyRequest : public ::IdentifyRequest + class IdentifyRequestListener : public NickServ::IdentifyRequestListener { Anope::string uid; public: - IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : ::IdentifyRequest(m, acc, pass), uid(id) { } + IdentifyRequestListener(const Anope::string &id) : uid(id) { } - void OnSuccess() override + void OnSuccess(NickServ::IdentifyRequest *req) override { if (!sasl) return; - NickAlias *na = NickAlias::Find(GetAccount()); + NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (!na || na->nc->HasExt("NS_SUSPENDED")) - return OnFail(); + return OnFail(req); Session *s = sasl->GetSession(uid); if (s) { - Log(Config->GetClient("NickServ")) << "A user identified to account " << this->GetAccount() << " using SASL"; + Log(Config->GetClient("NickServ")) << "A user identified to account " << req->GetAccount() << " using SASL"; sasl->Succeed(s, na->nc); delete s; } } - void OnFail() override + void OnFail(NickServ::IdentifyRequest *req) override { if (!sasl) return; @@ -111,13 +111,13 @@ namespace SASL } Anope::string accountstatus; - NickAlias *na = NickAlias::Find(GetAccount()); + NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (!na) accountstatus = "nonexistent "; else if (na->nc->HasExt("NS_SUSPENDED")) accountstatus = "suspended "; - Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL"; + Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << req->GetAccount() << " using SASL"; } }; } diff --git a/include/modules/ssl.h b/include/modules/ssl.h index 6eb97582c..fab3c35cc 100644 --- a/include/modules/ssl.h +++ b/include/modules/ssl.h @@ -3,7 +3,7 @@ class SSLService : public Service { public: SSLService(Module *o, const Anope::string &n) : Service(o, "SSLService", n) { } - + virtual void Init(Socket *s) = 0; }; diff --git a/include/modules/suspend.h b/include/modules/suspend.h index bd4eacd3b..3f5a8ded3 100644 --- a/include/modules/suspend.h +++ b/include/modules/suspend.h @@ -22,14 +22,14 @@ namespace Event /** Called when a channel is suspended * @param ci The channel */ - virtual void OnChanSuspend(ChannelInfo *ci) anope_abstract; + virtual void OnChanSuspend(ChanServ::Channel *ci) anope_abstract; }; struct CoreExport ChanUnsuspend : Events { /** Called when a channel is unsuspended * @param ci The channel */ - virtual void OnChanUnsuspend(ChannelInfo *ci) anope_abstract; + virtual void OnChanUnsuspend(ChanServ::Channel *ci) anope_abstract; }; extern CoreExport EventHandlers<ChanUnsuspend> OnChanUnsuspend; @@ -38,7 +38,7 @@ namespace Event /** Called when a nick is suspended * @param na The nick alias */ - virtual void OnNickSuspend(NickAlias *na) anope_abstract; + virtual void OnNickSuspend(NickServ::Nick *na) anope_abstract; }; struct CoreExport NickUnsuspended : Events @@ -46,7 +46,7 @@ namespace Event /** Called when a nick is unsuspneded * @param na The nick alias */ - virtual void OnNickUnsuspended(NickAlias *na) anope_abstract; + virtual void OnNickUnsuspended(NickServ::Nick *na) anope_abstract; }; } diff --git a/include/modules/xmlrpc.h b/include/modules/xmlrpc.h index d5a5ea4a7..55962db24 100644 --- a/include/modules/xmlrpc.h +++ b/include/modules/xmlrpc.h @@ -9,7 +9,7 @@ class XMLRPCRequest Anope::string id; std::deque<Anope::string> data; HTTPReply& r; - + XMLRPCRequest(HTTPReply &_r) : r(_r) { } inline void reply(const Anope::string &dname, const Anope::string &ddata) { this->replies.insert(std::make_pair(dname, ddata)); } inline const std::map<Anope::string, Anope::string> &get_replies() { return this->replies; } diff --git a/include/opertype.h b/include/opertype.h index 9cbd3347a..fded241c7 100644 --- a/include/opertype.h +++ b/include/opertype.h @@ -9,10 +9,9 @@ #pragma once #include "services.h" -#include "account.h" /* A services operator. Usually made by the configuration file, but not always. - * NickAlias::Find(name)->nc->o == this + * NickServ::FindNick(name)->nc->o == this */ struct CoreExport Oper { @@ -32,7 +31,7 @@ struct CoreExport Oper virtual ~Oper(); static std::vector<Oper *> opers; - + /** Find an oper block by name * @param name The name * @return the oper block diff --git a/include/protocol.h b/include/protocol.h index 06f9d35c9..dc57d2e10 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -186,7 +186,7 @@ class CoreExport IRCDProto : public Service * initial handshake requirements. */ virtual void SendConnect() = 0; - + /** Called right before we begin our burst, after we have handshaked successfully with the uplink/ * At this point none of our servesr, users, or channels exist on the uplink */ @@ -205,7 +205,7 @@ class CoreExport IRCDProto : public Service virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...); - virtual void SendLogin(User *u, NickAlias *na) = 0; + virtual void SendLogin(User *u, NickServ::Nick *na) = 0; virtual void SendLogout(User *u) = 0; /** Send a channel creation message to the uplink. diff --git a/include/regchannel.h b/include/regchannel.h deleted file mode 100644 index 402ed065b..000000000 --- a/include/regchannel.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * - * (C) 2008-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - */ - -#pragma once - -#include "memo.h" -#include "modes.h" -#include "extensible.h" -#include "logger.h" -#include "modules.h" -#include "serialize.h" -#include "bots.h" - -typedef Anope::hash_map<ChannelInfo *> registered_channel_map; - -extern CoreExport Serialize::Checker<registered_channel_map> RegisteredChannelList; - -/* AutoKick data. */ -class CoreExport AutoKick : public Serializable -{ - public: - /* Channel this autokick is on */ - Serialize::Reference<ChannelInfo> ci; - - Anope::string mask; - Serialize::Reference<NickCore> nc; - - Anope::string reason; - Anope::string creator; - time_t addtime; - time_t last_used; - - AutoKick(); - ~AutoKick(); - void Serialize(Serialize::Data &data) const override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); -}; - -/* It matters that Base is here before Extensible (it is inherited by Serializable) - */ -class CoreExport ChannelInfo : public Serializable, public Extensible -{ - /* channels who reference this one */ - Anope::map<int> references; - private: - Serialize::Reference<NickCore> founder; /* Channel founder */ - Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */ - Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */ - Serialize::Checker<std::vector<AutoKick *> > akick; /* List of users to kickban */ - Anope::map<int16_t> levels; - - public: - friend class ChanAccess; - friend class AutoKick; - - Anope::string name; /* Channel name */ - Anope::string desc; - - time_t time_registered; - time_t last_used; - - Anope::string last_topic; /* The last topic that was set on this channel */ - Anope::string last_topic_setter; /* Setter */ - time_t last_topic_time; /* Time */ - - Channel::ModeList last_modes; /* The last modes set on this channel */ - - int16_t bantype; - - MemoInfo memos; - - Channel *c; /* Pointer to channel, if the channel exists */ - - /* For BotServ */ - Serialize::Reference<BotInfo> bi; /* Bot used on this channel */ - - time_t banexpire; /* Time bans expire in */ - - /** Constructor - * @param chname The channel name - */ - ChannelInfo(const Anope::string &chname); - - /** Copy constructor - * @param ci The ChannelInfo to copy settings from - */ - ChannelInfo(const ChannelInfo &ci); - - ~ChannelInfo(); - - void Serialize(Serialize::Data &data) const override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &); - - /** Change the founder of the channek - * @params nc The new founder - */ - void SetFounder(NickCore *nc); - - /** Get the founder of the channel - * @return The founder - */ - NickCore *GetFounder() const; - - void SetSuccessor(NickCore *nc); - NickCore *GetSuccessor() const; - - /** Find which bot should send mode/topic/etc changes for this channel - * @return The bot - */ - BotInfo *WhoSends() const; - - /** Add an entry to the channel access list - * @param access The entry - */ - void AddAccess(ChanAccess *access); - - /** Get an entry from the channel access list by index - * - * @param index The index in the access list vector - * @return A ChanAccess struct corresponding to the index given, or NULL if outside the bounds - * - * Retrieves an entry from the access list that matches the given index. - */ - ChanAccess *GetAccess(unsigned index) const; - - /** Retrieve the access for a user or group in the form of a vector of access entries - * (as multiple entries can affect a single user). - */ - AccessGroup AccessFor(const User *u); - AccessGroup AccessFor(const NickCore *nc); - - /** Get the size of the accss vector for this channel - * @return The access vector size - */ - unsigned GetAccessCount() const; - - /** Get the number of access entries for this channel, - * including those that are on other channels. - */ - unsigned GetDeepAccessCount() const; - - /** Erase an entry from the channel access list - * - * @param index The index in the access list vector - * - * @return The erased entry - */ - ChanAccess *EraseAccess(unsigned index); - - /** Clear the entire channel access list - * - * Clears the entire access list by deleting every item and then clearing the vector. - */ - void ClearAccess(); - - /** Add an akick entry to the channel by NickCore - * @param user The user who added the akick - * @param akicknc The nickcore being akicked - * @param reason The reason for the akick - * @param t The time the akick was added, defaults to now - * @param lu The time the akick was last used, defaults to never - */ - AutoKick* AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); - - /** Add an akick entry to the channel by reason - * @param user The user who added the akick - * @param mask The mask of the akick - * @param reason The reason for the akick - * @param t The time the akick was added, defaults to now - * @param lu The time the akick was last used, defaults to never - */ - AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); - - /** Get an entry from the channel akick list - * @param index The index in the akick vector - * @return The akick structure, or NULL if not found - */ - AutoKick* GetAkick(unsigned index) const; - - /** Get the size of the akick vector for this channel - * @return The akick vector size - */ - unsigned GetAkickCount() const; - - /** Erase an entry from the channel akick list - * @param index The index of the akick - */ - void EraseAkick(unsigned index); - - /** Clear the whole akick list - */ - void ClearAkick(); - - /** Get the level for a privilege - * @param priv The privilege name - * @return the level - * @throws CoreException if priv is not a valid privilege - */ - int16_t GetLevel(const Anope::string &priv) const; - - /** Set the level for a privilege - * @param priv The privilege priv - * @param level The new level - */ - void SetLevel(const Anope::string &priv, int16_t 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(); - - /** Gets a ban mask for the given user based on the bantype - * of the channel. - * @param u The user - * @return A ban mask that affects the user - */ - Anope::string GetIdealBan(User *u) const; - - /** Finds a ChannelInfo - * @param name channel name to lookup - * @return the ChannelInfo associated with the channel - */ - static ChannelInfo* Find(const Anope::string &name); - - void AddChannelReference(const Anope::string &what); - void RemoveChannelReference(const Anope::string &what); - void GetChannelReferences(std::deque<Anope::string> &chans); -}; - -/** Is the user the real founder? - * @param user The user - * @param ci The channel - * @return true or false - */ -extern CoreExport bool IsFounder(const User *user, const ChannelInfo *ci); - diff --git a/include/users.h b/include/users.h index 5a0bb46a9..e89d7c8af 100644 --- a/include/users.h +++ b/include/users.h @@ -18,7 +18,6 @@ #include "extensible.h" #include "serialize.h" #include "commands.h" -#include "account.h" typedef Anope::hash_map<User *> user_map; @@ -46,8 +45,8 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe bool on_access; /* Map of user modes and the params this user has (if any) */ ModeList modes; - /* NickCore account the user is currently loggged in as, if they are logged in */ - Serialize::Reference<NickCore> nc; + /* NickServ::Account account the user is currently loggged in as, if they are logged in */ + Serialize::Reference<NickServ::Account> nc; /* # of invalid password attempts */ unsigned short invalid_pw_count; @@ -107,14 +106,14 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe * @param suid The unique identifier of the user. * @param nc The account the user is identified as, if any */ - User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc); + User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *nc); /** Destroy a user. */ virtual ~User(); public: - static User* OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc); + static User* OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *nc); /** Update the nickname of a user record accordingly, should be * called from ircd protocol. @@ -189,8 +188,8 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe * @param fmt Format of the Message * @param ... any number of parameters */ - void SendMessage(BotInfo *source, const char *fmt, ...); - void SendMessage(BotInfo *source, const Anope::string &msg) override; + void SendMessage(const MessageSource &, const char *fmt, ...); + void SendMessage(const MessageSource &, const Anope::string &msg) override; /** Identify the user to a nick. * updates last_seen, logs the user in, @@ -198,12 +197,12 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe * @param na the nick to identify to, should be the same as * the user's current nick */ - void Identify(NickAlias *na); + void Identify(NickServ::Nick *na); /** Login the user to an account * @param core The account */ - void Login(NickCore *core); + void Login(NickServ::Account *core); /** Logout the user */ @@ -212,7 +211,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe /** Get the account the user is logged in using * @return The account or NULL */ - NickCore *Account() const; + NickServ::Account *Account() const; /** Check if the user is identified for their nick * @param check_nick True to check if the user is identified to the nickname they are on too diff --git a/include/version.cpp b/include/version.cpp index b0ea0423d..5432188fe 100644 --- a/include/version.cpp +++ b/include/version.cpp @@ -28,7 +28,7 @@ static std::string get_git_hash(const std::string &git_dir) fd.close(); return ""; } - + fd.close(); filebuf = filebuf.substr(5); diff --git a/modules/bs_autoassign.cpp b/modules/bs_autoassign.cpp index e7543d646..e9a6e062b 100644 --- a/modules/bs_autoassign.cpp +++ b/modules/bs_autoassign.cpp @@ -14,11 +14,11 @@ class BSAutoAssign : public Module { public: BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , EventHook<Event::ChanRegistered>("OnChanRegistered") + , EventHook<Event::ChanRegistered>("OnChanRegistered") { } - void OnChanRegistered(ChannelInfo *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { const Anope::string &bot = Config->GetModule(this)->Get<const Anope::string>("bot"); if (bot.empty()) diff --git a/modules/commands/bs_assign.cpp b/modules/commands/bs_assign.cpp index 90fb7ed56..fe7938fc8 100644 --- a/modules/commands/bs_assign.cpp +++ b/modules/commands/bs_assign.cpp @@ -32,7 +32,7 @@ class CommandBSAssign : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -46,7 +46,7 @@ class CommandBSAssign : public Command return; } - AccessGroup access = source.AccessFor(ci); + ChanServ::AccessGroup access = source.AccessFor(ci); if (ci->HasExt("BS_NOBOT") || (!access.HasPriv("ASSIGN") && !source.HasPriv("botserv/administration"))) { source.Reply(ACCESS_DENIED); @@ -100,14 +100,14 @@ class CommandBSUnassign : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); return; } - AccessGroup access = source.AccessFor(ci); + ChanServ::AccessGroup access = source.AccessFor(ci); if (!source.HasPriv("botserv/administration") && !access.HasPriv("ASSIGN")) { source.Reply(ACCESS_DENIED); @@ -157,7 +157,7 @@ class CommandBSSetNoBot : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string &value = params[1]; if (Anope::ReadOnly) @@ -174,7 +174,7 @@ class CommandBSSetNoBot : public Command if (value.equals_ci("ON")) { - Log(LOG_ADMIN, source, this, ci) << "to enable nobot"; + Log(LOG_ADMIN, source, this, ci) << "to enable nobot"; ci->Extend<bool>("BS_NOBOT"); if (ci->bi) @@ -183,7 +183,7 @@ class CommandBSSetNoBot : public Command } else if (value.equals_ci("OFF")) { - Log(LOG_ADMIN, source, this, ci) << "to disable nobot"; + Log(LOG_ADMIN, source, this, ci) << "to disable nobot"; ci->Shrink<bool>("BS_NOBOT"); source.Reply(_("No-bot mode is now \002off\002 on channel %s."), ci->name.c_str()); @@ -230,7 +230,7 @@ class BSAssign : public Module if (Anope::ReadOnly || !c->ci || targ->server != Me || !(bi = dynamic_cast<BotInfo *>(targ))) return; - AccessGroup access = c->ci->AccessFor(source); + ChanServ::AccessGroup access = c->ci->AccessFor(source); if (nobot.HasExt(c->ci) || (!access.HasPriv("ASSIGN") && !source->HasPriv("botserv/administration"))) { targ->SendMessage(bi, ACCESS_DENIED); @@ -253,7 +253,7 @@ class BSAssign : public Module targ->SendMessage(bi, _("Bot \002%s\002 has been assigned to %s."), bi->nick.c_str(), c->name.c_str()); } - void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override + void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) override { if (nobot.HasExt(ci)) info.AddOption(_("No bot")); diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 082dae0bd..b410aced2 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -31,11 +31,11 @@ struct BadWordImpl : BadWord, Serializable struct BadWordsImpl : BadWords { - Serialize::Reference<ChannelInfo> ci; + Serialize::Reference<ChanServ::Channel> ci; typedef std::vector<BadWordImpl *> list; Serialize::Checker<list> badwords; - BadWordsImpl(Extensible *obj) : ci(anope_dynamic_static_cast<ChannelInfo *>(obj)), badwords("BadWord") { } + BadWordsImpl(Extensible *obj) : ci(anope_dynamic_static_cast<ChanServ::Channel *>(obj)), badwords("BadWord") { } ~BadWordsImpl(); @@ -72,7 +72,7 @@ struct BadWordsImpl : BadWords { if (this->badwords->empty() || index >= this->badwords->size()) return; - + (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, (*this->badwords)[index]); delete this->badwords->at(index); @@ -103,7 +103,7 @@ BadWordsImpl::~BadWordsImpl() BadWordImpl::~BadWordImpl() { - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci) { BadWordsImpl *badwords = ci->GetExt<BadWordsImpl>("badwords"); @@ -123,13 +123,13 @@ Serializable* BadWordImpl::Unserialize(Serializable *obj, Serialize::Data &data) data["ci"] >> sci; data["word"] >> sword; - ChannelInfo *ci = ChannelInfo::Find(sci); + ChanServ::Channel *ci = ChanServ::Find(sci); if (!ci) return NULL; unsigned int n; data["type"] >> n; - + BadWordImpl *bw; if (obj) bw = anope_dynamic_static_cast<BadWordImpl *>(obj); @@ -141,20 +141,20 @@ Serializable* BadWordImpl::Unserialize(Serializable *obj, Serialize::Data &data) BadWordsImpl *bws = ci->Require<BadWordsImpl>("badwords"); bws->badwords->push_back(bw); - + return bw; } class BadwordsDelCallback : public NumberList { CommandSource &source; - ChannelInfo *ci; + ChanServ::Channel *ci; BadWords *bw; Command *c; unsigned deleted; bool override; public: - BadwordsDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), override(false) + BadwordsDelCallback(CommandSource &_source, ChanServ::Channel *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), override(false) { if (!source.AccessFor(ci).HasPriv("BADWORDS") && source.HasPriv("botserv/administration")) this->override = true; @@ -185,7 +185,7 @@ class BadwordsDelCallback : public NumberList class CommandBSBadwords : public Command { private: - void DoList(CommandSource &source, ChannelInfo *ci, const Anope::string &word) + void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "LIST"; @@ -259,7 +259,7 @@ class CommandBSBadwords : public Command } } - void DoAdd(CommandSource &source, ChannelInfo *ci, const Anope::string &word) + void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { size_t pos = word.rfind(' '); BadWordType bwtype = BW_ANY; @@ -308,7 +308,7 @@ class CommandBSBadwords : public Command source.Reply(_("\002%s\002 added to %s bad words list."), realword.c_str(), ci->name.c_str()); } - void DoDelete(CommandSource &source, ChannelInfo *ci, const Anope::string &word) + void DoDelete(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { BadWords *badwords = ci->GetExt<BadWords>("badwords"); @@ -354,7 +354,7 @@ class CommandBSBadwords : public Command badwords->Check(); } - void DoClear(CommandSource &source, ChannelInfo *ci) + void DoClear(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "CLEAR"; @@ -387,7 +387,7 @@ class CommandBSBadwords : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index 9aa572f00..977d4b72f 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -73,7 +73,7 @@ class CommandBSBot : public Command * if so. You need to drop the nick manually before you can use * it as a bot nick from now on -GD */ - if (NickAlias::Find(nick)) + if (NickServ::FindNick(nick)) { source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); return; @@ -176,7 +176,7 @@ class CommandBSBot : public Command * if so. You need to drop the nick manually before you can use * it as a bot nick from now on -GD */ - if (NickAlias::Find(nick)) + if (NickServ::FindNick(nick)) { source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); return; @@ -210,10 +210,10 @@ class CommandBSBot : public Command { IRCD->SendClientIntroduction(bi); unsigned minusers = Config->GetBlock("botserv")->Get<unsigned>("minusers"); - const std::set<ChannelInfo *> &channels = bi->GetChannels(); - for (std::set<ChannelInfo *>::const_iterator it = channels.begin(), it_end = channels.end(); it != it_end; ++it) + const std::set<ChanServ::Channel *> &channels = bi->GetChannels(); + for (std::set<ChanServ::Channel *>::const_iterator it = channels.begin(), it_end = channels.end(); it != it_end; ++it) { - const ChannelInfo *ci = *it; + const ChanServ::Channel *ci = *it; if (ci->c && ci->c->users.size() >= minusers) bi->Join(ci->c); diff --git a/modules/commands/bs_control.cpp b/modules/commands/bs_control.cpp index 38745c191..0311a9df2 100644 --- a/modules/commands/bs_control.cpp +++ b/modules/commands/bs_control.cpp @@ -24,7 +24,7 @@ class CommandBSSay : public Command { const Anope::string &text = params[1]; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -84,7 +84,7 @@ class CommandBSAct : public Command { Anope::string message = params[1]; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index 49775a053..88ac15a48 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -20,18 +20,13 @@ class CommandBSInfo : public Command void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi) { Anope::string buf; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (ChanServ::Channel *ci : bi->GetChannels()) { - const ChannelInfo *ci = it->second; - - if (ci->bi == bi) + buf += " " + ci->name + " "; + if (buf.length() > 300) { - buf += " " + ci->name + " "; - if (buf.length() > 300) - { - buffers.push_back(buf); - buf.clear(); - } + buffers.push_back(buf); + buf.clear(); } } if (!buf.empty()) @@ -51,7 +46,7 @@ class CommandBSInfo : public Command const Anope::string &query = params[0]; BotInfo *bi = BotInfo::Find(query, true); - ChannelInfo *ci = ChannelInfo::Find(query); + ChanServ::Channel *ci = ChanServ::Find(query); InfoFormatter info(source.nc); if (bi) diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 3a4d78c93..7ffd9d353 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -28,15 +28,15 @@ struct KickerDataImpl : KickerData capsmin = capspercent = 0; floodlines = floodsecs = 0; repeattimes = 0; - + dontkickops = dontkickvoices = false; } - void Check(ChannelInfo *ci) override + void Check(ChanServ::Channel *ci) override { if (amsgs || badwords || bolds || caps || colors || flood || italics || repeat || reverses || underlines) return; - + ci->Shrink<KickerData>("kickerdata"); } @@ -46,10 +46,10 @@ struct KickerDataImpl : KickerData void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override { - if (s->GetSerializableType()->GetName() != "ChannelInfo") + if (s->GetSerializableType()->GetName() != "ChanServ::Channel") return; - const ChannelInfo *ci = anope_dynamic_static_cast<const ChannelInfo *>(e); + const ChanServ::Channel *ci = anope_dynamic_static_cast<const ChanServ::Channel *>(e); KickerData *kd = this->Get(ci); if (kd == NULL) return; @@ -76,10 +76,10 @@ struct KickerDataImpl : KickerData void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override { - if (s->GetSerializableType()->GetName() != "ChannelInfo") + if (s->GetSerializableType()->GetName() != "ChanServ::Channel") return; - ChannelInfo *ci = anope_dynamic_static_cast<ChannelInfo *>(e); + ChanServ::Channel *ci = anope_dynamic_static_cast<ChanServ::Channel *>(e); KickerData *kd = ci->Require<KickerData>("kickerdata"); data["kickerdata:amsgs"] >> kd->amsgs; @@ -173,12 +173,12 @@ class CommandBSKickBase : public Command virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) override = 0; protected: - bool CheckArguments(CommandSource &source, const std::vector<Anope::string> ¶ms, ChannelInfo* &ci) + bool CheckArguments(CommandSource &source, const std::vector<Anope::string> ¶ms, ChanServ::Channel* &ci) { const Anope::string &chan = params[0]; const Anope::string &option = params[1]; - ci = ChannelInfo::Find(chan); + ci = ChanServ::Find(chan); if (Anope::ReadOnly) source.Reply(_("Sorry, kicker configuration is temporarily disabled.")); @@ -198,7 +198,7 @@ class CommandBSKickBase : public Command return false; } - void Process(CommandSource &source, ChannelInfo *ci, const Anope::string ¶m, const Anope::string &ttb, size_t ttb_idx, const Anope::string &optname, KickerData *kd, bool &val) + void Process(CommandSource &source, ChanServ::Channel *ci, const Anope::string ¶m, const Anope::string &ttb, size_t ttb_idx, const Anope::string &optname, KickerData *kd, bool &val) { if (param.equals_ci("ON")) { @@ -257,7 +257,7 @@ class CommandBSKickAMSG : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); @@ -293,14 +293,14 @@ class CommandBSKickBadwords : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); Process(source, ci, params[1], params.size() > 2 ? params[2] : "", TTB_BADWORDS, "badwords", kd, kd->badwords); kd->Check(ci); } - + } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -332,7 +332,7 @@ class CommandBSKickBolds : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); @@ -366,7 +366,7 @@ class CommandBSKickCaps : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (!CheckArguments(source, params, ci)) return; @@ -462,7 +462,7 @@ class CommandBSKickColors : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); @@ -496,7 +496,7 @@ class CommandBSKickFlood : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (!CheckArguments(source, params, ci)) return; @@ -594,7 +594,7 @@ class CommandBSKickItalics : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); @@ -628,7 +628,7 @@ class CommandBSKickRepeat : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (!CheckArguments(source, params, ci)) return; @@ -716,7 +716,7 @@ class CommandBSKickReverses : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); @@ -750,7 +750,7 @@ class CommandBSKickUnderlines : public CommandBSKickBase void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci; + ChanServ::Channel *ci; if (CheckArguments(source, params, ci)) { KickerData *kd = ci->Require<KickerData>("kickerdata"); @@ -784,14 +784,14 @@ class CommandBSSetDontKickOps : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); return; } - AccessGroup access = source.AccessFor(ci); + ChanServ::AccessGroup access = source.AccessFor(ci); if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) { source.Reply(ACCESS_DENIED); @@ -808,7 +808,7 @@ class CommandBSSetDontKickOps : public Command if (params[1].equals_ci("ON")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickops"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickops"; kd->dontkickops = true; source.Reply(_("Bot \002won't kick ops\002 on channel %s."), ci->name.c_str()); @@ -816,7 +816,7 @@ class CommandBSSetDontKickOps : public Command else if (params[1].equals_ci("OFF")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickops"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickops"; kd->dontkickops = false; source.Reply(_("Bot \002will kick ops\002 on channel %s."), ci->name.c_str()); @@ -849,14 +849,14 @@ class CommandBSSetDontKickVoices : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); return; } - AccessGroup access = source.AccessFor(ci); + ChanServ::AccessGroup access = source.AccessFor(ci); if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) { source.Reply(ACCESS_DENIED); @@ -873,7 +873,7 @@ class CommandBSSetDontKickVoices : public Command if (params[1].equals_ci("ON")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickvoices"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickvoices"; kd->dontkickvoices = true; source.Reply(_("Bot \002won't kick voices\002 on channel %s."), ci->name.c_str()); @@ -881,7 +881,7 @@ class CommandBSSetDontKickVoices : public Command else if (params[1].equals_ci("OFF")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickvoices"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickvoices"; kd->dontkickvoices = false; source.Reply(_("Bot \002will kick voices\002 on channel %s."), ci->name.c_str()); @@ -1041,7 +1041,7 @@ class BSKick : public Module return ud; } - void check_ban(ChannelInfo *ci, User *u, KickerData *kd, int ttbtype) + void check_ban(ChanServ::Channel *ci, User *u, KickerData *kd, int ttbtype) { /* Don't ban ulines or protected users */ if (u->IsProtected()) @@ -1065,7 +1065,7 @@ class BSKick : public Module } } - void bot_kick(ChannelInfo *ci, User *u, const char *message, ...) + void bot_kick(ChanServ::Channel *ci, User *u, const char *message, ...) { va_list args; char buf[1024]; @@ -1112,7 +1112,7 @@ class BSKick : public Module } - void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override + void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) override { if (!ci) return; @@ -1237,7 +1237,7 @@ class BSKick : public Module * But FIRST we check whether the user is protected in any * way. */ - ChannelInfo *ci = c->ci; + ChanServ::Channel *ci = c->ci; if (ci == NULL) return; KickerData *kd = kickerdata.Get(ci); @@ -1370,7 +1370,7 @@ class BSKick : public Module else { Anope::string wordbuf = " " + bw->word + " "; - + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; } diff --git a/modules/commands/bs_set.cpp b/modules/commands/bs_set.cpp index 68aaf8d47..9c92e462c 100644 --- a/modules/commands/bs_set.cpp +++ b/modules/commands/bs_set.cpp @@ -85,14 +85,14 @@ class CommandBSSetBanExpire : public Command const Anope::string &chan = params[0]; const Anope::string &arg = params[1]; - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return; } - AccessGroup access = source.AccessFor(ci); + ChanServ::AccessGroup access = source.AccessFor(ci); if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) { source.Reply(ACCESS_DENIED); @@ -208,7 +208,7 @@ class BSSet : public Module { } - void OnBotBan(User *u, ChannelInfo *ci, const Anope::string &mask) override + void OnBotBan(User *u, ChanServ::Channel *ci, const Anope::string &mask) override { if (!ci->banexpire) return; diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 3bfbde97d..83d00f6ae 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -10,29 +10,30 @@ */ #include "module.h" +#include "modules/chanserv.h" #include "modules/cs_access.h" static std::map<Anope::string, int16_t, ci::less> defaultLevels; -static inline void reset_levels(ChannelInfo *ci) +static inline void reset_levels(ChanServ::Channel *ci) { ci->ClearLevels(); for (std::map<Anope::string, int16_t, ci::less>::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it) ci->SetLevel(it->first, it->second); } -class AccessChanAccess : public ChanAccess +class AccessChanAccess : public ChanServ::ChanAccess { public: int level; - AccessChanAccess(AccessProvider *p) : ChanAccess(p), level(0) + AccessChanAccess(ChanServ::AccessProvider *p) : ChanAccess(p), level(0) { } bool HasPriv(const Anope::string &name) const override { - return this->ci->GetLevel(name) != ACCESS_INVALID && this->level >= this->ci->GetLevel(name); + return this->ci->GetLevel(name) != ChanServ::ACCESS_INVALID && this->level >= this->ci->GetLevel(name); } Anope::string AccessSerialize() const @@ -51,15 +52,15 @@ class AccessChanAccess : public ChanAccess } } - bool operator>(const ChanAccess &other) const override + bool operator>(const ChanServ::ChanAccess &other) const override { if (this->provider != other.provider) - return ChanAccess::operator>(other); + return ChanServ::ChanAccess::operator>(other); else return this->level > anope_dynamic_static_cast<const AccessChanAccess *>(&other)->level; } - bool operator<(const ChanAccess &other) const override + bool operator<(const ChanServ::ChanAccess &other) const override { if (this->provider != other.provider) return ChanAccess::operator<(other); @@ -68,17 +69,17 @@ class AccessChanAccess : public ChanAccess } }; -class AccessAccessProvider : public AccessProvider +class AccessAccessProvider : public ChanServ::AccessProvider { public: static AccessAccessProvider *me; - AccessAccessProvider(Module *o) : AccessProvider(o, "access/access") + AccessAccessProvider(Module *o) : ChanServ::AccessProvider(o, "access/access") { me = this; } - ChanAccess *Create() override + ChanServ::ChanAccess *Create() override { return new AccessChanAccess(this); } @@ -87,11 +88,11 @@ AccessAccessProvider* AccessAccessProvider::me; class CommandCSAccess : public Command { - void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoAdd(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { Anope::string mask = params[2]; - Privilege *p = NULL; - int level = ACCESS_INVALID; + ChanServ::Privilege *p = NULL; + int level = ChanServ::ACCESS_INVALID; try { @@ -99,7 +100,7 @@ class CommandCSAccess : public Command } catch (const ConvertException &) { - p = PrivilegeManager::FindPrivilege(params[3]); + p = ChanServ::service ? ChanServ::service->FindPrivilege(params[3]) : nullptr; if (p != NULL && defaultLevels[p->name]) level = defaultLevels[p->name]; } @@ -109,14 +110,14 @@ class CommandCSAccess : public Command source.Reply(_("Access level must be non-zero.")); return; } - else if (level <= ACCESS_INVALID || level >= ACCESS_FOUNDER) + else if (level <= ChanServ::ACCESS_INVALID || level >= ChanServ::ACCESS_FOUNDER) { - source.Reply(CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); + source.Reply(CHAN_ACCESS_LEVEL_RANGE, ChanServ::ACCESS_INVALID + 1, ChanServ::ACCESS_FOUNDER - 1); return; } - AccessGroup u_access = source.AccessFor(ci); - const ChanAccess *highest = u_access.Highest(); + ChanServ::AccessGroup u_access = source.AccessFor(ci); + const ChanServ::ChanAccess *highest = u_access.Highest(); AccessChanAccess tmp_access(AccessAccessProvider::me); tmp_access.ci = ci; @@ -143,7 +144,7 @@ class CommandCSAccess : public Command return; } - ChannelInfo *targ_ci = ChannelInfo::Find(mask); + ChanServ::Channel *targ_ci = ChanServ::Find(mask); if (targ_ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, mask.c_str()); @@ -159,7 +160,7 @@ class CommandCSAccess : public Command } else { - const NickAlias *na = NickAlias::Find(mask); + const NickServ::Nick *na = NickServ::FindNick(mask); if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access")) { source.Reply(_("Masks and unregistered users may not be on access lists.")); @@ -180,7 +181,7 @@ class CommandCSAccess : public Command for (unsigned i = ci->GetAccessCount(); i > 0; --i) { - const ChanAccess *access = ci->GetAccess(i - 1); + const ChanServ::ChanAccess *access = ci->GetAccess(i - 1); if (mask.equals_ci(access->mask)) { /* Don't allow lowering from a level >= u_level */ @@ -201,7 +202,7 @@ class CommandCSAccess : public Command return; } - ServiceReference<AccessProvider> provider("AccessProvider", "access/access"); + ServiceReference<ChanServ::AccessProvider> provider("AccessProvider", "access/access"); if (!provider) return; AccessChanAccess *access = anope_dynamic_static_cast<AccessChanAccess *>(provider->Create()); @@ -222,11 +223,11 @@ class CommandCSAccess : public Command source.Reply(_("\002%s\002 added to %s access list at level \002%d\002."), access->mask.c_str(), ci->name.c_str(), level); } - void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoDel(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { Anope::string mask = params[2]; - if (!isdigit(mask[0]) && mask.find_first_of("#!*@") == Anope::string::npos && !NickAlias::Find(mask)) + if (!isdigit(mask[0]) && mask.find_first_of("#!*@") == Anope::string::npos && !NickServ::FindNick(mask)) { User *targ = User::Find(mask, true); if (targ != NULL) @@ -245,14 +246,14 @@ class CommandCSAccess : public Command class AccessDelCallback : public NumberList { CommandSource &source; - ChannelInfo *ci; + ChanServ::Channel *ci; Command *c; unsigned deleted; Anope::string Nicks; bool denied; bool override; public: - AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), denied(false), override(false) + AccessDelCallback(CommandSource &_source, ChanServ::Channel *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), denied(false), override(false) { if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/access/modify")) this->override = true; @@ -280,10 +281,10 @@ class CommandCSAccess : public Command if (!Number || Number > ci->GetAccessCount()) return; - ChanAccess *access = ci->GetAccess(Number - 1); + ChanServ::ChanAccess *access = ci->GetAccess(Number - 1); - AccessGroup ag = source.AccessFor(ci); - const ChanAccess *u_highest = ag.Highest(); + ChanServ::AccessGroup ag = source.AccessFor(ci); + const ChanServ::ChanAccess *u_highest = ag.Highest(); if ((!u_highest || *u_highest <= *access) && !ag.founder && !this->override && !access->mask.equals_ci(source.nc->display)) { @@ -308,12 +309,12 @@ class CommandCSAccess : public Command } else { - AccessGroup u_access = source.AccessFor(ci); - const ChanAccess *highest = u_access.Highest(); + ChanServ::AccessGroup u_access = source.AccessFor(ci); + const ChanServ::ChanAccess *highest = u_access.Highest(); for (unsigned i = ci->GetAccessCount(); i > 0; --i) { - ChanAccess *access = ci->GetAccess(i - 1); + ChanServ::ChanAccess *access = ci->GetAccess(i - 1); if (mask.equals_ci(access->mask)) { if (!access->mask.equals_ci(source.nc->display) && !u_access.founder && (!highest || *highest <= *access) && !source.HasPriv("chanserv/access/modify")) @@ -338,7 +339,7 @@ class CommandCSAccess : public Command return; } - void ProcessList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms, ListFormatter &list) + void ProcessList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms, ListFormatter &list) { const Anope::string &nick = params.size() > 2 ? params[2] : ""; @@ -349,10 +350,10 @@ class CommandCSAccess : public Command class AccessListCallback : public NumberList { ListFormatter &list; - ChannelInfo *ci; + ChanServ::Channel *ci; public: - AccessListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci) + AccessListCallback(ListFormatter &_list, ChanServ::Channel *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci) { } @@ -361,13 +362,13 @@ class CommandCSAccess : public Command if (!number || number > ci->GetAccessCount()) return; - const ChanAccess *access = ci->GetAccess(number - 1); + const ChanServ::ChanAccess *access = ci->GetAccess(number - 1); Anope::string timebuf; if (ci->c) for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) { - ChanAccess::Path p; + ChanServ::ChanAccess::Path p; if (access->Matches(cit->second->user, cit->second->user->Account(), p)) timebuf = "Now"; } @@ -395,7 +396,7 @@ class CommandCSAccess : public Command { for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - const ChanAccess *access = ci->GetAccess(i); + const ChanServ::ChanAccess *access = ci->GetAccess(i); if (!nick.empty() && !Anope::Match(access->mask, nick)) continue; @@ -404,7 +405,7 @@ class CommandCSAccess : public Command if (ci->c) for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) { - ChanAccess::Path p; + ChanServ::ChanAccess::Path p; if (access->Matches(cit->second->user, cit->second->user->Account(), p)) timebuf = "Now"; } @@ -434,7 +435,7 @@ class CommandCSAccess : public Command list.Process(replies); source.Reply(_("Access list for %s:"), ci->name.c_str()); - + for (unsigned i = 0; i < replies.size(); ++i) source.Reply(replies[i]); @@ -444,7 +445,7 @@ class CommandCSAccess : public Command return; } - void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { if (!ci->GetAccessCount()) { @@ -457,7 +458,7 @@ class CommandCSAccess : public Command this->ProcessList(source, ci, params, list); } - void DoView(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoView(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { if (!ci->GetAccessCount()) { @@ -470,7 +471,7 @@ class CommandCSAccess : public Command this->ProcessList(source, ci, params, list); } - void DoClear(CommandSource &source, ChannelInfo *ci) + void DoClear(CommandSource &source, ChanServ::Channel *ci) { if (!source.IsFounder(ci) && !source.HasPriv("chanserv/access/modify")) source.Reply(ACCESS_DENIED); @@ -506,7 +507,7 @@ class CommandCSAccess : public Command const Anope::string &nick = params.size() > 2 ? params[2] : ""; const Anope::string &s = params.size() > 3 ? params[3] : ""; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -526,7 +527,7 @@ class CommandCSAccess : public Command has_access = true; else if (is_del) { - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (na && na->nc == source.GetAccount()) has_access = true; } @@ -612,7 +613,7 @@ class CommandCSAccess : public Command class CommandCSLevels : public Command { - void DoSet(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoSet(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &what = params[2]; const Anope::string &lev = params[3]; @@ -620,7 +621,7 @@ class CommandCSLevels : public Command int level; if (lev.equals_ci("FOUNDER")) - level = ACCESS_FOUNDER; + level = ChanServ::ACCESS_FOUNDER; else { try @@ -634,11 +635,11 @@ class CommandCSLevels : public Command } } - if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER) - source.Reply(_("Level must be between %d and %d inclusive."), ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); + if (level <= ChanServ::ACCESS_INVALID || level > ChanServ::ACCESS_FOUNDER) + source.Reply(_("Level must be between %d and %d inclusive."), ChanServ::ACCESS_INVALID + 1, ChanServ::ACCESS_FOUNDER - 1); else { - Privilege *p = PrivilegeManager::FindPrivilege(what); + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(what) : nullptr; if (p == NULL) source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str()); else @@ -649,7 +650,7 @@ class CommandCSLevels : public Command ci->SetLevel(p->name, level); this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); - if (level == ACCESS_FOUNDER) + if (level == ChanServ::ACCESS_FOUNDER) source.Reply(_("Level for %s on channel %s changed to founder only."), p->name.c_str(), ci->name.c_str()); else source.Reply(_("Level for \002%s\002 on channel %s changed to \002%d\002."), p->name.c_str(), ci->name.c_str(), level); @@ -657,7 +658,7 @@ class CommandCSLevels : public Command } } - void DoDisable(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoDisable(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &what = params[2]; @@ -668,14 +669,14 @@ class CommandCSLevels : public Command return; } - Privilege *p = PrivilegeManager::FindPrivilege(what); + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(what) : nullptr; if (p != NULL) { bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable " << p->name; - ci->SetLevel(p->name, ACCESS_INVALID); - this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, ACCESS_INVALID); + ci->SetLevel(p->name, ChanServ::ACCESS_INVALID); + this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID); source.Reply(_("\002%s\002 disabled on channel %s."), p->name.c_str(), ci->name.c_str()); return; @@ -684,26 +685,29 @@ class CommandCSLevels : public Command source.Reply(_("Setting \002%s\002 not known. Type \002%s%s HELP LEVELS\002 for a list of valid settings."), what.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str()); } - void DoList(CommandSource &source, ChannelInfo *ci) + void DoList(CommandSource &source, ChanServ::Channel *ci) { + if (!ChanServ::service) + return; + source.Reply(_("Access level settings for channel %s:"), ci->name.c_str()); ListFormatter list(source.GetAccount()); list.AddColumn(_("Name")).AddColumn(_("Level")); - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); + const std::vector<ChanServ::Privilege> &privs = ChanServ::service->GetPrivileges(); for (unsigned i = 0; i < privs.size(); ++i) { - const Privilege &p = privs[i]; + const ChanServ::Privilege &p = privs[i]; int16_t j = ci->GetLevel(p.name); ListFormatter::ListEntry entry; entry["Name"] = p.name; - if (j == ACCESS_INVALID) + if (j == ChanServ::ACCESS_INVALID) entry["Level"] = Language::Translate(source.GetAccount(), _("(disabled)")); - else if (j == ACCESS_FOUNDER) + else if (j == ChanServ::ACCESS_FOUNDER) entry["Level"] = Language::Translate(source.GetAccount(), _("(founder only)")); else entry["Level"] = stringify(j); @@ -718,7 +722,7 @@ class CommandCSLevels : public Command source.Reply(replies[i]); } - void DoReset(CommandSource &source, ChannelInfo *ci) + void DoReset(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to reset all levels"; @@ -747,7 +751,7 @@ class CommandCSLevels : public Command const Anope::string &what = params.size() > 2 ? params[2] : ""; const Anope::string &s = params.size() > 3 ? params[3] : ""; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -786,14 +790,17 @@ class CommandCSLevels : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Name")).AddColumn(_("Description")); - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = 0; i < privs.size(); ++i) + if (ChanServ::service) { - const Privilege &p = privs[i]; - ListFormatter::ListEntry entry; - entry["Name"] = p.name; - entry["Description"] = Language::Translate(source.nc, p.desc.c_str()); - list.AddEntry(entry); + const std::vector<ChanServ::Privilege> &privs = ChanServ::service->GetPrivileges(); + for (unsigned i = 0; i < privs.size(); ++i) + { + const ChanServ::Privilege &p = privs[i]; + ListFormatter::ListEntry entry; + entry["Name"] = p.name; + entry["Description"] = Language::Translate(source.nc, p.desc.c_str()); + list.AddEntry(entry); + } } std::vector<Anope::string> replies; @@ -862,7 +869,7 @@ class CSAccess : public Module const Anope::string &pname = priv->Get<const Anope::string>("name"); - Privilege *p = PrivilegeManager::FindPrivilege(pname); + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(pname) : nullptr; if (p == NULL) continue; @@ -870,20 +877,20 @@ class CSAccess : public Module if (value.empty()) continue; else if (value.equals_ci("founder")) - defaultLevels[p->name] = ACCESS_FOUNDER; + defaultLevels[p->name] = ChanServ::ACCESS_FOUNDER; else if (value.equals_ci("disabled")) - defaultLevels[p->name] = ACCESS_INVALID; + defaultLevels[p->name] = ChanServ::ACCESS_INVALID; else defaultLevels[p->name] = priv->Get<int16_t>("level"); } } - void OnCreateChan(ChannelInfo *ci) override + void OnCreateChan(ChanServ::Channel *ci) override { reset_levels(ci); } - EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) override + EventReturn OnGroupCheckPriv(const ChanServ::AccessGroup *group, const Anope::string &priv) override { if (group->ci == NULL) return EVENT_CONTINUE; diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 61bc23181..b548d87a9 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -12,15 +12,89 @@ #include "module.h" #include "modules/cs_akick.h" +class AutoKickImpl : public AutoKick +{ + public: + ~AutoKickImpl() + { + if (this->ci) + { + std::vector<AutoKick *>::iterator it = std::find(this->ci->akick->begin(), this->ci->akick->end(), this); + if (it != this->ci->akick->end()) + this->ci->akick->erase(it); + + const NickServ::Nick *na = NickServ::FindNick(this->mask); + if (na != NULL) + na->nc->RemoveChannelReference(this->ci); + } + } + + void Serialize(Serialize::Data &data) const override + { + data["ci"] << this->ci->name; + if (this->nc) + data["nc"] << this->nc->display; + else + data["mask"] << this->mask; + data["reason"] << this->reason; + data["creator"] << this->creator; + data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime; + data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used; + } + + static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) + { + Anope::string sci, snc; + + data["ci"] >> sci; + data["nc"] >> snc; + + ChanServ::Channel *ci = ChanServ::Find(sci); + if (!ci) + return NULL; + + AutoKick *ak; + NickServ::Account *nc = NickServ::FindAccount(snc); + if (obj) + { + ak = anope_dynamic_static_cast<AutoKick *>(obj); + data["creator"] >> ak->creator; + data["reason"] >> ak->reason; + ak->nc = NickServ::FindAccount(snc); + data["mask"] >> ak->mask; + data["addtime"] >> ak->addtime; + data["last_used"] >> ak->last_used; + } + else + { + time_t addtime, lastused; + data["addtime"] >> addtime; + data["last_used"] >> lastused; + + Anope::string screator, sreason, smask; + + data["creator"] >> screator; + data["reason"] >> sreason; + data["mask"] >> smask; + + if (nc) + ak = ci->AddAkick(screator, nc, sreason, addtime, lastused); + else + ak = ci->AddAkick(screator, smask, sreason, addtime, lastused); + } + + return ak; + } +}; + class CommandCSAKick : public Command { - void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoAdd(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { Anope::string mask = params[2]; Anope::string reason = params.size() > 3 ? params[3] : ""; - const NickAlias *na = NickAlias::Find(mask); - NickCore *nc = NULL; - const AutoKick *akick; + const NickServ::Nick *na = NickServ::FindNick(mask); + NickServ::Account *nc = NULL; unsigned reasonmax = Config->GetModule("chanserv")->Get<unsigned>("reasonmax", "200"); if (reason.length() > reasonmax) @@ -59,7 +133,7 @@ class CommandCSAKick : public Command } Entry e("", mask); - + mask = (e.nick.empty() ? "*" : e.nick) + "!" + (e.user.empty() ? "*" : e.user) + "@" + (e.host.empty() ? "*" : e.host); @@ -94,7 +168,7 @@ class CommandCSAKick : public Command * or whether the mask matches a user with higher/equal access - Viper */ else if (ci->HasExt("PEACE") && nc) { - AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); + ChanServ::AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); if (nc == ci->GetFounder() || nc_access >= u_access) { source.Reply(ACCESS_DENIED); @@ -103,13 +177,14 @@ class CommandCSAKick : public Command } else if (ci->HasExt("PEACE")) { +#if 0 /* Match against all currently online users with equal or * higher access. - Viper */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u2 = it->second; - AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); + ChanServ::AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); Entry entry_mask("", mask); if ((ci->AccessFor(u2).HasPriv("FOUNDER") || nc_access >= u_access) && entry_mask.Matches(u2)) @@ -121,11 +196,11 @@ class CommandCSAKick : public Command /* Match against the lastusermask of all nickalias's with equal * or higher access. - Viper */ - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (nickalias_map::const_iterator it = NickServ::NickList->begin(), it_end = NickServ::NickList->end(); it != it_end; ++it) { na = it->second; - AccessGroup nc_access = ci->AccessFor(na->nc), u_access = source.AccessFor(ci); + ChanServ::AccessGroup nc_access = ci->AccessFor(na->nc), u_access = source.AccessFor(ci); if (na->nc && (na->nc == ci->GetFounder() || nc_access >= u_access)) { Anope::string buf = na->nick + "!" + na->last_usermask; @@ -136,14 +211,15 @@ class CommandCSAKick : public Command } } } +#endif } for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j) { - akick = ci->GetAkick(j); - if (akick->nc ? akick->nc == nc : mask.equals_ci(akick->mask)) + AutoKick *ak = ci->GetAkick(j); + if (ak->nc ? ak->nc == nc : mask.equals_ci(ak->mask)) { - source.Reply(_("\002%s\002 already exists on %s autokick list."), akick->nc ? akick->nc->display.c_str() : akick->mask.c_str(), ci->name.c_str()); + source.Reply(_("\002%s\002 already exists on %s autokick list."), ak->nc ? ak->nc->display.c_str() : ak->mask.c_str(), ci->name.c_str()); return; } } @@ -154,21 +230,22 @@ class CommandCSAKick : public Command return; } + AutoKick *ak; if (nc) - akick = ci->AddAkick(source.GetNick(), nc, reason); + ak = ci->AddAkick(source.GetNick(), nc, reason); else - akick = ci->AddAkick(source.GetNick(), mask, reason); + ak = ci->AddAkick(source.GetNick(), mask, reason); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason; - this->akickevents(&Event::Akick::OnAkickAdd, source, ci, akick); + this->akickevents(&Event::Akick::OnAkickAdd, source, ci, ak); source.Reply(_("\002%s\002 added to %s autokick list."), mask.c_str(), ci->name.c_str()); this->DoEnforce(source, ci); } - void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoDel(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &mask = params[2]; unsigned i, end; @@ -185,12 +262,12 @@ class CommandCSAKick : public Command class AkickDelCallback : public NumberList { CommandSource &source; - ChannelInfo *ci; + ChanServ::Channel *ci; CommandCSAKick *c; unsigned deleted; - AccessGroup ag; + ChanServ::AccessGroup ag; public: - AkickDelCallback(CommandSource &_source, ChannelInfo *_ci, CommandCSAKick *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), ag(source.AccessFor(ci)) + AkickDelCallback(CommandSource &_source, ChanServ::Channel *_ci, CommandCSAKick *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), ag(source.AccessFor(ci)) { } @@ -209,12 +286,12 @@ class CommandCSAKick : public Command if (!number || number > ci->GetAkickCount()) return; - const AutoKick *akick = ci->GetAkick(number - 1); + const AutoKick *ak = ci->GetAkick(number - 1); - c->akickevents(&Event::Akick::OnAkickDel, source, ci, akick); + c->akickevents(&Event::Akick::OnAkickDel, source, ci, ak); bool override = !ag.HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, c, ci) << "to delete " << (akick->nc ? akick->nc->display : akick->mask); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, c, ci) << "to delete " << (ak->nc ? ak->nc->display : ak->mask); ++deleted; ci->EraseAkick(number - 1); @@ -225,14 +302,14 @@ class CommandCSAKick : public Command } else { - const NickAlias *na = NickAlias::Find(mask); - const NickCore *nc = na ? *na->nc : NULL; + const NickServ::Nick *na = NickServ::FindNick(mask); + const NickServ::Account *nc = na ? *na->nc : NULL; for (i = 0, end = ci->GetAkickCount(); i < end; ++i) { - const AutoKick *akick = ci->GetAkick(i); + const AutoKick *ak = ci->GetAkick(i); - if (akick->nc ? akick->nc == nc : mask.equals_ci(akick->mask)) + if (ak->nc ? ak->nc == nc : mask.equals_ci(ak->mask)) break; } @@ -253,7 +330,7 @@ class CommandCSAKick : public Command } } - void ProcessList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms, ListFormatter &list) + void ProcessList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms, ListFormatter &list) { const Anope::string &mask = params.size() > 2 ? params[2] : ""; @@ -262,10 +339,10 @@ class CommandCSAKick : public Command class AkickListCallback : public NumberList { ListFormatter &list; - ChannelInfo *ci; + ChanServ::Channel *ci; public: - AkickListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci) + AkickListCallback(ListFormatter &_list, ChanServ::Channel *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci) { } @@ -273,29 +350,29 @@ class CommandCSAKick : public Command { if (!number || number > ci->GetAkickCount()) return; - - const AutoKick *akick = ci->GetAkick(number - 1); + + const AutoKick *ak = ci->GetAkick(number - 1); Anope::string timebuf, lastused; - if (akick->addtime) - timebuf = Anope::strftime(akick->addtime, NULL, true); + if (ak->addtime) + timebuf = Anope::strftime(ak->addtime, NULL, true); else timebuf = UNKNOWN; - if (akick->last_used) - lastused = Anope::strftime(akick->last_used, NULL, true); + if (ak->last_used) + lastused = Anope::strftime(ak->last_used, NULL, true); else lastused = UNKNOWN; ListFormatter::ListEntry entry; entry["Number"] = stringify(number); - if (akick->nc) - entry["Mask"] = akick->nc->display; + if (ak->nc) + entry["Mask"] = ak->nc->display; else - entry["Mask"] = akick->mask; - entry["Creator"] = akick->creator; + entry["Mask"] = ak->mask; + entry["Creator"] = ak->creator; entry["Created"] = timebuf; entry["Last used"] = lastused; - entry["Reason"] = akick->reason; + entry["Reason"] = ak->reason; this->list.AddEntry(entry); } } @@ -306,36 +383,36 @@ class CommandCSAKick : public Command { for (unsigned i = 0, end = ci->GetAkickCount(); i < end; ++i) { - const AutoKick *akick = ci->GetAkick(i); + const AutoKick *ak = ci->GetAkick(i); if (!mask.empty()) { - if (!akick->nc && !Anope::Match(akick->mask, mask)) + if (!ak->nc && !Anope::Match(ak->mask, mask)) continue; - if (akick->nc && !Anope::Match(akick->nc->display, mask)) + if (ak->nc && !Anope::Match(ak->nc->display, mask)) continue; } Anope::string timebuf, lastused; - if (akick->addtime) - timebuf = Anope::strftime(akick->addtime, NULL, true); + if (ak->addtime) + timebuf = Anope::strftime(ak->addtime, NULL, true); else timebuf = UNKNOWN; - if (akick->last_used) - lastused = Anope::strftime(akick->last_used, NULL, true); + if (ak->last_used) + lastused = Anope::strftime(ak->last_used, NULL, true); else lastused = UNKNOWN; ListFormatter::ListEntry entry; entry["Number"] = stringify(i + 1); - if (akick->nc) - entry["Mask"] = akick->nc->display; + if (ak->nc) + entry["Mask"] = ak->nc->display; else - entry["Mask"] = akick->mask; - entry["Creator"] = akick->creator; + entry["Mask"] = ak->mask; + entry["Creator"] = ak->creator; entry["Created"] = timebuf; entry["Last used"] = lastused; - entry["Reason"] = akick->reason; + entry["Reason"] = ak->reason; list.AddEntry(entry); } } @@ -348,7 +425,7 @@ class CommandCSAKick : public Command list.Process(replies); source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - + for (unsigned i = 0; i < replies.size(); ++i) source.Reply(replies[i]); @@ -356,7 +433,7 @@ class CommandCSAKick : public Command } } - void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { if (!ci->GetAkickCount()) { @@ -369,7 +446,7 @@ class CommandCSAKick : public Command this->ProcessList(source, ci, params, list); } - void DoView(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoView(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { if (!ci->GetAkickCount()) { @@ -382,7 +459,7 @@ class CommandCSAKick : public Command this->ProcessList(source, ci, params, list); } - void DoEnforce(CommandSource &source, ChannelInfo *ci) + void DoEnforce(CommandSource &source, ChanServ::Channel *ci) { Channel *c = ci->c; int count = 0; @@ -408,7 +485,7 @@ class CommandCSAKick : public Command source.Reply(_("AKICK ENFORCE for \002%s\002 complete; \002%d\002 users were affected."), ci->name.c_str(), count); } - void DoClear(CommandSource &source, ChannelInfo *ci) + void DoClear(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the akick list"; @@ -437,7 +514,7 @@ class CommandCSAKick : public Command Anope::string cmd = params[1]; Anope::string mask = params.size() > 2 ? params[2] : ""; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -512,17 +589,26 @@ class CommandCSAKick : public Command }; class CSAKick : public Module + , public AutoKickService , public EventHook<Event::CheckKick> { CommandCSAKick commandcsakick; EventHandlers<Event::Akick> akickevents; + Serialize::Type akick_type; public: CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , AutoKickService(this) , EventHook<Event::CheckKick>("OnCheckKick") , commandcsakick(this, akickevents) , akickevents(this, "Akick") + , akick_type("AutoKick", AutoKickImpl::Unserialize) + { + } + + AutoKick* Create() override { + return new AutoKickImpl(); } EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override diff --git a/modules/commands/cs_ban.cpp b/modules/commands/cs_ban.cpp index a6a1f4af6..e85afc4a0 100644 --- a/modules/commands/cs_ban.cpp +++ b/modules/commands/cs_ban.cpp @@ -44,7 +44,7 @@ class CommandCSBan : public Command { const Anope::string &chan = params[0]; - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -101,13 +101,13 @@ class CommandCSBan : public Command User *u = source.GetUser(); User *u2 = User::Find(target, true); - AccessGroup u_access = source.AccessFor(ci); + ChanServ::AccessGroup u_access = source.AccessFor(ci); if (!u_access.HasPriv("BAN") && !source.HasPriv("chanserv/kick")) source.Reply(ACCESS_DENIED); else if (u2) { - AccessGroup u2_access = ci->AccessFor(u2); + ChanServ::AccessGroup u2_access = ci->AccessFor(u2); if (u != u2 && ci->HasExt("PEACE") && u2_access >= u_access && !source.HasPriv("chanserv/kick")) source.Reply(ACCESS_DENIED); @@ -172,7 +172,7 @@ class CommandCSBan : public Command { ++matched; - AccessGroup u2_access = ci->AccessFor(uc->user); + ChanServ::AccessGroup u2_access = ci->AccessFor(uc->user); if (matched > 1 && !founder) continue; diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp index e7102091a..bd7a6c990 100644 --- a/modules/commands/cs_clone.cpp +++ b/modules/commands/cs_clone.cpp @@ -11,6 +11,7 @@ #include "module.h" #include "modules/bs_badwords.h" +#include "modules/cs_akick.h" class CommandCSClone : public Command { @@ -34,7 +35,7 @@ public: } User *u = source.GetUser(); - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); bool override = false; if (ci == NULL) @@ -43,7 +44,7 @@ public: return; } - ChannelInfo *target_ci = ChannelInfo::Find(target); + ChanServ::Channel *target_ci = ChanServ::Find(target); if (!target_ci) { source.Reply(CHAN_X_NOT_REGISTERED, target.c_str()); @@ -73,9 +74,10 @@ public: if (what.empty()) { delete target_ci; - target_ci = new ChannelInfo(*ci); + target_ci = ChanServ::service->Create(*ci); target_ci->name = target; - (*RegisteredChannelList)[target_ci->name] = target_ci; + ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); + map[target_ci->name] = target_ci; target_ci->c = Channel::Find(target_ci->name); target_ci->bi = NULL; @@ -115,8 +117,8 @@ public: for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { - const ChanAccess *taccess = ci->GetAccess(i); - AccessProvider *provider = taccess->provider; + const ChanServ::ChanAccess *taccess = ci->GetAccess(i); + ChanServ::AccessProvider *provider = taccess->provider; if (access_max && target_ci->GetDeepAccessCount() >= access_max) break; @@ -125,7 +127,7 @@ public: continue; masks.insert(taccess->mask); - ChanAccess *newaccess = provider->Create(); + ChanServ::ChanAccess *newaccess = provider->Create(); newaccess->ci = target_ci; newaccess->mask = taccess->mask; newaccess->creator = taccess->creator; @@ -145,11 +147,11 @@ public: target_ci->ClearAkick(); for (unsigned i = 0; i < ci->GetAkickCount(); ++i) { - const AutoKick *akick = ci->GetAkick(i); - if (akick->nc) - target_ci->AddAkick(akick->creator, akick->nc, akick->reason, akick->addtime, akick->last_used); + const AutoKick *ak = ci->GetAkick(i); + if (ak->nc) + target_ci->AddAkick(ak->creator, ak->nc, ak->reason, ak->addtime, ak->last_used); else - target_ci->AddAkick(akick->creator, akick->mask, akick->reason, akick->addtime, akick->last_used); + target_ci->AddAkick(ak->creator, ak->mask, ak->reason, ak->addtime, ak->last_used); } source.Reply(_("All akick entries from \002%s\002 have been cloned to \002%s\002."), channel.c_str(), target.c_str()); diff --git a/modules/commands/cs_drop.cpp b/modules/commands/cs_drop.cpp index 3b6c82ed0..55a28f294 100644 --- a/modules/commands/cs_drop.cpp +++ b/modules/commands/cs_drop.cpp @@ -33,7 +33,7 @@ class CommandCSDrop : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index aa710ef03..52b9093ca 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -16,7 +16,7 @@ class CommandCSEnforce : public Command { private: - void DoSecureOps(CommandSource &source, ChannelInfo *ci) + void DoSecureOps(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce secureops"; @@ -42,7 +42,7 @@ class CommandCSEnforce : public Command source.Reply(_("Secureops enforced on %s."), ci->name.c_str()); } - void DoRestricted(CommandSource &source, ChannelInfo *ci) + void DoRestricted(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce restricted"; @@ -61,7 +61,7 @@ class CommandCSEnforce : public Command } for (unsigned i = 0; i < users.size(); ++i) - { + { User *user = users[i]; Anope::string mask = ci->GetIdealBan(user); @@ -73,7 +73,7 @@ class CommandCSEnforce : public Command source.Reply(_("Restricted enforced on %s."), ci->name.c_str()); } - void DoRegOnly(CommandSource &source, ChannelInfo *ci) + void DoRegOnly(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce registered only"; @@ -105,7 +105,7 @@ class CommandCSEnforce : public Command source.Reply(_("Registered only enforced on %s."), ci->name.c_str()); } - void DoSSLOnly(CommandSource &source, ChannelInfo *ci) + void DoSSLOnly(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce SSL only"; @@ -137,7 +137,7 @@ class CommandCSEnforce : public Command source.Reply(_("SSL only enforced on %s."), ci->name.c_str()); } - void DoBans(CommandSource &source, ChannelInfo *ci) + void DoBans(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce bans"; @@ -158,7 +158,7 @@ class CommandCSEnforce : public Command for (unsigned i = 0; i < users.size(); ++i) { User *user = users[i]; - + Anope::string reason = Language::Translate(user, _("BANS enforced by ")) + source.GetNick(); ci->c->Kick(NULL, user, "%s", reason.c_str()); } @@ -166,7 +166,7 @@ class CommandCSEnforce : public Command source.Reply(_("Bans enforced on %s."), ci->name.c_str()); } - void DoLimit(CommandSource &source, ChannelInfo *ci) + void DoLimit(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce limit"; @@ -213,7 +213,7 @@ class CommandCSEnforce : public Command for (unsigned i = 0; i < users.size(); ++i) { User *user = users[i]; - + Anope::string reason = Language::Translate(user, _("LIMIT enforced by ")) + source.GetNick(); ci->c->Kick(NULL, user, "%s", reason.c_str()); } @@ -232,7 +232,7 @@ class CommandCSEnforce : public Command { const Anope::string &what = params.size() > 1 ? params[1] : ""; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (!ci) source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index 676d7b74a..8e196d18b 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -18,7 +18,7 @@ struct EntryMsgImpl : EntryMsg, Serializable { } - EntryMsgImpl(ChannelInfo *c, const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime) : Serializable("EntryMsg") + EntryMsgImpl(ChanServ::Channel *c, const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime) : Serializable("EntryMsg") { this->chan = c->name; this->creator = cname; @@ -51,7 +51,7 @@ struct EntryMessageListImpl : EntryMessageList EntryMsgImpl::~EntryMsgImpl() { - ChannelInfo *ci = ChannelInfo::Find(this->chan); + ChanServ::Channel *ci = ChanServ::Find(this->chan); if (!ci) return; @@ -74,7 +74,7 @@ Serializable* EntryMsgImpl::Unserialize(Serializable *obj, Serialize::Data &data data["creator"] >> screator; data["message"] >> smessage; - ChannelInfo *ci = ChannelInfo::Find(sci); + ChanServ::Channel *ci = ChanServ::Find(sci); if (!ci) return NULL; @@ -100,7 +100,7 @@ Serializable* EntryMsgImpl::Unserialize(Serializable *obj, Serialize::Data &data class CommandEntryMessage : public Command { private: - void DoList(CommandSource &source, ChannelInfo *ci) + void DoList(CommandSource &source, ChanServ::Channel *ci) { EntryMessageList *messages = ci->Require<EntryMessageList>("entrymsg"); @@ -133,8 +133,8 @@ class CommandEntryMessage : public Command source.Reply(_("End of entry message list.")); } - - void DoAdd(CommandSource &source, ChannelInfo *ci, const Anope::string &message) + + void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message) { EntryMessageList *messages = ci->Require<EntryMessageList>("entrymsg"); @@ -148,7 +148,7 @@ class CommandEntryMessage : public Command } } - void DoDel(CommandSource &source, ChannelInfo *ci, const Anope::string &message) + void DoDel(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message) { EntryMessageList *messages = ci->Require<EntryMessageList>("entrymsg"); @@ -179,7 +179,7 @@ class CommandEntryMessage : public Command } } - void DoClear(CommandSource &source, ChannelInfo *ci) + void DoClear(CommandSource &source, ChanServ::Channel *ci) { ci->Shrink<EntryMessageList>("entrymsg"); @@ -199,7 +199,7 @@ class CommandEntryMessage : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index 1298f74c5..2c5cfa547 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -13,12 +13,12 @@ static std::map<Anope::string, char> defaultFlags; -class FlagsChanAccess : public ChanAccess +class FlagsChanAccess : public ChanServ::ChanAccess { public: std::set<char> flags; - FlagsChanAccess(AccessProvider *p) : ChanAccess(p) + FlagsChanAccess(ChanServ::AccessProvider *p) : ChanAccess(p) { } @@ -41,11 +41,11 @@ class FlagsChanAccess : public ChanAccess this->flags.insert(data[i - 1]); } - static Anope::string DetermineFlags(const ChanAccess *access) + static Anope::string DetermineFlags(const ChanServ::ChanAccess *access) { if (access->provider->name == "access/flags") return access->AccessSerialize(); - + std::set<char> buffer; for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) @@ -59,17 +59,17 @@ class FlagsChanAccess : public ChanAccess } }; -class FlagsAccessProvider : public AccessProvider +class FlagsAccessProvider : public ChanServ::AccessProvider { public: static FlagsAccessProvider *ap; - FlagsAccessProvider(Module *o) : AccessProvider(o, "access/flags") + FlagsAccessProvider(Module *o) : ChanServ::AccessProvider(o, "access/flags") { ap = this; } - ChanAccess *Create() override + ChanServ::ChanAccess *Create() override { return new FlagsChanAccess(this); } @@ -78,7 +78,7 @@ FlagsAccessProvider* FlagsAccessProvider::ap; class CommandCSFlags : public Command { - void DoModify(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoModify(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { Anope::string mask = params.size() > 2 ? params[2] : ""; Anope::string flags = params.size() > 3 ? params[3] : ""; @@ -89,8 +89,8 @@ class CommandCSFlags : public Command return; } - AccessGroup u_access = source.AccessFor(ci); - const ChanAccess *highest = u_access.Highest(); + ChanServ::AccessGroup u_access = source.AccessFor(ci); + const ChanServ::ChanAccess *highest = u_access.Highest(); if (IRCD->IsChannelValid(mask)) { @@ -100,7 +100,7 @@ class CommandCSFlags : public Command return; } - ChannelInfo *targ_ci = ChannelInfo::Find(mask); + ChanServ::Channel *targ_ci = ChanServ::Find(mask); if (targ_ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, mask.c_str()); @@ -116,7 +116,7 @@ class CommandCSFlags : public Command } else { - const NickAlias *na = NickAlias::Find(mask); + const NickServ::Nick *na = NickServ::FindNick(mask); if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access")) { source.Reply(_("Masks and unregistered users may not be on access lists.")); @@ -135,13 +135,13 @@ class CommandCSFlags : public Command } } - ChanAccess *current = NULL; + ChanServ::ChanAccess *current = NULL; unsigned current_idx; std::set<char> current_flags; bool override = false; for (current_idx = ci->GetAccessCount(); current_idx > 0; --current_idx) { - ChanAccess *access = ci->GetAccess(current_idx - 1); + ChanServ::ChanAccess *access = ci->GetAccess(current_idx - 1); if (mask.equals_ci(access->mask)) { // Flags allows removing others that have the same access as you, @@ -174,7 +174,7 @@ class CommandCSFlags : public Command return; } - Privilege *p = NULL; + ChanServ::Privilege *p = NULL; bool add = true; for (size_t i = 0; i < flags.length(); ++i) { @@ -210,7 +210,7 @@ class CommandCSFlags : public Command } break; default: - p = PrivilegeManager::FindPrivilege(flags.substr(i)); + p = ChanServ::service ? ChanServ::service->FindPrivilege(flags.substr(i)) : nullptr; if (p != NULL && defaultFlags[p->name]) { f = defaultFlags[p->name]; @@ -256,7 +256,7 @@ class CommandCSFlags : public Command return; } - ServiceReference<AccessProvider> provider("AccessProvider", "access/flags"); + ServiceReference<ChanServ::AccessProvider> provider("AccessProvider", "access/flags"); if (!provider) return; FlagsChanAccess *access = anope_dynamic_static_cast<FlagsChanAccess *>(provider->Create()); @@ -286,7 +286,7 @@ class CommandCSFlags : public Command source.Reply(_("Flags for \002%s\002 on %s set to +\002%s\002"), access->mask.c_str(), ci->name.c_str(), access->AccessSerialize().c_str()); } - void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &arg = params.size() > 2 ? params[2] : ""; @@ -303,7 +303,7 @@ class CommandCSFlags : public Command unsigned count = 0; for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - const ChanAccess *access = ci->GetAccess(i); + const ChanServ::ChanAccess *access = ci->GetAccess(i); const Anope::string &flags = FlagsChanAccess::DetermineFlags(access); if (!arg.empty()) @@ -348,7 +348,7 @@ class CommandCSFlags : public Command } } - void DoClear(CommandSource &source, ChannelInfo *ci) + void DoClear(CommandSource &source, ChanServ::Channel *ci) { if (!source.IsFounder(ci) && !source.HasPriv("chanserv/access/modify")) source.Reply(ACCESS_DENIED); @@ -381,7 +381,7 @@ class CommandCSFlags : public Command const Anope::string &chan = params[0]; const Anope::string &cmd = params.size() > 1 ? params[1] : ""; - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -441,7 +441,7 @@ class CommandCSFlags : public Command for (reverse_map::iterator it = reverse.begin(), it_end = reverse.end(); it != it_end; ++it) { - Privilege *p = PrivilegeManager::FindPrivilege(it->second); + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(it->second) : nullptr; if (p == NULL) continue; source.Reply(" %c - %s", it->first, Language::Translate(source.nc, p->desc.c_str())); @@ -475,7 +475,7 @@ class CSFlags : public Module const Anope::string &pname = priv->Get<const Anope::string>("name"); - Privilege *p = PrivilegeManager::FindPrivilege(pname); + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(pname) : nullptr; if (p == NULL) continue; diff --git a/modules/commands/cs_getkey.cpp b/modules/commands/cs_getkey.cpp index 6b714d093..122035acc 100644 --- a/modules/commands/cs_getkey.cpp +++ b/modules/commands/cs_getkey.cpp @@ -24,7 +24,7 @@ class CommandCSGetKey : public Command { const Anope::string &chan = params[0]; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp index d0ae17a7e..2b974ef1d 100644 --- a/modules/commands/cs_info.cpp +++ b/modules/commands/cs_info.cpp @@ -28,8 +28,8 @@ class CommandCSInfo : public Command { const Anope::string &chan = params[0]; - NickCore *nc = source.nc; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + NickServ::Account *nc = source.nc; + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/cs_invite.cpp b/modules/commands/cs_invite.cpp index 6f19042cc..9e0168b53 100644 --- a/modules/commands/cs_invite.cpp +++ b/modules/commands/cs_invite.cpp @@ -33,7 +33,7 @@ class CommandCSInvite : public Command return; } - ChannelInfo *ci = c->ci; + ChanServ::Channel *ci = c->ci; if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); diff --git a/modules/commands/cs_kick.cpp b/modules/commands/cs_kick.cpp index bfaec6a29..9828c79fa 100644 --- a/modules/commands/cs_kick.cpp +++ b/modules/commands/cs_kick.cpp @@ -28,7 +28,7 @@ class CommandCSKick : public Command Anope::string reason = params.size() > 2 ? params[2] : "Requested"; User *u = source.GetUser(); - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); Channel *c = Channel::Find(params[0]); User *u2 = User::Find(target, true); @@ -47,13 +47,13 @@ class CommandCSKick : public Command if (reason.length() > reasonmax) reason = reason.substr(0, reasonmax); - AccessGroup u_access = source.AccessFor(ci); + ChanServ::AccessGroup u_access = source.AccessFor(ci); if (!u_access.HasPriv("KICK") && !source.HasPriv("chanserv/kick")) source.Reply(ACCESS_DENIED); else if (u2) { - AccessGroup u2_access = ci->AccessFor(u2); + ChanServ::AccessGroup u2_access = ci->AccessFor(u2); if (u != u2 && ci->HasExt("PEACE") && u2_access >= u_access && !source.HasPriv("chanserv/kick")) source.Reply(ACCESS_DENIED); else if (u2->IsProtected()) @@ -85,7 +85,7 @@ class CommandCSKick : public Command { ++matched; - AccessGroup u2_access = ci->AccessFor(uc->user); + ChanServ::AccessGroup u2_access = ci->AccessFor(uc->user); if (u != uc->user && ci->HasExt("PEACE") && u2_access >= u_access) continue; else if (uc->user->IsProtected()) diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp index 68cca6d42..f97e6e065 100644 --- a/modules/commands/cs_list.cpp +++ b/modules/commands/cs_list.cpp @@ -75,13 +75,14 @@ class CommandCSList : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Name")).AddColumn(_("Description")); - Anope::map<ChannelInfo *> ordered_map; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) - ordered_map[it->first] = it->second; + Anope::map<ChanServ::Channel *> ordered_map; + if (ChanServ::service) + for (auto& it : ChanServ::service->GetChannels()) + ordered_map[it.first] = it.second; - for (Anope::map<ChannelInfo *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) + for (Anope::map<ChanServ::Channel *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) { - const ChannelInfo *ci = it->second; + const ChanServ::Channel *ci = it->second; if (!is_servadmin) { @@ -185,7 +186,7 @@ class CommandCSSetPrivate : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -225,7 +226,7 @@ class CommandCSSetPrivate : public Command this->SendSyntax(source); source.Reply(" "); source.Reply(_("Enables or disables the \002private\002 option for a channel.")); - + BotInfo *bi; Anope::string cmd; if (Command::FindCommandFromService("chanserv/list", bi, cmd)) @@ -252,7 +253,7 @@ class CSList : public Module { } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_all) override { if (!show_all) return; diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp index 678a2fd5f..39e6a31b5 100644 --- a/modules/commands/cs_log.cpp +++ b/modules/commands/cs_log.cpp @@ -21,7 +21,7 @@ struct LogSettingImpl : LogSetting, Serializable ~LogSettingImpl() { - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci) { LogSettings *ls = ci->GetExt<LogSettings>("logsettings"); @@ -51,10 +51,10 @@ struct LogSettingImpl : LogSetting, Serializable Anope::string sci; data["ci"] >> sci; - ChannelInfo *ci = ChannelInfo::Find(sci); + ChanServ::Channel *ci = ChanServ::Find(sci); if (ci == NULL) return NULL; - + LogSettingImpl *ls; if (obj) ls = anope_dynamic_static_cast<LogSettingImpl *>(obj); @@ -112,7 +112,7 @@ public: { const Anope::string &channel = params[0]; - ChannelInfo *ci = ChannelInfo::Find(channel); + ChanServ::Channel *ci = ChanServ::Find(channel); if (ci == NULL) source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str()); else if (!source.AccessFor(ci).HasPriv("SET") && !source.HasPriv("chanserv/administration")) @@ -325,7 +325,7 @@ class CSLog : public Module } } - void OnChanRegistered(ChannelInfo *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { if (defaults.empty()) return; @@ -393,7 +393,7 @@ class CSLog : public Module else if (log->method.equals_ci("MESSAGE") && l->ci->c) { IRCD->SendPrivmsg(l->ci->WhoSends(), log->extra + l->ci->c->name, "%s", buffer.c_str()); - l->ci->WhoSends()->lastmsg = Anope::CurTime; + //l->ci->WhoSends()->lastmsg = Anope::CurTime; } else if (log->method.equals_ci("NOTICE") && l->ci->c) IRCD->SendNotice(l->ci->WhoSends(), log->extra + l->ci->c->name, "%s", buffer.c_str()); diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp index 2e858b382..9750cc031 100644 --- a/modules/commands/cs_mode.cpp +++ b/modules/commands/cs_mode.cpp @@ -23,7 +23,7 @@ struct ModeLockImpl : ModeLock, Serializable ~ModeLockImpl() { - ChannelInfo *chan = ChannelInfo::Find(ci); + ChanServ::Channel *chan = ChanServ::Find(ci); if (chan) { ModeLocks *ml = chan->GetExt<ModeLocks>("modelocks"); @@ -38,10 +38,10 @@ struct ModeLockImpl : ModeLock, Serializable struct ModeLocksImpl : ModeLocks { - Serialize::Reference<ChannelInfo> ci; + Serialize::Reference<ChanServ::Channel> ci; Serialize::Checker<ModeList> mlocks; - ModeLocksImpl(Extensible *obj) : ci(anope_dynamic_static_cast<ChannelInfo *>(obj)), mlocks("ModeLock") + ModeLocksImpl(Extensible *obj) : ci(anope_dynamic_static_cast<ChanServ::Channel *>(obj)), mlocks("ModeLock") { } @@ -224,13 +224,13 @@ void ModeLockImpl::Serialize(Serialize::Data &data) const Serializable* ModeLockImpl::Unserialize(Serializable *obj, Serialize::Data &data) { Anope::string sci; - + data["ci"] >> sci; - ChannelInfo *ci = ChannelInfo::Find(sci); + ChanServ::Channel *ci = ChanServ::Find(sci); if (!ci) return NULL; - + ModeLockImpl *ml; if (obj) ml = anope_dynamic_static_cast<ModeLockImpl *>(obj); @@ -254,7 +254,7 @@ Serializable* ModeLockImpl::Unserialize(Serializable *obj, Serialize::Data &data class CommandCSMode : public Command { - bool CanSet(CommandSource &source, ChannelInfo *ci, ChannelMode *cm, bool self) + bool CanSet(CommandSource &source, ChanServ::Channel *ci, ChannelMode *cm, bool self) { if (!ci || !cm || cm->type != MODE_STATUS) return false; @@ -262,7 +262,7 @@ class CommandCSMode : public Command return source.AccessFor(ci).HasPriv(cm->name + (self ? "ME" : "")); } - void DoLock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoLock(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { User *u = source.GetUser(); const Anope::string &subcommand = params[2]; @@ -332,7 +332,7 @@ class CommandCSMode : public Command source.Reply(_("List for mode %c is full."), cm->mchar); else { - modelocks->SetMLock(cm, adding, mode_param, source.GetNick()); + modelocks->SetMLock(cm, adding, mode_param, source.GetNick()); if (adding) { @@ -460,8 +460,8 @@ class CommandCSMode : public Command else this->OnSyntaxError(source, subcommand); } - - void DoSet(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + + void DoSet(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { User *u = source.GetUser(); @@ -536,7 +536,7 @@ class CommandCSMode : public Command if (!sep.GetToken(param)) param = source.GetNick(); - AccessGroup u_access = source.AccessFor(ci); + ChanServ::AccessGroup u_access = source.AccessFor(ci); if (param.find_first_of("*?") != Anope::string::npos) { @@ -551,7 +551,7 @@ class CommandCSMode : public Command ChanUserContainer *uc = it->second; ++it; - AccessGroup targ_access = ci->AccessFor(uc->user); + ChanServ::AccessGroup targ_access = ci->AccessFor(uc->user); if (uc->user->IsProtected() || (ci->HasExt("PEACE") && targ_access >= u_access && !can_override)) { @@ -585,7 +585,7 @@ class CommandCSMode : public Command if (source.GetUser() != target) { - AccessGroup targ_access = ci->AccessFor(target); + ChanServ::AccessGroup targ_access = ci->AccessFor(target); if (ci->HasExt("PEACE") && targ_access >= u_access && !can_override) { source.Reply(_("You do not have the access to change %s's modes."), target->nick.c_str()); @@ -632,7 +632,7 @@ class CommandCSMode : public Command } } - void DoClear(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoClear(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string ¶m = params.size() > 2 ? params[2] : ""; @@ -689,7 +689,7 @@ class CommandCSMode : public Command { const Anope::string &subcommand = params[1]; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (!ci) source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -760,7 +760,7 @@ class CommandCSModes : public Command { User *u = source.GetUser(), *targ = params.size() > 1 ? User::Find(params[1], true) : u; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (!targ) { @@ -780,7 +780,7 @@ class CommandCSModes : public Command return; } - AccessGroup u_access = source.AccessFor(ci), targ_access = ci->AccessFor(targ); + ChanServ::AccessGroup u_access = source.AccessFor(ci), targ_access = ci->AccessFor(targ); const std::pair<bool, Anope::string> &m = modes[source.command]; bool can_override = source.HasPriv("chanserv/administration"); @@ -791,7 +791,7 @@ class CommandCSModes : public Command source.Reply(ACCESS_DENIED); return; } - + if (u == targ ? !u_access.HasPriv(m.second + "ME") : !u_access.HasPriv(m.second)) { if (!can_override) @@ -898,7 +898,7 @@ class CSMode : public Module for (int i = 0; i < conf->CountBlock("command"); ++i) { Configuration::Block *block = conf->GetBlock("command", i); - + const Anope::string &cname = block->Get<const Anope::string>("name"), &cmd = block->Get<const Anope::string>("command"); @@ -907,7 +907,7 @@ class CSMode : public Module const Anope::string &set = block->Get<const Anope::string>("set"), &unset = block->Get<const Anope::string>("unset"); - + if (set.empty() && unset.empty()) continue; @@ -952,7 +952,7 @@ class CSMode : public Module if (c->HasMode(cm->name)) c->RemoveMode(NULL, cm, "", false); } - + } else if (cm->type == MODE_LIST || cm->type == MODE_STATUS) { @@ -964,7 +964,7 @@ class CSMode : public Module } } - void OnCreateChan(ChannelInfo *ci) override + void OnCreateChan(ChanServ::Channel *ci) override { ModeLocks *ml = modelocks.Require(ci); Anope::string mlock; @@ -990,7 +990,7 @@ class CSMode : public Module ml->Check(); } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) override { if (!show_hidden) return; diff --git a/modules/commands/cs_register.cpp b/modules/commands/cs_register.cpp index 7b2899939..4e584b51c 100644 --- a/modules/commands/cs_register.cpp +++ b/modules/commands/cs_register.cpp @@ -27,9 +27,9 @@ class CommandCSRegister : public Command unsigned maxregistered = Config->GetModule("chanserv")->Get<unsigned>("maxregistered"); User *u = source.GetUser(); - NickCore *nc = source.nc; + NickServ::Account *nc = source.nc; Channel *c = Channel::Find(params[0]); - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (Anope::ReadOnly) source.Reply(_("Sorry, channel registration is temporarily disabled.")); @@ -51,7 +51,9 @@ class CommandCSRegister : public Command source.Reply(nc->channelcount > maxregistered ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, maxregistered); else { - ci = new ChannelInfo(chan); + if (!ChanServ::service) + return; + ci = ChanServ::service->Create(chan); ci->SetFounder(nc); ci->desc = chdesc; diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index 595b999c9..873457b3a 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -58,7 +58,7 @@ struct SeenInfo : Serializable static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) { Anope::string snick; - + data["nick"] >> snick; SeenInfo *s; @@ -99,7 +99,7 @@ static SeenInfo *FindInfo(const Anope::string &nick) static bool ShouldHide(const Anope::string &channel, User *u) { Channel *targetchan = Channel::Find(channel); - const ChannelInfo *targetchan_ci = targetchan ? *targetchan->ci : ChannelInfo::Find(channel); + const ChanServ::Channel *targetchan_ci = targetchan ? *targetchan->ci : ChanServ::Find(channel); if (targetchan && targetchan->HasMode("SECRET")) return true; @@ -202,7 +202,7 @@ class CommandSeen : public Command return; } - NickAlias *na = NickAlias::Find(params[0]); + NickServ::Nick *na = NickServ::FindNick(params[0]); if (!na) { source.Reply(_("I don't know who %s is."), params[0].c_str()); @@ -235,11 +235,11 @@ class CommandSeen : public Command } } - AccessGroup ag = source.c->ci->AccessFor(na->nc); + ChanServ::AccessGroup ag = source.c->ci->AccessFor(na->nc); time_t last = 0; for (unsigned i = 0; i < ag.size(); ++i) { - ChanAccess *a = ag[i]; + ChanServ::ChanAccess *a = ag[i]; if (*a->nc == na->nc && a->last_seen > last) last = a->last_seen; @@ -378,7 +378,7 @@ class CSSeen : public Module Serialize::Type seeninfo_type; CommandSeen commandseen; CommandOSSeen commandosseen; - + public: CSSeen(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , EventHook<Event::ExpireTick>("OnExpireTick") @@ -446,9 +446,10 @@ class CSSeen : public Module UpdateUser(u, PART, u->nick, "", channel, msg); } - void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &msg) override + EventReturn OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &msg) override { UpdateUser(cu->user, KICK, cu->user->nick, source.GetSource(), cu->chan->name, msg); + return EVENT_CONTINUE; } private: diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 4cef222a4..21969833d 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -83,7 +83,7 @@ class CommandCSSetAutoOp : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -145,7 +145,7 @@ class CommandCSSetBanType : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -212,7 +212,7 @@ class CommandCSSetDescription : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (ci == NULL) { @@ -274,7 +274,7 @@ class CommandCSSetFounder : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -292,14 +292,14 @@ class CommandCSSetFounder : public Command return; } - const NickAlias *na = NickAlias::Find(params[1]); + const NickServ::Nick *na = NickServ::FindNick(params[1]); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, params[1].c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; unsigned max_reg = Config->GetModule("chanserv")->Get<unsigned>("maxregistered"); if (max_reg && nc->channelcount >= max_reg && !source.HasPriv("chanserv/no-register-limit")) { @@ -343,7 +343,7 @@ class CommandCSSetKeepModes : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -408,7 +408,7 @@ class CommandCSSetPeace : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -480,7 +480,7 @@ class CommandCSSetPersist : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -643,7 +643,7 @@ class CommandCSSetRestricted : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -705,7 +705,7 @@ class CommandCSSetSecure : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -769,7 +769,7 @@ class CommandCSSetSecureFounder : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -833,7 +833,7 @@ class CommandCSSetSecureOps : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -895,7 +895,7 @@ class CommandCSSetSignKick : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -972,7 +972,7 @@ class CommandCSSetSuccessor : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (ci == NULL) { @@ -991,11 +991,11 @@ class CommandCSSetSuccessor : public Command return; } - NickCore *nc; + NickServ::Account *nc; if (!param.empty()) { - const NickAlias *na = NickAlias::Find(param); + const NickServ::Nick *na = NickServ::FindNick(param); if (!na) { @@ -1058,7 +1058,7 @@ class CommandCSSetNoexpire : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -1124,10 +1124,10 @@ class CSSet : public Module { SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data); - if (s->GetSerializableType()->GetName() != "ChannelInfo") + if (s->GetSerializableType()->GetName() != "ChanServ::Channel") return; - const ChannelInfo *ci = anope_dynamic_static_cast<const ChannelInfo *>(s); + const ChanServ::Channel *ci = anope_dynamic_static_cast<const ChanServ::Channel *>(s); Anope::string modes; for (Channel::ModeList::const_iterator it = ci->last_modes.begin(); it != ci->last_modes.end(); ++it) { @@ -1144,10 +1144,10 @@ class CSSet : public Module { SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data); - if (s->GetSerializableType()->GetName() != "ChannelInfo") + if (s->GetSerializableType()->GetName() != "ChanServ::Channel") return; - ChannelInfo *ci = anope_dynamic_static_cast<ChannelInfo *>(s); + ChanServ::Channel *ci = anope_dynamic_static_cast<ChanServ::Channel *>(s); Anope::string modes; data["last_modes"] >> modes; for (spacesepstream sep(modes); sep.GetToken(modes);) @@ -1169,10 +1169,10 @@ class CSSet : public Module { SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data); - if (s->GetSerializableType()->GetName() != "ChannelInfo" || !this->HasExt(e)) + if (s->GetSerializableType()->GetName() != "ChanServ::Channel" || !this->HasExt(e)) return; - ChannelInfo *ci = anope_dynamic_static_cast<ChannelInfo *>(s); + ChanServ::Channel *ci = anope_dynamic_static_cast<ChanServ::Channel *>(s); if (ci->c) return; @@ -1272,7 +1272,7 @@ class CSSet : public Module persist_lower_ts = conf->GetModule(this)->Get<bool>("persist_lower_ts"); } - void OnCreateChan(ChannelInfo *ci) override + void OnCreateChan(ChanServ::Channel *ci) override { ci->bantype = Config->GetModule(this)->Get<int>("defbantype", "2"); } @@ -1303,7 +1303,7 @@ class CSSet : public Module return EVENT_CONTINUE; } - void OnDelChan(ChannelInfo *ci) override + void OnDelChan(ChanServ::Channel *ci) override { if (ci->c && persist.HasExt(ci)) ci->c->RemoveMode(ci->WhoSends(), "PERM", "", false); @@ -1357,11 +1357,11 @@ class CSSet : public Module } } - void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override + void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { if (chan->ci) { - if (noautoop.HasExt(chan->ci)) + if (noautoop.HasExt(chan->ci)) give_modes = false; if (secureops.HasExt(chan->ci)) // This overrides what chanserv does because it is loaded after chanserv @@ -1369,13 +1369,13 @@ class CSSet : public Module } } - void OnPreChanExpire(ChannelInfo *ci, bool &expire) override + void OnPreChanExpire(ChanServ::Channel *ci, bool &expire) override { if (noexpire.HasExt(ci)) expire = false; } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_all) override { if (!show_all) return; diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 3d8dbb0dd..783dae8d7 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -36,7 +36,7 @@ struct CSMiscData : MiscData, Serializable { CSMiscData(Extensible *obj) : Serializable("CSMiscData") { } - CSMiscData(ChannelInfo *c, const Anope::string &n, const Anope::string &d) : Serializable("CSMiscData") + CSMiscData(ChanServ::Channel *c, const Anope::string &n, const Anope::string &d) : Serializable("CSMiscData") { object = c->name; name = n; @@ -58,7 +58,7 @@ struct CSMiscData : MiscData, Serializable data["name"] >> sname; data["data"] >> sdata; - ChannelInfo *ci = ChannelInfo::Find(sci); + ChanServ::Channel *ci = ChanServ::Find(sci); if (ci == NULL) return NULL; @@ -105,7 +105,7 @@ class CommandCSSetMisc : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (ci == NULL) { @@ -206,7 +206,7 @@ class CSSetMisc : public Module } } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool) override { for (Anope::map<ExtensibleItem<CSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) { diff --git a/modules/commands/cs_status.cpp b/modules/commands/cs_status.cpp index bd707d537..7b7415fdb 100644 --- a/modules/commands/cs_status.cpp +++ b/modules/commands/cs_status.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/cs_akick.h" class CommandCSStatus : public Command { @@ -24,7 +25,7 @@ public: { const Anope::string &channel = params[0]; - ChannelInfo *ci = ChannelInfo::Find(channel); + ChanServ::Channel *ci = ChanServ::Find(channel); if (ci == NULL) source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str()); else if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && !source.HasPriv("chanserv/auspex")) @@ -35,14 +36,14 @@ public: if (params.size() > 1) nick = params[1]; - AccessGroup ag; + ChanServ::AccessGroup ag; User *u = User::Find(nick, true); - NickAlias *na = NULL; + NickServ::Nick *na = NULL; if (u != NULL) ag = ci->AccessFor(u); else { - na = NickAlias::Find(nick); + na = NickServ::FindNick(nick); if (na != NULL) ag = ci->AccessFor(na->nc); } @@ -59,7 +60,7 @@ public: for (unsigned i = 0; i < ag.size(); ++i) { - ChanAccess *acc = ag[i]; + ChanServ::ChanAccess *acc = ag[i]; source.Reply(_("\002%s\002 matches access entry %s, which has privilege %s."), nick.c_str(), acc->mask.c_str(), acc->AccessSerialize().c_str()); } diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index 7b604b250..411b141e6 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -38,7 +38,7 @@ struct CSSuspendInfo : SuspendInfo, Serializable si = anope_dynamic_static_cast<CSSuspendInfo *>(obj); else { - ChannelInfo *ci = ChannelInfo::Find(schan); + ChanServ::Channel *ci = ChanServ::Find(schan); if (!ci) return NULL; si = ci->Extend<CSSuspendInfo>("CS_SUSPENDED"); @@ -58,7 +58,7 @@ class CommandCSSuspend : public Command EventHandlers<Event::ChanSuspend> &onchansuspend; public: CommandCSSuspend(Module *creator, EventHandlers<Event::ChanSuspend> &event) : Command(creator, "chanserv/suspend", 2, 3), onchansuspend(event) - { + { this->SetDesc(_("Prevent a channel from being used preserving channel data and settings")); this->SetSyntax(_("\037channel\037 [+\037expiry\037] [\037reason\037]")); } @@ -89,7 +89,7 @@ class CommandCSSuspend : public Command if (Anope::ReadOnly) source.Reply(READ_ONLY_MODE); - ChannelInfo *ci = ChannelInfo::Find(chan); + ChanServ::Channel *ci = ChanServ::Find(chan); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -164,7 +164,7 @@ class CommandCSUnSuspend : public Command if (Anope::ReadOnly) source.Reply(READ_ONLY_MODE); - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -226,7 +226,7 @@ class CSSuspend : public Module { } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) override { CSSuspendInfo *si = suspend.Get(ci); if (si) @@ -243,7 +243,7 @@ class CSSuspend : public Module } } - void OnPreChanExpire(ChannelInfo *ci, bool &expire) override + void OnPreChanExpire(ChanServ::Channel *ci, bool &expire) override { CSSuspendInfo *si = suspend.Get(ci); if (!si) @@ -272,7 +272,7 @@ class CSSuspend : public Module return EVENT_STOP; } - EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) override + EventReturn OnChanDrop(CommandSource &source, ChanServ::Channel *ci) override { CSSuspendInfo *si = suspend.Get(ci); if (si && !source.HasCommand("chanserv/drop")) diff --git a/modules/commands/cs_sync.cpp b/modules/commands/cs_sync.cpp index d26ff6a7a..20154c70a 100644 --- a/modules/commands/cs_sync.cpp +++ b/modules/commands/cs_sync.cpp @@ -22,7 +22,7 @@ class CommandCSSync : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -55,7 +55,7 @@ class CommandCSSync : public Command class CSSync : public Module { CommandCSSync commandcssync; - + public: CSSync(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , commandcssync(this) diff --git a/modules/commands/cs_topic.cpp b/modules/commands/cs_topic.cpp index 2fd1b0a81..0c0e56696 100644 --- a/modules/commands/cs_topic.cpp +++ b/modules/commands/cs_topic.cpp @@ -31,7 +31,7 @@ class CommandCSSetKeepTopic : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -82,7 +82,7 @@ class CommandCSTopic : public Command { ExtensibleRef<bool> topiclock; - void Lock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void Lock(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { if (Anope::ReadOnly) { @@ -99,7 +99,7 @@ class CommandCSTopic : public Command source.Reply(_("Topic lock option for %s is now \002on\002."), ci->name.c_str()); } - void Unlock(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void Unlock(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { if (Anope::ReadOnly) { @@ -116,7 +116,7 @@ class CommandCSTopic : public Command source.Reply(_("Topic lock option for %s is now \002off\002."), ci->name.c_str()); } - void Set(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void Set(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &topic = params.size() > 2 ? params[2] : ""; @@ -125,12 +125,12 @@ class CommandCSTopic : public Command ci->c->ChangeTopic(source.GetNick(), topic, Anope::CurTime); if (has_topiclock) topiclock->Set(ci); - + bool override = !source.AccessFor(ci).HasPriv("TOPIC"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << (!topic.empty() ? "to change the topic to: " : "to unset the topic") << (!topic.empty() ? topic : ""); } - void Append(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void Append(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &topic = params[2]; @@ -165,7 +165,7 @@ class CommandCSTopic : public Command { const Anope::string &subcmd = params[1]; - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); else if (!source.AccessFor(ci).HasPriv("TOPIC") && !source.HasCommand("chanserv/topic")) @@ -256,7 +256,7 @@ class CSTopic : public Module } } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_all) override { if (keeptopic.HasExt(ci)) info.AddOption(_("Topic retention")); diff --git a/modules/commands/cs_unban.cpp b/modules/commands/cs_unban.cpp index f5e2a6460..a658c65dd 100644 --- a/modules/commands/cs_unban.cpp +++ b/modules/commands/cs_unban.cpp @@ -27,13 +27,13 @@ class CommandCSUnban : public Command if (!source.GetUser()) return; - std::deque<ChannelInfo *> queue; + std::deque<ChanServ::Channel *> queue; source.GetAccount()->GetChannelReferences(queue); unsigned count = 0; for (unsigned i = 0; i < queue.size(); ++i) { - ChannelInfo *ci = queue[i]; + ChanServ::Channel *ci = queue[i]; if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) continue; @@ -48,7 +48,7 @@ class CommandCSUnban : public Command return; } - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 282eb1479..bf94b9c2d 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -22,7 +22,7 @@ class CommandCSUp : public Command bool giving = true; /* whether or not we have given a mode */ bool given = false; - AccessGroup u_access = c->ci->AccessFor(u); + ChanServ::AccessGroup u_access = c->ci->AccessFor(u); for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) { @@ -160,7 +160,7 @@ class CommandCSDown : public Command const Anope::string &nick = params.size() > 1 ? params[1] : source.GetNick(); Channel *c = Channel::Find(channel); - + if (c == NULL) { source.Reply(CHAN_X_NOT_IN_USE, channel.c_str()); diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 84a8fbfb7..b2c554d71 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -17,12 +17,12 @@ namespace std::map<Anope::string, std::vector<Anope::string> > permissions; } -class XOPChanAccess : public ChanAccess +class XOPChanAccess : public ChanServ::ChanAccess { public: Anope::string type; - XOPChanAccess(AccessProvider *p) : ChanAccess(p) + XOPChanAccess(ChanServ::AccessProvider *p) : ChanAccess(p) { } @@ -47,7 +47,7 @@ class XOPChanAccess : public ChanAccess this->type = data; } - static Anope::string DetermineLevel(const ChanAccess *access) + static Anope::string DetermineLevel(const ChanServ::ChanAccess *access) { if (access->provider->name == "access/xop") { @@ -81,14 +81,14 @@ class XOPChanAccess : public ChanAccess } }; -class XOPAccessProvider : public AccessProvider +class XOPAccessProvider : public ChanServ::AccessProvider { public: XOPAccessProvider(Module *o) : AccessProvider(o, "access/xop") { } - ChanAccess *Create() override + ChanServ::ChanAccess *Create() override { return new XOPChanAccess(this); } @@ -97,7 +97,7 @@ class XOPAccessProvider : public AccessProvider class CommandCSXOP : public Command { private: - void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoAdd(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { Anope::string mask = params.size() > 2 ? params[2] : ""; @@ -117,8 +117,8 @@ class CommandCSXOP : public Command tmp_access.ci = ci; tmp_access.type = source.command.upper(); - AccessGroup access = source.AccessFor(ci); - const ChanAccess *highest = access.Highest(); + ChanServ::AccessGroup access = source.AccessFor(ci); + const ChanServ::ChanAccess *highest = access.Highest(); bool override = false; std::vector<Anope::string>::iterator cmd_it = std::find(order.begin(), order.end(), source.command.upper()), @@ -143,7 +143,7 @@ class CommandCSXOP : public Command return; } - ChannelInfo *targ_ci = ChannelInfo::Find(mask); + ChanServ::Channel *targ_ci = ChanServ::Find(mask); if (targ_ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, mask.c_str()); @@ -159,7 +159,7 @@ class CommandCSXOP : public Command } else { - const NickAlias *na = NickAlias::Find(mask); + const NickServ::Nick *na = NickServ::FindNick(mask); if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access")) { source.Reply(_("Masks and unregistered users may not be on access lists.")); @@ -180,7 +180,7 @@ class CommandCSXOP : public Command for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { - const ChanAccess *a = ci->GetAccess(i); + const ChanServ::ChanAccess *a = ci->GetAccess(i); if (a->mask.equals_ci(mask)) { @@ -202,7 +202,7 @@ class CommandCSXOP : public Command return; } - ServiceReference<AccessProvider> provider("AccessProvider", "access/xop"); + ServiceReference<ChanServ::AccessProvider> provider("AccessProvider", "access/xop"); if (!provider) return; XOPChanAccess *acc = anope_dynamic_static_cast<XOPChanAccess *>(provider->Create()); @@ -220,9 +220,9 @@ class CommandCSXOP : public Command source.Reply(_("\002%s\002 added to %s %s list."), acc->mask.c_str(), ci->name.c_str(), source.command.c_str()); } - void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoDel(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { - NickCore *nc = source.nc; + NickServ::Account *nc = source.nc; Anope::string mask = params.size() > 2 ? params[2] : ""; if (mask.empty()) @@ -247,11 +247,11 @@ class CommandCSXOP : public Command tmp_access.ci = ci; tmp_access.type = source.command.upper(); - AccessGroup access = source.AccessFor(ci); - const ChanAccess *highest = access.Highest(); + ChanServ::AccessGroup access = source.AccessFor(ci); + const ChanServ::ChanAccess *highest = access.Highest(); bool override = false; - if (!isdigit(mask[0]) && mask.find_first_of("#!*@") == Anope::string::npos && !NickAlias::Find(mask)) + if (!isdigit(mask[0]) && mask.find_first_of("#!*@") == Anope::string::npos && !NickServ::FindNick(mask)) { User *targ = User::Find(mask, true); if (targ != NULL) @@ -283,13 +283,13 @@ class CommandCSXOP : public Command class XOPDelCallback : public NumberList { CommandSource &source; - ChannelInfo *ci; + ChanServ::Channel *ci; Command *c; unsigned deleted; Anope::string nicks; bool override; public: - XOPDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, bool _override, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), override(_override) + XOPDelCallback(CommandSource &_source, ChanServ::Channel *_ci, Command *_c, bool _override, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), deleted(0), override(_override) { } @@ -313,7 +313,7 @@ class CommandCSXOP : public Command if (!number || number > ci->GetAccessCount()) return; - ChanAccess *caccess = ci->GetAccess(number - 1); + ChanServ::ChanAccess *caccess = ci->GetAccess(number - 1); if (caccess->provider->name != "access/xop" || this->source.command.upper() != caccess->AccessSerialize()) return; @@ -336,7 +336,7 @@ class CommandCSXOP : public Command { for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { - ChanAccess *a = ci->GetAccess(i); + ChanServ::ChanAccess *a = ci->GetAccess(i); if (a->provider->name != "access/xop" || source.command.upper() != a->AccessSerialize()) continue; @@ -354,17 +354,17 @@ class CommandCSXOP : public Command return; } } - + source.Reply(_("\002%s\002 not found on %s %s list."), mask.c_str(), ci->name.c_str(), source.command.c_str()); } } - void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector<Anope::string> ¶ms) { const Anope::string &nick = params.size() > 2 ? params[2] : ""; - AccessGroup access = source.AccessFor(ci); + ChanServ::AccessGroup access = source.AccessFor(ci); if (!access.HasPriv("ACCESS_LIST") && !source.HasCommand("chanserv/access/list")) { @@ -386,10 +386,10 @@ class CommandCSXOP : public Command class XOPListCallback : public NumberList { ListFormatter &list; - ChannelInfo *ci; + ChanServ::Channel *ci; CommandSource &source; public: - XOPListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist, CommandSource &src) : NumberList(numlist, false), list(_list), ci(_ci), source(src) + XOPListCallback(ListFormatter &_list, ChanServ::Channel *_ci, const Anope::string &numlist, CommandSource &src) : NumberList(numlist, false), list(_list), ci(_ci), source(src) { } @@ -398,7 +398,7 @@ class CommandCSXOP : public Command if (!Number || Number > ci->GetAccessCount()) return; - const ChanAccess *a = ci->GetAccess(Number - 1); + const ChanServ::ChanAccess *a = ci->GetAccess(Number - 1); if (a->provider->name != "access/xop" || this->source.command.upper() != a->AccessSerialize()) return; @@ -415,7 +415,7 @@ class CommandCSXOP : public Command { for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - const ChanAccess *a = ci->GetAccess(i); + const ChanServ::ChanAccess *a = ci->GetAccess(i); if (a->provider->name != "access/xop" || source.command.upper() != a->AccessSerialize()) continue; @@ -442,7 +442,7 @@ class CommandCSXOP : public Command } } - void DoClear(CommandSource &source, ChannelInfo *ci) + void DoClear(CommandSource &source, ChanServ::Channel *ci) { if (Anope::ReadOnly) { @@ -467,11 +467,11 @@ class CommandCSXOP : public Command for (unsigned i = ci->GetAccessCount(); i > 0; --i) { - const ChanAccess *access = ci->GetAccess(i - 1); + const ChanServ::ChanAccess *access = ci->GetAccess(i - 1); if (access->provider->name != "access/xop" || source.command.upper() != access->AccessSerialize()) continue; - + delete ci->EraseAccess(i - 1); } @@ -496,7 +496,7 @@ class CommandCSXOP : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -611,7 +611,7 @@ class CSXOP : public Module Configuration::Block *block = conf->GetBlock("privilege", i); const Anope::string &pname = block->Get<const Anope::string>("name"); - Privilege *p = PrivilegeManager::FindPrivilege(pname); + ChanServ::Privilege *p = ChanServ::service ? ChanServ::service->FindPrivilege(pname) : nullptr; if (p == NULL) continue; diff --git a/modules/commands/greet.cpp b/modules/commands/greet.cpp index cacda2d3c..e35ba5b19 100644 --- a/modules/commands/greet.cpp +++ b/modules/commands/greet.cpp @@ -25,7 +25,7 @@ class CommandBSSetGreet : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string &value = params[1]; if (ci == NULL) @@ -49,7 +49,7 @@ class CommandBSSetGreet : public Command if (value.equals_ci("ON")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable greets"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable greets"; ci->Extend<bool>("BS_GREET"); source.Reply(_("Greet mode is now \002on\002 on channel %s."), ci->name.c_str()); @@ -57,7 +57,7 @@ class CommandBSSetGreet : public Command else if (value.equals_ci("OFF")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable greets"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable greets"; ci->Shrink<bool>("BS_GREET"); source.Reply(_("Greet mode is now \002off\002 on channel %s."), ci->name.c_str()); @@ -95,13 +95,13 @@ class CommandNSSetGreet : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) @@ -208,14 +208,14 @@ class Greet : public Module } } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { Anope::string *greet = ns_greet.Get(na->nc); if (greet != NULL) info[_("Greet")] = *greet; } - void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) override + void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) override { if (bs_greet.HasExt(ci)) info.AddOption(_("Greet")); diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index c23454c25..ba743f661 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -42,7 +42,7 @@ class CommandHelp : public Command EventReturn MOD_RESULT = this->onhelp(&Event::Help::OnPreHelp, source, params); if (MOD_RESULT == EVENT_STOP) return; - + Anope::string source_command = source.command; const BotInfo *bi = source.service; const CommandInfo::map &map = source.c ? Config->Fantasy : bi->commands; @@ -151,7 +151,7 @@ class CommandHelp : public Command if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) continue; - + // Allow unregistered users to see help for commands that they explicitly request help for const Anope::string &subcommand = params.size() > max ? params[max] : ""; @@ -185,7 +185,7 @@ class CommandHelp : public Command if (helped == false) source.Reply(_("No help available for \002%s\002."), params[0].c_str()); } - + this->onhelp(&Event::Help::OnPostHelp, source, params); } }; diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp index ae0e2e6c2..d527c772b 100644 --- a/modules/commands/hs_del.cpp +++ b/modules/commands/hs_del.cpp @@ -32,7 +32,7 @@ class CommandHSDel : public Command } const Anope::string &nick = params[0]; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (na) { Log(LOG_ADMIN, source, this) << "for user " << na->nick; @@ -74,11 +74,11 @@ class CommandHSDelAll : public Command } const Anope::string &nick = params[0]; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (na) { this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na); - const NickCore *nc = na->nc; + const NickServ::Account *nc = na->nc; for (unsigned i = 0; i < nc->aliases->size(); ++i) { na = nc->aliases->at(i); diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp index eb1c6d299..47e4c03de 100644 --- a/modules/commands/hs_group.cpp +++ b/modules/commands/hs_group.cpp @@ -17,7 +17,7 @@ class CommandHSGroup : public Command bool setting; public: - void Sync(const NickAlias *na) + void Sync(const NickServ::Nick *na) { if (setting) return; @@ -25,10 +25,10 @@ class CommandHSGroup : public Command if (!na || !na->HasVhost()) return; - setting = true; + setting = true; for (unsigned i = 0; i < na->nc->aliases->size(); ++i) { - NickAlias *nick = na->nc->aliases->at(i); + NickServ::Nick *nick = na->nc->aliases->at(i); if (nick) { nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); @@ -51,7 +51,7 @@ class CommandHSGroup : public Command return; } - NickAlias *na = NickAlias::Find(source.GetNick()); + NickServ::Nick *na = NickServ::FindNick(source.GetNick()); if (na && source.GetAccount() == na->nc && na->HasVhost()) { this->Sync(na); @@ -93,7 +93,7 @@ class HSGroup : public Module { } - void OnSetVhost(NickAlias *na) override + void OnSetVhost(NickServ::Nick *na) override { if (!synconset) return; @@ -101,7 +101,7 @@ class HSGroup : public Module commandhsgroup.Sync(na); } - void OnNickGroup(User *u, NickAlias *na) override + void OnNickGroup(User *u, NickServ::Nick *na) override { if (!syncongroup) return; diff --git a/modules/commands/hs_list.cpp b/modules/commands/hs_list.cpp index b5b8aa76a..f662ebbf1 100644 --- a/modules/commands/hs_list.cpp +++ b/modules/commands/hs_list.cpp @@ -57,9 +57,9 @@ class CommandHSList : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created")); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetNickList()) { - const NickAlias *na = it->second; + const NickServ::Nick *na = it.second; if (!na->HasVhost()) continue; diff --git a/modules/commands/hs_off.cpp b/modules/commands/hs_off.cpp index c0d51f884..4923d390d 100644 --- a/modules/commands/hs_off.cpp +++ b/modules/commands/hs_off.cpp @@ -23,7 +23,7 @@ class CommandHSOff : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { User *u = source.GetUser(); - const NickAlias *na = NickAlias::Find(u->nick); + const NickServ::Nick *na = NickServ::FindNick(u->nick); if (!na || !na->HasVhost()) source.Reply(HOST_NOT_ASSIGNED); diff --git a/modules/commands/hs_on.cpp b/modules/commands/hs_on.cpp index 4b92bf0be..7331dd355 100644 --- a/modules/commands/hs_on.cpp +++ b/modules/commands/hs_on.cpp @@ -26,7 +26,7 @@ class CommandHSOn : public Command return; // HostServ wouldn't even be loaded at this point User *u = source.GetUser(); - const NickAlias *na = NickAlias::Find(u->nick); + const NickServ::Nick *na = NickServ::FindNick(u->nick); if (na && u->Account() == na->nc && na->HasVhost()) { if (!na->GetVhostIdent().empty()) diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index 1e5c98e31..119cc5a6d 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -42,7 +42,7 @@ struct HostRequest : Serializable Anope::string snick; data["nick"] >> snick; - NickAlias *na = NickAlias::Find(snick); + NickServ::Nick *na = NickServ::FindNick(snick); if (na == NULL) return NULL; @@ -88,7 +88,7 @@ class CommandHSRequest : public Command } User *u = source.GetUser(); - NickAlias *na = NickAlias::Find(source.GetNick()); + NickServ::Nick *na = NickServ::FindNick(source.GetNick()); if (!na || na->nc != source.GetAccount()) { source.Reply(ACCESS_DENIED); @@ -96,7 +96,7 @@ class CommandHSRequest : public Command } Anope::string rawhostmask = params[0]; - + Anope::string user, host; size_t a = rawhostmask.find('@'); @@ -196,7 +196,7 @@ class CommandHSActivate : public Command const Anope::string &nick = params[0]; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); HostRequest *req = na ? na->GetExt<HostRequest>("hostrequest") : NULL; if (req) { @@ -246,7 +246,7 @@ class CommandHSReject : public Command const Anope::string &nick = params[0]; const Anope::string &reason = params.size() > 1 ? params[1] : ""; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); HostRequest *req = na ? na->GetExt<HostRequest>("hostrequest") : NULL; if (req) { @@ -298,9 +298,9 @@ class CommandHSWaiting : public Command list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created")); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetNickList()) { - const NickAlias *na = it->second; + const NickServ::Nick *na = it.second; HostRequest *hr = na->GetExt<HostRequest>("hostrequest"); if (!hr) continue; @@ -311,7 +311,7 @@ class CommandHSWaiting : public Command ListFormatter::ListEntry entry; entry["Number"] = stringify(display_counter); - entry["Nick"] = it->first; + entry["Nick"] = na->nick; if (!hr->ident.empty()) entry["Vhost"] = hr->ident + "@" + hr->host; else @@ -379,8 +379,8 @@ static void req_send_memos(Module *me, CommandSource &source, const Anope::strin for (unsigned i = 0; i < Oper::opers.size(); ++i) { Oper *o = Oper::opers[i]; - - const NickAlias *na = NickAlias::Find(o->name); + + const NickServ::Nick *na = NickServ::FindNick(o->name); if (!na) continue; diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp index 69281b6ec..614bfc2e9 100644 --- a/modules/commands/hs_set.cpp +++ b/modules/commands/hs_set.cpp @@ -30,7 +30,7 @@ class CommandHSSet : public Command const Anope::string &nick = params[0]; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -106,14 +106,14 @@ class CommandHSSet : public Command class CommandHSSetAll : public Command { - void Sync(const NickAlias *na) + void Sync(const NickServ::Nick *na) { if (!na || !na->HasVhost()) return; - + for (unsigned i = 0; i < na->nc->aliases->size(); ++i) { - NickAlias *nick = na->nc->aliases->at(i); + NickServ::Nick *nick = na->nc->aliases->at(i); if (nick) nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); } @@ -136,7 +136,7 @@ class CommandHSSetAll : public Command Anope::string nick = params[0]; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); diff --git a/modules/commands/ms_cancel.cpp b/modules/commands/ms_cancel.cpp index 09746d0f2..0de3ae0ea 100644 --- a/modules/commands/ms_cancel.cpp +++ b/modules/commands/ms_cancel.cpp @@ -23,7 +23,7 @@ class CommandMSCancel : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - if (Anope::ReadOnly) + if (Anope::ReadOnly || !MemoServ::service) { source.Reply(READ_ONLY_MODE); return; @@ -31,32 +31,32 @@ class CommandMSCancel : public Command const Anope::string &nname = params[0]; - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(nname, ischan); + bool ischan, isregistered; + MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(name, ischan, isregistered, false); - if (mi == NULL) + if (!isregistered) source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), nname.c_str()); else { - ChannelInfo *ci = NULL; - NickAlias *na = NULL; + ChanServ::Channel *ci = NULL; + NickServ::Nick *na = NULL; if (ischan) - ci = ChannelInfo::Find(nname); + ci = ChanServ::Find(nname); else - na = NickAlias::Find(nname); - for (int i = mi->memos->size() - 1; i >= 0; --i) - if (mi->GetMemo(i)->unread && source.nc->display.equals_ci(mi->GetMemo(i)->sender)) - { - if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->name : na->nc->display, mi, mi->GetMemo(i)); - mi->Del(i); - source.Reply(_("Last memo to \002%s\002 has been cancelled."), nname.c_str()); - return; - } + na = NickServ::FindNick(nname); + if (mi) + for (int i = mi->memos->size() - 1; i >= 0; --i) + if (mi->GetMemo(i)->unread && source.nc->display.equals_ci(mi->GetMemo(i)->sender)) + { + if (MemoServ::Event::OnMemoDel) + MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->name : na->nc->display, mi, mi->GetMemo(i)); + mi->Del(i); + source.Reply(_("Last memo to \002%s\002 has been cancelled."), nname.c_str()); + return; + } source.Reply(_("No memo was cancelable.")); } - return; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ms_check.cpp b/modules/commands/ms_check.cpp index a534aaca3..f20724a45 100644 --- a/modules/commands/ms_check.cpp +++ b/modules/commands/ms_check.cpp @@ -27,34 +27,35 @@ class CommandMSCheck : public Command bool found = false; - const NickAlias *na = NickAlias::Find(recipient); + const NickServ::Nick *na = NickServ::FindNick(recipient); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, recipient.c_str()); return; } - MemoInfo *mi = &na->nc->memos; + MemoServ::MemoInfo *mi = na->nc->memos; /* Okay, I know this looks strange but we wanna get the LAST memo, so we have to loop backwards */ - for (unsigned i = mi->memos->size(); i > 0; --i) - { - Memo *m = mi->GetMemo(i - 1); - NickAlias *na2 = NickAlias::Find(m->sender); - - if (na2 != NULL && na2->nc == source.GetAccount()) + if (mi) + for (unsigned i = mi->memos->size(); i > 0; --i) { - found = true; /* Yes, we've found the memo */ - - if (m->unread) - source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str()); - else - source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str()); - break; + MemoServ::Memo *m = mi->GetMemo(i - 1); + NickServ::Nick *na2 = NickServ::FindNick(m->sender); + + if (na2 != NULL && na2->nc == source.GetAccount()) + { + found = true; /* Yes, we've found the memo */ + + if (m->unread) + source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str()); + else + source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str()); + break; + } } - } if (!found) source.Reply(_("Nick %s doesn't have a memo from you."), na->nick.c_str()); diff --git a/modules/commands/ms_del.cpp b/modules/commands/ms_del.cpp index e1d329921..9089dd6a1 100644 --- a/modules/commands/ms_del.cpp +++ b/modules/commands/ms_del.cpp @@ -15,10 +15,10 @@ class MemoDelCallback : public NumberList { CommandSource &source; - ChannelInfo *ci; - MemoInfo *mi; + ChanServ::Channel *ci; + MemoServ::MemoInfo *mi; public: - MemoDelCallback(CommandSource &_source, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), mi(_mi) + MemoDelCallback(CommandSource &_source, ChanServ::Channel *_ci, MemoServ::MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), mi(_mi) { } @@ -52,8 +52,8 @@ class CommandMSDel : public Command return; } - MemoInfo *mi; - ChannelInfo *ci = NULL; + MemoServ::MemoInfo *mi; + ChanServ::Channel *ci = NULL; Anope::string numstr = !params.empty() ? params[0] : "", chan; if (!numstr.empty() && numstr[0] == '#') @@ -61,7 +61,7 @@ class CommandMSDel : public Command chan = numstr; numstr = params.size() > 1 ? params[1] : ""; - ci = ChannelInfo::Find(chan); + ci = ChanServ::Find(chan); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -72,13 +72,13 @@ class CommandMSDel : public Command source.Reply(ACCESS_DENIED); return; } - mi = &ci->memos; + mi = ci->memos; } else - mi = &source.nc->memos; + mi = source.nc->memos; if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST"))) this->OnSyntaxError(source, numstr); - else if (mi->memos->empty()) + else if (!mi || mi->memos->empty()) { if (!chan.empty()) source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str()); diff --git a/modules/commands/ms_ignore.cpp b/modules/commands/ms_ignore.cpp index f73a27930..98b4a2f9e 100644 --- a/modules/commands/ms_ignore.cpp +++ b/modules/commands/ms_ignore.cpp @@ -29,6 +29,8 @@ class CommandMSIgnore : public Command source.Reply(READ_ONLY_MODE); return; } + if (!MemoServ::service) + return; Anope::string channel = params[0]; Anope::string command = (params.size() > 1 ? params[1] : ""); @@ -41,10 +43,10 @@ class CommandMSIgnore : public Command channel = source.GetNick(); } - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(channel, ischan); - ChannelInfo *ci = ChannelInfo::Find(channel); - if (!mi) + bool ischan, isregistered; + MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(channel, ischan, isregistered, true); + ChanServ::Channel *ci = ChanServ::Find(channel); + if (!isregistered) source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), channel.c_str()); else if (ischan && !source.AccessFor(ci).HasPriv("MEMO")) source.Reply(ACCESS_DENIED); diff --git a/modules/commands/ms_info.cpp b/modules/commands/ms_info.cpp index 0e7506765..9544be3c7 100644 --- a/modules/commands/ms_info.cpp +++ b/modules/commands/ms_info.cpp @@ -22,27 +22,27 @@ class CommandMSInfo : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - NickCore *nc = source.nc; - const MemoInfo *mi; - const NickAlias *na = NULL; - ChannelInfo *ci = NULL; + NickServ::Account *nc = source.nc; + const MemoServ::MemoInfo *mi; + const NickServ::Nick *na = NULL; + ChanServ::Channel *ci = NULL; const Anope::string &nname = !params.empty() ? params[0] : ""; bool hardmax; if (!nname.empty() && nname[0] != '#' && source.HasPriv("memoserv/info")) { - na = NickAlias::Find(nname); + na = NickServ::FindNick(nname); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, nname.c_str()); return; } - mi = &na->nc->memos; + mi = na->nc->memos; hardmax = na->nc->HasExt("MEMO_HARDMAX"); } else if (!nname.empty() && nname[0] == '#') { - ci = ChannelInfo::Find(nname); + ci = ChanServ::Find(nname); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, nname.c_str()); @@ -53,7 +53,7 @@ class CommandMSInfo : public Command source.Reply(ACCESS_DENIED); return; } - mi = &ci->memos; + mi = ci->memos; hardmax = ci->HasExt("MEMO_HARDMAX"); } else if (!nname.empty()) /* It's not a chan and we aren't services admin */ @@ -63,9 +63,11 @@ class CommandMSInfo : public Command } else { - mi = &nc->memos; + mi = nc->memos; hardmax = nc->HasExt("MEMO_HARDMAX"); } + if (!mi) + return; if (!nname.empty() && (ci || na->nc != nc)) { diff --git a/modules/commands/ms_list.cpp b/modules/commands/ms_list.cpp index e5ca96770..758bb08be 100644 --- a/modules/commands/ms_list.cpp +++ b/modules/commands/ms_list.cpp @@ -24,15 +24,15 @@ class CommandMSList : public Command { Anope::string param = !params.empty() ? params[0] : "", chan; - ChannelInfo *ci = NULL; - const MemoInfo *mi; + ChanServ::Channel *ci = NULL; + const MemoServ::MemoInfo *mi; if (!param.empty() && param[0] == '#') { chan = param; param = params.size() > 1 ? params[1] : ""; - ci = ChannelInfo::Find(chan); + ci = ChanServ::Find(chan); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -43,10 +43,10 @@ class CommandMSList : public Command source.Reply(ACCESS_DENIED); return; } - mi = &ci->memos; + mi = ci->memos; } else - mi = &source.nc->memos; + mi = source.nc->memos; if (!param.empty() && !isdigit(param[0]) && !param.equals_ci("NEW")) this->OnSyntaxError(source, param); @@ -69,9 +69,9 @@ class CommandMSList : public Command { ListFormatter &list; CommandSource &source; - const MemoInfo *mi; + const MemoServ::MemoInfo *mi; public: - MemoListCallback(ListFormatter &_list, CommandSource &_source, const MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), list(_list), source(_source), mi(_mi) + MemoListCallback(ListFormatter &_list, CommandSource &_source, const MemoServ::MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), list(_list), source(_source), mi(_mi) { } @@ -80,7 +80,7 @@ class CommandMSList : public Command if (!number || number > mi->memos->size()) return; - const Memo *m = mi->GetMemo(number - 1); + const MemoServ::Memo *m = mi->GetMemo(number - 1); ListFormatter::ListEntry entry; entry["Number"] = (m->unread ? "* " : " ") + stringify(number); @@ -115,7 +115,7 @@ class CommandMSList : public Command if (!param.empty() && !mi->GetMemo(i)->unread) continue; - const Memo *m = mi->GetMemo(i); + const MemoServ::Memo *m = mi->GetMemo(i); ListFormatter::ListEntry entry; entry["Number"] = (m->unread ? "* " : " ") + stringify(i + 1); diff --git a/modules/commands/ms_read.cpp b/modules/commands/ms_read.cpp index ba5eda863..32852a29f 100644 --- a/modules/commands/ms_read.cpp +++ b/modules/commands/ms_read.cpp @@ -12,19 +12,19 @@ #include "module.h" #include "modules/memoserv.h" -static void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Anope::string &targ) +static void rsend_notify(CommandSource &source, MemoServ::MemoInfo *mi, MemoServ::Memo *m, const Anope::string &targ) { /* Only send receipt if memos are allowed */ if (MemoServ::service && !Anope::ReadOnly) { /* Get nick alias for sender */ - const NickAlias *na = NickAlias::Find(m->sender); + const NickServ::Nick *na = NickServ::FindNick(m->sender); if (!na) return; /* Get nick core for sender */ - const NickCore *nc = na->nc; + const NickServ::Account *nc = na->nc; if (!nc) return; @@ -49,10 +49,10 @@ static void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Ano class MemoListCallback : public NumberList { CommandSource &source; - MemoInfo *mi; - const ChannelInfo *ci; + MemoServ::MemoInfo *mi; + const ChanServ::Channel *ci; public: - MemoListCallback(CommandSource &_source, MemoInfo *_mi, const ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi), ci(_ci) + MemoListCallback(CommandSource &_source, MemoServ::MemoInfo *_mi, const ChanServ::Channel *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi), ci(_ci) { } @@ -64,12 +64,12 @@ class MemoListCallback : public NumberList MemoListCallback::DoRead(source, mi, ci, number - 1); } - static void DoRead(CommandSource &source, MemoInfo *mi, const ChannelInfo *ci, unsigned index) + static void DoRead(CommandSource &source, MemoServ::MemoInfo *mi, const ChanServ::Channel *ci, unsigned index) { - Memo *m = mi->GetMemo(index); + MemoServ::Memo *m = mi->GetMemo(index); if (!m) return; - + if (ci) source.Reply(_("Memo %d from %s (%s)."), index + 1, m->sender.c_str(), Anope::strftime(m->time, source.GetAccount()).c_str()); else @@ -106,8 +106,8 @@ class CommandMSRead : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - MemoInfo *mi; - ChannelInfo *ci = NULL; + MemoServ::MemoInfo *mi; + ChanServ::Channel *ci = NULL; Anope::string numstr = params[0], chan; if (!numstr.empty() && numstr[0] == '#') @@ -115,7 +115,7 @@ class CommandMSRead : public Command chan = numstr; numstr = params.size() > 1 ? params[1] : ""; - ci = ChannelInfo::Find(chan); + ci = ChanServ::Find(chan); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -126,10 +126,10 @@ class CommandMSRead : public Command source.Reply(ACCESS_DENIED); return; } - mi = &ci->memos; + mi = ci->memos; } else - mi = &source.nc->memos; + mi = source.nc->memos; if (numstr.empty() || (!numstr.equals_ci("LAST") && !numstr.equals_ci("NEW") && !numstr.is_number_only())) this->OnSyntaxError(source, numstr); diff --git a/modules/commands/ms_rsend.cpp b/modules/commands/ms_rsend.cpp index 4cdeb132b..98315845c 100644 --- a/modules/commands/ms_rsend.cpp +++ b/modules/commands/ms_rsend.cpp @@ -34,10 +34,10 @@ class CommandMSRSend : public Command const Anope::string &nick = params[0]; const Anope::string &text = params[1]; - const NickAlias *na = NULL; + const NickServ::Nick *na = NULL; /* prevent user from rsend to themselves */ - if ((na = NickAlias::Find(nick)) && na->nc == source.GetAccount()) + if ((na = NickServ::FindNick(nick)) && na->nc == source.GetAccount()) { source.Reply(_("You can not request a receipt when sending a memo to yourself.")); return; @@ -54,15 +54,15 @@ class CommandMSRSend : public Command source.Reply(_("Please wait %d seconds before using the %s command again."), Config->GetModule("memoserv")->Get<time_t>("senddelay"), source.command.c_str()); else if (result == MemoServ::MemoServService::MEMO_TARGET_FULL) source.Reply(_("Sorry, %s currently has too many memos and cannot receive more."), nick.c_str()); - else + else { source.Reply(_("Memo sent to \002%s\002."), nick.c_str()); - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(nick, ischan); + bool ischan, isregistered; + MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(nick, ischan, isregistered, false); if (mi == NULL) throw CoreException("NULL mi in ms_rsend"); - Memo *m = (mi->memos->size() ? mi->GetMemo(mi->memos->size() - 1) : NULL); + MemoServ::Memo *m = (mi->memos->size() ? mi->GetMemo(mi->memos->size() - 1) : NULL); if (m != NULL) m->receipt = true; } diff --git a/modules/commands/ms_sendall.cpp b/modules/commands/ms_sendall.cpp index c567b0ed3..a1c545ec2 100644 --- a/modules/commands/ms_sendall.cpp +++ b/modules/commands/ms_sendall.cpp @@ -30,9 +30,9 @@ class CommandMSSendAll : public Command Log(LOG_ADMIN, source, this) << "to send " << text; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetAccountList()) { - const NickCore *nc = it->second; + const NickServ::Account *nc = it.second; if (nc != source.nc) MemoServ::service->Send(source.GetNick(), nc->display, text); diff --git a/modules/commands/ms_set.cpp b/modules/commands/ms_set.cpp index 5e5591471..47acb177d 100644 --- a/modules/commands/ms_set.cpp +++ b/modules/commands/ms_set.cpp @@ -14,10 +14,10 @@ class CommandMSSet : public Command { private: - void DoNotify(CommandSource &source, const std::vector<Anope::string> ¶ms, MemoInfo *mi) + void DoNotify(CommandSource &source, const std::vector<Anope::string> ¶ms, MemoServ::MemoInfo *mi) { const Anope::string ¶m = params[1]; - NickCore *nc = source.nc; + NickServ::Account *nc = source.nc; BotInfo *MemoServ = Config->GetClient("MemoServ"); if (!MemoServ) @@ -67,7 +67,7 @@ class CommandMSSet : public Command this->OnSyntaxError(source, ""); } - void DoLimit(CommandSource &source, const std::vector<Anope::string> ¶ms, MemoInfo *mi) + void DoLimit(CommandSource &source, const std::vector<Anope::string> ¶ms, MemoServ::MemoInfo *mi) { Anope::string p1 = params[1]; @@ -75,8 +75,8 @@ class CommandMSSet : public Command Anope::string p3 = params.size() > 3 ? params[3] : ""; Anope::string user, chan; int16_t limit; - NickCore *nc = source.nc; - ChannelInfo *ci = NULL; + NickServ::Account *nc = source.nc; + ChanServ::Channel *ci = NULL; bool is_servadmin = source.HasPriv("memoserv/set-limit"); if (p1[0] == '#') @@ -86,7 +86,7 @@ class CommandMSSet : public Command p2 = p3; p3 = params.size() > 4 ? params[4] : ""; - ci = ChannelInfo::Find(chan); + ci = ChanServ::Find(chan); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); @@ -97,20 +97,20 @@ class CommandMSSet : public Command source.Reply(ACCESS_DENIED); return; } - mi = &ci->memos; + mi = ci->memos; } if (is_servadmin) { if (!p2.empty() && !p2.equals_ci("HARD") && chan.empty()) { - const NickAlias *na; - if (!(na = NickAlias::Find(p1))) + const NickServ::Nick *na; + if (!(na = NickServ::FindNick(p1))) { source.Reply(NICK_X_NOT_REGISTERED, p1.c_str()); return; } user = p1; - mi = &na->nc->memos; + mi = na->nc->memos; nc = na->nc; p1 = p2; p2 = p3; @@ -210,7 +210,7 @@ class CommandMSSet : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { const Anope::string &cmd = params[0]; - MemoInfo *mi = &source.nc->memos; + MemoServ::MemoInfo *mi = source.nc->memos; if (Anope::ReadOnly) source.Reply(_("Sorry, memo option setting is temporarily disabled.")); @@ -219,11 +219,7 @@ class CommandMSSet : public Command else if (cmd.equals_ci("LIMIT")) return this->DoLimit(source, params, mi); else - { this->OnSyntaxError(source, ""); - } - - return; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ms_staff.cpp b/modules/commands/ms_staff.cpp index 125ef60fc..7e33b76b3 100644 --- a/modules/commands/ms_staff.cpp +++ b/modules/commands/ms_staff.cpp @@ -28,9 +28,9 @@ class CommandMSStaff : public Command const Anope::string &text = params[0]; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetAccountList()) { - const NickCore *nc = it->second; + const NickServ::Account *nc = it.second; if (source.nc != nc && nc->IsServicesOper()) MemoServ::service->Send(source.GetNick(), nc->display, text, true); diff --git a/modules/commands/ns_access.cpp b/modules/commands/ns_access.cpp index 1df0bbe0e..e15f2abfd 100644 --- a/modules/commands/ns_access.cpp +++ b/modules/commands/ns_access.cpp @@ -15,7 +15,7 @@ class CommandNSAccess : public Command { private: - void DoAdd(CommandSource &source, NickCore *nc, const Anope::string &mask) + void DoAdd(CommandSource &source, NickServ::Account *nc, const Anope::string &mask) { if (mask.empty()) { @@ -48,7 +48,7 @@ class CommandNSAccess : public Command return; } - void DoDel(CommandSource &source, NickCore *nc, const Anope::string &mask) + void DoDel(CommandSource &source, NickServ::Account *nc, const Anope::string &mask) { if (mask.empty()) { @@ -75,7 +75,7 @@ class CommandNSAccess : public Command return; } - void DoList(CommandSource &source, NickCore *nc, const Anope::string &mask) + void DoList(CommandSource &source, NickServ::Account *nc, const Anope::string &mask) { unsigned i, end; @@ -118,10 +118,10 @@ class CommandNSAccess : public Command mask = params.size() > 1 ? params[params.size() - 1] : ""; } - NickCore *nc; + NickServ::Account *nc; if (!nick.empty()) { - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -199,7 +199,7 @@ class NSAccess : public Module { } - void OnNickRegister(User *u, NickAlias *na) override + void OnNickRegister(User *u, NickServ::Nick *na) override { if (u && Config->GetModule(this)->Get<bool>("addaccessonreg")) na->nc->AddAccess(u->Mask()); diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp index 0967dbf61..834607028 100644 --- a/modules/commands/ns_ajoin.cpp +++ b/modules/commands/ns_ajoin.cpp @@ -21,7 +21,7 @@ struct AJoinList : Serialize::Checker<std::vector<AJoinEntry *> > struct AJoinEntry : Serializable { - Serialize::Reference<NickCore> owner; + Serialize::Reference<NickServ::Account> owner; Anope::string channel; Anope::string key; @@ -54,7 +54,7 @@ struct AJoinEntry : Serializable sd["owner"] >> sowner; - NickCore *nc = NickCore::Find(sowner); + NickServ::Account *nc = NickServ::FindAccount(sowner); if (nc == NULL) return NULL; @@ -88,7 +88,7 @@ AJoinList::~AJoinList() class CommandNSAJoin : public Command { - void DoList(CommandSource &source, NickCore *nc) + void DoList(CommandSource &source, NickServ::Account *nc) { AJoinList *channels = nc->Require<AJoinList>("ajoinlist"); @@ -118,7 +118,7 @@ class CommandNSAJoin : public Command } } - void DoAdd(CommandSource &source, NickCore *nc, const Anope::string &chans, const Anope::string &keys) + void DoAdd(CommandSource &source, NickServ::Account *nc, const Anope::string &chans, const Anope::string &keys) { AJoinList *channels = nc->Require<AJoinList>("ajoinlist"); @@ -184,7 +184,7 @@ class CommandNSAJoin : public Command source.Reply(_("%s added to %s's auto join list."), addedchans.c_str(), nc->display.c_str()); } - void DoDel(CommandSource &source, NickCore *nc, const Anope::string &chans) + void DoDel(CommandSource &source, NickServ::Account *nc, const Anope::string &chans) { AJoinList *channels = nc->Require<AJoinList>("ajoinlist"); Anope::string delchans; @@ -197,7 +197,7 @@ class CommandNSAJoin : public Command for (; i < (*channels)->size(); ++i) if ((*channels)->at(i)->channel.equals_ci(chan)) break; - + if (i == (*channels)->size()) notfoundchans += chan + ", "; else @@ -243,10 +243,10 @@ class CommandNSAJoin : public Command else nick = (params.size() > 2 && IRCD->IsChannelValid(params[2])) ? params[1] : ""; - NickCore *nc; + NickServ::Account *nc; if (!nick.empty()) { - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -333,17 +333,17 @@ class NSAJoin : public Module { AJoinEntry *entry = (*channels)->at(i); Channel *c = Channel::Find(entry->channel); - ChannelInfo *ci; + ChanServ::Channel *ci; if (c) ci = c->ci; else - ci = ChannelInfo::Find(entry->channel); + ci = ChanServ::Find(entry->channel); bool need_invite = false; Anope::string key = entry->key; - AccessGroup u_access; - + ChanServ::AccessGroup u_access; + if (ci != NULL) { if (ci->HasExt("CS_SUSPENDED")) @@ -364,7 +364,7 @@ class NSAJoin : public Module need_invite = true; else if (c->HasMode("INVITE") && c->MatchesList(u, "INVITEOVERRIDE") == false) need_invite = true; - + if (c->HasMode("KEY")) { Anope::string k; diff --git a/modules/commands/ns_alist.cpp b/modules/commands/ns_alist.cpp index 54216b190..ff3b5d037 100644 --- a/modules/commands/ns_alist.cpp +++ b/modules/commands/ns_alist.cpp @@ -13,7 +13,7 @@ class CommandNSAList : public Command { - static bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2) + static bool ChannelSort(ChanServ::Channel *ci1, ChanServ::Channel *ci2) { return ci::less()(ci1->name, ci2->name); } @@ -28,12 +28,12 @@ class CommandNSAList : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { Anope::string nick = source.GetNick(); - NickCore *nc = source.nc; + NickServ::Account *nc = source.nc; if (params.size() && source.HasPriv("nickserv/alist")) { nick = params[0]; - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -47,13 +47,13 @@ class CommandNSAList : public Command list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Access")).AddColumn(_("Description")); - std::deque<ChannelInfo *> queue; + std::deque<ChanServ::Channel *> queue; nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); for (unsigned i = 0; i < queue.size(); ++i) { - ChannelInfo *ci = queue[i]; + ChanServ::Channel *ci = queue[i]; ListFormatter::ListEntry entry; if (ci->GetFounder() == nc) @@ -78,10 +78,10 @@ class CommandNSAList : public Command continue; } - AccessGroup access = ci->AccessFor(nc); + ChanServ::AccessGroup access = ci->AccessFor(nc); if (access.empty()) continue; - + ++chan_count; entry["Number"] = stringify(chan_count); diff --git a/modules/commands/ns_cert.cpp b/modules/commands/ns_cert.cpp index bda723981..4f2ab5270 100644 --- a/modules/commands/ns_cert.cpp +++ b/modules/commands/ns_cert.cpp @@ -13,16 +13,16 @@ #include "modules/ns_cert.h" #include "modules/nickserv.h" -static Anope::hash_map<NickCore *> certmap; +static Anope::hash_map<NickServ::Account *> certmap; static EventHandlers<Event::NickCertEvents> *events; struct CertServiceImpl : CertService { CertServiceImpl(Module *o) : CertService(o) { } - NickCore* FindAccountFromCert(const Anope::string &cert) override + NickServ::Account* FindAccountFromCert(const Anope::string &cert) override { - Anope::hash_map<NickCore *>::iterator it = certmap.find(cert); + Anope::hash_map<NickServ::Account *>::iterator it = certmap.find(cert); if (it != certmap.end()) return it->second; return NULL; @@ -31,11 +31,11 @@ struct CertServiceImpl : CertService struct NSCertListImpl : NSCertList { - Serialize::Reference<NickCore> nc; + Serialize::Reference<NickServ::Account> nc; std::vector<Anope::string> certs; public: - NSCertListImpl(Extensible *obj) : nc(anope_dynamic_static_cast<NickCore *>(obj)) { } + NSCertListImpl(Extensible *obj) : nc(anope_dynamic_static_cast<NickServ::Account *>(obj)) { } ~NSCertListImpl() { @@ -127,10 +127,10 @@ struct NSCertListImpl : NSCertList void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override { - if (s->GetSerializableType()->GetName() != "NickCore") + if (s->GetSerializableType()->GetName() != "NickServ::Account") return; - const NickCore *n = anope_dynamic_static_cast<const NickCore *>(e); + const NickServ::Account *n = anope_dynamic_static_cast<const NickServ::Account *>(e); NSCertList *c = this->Get(n); if (c == NULL || !c->GetCertCount()) return; @@ -141,10 +141,10 @@ struct NSCertListImpl : NSCertList void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override { - if (s->GetSerializableType()->GetName() != "NickCore") + if (s->GetSerializableType()->GetName() != "NickServ::Account") return; - NickCore *n = anope_dynamic_static_cast<NickCore *>(e); + NickServ::Account *n = anope_dynamic_static_cast<NickServ::Account *>(e); NSCertListImpl *c = this->Require(n); Anope::string buf; @@ -165,7 +165,7 @@ struct NSCertListImpl : NSCertList class CommandNSCert : public Command { private: - void DoAdd(CommandSource &source, NickCore *nc, Anope::string certfp) + void DoAdd(CommandSource &source, NickServ::Account *nc, Anope::string certfp) { NSCertList *cl = nc->Require<NSCertList>("certificates"); unsigned max = Config->GetModule(this->owner)->Get<unsigned>("max", "5"); @@ -206,7 +206,7 @@ class CommandNSCert : public Command source.Reply(_("\002%s\002 added to %s's certificate list."), certfp.c_str(), nc->display.c_str()); } - void DoDel(CommandSource &source, NickCore *nc, Anope::string certfp) + void DoDel(CommandSource &source, NickServ::Account *nc, Anope::string certfp) { NSCertList *cl = nc->Require<NSCertList>("certificates"); @@ -235,7 +235,7 @@ class CommandNSCert : public Command source.Reply(_("\002%s\002 deleted from %s's certificate list."), certfp.c_str(), nc->display.c_str()); } - void DoList(CommandSource &source, const NickCore *nc) + void DoList(CommandSource &source, const NickServ::Account *nc) { NSCertList *cl = nc->GetExt<NSCertList>("certificates"); @@ -275,10 +275,10 @@ class CommandNSCert : public Command certfp = params.size() > 1 ? params[params.size() - 1] : ""; } - NickCore *nc; + NickServ::Account *nc; if (!nick.empty()) { - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -371,11 +371,11 @@ class NSCert : public Module if (!NickServ || u->IsIdentified()) return; - NickCore *nc = cs.FindAccountFromCert(u->fingerprint); + NickServ::Account *nc = cs.FindAccountFromCert(u->fingerprint); if (!nc || nc->HasExt("NS_SUSPENDED")) return; - NickAlias *na = NickAlias::Find(u->nick); + NickServ::Nick *na = NickServ::FindNick(u->nick); if (na && na->nc == nc) u->Identify(na); else @@ -385,7 +385,7 @@ class NSCert : public Module Log(NickServ) << u->GetMask() << " automatically identified for account " << nc->display << " via SSL certificate fingerprint"; } - EventReturn OnNickValidate(User *u, NickAlias *na) override + EventReturn OnNickValidate(User *u, NickServ::Nick *na) override { NSCertList *cl = certs.Get(na->nc); if (!u->fingerprint.empty() && cl && cl->FindCert(u->fingerprint)) diff --git a/modules/commands/ns_drop.cpp b/modules/commands/ns_drop.cpp index fef7682da..bd5fd7305 100644 --- a/modules/commands/ns_drop.cpp +++ b/modules/commands/ns_drop.cpp @@ -33,7 +33,7 @@ class CommandNSDrop : public Command return; } - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); diff --git a/modules/commands/ns_getemail.cpp b/modules/commands/ns_getemail.cpp index 96845571c..b926b6756 100644 --- a/modules/commands/ns_getemail.cpp +++ b/modules/commands/ns_getemail.cpp @@ -31,9 +31,9 @@ class CommandNSGetEMail : public Command Log(LOG_ADMIN, source, this) << "on " << email; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetAccountList()) { - const NickCore *nc = it->second; + const NickServ::Account *nc = it.second; if (!nc->email.empty() && nc->email.equals_ci(email)) { @@ -66,7 +66,7 @@ class CommandNSGetEMail : public Command class NSGetEMail : public Module { CommandNSGetEMail commandnsgetemail; - + public: NSGetEMail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , commandnsgetemail(this) diff --git a/modules/commands/ns_getpass.cpp b/modules/commands/ns_getpass.cpp index c9bfc0402..344947988 100644 --- a/modules/commands/ns_getpass.cpp +++ b/modules/commands/ns_getpass.cpp @@ -24,9 +24,9 @@ class CommandNSGetPass : public Command { const Anope::string &nick = params[0]; Anope::string tmp_pass; - const NickAlias *na; + const NickServ::Nick *na; - if (!(na = NickAlias::Find(nick))) + if (!(na = NickServ::FindNick(nick))) source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && na->nc->IsServicesOper()) source.Reply(_("You may not get the password of other Services Operators.")); diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp index edd12f83d..bc61ee099 100644 --- a/modules/commands/ns_group.cpp +++ b/modules/commands/ns_group.cpp @@ -13,24 +13,24 @@ #include "modules/ns_cert.h" #include "modules/ns_group.h" -class NSGroupRequest : public IdentifyRequest +class NSGroupRequestListener : public NickServ::IdentifyRequestListener { EventHandlers<Event::NickGroup> &onnickgroup; CommandSource source; Command *cmd; Anope::string nick; - Reference<NickAlias> target; - + Reference<NickServ::Nick> target; + public: - NSGroupRequest(Module *o, EventHandlers<Event::NickGroup> &event, CommandSource &src, Command *c, const Anope::string &n, NickAlias *targ, const Anope::string &pass) : IdentifyRequest(o, targ->nc->display, pass), onnickgroup(event), source(src), cmd(c), nick(n), target(targ) { } + NSGroupRequestListener(EventHandlers<Event::NickGroup> &event, CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : onnickgroup(event), source(src), cmd(c), nick(n), target(targ) { } - void OnSuccess() override + void OnSuccess(NickServ::IdentifyRequest *) override { if (!source.GetUser() || source.GetUser()->nick != nick || !target || !target->nc) return; User *u = source.GetUser(); - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); /* If the nick is already registered, drop it. */ if (na) { @@ -38,7 +38,7 @@ class NSGroupRequest : public IdentifyRequest delete na; } - na = new NickAlias(nick, target->nc); + na = NickServ::service->CreateNick(nick, target->nc); Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); na->last_usermask = last_usermask; @@ -55,19 +55,14 @@ class NSGroupRequest : public IdentifyRequest } - void OnFail() override + void OnFail(NickServ::IdentifyRequest *) override { if (!source.GetUser()) return; Log(LOG_COMMAND, source, cmd) << "and failed to group to " << target->nick; - if (NickAlias::Find(GetAccount()) != NULL) - { - source.Reply(PASSWORD_INCORRECT); - source.GetUser()->BadPassword(); - } - else - source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str()); + source.Reply(PASSWORD_INCORRECT); + source.GetUser()->BadPassword(); } }; @@ -91,7 +86,7 @@ class CommandNSGroup : public Command Anope::string nick; if (params.empty()) { - NickCore* core = u->Account(); + NickServ::Account* core = u->Account(); if (core) nick = core->display; } @@ -130,11 +125,11 @@ class CommandNSGroup : public Command } } - NickAlias *target, *na = NickAlias::Find(u->nick); + NickServ::Nick *target, *na = NickServ::FindNick(u->nick); const Anope::string &guestnick = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest"); time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay"); unsigned maxaliases = Config->GetModule(this->owner)->Get<unsigned>("maxaliases"); - if (!(target = NickAlias::Find(nick))) + if (!(target = NickServ::FindNick(nick))) source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (Anope::CurTime < u->lastnickreg + reg_delay) source.Reply(_("Please wait %d seconds before using the GROUP command again."), (reg_delay + u->lastnickreg) - Anope::CurTime); @@ -169,18 +164,18 @@ class CommandNSGroup : public Command if (ok == false && !pass.empty()) { - NSGroupRequest *req = new NSGroupRequest(owner, this->onnickgroup, source, this, u->nick, target, pass); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(onnickgroup, source, this, u->nick, target), owner, target->nc->display, pass); Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else { - NSGroupRequest req(owner, this->onnickgroup, source, this, u->nick, target, pass); + NSGroupRequestListener req(onnickgroup, source, this, u->nick, target); if (ok) - req.OnSuccess(); + req.OnSuccess(nullptr); else - req.OnFail(); + req.OnFail(nullptr); } } } @@ -233,7 +228,7 @@ class CommandNSUngroup : public Command { User *u = source.GetUser(); Anope::string nick = !params.empty() ? params[0] : ""; - NickAlias *na = NickAlias::Find(!nick.empty() ? nick : u->nick); + NickServ::Nick *na = NickServ::FindNick(!nick.empty() ? nick : u->nick); if (u->Account()->aliases->size() == 1) source.Reply(_("Your nick is not grouped to anything, you can't ungroup it.")); @@ -243,16 +238,16 @@ class CommandNSUngroup : public Command source.Reply(_("Nick %s is not in your group."), na->nick.c_str()); else { - NickCore *oldcore = na->nc; + NickServ::Account *oldcore = na->nc; - std::vector<NickAlias *>::iterator it = std::find(oldcore->aliases->begin(), oldcore->aliases->end(), na); + std::vector<NickServ::Nick *>::iterator it = std::find(oldcore->aliases->begin(), oldcore->aliases->end(), na); if (it != oldcore->aliases->end()) oldcore->aliases->erase(it); if (na->nick.equals_ci(oldcore->display)) oldcore->SetDisplay(oldcore->aliases->front()); - NickCore *nc = new NickCore(na->nick); + NickServ::Account *nc = NickServ::service->CreateAccount(na->nick); na->nc = nc; nc->aliases->push_back(na); @@ -294,11 +289,11 @@ class CommandNSGList : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { const Anope::string &nick = !params.empty() ? params[0] : ""; - const NickCore *nc; + const NickServ::Account *nc; if (!nick.empty()) { - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -321,7 +316,7 @@ class CommandNSGList : public Command unconfirmed_expire = Config->GetModule("nickserv")->Get<time_t>("unconfirmedexpire", "1d"); for (unsigned i = 0; i < nc->aliases->size(); ++i) { - const NickAlias *na2 = nc->aliases->at(i); + const NickServ::Nick *na2 = nc->aliases->at(i); Anope::string expires; if (na2->HasExt("NS_NO_EXPIRE")) @@ -342,7 +337,7 @@ class CommandNSGList : public Command source.Reply(!nick.empty() ? _("List of nicknames in the group of \002%s\002:") : _("List of nicknames in your group:"), nc->display.c_str()); std::vector<Anope::string> replies; list.Process(replies); - + for (unsigned i = 0; i < replies.size(); ++i) source.Reply(replies[i]); diff --git a/modules/commands/ns_identify.cpp b/modules/commands/ns_identify.cpp index 5d7ed4c95..03c79c623 100644 --- a/modules/commands/ns_identify.cpp +++ b/modules/commands/ns_identify.cpp @@ -11,24 +11,24 @@ #include "module.h" -class NSIdentifyRequest : public IdentifyRequest +class NSIdentifyRequestListener : public NickServ::IdentifyRequestListener { CommandSource source; Command *cmd; public: - NSIdentifyRequest(Module *o, CommandSource &s, Command *c, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(o, acc, pass), source(s), cmd(c) { } + NSIdentifyRequestListener(CommandSource &s, Command *c) : source(s), cmd(c) { } - void OnSuccess() override + void OnSuccess(NickServ::IdentifyRequest *req) override { if (!source.GetUser()) return; User *u = source.GetUser(); - NickAlias *na = NickAlias::Find(GetAccount()); + NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (!na) - source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str()); + source.Reply(NICK_X_NOT_REGISTERED, req->GetAccount().c_str()); else { if (u->IsIdentified()) @@ -40,19 +40,19 @@ class NSIdentifyRequest : public IdentifyRequest } } - void OnFail() override + void OnFail(NickServ::IdentifyRequest *req) override { if (source.GetUser()) { - bool accountexists = NickAlias::Find(GetAccount()) != NULL; - Log(LOG_COMMAND, source, cmd) << "and failed to identify to" << (accountexists ? " " : " nonexistent ") << "account " << GetAccount(); + bool accountexists = NickServ::FindNick(req->GetAccount()) != NULL; + Log(LOG_COMMAND, source, cmd) << "and failed to identify to" << (accountexists ? " " : " nonexistent ") << "account " << req->GetAccount(); if (accountexists) { source.Reply(PASSWORD_INCORRECT); source.GetUser()->BadPassword(); } else - source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str()); + source.Reply(NICK_X_NOT_REGISTERED, req->GetAccount().c_str()); } } }; @@ -75,14 +75,14 @@ class CommandNSIdentify : public Command const Anope::string &nick = params.size() == 2 ? params[0] : u->nick; Anope::string pass = params[params.size() - 1]; - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (na && na->nc->HasExt("NS_SUSPENDED")) source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); else if (u->Account() && na && u->Account() == na->nc) source.Reply(_("You are already identified.")); else { - NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), owner, na ? na->nc->display : nick, pass); Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req); req->Dispatch(); } diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp index 16f51db07..5bf413591 100644 --- a/modules/commands/ns_info.cpp +++ b/modules/commands/ns_info.cpp @@ -29,7 +29,7 @@ class CommandNSInfo : public Command { const Anope::string &nick = params.size() ? params[0] : (source.nc ? source.nc->display : source.GetNick()); - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); bool has_auspex = source.HasPriv("nickserv/auspex"); if (!na) @@ -150,13 +150,13 @@ class CommandNSSetHide : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp index 0037cbcc5..78daff7ef 100644 --- a/modules/commands/ns_list.cpp +++ b/modules/commands/ns_list.cpp @@ -26,7 +26,7 @@ class CommandNSList : public Command { Anope::string pattern = params[0]; - const NickCore *mync; + const NickServ::Account *mync; unsigned nnicks; bool is_servadmin = source.HasCommand("nickserv/list"); int count = 0, from = 0, to = 0; @@ -76,13 +76,13 @@ class CommandNSList : public Command list.AddColumn(_("Nick")).AddColumn(_("Last usermask")); - Anope::map<NickAlias *> ordered_map; - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) - ordered_map[it->first] = it->second; + Anope::map<NickServ::Nick *> ordered_map; + for (auto& it : NickServ::service->GetNickList()) + ordered_map[it.first] = it.second; - for (Anope::map<NickAlias *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) + for (Anope::map<NickServ::Nick *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) { - const NickAlias *na = it->second; + const NickServ::Nick *na = it->second; /* Don't show private nicks to non-services admins. */ if (na->nc->HasExt("NS_PRIVATE") && !is_servadmin && na->nc != mync) @@ -121,7 +121,7 @@ class CommandNSList : public Command ++count; } } - + source.Reply(_("List of entries matching \002%s\002:"), pattern.c_str()); std::vector<Anope::string> replies; @@ -197,13 +197,13 @@ class CommandNSSetPrivate : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) @@ -293,7 +293,7 @@ class NSList : public Module { } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_all) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_all) override { if (!show_all) return; diff --git a/modules/commands/ns_recover.cpp b/modules/commands/ns_recover.cpp index de83ea619..3307c6668 100644 --- a/modules/commands/ns_recover.cpp +++ b/modules/commands/ns_recover.cpp @@ -15,22 +15,23 @@ typedef std::map<Anope::string, ChannelStatus> NSRecoverInfo; -class NSRecoverRequest : public IdentifyRequest +class NSRecoverRequestListener : public NickServ::IdentifyRequestListener { CommandSource source; Command *cmd; Anope::string user; - + Anope::string pass; + public: - NSRecoverRequest(Module *o, CommandSource &src, Command *c, const Anope::string &nick, const Anope::string &pass) : IdentifyRequest(o, nick, pass), source(src), cmd(c), user(nick) { } + NSRecoverRequestListener(CommandSource &src, Command *c, const Anope::string &nick, const Anope::string &p) : source(src), cmd(c), user(nick), pass(p) { } - void OnSuccess() override + void OnSuccess(NickServ::IdentifyRequest *) override { User *u = User::Find(user, true); if (!source.GetUser() || !source.service) return; - NickAlias *na = NickAlias::Find(user); + NickServ::Nick *na = NickServ::FindNick(user); if (!na) return; @@ -66,7 +67,7 @@ class NSRecoverRequest : public IdentifyRequest } } - u->SendMessage(source.service, _("This nickname has been recovered by %s. If you did not do\n" + u->SendMessage(*source.service, _("This nickname has been recovered by %s. If you did not do\n" "this then %s may have your password, and you should change it."), source.GetNick().c_str(), source.GetNick().c_str()); @@ -76,7 +77,7 @@ class NSRecoverRequest : public IdentifyRequest source.Reply(_("Ghost with your nick has been killed.")); if (IRCD->CanSVSNick) - IRCD->SendForceNickChange(source.GetUser(), GetAccount(), Anope::CurTime); + IRCD->SendForceNickChange(source.GetUser(), user, Anope::CurTime); } /* User is not identified or not identified to the same account as the person using this command */ else @@ -87,7 +88,7 @@ class NSRecoverRequest : public IdentifyRequest Log(LOG_COMMAND, source, cmd) << "and was automatically identified to " << na->nick << " (" << na->nc->display << ")"; } - u->SendMessage(source.service, _("This nickname has been recovered by %s."), source.GetNick().c_str()); + u->SendMessage(*source.service, _("This nickname has been recovered by %s."), source.GetNick().c_str()); if (NickServ::service) NickServ::service->Collide(u, na); @@ -95,7 +96,7 @@ class NSRecoverRequest : public IdentifyRequest { /* If we can svsnick then release our hold and svsnick the user using the command */ NickServ::service->Release(na); - IRCD->SendForceNickChange(source.GetUser(), GetAccount(), Anope::CurTime); + IRCD->SendForceNickChange(source.GetUser(), user, Anope::CurTime); } else source.Reply(_("The user with your nick has been removed. Use this command again\n" @@ -103,20 +104,20 @@ class NSRecoverRequest : public IdentifyRequest } } - void OnFail() override + void OnFail(NickServ::IdentifyRequest *) override { - if (NickAlias::Find(GetAccount()) != NULL) + if (NickServ::FindNick(user) != NULL) { source.Reply(ACCESS_DENIED); - if (!GetPassword().empty()) + if (!pass.empty()) { - Log(LOG_COMMAND, source, cmd) << "with an invalid password for " << GetAccount(); + Log(LOG_COMMAND, source, cmd) << "with an invalid password for " << user; if (source.GetUser()) source.GetUser()->BadPassword(); } } else - source.Reply(NICK_X_NOT_REGISTERED, GetAccount().c_str()); + source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); } }; @@ -143,7 +144,7 @@ class CommandNSRecover : public Command return; } - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { @@ -168,18 +169,18 @@ class CommandNSRecover : public Command if (ok == false && !pass.empty()) { - NSRecoverRequest *req = new NSRecoverRequest(owner, source, this, na->nick, pass); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->nick, pass), owner, na->nick, pass); Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else { - NSRecoverRequest req(owner, source, this, na->nick, pass); + NSRecoverRequestListener req(source, this, na->nick, pass); if (ok) - req.OnSuccess(); + req.OnSuccess(nullptr); else - req.OnFail(); + req.OnFail(nullptr); } } diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index 802292c91..590ced8dc 100644 --- a/modules/commands/ns_register.cpp +++ b/modules/commands/ns_register.cpp @@ -12,7 +12,7 @@ #include "module.h" #include "modules/nickserv.h" -static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi); +static bool SendRegmail(User *u, const NickServ::Nick *na, BotInfo *bi); class CommandNSConfirm : public Command { @@ -30,7 +30,7 @@ class CommandNSConfirm : public Command if (source.nc && !source.nc->HasExt("UNCONFIRMED") && source.HasPriv("nickserv/confirm")) { - NickAlias *na = NickAlias::Find(passcode); + NickServ::Nick *na = NickServ::FindNick(passcode); if (na == NULL) source.Reply(NICK_X_NOT_REGISTERED, passcode.c_str()); else if (na->nc->HasExt("UNCONFIRMED") == false) @@ -47,7 +47,7 @@ class CommandNSConfirm : public Command Anope::string *code = source.nc->GetExt<Anope::string>("passcode"); if (code != NULL && *code == passcode) { - NickCore *nc = source.nc; + NickServ::Account *nc = source.nc; nc->Shrink<Anope::string>("passcode"); Log(LOG_COMMAND, source, this) << "to confirm their email"; source.Reply(_("Your email address of \002%s\002 has been confirmed."), source.nc->email.c_str()); @@ -55,7 +55,7 @@ class CommandNSConfirm : public Command if (source.GetUser()) { - NickAlias *na = NickAlias::Find(source.GetNick()); + NickServ::Nick *na = NickServ::FindNick(source.GetNick()); if (na) { IRCD->SendLogin(source.GetUser(), na); @@ -173,7 +173,7 @@ class CommandNSRegister : public Command this->OnSyntaxError(source, ""); else if (u && Anope::CurTime < u->lastnickreg + reg_delay) source.Reply(_("Please wait %d seconds before using the REGISTER command again."), (u->lastnickreg + reg_delay) - Anope::CurTime); - else if (NickAlias::Find(u_nick) != NULL) + else if (NickServ::FindNick(u_nick) != NULL) source.Reply(NICK_ALREADY_REGISTERED, u_nick.c_str()); else if (pass.equals_ci(u_nick) || (Config->GetBlock("options")->Get<bool>("strictpasswords") && pass.length() < 5)) source.Reply(MORE_OBSCURE_PASSWORD); @@ -183,8 +183,8 @@ class CommandNSRegister : public Command source.Reply(MAIL_X_INVALID, email.c_str()); else { - NickCore *nc = new NickCore(u_nick); - NickAlias *na = new NickAlias(u_nick, nc); + NickServ::Account *nc = NickServ::service->CreateAccount(u_nick); + NickServ::Nick *na = NickServ::service->CreateNick(u_nick, nc); Anope::Encrypt(pass, nc->pass); if (!email.empty()) nc->email = email; @@ -291,7 +291,7 @@ class CommandNSResend : public Command return; } - const NickAlias *na = NickAlias::Find(source.GetNick()); + const NickServ::Nick *na = NickServ::FindNick(source.GetNick()); if (na == NULL) source.Reply(NICK_NOT_REGISTERED); @@ -367,7 +367,7 @@ class NSRegister : public Module u->SendMessage(NickServ, _("All new accounts must be validated by an administrator. Please wait for your registration to be confirmed.")); else u->SendMessage(NickServ, _("Your email address is not confirmed. To confirm it, follow the instructions that were emailed to you.")); - const NickAlias *this_na = NickAlias::Find(u->Account()->display); + const NickServ::Nick *this_na = NickServ::FindNick(u->Account()->display); time_t time_registered = Anope::CurTime - this_na->time_registered; time_t unconfirmed_expire = Config->GetModule(this)->Get<time_t>("unconfirmedexpire", "1d"); if (unconfirmed_expire > time_registered) @@ -375,7 +375,7 @@ class NSRegister : public Module } } - void OnPreNickExpire(NickAlias *na, bool &expire) override + void OnPreNickExpire(NickServ::Nick *na, bool &expire) override { if (unconfirmed.HasExt(na->nc)) { @@ -386,9 +386,9 @@ class NSRegister : public Module } }; -static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi) +static bool SendRegmail(User *u, const NickServ::Nick *na, BotInfo *bi) { - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; Anope::string *code = na->nc->GetExt<Anope::string>("passcode"); if (code == NULL) diff --git a/modules/commands/ns_resetpass.cpp b/modules/commands/ns_resetpass.cpp index af5c43cb7..d4171807d 100644 --- a/modules/commands/ns_resetpass.cpp +++ b/modules/commands/ns_resetpass.cpp @@ -11,7 +11,7 @@ #include "module.h" -static bool SendResetEmail(User *u, const NickAlias *na, BotInfo *bi); +static bool SendResetEmail(User *u, const NickServ::Nick *na, BotInfo *bi); class CommandNSResetPass : public Command { @@ -25,9 +25,9 @@ class CommandNSResetPass : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - const NickAlias *na; + const NickServ::Nick *na; - if (!(na = NickAlias::Find(params[0]))) + if (!(na = NickServ::FindNick(params[0]))) source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str()); else if (!na->nc->email.equals_ci(params[1])) source.Reply(_("Incorrect email address.")); @@ -85,12 +85,12 @@ class NSResetPass : public Module return EVENT_STOP; } - NickAlias *na = NickAlias::Find(params[0]); + NickServ::Nick *na = NickServ::FindNick(params[0]); ResetInfo *ri = na ? reset.Get(na->nc) : NULL; if (na && ri) { - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; const Anope::string &passcode = params[1]; if (ri->time < Anope::CurTime - 3600) { @@ -121,7 +121,7 @@ class NSResetPass : public Module } }; -static bool SendResetEmail(User *u, const NickAlias *na, BotInfo *bi) +static bool SendResetEmail(User *u, const NickServ::Nick *na, BotInfo *bi) { Anope::string subject = Language::Translate(na->nc, Config->GetBlock("mail")->Get<const Anope::string>("reset_subject").c_str()), message = Language::Translate(na->nc, Config->GetBlock("mail")->Get<const Anope::string>("reset_message").c_str()), diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 89f3c5e83..984f1d002 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -179,13 +179,13 @@ class CommandNSSASetPassword : public Command return; } - const NickAlias *setter_na = NickAlias::Find(params[0]); + const NickServ::Nick *setter_na = NickServ::FindNick(params[0]); if (setter_na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str()); return; } - NickCore *nc = setter_na->nc; + NickServ::Account *nc = setter_na->nc; size_t len = params[1].length(); @@ -241,13 +241,13 @@ class CommandNSSetAutoOp : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT; MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); @@ -333,7 +333,7 @@ class CommandNSSetDisplay : public Command return; } - const NickAlias *user_na = NickAlias::Find(user), *na = NickAlias::Find(param); + const NickServ::Nick *user_na = NickServ::FindNick(user), *na = NickServ::FindNick(param); if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership")) { @@ -406,7 +406,7 @@ class CommandNSSetEmail : public Command static bool SendConfirmMail(User *u, BotInfo *bi, const Anope::string &new_email) { Anope::string code = Anope::Random(9); - + std::pair<Anope::string, Anope::string> *n = u->Account()->Extend<std::pair<Anope::string, Anope::string> >("ns_set_email"); n->first = new_email; n->second = code; @@ -444,13 +444,13 @@ class CommandNSSetEmail : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; if (nc->HasExt("UNCONFIRMED")) { @@ -557,13 +557,13 @@ class CommandNSSetKeepModes : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT; MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); @@ -650,13 +650,13 @@ class CommandNSSetKill : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT; MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); @@ -782,13 +782,13 @@ class CommandNSSetLanguage : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT; MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); @@ -891,13 +891,13 @@ class CommandNSSetMessage : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; if (!Config->GetBlock("options")->Get<bool>("useprivmsg")) { @@ -995,13 +995,13 @@ class CommandNSSetSecure : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT; MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); @@ -1090,7 +1090,7 @@ class CommandNSSASetNoexpire : public Command return; } - NickAlias *na = NickAlias::Find(params[0]); + NickServ::Nick *na = NickServ::FindNick(params[0]); if (na == NULL) { source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str()); @@ -1168,7 +1168,7 @@ class NSSet : public Module SerializableExtensibleItem<bool> autoop, killprotect, kill_quick, kill_immed, message, secure, noexpire; - + struct KeepModes : SerializableExtensibleItem<bool> { KeepModes(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { } @@ -1177,10 +1177,10 @@ class NSSet : public Module { SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data); - if (s->GetSerializableType()->GetName() != "NickCore") + if (s->GetSerializableType()->GetName() != "NickServ::Account") return; - const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s); + const NickServ::Account *nc = anope_dynamic_static_cast<const NickServ::Account *>(s); Anope::string modes; for (User::ModeList::const_iterator it = nc->last_modes.begin(); it != nc->last_modes.end(); ++it) { @@ -1197,10 +1197,10 @@ class NSSet : public Module { SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data); - if (s->GetSerializableType()->GetName() != "NickCore") + if (s->GetSerializableType()->GetName() != "NickServ::Account") return; - NickCore *nc = anope_dynamic_static_cast<NickCore *>(s); + NickServ::Account *nc = anope_dynamic_static_cast<NickServ::Account *>(s); Anope::string modes; data["last_modes"] >> modes; for (spacesepstream sep(modes); sep.GetToken(modes);) @@ -1264,7 +1264,7 @@ class NSSet : public Module EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) override { - NickCore *uac = source.nc; + NickServ::Account *uac = source.nc; if (command->name == "nickserv/confirm" && !params.empty() && uac) { @@ -1285,7 +1285,7 @@ class NSSet : public Module return EVENT_CONTINUE; } - void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override + void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { if (chan->ci) { @@ -1294,13 +1294,13 @@ class NSSet : public Module } } - void OnPreNickExpire(NickAlias *na, bool &expire) override + void OnPreNickExpire(NickServ::Nick *na, bool &expire) override { if (noexpire.HasExt(na)) expire = false; } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { if (!show_hidden) return; diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp index bf3ea8660..4038b9cc1 100644 --- a/modules/commands/ns_set_misc.cpp +++ b/modules/commands/ns_set_misc.cpp @@ -37,7 +37,7 @@ struct NSMiscData : MiscData, Serializable { NSMiscData(Extensible *) : Serializable("NSMiscData") { } - NSMiscData(NickCore *ncore, const Anope::string &n, const Anope::string &d) : Serializable("NSMiscData") + NSMiscData(NickServ::Account *ncore, const Anope::string &n, const Anope::string &d) : Serializable("NSMiscData") { object = ncore->display; name = n; @@ -59,7 +59,7 @@ struct NSMiscData : MiscData, Serializable data["name"] >> sname; data["data"] >> sdata; - NickCore *nc = NickCore::Find(snc); + NickServ::Account *nc = NickServ::FindAccount(snc); if (nc == NULL) return NULL; @@ -106,13 +106,13 @@ class CommandNSSetMisc : public Command return; } - const NickAlias *na = NickAlias::Find(user); + const NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) @@ -206,7 +206,7 @@ class NSSetMisc : public Module for (int i = 0; i < conf->CountBlock("command"); ++i) { Configuration::Block *block = conf->GetBlock("command", i); - + const Anope::string &cmd = block->Get<const Anope::string>("command"); if (cmd != "nickserv/set/misc" && cmd != "nickserv/saset/misc") @@ -222,7 +222,7 @@ class NSSetMisc : public Module } } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool) override { for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) { diff --git a/modules/commands/ns_status.cpp b/modules/commands/ns_status.cpp index f4c8c7192..24c901a52 100644 --- a/modules/commands/ns_status.cpp +++ b/modules/commands/ns_status.cpp @@ -24,7 +24,7 @@ class CommandNSStatus : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { const Anope::string &nick = !params.empty() ? params[0] : source.GetNick(); - const NickAlias *na = NickAlias::Find(nick); + const NickServ::Nick *na = NickServ::FindNick(nick); spacesepstream sep(nick); Anope::string nickbuf; diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp index ca669d537..ae8dd20ee 100644 --- a/modules/commands/ns_suspend.cpp +++ b/modules/commands/ns_suspend.cpp @@ -37,7 +37,7 @@ struct NSSuspendInfo : SuspendInfo, Serializable si = anope_dynamic_static_cast<NSSuspendInfo *>(obj); else { - NickAlias *na = NickAlias::Find(snick); + NickServ::Nick *na = NickServ::FindNick(snick); if (!na) return NULL; si = na->nc->Extend<NSSuspendInfo>("NS_SUSPENDED"); @@ -90,7 +90,7 @@ class CommandNSSuspend : public Command } } - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -109,7 +109,7 @@ class CommandNSSuspend : public Command return; } - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; NSSuspendInfo *si = nc->Extend<NSSuspendInfo>("NS_SUSPENDED"); si->what = nc->display; @@ -120,7 +120,7 @@ class CommandNSSuspend : public Command for (unsigned i = 0; i < nc->aliases->size(); ++i) { - NickAlias *na2 = nc->aliases->at(i); + NickServ::Nick *na2 = nc->aliases->at(i); if (na2 && *na2->nc == *na->nc) { @@ -172,7 +172,7 @@ class CommandNSUnSuspend : public Command if (Anope::ReadOnly) source.Reply(READ_ONLY_MODE); - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); @@ -231,7 +231,7 @@ class NSSuspend : public Module { } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { NSSuspendInfo *s = suspend.Get(na->nc); if (s) @@ -248,7 +248,7 @@ class NSSuspend : public Module } } - void OnPreNickExpire(NickAlias *na, bool &expire) override + void OnPreNickExpire(NickServ::Nick *na, bool &expire) override { NSSuspendInfo *s = suspend.Get(na->nc); if (!s) @@ -268,7 +268,7 @@ class NSSuspend : public Module } } - EventReturn OnNickValidate(User *u, NickAlias *na) override + EventReturn OnNickValidate(User *u, NickServ::Nick *na) override { NSSuspendInfo *s = suspend.Get(na->nc); if (!s) diff --git a/modules/commands/ns_update.cpp b/modules/commands/ns_update.cpp index 1fa9c5b36..682c57c6f 100644 --- a/modules/commands/ns_update.cpp +++ b/modules/commands/ns_update.cpp @@ -26,7 +26,7 @@ class CommandNSUpdate : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { User *u = source.GetUser(); - NickAlias *na = NickAlias::Find(u->nick); + NickServ::Nick *na = NickServ::FindNick(u->nick); if (na && na->nc == source.GetAccount()) { diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp index 971b284e5..bf2a1abe8 100644 --- a/modules/commands/os_akill.cpp +++ b/modules/commands/os_akill.cpp @@ -304,7 +304,7 @@ class CommandOSAKill : public Command else { source.Reply(_("Current AKILL list:")); - + std::vector<Anope::string> replies; list.Process(replies); diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp index e81030bc9..e0ed86e8b 100644 --- a/modules/commands/os_config.cpp +++ b/modules/commands/os_config.cpp @@ -53,7 +53,7 @@ class CommandOSConfig : public Command const Anope::string show_blocks[] = { "serverinfo", "networkinfo", "options", "" }; Log(LOG_ADMIN, source, this) << "VIEW"; - + for (unsigned i = 0; !show_blocks[i].empty(); ++i) { Configuration::Block *block = Config->GetBlock(show_blocks[i]); diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp index 29e6638d4..2732f1a3e 100644 --- a/modules/commands/os_defcon.cpp +++ b/modules/commands/os_defcon.cpp @@ -81,19 +81,19 @@ struct DefconConfig { DefConModesOnParams.erase(name); } - + bool GetDefConParam(const Anope::string &name, Anope::string &buf) { std::map<Anope::string, Anope::string>::iterator it = DefConModesOnParams.find(name); - + buf.clear(); - + if (it != DefConModesOnParams.end()) { buf = it->second; return true; } - + return false; } }; @@ -334,7 +334,7 @@ class OSDefcon : public Module if ((cm = ModeManager::FindChannelModeByName("REDIRECT")) && DConfig.DefConModesOn.count(cm->name) && !DConfig.DefConModesOn.count("LIMIT")) { DConfig.DefConModesOn.erase("REDIRECT"); - + Log(this) << "DefConChanModes must lock mode +l as well to lock mode +L"; } } diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index d76ad451f..0f47eb3e8 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -423,7 +423,7 @@ class CommandOSDNS : public Command { DNSServer *s = DNSServer::Find(params[1]); const Anope::string &zone = params.size() > 2 ? params[2] : ""; - + if (!s) { source.Reply(_("Server %s does not exist."), params[1].c_str()); @@ -485,7 +485,7 @@ class CommandOSDNS : public Command void AddIP(CommandSource &source, const std::vector<Anope::string> ¶ms) { DNSServer *s = DNSServer::Find(params[1]); - + if (!s) { source.Reply(_("Server %s does not exist."), params[1].c_str()); @@ -520,11 +520,11 @@ class CommandOSDNS : public Command dnsmanager->Notify(*it); } } - + void DelIP(CommandSource &source, const std::vector<Anope::string> ¶ms) { DNSServer *s = DNSServer::Find(params[1]); - + if (!s) { source.Reply(_("Server %s does not exist."), params[1].c_str()); @@ -563,7 +563,7 @@ class CommandOSDNS : public Command void OnSet(CommandSource &source, const std::vector<Anope::string> ¶ms) { DNSServer *s = DNSServer::Find(params[1]); - + if (!s) { source.Reply(_("Server %s does not exist."), params[1].c_str()); @@ -596,7 +596,7 @@ class CommandOSDNS : public Command void OnPool(CommandSource &source, const std::vector<Anope::string> ¶ms) { DNSServer *s = DNSServer::Find(params[1]); - + if (!s) { source.Reply(_("Server %s does not exist."), params[1].c_str()); @@ -631,7 +631,7 @@ class CommandOSDNS : public Command void OnDepool(CommandSource &source, const std::vector<Anope::string> ¶ms) { DNSServer *s = DNSServer::Find(params[1]); - + if (!s) { source.Reply(_("Server %s does not exist."), params[1].c_str()); diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index 1f54f804f..212beb1ed 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -214,7 +214,7 @@ class CommandOSForbid : public Command expiryt += Anope::CurTime; } - NickAlias *target = NickAlias::Find(entry); + NickServ::Nick *target = NickServ::FindNick(entry); if (target != NULL && Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && target->nc->IsServicesOper()) { source.Reply(ACCESS_DENIED); @@ -254,9 +254,9 @@ class CommandOSForbid : public Command for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) this->OnUserNickChange(it->second); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end;) + for (auto it = NickServ::service->GetNickList().begin(); it != NickServ::service->GetNickList().end();) { - NickAlias *na = it->second; + NickServ::Nick *na = it->second; ++it; d = this->fs->FindForbid(na->nick, FT_NICK); @@ -312,9 +312,9 @@ class CommandOSForbid : public Command } } - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(); it != RegisteredChannelList->end();) + for (auto it = ChanServ::service->GetChannels().begin(); it != ChanServ::service->GetChannels().end();) { - ChannelInfo *ci = it->second; + ChanServ::Channel *ci = it->second; ++it; d = this->fs->FindForbid(ci->name, FT_CHAN); diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index fa6537a21..728fe1c1c 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -38,7 +38,7 @@ Serializable* IgnoreDataImpl::Unserialize(Serializable *obj, Serialize::Data &da { if (!ignore_service) return NULL; - + IgnoreDataImpl *ign; if (obj) ign = anope_dynamic_static_cast<IgnoreDataImpl *>(obj); @@ -94,7 +94,7 @@ class OSIgnoreService : public IgnoreService { User *u = User::Find(mask, true); std::vector<IgnoreData *>::iterator ign = this->ignores->begin(), ign_end = this->ignores->end(); - + if (u) { for (; ign != ign_end; ++ign) @@ -163,7 +163,7 @@ class CommandOSIgnore : public Command User *u = User::Find(mask, true); if (u) return "*!*@" + u->host; - + size_t host = mask.find('@'); /* Determine whether we get a nick or a mask. */ if (host != Anope::string::npos) diff --git a/modules/commands/os_info.cpp b/modules/commands/os_info.cpp index 53b5fecd6..03e98377e 100644 --- a/modules/commands/os_info.cpp +++ b/modules/commands/os_info.cpp @@ -20,7 +20,7 @@ struct OperInfo : Serializable OperInfo() : Serializable("OperInfo"), created(0) { } OperInfo(const Anope::string &t, const Anope::string &i, const Anope::string &a, time_t c) : Serializable("OperInfo"), target(t), info(i), adder(a), created(c) { } - + ~OperInfo(); void Serialize(Serialize::Data &data) const override @@ -46,10 +46,10 @@ struct OperInfos : Serialize::Checker<std::vector<OperInfo *> > static Extensible *Find(const Anope::string &target) { - NickAlias *na = NickAlias::Find(target); + NickServ::Nick *na = NickServ::FindNick(target); if (na) return na->nc; - return ChannelInfo::Find(target); + return ChanServ::Find(target); } }; @@ -76,7 +76,7 @@ Serializable *OperInfo::Unserialize(Serializable *obj, Serialize::Data &data) Extensible *e = OperInfos::Find(starget); if (!e) return NULL; - + OperInfos *oi = e->Require<OperInfos>("operinfo"); OperInfo *o; if (obj) @@ -113,7 +113,7 @@ class CommandOSInfo : public Command Extensible *e; if (IRCD->IsChannelValid(target)) { - ChannelInfo *ci = ChannelInfo::Find(target); + ChanServ::Channel *ci = ChanServ::Find(target); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, target.c_str()); @@ -124,7 +124,7 @@ class CommandOSInfo : public Command } else { - NickAlias *na = NickAlias::Find(target); + NickServ::Nick *na = NickServ::FindNick(target); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, target.c_str()); @@ -284,12 +284,12 @@ class OSInfo : public Module } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { OnInfo(source, na->nc, info); } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_hidden) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) override { OnInfo(source, ci, info); } diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp index cba659957..5650feaa2 100644 --- a/modules/commands/os_logsearch.cpp +++ b/modules/commands/os_logsearch.cpp @@ -18,7 +18,7 @@ class CommandOSLogSearch : public Command char timestamp[32]; tm *tm = localtime(&t); - + strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm); return Anope::LogDir + "/" + file + "." + timestamp; diff --git a/modules/commands/os_mode.cpp b/modules/commands/os_mode.cpp index 7358e4c78..4d94759df 100644 --- a/modules/commands/os_mode.cpp +++ b/modules/commands/os_mode.cpp @@ -152,7 +152,7 @@ class CommandOSUMode : public Command u2->SetModes(source.service, "%s", modes.c_str()); source.Reply(_("Changed usermodes of \002%s\002 to %s."), u2->nick.c_str(), modes.c_str()); - u2->SendMessage(source.service, _("\002%s\002 changed your usermodes to %s."), source.GetNick().c_str(), modes.c_str()); + u2->SendMessage(*source.service, _("\002%s\002 changed your usermodes to %s."), source.GetNick().c_str(), modes.c_str()); Log(LOG_ADMIN, source, this) << modes << " on " << target; } diff --git a/modules/commands/os_module.cpp b/modules/commands/os_module.cpp index c4f814ee3..826fcabbb 100644 --- a/modules/commands/os_module.cpp +++ b/modules/commands/os_module.cpp @@ -139,7 +139,7 @@ class CommandOSModUnLoad : public Command source.Reply(_("Module \002%s\002 isn't loaded."), mname.c_str()); return; } - + if (!m->handle || m->GetPermanent() || m->type == PROTOCOL) { source.Reply(_("Unable to remove module \002%s\002."), m->name.c_str()); diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp index 62379e30a..0550146f3 100644 --- a/modules/commands/os_news.cpp +++ b/modules/commands/os_news.cpp @@ -115,7 +115,7 @@ class MyNewsService : public NewsService { this->newsItems[n->type].push_back(n); } - + void DelNewsItem(NewsItem *n) { std::vector<NewsItem *> &list = this->GetNewsList(n->type); diff --git a/modules/commands/os_oline.cpp b/modules/commands/os_oline.cpp index 6d1d5d443..3cb521063 100644 --- a/modules/commands/os_oline.cpp +++ b/modules/commands/os_oline.cpp @@ -33,7 +33,7 @@ class CommandOSOLine : public Command { IRCD->SendSVSO(source.service, nick, flag); u2->SetMode(source.service, "OPER"); - u2->SendMessage(source.service, _("You are now an IRC Operator.")); + u2->SendMessage(*source.service, _("You are now an IRC Operator.")); source.Reply(_("Operflags \002%s\002 have been added for \002%s\002."), flag.c_str(), nick.c_str()); Log(LOG_ADMIN, source, this) << "for " << nick; } diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp index a18b022ab..59619cb48 100644 --- a/modules/commands/os_oper.cpp +++ b/modules/commands/os_oper.cpp @@ -31,7 +31,7 @@ struct MyOper : Oper, Serializable OperType *ot = OperType::Find(stype); if (ot == NULL) return NULL; - NickCore *nc = NickCore::Find(sname); + NickServ::Account *nc = NickServ::FindAccount(sname); if (nc == NULL) return NULL; @@ -82,7 +82,7 @@ class CommandOSOper : public Command const Anope::string &oper = params[1]; const Anope::string &otype = params[2]; - const NickAlias *na = NickAlias::Find(oper); + const NickServ::Nick *na = NickServ::FindNick(oper); if (na == NULL) source.Reply(NICK_X_NOT_REGISTERED, oper.c_str()); else if (na->nc->o) @@ -115,7 +115,7 @@ class CommandOSOper : public Command { const Anope::string &oper = params[1]; - const NickAlias *na = NickAlias::Find(oper); + const NickServ::Nick *na = NickServ::FindNick(oper); if (na == NULL) source.Reply(NICK_X_NOT_REGISTERED, oper.c_str()); else if (!na->nc || !na->nc->o) @@ -137,9 +137,9 @@ class CommandOSOper : public Command else if (subcommand.equals_ci("LIST")) { source.Reply(_("Name Type")); - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetAccountList()) { - const NickCore *nc = it->second; + const NickServ::Account *nc = it.second; if (!nc->o) continue; @@ -160,7 +160,7 @@ class CommandOSOper : public Command if (params.size() > 2) fulltype += " " + params[2]; OperType *ot = OperType::Find(fulltype); - if (ot == NULL) + if (ot == NULL) source.Reply(_("Oper type \002%s\002 has not been configured."), fulltype.c_str()); else { @@ -243,9 +243,9 @@ class OSOper : public Module ~OSOper() { - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetAccountList()) { - NickCore *nc = it->second; + NickServ::Account *nc = it.second; if (nc->o && dynamic_cast<MyOper *>(nc->o)) { diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp index 9cb525b4d..03c807efb 100644 --- a/modules/commands/os_session.cpp +++ b/modules/commands/os_session.cpp @@ -68,7 +68,7 @@ class MySessionService : public SessionService Exception *e = *it; if (Anope::Match(u->host, e->mask) || Anope::Match(u->ip, e->mask)) return e; - + if (cidr(e->mask).match(sockaddrs(u->ip))) return e; } @@ -211,7 +211,7 @@ class CommandOSSession : public Command std::vector<Anope::string> replies; list.Process(replies); - + for (unsigned i = 0; i < replies.size(); ++i) source.Reply(replies[i]); } @@ -531,7 +531,7 @@ class CommandOSException : public Command else { source.Reply(_("Current Session Limit Exception list:")); - + std::vector<Anope::string> replies; list.Process(replies); diff --git a/modules/commands/os_set.cpp b/modules/commands/os_set.cpp index bc58b7dc1..be5e980b1 100644 --- a/modules/commands/os_set.cpp +++ b/modules/commands/os_set.cpp @@ -129,7 +129,7 @@ class CommandOSSet : public Command return; } catch (const ConvertException &) { } - + source.Reply(_("Setting for DEBUG must be \002ON\002, \002OFF\002, or a positive number.")); } diff --git a/modules/commands/os_stats.cpp b/modules/commands/os_stats.cpp index d55bdb1dc..f325b3ab9 100644 --- a/modules/commands/os_stats.cpp +++ b/modules/commands/os_stats.cpp @@ -173,13 +173,13 @@ class CommandOSStats : public Command GetHashStats(ChannelList, entries, buckets, max_chain); source.Reply(_("Channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); - GetHashStats(*RegisteredChannelList, entries, buckets, max_chain); + GetHashStats(ChanServ::service->GetChannels(), entries, buckets, max_chain); source.Reply(_("Registered channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); - GetHashStats(*NickAliasList, entries, buckets, max_chain); + GetHashStats(NickServ::service->GetNickList(), entries, buckets, max_chain); source.Reply(_("Registered nicknames: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); - GetHashStats(*NickCoreList, entries, buckets, max_chain); + GetHashStats(NickServ::service->GetAccountList(), entries, buckets, max_chain); source.Reply(_("Registered nick groups: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); if (session_service) diff --git a/modules/cs_statusupdate.cpp b/modules/cs_statusupdate.cpp index 58498ff40..b65f8a6e5 100644 --- a/modules/cs_statusupdate.cpp +++ b/modules/cs_statusupdate.cpp @@ -19,17 +19,17 @@ class StatusUpdate : public Module } - void OnAccessAdd(ChannelInfo *ci, CommandSource &, ChanAccess *access) override + void OnAccessAdd(ChanServ::Channel *ci, CommandSource &, ChanServ::ChanAccess *access) override { if (ci->c) for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { User *user = it->second->user; - ChanAccess::Path p; + ChanServ::ChanAccess::Path p; if (user->server != Me && access->Matches(user, user->Account(), p)) { - AccessGroup ag = ci->AccessFor(user); + ChanServ::AccessGroup ag = ci->AccessFor(user); for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) { @@ -42,17 +42,17 @@ class StatusUpdate : public Module } } - void OnAccessDel(ChannelInfo *ci, CommandSource &, ChanAccess *access) override + void OnAccessDel(ChanServ::Channel *ci, CommandSource &, ChanServ::ChanAccess *access) override { if (ci->c) for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { User *user = it->second->user; - ChanAccess::Path p; + ChanServ::ChanAccess::Path p; if (user->server != Me && access->Matches(user, user->Account(), p)) { - AccessGroup ag = ci->AccessFor(user); + ChanServ::AccessGroup ag = ci->AccessFor(user); for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) { diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index 50f1412b1..266b79379 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -93,7 +93,7 @@ class LoadData : public Serialize::Data hash ^= Anope::hash_cs()(it->second); return hash; } - + void Reset() { id = 0; @@ -255,7 +255,7 @@ class DBFlatFile : public Module, public Pipe Serialize::Type *stype = Serialize::Type::Find(type_order[i]); if (!stype || stype->GetOwner()) continue; - + std::vector<std::streampos> &pos = positions[stype->GetName()]; for (unsigned j = 0; j < pos.size(); ++j) diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp index f80d55d5a..c541104d9 100644 --- a/modules/database/db_old.cpp +++ b/modules/database/db_old.cpp @@ -142,7 +142,7 @@ enum LANG_PL /* Polish */ }; -static void process_mlock(ChannelInfo *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key) +static void process_mlock(ChanServ::Channel *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key) { ModeLocks *ml = ci->Require<ModeLocks>("modelocks"); for (unsigned i = 0; i < (sizeof(mlock_infos) / sizeof(mlock_info)); ++i) @@ -434,6 +434,8 @@ int read_int32(int32_t *ret, dbFILE *f) static void LoadNicks() { + if (!NickServ::service) + return; ServiceReference<ForbidService> forbid("ForbidService", "forbid"); dbFILE *f = open_db_read("NickServ", "nick.db", 14); if (f == NULL) @@ -444,7 +446,7 @@ static void LoadNicks() Anope::string buffer; READ(read_string(buffer, f)); - NickCore *nc = new NickCore(buffer); + NickServ::Account *nc = NickServ::service->CreateAccount(buffer); const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email", "hide_mask", "hide_quit", "memo_signon", "memo_receive", "autoop", "msg", "ns_keepmodes" }; @@ -573,27 +575,38 @@ static void LoadNicks() int16_t i16; READ(read_int16(&i16, f)); - READ(read_int16(&nc->memos.memomax, f)); + READ(read_int16(&i16, f)); + if (nc->memos) + nc->memos->memomax = i16; for (int16_t j = 0; j < i16; ++j) { - Memo *m = new Memo; + MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; READ(read_uint32(&u32, f)); uint16_t flags; READ(read_uint16(&flags, f)); int32_t tmp32; READ(read_int32(&tmp32, f)); - m->time = tmp32; + if (m) + m->time = tmp32; char sbuf[32]; READ(read_buffer(sbuf, f)); - m->sender = sbuf; - READ(read_string(m->text, f)); - m->owner = nc->display; - nc->memos.memos->push_back(m); + if (m) + m->sender = sbuf; + Anope::string text; + READ(read_string(text, f)); + if (m) + m->text = text; + if (m) + m->owner = nc->display; + if (nc->memos && m) + nc->memos->memos->push_back(m); + else + delete m; } READ(read_uint16(&u16, f)); READ(read_int16(&i16, f)); - Log(LOG_DEBUG) << "Loaded NickCore " << nc->display; + Log(LOG_DEBUG) << "Loaded NickServ::Account " << nc->display; } for (int i = 0; i < 1024; ++i) @@ -618,7 +631,7 @@ static void LoadNicks() Anope::string core; READ(read_string(core, f)); - NickCore *nc = NickCore::Find(core); + NickServ::Account *nc = NickServ::FindAccount(core); if (nc == NULL) { Log() << "Skipping coreless nick " << nick << " with core " << core; @@ -651,7 +664,7 @@ static void LoadNicks() continue; } - NickAlias *na = new NickAlias(nick, nc); + NickServ::Nick *na = NickServ::service->CreateNick(nick, nc); na->last_usermask = last_usermask; na->last_realname = last_realname; na->last_quit = last_quit; @@ -661,7 +674,7 @@ static void LoadNicks() if (tmpu16 & OLD_NS_NO_EXPIRE) na->Extend<bool>("NS_NO_EXPIRE"); - Log(LOG_DEBUG) << "Loaded NickAlias " << na->nick; + Log(LOG_DEBUG) << "Loaded NickServ::Nick " << na->nick; } close_db(f); /* End of section Ia */ @@ -684,7 +697,7 @@ static void LoadVHosts() READ(read_string(creator, f)); READ(read_int32(&vtime, f)); - NickAlias *na = NickAlias::Find(nick); + NickServ::Nick *na = NickServ::FindNick(nick); if (na == NULL) { Log() << "Removing vhost for nonexistant nick " << nick; @@ -735,6 +748,9 @@ static void LoadBots() static void LoadChannels() { + if (!ChanServ::service) + return; + ServiceReference<ForbidService> forbid("ForbidService", "forbid"); dbFILE *f = open_db_read("ChanServ", "chan.db", 16); if (f == NULL) @@ -746,7 +762,7 @@ static void LoadChannels() Anope::string buffer; char namebuf[64]; READ(read_buffer(namebuf, f)); - ChannelInfo *ci = new ChannelInfo(namebuf); + ChanServ::Channel *ci = ChanServ::service->Create(namebuf); const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder", "signkick", "signkick_level", "topiclock", "persist", "noautoop", "cs_keepmodes" }; @@ -754,10 +770,10 @@ static void LoadChannels() ci->Shrink<bool>(settings[j].upper()); READ(read_string(buffer, f)); - ci->SetFounder(NickCore::Find(buffer)); + ci->SetFounder(NickServ::FindAccount(buffer)); READ(read_string(buffer, f)); - ci->SetSuccessor(NickCore::Find(buffer)); + ci->SetSuccessor(NickServ::FindAccount(buffer)); char pwbuf[32]; READ(read_buffer(pwbuf, f)); @@ -836,8 +852,8 @@ static void LoadChannels() int16_t level; READ(read_int16(&level, f)); - if (level == ACCESS_INVALID) - level = ACCESS_FOUNDER; + if (level == ChanServ::ACCESS_INVALID) + level = ChanServ::ACCESS_FOUNDER; if (j == 10 && level < 0) // NOJOIN ci->Shrink<bool>("RESTRICTED"); // If CSDefRestricted was enabled this can happen @@ -846,7 +862,7 @@ static void LoadChannels() } bool xop = tmpu32 & OLD_CI_XOP; - ServiceReference<AccessProvider> provider_access("AccessProvider", "access/access"), provider_xop("AccessProvider", "access/xop"); + ServiceReference<ChanServ::AccessProvider> provider_access("AccessProvider", "access/access"), provider_xop("AccessProvider", "access/xop"); uint16_t tmpu16; READ(read_uint16(&tmpu16, f)); for (uint16_t j = 0; j < tmpu16; ++j) @@ -855,8 +871,8 @@ static void LoadChannels() READ(read_uint16(&in_use, f)); if (in_use) { - ChanAccess *access = NULL; - + ChanServ::ChanAccess *access = NULL; + if (xop) { if (provider_xop) @@ -941,20 +957,31 @@ static void LoadChannels() READ(read_string(buffer, f)); // +L READ(read_int16(&tmp16, f)); - READ(read_int16(&ci->memos.memomax, f)); + READ(read_int16(&tmp16, f)); + if (ci->memos) + ci->memos->memomax = tmp16; for (int16_t j = 0; j < tmp16; ++j) { READ(read_uint32(&tmpu32, f)); READ(read_uint16(&tmpu16, f)); - Memo *m = new Memo; + MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; READ(read_int32(&tmp32, f)); - m->time = tmp32; + if (m) + m->time = tmp32; char sbuf[32]; READ(read_buffer(sbuf, f)); - m->sender = sbuf; - READ(read_string(m->text, f)); - m->owner = ci->name; - ci->memos.memos->push_back(m); + if (m) + m->sender = sbuf; + Anope::string text; + READ(read_string(text, f)); + if (m) + m->text = text; + if (m) + m->owner = ci->name; + if (ci->memos && m) + ci->memos->memos->push_back(m); + else + delete m; } READ(read_string(buffer, f)); @@ -1211,7 +1238,7 @@ static void LoadExceptions() dbFILE *f = open_db_read("OperServ", "exception.db", 9); if (f == NULL) return; - + int16_t num; READ(read_int16(&num, f)); for (int i = 0; i < num; ++i) @@ -1330,9 +1357,11 @@ class DBOld : public Module void OnUplinkSync(Server *s) override { - for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + if (!ChanServ::service) + return; + for (auto& it : ChanServ::service->GetChannels()) { - ChannelInfo *ci = it->second; + ChanServ::Channel *ci = it.second; uint32_t *limit = mlock_limit.Get(ci); Anope::string *key = mlock_key.Get(ci); diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp index 81b1f083f..dd5ff0301 100644 --- a/modules/database/db_redis.cpp +++ b/modules/database/db_redis.cpp @@ -214,7 +214,7 @@ class DatabaseRedis : public Module, public Pipe std::vector<Anope::string> args; args.push_back("SMEMBERS"); args.push_back("ids:" + sb->GetName()); - + redis->SendCommand(new TypeLoader(this, sb->GetName()), args); } @@ -469,14 +469,14 @@ void SubscriptionListener::OnResult(const Reply &r) */ if (r.multi_bulk.size() != 4) return; - + size_t sz = r.multi_bulk[2]->bulk.find(':'); if (sz == Anope::string::npos) return; - + const Anope::string &key = r.multi_bulk[2]->bulk.substr(sz + 1), &op = r.multi_bulk[3]->bulk; - + sz = key.rfind(':'); if (sz == Anope::string::npos) return; @@ -492,7 +492,7 @@ void SubscriptionListener::OnResult(const Reply &r) if (s_type == NULL) return; - + uint64_t obj_id; try { diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index ad10f0a7d..0377bcdd1 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -163,7 +163,7 @@ class DBMySQL : public Module, public Pipe void OnSerializableDestruct(Serializable *obj) override { - if (!this->CheckInit()) + if (!this->CheckInit()) return; Serialize::Type *s_type = obj->GetSerializableType(); if (s_type) diff --git a/modules/encryption/enc_bcrypt.cpp b/modules/encryption/enc_bcrypt.cpp index 020bafe6e..296d81b53 100644 --- a/modules/encryption/enc_bcrypt.cpp +++ b/modules/encryption/enc_bcrypt.cpp @@ -839,6 +839,7 @@ char *_crypt_gensalt_blowfish_rn(const char *prefix, unsigned long count, #include "module.h" #include "modules/encryption.h" +#include "modules/nickserv.h" class EBCRYPT : public Module , public EventHook<Event::Encrypt> @@ -897,12 +898,12 @@ class EBCRYPT : public Module return EVENT_ALLOW; } - void OnCheckAuthentication(User *, IdentifyRequest *req) override + void OnCheckAuthentication(User *, NickServ::IdentifyRequest *req) override { - const NickAlias *na = NickAlias::Find(req->GetAccount()); + const NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (na == NULL) return; - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; size_t pos = nc->pass.find(':'); if (pos == Anope::string::npos) diff --git a/modules/encryption/enc_md5.cpp b/modules/encryption/enc_md5.cpp index 108fb2504..442918aa6 100644 --- a/modules/encryption/enc_md5.cpp +++ b/modules/encryption/enc_md5.cpp @@ -284,7 +284,7 @@ class MD5Context : public Encryption::Context /* MD5 finalization. Ends an MD5 message-digest opera * the message digest and zeroizing the context. - */ + */ void Finalize() override { unsigned char bits[8]; @@ -369,12 +369,12 @@ class EMD5 : public Module return EVENT_ALLOW; } - void OnCheckAuthentication(User *, IdentifyRequest *req) override + void OnCheckAuthentication(User *, NickServ::IdentifyRequest *req) override { - const NickAlias *na = NickAlias::Find(req->GetAccount()); + const NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (na == NULL) return; - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; size_t pos = nc->pass.find(':'); if (pos == Anope::string::npos) diff --git a/modules/encryption/enc_none.cpp b/modules/encryption/enc_none.cpp index 1346177f7..8781be910 100644 --- a/modules/encryption/enc_none.cpp +++ b/modules/encryption/enc_none.cpp @@ -44,12 +44,12 @@ class ENone : public Module return EVENT_ALLOW; } - void OnCheckAuthentication(User *, IdentifyRequest *req) override + void OnCheckAuthentication(User *, NickServ::IdentifyRequest *req) override { - const NickAlias *na = NickAlias::Find(req->GetAccount()); + const NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (na == NULL) return; - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; size_t pos = nc->pass.find(':'); if (pos == Anope::string::npos) diff --git a/modules/encryption/enc_old.cpp b/modules/encryption/enc_old.cpp index 671921c72..f36b2236b 100644 --- a/modules/encryption/enc_old.cpp +++ b/modules/encryption/enc_old.cpp @@ -85,12 +85,12 @@ class EOld : public Module return EVENT_ALLOW; } - void OnCheckAuthentication(User *, IdentifyRequest *req) override + void OnCheckAuthentication(User *, NickServ::IdentifyRequest *req) override { - const NickAlias *na = NickAlias::Find(req->GetAccount()); + const NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (na == NULL) return; - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; size_t pos = nc->pass.find(':'); if (pos == Anope::string::npos) diff --git a/modules/encryption/enc_sha1.cpp b/modules/encryption/enc_sha1.cpp index df7de4f72..d2189a941 100644 --- a/modules/encryption/enc_sha1.cpp +++ b/modules/encryption/enc_sha1.cpp @@ -224,12 +224,12 @@ class ESHA1 : public Module return EVENT_ALLOW; } - void OnCheckAuthentication(User *, IdentifyRequest *req) override + void OnCheckAuthentication(User *, NickServ::IdentifyRequest *req) override { - const NickAlias *na = NickAlias::Find(req->GetAccount()); + const NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (na == NULL) return; - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; size_t pos = nc->pass.find(':'); if (pos == Anope::string::npos) diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp index 9cd682c57..b8c5c8e76 100644 --- a/modules/encryption/enc_sha256.cpp +++ b/modules/encryption/enc_sha256.cpp @@ -306,12 +306,12 @@ class ESHA256 : public Module return EVENT_ALLOW; } - void OnCheckAuthentication(User *, IdentifyRequest *req) override + void OnCheckAuthentication(User *, NickServ::IdentifyRequest *req) override { - const NickAlias *na = NickAlias::Find(req->GetAccount()); + const NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (na == NULL) return; - NickCore *nc = na->nc; + NickServ::Account *nc = na->nc; size_t pos = nc->pass.find(':'); if (pos == Anope::string::npos) diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp index 1615d855c..efbef59f8 100644 --- a/modules/extra/m_ldap.cpp +++ b/modules/extra/m_ldap.cpp @@ -125,7 +125,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition ldap_unbind_ext(this->con, NULL, NULL); } - + LDAPQuery BindAsAdmin(LDAPInterface *i) { return this->Bind(i, this->admin_binddn, this->admin_pass); @@ -554,7 +554,7 @@ class ModuleLDAP : public Module, public Pipe } } s->Unlock(); - } + } } void OnNotify() override @@ -586,7 +586,7 @@ class ModuleLDAP : public Module, public Pipe delete r; } - } + } } }; diff --git a/modules/extra/m_ldap_authentication.cpp b/modules/extra/m_ldap_authentication.cpp index abd5cc33c..9f2550e69 100644 --- a/modules/extra/m_ldap_authentication.cpp +++ b/modules/extra/m_ldap_authentication.cpp @@ -22,7 +22,7 @@ struct IdentifyInfo { req->Hold(me); } - + ~IdentifyInfo() { req->Release(me); @@ -100,10 +100,10 @@ class IdentifyInterface : public LDAPInterface } else { - NickAlias *na = NickAlias::Find(ii->req->GetAccount()); + NickServ::Nick *na = NickServ::FindNick(ii->req->GetAccount()); if (na == NULL) { - na = new NickAlias(ii->req->GetAccount(), new NickCore(ii->req->GetAccount())); + na = new NickServ::Nick(ii->req->GetAccount(), new NickServ::Account(ii->req->GetAccount())); na->last_realname = ii->user ? ii->user->realname : ii->req->GetAccount(); NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na); BotInfo *NickServ = Config->GetClient("NickServ"); @@ -311,7 +311,7 @@ class NSIdentifyLDAP : public Module } } - void OnNickRegister(User *, NickAlias *na) override + void OnNickRegister(User *, NickServ::Nick *na) override { if (!this->disable_register_reason.empty() || !this->ldap) return; diff --git a/modules/extra/m_ldap_oper.cpp b/modules/extra/m_ldap_oper.cpp index 7c6db48f5..ca6020c6a 100644 --- a/modules/extra/m_ldap_oper.cpp +++ b/modules/extra/m_ldap_oper.cpp @@ -30,7 +30,7 @@ class IdentifyInterface : public LDAPInterface if (!u || !u->Account()) return; - NickCore *nc = u->Account(); + NickServ::Account *nc = u->Account(); try { @@ -131,7 +131,7 @@ class LDAPOper : public Module } } - void OnDelCore(NickCore *nc) override + void OnDelCore(NickServ::Account *nc) override { if (nc->o != NULL && my_opers.count(nc->o) > 0) { diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp index d0db90195..02d015ed8 100644 --- a/modules/extra/m_mysql.cpp +++ b/modules/extra/m_mysql.cpp @@ -438,7 +438,7 @@ Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Dat *it->second >> buf; query.SetValue(it->first, buf); } - + return query; } @@ -458,7 +458,7 @@ void MySQLService::Connect() if (!connect) throw SQL::Exception("Unable to connect to MySQL service " + this->name + ": " + mysql_error(this->sql)); - + Log(LOG_DEBUG) << "Successfully connected to MySQL service " << this->name << " at " << this->server << ":" << this->port; } diff --git a/modules/extra/m_sql_authentication.cpp b/modules/extra/m_sql_authentication.cpp index 65f0f2800..74e2554fa 100644 --- a/modules/extra/m_sql_authentication.cpp +++ b/modules/extra/m_sql_authentication.cpp @@ -38,11 +38,11 @@ class SQLAuthenticationResult : public SQL::Interface } catch (const SQL::Exception &) { } - NickAlias *na = NickAlias::Find(req->GetAccount()); + NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); BotInfo *NickServ = Config->GetClient("NickServ"); if (na == NULL) { - na = new NickAlias(req->GetAccount(), new NickCore(req->GetAccount())); + na = new NickServ::Nick(req->GetAccount(), new NickServ::Account(req->GetAccount())); NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, user, na); if (user && NickServ) user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->nick.c_str()); diff --git a/modules/extra/m_sql_oper.cpp b/modules/extra/m_sql_oper.cpp index 90fab856a..8337252ba 100644 --- a/modules/extra/m_sql_oper.cpp +++ b/modules/extra/m_sql_oper.cpp @@ -105,9 +105,9 @@ class ModuleSQLOper : public Module ~ModuleSQLOper() { - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (nickcore_map::const_iterator it = NickServ::AccountList->begin(), it_end = NickServ::AccountList->end(); it != it_end; ++it) { - NickCore *nc = it->second; + NickServ::Account *nc = it->second; if (nc->o && dynamic_cast<SQLOper *>(nc->o)) { diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp index c0f503141..32d335b1b 100644 --- a/modules/extra/m_sqlite.cpp +++ b/modules/extra/m_sqlite.cpp @@ -282,7 +282,7 @@ Query SQLiteService::BuildInsert(const Anope::string &table, unsigned int id, Da *it->second >> buf; query.SetValue(it->first, buf); } - + return query; } diff --git a/modules/extra/m_ssl_openssl.cpp b/modules/extra/m_ssl_openssl.cpp index 3344f1d28..7687b599e 100644 --- a/modules/extra/m_ssl_openssl.cpp +++ b/modules/extra/m_ssl_openssl.cpp @@ -181,7 +181,7 @@ void MySSLService::Init(Socket *s) { if (s->io != &NormalSocketIO) throw CoreException("Socket initializing SSL twice"); - + s->io = new SSLSocketIO(); } @@ -259,7 +259,7 @@ ClientSocket *SSLSocketIO::Accept(ListenSocket *s) newsocket->flags[SF_ACCEPTING] = true; this->FinishAccept(newsocket); - + return newsocket; } @@ -273,7 +273,7 @@ SocketFlag SSLSocketIO::FinishAccept(ClientSocket *cs) throw SocketException("SSLSocketIO::FinishAccept called for a socket not accepted nor accepting?"); SSLSocketIO *io = anope_dynamic_static_cast<SSLSocketIO *>(cs->io); - + int ret = SSL_accept(io->sslsock); if (ret <= 0) { @@ -354,7 +354,7 @@ SocketFlag SSLSocketIO::FinishConnect(ConnectionSocket *s) if (!SSL_set_fd(io->sslsock, s->GetFD())) throw SocketException("Unable to set SSL fd"); } - + int ret = SSL_connect(io->sslsock); if (ret <= 0) { diff --git a/modules/extra/stats/cs_fantasy_stats.cpp b/modules/extra/stats/cs_fantasy_stats.cpp index b400e23ed..4674e0892 100644 --- a/modules/extra/stats/cs_fantasy_stats.cpp +++ b/modules/extra/stats/cs_fantasy_stats.cpp @@ -113,7 +113,7 @@ class CSStats : public Module channel = params[0]; else { - if (NickAlias *na = NickAlias::Find(params[0])) + if (NickServ::Nick *na = NickServ::FindNick(params[0])) display = na->nc->display; else { diff --git a/modules/extra/stats/m_chanstats.cpp b/modules/extra/stats/m_chanstats.cpp index 4efb1f430..d472fd55d 100644 --- a/modules/extra/stats/m_chanstats.cpp +++ b/modules/extra/stats/m_chanstats.cpp @@ -12,7 +12,7 @@ class CommandCSSetChanstats : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -65,7 +65,7 @@ class CommandNSSetChanstats : public Command } void Run(CommandSource &source, const Anope::string &user, const Anope::string ¶m, bool saset = false) { - NickAlias *na = NickAlias::Find(user); + NickServ::Nick *na = NickServ::FindNick(user); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); @@ -103,7 +103,7 @@ class CommandNSSetChanstats : public Command { this->Run(source, source.nc->display, params[0]); } - + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); @@ -501,7 +501,7 @@ class MChanstats : public Module Log(this) << "no database connection to " << engine; } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_all) override { if (!show_all) return; @@ -509,7 +509,7 @@ class MChanstats : public Module info.AddOption(_("Chanstats")); } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { if (!show_hidden) return; @@ -610,14 +610,14 @@ class MChanstats : public Module this->RunQuery(query); } - void OnDelCore(NickCore *nc) override + void OnDelCore(NickServ::Account *nc) override { query = "DELETE FROM `" + prefix + "chanstats` WHERE `nick` = @nick@;"; query.SetValue("nick", nc->display); this->RunQuery(query); } - void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) override + void OnChangeCoreDisplay(NickServ::Account *nc, const Anope::string &newdisplay) override { query = "CALL " + prefix + "chanstats_proc_chgdisplay(@old_display@, @new_display@);"; query.SetValue("old_display", nc->display); @@ -625,20 +625,20 @@ class MChanstats : public Module this->RunQuery(query); } - void OnDelChan(ChannelInfo *ci) override + void OnDelChan(ChanServ::Channel *ci) override { query = "DELETE FROM `" + prefix + "chanstats` WHERE `chan` = @channel@;"; query.SetValue("channel", ci->name); this->RunQuery(query); } - void OnChanRegistered(ChannelInfo *ci) + void OnChanRegistered(ChanServ::Channel *ci) { if (CSDefChanstats) ci->Extend<bool>("CS_STATS"); } - void OnNickRegister(User *user, NickAlias *na) + void OnNickRegister(User *user, NickServ::Nick *na) { if (NSDefChanstats) na->nc->Extend<bool>("NS_STATS"); diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp index e89b35365..ef95a83b3 100644 --- a/modules/fantasy.cpp +++ b/modules/fantasy.cpp @@ -23,7 +23,7 @@ class CommandBSSetFantasy : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string &value = params[1]; if (ci == NULL) @@ -47,7 +47,7 @@ class CommandBSSetFantasy : public Command if (value.equals_ci("ON")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable fantasy"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable fantasy"; ci->Extend<bool>("BS_FANTASY"); source.Reply(_("Fantasy mode is now \002on\002 on channel %s."), ci->name.c_str()); @@ -55,7 +55,7 @@ class CommandBSSetFantasy : public Command else if (value.equals_ci("OFF")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable fantasy"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable fantasy"; ci->Shrink<bool>("BS_FANTASY"); source.Reply(_("Fantasy mode is now \002off\002 on channel %s."), ci->name.c_str()); @@ -118,7 +118,7 @@ class Fantasy : public Module params[0].erase(params[0].begin()); else return; - + if (params.empty()) return; @@ -171,7 +171,7 @@ class Fantasy : public Module source.command = it->first; source.permission = info.permission; - AccessGroup ag = c->ci->AccessFor(u); + ChanServ::AccessGroup ag = c->ci->AccessFor(u); bool has_fantasia = ag.HasPriv("FANTASIA") || source.HasPriv("chanserv/administration"); EventReturn MOD_RESULT; @@ -194,14 +194,14 @@ class Fantasy : public Module if (MOD_RESULT == EVENT_STOP) return; - Reference<NickCore> nc_reference(u->Account()); + Reference<NickServ::Account> nc_reference(u->Account()); cmd->Execute(source, params); if (!nc_reference) source.nc = NULL; Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, cmd, params); } - void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) + void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) { if (fantasy.HasExt(ci)) info.AddOption(_("Fantasy")); diff --git a/modules/m_dns.cpp b/modules/m_dns.cpp index dfe44516a..a4c2f21ac 100644 --- a/modules/m_dns.cpp +++ b/modules/m_dns.cpp @@ -106,7 +106,7 @@ class Packet : public Query return name; } - + Question UnpackQuestion(const unsigned char *input, unsigned short input_size, unsigned short &pos) { Question question; @@ -202,7 +202,7 @@ class Packet : public Query unsigned short id; /* Flags on the packet */ unsigned short flags; - + Packet(Manager *m, sockaddrs *a) : manager(m), id(0), flags(0) { if (a) @@ -238,7 +238,7 @@ class Packet : public Query for (unsigned i = 0; i < qdcount; ++i) this->questions.push_back(this->UnpackQuestion(input, len, packet_pos)); - + for (unsigned i = 0; i < ancount; ++i) this->answers.push_back(this->UnpackResourceRecord(input, len, packet_pos)); @@ -253,7 +253,7 @@ class Packet : public Query { if (output_size < HEADER_LENGTH) throw SocketException("Unable to pack packet"); - + unsigned short pos = 0; output[pos++] = this->id >> 8; @@ -416,7 +416,7 @@ class Packet : public Query l = htonl(manager->GetSerial()); memcpy(&output[pos], &l, 4); pos += 4; - + l = htonl(refresh); // Refresh memcpy(&output[pos], &l, 4); pos += 4; @@ -442,7 +442,7 @@ class Packet : public Query break; } } - + return pos; } }; @@ -461,7 +461,7 @@ namespace DNS class TCPSocket : public ListenSocket { Manager *manager; - + public: /* A TCP client */ class Client : public ClientSocket, public Timer, public ReplySocket @@ -470,7 +470,7 @@ class TCPSocket : public ListenSocket Packet *packet; unsigned char packet_buffer[524]; int length; - + public: Client(Manager *m, TCPSocket *l, int fd, const sockaddrs &addr) : Socket(fd, l->IsIPv6()), ClientSocket(l, addr), Timer(5), manager(m), packet(NULL), length(0) @@ -483,7 +483,7 @@ class TCPSocket : public ListenSocket Log(LOG_DEBUG_2) << "Resolver: Exiting client from " << clientaddr.addr(); delete packet; } - + /* Times out after a few seconds */ void Tick(time_t) override { } @@ -543,13 +543,13 @@ class TCPSocket : public ListenSocket }; TCPSocket(Manager *m, const Anope::string &ip, int port) : Socket(-1, ip.find(':') != Anope::string::npos), ListenSocket(ip, port, ip.find(':') != Anope::string::npos), manager(m) { } - + ClientSocket *OnAccept(int fd, const sockaddrs &addr) override { return new Client(this->manager, this, fd, addr); } }; - + /* Listens for UDP requests */ class UDPSocket : public ReplySocket { @@ -564,15 +564,15 @@ class UDPSocket : public ReplySocket for (unsigned i = 0; i < packets.size(); ++i) delete packets[i]; } - + void Reply(Packet *p) override { packets.push_back(p); SocketEngine::Change(this, true, SF_WRITABLE); } - + std::deque<Packet *>& GetPackets() { return packets; } - + bool ProcessRead() override { Log(LOG_DEBUG_2) << "Resolver: Reading from DNS UDP socket"; @@ -583,7 +583,7 @@ class UDPSocket : public ReplySocket int length = recvfrom(this->GetFD(), reinterpret_cast<char *>(&packet_buffer), sizeof(packet_buffer), 0, &from_server.sa, &x); return this->manager->HandlePacket(this, packet_buffer, length, &from_server); } - + bool ProcessWrite() override { Log(LOG_DEBUG_2) << "Resolver: Writing to DNS UDP socket"; @@ -606,7 +606,7 @@ class UDPSocket : public ReplySocket if (packets.empty()) SocketEngine::Change(this, false, SF_WRITABLE); - + return true; } }; @@ -672,7 +672,7 @@ class MyManager : public Manager, public Timer delete tcpsock; for (std::map<unsigned short, Request *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end;) - { + { Request *request = it->second; ++it; @@ -750,7 +750,7 @@ class MyManager : public Manager, public Timer this->requests[req->id] = req; req->SetSecs(timeout); - + Packet *p = new Packet(this, &this->addrs); p->flags = QUERYFLAGS_RD; p->id = req->id; @@ -911,7 +911,7 @@ class MyManager : public Manager, public Timer request->OnLookupComplete(&recv_packet); this->AddCache(recv_packet); } - + delete request; return true; } @@ -972,7 +972,7 @@ class MyManager : public Manager, public Timer this->cache.erase(it); } } - + private: /** Add a record to the dns cache * @param r The record @@ -1000,7 +1000,7 @@ class MyManager : public Manager, public Timer return false; } - + }; class ModuleDNS : public Module diff --git a/modules/m_httpd.cpp b/modules/m_httpd.cpp index 314badc55..2d959ef14 100644 --- a/modules/m_httpd.cpp +++ b/modules/m_httpd.cpp @@ -148,7 +148,7 @@ class MyHTTPClient : public HTTPClient this->Serve(); } - + return true; } diff --git a/modules/m_rewrite.cpp b/modules/m_rewrite.cpp index 940308c12..adf702b9d 100644 --- a/modules/m_rewrite.cpp +++ b/modules/m_rewrite.cpp @@ -19,7 +19,7 @@ struct Rewrite for (unsigned i = 0; i < sm.size(); ++i) if (i >= message.size() || (sm[i] != "$" && !sm[i].equals_ci(message[i]))) return false; - + return true; } @@ -70,7 +70,7 @@ struct Rewrite } static std::vector<Rewrite> rewrites; - + static Rewrite *Find(const Anope::string &client, const Anope::string &cmd) { for (unsigned i = 0; i < rewrites.size(); ++i) diff --git a/modules/m_sasl.cpp b/modules/m_sasl.cpp index e38e865ff..67c1148ee 100644 --- a/modules/m_sasl.cpp +++ b/modules/m_sasl.cpp @@ -40,10 +40,10 @@ class Plain : public Mechanism Anope::string acc = decoded.substr(0, p), pass = decoded.substr(p + 1); - if (acc.empty() || pass.empty()) + if (acc.empty() || pass.empty() || !NickServ::service) return; - SASL::IdentifyRequest *req = new SASL::IdentifyRequest(this->owner, m.source, acc, pass); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new IdentifyRequestListener(m.source), this->owner, acc, pass); Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); } @@ -92,7 +92,7 @@ class External : public Mechanism return; } - NickCore *nc = certs->FindAccountFromCert(mysess->cert); + NickServ::Account *nc = certs->FindAccountFromCert(mysess->cert); if (!nc || nc->HasExt("NS_SUSPENDED")) { sasl->Fail(sess); @@ -208,7 +208,7 @@ class SASLService : public SASL::Service, public Timer IRCD->SendSASLMessage(msg); } - void Succeed(Session *session, NickCore *nc) override + void Succeed(Session *session, NickServ::Account *nc) override { IRCD->SendSVSLogin(session->uid, nc->display); this->SendMessage(session, "D", "S"); diff --git a/modules/m_xmlrpc_main.cpp b/modules/m_xmlrpc_main.cpp index 011b2d250..224b25a60 100644 --- a/modules/m_xmlrpc_main.cpp +++ b/modules/m_xmlrpc_main.cpp @@ -3,7 +3,7 @@ static Module *me; -class XMLRPCIdentifyRequest : public IdentifyRequest +class XMLRPCIdentifyRequest : public NickServ::IdentifyRequestListener { XMLRPCRequest request; HTTPReply repl; /* Request holds a reference to the HTTPReply, because we might exist long enough to invalidate it @@ -12,9 +12,9 @@ class XMLRPCIdentifyRequest : public IdentifyRequest Reference<XMLRPCServiceInterface> xinterface; public: - XMLRPCIdentifyRequest(Module *m, XMLRPCRequest& req, HTTPClient *c, XMLRPCServiceInterface* iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { } + XMLRPCIdentifyRequest(XMLRPCRequest& req, HTTPClient *c, XMLRPCServiceInterface* iface) : request(req), repl(request.r), client(c), xinterface(iface) { } - void OnSuccess() override + void OnSuccess(NickServ::IdentifyRequest *req) override { if (!xinterface || !client) return; @@ -22,13 +22,13 @@ class XMLRPCIdentifyRequest : public IdentifyRequest request.r = this->repl; request.reply("result", "Success"); - request.reply("account", GetAccount()); + request.reply("account", req->GetAccount()); xinterface->Reply(request); client->SendReply(&request.r); } - void OnFail() override + void OnFail(NickServ::IdentifyRequest *req) override { if (!xinterface || !client) return; @@ -81,7 +81,7 @@ class MyXMLRPCEvent : public XMLRPCEvent { request.reply("result", "Success"); - NickAlias *na = NickAlias::Find(user); + NickServ::Nick *na = NickServ::FindNick(user); Anope::string out; @@ -91,7 +91,7 @@ class MyXMLRPCEvent : public XMLRPCEvent XMLRPCommandReply(Anope::string &s) : str(s) { } - void SendMessage(BotInfo *, const Anope::string &msg) override + void SendMessage(const MessageSource &, const Anope::string &msg) override { str += msg + "\n"; }; @@ -112,16 +112,16 @@ class MyXMLRPCEvent : public XMLRPCEvent Anope::string username = request.data.size() > 0 ? request.data[0] : ""; Anope::string password = request.data.size() > 1 ? request.data[1] : ""; - if (username.empty() || password.empty()) + if (username.empty() || password.empty() || !NickServ::service) request.reply("error", "Invalid parameters"); else { - XMLRPCIdentifyRequest *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new XMLRPCIdentifyRequest(request, client, iface), me, username, password); Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); return false; } - + return true; } diff --git a/modules/ns_maxemail.cpp b/modules/ns_maxemail.cpp index a7e2f29ac..2ead0de86 100644 --- a/modules/ns_maxemail.cpp +++ b/modules/ns_maxemail.cpp @@ -33,16 +33,16 @@ class NSMaxEmail : public Module return true; } - int CountEmail(const Anope::string &email, NickCore *unc) + int CountEmail(const Anope::string &email, NickServ::Account *unc) { int count = 0; if (email.empty()) return 0; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (auto& it : NickServ::service->GetAccountList()) { - const NickCore *nc = it->second; + const NickServ::Account *nc = it.second; if (unc != nc && !nc->email.empty() && nc->email.equals_ci(email)) ++count; diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 5c1a23426..3b829d336 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -282,7 +282,7 @@ class BahamutIRCdProto : public IRCDProto UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; } - void SendLogin(User *u, NickAlias *) override + void SendLogin(User *u, NickServ::Nick *) override { IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); } @@ -373,11 +373,11 @@ struct IRCDMessageNick : IRCDMessage return; } - NickAlias *na = NULL; + NickServ::Nick *na = NULL; time_t signon = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, stamp = params[7].is_pos_number_only() ? convertTo<time_t>(params[7]) : 0; - if (signon && signon == stamp) - na = NickAlias::Find(params[0]); + if (signon && signon == stamp && NickServ::service) + na = NickServ::service->FindNick(params[0]); User::OnIntroduce(params[0], params[4], params[5], "", params[8], s, params[9], signon, params[3], "", na ? *na->nc : NULL); } diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index 68bf31e76..e69de2b12 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -60,7 +60,7 @@ class CharybdisProto : public IRCDProto void SendChannel(Channel *c) override { ratbox->SendChannel(c); } void SendTopic(const MessageSource &source, Channel *c) override { ratbox->SendTopic(source, c); } bool IsIdentValid(const Anope::string &ident) override { return ratbox->IsIdentValid(ident); } - void SendLogin(User *u, NickAlias *na) override { ratbox->SendLogin(u, na); } + void SendLogin(User *u, NickServ::Nick *na) override { ratbox->SendLogin(u, na); } void SendLogout(User *u) override { ratbox->SendLogout(u); } void SendSQLine(User *, const XLine *x) override @@ -166,7 +166,7 @@ struct IRCDMessageEncap : IRCDMessage // In a burst, states that the source user is logged in as the account. if (params[1] == "LOGIN" || params[1] == "SU") { - NickCore *nc = NickCore::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); if (!nc) return; u->Login(nc); @@ -221,9 +221,9 @@ struct IRCDMessageEUID : IRCDMessage */ void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { - NickAlias *na = NULL; + NickServ::Nick *na = NULL; if (params[9] != "*") - na = NickAlias::Find(params[9]); + na = NickServ::FindNick(params[9]); User::OnIntroduce(params[0], params[4], params[8], params[5], params[6], source.GetServer(), params[10], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime, params[3], params[7], na ? *na->nc : NULL); } @@ -304,7 +304,7 @@ class ProtoCharybdis : public Module ModeManager::AddUserMode(new UserMode("NOFORWARD", 'Q')); ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); ModeManager::AddUserMode(new UserModeOperOnly("OPERWALLS", 'z')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'Z')); + ModeManager::AddUserMode(new UserModeNoone("SSL", 'Z')); /* b/e/I */ ModeManager::AddChannelMode(new ChannelModeList("QUIET", 'q')); @@ -400,7 +400,7 @@ class ProtoCharybdis : public Module } } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); @@ -413,7 +413,7 @@ class ProtoCharybdis : public Module return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index d2b5b935a..9dd906387 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -224,7 +224,7 @@ class HybridProto : public IRCDProto UplinkSocket::Message(source) << "SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; } - void SendLogin(User *u, NickAlias *na) override + void SendLogin(User *u, NickServ::Nick *na) override { IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); } @@ -535,9 +535,9 @@ struct IRCDMessageUID : IRCDMessage if (ip == "0") /* Can be 0 for spoofed clients */ ip.clear(); - NickAlias *na = NULL; + NickServ::Nick *na = NULL; if (params[8] != "0") - na = NickAlias::Find(params[8]); + na = NickServ::FindNick(params[8]); /* Source is always the server */ User::OnIntroduce(params[0], params[4], params[5], "", diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 77ebb2fe6..1981b3cc5 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -361,7 +361,7 @@ class InspIRCd20Proto : public IRCDProto UplinkSocket::Message(source) << "SNONOTICE A :" << buf; } - void SendLogin(User *u, NickAlias *na) override + void SendLogin(User *u, NickServ::Nick *na) override { /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */ if (na->nc->HasExt("UNCONFIRMED")) @@ -1166,7 +1166,7 @@ struct IRCDMessageMetadata : IRCDMessage if (params[1].equals_cs("accountname")) { User *u = User::Find(params[0]); - NickCore *nc = NickCore::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); if (u && nc) u->Login(nc); } @@ -1347,7 +1347,7 @@ struct IRCDMessageServer : IRCDMessage struct IRCDMessageSQuit : Message::SQuit { IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { } - + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params[0] == rsquit_id || params[0] == rsquit_server) @@ -1401,7 +1401,7 @@ struct IRCDMessageUID : IRCDMessage for (unsigned i = 9; i < params.size() - 1; ++i) modes += " " + params[i]; - NickAlias *na = NULL; + NickServ::Nick *na = NULL; if (SASL::sasl) for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) { @@ -1411,7 +1411,7 @@ struct IRCDMessageUID : IRCDMessage it = saslusers.erase(it); else if (u.uid == params[0]) { - na = NickAlias::Find(u.acc); + na = NickServ::FindNick(u.acc); it = saslusers.erase(it); } else @@ -1541,7 +1541,7 @@ class ProtoInspIRCd20 : public Module this->OnChanRegistered(c->ci); } - void OnChanRegistered(ChannelInfo *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); if (use_server_side_mlock && ci->c && modelocks && !modelocks->GetMLockAsString(false).empty()) @@ -1557,7 +1557,7 @@ class ProtoInspIRCd20 : public Module } } - void OnDelChan(ChannelInfo *ci) override + void OnDelChan(ChanServ::Channel *ci) override { if (use_server_side_mlock && ci->c) SendChannelMetadata(ci->c, "mlock", ""); @@ -1566,7 +1566,7 @@ class ProtoInspIRCd20 : public Module SendChannelMetadata(ci->c, "topiclock", ""); } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); @@ -1579,7 +1579,7 @@ class ProtoInspIRCd20 : public Module return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); @@ -1592,7 +1592,7 @@ class ProtoInspIRCd20 : public Module return EVENT_CONTINUE; } - EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) override + EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) override { if (cmd->name == "chanserv/topic" && ci->c) { diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index 06790b2af..a18f8f770 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -118,7 +118,7 @@ class ngIRCdProto : public IRCDProto UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick; } - void SendLogin(User *u, NickAlias *na) override + void SendLogin(User *u, NickServ::Nick *na) override { UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display; } @@ -126,7 +126,7 @@ class ngIRCdProto : public IRCDProto void SendLogout(User *u) override { UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; - } + } void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override { @@ -345,7 +345,7 @@ struct IRCDMessageMetadata : IRCDMessage } if (params[1].equals_cs("accountname")) { - NickCore *nc = NickCore::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); if (nc) u->Login(nc); } @@ -492,7 +492,7 @@ struct IRCDMessageNJoin : IRCDMessage continue; } users.push_back(sju); - } + } Message::Join::SJoin(source, params[0], 0, "", users); } diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index e4cc26e6a..0e22ba6c0 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -142,7 +142,7 @@ class PlexusProto : public IRCDProto UplinkSocket::Message(source) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; } - void SendLogin(User *u, NickAlias *na) override + void SendLogin(User *u, NickServ::Nick *na) override { UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display; } @@ -184,7 +184,7 @@ struct IRCDMessageEncap : IRCDMessage if (params[1].equals_cs("SU")) { User *u = User::Find(params[2]); - NickCore *nc = NickCore::Find(params[3]); + NickServ::Account *nc = NickServ::FindAccount(params[3]); if (u && nc) { u->Login(nc); @@ -272,15 +272,15 @@ struct IRCDMessageUID : IRCDMessage ts = Anope::CurTime; } - NickAlias *na = NULL; + NickServ::Nick *na = NULL; try { if (params[8].is_pos_number_only() && convertTo<time_t>(params[8]) == ts) - na = NickAlias::Find(params[0]); + na = NickServ::FindNick(params[0]); } catch (const ConvertException &) { } if (params[8] != "0" && !na) - na = NickAlias::Find(params[8]); + na = NickServ::FindNick(params[8]); User::OnIntroduce(params[0], params[4], params[9], params[5], ip, source.GetServer(), params[10], ts, params[3], params[7], na ? *na->nc : NULL); } @@ -312,7 +312,7 @@ class ProtoPlexus : public Module Message::Topic message_topic; Message::Version message_version; Message::Whois message_whois; - + /* Hybrid message handlers */ ServiceAlias message_bmask, message_eob, message_join, message_nick, message_sid, message_sjoin, message_tburst, message_tmode; diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 5cc80742f..ec946c391 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -81,7 +81,7 @@ class RatboxProto : public IRCDProto UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname; } - void SendLogin(User *u, NickAlias *na) override + void SendLogin(User *u, NickServ::Nick *na) override { if (na->nc->HasExt("UNCONFIRMED")) return; @@ -125,7 +125,7 @@ struct IRCDMessageEncap : IRCDMessage { User *u = source.GetUser(); - NickCore *nc = NickCore::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); if (!nc) return; u->Login(nc); diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index eec4601ce..606f22270 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -343,7 +343,7 @@ class UnrealIRCdProto : public IRCDProto return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':'; } - void SendLogin(User *u, NickAlias *na) override + void SendLogin(User *u, NickServ::Nick *na) override { if (Servers::Capab.count("ESVID") > 0) IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); @@ -474,7 +474,7 @@ class UnrealExtBan : public ChannelModeList if (u->Account() && Anope::Match(u->Account()->display, real_mask)) return true; } - + return false; } }; @@ -496,7 +496,7 @@ class ChannelModeFlood : public ChannelModeParam return true; } catch (const ConvertException &) { } - + /* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */ size_t end_bracket = value.find(']', 1); if (end_bracket == Anope::string::npos) @@ -840,19 +840,19 @@ struct IRCDMessageNick : IRCDMessage Log(LOG_DEBUG) << "User " << params[0] << " introduced from nonexistant server " << params[5] << "?"; return; } - - NickAlias *na = NULL; + + NickServ::Nick *na = NULL; if (params[6] == "0") ; else if (params[6].is_pos_number_only()) { if (convertTo<time_t>(params[6]) == user_ts) - na = NickAlias::Find(params[0]); + na = NickServ::FindNick(params[0]); } else { - na = NickAlias::Find(params[6]); + na = NickServ::FindNick(params[6]); } User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? *na->nc : NULL); @@ -889,7 +889,7 @@ struct IRCDMessageSASL : IRCDMessage void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { size_t p = params[1].find('!'); - if (!SASL::sasl || p == Anope::string::npos) + if (!SASL::sasl || p == Anope::string::npos) return; SASL::Message m; @@ -1032,7 +1032,7 @@ struct IRCDMessageSJoin : IRCDMessage users.push_back(sju); } } - + time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; Message::Join::SJoin(source, params[1], ts, modes, users); @@ -1252,7 +1252,7 @@ class ProtoUnreal : public Module } } - void OnChanRegistered(ChannelInfo *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK")) @@ -1261,14 +1261,14 @@ class ProtoUnreal : public Module UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; } - void OnDelChan(ChannelInfo *ci) override + void OnDelChan(ChanServ::Channel *ci) override { if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) return; UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :"; } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); @@ -1281,7 +1281,7 @@ class ProtoUnreal : public Module return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); diff --git a/modules/pseudoclients/botserv/CMakeLists.txt b/modules/pseudoclients/botserv/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/pseudoclients/botserv/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv/botserv.cpp index 2f4511f32..cbb76599a 100644 --- a/modules/pseudoclients/botserv.cpp +++ b/modules/pseudoclients/botserv/botserv.cpp @@ -10,9 +10,10 @@ */ #include "module.h" +#include "modules/botserv.h" #include "modules/help.h" -class BotServCore : public Module +class BotServCore : public Module, public BotServ::BotServService , public EventHook<Event::SetCorrectModes> , public EventHook<Event::BotAssign> , public EventHook<Event::JoinChannel> @@ -28,6 +29,7 @@ class BotServCore : public Module public: BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , BotServ::BotServService(this) , EventHook<Event::SetCorrectModes>("OnSetCorrectModes") , EventHook<Event::BotAssign>("OnBotAssign") , EventHook<Event::JoinChannel>("OnJoinChannel") @@ -48,7 +50,7 @@ class BotServCore : public Module BotServ = BotInfo::Find(bsnick, true); } - void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override + void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { /* Do not allow removing bot modes on our service bots */ if (chan->ci && chan->ci->bi == user) @@ -59,7 +61,7 @@ class BotServCore : public Module } } - void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) override + void OnBotAssign(User *sender, ChanServ::Channel *ci, BotInfo *bi) override { if (ci->c && ci->c->users.size() >= Config->GetModule(this)->Get<unsigned>("minusers")) { @@ -128,7 +130,7 @@ class BotServCore : public Module /* Channel is persistent, it shouldn't be deleted and the service bot should stay */ if (c->ci && persist && persist->HasExt(c->ci)) return; - + /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediatly * We also don't part the bot here either, if necessary we will part it after the sync */ @@ -208,7 +210,7 @@ class BotServCore : public Module return EVENT_CONTINUE; } - void OnCreateChan(ChannelInfo *ci) override + void OnCreateChan(ChanServ::Channel *ci) override { /* Set default bot flags */ spacesepstream sep(Config->GetModule(this)->Get<const Anope::string>("defaults", "greet fantasy")); diff --git a/modules/pseudoclients/chanserv/CMakeLists.txt b/modules/pseudoclients/chanserv/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/pseudoclients/chanserv/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/regchannel.cpp b/modules/pseudoclients/chanserv/channel.cpp index 7551266b0..5364075ae 100644 --- a/src/regchannel.cpp +++ b/modules/pseudoclients/chanserv/channel.cpp @@ -10,103 +10,18 @@ * */ -#include "services.h" -#include "modules.h" -#include "regchannel.h" -#include "account.h" -#include "access.h" -#include "channels.h" -#include "config.h" -#include "bots.h" -#include "servers.h" -#include "event.h" +#include "module.h" +#include "channel.h" +#include "modules/cs_akick.h" -Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo"); - -AutoKick::AutoKick() : Serializable("AutoKick") -{ -} - -AutoKick::~AutoKick() -{ - if (this->ci) - { - std::vector<AutoKick *>::iterator it = std::find(this->ci->akick->begin(), this->ci->akick->end(), this); - if (it != this->ci->akick->end()) - this->ci->akick->erase(it); - - const NickAlias *na = NickAlias::Find(this->mask); - if (na != NULL) - na->nc->RemoveChannelReference(this->ci); - } -} - -void AutoKick::Serialize(Serialize::Data &data) const -{ - data["ci"] << this->ci->name; - if (this->nc) - data["nc"] << this->nc->display; - else - data["mask"] << this->mask; - data["reason"] << this->reason; - data["creator"] << this->creator; - data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime; - data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used; -} - -Serializable* AutoKick::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string sci, snc; - - data["ci"] >> sci; - data["nc"] >> snc; - - ChannelInfo *ci = ChannelInfo::Find(sci); - if (!ci) - return NULL; - - AutoKick *ak; - NickCore *nc = NickCore::Find(snc); - if (obj) - { - ak = anope_dynamic_static_cast<AutoKick *>(obj); - data["creator"] >> ak->creator; - data["reason"] >> ak->reason; - ak->nc = NickCore::Find(snc); - data["mask"] >> ak->mask; - data["addtime"] >> ak->addtime; - data["last_used"] >> ak->last_used; - } - else - { - time_t addtime, lastused; - data["addtime"] >> addtime; - data["last_used"] >> lastused; - - Anope::string screator, sreason, smask; - - data["creator"] >> screator; - data["reason"] >> sreason; - data["mask"] >> smask; - - if (nc) - ak = ci->AddAkick(screator, nc, sreason, addtime, lastused); - else - ak = ci->AddAkick(screator, smask, sreason, addtime, lastused); - } - - return ak; -} - -ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInfo"), - access("ChanAccess"), akick("AutoKick") +ChannelImpl::ChannelImpl(const Anope::string &chname) { if (chname.empty()) - throw CoreException("Empty channel passed to ChannelInfo constructor"); + throw CoreException("Empty channel passed to ChanServ::Channel constructor"); this->founder = NULL; this->successor = NULL; - this->c = Channel::Find(chname); + this->c = ::Channel::Find(chname); if (this->c) this->c->ci = this; this->banexpire = 0; @@ -116,19 +31,18 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf this->name = chname; this->bantype = 2; - this->memos.memomax = 0; this->last_used = this->time_registered = Anope::CurTime; - size_t old = RegisteredChannelList->size(); - (*RegisteredChannelList)[this->name] = this; - if (old == RegisteredChannelList->size()) + ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); + Channel* &ci = map[chname]; + if (ci) Log(LOG_DEBUG) << "Duplicate channel " << this->name << " in registered channel table?"; + ci = this; Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); } -ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), - access("ChanAccess"), akick("AutoKick") +ChannelImpl::ChannelImpl(const ChanServ::Channel &ci) { *this = ci; @@ -140,10 +54,10 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), for (unsigned i = 0; i < ci.GetAccessCount(); ++i) { - const ChanAccess *taccess = ci.GetAccess(i); - AccessProvider *provider = taccess->provider; + const ChanServ::ChanAccess *taccess = ci.GetAccess(i); + ChanServ::AccessProvider *provider = taccess->provider; - ChanAccess *newaccess = provider->Create(); + ChanServ::ChanAccess *newaccess = provider->Create(); newaccess->ci = this; newaccess->mask = taccess->mask; newaccess->creator = taccess->creator; @@ -166,7 +80,7 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); } -ChannelInfo::~ChannelInfo() +ChannelImpl::~ChannelImpl() { Event::OnDelChan(&Event::DelChan::OnDelChan, this); @@ -188,7 +102,8 @@ ChannelInfo::~ChannelInfo() } } - RegisteredChannelList->erase(this->name); + ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); + map.erase(this->name); this->SetFounder(NULL); this->SetSuccessor(NULL); @@ -196,18 +111,19 @@ ChannelInfo::~ChannelInfo() this->ClearAccess(); this->ClearAkick(); - if (!this->memos.memos->empty()) + if (this->memos) { - for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i) - delete this->memos.GetMemo(i); - this->memos.memos->clear(); + for (unsigned i = 0, end = this->memos->memos->size(); i < end; ++i) + delete this->memos->GetMemo(i); + this->memos->memos->clear(); + delete memos; } if (this->founder) --this->founder->channelcount; } -void ChannelInfo::Serialize(Serialize::Data &data) const +void ChannelImpl::Serialize(Serialize::Data &data) const { data["name"] << this->name; if (this->founder) @@ -230,14 +146,17 @@ void ChannelInfo::Serialize(Serialize::Data &data) const if (this->bi) data["bi"] << this->bi->nick; data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire; - data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; + if (memos) + { + data["memomax"] << this->memos->memomax; + for (unsigned i = 0; i < this->memos->ignores.size(); ++i) + data["memoignores"] << this->memos->ignores[i] << " "; + } Extensible::ExtensibleSerialize(this, this, data); } -Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) +Serializable* ChannelImpl::Unserialize(Serializable *obj, Serialize::Data &data) { Anope::string sname, sfounder, ssuccessor, slevels, sbi; @@ -247,14 +166,14 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) data["levels"] >> slevels; data["bi"] >> sbi; - ChannelInfo *ci; + ChannelImpl *ci; if (obj) - ci = anope_dynamic_static_cast<ChannelInfo *>(obj); + ci = anope_dynamic_static_cast<ChannelImpl *>(obj); else - ci = new ChannelInfo(sname); + ci = new ChannelImpl(sname); - ci->SetFounder(NickCore::Find(sfounder)); - ci->SetSuccessor(NickCore::Find(ssuccessor)); + ci->SetFounder(NickServ::FindAccount(sfounder)); + ci->SetSuccessor(NickServ::FindAccount(ssuccessor)); data["description"] >> ci->desc; data["time_registered"] >> ci->time_registered; @@ -282,14 +201,17 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) ci->bi->UnAssign(NULL, ci); } data["banexpire"] >> ci->banexpire; - data["memomax"] >> ci->memos.memomax; + if (ci->memos) { - Anope::string buf; - data["memoignores"] >> buf; - spacesepstream sep(buf); - ci->memos.ignores.clear(); - while (sep.GetToken(buf)) - ci->memos.ignores.push_back(buf); + data["memomax"] >> ci->memos->memomax; + { + Anope::string buf; + data["memoignores"] >> buf; + spacesepstream sep(buf); + ci->memos->ignores.clear(); + while (sep.GetToken(buf)) + ci->memos->ignores.push_back(buf); + } } Extensible::ExtensibleUnserialize(ci, ci, data); @@ -346,7 +268,7 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) } -void ChannelInfo::SetFounder(NickCore *nc) +void ChannelImpl::SetFounder(NickServ::Account *nc) { if (this->founder) { @@ -363,12 +285,12 @@ void ChannelInfo::SetFounder(NickCore *nc) } } -NickCore *ChannelInfo::GetFounder() const +NickServ::Account *ChannelImpl::GetFounder() const { return this->founder; } -void ChannelInfo::SetSuccessor(NickCore *nc) +void ChannelImpl::SetSuccessor(NickServ::Account *nc) { if (this->successor) this->successor->RemoveChannelReference(this); @@ -377,16 +299,16 @@ void ChannelInfo::SetSuccessor(NickCore *nc) this->successor->AddChannelReference(this); } -NickCore *ChannelInfo::GetSuccessor() const +NickServ::Account *ChannelImpl::GetSuccessor() const { return this->successor; } -BotInfo *ChannelInfo::WhoSends() const +BotInfo *ChannelImpl::WhoSends() const { if (this && this->bi) return this->bi; - + BotInfo *ChanServ = Config->GetClient("ChanServ"); if (ChanServ) return ChanServ; @@ -397,11 +319,11 @@ BotInfo *ChannelInfo::WhoSends() const return NULL; } -void ChannelInfo::AddAccess(ChanAccess *taccess) +void ChannelImpl::AddAccess(ChanServ::ChanAccess *taccess) { this->access->push_back(taccess); - const NickAlias *na = NickAlias::Find(taccess->mask); + const NickServ::Nick *na = NickServ::FindNick(taccess->mask); if (na != NULL) { na->nc->AddChannelReference(this); @@ -409,45 +331,45 @@ void ChannelInfo::AddAccess(ChanAccess *taccess) } else { - ChannelInfo *ci = ChannelInfo::Find(taccess->mask); + ChanServ::Channel *ci = ChanServ::Find(taccess->mask); if (ci != NULL) ci->AddChannelReference(this->name); } } -ChanAccess *ChannelInfo::GetAccess(unsigned index) const +ChanServ::ChanAccess *ChannelImpl::GetAccess(unsigned index) const { if (this->access->empty() || index >= this->access->size()) return NULL; - ChanAccess *acc = (*this->access)[index]; + ChanServ::ChanAccess *acc = (*this->access)[index]; acc->QueueUpdate(); return acc; } -AccessGroup ChannelInfo::AccessFor(const User *u) +ChanServ::AccessGroup ChannelImpl::AccessFor(const User *u) { - AccessGroup group; + ChanServ::AccessGroup group; if (u == NULL) return group; - const NickCore *nc = u->Account(); + const NickServ::Account *nc = u->Account(); if (nc == NULL && !this->HasExt("NS_SECURE") && u->IsRecognized()) { - const NickAlias *na = NickAlias::Find(u->nick); + const NickServ::Nick *na = NickServ::FindNick(u->nick); if (na != NULL) nc = na->nc; } group.super_admin = u->super_admin; - group.founder = IsFounder(u, this); + group.founder = IsFounder(u); group.ci = this; group.nc = nc; for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { - ChanAccess *a = this->GetAccess(i); + ChanServ::ChanAccess *a = this->GetAccess(i); if (a->Matches(u, u->Account(), group.path)) group.push_back(a); } @@ -463,9 +385,9 @@ AccessGroup ChannelInfo::AccessFor(const User *u) return group; } -AccessGroup ChannelInfo::AccessFor(const NickCore *nc) +ChanServ::AccessGroup ChannelImpl::AccessFor(const NickServ::Account *nc) { - AccessGroup group; + ChanServ::AccessGroup group; group.founder = (this->founder && this->founder == nc); group.ci = this; @@ -473,7 +395,7 @@ AccessGroup ChannelInfo::AccessFor(const NickCore *nc) for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { - ChanAccess *a = this->GetAccess(i); + ChanServ::ChanAccess *a = this->GetAccess(i); if (a->Matches(NULL, nc, group.path)) group.push_back(a); } @@ -486,26 +408,26 @@ AccessGroup ChannelInfo::AccessFor(const NickCore *nc) return group; } -unsigned ChannelInfo::GetAccessCount() const +unsigned ChannelImpl::GetAccessCount() const { return this->access->size(); } -unsigned ChannelInfo::GetDeepAccessCount() const +unsigned ChannelImpl::GetDeepAccessCount() const { - ChanAccess::Path path; + ChanServ::ChanAccess::Path path; for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { - ChanAccess *a = this->GetAccess(i); + ChanServ::ChanAccess *a = this->GetAccess(i); a->Matches(NULL, NULL, path); } unsigned count = this->GetAccessCount(); - std::set<const ChannelInfo *> channels; + std::set<const ChanServ::Channel *> channels; channels.insert(this); - for (ChanAccess::Set::iterator it = path.first.begin(); it != path.first.end(); ++it) + for (ChanServ::ChanAccess::Set::iterator it = path.first.begin(); it != path.first.end(); ++it) { - const ChannelInfo *ci = it->first->ci; + const ChanServ::Channel *ci = it->first->ci; if (!channels.count(ci)) { channels.count(ci); @@ -515,25 +437,28 @@ unsigned ChannelInfo::GetDeepAccessCount() const return count; } -ChanAccess *ChannelInfo::EraseAccess(unsigned index) +ChanServ::ChanAccess *ChannelImpl::EraseAccess(unsigned index) { if (this->access->empty() || index >= this->access->size()) return NULL; - ChanAccess *ca = this->access->at(index); + ChanServ::ChanAccess *ca = this->access->at(index); this->access->erase(this->access->begin() + index); return ca; } -void ChannelInfo::ClearAccess() +void ChannelImpl::ClearAccess() { for (unsigned i = this->access->size(); i > 0; --i) delete this->GetAccess(i - 1); } -AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu) +AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t, time_t lu) { - AutoKick *autokick = new AutoKick(); + if (!::akick) + return nullptr; + + AutoKick *autokick = ::akick->Create(); autokick->ci = this; autokick->nc = akicknc; autokick->reason = reason; @@ -548,9 +473,12 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, co return autokick; } -AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu) +AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu) { - AutoKick *autokick = new AutoKick(); + if (!::akick) + return nullptr; + + AutoKick *autokick = ::akick->Create(); autokick->ci = this; autokick->mask = mask; autokick->nc = NULL; @@ -564,7 +492,7 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string & return autokick; } -AutoKick *ChannelInfo::GetAkick(unsigned index) const +AutoKick *ChannelImpl::GetAkick(unsigned index) const { if (this->akick->empty() || index >= this->akick->size()) return NULL; @@ -574,31 +502,31 @@ AutoKick *ChannelInfo::GetAkick(unsigned index) const return ak; } -unsigned ChannelInfo::GetAkickCount() const +unsigned ChannelImpl::GetAkickCount() const { return this->akick->size(); } -void ChannelInfo::EraseAkick(unsigned index) +void ChannelImpl::EraseAkick(unsigned index) { if (this->akick->empty() || index >= this->akick->size()) return; - + delete this->GetAkick(index); } -void ChannelInfo::ClearAkick() +void ChannelImpl::ClearAkick() { while (!this->akick->empty()) delete this->akick->back(); } -int16_t ChannelInfo::GetLevel(const Anope::string &priv) const +int16_t ChannelImpl::GetLevel(const Anope::string &priv) const { - if (PrivilegeManager::FindPrivilege(priv) == NULL) + if (!ChanServ::service || !ChanServ::service->FindPrivilege(priv)) { Log(LOG_DEBUG) << "Unknown privilege " + priv; - return ACCESS_INVALID; + return ChanServ::ACCESS_INVALID; } Anope::map<int16_t>::const_iterator it = this->levels.find(priv); @@ -607,22 +535,22 @@ int16_t ChannelInfo::GetLevel(const Anope::string &priv) const return it->second; } -void ChannelInfo::SetLevel(const Anope::string &priv, int16_t level) +void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) { this->levels[priv] = level; } -void ChannelInfo::RemoveLevel(const Anope::string &priv) +void ChannelImpl::RemoveLevel(const Anope::string &priv) { this->levels.erase(priv); } -void ChannelInfo::ClearLevels() +void ChannelImpl::ClearLevels() { this->levels.clear(); } -Anope::string ChannelInfo::GetIdealBan(User *u) const +Anope::string ChannelImpl::GetIdealBan(User *u) const { int bt = this ? this->bantype : -1; switch (bt) @@ -642,46 +570,34 @@ Anope::string ChannelInfo::GetIdealBan(User *u) const } } -ChannelInfo* ChannelInfo::Find(const Anope::string &name) -{ - registered_channel_map::const_iterator it = RegisteredChannelList->find(name); - if (it != RegisteredChannelList->end()) - { - it->second->QueueUpdate(); - return it->second; - } - - return NULL; -} - -bool IsFounder(const User *user, const ChannelInfo *ci) +bool ChannelImpl::IsFounder(const User *user) { - if (!user || !ci) + if (!user) return false; if (user->super_admin) return true; - if (user->Account() && user->Account() == ci->GetFounder()) + if (user->Account() && user->Account() == this->GetFounder()) return true; return false; } -void ChannelInfo::AddChannelReference(const Anope::string &what) +void ChannelImpl::AddChannelReference(const Anope::string &what) { ++references[what]; } -void ChannelInfo::RemoveChannelReference(const Anope::string &what) +void ChannelImpl::RemoveChannelReference(const Anope::string &what) { int &i = references[what]; if (--i <= 0) references.erase(what); } -void ChannelInfo::GetChannelReferences(std::deque<Anope::string> &chans) +void ChannelImpl::GetChannelReferences(std::deque<Anope::string> &chans) { chans.clear(); for (Anope::map<int>::iterator it = references.begin(); it != references.end(); ++it) diff --git a/modules/pseudoclients/chanserv/channel.h b/modules/pseudoclients/chanserv/channel.h new file mode 100644 index 000000000..c9a85dba6 --- /dev/null +++ b/modules/pseudoclients/chanserv/channel.h @@ -0,0 +1,41 @@ + + +class ChannelImpl : public ChanServ::Channel +{ + public: + ChannelImpl(const Anope::string &chname); + ChannelImpl(const ChanServ::Channel &ci); + ~ChannelImpl(); + + void Serialize(Serialize::Data &data) const override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); + + bool IsFounder(const User *user) override; + void SetFounder(NickServ::Account *nc) override; + NickServ::Account *GetFounder() const override; + void SetSuccessor(NickServ::Account *nc) override; + NickServ::Account *GetSuccessor() const override; + BotInfo *WhoSends() const override; + void AddAccess(ChanServ::ChanAccess *access) override; + ChanServ::ChanAccess *GetAccess(unsigned index) const override; + ChanServ::AccessGroup AccessFor(const User *u) override; + ChanServ::AccessGroup AccessFor(const NickServ::Account *nc) override; + unsigned GetAccessCount() const override; + unsigned GetDeepAccessCount() const override; + ChanServ::ChanAccess *EraseAccess(unsigned index) override; + void ClearAccess() override; + AutoKick* AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override; + AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override; + AutoKick* GetAkick(unsigned index) const override; + unsigned GetAkickCount() const override; + void EraseAkick(unsigned index) override; + void ClearAkick() override; + int16_t GetLevel(const Anope::string &priv) const override; + void SetLevel(const Anope::string &priv, int16_t level) override; + void RemoveLevel(const Anope::string &priv) override; + void ClearLevels() override; + Anope::string GetIdealBan(User *u) const override; + void AddChannelReference(const Anope::string &what) override; + void RemoveChannelReference(const Anope::string &what) override; + void GetChannelReferences(std::deque<Anope::string> &chans) override; +}; diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv/chanserv.cpp index 419f25fc3..d4f3aa1c7 100644 --- a/modules/pseudoclients/chanserv.cpp +++ b/modules/pseudoclients/chanserv/chanserv.cpp @@ -10,14 +10,17 @@ */ #include "module.h" +#include "channel.h" #include "modules/cs_mode.h" #include "modules/help.h" #include "modules/bs_bot.h" #include "modules/chanserv.h" #include "modules/cs_info.h" +#include "modules/cs_akick.h" class ChanServCore : public Module , public ChanServ::ChanServService + , public EventHook<Event::ChannelCreate> , public EventHook<Event::BotDelete> , public EventHook<Event::BotPrivmsg> , public EventHook<Event::DelCore> @@ -44,10 +47,15 @@ class ChanServCore : public Module bool always_lower; EventHandlers<ChanServ::Event::PreChanExpire> OnPreChanExpire; EventHandlers<ChanServ::Event::ChanExpire> OnChanExpire; + std::vector<ChanServ::Privilege> Privileges; + std::vector<ChanServ::AccessProvider *> Providers; + Serialize::Checker<ChanServ::registered_channel_map> registered_channels; + Serialize::Type channel_type, access_type; public: ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , ChanServService(this) + , EventHook<Event::ChannelCreate>("OnChannelCreate") , EventHook<Event::BotDelete>("OnBotDelete") , EventHook<Event::BotPrivmsg>("OnBotPrivmsg") , EventHook<Event::DelCore>("OnDelCore") @@ -71,9 +79,33 @@ class ChanServCore : public Module , always_lower(false) , OnPreChanExpire(this, "OnPreChanExpire") , OnChanExpire(this, "OnChanExpire") + , registered_channels("ChannelInfo") + , channel_type("ChannelInfo", ChannelImpl::Unserialize) + , access_type("ChanAccess", Unserialize) { } + ChanServ::Channel *Create(const Anope::string &name) override + { + return new ChannelImpl(name); + } + + ChanServ::Channel *Create(const ChanServ::Channel &ci) override + { + return new ChannelImpl(ci); + } + + ChanServ::Channel *Find(const Anope::string &name) override + { + auto it = registered_channels->find(name); + return it != registered_channels->end() ? it->second : nullptr; + } + + ChanServ::registered_channel_map& GetChannels() override + { + return registered_channels; + } + void Hold(Channel *c) override { /** A timer used to keep the BotServ bot/ChanServ in the channel @@ -86,7 +118,7 @@ class ChanServCore : public Module Reference<Channel> c; public: - /** Constructor + /** Constructor * @param chan The channel */ ChanServTimer(Reference<BotInfo> &cs, ExtensibleItem<bool> &i, Module *m, Channel *chan) : Timer(m, Config->GetModule(m)->Get<time_t>("inhabit", "15s")), ChanServ(cs), inhabit(i), c(chan) @@ -137,6 +169,166 @@ class ChanServCore : public Module new ChanServTimer(ChanServ, inhabit, this->owner, c); } + void AddPrivilege(ChanServ::Privilege p) override + { + unsigned i; + for (i = 0; i < Privileges.size(); ++i) + { + ChanServ::Privilege &priv = Privileges[i]; + + if (priv.rank > p.rank) + break; + } + + Privileges.insert(Privileges.begin() + i, p); + } + + void RemovePrivilege(ChanServ::Privilege &p) override + { + std::vector<ChanServ::Privilege>::iterator it = std::find(Privileges.begin(), Privileges.end(), p); + if (it != Privileges.end()) + Privileges.erase(it); + + for (auto& cit : GetChannels()) + { + ChanServ::Channel *ci = cit.second; + ci->QueueUpdate(); + ci->RemoveLevel(p.name); + } + } + + ChanServ::Privilege *FindPrivilege(const Anope::string &name) override + { + for (unsigned i = Privileges.size(); i > 0; --i) + if (Privileges[i - 1].name.equals_ci(name)) + return &Privileges[i - 1]; + return NULL; + } + + std::vector<ChanServ::Privilege> &GetPrivileges() override + { + return Privileges; + } + + void ClearPrivileges() override + { + Privileges.clear(); + } + + std::vector<ChanServ::AccessProvider *>& GetProviders() override + { + return Providers; + } + + void Destruct(ChanServ::ChanAccess *access) override + { + if (access->ci) + { + std::vector<ChanServ::ChanAccess *>::iterator it = std::find(access->ci->access->begin(), access->ci->access->end(), access); + if (it != access->ci->access->end()) + access->ci->access->erase(it); + + const NickServ::Nick *na = NickServ::FindNick(access->mask); + if (na != NULL) + na->nc->RemoveChannelReference(access->ci); + else + { + ChanServ::Channel *c = this->Find(access->mask); + if (c) + c->RemoveChannelReference(access->ci->name); + } + } + } + + void Serialize(const ChanServ::ChanAccess *, Serialize::Data &data) override + { + } + + bool Matches(const ChanServ::ChanAccess *access, const User *u, const NickServ::Account *acc, ChanServ::ChanAccess::Path &p) override + { + if (access->nc) + return access->nc == acc; + + if (u) + { + bool is_mask = access->mask.find_first_of("!@?*") != Anope::string::npos; + if (is_mask && Anope::Match(u->nick, access->mask)) + return true; + else if (Anope::Match(u->GetDisplayedMask(), access->mask)) + return true; + } + + if (acc) + { + for (unsigned i = 0; i < acc->aliases->size(); ++i) + { + const NickServ::Nick *na = acc->aliases->at(i); + if (Anope::Match(na->nick, access->mask)) + return true; + } + } + + if (IRCD->IsChannelValid(access->mask)) + { + ChanServ::Channel *tci = Find(access->mask); + if (tci) + { + for (unsigned i = 0; i < tci->GetAccessCount(); ++i) + { + ChanServ::ChanAccess *a = tci->GetAccess(i); + std::pair<const ChanServ::ChanAccess *, const ChanServ::ChanAccess *> pair = std::make_pair(access, a); + + std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(access); + for (; range.first != range.second; ++range.first) + if (range.first->first == pair.first && range.first->second == pair.second) + goto cont; + + p.first.insert(pair); + if (a->Matches(u, acc, p)) + p.second.insert(pair); + + cont:; + } + + return p.second.count(access) > 0; + } + } + + return false; + } + + static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) + { + Anope::string provider, chan; + + data["provider"] >> provider; + data["ci"] >> chan; + + ServiceReference<ChanServ::AccessProvider> aprovider("AccessProvider", provider); + ChanServ::Channel *ci = ChanServ::service->Find(chan); + if (!aprovider || !ci) + return NULL; + + ChanServ::ChanAccess *access; + if (obj) + access = anope_dynamic_static_cast<ChanServ::ChanAccess *>(obj); + else + access = aprovider->Create(); + access->ci = ci; + data["mask"] >> access->mask; + data["creator"] >> access->creator; + data["last_seen"] >> access->last_seen; + data["created"] >> access->created; + + Anope::string adata; + data["data"] >> adata; + access->AccessUnserialize(adata); + + if (!obj) + ci->AddAccess(access); + return access; + } + void OnReload(Configuration::Conf *conf) override { const Anope::string &channick = conf->GetModule(this)->Get<const Anope::string>("client"); @@ -150,6 +342,18 @@ class ChanServCore : public Module ChanServ = bi; + ClearPrivileges(); + for (int i = 0; i < conf->CountBlock("privilege"); ++i) + { + Configuration::Block *privilege = conf->GetBlock("privilege", i); + + const Anope::string &nname = privilege->Get<const Anope::string>("name"), + &desc = privilege->Get<const Anope::string>("desc"); + int rank = privilege->Get<int>("rank"); + + AddPrivilege(ChanServ::Privilege(nname, desc, rank)); + } + spacesepstream(conf->GetModule(this)->Get<const Anope::string>("defaults", "greet fantasy")).GetTokens(defaults); if (defaults.empty()) { @@ -164,6 +368,13 @@ class ChanServCore : public Module always_lower = conf->GetModule(this)->Get<bool>("always_lower_ts"); } + void OnChannelCreate(Channel *c) override + { + c->ci = Find(c->name); + if (c->ci) + c->ci->c = c; + } + void OnBotDelete(BotInfo *bi) override { if (bi == ChanServ) @@ -181,28 +392,28 @@ class ChanServCore : public Module return EVENT_CONTINUE; } - void OnDelCore(NickCore *nc) override + void OnDelCore(NickServ::Account *nc) override { - std::deque<ChannelInfo *> chans; + std::deque<ChanServ::Channel *> chans; nc->GetChannelReferences(chans); int max_reg = Config->GetModule(this)->Get<int>("maxregistered"); for (unsigned i = 0; i < chans.size(); ++i) { - ChannelInfo *ci = chans[i]; + ChanServ::Channel *ci = chans[i]; if (ci->GetFounder() == nc) { - NickCore *newowner = NULL; + NickServ::Account *newowner = NULL; if (ci->GetSuccessor() && ci->GetSuccessor() != nc && (ci->GetSuccessor()->IsServicesOper() || !max_reg || ci->GetSuccessor()->channelcount < max_reg)) newowner = ci->GetSuccessor(); else { - const ChanAccess *highest = NULL; + const ChanServ::ChanAccess *highest = NULL; for (unsigned j = 0; j < ci->GetAccessCount(); ++j) { - const ChanAccess *ca = ci->GetAccess(j); - const NickCore *anc = NickCore::Find(ca->mask); + const ChanServ::ChanAccess *ca = ci->GetAccess(j); + const NickServ::Account *anc = NickServ::FindAccount(ca->mask); if (!anc || (!anc->IsServicesOper() && max_reg && anc->channelcount >= max_reg) || (anc == nc)) continue; @@ -210,7 +421,7 @@ class ChanServCore : public Module highest = ca; } if (highest) - newowner = NickCore::Find(highest->mask); + newowner = NickServ::FindAccount(highest->mask); } if (newowner) @@ -233,8 +444,8 @@ class ChanServCore : public Module for (unsigned j = 0; j < ci->GetAccessCount(); ++j) { - const ChanAccess *ca = ci->GetAccess(j); - const NickCore *anc = NickCore::Find(ca->mask); + const ChanServ::ChanAccess *ca = ci->GetAccess(j); + const NickServ::Account *anc = NickServ::FindAccount(ca->mask); if (anc && anc == nc) { @@ -245,8 +456,8 @@ class ChanServCore : public Module for (unsigned j = 0; j < ci->GetAkickCount(); ++j) { - const AutoKick *akick = ci->GetAkick(j); - if (akick->nc == nc) + const AutoKick *ak = ci->GetAkick(j); + if (ak->nc == nc) { ci->EraseAkick(j); break; @@ -255,7 +466,7 @@ class ChanServCore : public Module } } - void OnDelChan(ChannelInfo *ci) override + void OnDelChan(ChanServ::Channel *ci) override { /* remove access entries that are this channel */ @@ -264,13 +475,13 @@ class ChanServCore : public Module for (unsigned i = 0; i < chans.size(); ++i) { - ChannelInfo *c = ChannelInfo::Find(chans[i]); + ChanServ::Channel *c = ChanServ::Find(chans[i]); if (!c) continue; for (unsigned j = 0; j < c->GetAccessCount(); ++j) { - ChanAccess *a = c->GetAccess(j); + ChanServ::ChanAccess *a = c->GetAccess(j); if (a->mask.equals_ci(ci->name)) { @@ -342,7 +553,7 @@ class ChanServCore : public Module } } - void OnCreateChan(ChannelInfo *ci) override + void OnCreateChan(ChanServ::Channel *ci) override { /* Set default chan flags */ for (unsigned i = 0; i < defaults.size(); ++i) @@ -379,9 +590,9 @@ class ChanServCore : public Module if (!chanserv_expire || Anope::NoExpire || Anope::ReadOnly) return; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ) + for (auto it = registered_channels->begin(); it != registered_channels->end();) { - ChannelInfo *ci = it->second; + ChanServ::Channel *ci = it->second; ++it; bool expire = false; @@ -428,9 +639,9 @@ class ChanServCore : public Module if (!persist) return; /* Find all persistent channels and create them, as we are about to finish burst to our uplink */ - for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (auto& it : *registered_channels) { - ChannelInfo *ci = it->second; + ChanServ::Channel *ci = it.second; if (persist->Get(ci)) { bool c; @@ -456,8 +667,8 @@ class ChanServCore : public Module } } - - void OnChanRegistered(ChannelInfo *ci) override + + void OnChanRegistered(ChanServ::Channel *ci) override { if (!persist || !ci->c) return; @@ -499,7 +710,7 @@ class ChanServCore : public Module return EVENT_CONTINUE; } - void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool show_all) override + void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_all) override { if (!show_all) return; @@ -509,7 +720,7 @@ class ChanServCore : public Module info[_("Expires")] = Anope::strftime(ci->last_used + chanserv_expire, source.GetAccount()); } - void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override + void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { if (always_lower) // Since we always lower the TS, the other side will remove the modes if the channel ts lowers, so we don't diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp index e7577db47..42b629af6 100644 --- a/modules/pseudoclients/global.cpp +++ b/modules/pseudoclients/global.cpp @@ -79,7 +79,7 @@ class GlobalCore : public Module if (!gl.empty()) this->SendGlobal(Global, "", gl); } - + void OnShutdown() override { const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycledown"); diff --git a/modules/pseudoclients/hostserv.cpp b/modules/pseudoclients/hostserv.cpp index 373275e59..f99d0712a 100644 --- a/modules/pseudoclients/hostserv.cpp +++ b/modules/pseudoclients/hostserv.cpp @@ -22,7 +22,7 @@ class HostServCore : public Module , public EventHook<Event::DeleteVhost> { Reference<BotInfo> HostServ; - + public: HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , EventHook<Event::UserLogin>("OnUserLogin") @@ -54,9 +54,9 @@ class HostServCore : public Module if (!IRCD->CanSetVHost) return; - const NickAlias *na = NickAlias::Find(u->nick); + const NickServ::Nick *na = NickServ::FindNick(u->nick); if (!na || na->nc != u->Account() || !na->HasVhost()) - na = NickAlias::Find(u->Account()->display); + na = NickServ::FindNick(u->Account()->display); if (!na || !na->HasVhost()) return; @@ -73,9 +73,9 @@ class HostServCore : public Module if (HostServ) { if (!na->GetVhostIdent().empty()) - u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); + u->SendMessage(*HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); else - u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str()); + u->SendMessage(*HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str()); } } } @@ -97,7 +97,7 @@ class HostServCore : public Module { } - void OnSetVhost(NickAlias *na) override + void OnSetVhost(NickServ::Nick *na) override { if (Config->GetModule(this)->Get<bool>("activate_on_set")) { @@ -116,15 +116,15 @@ class HostServCore : public Module if (HostServ) { if (!na->GetVhostIdent().empty()) - u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); + u->SendMessage(*HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); else - u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str()); + u->SendMessage(*HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str()); } } } } - void OnDeleteVhost(NickAlias *na) override + void OnDeleteVhost(NickServ::Nick *na) override { if (Config->GetModule(this)->Get<bool>("activate_on_set")) { diff --git a/modules/pseudoclients/memoserv/CMakeLists.txt b/modules/pseudoclients/memoserv/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/pseudoclients/memoserv/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/pseudoclients/memoserv/memo.cpp b/modules/pseudoclients/memoserv/memo.cpp new file mode 100644 index 000000000..9383e3b8b --- /dev/null +++ b/modules/pseudoclients/memoserv/memo.cpp @@ -0,0 +1,58 @@ +#include "memo.h" + +MemoImpl::MemoImpl() +{ + unread = receipt = false; +} + +MemoImpl::~MemoImpl() +{ + bool ischan, isregistered; + MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(this->owner, ischan, isregistered, false); + if (mi) + { + std::vector<Memo *>::iterator it = std::find(mi->memos->begin(), mi->memos->end(), this); + + if (it != mi->memos->end()) + mi->memos->erase(it); + } +} + +void MemoImpl::Serialize(Serialize::Data &data) const +{ + data["owner"] << this->owner; + data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time; + data["sender"] << this->sender; + data["text"] << this->text; + data["unread"] << this->unread; + data["receipt"] << this->receipt; +} + +Serializable* MemoImpl::Unserialize(Serializable *obj, Serialize::Data &data) +{ + Anope::string owner; + + data["owner"] >> owner; + + bool ischan, isregistered; + MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(owner, ischan, isregistered, true); + if (!mi) + return NULL; + + Memo *m; + if (obj) + m = anope_dynamic_static_cast<Memo *>(obj); + else + m = new MemoImpl(); + + m->owner = owner; + data["time"] >> m->time; + data["sender"] >> m->sender; + data["text"] >> m->text; + data["unread"] >> m->unread; + data["receipt"] >> m->receipt; + + if (obj == NULL) + mi->memos->push_back(m); + return m; +} diff --git a/modules/pseudoclients/memoserv/memo.h b/modules/pseudoclients/memoserv/memo.h new file mode 100644 index 000000000..fbe8734a6 --- /dev/null +++ b/modules/pseudoclients/memoserv/memo.h @@ -0,0 +1,11 @@ +#include "modules/memoserv.h" + +class MemoImpl : public MemoServ::Memo +{ + public: + MemoImpl(); + ~MemoImpl(); + + void Serialize(Serialize::Data &data) const override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); +}; diff --git a/modules/pseudoclients/memoserv/memoinfo.cpp b/modules/pseudoclients/memoserv/memoinfo.cpp new file mode 100644 index 000000000..a51cd4e6a --- /dev/null +++ b/modules/pseudoclients/memoserv/memoinfo.cpp @@ -0,0 +1,33 @@ +#include "memoinfo.h" + +MemoServ::Memo *MemoInfoImpl::GetMemo(unsigned index) const +{ + if (index >= this->memos->size()) + return NULL; + MemoServ::Memo *m = (*memos)[index]; + m->QueueUpdate(); + return m; +} + +unsigned MemoInfoImpl::GetIndex(MemoServ::Memo *m) const +{ + for (unsigned i = 0; i < this->memos->size(); ++i) + if (this->GetMemo(i) == m) + return i; + return -1; +} + +void MemoInfoImpl::Del(unsigned index) +{ + if (index >= this->memos->size()) + return; + delete this->GetMemo(index); +} + +bool MemoInfoImpl::HasIgnore(User *u) +{ + for (unsigned i = 0; i < this->ignores.size(); ++i) + if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i]))) + return true; + return false; +} diff --git a/modules/pseudoclients/memoserv/memoinfo.h b/modules/pseudoclients/memoserv/memoinfo.h new file mode 100644 index 000000000..06bea0682 --- /dev/null +++ b/modules/pseudoclients/memoserv/memoinfo.h @@ -0,0 +1,10 @@ +#include "modules/memoserv.h" + +struct MemoInfoImpl : MemoServ::MemoInfo +{ + MemoServ::Memo *GetMemo(unsigned index) const override; + unsigned GetIndex(MemoServ::Memo *m) const override; + void Del(unsigned index) override; + bool HasIgnore(User *u) override; +}; + diff --git a/modules/pseudoclients/memoserv.cpp b/modules/pseudoclients/memoserv/memoserv.cpp index c9b11d294..c0a1022d0 100644 --- a/modules/pseudoclients/memoserv.cpp +++ b/modules/pseudoclients/memoserv/memoserv.cpp @@ -14,6 +14,8 @@ #include "modules/help.h" #include "modules/bs_bot.h" #include "modules/memoserv.h" +#include "memoinfo.h" +#include "memo.h" class MemoServCore : public Module, public MemoServ::MemoServService , public EventHook<Event::NickCoreCreate> @@ -28,8 +30,9 @@ class MemoServCore : public Module, public MemoServ::MemoServService Reference<BotInfo> MemoServ; EventHandlers<MemoServ::Event::MemoSend> onmemosend; EventHandlers<MemoServ::Event::MemoDel> onmemodel; + Serialize::Type memo_type; - bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m) + bool SendMemoMail(NickServ::Account *nc, MemoServ::MemoInfo *mi, MemoServ::Memo *m) { Anope::string subject = Language::Translate(nc, Config->GetBlock("mail")->Get<const Anope::string>("memo_subject").c_str()), message = Language::Translate(Config->GetBlock("mail")->Get<const Anope::string>("memo_message").c_str()); @@ -62,13 +65,14 @@ class MemoServCore : public Module, public MemoServ::MemoServService , EventHook<Event::Help>("OnHelp") , onmemosend(this, "OnMemoSend") , onmemodel(this, "OnMemoDel") + , memo_type("Memo", MemoImpl::Unserialize) { } MemoResult Send(const Anope::string &source, const Anope::string &target, const Anope::string &message, bool force) override { - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(target, ischan); + bool ischan, isregistered; + MemoServ::MemoInfo *mi = GetMemoInfo(target, ischan, isregistered, true); if (mi == NULL) return MEMO_INVALID_TARGET; @@ -90,7 +94,7 @@ class MemoServCore : public Module, public MemoServ::MemoServService if (sender != NULL) sender->lastmemosend = Anope::CurTime; - Memo *m = new Memo(); + MemoServ::Memo *m = new MemoImpl(); mi->memos->push_back(m); m->owner = target; m->sender = source; @@ -102,7 +106,7 @@ class MemoServCore : public Module, public MemoServ::MemoServService if (ischan) { - ChannelInfo *ci = ChannelInfo::Find(target); + ChanServ::Channel *ci = ChanServ::Find(target); if (ci->c) { @@ -113,23 +117,23 @@ class MemoServCore : public Module, public MemoServ::MemoServService if (ci->AccessFor(cu->user).HasPriv("MEMO")) { if (cu->user->Account() && cu->user->Account()->HasExt("MEMO_RECEIVE")) - cu->user->SendMessage(MemoServ, MEMO_NEW_X_MEMO_ARRIVED, ci->name.c_str(), Config->StrictPrivmsg.c_str(), MemoServ->nick.c_str(), ci->name.c_str(), mi->memos->size()); + cu->user->SendMessage(*MemoServ, MEMO_NEW_X_MEMO_ARRIVED, ci->name.c_str(), Config->StrictPrivmsg.c_str(), MemoServ->nick.c_str(), ci->name.c_str(), mi->memos->size()); } } } } else { - NickCore *nc = NickAlias::Find(target)->nc; + NickServ::Account *nc = NickServ::FindNick(target)->nc; if (nc->HasExt("MEMO_RECEIVE")) { for (unsigned i = 0; i < nc->aliases->size(); ++i) { - const NickAlias *na = nc->aliases->at(i); + const NickServ::Nick *na = nc->aliases->at(i); User *user = User::Find(na->nick); if (user && user->IsIdentified()) - user->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->StrictPrivmsg.c_str(), MemoServ->nick.c_str(), mi->memos->size()); + user->SendMessage(*MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->StrictPrivmsg.c_str(), MemoServ->nick.c_str(), mi->memos->size()); } } @@ -141,27 +145,66 @@ class MemoServCore : public Module, public MemoServ::MemoServService return MEMO_SUCCESS; } - void Check(User *u) + void Check(User *u) override { - const NickCore *nc = u->Account(); - if (!nc) + const NickServ::Account *nc = u->Account(); + if (!nc || !nc->memos) return; - unsigned i = 0, end = nc->memos.memos->size(), newcnt = 0; + unsigned i = 0, end = nc->memos->memos->size(), newcnt = 0; for (; i < end; ++i) - if (nc->memos.GetMemo(i)->unread) + if (nc->memos->GetMemo(i)->unread) ++newcnt; if (newcnt > 0) - u->SendMessage(MemoServ, newcnt == 1 ? _("You have 1 new memo.") : _("You have %d new memos."), newcnt); - if (nc->memos.memomax > 0 && nc->memos.memos->size() >= static_cast<unsigned>(nc->memos.memomax)) + u->SendMessage(*MemoServ, newcnt == 1 ? _("You have 1 new memo.") : _("You have %d new memos."), newcnt); + if (nc->memos->memomax > 0 && nc->memos->memos->size() >= static_cast<unsigned>(nc->memos->memomax)) { - if (nc->memos.memos->size() > static_cast<unsigned>(nc->memos.memomax)) - u->SendMessage(MemoServ, _("You are over your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos.memomax); + if (nc->memos->memos->size() > static_cast<unsigned>(nc->memos->memomax)) + u->SendMessage(*MemoServ, _("You are over your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos->memomax); else - u->SendMessage(MemoServ, _("You have reached your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos.memomax); + u->SendMessage(*MemoServ, _("You have reached your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos->memomax); } } + MemoServ::Memo *CreateMemo() override + { + return new MemoImpl(); + } + + MemoServ::MemoInfo *GetMemoInfo(const Anope::string &target, bool &is_registered, bool &ischan, bool create) override + { + if (!target.empty() && target[0] == '#') + { + ischan = true; + ChanServ::Channel *ci = ChanServ::Find(target); + if (ci != NULL) + { + is_registered = true; + if (create && !ci->memos) + ci->memos = new MemoInfoImpl(); + return ci->memos; + } + else + is_registered = false; + } + else + { + ischan = false; + NickServ::Nick *na = NickServ::FindNick(target); + if (na != NULL) + { + is_registered = true; + if (create && !na->nc->memos) + na->nc->memos = new MemoInfoImpl(); + return na->nc->memos; + } + else + is_registered = false; + } + + return NULL; + } + void OnReload(Configuration::Conf *conf) override { const Anope::string &msnick = conf->GetModule(this)->Get<const Anope::string>("client"); @@ -176,14 +219,16 @@ class MemoServCore : public Module, public MemoServ::MemoServService MemoServ = bi; } - void OnNickCoreCreate(NickCore *nc) override + void OnNickCoreCreate(NickServ::Account *nc) override { - nc->memos.memomax = Config->GetModule(this)->Get<int>("maxmemos"); + nc->memos = new MemoInfoImpl(); + nc->memos->memomax = Config->GetModule(this)->Get<int>("maxmemos"); } - void OnCreateChan(ChannelInfo *ci) override + void OnCreateChan(ChanServ::Channel *ci) override { - ci->memos.memomax = Config->GetModule(this)->Get<int>("maxmemos"); + ci->memos = new MemoInfoImpl(); + ci->memos->memomax = Config->GetModule(this)->Get<int>("maxmemos"); } void OnBotDelete(BotInfo *bi) override @@ -199,12 +244,12 @@ class MemoServCore : public Module, public MemoServ::MemoServService void OnJoinChannel(User *u, Channel *c) override { - if (c->ci && !c->ci->memos.memos->empty() && c->ci->AccessFor(u).HasPriv("MEMO")) + if (c->ci && c->ci->memos && !c->ci->memos->memos->empty() && c->ci->AccessFor(u).HasPriv("MEMO")) { - if (c->ci->memos.memos->size() == 1) - u->SendMessage(MemoServ, _("There is \002%d\002 memo on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str()); + if (c->ci->memos->memos->size() == 1) + u->SendMessage(*MemoServ, _("There is \002%d\002 memo on channel %s."), c->ci->memos->memos->size(), c->ci->name.c_str()); else - u->SendMessage(MemoServ, _("There are \002%d\002 memos on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str()); + u->SendMessage(*MemoServ, _("There are \002%d\002 memos on channel %s."), c->ci->memos->memos->size(), c->ci->name.c_str()); } } diff --git a/modules/pseudoclients/nickserv/CMakeLists.txt b/modules/pseudoclients/nickserv/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/pseudoclients/nickserv/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/nickcore.cpp b/modules/pseudoclients/nickserv/account.cpp index dc20f2731..55c537a0c 100644 --- a/src/nickcore.cpp +++ b/modules/pseudoclients/nickserv/account.cpp @@ -10,18 +10,13 @@ * */ -#include "services.h" -#include "modules.h" +#include "module.h" #include "account.h" -#include "config.h" -#include "event.h" -Serialize::Checker<nickcore_map> NickCoreList("NickCore"); - -NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias") +AccountImpl::AccountImpl(const Anope::string &coredisplay) { if (coredisplay.empty()) - throw CoreException("Empty display passed to NickCore constructor"); + throw CoreException("Empty display passed to NickServ::Account constructor"); this->o = NULL; this->channelcount = 0; @@ -29,15 +24,16 @@ NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), this->display = coredisplay; - size_t old = NickCoreList->size(); - (*NickCoreList)[this->display] = this; - if (old == NickCoreList->size()) + NickServ::nickcore_map& map = NickServ::service->GetAccountList(); + NickServ::Account* &nc = map[this->display]; + if (nc) Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?"; - + nc = this; + Event::OnNickCoreCreate(&Event::NickCoreCreate::OnNickCoreCreate, this); } -NickCore::~NickCore() +AccountImpl::~AccountImpl() { Event::OnDelCore(&Event::DelCore::OnDelCore, this); @@ -51,19 +47,21 @@ NickCore::~NickCore() } this->users.clear(); - NickCoreList->erase(this->display); + NickServ::nickcore_map& map = NickServ::service->GetAccountList(); + map.erase(this->display); this->ClearAccess(); - if (!this->memos.memos->empty()) + if (memos) { - for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i) - delete this->memos.GetMemo(i); - this->memos.memos->clear(); + for (unsigned i = 0, end = this->memos->memos->size(); i < end; ++i) + delete this->memos->GetMemo(i); + this->memos->memos->clear(); + delete memos; } } -void NickCore::Serialize(Serialize::Data &data) const +void AccountImpl::Serialize(Serialize::Data &data) const { data["display"] << this->display; data["pass"] << this->pass; @@ -71,24 +69,27 @@ void NickCore::Serialize(Serialize::Data &data) const data["language"] << this->language; for (unsigned i = 0; i < this->access.size(); ++i) data["access"] << this->access[i] << " "; - data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; + if (memos) + { + data["memomax"] << this->memos->memomax; + for (unsigned i = 0; i < this->memos->ignores.size(); ++i) + data["memoignores"] << this->memos->ignores[i] << " "; + } Extensible::ExtensibleSerialize(this, this, data); } -Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) +Serializable* AccountImpl::Unserialize(Serializable *obj, Serialize::Data &data) { - NickCore *nc; + NickServ::Account *nc; Anope::string sdisplay; data["display"] >> sdisplay; if (obj) - nc = anope_dynamic_static_cast<NickCore *>(obj); + nc = anope_dynamic_static_cast<NickServ::Account *>(obj); else - nc = new NickCore(sdisplay); + nc = new AccountImpl(sdisplay); data["pass"] >> nc->pass; data["email"] >> nc->email; @@ -101,14 +102,17 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) while (sep.GetToken(buf)) nc->access.push_back(buf); } - data["memomax"] >> nc->memos.memomax; + if (nc->memos) { - Anope::string buf; - data["memoignores"] >> buf; - spacesepstream sep(buf); - nc->memos.ignores.clear(); - while (sep.GetToken(buf)) - nc->memos.ignores.push_back(buf); + data["memomax"] >> nc->memos->memomax; + { + Anope::string buf; + data["memoignores"] >> buf; + spacesepstream sep(buf); + nc->memos->ignores.clear(); + while (sep.GetToken(buf)) + nc->memos->ignores.push_back(buf); + } } Extensible::ExtensibleUnserialize(nc, nc, data); @@ -152,45 +156,51 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) return nc; } -void NickCore::SetDisplay(const NickAlias *na) +void AccountImpl::SetDisplay(const NickServ::Nick *na) { if (na->nc != this || na->nick == this->display) return; Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->nick); + NickServ::nickcore_map& map = NickServ::service->GetAccountList(); + /* Remove the core from the list */ - NickCoreList->erase(this->display); + map.erase(this->display); this->display = na->nick; - (*NickCoreList)[this->display] = this; + NickServ::Account* &nc = map[this->display]; + if (nc) + Log(LOG_DEBUG) << "Duplicate account " << display << " in nickcore table?"; + + nc = this; } -bool NickCore::IsServicesOper() const +bool AccountImpl::IsServicesOper() const { return this->o != NULL; } -void NickCore::AddAccess(const Anope::string &entry) +void AccountImpl::AddAccess(const Anope::string &entry) { this->access.push_back(entry); Event::OnNickAddAccess(&Event::NickAddAccess::OnNickAddAccess, this, entry); } -Anope::string NickCore::GetAccess(unsigned entry) const +Anope::string AccountImpl::GetAccess(unsigned entry) const { if (this->access.empty() || entry >= this->access.size()) return ""; return this->access[entry]; } -unsigned NickCore::GetAccessCount() const +unsigned AccountImpl::GetAccessCount() const { return this->access.size(); } -bool NickCore::FindAccess(const Anope::string &entry) +bool AccountImpl::FindAccess(const Anope::string &entry) { for (unsigned i = 0, end = this->access.size(); i < end; ++i) if (this->access[i] == entry) @@ -199,7 +209,7 @@ bool NickCore::FindAccess(const Anope::string &entry) return false; } -void NickCore::EraseAccess(const Anope::string &entry) +void AccountImpl::EraseAccess(const Anope::string &entry) { for (unsigned i = 0, end = this->access.size(); i < end; ++i) if (this->access[i] == entry) @@ -210,13 +220,13 @@ void NickCore::EraseAccess(const Anope::string &entry) } } -void NickCore::ClearAccess() +void AccountImpl::ClearAccess() { Event::OnNickClearAccess(&Event::NickClearAccess::OnNickClearAccess, this); this->access.clear(); } -bool NickCore::IsOnAccess(const User *u) const +bool AccountImpl::IsOnAccess(const User *u) const { Anope::string buf = u->GetIdent() + "@" + u->host, buf2, buf3; if (!u->vhost.empty()) @@ -233,34 +243,22 @@ bool NickCore::IsOnAccess(const User *u) const return false; } -void NickCore::AddChannelReference(ChannelInfo *ci) +void AccountImpl::AddChannelReference(ChanServ::Channel *ci) { ++(*this->chanaccess)[ci]; } -void NickCore::RemoveChannelReference(ChannelInfo *ci) +void AccountImpl::RemoveChannelReference(ChanServ::Channel *ci) { int& i = (*this->chanaccess)[ci]; if (--i <= 0) this->chanaccess->erase(ci); } -void NickCore::GetChannelReferences(std::deque<ChannelInfo *> &queue) +void AccountImpl::GetChannelReferences(std::deque<ChanServ::Channel *> &queue) { queue.clear(); - for (std::map<ChannelInfo *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it) + for (std::map<ChanServ::Channel *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it) queue.push_back(it->first); } -NickCore* NickCore::Find(const Anope::string &nick) -{ - nickcore_map::const_iterator it = NickCoreList->find(nick); - if (it != NickCoreList->end()) - { - it->second->QueueUpdate(); - return it->second; - } - - return NULL; -} - diff --git a/modules/pseudoclients/nickserv/account.h b/modules/pseudoclients/nickserv/account.h new file mode 100644 index 000000000..ec154e8d0 --- /dev/null +++ b/modules/pseudoclients/nickserv/account.h @@ -0,0 +1,22 @@ +#include "modules/nickserv.h" + +class AccountImpl : public NickServ::Account +{ + public: + AccountImpl(const Anope::string &nickdisplay); + ~AccountImpl(); + void Serialize(Serialize::Data &data) const override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); + void SetDisplay(const NickServ::Nick *na) override; + bool IsServicesOper() const override; + void AddAccess(const Anope::string &entry) override; + Anope::string GetAccess(unsigned entry) const override; + unsigned GetAccessCount() const override; + bool FindAccess(const Anope::string &entry) override; + void EraseAccess(const Anope::string &entry) override; + void ClearAccess() override; + bool IsOnAccess(const User *u) const override; + void AddChannelReference(ChanServ::Channel *ci); + void RemoveChannelReference(ChanServ::Channel *ci) override; + void GetChannelReferences(std::deque<ChanServ::Channel *> &queue) override; +}; diff --git a/modules/pseudoclients/nickserv/identifyrequest.cpp b/modules/pseudoclients/nickserv/identifyrequest.cpp new file mode 100644 index 000000000..4fc2f9989 --- /dev/null +++ b/modules/pseudoclients/nickserv/identifyrequest.cpp @@ -0,0 +1,51 @@ +#include "identifyrequest.h" + +IdentifyRequestImpl::IdentifyRequestImpl(NickServ::IdentifyRequestListener *li, Module *o, const Anope::string &acc, const Anope::string &pass) : NickServ::IdentifyRequest(li, o, acc, pass) +{ + std::set<NickServ::IdentifyRequest *> &requests = NickServ::service->GetIdentifyRequests(); + requests.insert(this); +} + +IdentifyRequestImpl::~IdentifyRequestImpl() +{ + std::set<NickServ::IdentifyRequest *> &requests = NickServ::service->GetIdentifyRequests(); + requests.erase(this); + delete l; +} + +void IdentifyRequestImpl::Hold(Module *m) +{ + holds.insert(m); +} + +void IdentifyRequestImpl::Release(Module *m) +{ + holds.erase(m); + if (holds.empty() && dispatched) + { + if (!success) + l->OnFail(this); + delete this; + } +} + +void IdentifyRequestImpl::Success(Module *m) +{ + if (!success) + { + l->OnSuccess(this); + success = true; + } +} + +void IdentifyRequestImpl::Dispatch() +{ + if (holds.empty()) + { + if (!success) + l->OnFail(this); + delete this; + } + else + dispatched = true; +} diff --git a/modules/pseudoclients/nickserv/identifyrequest.h b/modules/pseudoclients/nickserv/identifyrequest.h new file mode 100644 index 000000000..e74d3129e --- /dev/null +++ b/modules/pseudoclients/nickserv/identifyrequest.h @@ -0,0 +1,13 @@ +#include "modules/nickserv.h" + +class IdentifyRequestImpl : public NickServ::IdentifyRequest +{ + public: + IdentifyRequestImpl(NickServ::IdentifyRequestListener *, Module *o, const Anope::string &acc, const Anope::string &pass); + virtual ~IdentifyRequestImpl(); + + void Hold(Module *m) override; + void Release(Module *m) override; + void Success(Module *m) override; + void Dispatch() override; +}; diff --git a/src/nickalias.cpp b/modules/pseudoclients/nickserv/nick.cpp index dfe06a176..acba58b1e 100644 --- a/src/nickalias.cpp +++ b/modules/pseudoclients/nickserv/nick.cpp @@ -10,34 +10,26 @@ * */ -#include "services.h" -#include "account.h" -#include "modules.h" -#include "opertype.h" -#include "protocol.h" -#include "users.h" -#include "servers.h" -#include "config.h" -#include "event.h" - -Serialize::Checker<nickalias_map> NickAliasList("NickAlias"); - -NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Serializable("NickAlias") +#include "module.h" +#include "nick.h" + +NickImpl::NickImpl(const Anope::string &nickname, NickServ::Account* nickcore) { if (nickname.empty()) - throw CoreException("Empty nick passed to NickAlias constructor"); + throw CoreException("Empty nick passed to NickServ::Nick constructor"); else if (!nickcore) - throw CoreException("Empty nickcore passed to NickAlias constructor"); + throw CoreException("Empty nickcore passed to NickServ::Nick constructor"); this->time_registered = this->last_seen = Anope::CurTime; this->nick = nickname; this->nc = nickcore; nickcore->aliases->push_back(this); - size_t old = NickAliasList->size(); - (*NickAliasList)[this->nick] = this; - if (old == NickAliasList->size()) + NickServ::nickalias_map &map = NickServ::service->GetNickList(); + NickServ::Nick* &na = map[this->nick]; + if (na) Log(LOG_DEBUG) << "Duplicate nick " << nickname << " in nickalias table"; + na = this; if (this->nc->o == NULL) { @@ -50,7 +42,7 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Serial } } -NickAlias::~NickAlias() +NickImpl::~NickImpl() { Event::OnDelNick(&Event::DelNick::OnDelNick, this); @@ -58,7 +50,7 @@ NickAlias::~NickAlias() if (this->nc) { /* Next: see if our core is still useful. */ - std::vector<NickAlias *>::iterator it = std::find(this->nc->aliases->begin(), this->nc->aliases->end(), this); + std::vector<NickServ::Nick *>::iterator it = std::find(this->nc->aliases->begin(), this->nc->aliases->end(), this); if (it != this->nc->aliases->end()) this->nc->aliases->erase(it); if (this->nc->aliases->empty()) @@ -75,10 +67,11 @@ NickAlias::~NickAlias() } /* Remove us from the aliases list */ - NickAliasList->erase(this->nick); + NickServ::nickalias_map &map = NickServ::service->GetNickList(); + map.erase(this->nick); } -void NickAlias::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) +void NickImpl::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) { this->vhost_ident = ident; this->vhost_host = host; @@ -86,7 +79,7 @@ void NickAlias::SetVhost(const Anope::string &ident, const Anope::string &host, this->vhost_created = created; } -void NickAlias::RemoveVhost() +void NickImpl::RemoveVhost() { this->vhost_ident.clear(); this->vhost_host.clear(); @@ -94,44 +87,32 @@ void NickAlias::RemoveVhost() this->vhost_created = 0; } -bool NickAlias::HasVhost() const +bool NickImpl::HasVhost() const { return !this->vhost_host.empty(); } -const Anope::string &NickAlias::GetVhostIdent() const +const Anope::string &NickImpl::GetVhostIdent() const { return this->vhost_ident; } -const Anope::string &NickAlias::GetVhostHost() const +const Anope::string &NickImpl::GetVhostHost() const { return this->vhost_host; } -const Anope::string &NickAlias::GetVhostCreator() const +const Anope::string &NickImpl::GetVhostCreator() const { return this->vhost_creator; } -time_t NickAlias::GetVhostCreated() const +time_t NickImpl::GetVhostCreated() const { return this->vhost_created; } -NickAlias *NickAlias::Find(const Anope::string &nick) -{ - nickalias_map::const_iterator it = NickAliasList->find(nick); - if (it != NickAliasList->end()) - { - it->second->QueueUpdate(); - return it->second; - } - - return NULL; -} - -void NickAlias::Serialize(Serialize::Data &data) const +void NickImpl::Serialize(Serialize::Data &data) const { data["nick"] << this->nick; data["last_quit"] << this->last_quit; @@ -153,26 +134,26 @@ void NickAlias::Serialize(Serialize::Data &data) const Extensible::ExtensibleSerialize(this, this, data); } -Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data) +Serializable* NickImpl::Unserialize(Serializable *obj, Serialize::Data &data) { Anope::string snc, snick; data["nc"] >> snc; data["nick"] >> snick; - NickCore *core = NickCore::Find(snc); + NickServ::Account *core = NickServ::FindAccount(snc); if (core == NULL) return NULL; - NickAlias *na; + NickServ::Nick *na; if (obj) - na = anope_dynamic_static_cast<NickAlias *>(obj); + na = anope_dynamic_static_cast<NickServ::Nick *>(obj); else - na = new NickAlias(snick, core); + na = new NickImpl(snick, core); if (na->nc != core) { - std::vector<NickAlias *>::iterator it = std::find(na->nc->aliases->begin(), na->nc->aliases->end(), na); + std::vector<NickServ::Nick *>::iterator it = std::find(na->nc->aliases->begin(), na->nc->aliases->end(), na); if (it != na->nc->aliases->end()) na->nc->aliases->erase(it); diff --git a/modules/pseudoclients/nickserv/nick.h b/modules/pseudoclients/nickserv/nick.h new file mode 100644 index 000000000..76c948f1e --- /dev/null +++ b/modules/pseudoclients/nickserv/nick.h @@ -0,0 +1,18 @@ + +class NickImpl : public NickServ::Nick +{ + public: + NickImpl(const Anope::string &nickname, NickServ::Account *nickcore); + ~NickImpl(); + + void Serialize(Serialize::Data &data) const override; + static Serializable* Unserialize(Serializable *obj, Serialize::Data &); + + void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime); + void RemoveVhost(); + bool HasVhost() const; + const Anope::string &GetVhostIdent() const override; + const Anope::string &GetVhostHost() const override; + const Anope::string &GetVhostCreator() const override; + time_t GetVhostCreated() const override; +}; diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv/nickserv.cpp index f29b1aa02..b58fe3ccc 100644 --- a/modules/pseudoclients/nickserv.cpp +++ b/modules/pseudoclients/nickserv/nickserv.cpp @@ -15,6 +15,9 @@ #include "modules/ns_update.h" #include "modules/help.h" #include "modules/nickserv.h" +#include "nick.h" +#include "account.h" +#include "identifyrequest.h" /** Timer for colliding nicks to force people off of nicknames */ @@ -23,10 +26,10 @@ class NickServCollide : public Timer NickServ::NickServService *service; Reference<User> u; time_t ts; - Reference<NickAlias> na; + Reference<NickServ::Nick> na; public: - NickServCollide(NickServ::NickServService *nss, User *user, NickAlias *nick, time_t delay) : Timer(delay), service(nss), u(user), ts(user->timestamp), na(nick) + NickServCollide(NickServ::NickServService *nss, User *user, NickServ::Nick *nick, time_t delay) : Timer(delay), service(nss), u(user), ts(user->timestamp), na(nick) { } @@ -46,10 +49,10 @@ class NickServCollide : public Timer */ class NickServHeld : public Timer { - Reference<NickAlias> na; + Reference<NickServ::Nick> na; Anope::string nick; public: - NickServHeld(NickAlias *n, long l) : Timer(l), na(n), nick(na->nick) + NickServHeld(NickServ::Nick *n, long l) : Timer(l), na(n), nick(na->nick) { n->Extend<bool>("HELD"); } @@ -71,7 +74,7 @@ class NickServRelease : public User, public Timer Anope::string nick; public: - NickServRelease(NickAlias *na, time_t delay) : User(na->nick, Config->GetModule("nickserv")->Get<const Anope::string>("enforceruser", "user"), + NickServRelease(NickServ::Nick *na, time_t delay) : User(na->nick, Config->GetModule("nickserv")->Get<const Anope::string>("enforceruser", "user"), Config->GetModule("nickserv")->Get<const Anope::string>("enforcerhost", "services.localhost.net"), "", "", Me, "Services Enforcer", Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Timer(delay), nick(na->nick) { /* Erase the current release timer and use the new one */ @@ -114,6 +117,9 @@ class NickServCore : public Module, public NickServ::NickServService , public EventHook<Event::Help> , public EventHook<Event::ExpireTick> , public EventHook<Event::NickInfo> + , public EventHook<Event::ModuleUnload> + , public EventHook<Event::NickCoreCreate> + , public EventHook<Event::UserQuit> { Reference<BotInfo> NickServ; std::vector<Anope::string> defaults; @@ -122,8 +128,12 @@ class NickServCore : public Module, public NickServ::NickServService EventHandlers<NickServ::Event::NickExpire> onnickexpire; EventHandlers<NickServ::Event::NickRegister> onnickregister; EventHandlers<NickServ::Event::NickValidate> onnickvalidate; + std::set<NickServ::IdentifyRequest *> identifyrequests; + Serialize::Checker<NickServ::nickalias_map> NickList; + Serialize::Checker<NickServ::nickcore_map> AccountList; + Serialize::Type nick_type, account_type; - void OnCancel(User *u, NickAlias *na) + void OnCancel(User *u, NickServ::Nick *na) { if (collided.HasExt(na)) { @@ -158,12 +168,19 @@ class NickServCore : public Module, public NickServ::NickServService , EventHook<Event::Help>("OnHelp") , EventHook<Event::ExpireTick>("OnExpireTick") , EventHook<Event::NickInfo>("OnNickInfo") + , EventHook<Event::ModuleUnload>("OnModuleUnload") + , EventHook<Event::NickCoreCreate>("OnNickCoreCreate") + , EventHook<Event::UserQuit>("OnUserQuit") , held(this, "HELD") , collided(this, "COLLIDED") , onprenickexpire(this, "OnPreNickExpire") , onnickexpire(this, "OnNickExpire") , onnickregister(this, "OnNickRegister") , onnickvalidate(this, "OnNickValidate") + , NickList("NickAlias") + , AccountList("NickCore") + , nick_type("NickAlias", NickImpl::Unserialize) + , account_type("NickCore", AccountImpl::Unserialize) { } @@ -177,8 +194,8 @@ class NickServCore : public Module, public NickServ::NickServService /* On shutdown, restart, or mod unload, remove all of our holds for nicks (svshold or qlines) * because some IRCds do not allow us to have these automatically expire */ - for (nickalias_map::const_iterator it = NickAliasList->begin(); it != NickAliasList->end(); ++it) - this->Release(it->second); + for (auto& it : *NickList) + this->Release(it.second); } void OnRestart() override @@ -188,7 +205,7 @@ class NickServCore : public Module, public NickServ::NickServService void Validate(User *u) override { - NickAlias *na = NickAlias::Find(u->nick); + NickServ::Nick *na = NickServ::FindNick(u->nick); if (!na) return; @@ -217,27 +234,27 @@ class NickServCore : public Module, public NickServ::NickServService if (on_access || !na->nc->HasExt("KILL_IMMED")) { if (na->nc->HasExt("NS_SECURE")) - u->SendMessage(NickServ, NICK_IS_SECURE, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str()); + u->SendMessage(*NickServ, NICK_IS_SECURE, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str()); else - u->SendMessage(NickServ, NICK_IS_REGISTERED, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str()); + u->SendMessage(*NickServ, NICK_IS_REGISTERED, Config->StrictPrivmsg.c_str(), NickServ->nick.c_str()); } if (na->nc->HasExt("KILLPROTECT") && !on_access) { if (na->nc->HasExt("KILL_IMMED")) { - u->SendMessage(NickServ, FORCENICKCHANGE_NOW); + u->SendMessage(*NickServ, FORCENICKCHANGE_NOW); this->Collide(u, na); } else if (na->nc->HasExt("KILL_QUICK")) { time_t killquick = Config->GetModule("nickserv")->Get<time_t>("killquick", "20s"); - u->SendMessage(NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(killquick, u->Account()).c_str()); + u->SendMessage(*NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(killquick, u->Account()).c_str()); new NickServCollide(this, u, na, killquick); } else { time_t kill = Config->GetModule("nickserv")->Get<time_t>("kill", "60s"); - u->SendMessage(NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(kill, u->Account()).c_str()); + u->SendMessage(*NickServ, _("If you do not change within %s, I will change your nick."), Anope::Duration(kill, u->Account()).c_str()); new NickServCollide(this, u, na, kill); } } @@ -246,7 +263,7 @@ class NickServCore : public Module, public NickServ::NickServService void OnUserLogin(User *u) override { - NickAlias *na = NickAlias::Find(u->nick); + NickServ::Nick *na = NickServ::FindNick(u->nick); if (na && *na->nc == u->Account() && !Config->GetModule("nickserv")->Get<bool>("nonicknameownership") && !na->nc->HasExt("UNCONFIRMED")) u->SetMode(NickServ, "REGISTERED"); @@ -255,7 +272,7 @@ class NickServCore : public Module, public NickServ::NickServService u->SetModes(NickServ, "%s", modesonid.c_str()); } - void Collide(User *u, NickAlias *na) override + void Collide(User *u, NickServ::Nick *na) override { if (na) collided.Set(na); @@ -281,7 +298,7 @@ class NickServCore : public Module, public NickServ::NickServService else { if (NickServ) - u->SendMessage(NickServ, _("Your nickname is now being changed to \002%s\002"), guestnick.c_str()); + u->SendMessage(*NickServ, _("Your nickname is now being changed to \002%s\002"), guestnick.c_str()); IRCD->SendForceNickChange(u, guestnick, Anope::CurTime); } } @@ -289,7 +306,7 @@ class NickServCore : public Module, public NickServ::NickServService u->Kill(NickServ ? NickServ->nick : "", "Services nickname-enforcer kill"); } - void Release(NickAlias *na) override + void Release(NickServ::Nick *na) override { if (held.HasExt(na)) { @@ -308,6 +325,48 @@ class NickServCore : public Module, public NickServ::NickServService } } + NickServ::IdentifyRequest *CreateIdentifyRequest(NickServ::IdentifyRequestListener *l, Module *o, const Anope::string &acc, const Anope::string &pass) override + { + return new IdentifyRequestImpl(l, o, acc, pass); + } + + std::set<NickServ::IdentifyRequest *>& GetIdentifyRequests() override + { + return identifyrequests; + } + + NickServ::nickalias_map& GetNickList() override + { + return NickList; + } + + NickServ::nickcore_map& GetAccountList() override + { + return AccountList; + } + + NickServ::Nick *CreateNick(const Anope::string &nick, NickServ::Account *acc) override + { + return new NickImpl(nick, acc); + } + + NickServ::Account *CreateAccount(const Anope::string &acc) override + { + return new AccountImpl(acc); + } + + NickServ::Nick *FindNick(const Anope::string &nick) override + { + auto it = NickList->find(nick); + return it != NickList->end() ? it->second : nullptr; + } + + NickServ::Account *FindAccount(const Anope::string &acc) override + { + auto it = AccountList->find(acc); + return it != AccountList->end() ? it->second : nullptr; + } + void OnReload(Configuration::Conf *conf) override { const Anope::string &nsnick = conf->GetModule(this)->Get<const Anope::string>("client"); @@ -332,7 +391,7 @@ class NickServCore : public Module, public NickServ::NickServService defaults.clear(); } - void OnDelNick(NickAlias *na) override + void OnDelNick(NickServ::Nick *na) override { User *u = User::Find(na->nick); if (u && u->Account() == na->nc) @@ -343,7 +402,7 @@ class NickServCore : public Module, public NickServ::NickServService } } - void OnDelCore(NickCore *nc) override + void OnDelCore(NickServ::Account *nc) override { Log(NickServ, "nick") << "Deleting nickname group " << nc->display; @@ -359,7 +418,7 @@ class NickServCore : public Module, public NickServ::NickServService nc->users.clear(); } - void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) override + void OnChangeCoreDisplay(NickServ::Account *nc, const Anope::string &newdisplay) override { Log(LOG_NORMAL, "nick", NickServ) << "Changing " << nc->display << " nickname group display to " << newdisplay; } @@ -384,16 +443,16 @@ class NickServCore : public Module, public NickServ::NickServService if (block->Get<bool>("forceemail", "yes") && u->Account()->email.empty()) { - u->SendMessage(NickServ, _("You must now supply an e-mail for your nick.\n" + u->SendMessage(*NickServ, _("You must now supply an e-mail for your nick.\n" "This e-mail will allow you to retrieve your password in\n" "case you forget it.")); - u->SendMessage(NickServ, _("Type \002%s%s SET EMAIL \037e-mail\037\002 in order to set your e-mail.\n" + u->SendMessage(*NickServ, _("Type \002%s%s SET EMAIL \037e-mail\037\002 in order to set your e-mail.\n" "Your privacy is respected; this e-mail won't be given to\n" "any third-party person."), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str()); } } - void OnNickGroup(User *u, NickAlias *target) override + void OnNickGroup(User *u, NickServ::Nick *target) override { if (!target->nc->HasExt("UNCONFIRMED")) u->SetMode(NickServ, "REGISTERED"); @@ -415,18 +474,18 @@ class NickServCore : public Module, public NickServ::NickServService if (u->Quitting() || !u->server->IsSynced() || u->server->IsULined()) return; - const NickAlias *na = NickAlias::Find(u->nick); + const NickServ::Nick *na = NickServ::FindNick(u->nick); const Anope::string &unregistered_notice = Config->GetModule(this)->Get<const Anope::string>("unregistered_notice"); if (!Config->GetModule("nickserv")->Get<bool>("nonicknameownership") && !unregistered_notice.empty() && !na && !u->Account()) - u->SendMessage(NickServ, unregistered_notice); + u->SendMessage(*NickServ, unregistered_notice); else if (na && !u->IsIdentified(true)) this->Validate(u); } void OnPostUserLogoff(User *u) override { - NickAlias *na = NickAlias::Find(u->nick); + NickServ::Nick *na = NickServ::FindNick(u->nick); if (na) OnCancel(u, na); } @@ -449,7 +508,7 @@ class NickServCore : public Module, public NickServ::NickServService void OnUserNickChange(User *u, const Anope::string &oldnick) override { - NickAlias *old_na = NickAlias::Find(oldnick), *na = NickAlias::Find(u->nick); + NickServ::Nick *old_na = NickServ::FindNick(oldnick), *na = NickServ::FindNick(u->nick); /* If the new nick isn't registered or it's registered and not yours */ if (!na || na->nc != u->Account()) { @@ -521,20 +580,20 @@ class NickServCore : public Module, public NickServ::NickServService "nickname(s)."), NickServ->nick.c_str()); } - void OnNickCoreCreate(NickCore *nc) + void OnNickCoreCreate(NickServ::Account *nc) override { /* Set default flags */ for (unsigned i = 0; i < defaults.size(); ++i) nc->Extend<bool>(defaults[i].upper()); } - void OnUserQuit(User *u, const Anope::string &msg) + void OnUserQuit(User *u, const Anope::string &msg) override { if (u->server && !u->server->GetQuitReason().empty() && Config->GetModule(this)->Get<bool>("hidenetsplitquit")) return; /* Update last quit and last seen for the user */ - NickAlias *na = NickAlias::Find(u->nick); + NickServ::Nick *na = NickServ::FindNick(u->nick); if (na && !na->nc->HasExt("NS_SUSPENDED") && (u->IsRecognized() || u->IsIdentified(true))) { na->last_seen = Anope::CurTime; @@ -549,9 +608,9 @@ class NickServCore : public Module, public NickServ::NickServService time_t nickserv_expire = Config->GetModule(this)->Get<time_t>("expire", "21d"); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ) + for (auto it = NickList->begin(); it != NickList->end();) { - NickAlias *na = it->second; + NickServ::Nick *na = it->second; ++it; User *u = User::Find(na->nick); @@ -564,7 +623,7 @@ class NickServCore : public Module, public NickServ::NickServService expire = true; this->onprenickexpire(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire); - + if (expire) { Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (na->nc->email.empty() ? "none" : na->nc->email) << ")"; @@ -574,7 +633,7 @@ class NickServCore : public Module, public NickServ::NickServService } } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override + void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { if (!na->nc->HasExt("UNCONFIRMED")) { @@ -588,6 +647,19 @@ class NickServCore : public Module, public NickServ::NickServService info[_("Expires")] = Anope::strftime(na->time_registered + unconfirmed_expire, source.GetAccount()); } } + + void OnModuleUnload(User *u, Module *m) override + { + for (std::set<NickServ::IdentifyRequest *>::iterator it = identifyrequests.begin(), it_end = identifyrequests.end(); it != it_end;) + { + NickServ::IdentifyRequest *ir = *it; + ++it; + + ir->Release(m); + if (ir->GetOwner() == m) + delete ir; + } + } }; MODULE_INIT(NickServCore) diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index 91d7f1add..2d2d56425 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -27,7 +27,7 @@ class SGLineManager : public XLineManager { ::Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired"; } - + void Send(User *u, XLine *x) override { IRCD->SendAkill(u, x); diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp index d87613ed7..058acc457 100644 --- a/modules/webcpanel/pages/chanserv/access.cpp +++ b/modules/webcpanel/pages/chanserv/access.cpp @@ -12,7 +12,7 @@ WebCPanel::ChanServ::Access::Access(const Anope::string &cat, const Anope::strin { } -bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { TemplateFileServer Page("chanserv/access.html"); const Anope::string &chname = message.get_data["channel"]; @@ -25,7 +25,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s return true; } - ChannelInfo *ci = ChannelInfo::Find(chname); + ::ChanServ::Channel *ci = ::ChanServ::Find(chname); if (!ci) { @@ -34,7 +34,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s return true; } - AccessGroup u_access = ci->AccessFor(na->nc); + ::ChanServ::AccessGroup u_access = ci->AccessFor(na->nc); bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/access/modify"); if (!u_access.HasPriv("ACCESS_LIST") && !has_priv) @@ -46,8 +46,8 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s replacements["ACCESS_LIST"] = "YES"; - const ChanAccess *highest = u_access.Highest(); - + const ::ChanServ::ChanAccess *highest = u_access.Highest(); + if (u_access.HasPriv("ACCESS_CHANGE") || has_priv) { if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) @@ -62,10 +62,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s else if (message.post_data["mask"].empty() == false && message.post_data["access"].empty() == false && message.post_data["provider"].empty() == false) { // Generic access add code here, works with any provider (so we can't call a command exactly) - AccessProvider *a = NULL; - for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it) - if ((*it)->name == message.post_data["provider"]) - a = *it; + ServiceReference<::ChanServ::AccessProvider> a("AccessProvider", "access/" + message.post_data["provider"]); if (a) { @@ -73,7 +70,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { - ChanAccess *acc = ci->GetAccess(i); + ::ChanServ::ChanAccess *acc = ci->GetAccess(i); if (acc->mask == message.post_data["mask"]) { @@ -94,7 +91,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s replacements["MESSAGES"] = "Sorry, you can only have " + stringify(access_max) + " access entries on a channel."; else if (!denied) { - ChanAccess *new_acc = a->Create(); + ::ChanServ::ChanAccess *new_acc = a->Create(); new_acc->ci = ci; new_acc->mask = message.post_data["mask"]; new_acc->creator = na->nc->display; @@ -136,18 +133,16 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { - ChanAccess *access = ci->GetAccess(i); + ::ChanServ::ChanAccess *access = ci->GetAccess(i); replacements["MASKS"] = HTTPUtils::Escape(access->mask); replacements["ACCESSES"] = HTTPUtils::Escape(access->AccessSerialize()); replacements["CREATORS"] = HTTPUtils::Escape(access->creator); } - for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it) - { - const AccessProvider *a = *it; - replacements["PROVIDERS"] = a->name; - } + if (::ChanServ::service) + for (::ChanServ::AccessProvider *p : ::ChanServ::service->GetProviders()) + replacements["PROVIDERS"] = p->name; Page.Serve(server, page_name, client, message, reply, replacements); return true; diff --git a/modules/webcpanel/pages/chanserv/access.h b/modules/webcpanel/pages/chanserv/access.h index 9ff77c486..a22521ada 100644 --- a/modules/webcpanel/pages/chanserv/access.h +++ b/modules/webcpanel/pages/chanserv/access.h @@ -16,7 +16,7 @@ class Access : public WebPanelProtectedPage public: Access(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; std::set<Anope::string> GetData() override; }; diff --git a/modules/webcpanel/pages/chanserv/akick.cpp b/modules/webcpanel/pages/chanserv/akick.cpp index bff38910c..a77995048 100644 --- a/modules/webcpanel/pages/chanserv/akick.cpp +++ b/modules/webcpanel/pages/chanserv/akick.cpp @@ -7,12 +7,13 @@ #include "../../webcpanel.h" #include "utils.h" +#include "modules/cs_akick.h" WebCPanel::ChanServ::Akick::Akick(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) { } -bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { const Anope::string &chname = message.get_data["channel"]; TemplateFileServer Page("chanserv/akick.html"); @@ -25,7 +26,7 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st return true; } - ChannelInfo *ci = ChannelInfo::Find(chname); + ::ChanServ::Channel *ci = ::ChanServ::Find(chname); if (!ci) { @@ -34,7 +35,7 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st return true; } - AccessGroup u_access = ci->AccessFor(na->nc); + ::ChanServ::AccessGroup u_access = ci->AccessFor(na->nc); bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/access/modify"); if (!u_access.HasPriv("AKICK") && !has_priv) @@ -71,14 +72,14 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st for (unsigned i = 0; i < ci->GetAkickCount(); ++i) { - AutoKick *akick = ci->GetAkick(i); + AutoKick *ak = ci->GetAkick(i); - if (akick->nc) - replacements["MASKS"] = HTTPUtils::Escape(akick->nc->display); + if (ak->nc) + replacements["MASKS"] = HTTPUtils::Escape(ak->nc->display); else - replacements["MASKS"] = HTTPUtils::Escape(akick->mask); - replacements["CREATORS"] = HTTPUtils::Escape(akick->creator); - replacements["REASONS"] = HTTPUtils::Escape(akick->reason); + replacements["MASKS"] = HTTPUtils::Escape(ak->mask); + replacements["CREATORS"] = HTTPUtils::Escape(ak->creator); + replacements["REASONS"] = HTTPUtils::Escape(ak->reason); } Page.Serve(server, page_name, client, message, reply, replacements); diff --git a/modules/webcpanel/pages/chanserv/akick.h b/modules/webcpanel/pages/chanserv/akick.h index 938dbde04..0df08d3b3 100644 --- a/modules/webcpanel/pages/chanserv/akick.h +++ b/modules/webcpanel/pages/chanserv/akick.h @@ -16,7 +16,7 @@ class Akick : public WebPanelProtectedPage public: Akick(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; std::set<Anope::string> GetData() override; }; diff --git a/modules/webcpanel/pages/chanserv/drop.cpp b/modules/webcpanel/pages/chanserv/drop.cpp index 5fa37b5a2..c81543c57 100644 --- a/modules/webcpanel/pages/chanserv/drop.cpp +++ b/modules/webcpanel/pages/chanserv/drop.cpp @@ -13,7 +13,7 @@ WebCPanel::ChanServ::Drop::Drop(const Anope::string &cat, const Anope::string &u } -bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { if (message.post_data.count("channel") > 0 && message.post_data.count("confChan") > 0) @@ -31,11 +31,11 @@ bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::str replacements["MESSAGES"] = "Invalid Confirmation"; } - std::deque<ChannelInfo *> queue; + std::deque<::ChanServ::Channel *> queue; na->nc->GetChannelReferences(queue); for (unsigned i = 0; i < queue.size(); ++i) { - ChannelInfo *ci = queue[i]; + ::ChanServ::Channel *ci = queue[i]; if ((ci->HasExt("SECUREFOUNDER") ? ci->AccessFor(na->nc).founder : ci->AccessFor(na->nc).HasPriv("FOUNDER")) || (na->nc->IsServicesOper() && na->nc->o->ot->HasCommand("chanserv/drop"))) { replacements["CHANNEL_NAMES"] = ci->name; diff --git a/modules/webcpanel/pages/chanserv/drop.h b/modules/webcpanel/pages/chanserv/drop.h index 684562453..773dfe789 100644 --- a/modules/webcpanel/pages/chanserv/drop.h +++ b/modules/webcpanel/pages/chanserv/drop.h @@ -16,7 +16,7 @@ namespace WebCPanel public: Drop(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; diff --git a/modules/webcpanel/pages/chanserv/info.cpp b/modules/webcpanel/pages/chanserv/info.cpp index c16c3eaec..725446958 100644 --- a/modules/webcpanel/pages/chanserv/info.cpp +++ b/modules/webcpanel/pages/chanserv/info.cpp @@ -12,7 +12,7 @@ WebCPanel::ChanServ::Info::Info(const Anope::string &cat, const Anope::string &u { } -bool WebCPanel::ChanServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::ChanServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { const Anope::string &chname = message.get_data["channel"]; diff --git a/modules/webcpanel/pages/chanserv/info.h b/modules/webcpanel/pages/chanserv/info.h index 8f70f13b2..2e9888ede 100644 --- a/modules/webcpanel/pages/chanserv/info.h +++ b/modules/webcpanel/pages/chanserv/info.h @@ -16,7 +16,7 @@ class Info : public WebPanelProtectedPage public: Info(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/chanserv/modes.cpp b/modules/webcpanel/pages/chanserv/modes.cpp index f087b86a9..61c170ee2 100644 --- a/modules/webcpanel/pages/chanserv/modes.cpp +++ b/modules/webcpanel/pages/chanserv/modes.cpp @@ -12,7 +12,7 @@ WebCPanel::ChanServ::Modes::Modes(const Anope::string &cat, const Anope::string { } -bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { const Anope::string &chname = message.get_data["channel"]; const Anope::string &mode = message.get_data["m"]; @@ -27,7 +27,7 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st } replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); - ChannelInfo *ci = ChannelInfo::Find(chname); + ::ChanServ::Channel *ci = ::ChanServ::Find(chname); if (!ci) { @@ -44,7 +44,7 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st return true; } - AccessGroup u_access = ci->AccessFor(na->nc); + ::ChanServ::AccessGroup u_access = ci->AccessFor(na->nc); bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/administration"); if (!u_access.HasPriv("MODE") && !has_priv) diff --git a/modules/webcpanel/pages/chanserv/modes.h b/modules/webcpanel/pages/chanserv/modes.h index 5fd69e07f..33197b1f4 100644 --- a/modules/webcpanel/pages/chanserv/modes.h +++ b/modules/webcpanel/pages/chanserv/modes.h @@ -16,7 +16,7 @@ class Modes : public WebPanelProtectedPage public: Modes(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; std::set<Anope::string> GetData() override; }; diff --git a/modules/webcpanel/pages/chanserv/set.cpp b/modules/webcpanel/pages/chanserv/set.cpp index f763ba13b..c2ea480d4 100644 --- a/modules/webcpanel/pages/chanserv/set.cpp +++ b/modules/webcpanel/pages/chanserv/set.cpp @@ -12,7 +12,7 @@ WebCPanel::ChanServ::Set::Set(const Anope::string &cat, const Anope::string &u) { } -bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { const Anope::string &chname = message.get_data["channel"]; bool can_set = false; @@ -26,7 +26,7 @@ bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::stri return true; } - ChannelInfo *ci = ChannelInfo::Find(chname); + ::ChanServ::Channel *ci = ::ChanServ::Find(chname); if (!ci) { diff --git a/modules/webcpanel/pages/chanserv/set.h b/modules/webcpanel/pages/chanserv/set.h index 12c94dcf0..3c6af8adb 100644 --- a/modules/webcpanel/pages/chanserv/set.h +++ b/modules/webcpanel/pages/chanserv/set.h @@ -16,7 +16,7 @@ class Set : public WebPanelProtectedPage public: Set(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; std::set<Anope::string> GetData() override; }; diff --git a/modules/webcpanel/pages/chanserv/utils.cpp b/modules/webcpanel/pages/chanserv/utils.cpp index b4571b74c..f14595a82 100644 --- a/modules/webcpanel/pages/chanserv/utils.cpp +++ b/modules/webcpanel/pages/chanserv/utils.cpp @@ -9,7 +9,7 @@ namespace { - bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2) + bool ChannelSort(ChanServ::Channel *ci1, ChanServ::Channel *ci2) { return ci::less()(ci1->name, ci2->name); } @@ -21,15 +21,15 @@ namespace WebCPanel namespace ChanServ { -void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements) +void BuildChanList(::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { - std::deque<ChannelInfo *> queue; + std::deque<::ChanServ::Channel *> queue; na->nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); for (unsigned i = 0; i < queue.size(); ++i) { - ChannelInfo *ci = queue[i]; + ::ChanServ::Channel *ci = queue[i]; if (na->nc != ci->GetFounder() && ci->AccessFor(na->nc).empty()) continue; diff --git a/modules/webcpanel/pages/chanserv/utils.h b/modules/webcpanel/pages/chanserv/utils.h index 111abb4ad..34e82999f 100644 --- a/modules/webcpanel/pages/chanserv/utils.h +++ b/modules/webcpanel/pages/chanserv/utils.h @@ -11,7 +11,7 @@ namespace WebCPanel namespace ChanServ { -extern void BuildChanList(NickAlias *, TemplateFileServer::Replacements &); +extern void BuildChanList(::NickServ::Nick *, TemplateFileServer::Replacements &); } diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp index ee6356214..605e0082c 100644 --- a/modules/webcpanel/pages/hostserv/request.cpp +++ b/modules/webcpanel/pages/hostserv/request.cpp @@ -7,11 +7,11 @@ #include "../../webcpanel.h" -WebCPanel::HostServ::Request::Request(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage (cat, u) +WebCPanel::HostServ::Request::Request(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage (cat, u) { } -bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { if (message.post_data.count("req") > 0) { diff --git a/modules/webcpanel/pages/hostserv/request.h b/modules/webcpanel/pages/hostserv/request.h index 53e72c1bc..c8a518361 100644 --- a/modules/webcpanel/pages/hostserv/request.h +++ b/modules/webcpanel/pages/hostserv/request.h @@ -16,7 +16,7 @@ class Request : public WebPanelProtectedPage public: Request(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/index.cpp b/modules/webcpanel/pages/index.cpp index 0b2ce3d9c..d2a99becd 100644 --- a/modules/webcpanel/pages/index.cpp +++ b/modules/webcpanel/pages/index.cpp @@ -6,8 +6,9 @@ */ #include "../webcpanel.h" +#include "modules/nickserv.h" -class WebpanelRequest : public IdentifyRequest +class WebpanelRequest : public NickServ::IdentifyRequestListener { HTTPReply reply; HTTPMessage message; @@ -17,16 +18,16 @@ class WebpanelRequest : public IdentifyRequest TemplateFileServer::Replacements replacements; public: - WebpanelRequest(Module *o, HTTPReply &r, HTTPMessage &m, HTTPProvider *s, const Anope::string &p_n, HTTPClient *c, TemplateFileServer::Replacements &re, const Anope::string &user, const Anope::string &pass) : IdentifyRequest(o, user, pass), reply(r), message(m), server(s), page_name(p_n), client(c), replacements(re) { } + WebpanelRequest(HTTPReply &r, HTTPMessage &m, HTTPProvider *s, const Anope::string &p_n, HTTPClient *c, TemplateFileServer::Replacements &re) : reply(r), message(m), server(s), page_name(p_n), client(c), replacements(re) { } - void OnSuccess() override + void OnSuccess(NickServ::IdentifyRequest *req) override { if (!client || !server) return; - NickAlias *na = NickAlias::Find(this->GetAccount()); + ::NickServ::Nick *na = ::NickServ::FindNick(req->GetAccount()); if (!na) { - this->OnFail(); + this->OnFail(req); return; } @@ -50,7 +51,7 @@ class WebpanelRequest : public IdentifyRequest reply.cookies.push_back(c); } - { + { HTTPReply::cookie c; c.push_back(std::make_pair("id", id)); c.push_back(std::make_pair("Path", "/")); @@ -63,7 +64,7 @@ class WebpanelRequest : public IdentifyRequest client->SendReply(&reply); } - void OnFail() override + void OnFail(NickServ::IdentifyRequest *req) override { if (!client || !server) return; @@ -82,11 +83,11 @@ bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page replacements["TITLE"] = page_title; - if (!user.empty() && !pass.empty()) + if (!user.empty() && !pass.empty() && ::NickServ::service) { - // Rate limit check. + // XXX Rate limit check. - WebpanelRequest *req = new WebpanelRequest(me, reply, message, server, page_name, client, replacements, user, pass); + ::NickServ::IdentifyRequest *req = ::NickServ::service->CreateIdentifyRequest(new WebpanelRequest(reply, message, server, page_name, client, replacements), me, user, pass); Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); return false; diff --git a/modules/webcpanel/pages/logout.cpp b/modules/webcpanel/pages/logout.cpp index d9f5432a3..648b277cc 100644 --- a/modules/webcpanel/pages/logout.cpp +++ b/modules/webcpanel/pages/logout.cpp @@ -11,7 +11,7 @@ WebCPanel::Logout::Logout(const Anope::string &u) : WebPanelProtectedPage("", u) { } -bool WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { na->Shrink<Anope::string>("webcpanel_id"); na->Shrink<Anope::string>("webcpanel_ip"); diff --git a/modules/webcpanel/pages/logout.h b/modules/webcpanel/pages/logout.h index f44f3aad5..d3e6cb1ff 100644 --- a/modules/webcpanel/pages/logout.h +++ b/modules/webcpanel/pages/logout.h @@ -13,7 +13,7 @@ class Logout : public WebPanelProtectedPage public: Logout(const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/memoserv/memos.cpp b/modules/webcpanel/pages/memoserv/memos.cpp index 944864cdd..845e7becd 100644 --- a/modules/webcpanel/pages/memoserv/memos.cpp +++ b/modules/webcpanel/pages/memoserv/memos.cpp @@ -11,41 +11,42 @@ WebCPanel::MemoServ::Memos::Memos(const Anope::string &cat, const Anope::string { } -bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { const Anope::string &chname = message.get_data["channel"]; - ChannelInfo *ci; - const MemoInfo *mi; - Memo *m; + ::ChanServ::Channel *ci; + const ::MemoServ::MemoInfo *mi; + ::MemoServ::Memo *m; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) - { - ci = it->second; - - if (ci->AccessFor(na->nc).HasPriv("MEMO")) + if (::ChanServ::service) + for (auto& it : ::ChanServ::service->GetChannels()) { - replacements["CHANNEL_NAMES"] = ci->name; - replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); + ci = it.second; + + if (ci->AccessFor(na->nc).HasPriv("MEMO")) + { + replacements["CHANNEL_NAMES"] = ci->name; + replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); + } } - } if (chname.empty()) { replacements["MESSAGES"] = "No Channel specified, displaying the memos for your Nick"; - mi = &na->nc->memos; + mi = na->nc->memos; } else { - ci = ChannelInfo::Find(chname); + ci = ::ChanServ::Find(chname); if (ci) { replacements["MESSAGES"] = "Displaying the memos for " + chname + "."; - mi = &ci->memos; + mi = ci->memos; } else { replacements["MESSAGES"] = "Channel " + chname + " not found, displaying the memos for your nick"; - mi = &na->nc->memos; + mi = na->nc->memos; } replacements["CHANNEL_NAME"] = ci->name; @@ -84,7 +85,7 @@ bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::st if (number > 0) { - m = mi->GetMemo(number-1); + m = mi ? mi->GetMemo(number-1) : nullptr; if (!m) replacements["MESSAGES"] = "ERROR - invalid memo number."; @@ -95,18 +96,19 @@ bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::st } } - for (unsigned i = 0; i < mi->memos->size(); ++i) - { - m = mi->GetMemo(i); - replacements["NUMBER"] = stringify(i+1); - replacements["SENDER"] = m->sender; - replacements["TIME"] = Anope::strftime(m->time); - replacements["TEXT"] = HTTPUtils::Escape(m->text); - if (m->unread) - replacements["UNREAD"] = "YES"; - else - replacements["UNREAD"] = "NO"; - } + if (mi) + for (unsigned i = 0; i < mi->memos->size(); ++i) + { + m = mi->GetMemo(i); + replacements["NUMBER"] = stringify(i+1); + replacements["SENDER"] = m->sender; + replacements["TIME"] = Anope::strftime(m->time); + replacements["TEXT"] = HTTPUtils::Escape(m->text); + if (m->unread) + replacements["UNREAD"] = "YES"; + else + replacements["UNREAD"] = "NO"; + } TemplateFileServer page("memoserv/memos.html"); page.Serve(server, page_name, client, message, reply, replacements); diff --git a/modules/webcpanel/pages/memoserv/memos.h b/modules/webcpanel/pages/memoserv/memos.h index afe9067b8..e841007d8 100644 --- a/modules/webcpanel/pages/memoserv/memos.h +++ b/modules/webcpanel/pages/memoserv/memos.h @@ -16,7 +16,7 @@ class Memos : public WebPanelProtectedPage public: Memos(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/nickserv/access.cpp b/modules/webcpanel/pages/nickserv/access.cpp index de7809591..59082d307 100644 --- a/modules/webcpanel/pages/nickserv/access.cpp +++ b/modules/webcpanel/pages/nickserv/access.cpp @@ -11,7 +11,7 @@ WebCPanel::NickServ::Access::Access(const Anope::string &cat, const Anope::strin { } -bool WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { if (message.post_data.count("access") > 0) { diff --git a/modules/webcpanel/pages/nickserv/access.h b/modules/webcpanel/pages/nickserv/access.h index 0752fc1b0..ff2caaa69 100644 --- a/modules/webcpanel/pages/nickserv/access.h +++ b/modules/webcpanel/pages/nickserv/access.h @@ -16,7 +16,7 @@ class Access : public WebPanelProtectedPage public: Access(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/nickserv/alist.cpp b/modules/webcpanel/pages/nickserv/alist.cpp index 21e281f5f..04d1d1cd4 100644 --- a/modules/webcpanel/pages/nickserv/alist.cpp +++ b/modules/webcpanel/pages/nickserv/alist.cpp @@ -7,7 +7,7 @@ #include "../../webcpanel.h" -static bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2) +static bool ChannelSort(ChanServ::Channel *ci1, ChanServ::Channel *ci2) { return ci::less()(ci1->name, ci2->name); } @@ -16,9 +16,9 @@ WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string { } -bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { - std::deque<ChannelInfo *> queue; + std::deque<::ChanServ::Channel *> queue; na->nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); @@ -26,7 +26,7 @@ bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::st for (unsigned q = 0; q < queue.size(); ++q) { - ChannelInfo *ci = queue[q]; + ::ChanServ::Channel *ci = queue[q]; if (ci->GetFounder() == na->nc) { @@ -38,10 +38,10 @@ bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::st continue; } - AccessGroup access = ci->AccessFor(na->nc); + ::ChanServ::AccessGroup access = ci->AccessFor(na->nc); if (access.empty()) continue; - + ++chan_count; replacements["NUMBERS"] = stringify(chan_count); diff --git a/modules/webcpanel/pages/nickserv/alist.h b/modules/webcpanel/pages/nickserv/alist.h index ba2ca1a7a..97a02e959 100644 --- a/modules/webcpanel/pages/nickserv/alist.h +++ b/modules/webcpanel/pages/nickserv/alist.h @@ -16,7 +16,7 @@ class Alist : public WebPanelProtectedPage public: Alist(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/nickserv/cert.cpp b/modules/webcpanel/pages/nickserv/cert.cpp index eb86f4bd8..52c5a31a0 100644 --- a/modules/webcpanel/pages/nickserv/cert.cpp +++ b/modules/webcpanel/pages/nickserv/cert.cpp @@ -12,7 +12,7 @@ WebCPanel::NickServ::Cert::Cert(const Anope::string &cat, const Anope::string &u { } -bool WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { if (message.post_data.count("certfp") > 0) { diff --git a/modules/webcpanel/pages/nickserv/cert.h b/modules/webcpanel/pages/nickserv/cert.h index 32c5d1aa9..bf534c739 100644 --- a/modules/webcpanel/pages/nickserv/cert.h +++ b/modules/webcpanel/pages/nickserv/cert.h @@ -16,7 +16,7 @@ class Cert : public WebPanelProtectedPage public: Cert(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp index f8753d83f..1e9e660b4 100644 --- a/modules/webcpanel/pages/nickserv/info.cpp +++ b/modules/webcpanel/pages/nickserv/info.cpp @@ -11,7 +11,7 @@ WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u { } -bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { if (message.post_data.empty() == false) { @@ -110,7 +110,7 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str replacements["KILL_QUICK"]; if (!na->nc->HasExt("KILLPROTECT") && !na->nc->HasExt("KILL_QUICK")) replacements["KILL_OFF"]; - + TemplateFileServer page("nickserv/info.html"); page.Serve(server, page_name, client, message, reply, replacements); return true; diff --git a/modules/webcpanel/pages/nickserv/info.h b/modules/webcpanel/pages/nickserv/info.h index 1b70a3827..b94fe0f6c 100644 --- a/modules/webcpanel/pages/nickserv/info.h +++ b/modules/webcpanel/pages/nickserv/info.h @@ -16,7 +16,7 @@ class Info : public WebPanelProtectedPage public: Info(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/pages/operserv/akill.cpp b/modules/webcpanel/pages/operserv/akill.cpp index e23141915..20633c0f4 100644 --- a/modules/webcpanel/pages/operserv/akill.cpp +++ b/modules/webcpanel/pages/operserv/akill.cpp @@ -11,7 +11,7 @@ WebCPanel::OperServ::Akill::Akill(const Anope::string &cat, const Anope::string { } -bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { static ServiceReference<XLineManager> akills("XLineManager","xlinemanager/sgline"); diff --git a/modules/webcpanel/pages/operserv/akill.h b/modules/webcpanel/pages/operserv/akill.h index 1cabaf205..7367f593f 100644 --- a/modules/webcpanel/pages/operserv/akill.h +++ b/modules/webcpanel/pages/operserv/akill.h @@ -16,7 +16,7 @@ class Akill : public WebPanelProtectedPage public: Akill(const Anope::string &cat, const Anope::string &u); - bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) override; + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, ::NickServ::Nick *, TemplateFileServer::Replacements &) override; }; } diff --git a/modules/webcpanel/static_fileserver.cpp b/modules/webcpanel/static_fileserver.cpp index 21f4e7052..b6ced6461 100644 --- a/modules/webcpanel/static_fileserver.cpp +++ b/modules/webcpanel/static_fileserver.cpp @@ -35,7 +35,7 @@ bool StaticFileServer::OnRequest(HTTPProvider *server, const Anope::string &page char buffer[BUFSIZE]; while ((i = read(fd, buffer, sizeof(buffer))) > 0) reply.Write(buffer, i); - + close(fd); return true; } diff --git a/modules/webcpanel/template_fileserver.cpp b/modules/webcpanel/template_fileserver.cpp index dc950b330..0eba381be 100644 --- a/modules/webcpanel/template_fileserver.cpp +++ b/modules/webcpanel/template_fileserver.cpp @@ -79,7 +79,7 @@ static Anope::string FindReplacement(const TemplateFileServer::Replacements &r, } } } - + TemplateFileServer::Replacements::const_iterator it = r.find(key); if (it != r.end()) return it->second; @@ -110,7 +110,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n buffer[i] = 0; buf += buffer; } - + close(fd); Anope::string finished; @@ -235,7 +235,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n // If the if stack is empty or we are in a true statement bool ifok = IfStack.empty() || IfStack.top(); bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r); - + if (ifok && forok) { const Anope::string &replacement = FindReplacement(r, content.substr(0, f - 1)); @@ -252,7 +252,7 @@ void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_n // If the if stack is empty or we are in a true statement bool ifok = IfStack.empty() || IfStack.top(); bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r); - + if (ifok && forok) finished += buf[j]; } diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp index 17a64529b..077ed5f15 100644 --- a/modules/webcpanel/webcpanel.cpp +++ b/modules/webcpanel/webcpanel.cpp @@ -238,7 +238,7 @@ class ModuleWebCPanel : public Module provider->UnregisterPage(&this->chanserv_drop); provider->UnregisterPage(&this->memoserv_memos); - + provider->UnregisterPage(&this->hostserv_request); provider->UnregisterPage(&this->operserv_akill); @@ -248,7 +248,7 @@ class ModuleWebCPanel : public Module namespace WebPanel { - void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key) + void RunCommand(const Anope::string &user, NickServ::Account *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key) { ServiceReference<Command> cmd("Command", c); if (!cmd) @@ -275,7 +275,7 @@ namespace WebPanel MyComandReply(TemplateFileServer::Replacements &_r, const Anope::string &_k) : re(_r), k(_k) { } - void SendMessage(BotInfo *source, const Anope::string &msg) override + void SendMessage(const MessageSource &, const Anope::string &msg) override { re[k] = msg; } diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h index e03e45ed1..771e6b797 100644 --- a/modules/webcpanel/webcpanel.h +++ b/modules/webcpanel/webcpanel.h @@ -35,7 +35,7 @@ class Panel : public Section, public Service std::vector<Section> sections; - NickAlias *GetNickFromSession(HTTPClient *client, HTTPMessage &msg) + NickServ::Nick *GetNickFromSession(HTTPClient *client, HTTPMessage &msg) { if (!client) return NULL; @@ -45,7 +45,7 @@ class Panel : public Section, public Service if (acc.empty() || id.empty()) return NULL; - NickAlias *na = NickAlias::Find(acc); + NickServ::Nick *na = NickServ::FindNick(acc); if (na == NULL) return NULL; @@ -83,7 +83,7 @@ class WebPanelProtectedPage : public WebPanelPage bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) override final { ServiceReference<Panel> panel("Panel", "webcpanel"); - NickAlias *na; + NickServ::Nick *na; if (!panel || !(na = panel->GetNickFromSession(client, message))) { @@ -134,7 +134,7 @@ class WebPanelProtectedPage : public WebPanelPage return this->OnRequest(provider, page_name, client, message, reply, na, replacements); } - virtual bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) = 0; + virtual bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickServ::Nick *, TemplateFileServer::Replacements &) = 0; /* What get data should be appended to links in the navbar */ virtual std::set<Anope::string> GetData() { return std::set<Anope::string>(); } @@ -151,7 +151,7 @@ namespace WebPanel * @param r Replacements, reply from command goes back here into key * @param key The key to put the replies into r */ - extern void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES"); + extern void RunCommand(const Anope::string &user, NickServ::Account *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES"); } #include "pages/index.h" diff --git a/src/access.cpp b/src/access.cpp deleted file mode 100644 index 26c8dee27..000000000 --- a/src/access.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "service.h" -#include "access.h" -#include "regchannel.h" -#include "users.h" -#include "account.h" -#include "protocol.h" -#include "event.h" - -static struct -{ - Anope::string name; - Anope::string desc; -} descriptions[] = { - {"ACCESS_CHANGE", _("Allowed to modify the access list")}, - {"ACCESS_LIST", _("Allowed to view the access list")}, - {"AKICK", _("Allowed to use the AKICK command")}, - {"ASSIGN", _("Allowed to assign/unassign a bot")}, - {"AUTOHALFOP", _("Automatic halfop upon join")}, - {"AUTOOP", _("Automatic channel operator status upon join")}, - {"AUTOOWNER", _("Automatic owner upon join")}, - {"AUTOPROTECT", _("Automatic protect upon join")}, - {"AUTOVOICE", _("Automatic voice on join")}, - {"BADWORDS", _("Allowed to modify channel badwords list")}, - {"BAN", _("Allowed to ban users")}, - {"FANTASIA", _("Allowed to use fantasy commands")}, - {"FOUNDER", _("Allowed to issue commands restricted to channel founders")}, - {"GETKEY", _("Allowed to use GETKEY command")}, - {"GREET", _("Greet message displayed on join")}, - {"HALFOP", _("Allowed to (de)halfop users")}, - {"HALFOPME", _("Allowed to (de)halfop him/herself")}, - {"INFO", _("Allowed to get full INFO output")}, - {"INVITE", _("Allowed to use the INVITE command")}, - {"KICK", _("Allowed to use the KICK command")}, - {"MEMO", _("Allowed to read channel memos")}, - {"MODE", _("Allowed to use the MODE command")}, - {"NOKICK", _("Prevents users being kicked by Services")}, - {"OP", _("Allowed to (de)op users")}, - {"OPME", _("Allowed to (de)op him/herself")}, - {"OWNER", _("Allowed to (de)owner users")}, - {"OWNERME", _("Allowed to (de)owner him/herself")}, - {"PROTECT", _("Allowed to (de)protect users")}, - {"PROTECTME", _("Allowed to (de)protect him/herself")}, - {"SAY", _("Allowed to use SAY and ACT commands")}, - {"SET", _("Allowed to set channel settings")}, - {"SIGNKICK", _("No signed kick when SIGNKICK LEVEL is used")}, - {"TOPIC", _("Allowed to change channel topics")}, - {"UNBAN", _("Allowed to unban users")}, - {"VOICE", _("Allowed to (de)voice users")}, - {"VOICEME", _("Allowed to (de)voice him/herself")} -}; - -Privilege::Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r) -{ - if (this->desc.empty()) - for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) - if (descriptions[j].name.equals_ci(name)) - this->desc = descriptions[j].desc; -} - -bool Privilege::operator==(const Privilege &other) const -{ - return this->name.equals_ci(other.name); -} - -std::vector<Privilege> PrivilegeManager::Privileges; - -void PrivilegeManager::AddPrivilege(Privilege p) -{ - unsigned i; - for (i = 0; i < Privileges.size(); ++i) - { - Privilege &priv = Privileges[i]; - - if (priv.rank > p.rank) - break; - } - - Privileges.insert(Privileges.begin() + i, p); -} - -void PrivilegeManager::RemovePrivilege(Privilege &p) -{ - std::vector<Privilege>::iterator it = std::find(Privileges.begin(), Privileges.end(), p); - if (it != Privileges.end()) - Privileges.erase(it); - - for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) - { - cit->second->QueueUpdate(); - cit->second->RemoveLevel(p.name); - } -} - -Privilege *PrivilegeManager::FindPrivilege(const Anope::string &name) -{ - for (unsigned i = Privileges.size(); i > 0; --i) - if (Privileges[i - 1].name.equals_ci(name)) - return &Privileges[i - 1]; - return NULL; -} - -std::vector<Privilege> &PrivilegeManager::GetPrivileges() -{ - return Privileges; -} - -void PrivilegeManager::ClearPrivileges() -{ - Privileges.clear(); -} - -AccessProvider::AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) -{ - Providers.push_back(this); -} - -AccessProvider::~AccessProvider() -{ - std::list<AccessProvider *>::iterator it = std::find(Providers.begin(), Providers.end(), this); - if (it != Providers.end()) - Providers.erase(it); -} - -std::list<AccessProvider *> AccessProvider::Providers; - -const std::list<AccessProvider *>& AccessProvider::GetProviders() -{ - return Providers; -} - -ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p) -{ -} - -ChanAccess::~ChanAccess() -{ - if (this->ci) - { - std::vector<ChanAccess *>::iterator it = std::find(this->ci->access->begin(), this->ci->access->end(), this); - if (it != this->ci->access->end()) - this->ci->access->erase(it); - - const NickAlias *na = NickAlias::Find(this->mask); - if (na != NULL) - na->nc->RemoveChannelReference(this->ci); - else - { - ChannelInfo *c = ChannelInfo::Find(this->mask); - if (c) - c->RemoveChannelReference(this->ci->name); - } - } -} - -void ChanAccess::Serialize(Serialize::Data &data) const -{ - data["provider"] << this->provider->name; - data["ci"] << this->ci->name; - data["mask"] << this->mask; - data["creator"] << this->creator; - data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; - data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created; - data["data"] << this->AccessSerialize(); -} - -Serializable* ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string provider, chan; - - data["provider"] >> provider; - data["ci"] >> chan; - - ServiceReference<AccessProvider> aprovider("AccessProvider", provider); - ChannelInfo *ci = ChannelInfo::Find(chan); - if (!aprovider || !ci) - return NULL; - - ChanAccess *access; - if (obj) - access = anope_dynamic_static_cast<ChanAccess *>(obj); - else - access = aprovider->Create(); - access->ci = ci; - data["mask"] >> access->mask; - data["creator"] >> access->creator; - data["last_seen"] >> access->last_seen; - data["created"] >> access->created; - - Anope::string adata; - data["data"] >> adata; - access->AccessUnserialize(adata); - - if (!obj) - ci->AddAccess(access); - return access; -} - -bool ChanAccess::Matches(const User *u, const NickCore *acc, Path &p) const -{ - if (this->nc) - return this->nc == acc; - - if (u) - { - bool is_mask = this->mask.find_first_of("!@?*") != Anope::string::npos; - if (is_mask && Anope::Match(u->nick, this->mask)) - return true; - else if (Anope::Match(u->GetDisplayedMask(), this->mask)) - return true; - } - - if (acc) - { - for (unsigned i = 0; i < acc->aliases->size(); ++i) - { - const NickAlias *na = acc->aliases->at(i); - if (Anope::Match(na->nick, this->mask)) - return true; - } - } - - if (IRCD->IsChannelValid(this->mask)) - { - ChannelInfo *tci = ChannelInfo::Find(this->mask); - if (tci) - { - for (unsigned i = 0; i < tci->GetAccessCount(); ++i) - { - ChanAccess *a = tci->GetAccess(i); - std::pair<const ChanAccess *, const ChanAccess *> pair = std::make_pair(this, a); - - std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(this); - for (; range.first != range.second; ++range.first) - if (range.first->first == pair.first && range.first->second == pair.second) - goto cont; - - p.first.insert(pair); - if (a->Matches(u, acc, p)) - p.second.insert(pair); - - cont:; - } - - return p.second.count(this) > 0; - } - } - - return false; -} - -bool ChanAccess::operator>(const ChanAccess &other) const -{ - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = privs.size(); i > 0; --i) - { - bool this_p = this->HasPriv(privs[i - 1].name), - other_p = other.HasPriv(privs[i - 1].name); - - if (!this_p && !other_p) - continue; - - return this_p && !other_p; - } - - return false; -} - -bool ChanAccess::operator<(const ChanAccess &other) const -{ - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = privs.size(); i > 0; --i) - { - bool this_p = this->HasPriv(privs[i - 1].name), - other_p = other.HasPriv(privs[i - 1].name); - - if (!this_p && !other_p) - continue; - - return !this_p && other_p; - } - - return false; -} - -bool ChanAccess::operator>=(const ChanAccess &other) const -{ - return !(*this < other); -} - -bool ChanAccess::operator<=(const ChanAccess &other) const -{ - return !(*this > other); -} - -AccessGroup::AccessGroup() : std::vector<ChanAccess *>() -{ - this->ci = NULL; - this->nc = NULL; - this->super_admin = this->founder = false; -} - -static bool HasPriv(const AccessGroup &ag, const ChanAccess *access, const Anope::string &name) -{ - EventReturn MOD_RESULT = Event::OnCheckPriv(&Event::CheckPriv::OnCheckPriv, access, name); - if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name)) - { - typedef std::multimap<const ChanAccess *, const ChanAccess *> path; - std::pair<path::const_iterator, path::const_iterator> it = ag.path.second.equal_range(access); - if (it.first != it.second) - /* check all of the paths for this entry */ - for (; it.first != it.second; ++it.first) - { - const ChanAccess *a = it.first->second; - /* if only one path fully matches then we are ok */ - if (HasPriv(ag, a, name)) - return true; - } - else - /* entry is the end of a chain, all entries match, ok */ - return true; - } - - /* entry does not match or none of the chains fully match */ - return false; -} - -bool AccessGroup::HasPriv(const Anope::string &name) const -{ - if (this->super_admin) - return true; - else if (!ci || ci->GetLevel(name) == ACCESS_INVALID) - return false; - - /* Privileges prefixed with auto are understood to be given - * automatically. Sometimes founders want to not automatically - * obtain privileges, so we will let them */ - bool auto_mode = !name.find("AUTO"); - - /* Only grant founder privilege if this isn't an auto mode or if they don't match any entries in this group */ - if ((!auto_mode || this->empty()) && this->founder) - return true; - - EventReturn MOD_RESULT; - MOD_RESULT = Event::OnGroupCheckPriv(&Event::GroupCheckPriv::OnGroupCheckPriv, this, name); - if (MOD_RESULT != EVENT_CONTINUE) - return MOD_RESULT == EVENT_ALLOW; - - for (unsigned i = this->size(); i > 0; --i) - { - ChanAccess *access = this->at(i - 1); - - if (::HasPriv(*this, access, name)) - return true; - } - - return false; -} - -const ChanAccess *AccessGroup::Highest() const -{ - ChanAccess *highest = NULL; - for (unsigned i = 0; i < this->size(); ++i) - if (highest == NULL || *this->at(i) > *highest) - highest = this->at(i); - return highest; -} - -bool AccessGroup::operator>(const AccessGroup &other) const -{ - if (other.super_admin) - return false; - else if (this->super_admin) - return true; - else if (other.founder) - return false; - else if (this->founder) - return true; - - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = privs.size(); i > 0; --i) - { - bool this_p = this->HasPriv(privs[i - 1].name), - other_p = other.HasPriv(privs[i - 1].name); - - if (!this_p && !other_p) - continue; - - return this_p && !other_p; - } - - return false; -} - -bool AccessGroup::operator<(const AccessGroup &other) const -{ - if (this->super_admin) - return false; - else if (other.super_admin) - return true; - else if (this->founder) - return false; - else if (other.founder) - return true; - - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = privs.size(); i > 0; --i) - { - bool this_p = this->HasPriv(privs[i - 1].name), - other_p = other.HasPriv(privs[i - 1].name); - - if (!this_p && !other_p) - continue; - - return !this_p && other_p; - } - - return false; -} - -bool AccessGroup::operator>=(const AccessGroup &other) const -{ - return !(*this < other); -} - -bool AccessGroup::operator<=(const AccessGroup &other) const -{ - return !(*this > other); -} - diff --git a/src/account.cpp b/src/account.cpp deleted file mode 100644 index e58ee1646..000000000 --- a/src/account.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "services.h" -#include "account.h" -#include "modules.h" -#include "users.h" -#include "protocol.h" -#include "regchannel.h" - -std::set<IdentifyRequest *> IdentifyRequest::Requests; - -IdentifyRequest::IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass) : owner(o), account(acc), password(pass), dispatched(false), success(false) -{ - Requests.insert(this); -} - -IdentifyRequest::~IdentifyRequest() -{ - Requests.erase(this); -} - -void IdentifyRequest::Hold(Module *m) -{ - holds.insert(m); -} - -void IdentifyRequest::Release(Module *m) -{ - holds.erase(m); - if (holds.empty() && dispatched) - { - if (!success) - this->OnFail(); - delete this; - } -} - -void IdentifyRequest::Success(Module *m) -{ - if (!success) - { - this->OnSuccess(); - success = true; - } -} - -void IdentifyRequest::Dispatch() -{ - if (holds.empty()) - { - if (!success) - this->OnFail(); - delete this; - } - else - dispatched = true; -} - -void IdentifyRequest::ModuleUnload(Module *m) -{ - for (std::set<IdentifyRequest *>::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end;) - { - IdentifyRequest *ir = *it; - ++it; - - ir->Release(m); - if (ir->owner == m) - delete ir; - } -} diff --git a/src/bots.cpp b/src/bots.cpp index b2feb9c4e..ea0bf4ec3 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -13,16 +13,16 @@ #include "servers.h" #include "protocol.h" #include "xline.h" -#include "regchannel.h" #include "channels.h" #include "config.h" #include "language.h" #include "serialize.h" #include "event.h" +#include "modules/chanserv.h" Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo"); -BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes) +BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Serializable("BotInfo"), channels("ChanServ::Channel"), botmodes(bmodes) { this->lastmsg = this->created = Anope::CurTime; this->introduced = false; @@ -31,7 +31,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A (*BotListByNick)[this->nick] = this; if (!this->uid.empty()) (*BotListByUID)[this->uid] = this; - + Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this); // If we're synchronised with the uplink already, send the bot. @@ -61,9 +61,9 @@ BotInfo::~BotInfo() IRCD->SendSQLineDel(&x); } - for (std::set<ChannelInfo *>::iterator it = this->channels->begin(), it_end = this->channels->end(); it != it_end; ++it) + for (std::set<ChanServ::Channel *>::iterator it = this->channels->begin(), it_end = this->channels->end(); it != it_end; ++it) { - ChannelInfo *ci = *it; + ChanServ::Channel *ci = *it; this->UnAssign(NULL, ci); } @@ -145,12 +145,12 @@ void BotInfo::SetNewNick(const Anope::string &newnick) (*BotListByNick)[this->nick] = this; } -const std::set<ChannelInfo *> &BotInfo::GetChannels() const +const std::set<ChanServ::Channel *> &BotInfo::GetChannels() const { return this->channels; } -void BotInfo::Assign(User *u, ChannelInfo *ci) +void BotInfo::Assign(User *u, ChanServ::Channel *ci) { EventReturn MOD_RESULT; MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this); @@ -159,14 +159,14 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) if (ci->bi) ci->bi->UnAssign(u, ci); - + ci->bi = this; this->channels->insert(ci); Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this); } -void BotInfo::UnAssign(User *u, ChannelInfo *ci) +void BotInfo::UnAssign(User *u, ChanServ::Channel *ci) { EventReturn MOD_RESULT; MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci); diff --git a/src/channels.cpp b/src/channels.cpp index 09b88a7e9..9ba886c30 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -12,20 +12,18 @@ #include "services.h" #include "channels.h" -#include "regchannel.h" #include "logger.h" #include "modules.h" #include "users.h" -#include "bots.h" #include "servers.h" #include "protocol.h" #include "users.h" #include "config.h" -#include "access.h" #include "sockets.h" #include "language.h" #include "uplink.h" #include "event.h" +#include "modules/chanserv.h" channel_map ChannelList; @@ -41,10 +39,6 @@ Channel::Channel(const Anope::string &nname, time_t ts) this->server_modetime = this->chanserv_modetime = 0; this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_ts = this->topic_time = 0; - this->ci = ChannelInfo::Find(this->name); - if (this->ci) - this->ci->c = this; - if (Me && Me->IsSynced()) Log(NULL, this, "create"); @@ -89,7 +83,7 @@ void Channel::Reset() for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) this->SetCorrectModes(it->second->user, true); - + // If the channel is syncing now, do not force a sync due to Reset(), as we are probably iterating over users in Message::SJoin // A sync will come soon if (!syncing) @@ -127,7 +121,7 @@ bool Channel::CheckDelete() */ if (this->syncing) return false; - + /* Permanent channels never get deleted */ if (this->HasMode("PERM")) return false; @@ -332,8 +326,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *cm, c return; } - BotInfo *bi = BotInfo::Find(param); - User *u = bi ? bi : User::Find(param); + User *u = User::Find(param); if (!u) { @@ -368,7 +361,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *cm, c } else this->modes.erase(cm->name); - + if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast<ChannelModeList *>(cm); @@ -393,7 +386,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *cm, c this->CheckModes(); } -void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) +void Channel::SetMode(User *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; @@ -438,12 +431,12 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, SetModeInternal(bi, cm, param, enforce_mlock); } -void Channel::SetMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) +void Channel::SetMode(User *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) { SetMode(bi, ModeManager::FindChannelModeByName(mname), param, enforce_mlock); } -void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) +void Channel::RemoveMode(User *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; @@ -488,7 +481,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶ RemoveModeInternal(bi, cm, realparam, enforce_mlock); } -void Channel::RemoveMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) +void Channel::RemoveMode(User *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) { RemoveMode(bi, ModeManager::FindChannelModeByName(mname), param, enforce_mlock); } @@ -508,7 +501,7 @@ bool Channel::GetParam(const Anope::string &mname, Anope::string &target) const return false; } -void Channel::SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...) +void Channel::SetModes(User *bi, bool enforce_mlock, const char *cmodes, ...) { char buf[BUFSIZE] = ""; va_list args; @@ -688,7 +681,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, Log(setter, this, "mode") << modestring << paramstring; else Log(LOG_DEBUG) << source.GetName() << " is setting " << this->name << " to " << modestring << paramstring; - + if (enforce_mlock) this->CheckModes(); } @@ -710,14 +703,14 @@ bool Channel::MatchesList(User *u, const Anope::string &mode) return false; } -void Channel::KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason) +bool Channel::KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason) { User *sender = source.GetUser(); User *target = User::Find(nick); if (!target) { Log(LOG_DEBUG) << "Channel::KickInternal got a nonexistent user " << nick << " on " << this->name << ": " << reason; - return; + return false; } if (sender) @@ -731,18 +724,23 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic if (cu == NULL) { Log(LOG_DEBUG) << "Channel::KickInternal got kick for user " << target->nick << " from " << source.GetSource() << " who isn't on channel " << this->name; - return; + return false; } Anope::string this_name = this->name; ChannelStatus status = cu->status; - Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason); + EventReturn MOD_RESULT = Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason); + if ((sender && sender->server == Me) || source.GetServer() == Me) + if (MOD_RESULT == EVENT_STOP) + return false; + this->DeleteUser(target); /* This can delete this; */ Event::OnUserKicked(&Event::UserKicked::OnUserKicked, source, target, this_name, status, reason); + return true; } -bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) +bool Channel::Kick(User *source, User *u, const char *reason, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -753,16 +751,13 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) /* Do not kick protected clients or Ulines */ if (u->IsProtected()) return false; - - if (bi == NULL) - bi = this->ci->WhoSends(); - EventReturn MOD_RESULT; - MOD_RESULT = Event::OnBotKick(&Event::BotKick::OnBotKick, bi, this, u, buf); - if (MOD_RESULT == EVENT_STOP) + if (source == NULL) + source = this->ci->WhoSends(); + + if (!this->KickInternal(source, u->nick, buf)) return false; - IRCD->SendKick(bi, this, u, "%s", buf); - this->KickInternal(bi, u->nick, buf); + IRCD->SendKick(source, this, u, "%s", buf); return true; } @@ -800,13 +795,13 @@ void Channel::SetCorrectModes(User *user, bool give_modes) { if (user == NULL) return; - + if (!this->ci) return; Log(LOG_DEBUG) << "Setting correct user modes for " << user->nick << " on " << this->name << " (" << (give_modes ? "" : "not ") << "giving modes)"; - AccessGroup u_access = ci->AccessFor(user); + ChanServ::AccessGroup u_access = ci->AccessFor(user); /* Initially only take modes if the channel is being created by a non netmerge */ bool take_modes = this->syncing && user->server->IsSynced(); @@ -886,7 +881,7 @@ bool Channel::CheckKick(User *user) MOD_RESULT = Event::OnCheckKick(&Event::CheckKick::OnCheckKick, user, this, mask, reason); if (MOD_RESULT != EVENT_STOP) return false; - + if (mask.empty()) mask = this->ci->GetIdealBan(user); if (reason.empty()) diff --git a/src/command.cpp b/src/command.cpp index 5241e9316..16070b221 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -12,14 +12,15 @@ #include "users.h" #include "language.h" #include "config.h" -#include "bots.h" #include "opertype.h" -#include "access.h" -#include "regchannel.h" #include "channels.h" #include "event.h" +#include "bots.h" +#include "protocol.h" +#include "modules/botserv.h" +#include "modules/chanserv.h" -CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), +CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) { } @@ -34,25 +35,25 @@ User *CommandSource::GetUser() return this->u; } -NickCore *CommandSource::GetAccount() +NickServ::Account *CommandSource::GetAccount() { return this->nc; } -AccessGroup CommandSource::AccessFor(ChannelInfo *ci) +ChanServ::AccessGroup CommandSource::AccessFor(ChanServ::Channel *ci) { if (this->u) return ci->AccessFor(this->u); else if (this->nc) return ci->AccessFor(this->nc); else - return AccessGroup(); + return ChanServ::AccessGroup(); } -bool CommandSource::IsFounder(ChannelInfo *ci) +bool CommandSource::IsFounder(ChanServ::Channel *ci) { if (this->u) - return ::IsFounder(this->u, ci); + return ci->IsFounder(this->u); else if (this->nc) return *this->nc == ci->GetFounder(); return false; @@ -116,7 +117,7 @@ void CommandSource::Reply(const Anope::string &message) sepstream sep(translated_message, '\n', true); Anope::string tok; while (sep.GetToken(tok)) - this->reply->SendMessage(this->service, tok); + this->reply->SendMessage(*this->service, tok); } Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(owner) @@ -306,7 +307,7 @@ bool Command::FindCommandFromService(const Anope::string &command_service, BotIn return true; } } - + return false; } diff --git a/src/config.cpp b/src/config.cpp index b2ec7789f..7e918e079 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -12,12 +12,12 @@ #include "services.h" #include "config.h" -#include "bots.h" -#include "access.h" #include "opertype.h" #include "channels.h" #include "hashcomp.h" #include "event.h" +#include "bots.h" +#include "modules/nickserv.h" using namespace Configuration; @@ -37,7 +37,7 @@ int Block::CountBlock(const Anope::string &bname) { if (!this) return 0; - + return blocks.count(bname); } @@ -45,7 +45,7 @@ Block* Block::GetBlock(const Anope::string &bname, int num) { if (!this) return NULL; - + std::pair<block_map::iterator, block_map::iterator> it = blocks.equal_range(bname); for (int i = 0; it.first != it.second; ++it.first, ++i) @@ -280,7 +280,7 @@ Conf::Conf() : Block("") ValidateNotEmpty("oper", "name", nname); ValidateNotEmpty("oper", "type", type); - + OperType *ot = NULL; for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) if (this->MyOperTypes[j]->GetName() == type) @@ -436,18 +436,6 @@ Conf::Conf() : Block("") ci.hide = hide; } - PrivilegeManager::ClearPrivileges(); - for (int i = 0; i < this->CountBlock("privilege"); ++i) - { - Block *privilege = this->GetBlock("privilege", i); - - const Anope::string &nname = privilege->Get<const Anope::string>("name"), - &desc = privilege->Get<const Anope::string>("desc"); - int rank = privilege->Get<int>("rank"); - - PrivilegeManager::AddPrivilege(Privilege(nname, desc, rank)); - } - for (int i = 0; i < this->CountBlock("fantasy"); ++i) { Block *fantasy = this->GetBlock("fantasy", i); @@ -488,24 +476,29 @@ Conf::Conf() : Block("") if (Config) /* Clear existing conf opers */ - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + if (NickServ::service) { - NickCore *nc = it->second; - if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) - nc->o = NULL; + NickServ::nickcore_map& ncmap = NickServ::service->GetAccountList(); + for (auto& it : ncmap) + { + NickServ::Account *nc = it.second; + if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) + nc->o = NULL; + } } /* Apply new opers */ - for (unsigned i = 0; i < this->Opers.size(); ++i) - { - Oper *o = this->Opers[i]; + if (NickServ::service) + for (unsigned i = 0; i < this->Opers.size(); ++i) + { + Oper *o = this->Opers[i]; - NickAlias *na = NickAlias::Find(o->name); - if (!na) - continue; + NickServ::Nick *na = NickServ::service->FindNick(o->name); + if (!na) + continue; - na->nc->o = o; - Log() << "Tied oper " << na->nc->display << " to type " << o->ot->GetName(); - } + na->nc->o = o; + Log() << "Tied oper " << na->nc->display << " to type " << o->ot->GetName(); + } if (options->Get<const Anope::string>("casemap", "ascii") == "ascii") Anope::casemap = std::locale(std::locale(), new Anope::ascii_ctype<char>()); @@ -591,7 +584,7 @@ Block *Conf::GetModule(Module *m) { if (!m) return NULL; - + return GetModule(m->name); } @@ -602,7 +595,7 @@ Block *Conf::GetModule(const Anope::string &mname) return it->second; Block* &block = modules[mname]; - + /* Search for the block */ for (std::pair<block_map::iterator, block_map::iterator> iters = blocks.equal_range("module"); iters.first != iters.second; ++iters.first) { @@ -708,10 +701,10 @@ void Conf::LoadConf(File &file) Log(LOG_DEBUG) << "Start to read conf " << file.GetName(); // Start reading characters... while (!file.End()) - { + { Anope::string line = file.Read(); ++linenumber; - + /* If this line is completely empty and we are in a quote, just append a newline */ if (line.empty() && in_quote) wordbuffer += "\n"; diff --git a/src/event.cpp b/src/event.cpp index c13118dc4..cba56a314 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -28,7 +28,6 @@ EventHandlers<Encrypt> Event::OnEncrypt(nullptr, "OnEncrypt"); EventHandlers<Decrypt> Event::OnDecrypt(nullptr, "OnDecrypt"); EventHandlers<CreateBot> Event::OnCreateBot(nullptr, "OnCreateBot"); EventHandlers<DelBot> Event::OnDelBot(nullptr, "OnDelBot"); -EventHandlers<BotKick> Event::OnBotKick(nullptr, "OnBotKick"); EventHandlers<PrePartChannel> Event::OnPrePartChannel(nullptr, "OnPrePartChannel"); EventHandlers<PartChannel> Event::OnPartChannel(nullptr, "OnPartChannel"); EventHandlers<LeaveChannel> Event::OnLeaveChannel(nullptr, "OnLeaveChannel"); diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 9f48bba29..beaf727ec 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -44,7 +44,7 @@ unsigned char Anope::toupper(unsigned char c) * which is a case-insensitive equivalent to std::string. * */ - + bool ci::ci_char_traits::eq(char c1st, char c2nd) { return case_map_upper[static_cast<unsigned char>(c1st)] == case_map_upper[static_cast<unsigned char>(c2nd)]; diff --git a/src/init.cpp b/src/init.cpp index cd06a5194..d31f79767 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -105,7 +105,7 @@ void Anope::Fork() { #ifndef _WIN32 kill(getppid(), SIGUSR2); - + freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); diff --git a/src/language.cpp b/src/language.cpp index fdfb4c15e..feaa0b242 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -15,6 +15,7 @@ #include "commands.h" #include "config.h" #include "language.h" +#include "modules/nickserv.h" #if GETTEXT_FOUND # include <libintl.h> @@ -69,7 +70,7 @@ const char *Language::Translate(User *u, const char *string) return Translate("", string); } -const char *Language::Translate(const NickCore *nc, const char *string) +const char *Language::Translate(const NickServ::Account *nc, const char *string) { return Translate(nc ? nc->language.c_str() : "", string); } @@ -83,10 +84,10 @@ const char *Language::Translate(const char *lang, const char *string) { if (!string || !*string) return ""; - + if (!lang || !*lang) lang = Config->DefLanguage.c_str(); - + if (Anope::string(lang) == "en") return string; diff --git a/src/logger.cpp b/src/logger.cpp index 1aa530f82..86141ed8a 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -22,6 +22,8 @@ #include "uplink.h" #include "protocol.h" #include "event.h" +#include "modules/nickserv.h" +#include "modules/chanserv.h" #ifndef _WIN32 #include <sys/time.h> @@ -80,11 +82,11 @@ Log::Log(LogType t, const Anope::string &cat, BotInfo *b) : bi(b), u(NULL), nc(N { } -Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t) +Log::Log(LogType t, CommandSource &src, Command *_c, ChanServ::Channel *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t) { if (!c) throw CoreException("Invalid pointers passed to Log::Log"); - + if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN) throw CoreException("This constructor does not support this log type"); @@ -131,7 +133,7 @@ Log::~Log() std::cout << this->BuildPrefix() << this->buf.str() << std::endl; Event::OnLog(&Event::Log::OnLog, this); - + if (Config) for (unsigned i = 0; i < Config->LogInfos.size(); ++i) if (Config->LogInfos[i].HasType(this->type, this->category)) @@ -362,7 +364,7 @@ void LogInfo::ProcessMessage(const Log *l) if (!c) continue; - BotInfo *bi = l->bi; + User *bi = l->bi; if (!bi) bi = this->bot; if (!bi) @@ -379,7 +381,7 @@ void LogInfo::ProcessMessage(const Log *l) } } } - + tm *tm = localtime(&Anope::CurTime); if (tm->tm_mday != this->last_day) { diff --git a/src/mail.cpp b/src/mail.cpp index e514c19ec..342a49a24 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -13,6 +13,9 @@ #include "services.h" #include "mail.h" #include "config.h" +#include "bots.h" +#include "protocol.h" +#include "modules/nickserv.h" Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &a, const Anope::string &s, const Anope::string &m) : Thread(), sendmail_path(Config->GetBlock("mail")->Get<const Anope::string>("sendmailpath")), send_from(sf), mail_to(mailto), addr(a), subject(s), message(m), dont_quote_addresses(Config->GetBlock("mail")->Get<bool>("dontquoteaddresses")), success(false) { @@ -51,13 +54,13 @@ void Mail::Message::Run() SetExitState(); } -bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message) +bool Mail::Send(User *u, NickServ::Account *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message) { if (!nc || !service || subject.empty() || message.empty()) return false; Configuration::Block *b = Config->GetBlock("mail"); - + if (!u) { if (!b->Get<bool>("usemail") || b->Get<const Anope::string>("sendfrom").empty()) @@ -90,7 +93,7 @@ bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &su } } -bool Mail::Send(NickCore *nc, const Anope::string &subject, const Anope::string &message) +bool Mail::Send(NickServ::Account *nc, const Anope::string &subject, const Anope::string &message) { Configuration::Block *b = Config->GetBlock("mail"); if (!b->Get<bool>("usemail") || b->Get<const Anope::string>("sendfrom").empty() || !nc || nc->email.empty() || subject.empty() || message.empty()) diff --git a/src/memos.cpp b/src/memos.cpp deleted file mode 100644 index 8b2816f9a..000000000 --- a/src/memos.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* MemoServ functions. - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "services.h" -#include "modules.h" -#include "service.h" -#include "memo.h" -#include "users.h" -#include "account.h" -#include "regchannel.h" - -Memo::Memo() : Serializable("Memo") -{ - unread = receipt = false; -} - -Memo::~Memo() -{ - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(this->owner, ischan); - if (mi) - { - std::vector<Memo *>::iterator it = std::find(mi->memos->begin(), mi->memos->end(), this); - - if (it != mi->memos->end()) - mi->memos->erase(it); - } -} - -void Memo::Serialize(Serialize::Data &data) const -{ - data["owner"] << this->owner; - data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time; - data["sender"] << this->sender; - data["text"] << this->text; - data["unread"] << this->unread; - data["receipt"] << this->receipt; -} - -Serializable* Memo::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string owner; - - data["owner"] >> owner; - - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(owner, ischan); - if (!mi) - return NULL; - - Memo *m; - if (obj) - m = anope_dynamic_static_cast<Memo *>(obj); - else - m = new Memo(); - - m->owner = owner; - data["time"] >> m->time; - data["sender"] >> m->sender; - data["text"] >> m->text; - data["unread"] >> m->unread; - data["receipt"] >> m->receipt; - - if (obj == NULL) - mi->memos->push_back(m); - return m; -} - -MemoInfo::MemoInfo() : memomax(0), memos("Memo") -{ -} - -Memo *MemoInfo::GetMemo(unsigned index) const -{ - if (index >= this->memos->size()) - return NULL; - Memo *m = (*memos)[index]; - m->QueueUpdate(); - return m; -} - -unsigned MemoInfo::GetIndex(Memo *m) const -{ - for (unsigned i = 0; i < this->memos->size(); ++i) - if (this->GetMemo(i) == m) - return i; - return -1; -} - -void MemoInfo::Del(unsigned index) -{ - if (index >= this->memos->size()) - return; - delete this->GetMemo(index); -} - -bool MemoInfo::HasIgnore(User *u) -{ - for (unsigned i = 0; i < this->ignores.size(); ++i) - if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i]))) - return true; - return false; -} - -MemoInfo *MemoInfo::GetMemoInfo(const Anope::string &target, bool &ischan) -{ - if (!target.empty() && target[0] == '#') - { - ischan = true; - ChannelInfo *ci = ChannelInfo::Find(target); - if (ci != NULL) - return &ci->memos; - } - else - { - ischan = false; - NickAlias *na = NickAlias::Find(target); - if (na != NULL) - return &na->nc->memos; - } - - return NULL; -} - diff --git a/src/messages.cpp b/src/messages.cpp index b4da470bf..8ba37498e 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -21,6 +21,7 @@ #include "servers.h" #include "channels.h" #include "event.h" +#include "bots.h" using namespace Message; @@ -57,7 +58,7 @@ void Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms if (!targ || targ->server != Me || !c || c->FindUser(targ)) return; - + Event::OnInvite(&Event::Invite::OnInvite, source.GetUser(), c, targ); } @@ -115,14 +116,14 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co /* Their TS is newer, don't accept any modes from them */ else if (ts > c->creation_time) keep_their_modes = false; - + /* Update the modes for the channel */ if (keep_their_modes && !modes.empty()) /* If we are syncing, mlock is checked later in Channel::Sync. It is important to not check it here * so that Channel::SetCorrectModes can correctly detect the presence of channel mode +r. */ c->SetModesInternal(source, modes, ts, !c->syncing); - + for (std::list<SJoinUser>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it) { const ChannelStatus &status = it->first; @@ -140,7 +141,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co * they aren't allowed to have (secureops etc). */ c->SetCorrectModes(u, true); - + Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, u, c); } @@ -355,7 +356,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m MOD_RESULT = Event::OnBotPrivmsg(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message); if (MOD_RESULT == EVENT_STOP) return; - + bi->OnMessage(u, message); } } @@ -412,9 +413,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { Oper *o = Oper::opers[i]; - const NickAlias *na = NickAlias::Find(o->name); - if (na) - IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); + IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); } IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); diff --git a/src/misc.cpp b/src/misc.cpp index 7e5121ed6..a68028a70 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -121,7 +121,7 @@ bool NumberList::InvalidRange(const Anope::string &) return true; } -ListFormatter::ListFormatter(NickCore *acc) : nc(acc) +ListFormatter::ListFormatter(NickServ::Account *acc) : nc(acc) { } @@ -215,7 +215,7 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) } } -InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc), longest(0) +InfoFormatter::InfoFormatter(NickServ::Account *acc) : nc(acc), longest(0) { } @@ -312,7 +312,7 @@ time_t Anope::DoTime(const Anope::string &s) return amount; } -Anope::string Anope::Duration(time_t t, const NickCore *nc) +Anope::string Anope::Duration(time_t t, const NickServ::Account *nc) { /* We first calculate everything */ time_t years = t / 31536000; @@ -353,7 +353,7 @@ Anope::string Anope::Duration(time_t t, const NickCore *nc) } } -Anope::string Anope::strftime(time_t t, const NickCore *nc, bool short_output) +Anope::string Anope::strftime(time_t t, const NickServ::Account *nc, bool short_output) { tm tm = *localtime(&t); char buf[BUFSIZE]; @@ -368,7 +368,7 @@ Anope::string Anope::strftime(time_t t, const NickCore *nc, bool short_output) return Anope::string(buf) + " " + Language::Translate(nc, _("(now)")); } -Anope::string Anope::Expires(time_t expires, const NickCore *nc) +Anope::string Anope::Expires(time_t expires, const NickServ::Account *nc) { if (!expires) return Language::Translate(nc, NO_EXPIRE); @@ -644,7 +644,7 @@ Anope::string Anope::VersionBuildString() if (!flags.empty()) s += ", flags " + flags; - + return s; } diff --git a/src/modes.cpp b/src/modes.cpp index c8908820c..cecab9d11 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -15,6 +15,7 @@ #include "channels.h" #include "uplink.h" #include "event.h" +#include "modules/chanserv.h" struct StackerInfo; @@ -42,7 +43,7 @@ struct StackerInfo /* Modes to be deleted */ std::list<std::pair<Mode *, Anope::string> > DelModes; /* Bot this is sent from */ - BotInfo *bi; + User *bi; StackerInfo() : bi(NULL) { } @@ -322,7 +323,7 @@ bool ModeManager::AddUserMode(UserMode *um) { if (ModeManager::FindUserModeByChar(um->mchar) != NULL) return false; - + if (um->name.empty()) { um->name = stringify(++GenericUserModes); @@ -379,14 +380,14 @@ void ModeManager::RemoveUserMode(UserMode *um) { if (!um) return; - + unsigned want = um->mchar; if (want >= ModeManager::UserModes.size()) return; - + if (ModeManager::UserModes[want] != um) return; - + ModeManager::UserModes[want] = NULL; UserModesByName.erase(um->name); @@ -398,14 +399,14 @@ void ModeManager::RemoveChannelMode(ChannelMode *cm) { if (!cm) return; - + unsigned want = cm->mchar; if (want >= ModeManager::ChannelModes.size()) return; - + if (ModeManager::ChannelModes[want] != cm) return; - + ModeManager::ChannelModes[want] = NULL; if (cm->type == MODE_STATUS) @@ -434,7 +435,7 @@ ChannelMode *ModeManager::FindChannelModeByChar(char mode) unsigned want = mode; if (want >= ModeManager::ChannelModes.size()) return NULL; - + return ModeManager::ChannelModes[want]; } @@ -443,7 +444,7 @@ UserMode *ModeManager::FindUserModeByChar(char mode) unsigned want = mode; if (want >= ModeManager::UserModes.size()) return NULL; - + return ModeManager::UserModes[want]; } @@ -468,11 +469,11 @@ char ModeManager::GetStatusChar(char value) unsigned want = value; if (want >= ModeManager::ChannelModes.size()) return 0; - + ChannelMode *cm = ModeManager::ChannelModes[want]; if (cm == NULL || cm->type != MODE_STATUS || cm->mchar == value) return 0; - + return cm->mchar; } @@ -512,7 +513,7 @@ void ModeManager::RebuildStatusModes() std::sort(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), statuscmp); } -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) +void ModeManager::StackerAdd(User *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) { StackerInfo *s = GetInfo(ChannelStackerObjects, c); s->AddMode(cm, Set, Param); @@ -526,7 +527,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, modePipe->Notify(); } -void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) +void ModeManager::StackerAdd(User *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) { StackerInfo *s = GetInfo(UserStackerObjects, u); s->AddMode(um, Set, Param); @@ -671,21 +672,21 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh else this->nick = fh; } - + at = this->host.find('#'); if (at != Anope::string::npos) { this->real = this->host.substr(at + 1); this->host = this->host.substr(0, at); } - + /* If the mask is all *'s it will match anything, so just clear it */ if (this->nick.find_first_not_of("*") == Anope::string::npos) this->nick.clear(); - + if (this->user.find_first_not_of("*") == Anope::string::npos) this->user.clear(); - + if (this->host.find_first_not_of("*") == Anope::string::npos) this->host.clear(); else @@ -769,10 +770,10 @@ bool Entry::Matches(User *u, bool full) const else if (!this->host.empty() && !Anope::Match(u->GetDisplayedHost(), this->host) && !Anope::Match(u->GetCloakedHost(), this->host) && (!full || (!Anope::Match(u->host, this->host) && !Anope::Match(u->ip, this->host)))) ret = false; - + if (!this->real.empty() && !Anope::Match(u->realname, this->real)) ret = false; - + return ret; } diff --git a/src/module.cpp b/src/module.cpp index eabf6c0aa..1b19c976c 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -10,7 +10,6 @@ #include "services.h" #include "modules.h" #include "language.h" -#include "account.h" #ifdef GETTEXT_FOUND # include <libintl.h> @@ -34,7 +33,7 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt if (ModuleManager::FindModule(this->name)) throw CoreException("Module already exists!"); - + if (Anope::NoThird && type & THIRD) throw ModuleException("Third party modules may not be loaded"); @@ -64,7 +63,6 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt Module::~Module() { - IdentifyRequest::ModuleUnload(this); /* Clear any active timers this module has */ TimerManager::DeleteTimersFor(this); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index c70e58ecf..9e27eec26 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -10,7 +10,6 @@ #include "services.h" #include "modules.h" #include "users.h" -#include "regchannel.h" #include "config.h" #include "event.h" @@ -37,7 +36,7 @@ void ModuleManager::CleanupRuntimeDirectory() Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")"; return; } - + for (dirent *dp; (dp = readdir(dirp));) { if (!dp->d_ino) @@ -63,17 +62,17 @@ void ModuleManager::CleanupRuntimeDirectory() static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &output) { Anope::string input = Anope::ModuleDir + "/modules/" + name + ".so"; - + struct stat s; if (stat(input.c_str(), &s) == -1) return MOD_ERR_NOEXIST; else if (!S_ISREG(s.st_mode)) return MOD_ERR_NOEXIST; - + std::ifstream source(input.c_str(), std::ios_base::in | std::ios_base::binary); if (!source.is_open()) return MOD_ERR_NOEXIST; - + char *tmp_output = strdup(output.c_str()); int target_fd = mkstemp(tmp_output); if (target_fd == -1 || close(target_fd) == -1) @@ -86,7 +85,7 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out free(tmp_output); Log(LOG_DEBUG_2) << "Runtime module location: " << output; - + std::ofstream target(output.c_str(), std::ios_base::in | std::ios_base::binary); if (!target.is_open()) { @@ -104,7 +103,7 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out target.write(buffer, read_len); want -= read_len; } - + source.close(); target.close(); @@ -339,7 +338,7 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) if (!filename.empty()) unlink(filename.c_str()); #endif - + return MOD_ERR_OK; } @@ -353,7 +352,7 @@ void ModuleManager::UnloadAll() if ((m->type & j) == m->type) modules.push_back(m->name); } - + for (unsigned i = 0; i < modules.size(); ++i) { Module *m = FindModule(modules[i]); diff --git a/src/process.cpp b/src/process.cpp index 2308dc47d..70849243b 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -14,7 +14,6 @@ #include "protocol.h" #include "servers.h" #include "users.h" -#include "regchannel.h" #include "event.h" void Anope::Process(const Anope::string &buffer) @@ -37,7 +36,7 @@ void Anope::Process(const Anope::string &buffer) Anope::string command; if (!buf_sep.GetToken(command)) return; - + Anope::string buf_token; std::vector<Anope::string> params; while (buf_sep.GetToken(buf_token)) @@ -69,7 +68,7 @@ void Anope::Process(const Anope::string &buffer) static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : ""; MessageSource src(source); - + EventReturn MOD_RESULT; MOD_RESULT = Event::OnMessage(&Event::Message::OnMessage, src, command, params); if (MOD_RESULT == EVENT_STOP) diff --git a/src/protocol.cpp b/src/protocol.cpp index b90c44400..d8fd9dc79 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -311,14 +311,14 @@ bool IRCDProto::IsNickValid(const Anope::string &nick) if (nick.empty()) return false; - + Anope::string special = "[]\\`_^{|}"; - + for (unsigned i = 0; i < nick.length(); ++i) if (!(nick[i] >= 'A' && nick[i] <= 'Z') && !(nick[i] >= 'a' && nick[i] <= 'z') && special.find(nick[i]) == Anope::string::npos && (!i || (!(nick[i] >= '0' && nick[i] <= '9') && nick[i] != '-'))) return false; - + return true; } diff --git a/src/serialize.cpp b/src/serialize.cpp index 0cb6ec196..a24f6d0e3 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -15,11 +15,8 @@ #include "anope.h" #include "serialize.h" #include "modules.h" -#include "account.h" #include "bots.h" -#include "regchannel.h" #include "xline.h" -#include "access.h" #include "event.h" using namespace Serialize; @@ -30,9 +27,8 @@ std::list<Serializable *> *Serializable::SerializableItems; void Serialize::RegisterTypes() { - static Type nc("NickCore", NickCore::Unserialize), na("NickAlias", NickAlias::Unserialize), bi("BotInfo", BotInfo::Unserialize), - ci("ChannelInfo", ChannelInfo::Unserialize), access("ChanAccess", ChanAccess::Unserialize), - akick("AutoKick", AutoKick::Unserialize), memo("Memo", Memo::Unserialize), xline("XLine", XLine::Unserialize); + static Type bi("BotInfo", BotInfo::Unserialize), + xline("XLine", XLine::Unserialize); } void Serialize::CheckTypes() diff --git a/src/servers.cpp b/src/servers.cpp index 5e55d4c28..c4cb3665e 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -15,11 +15,11 @@ #include "xline.h" #include "servers.h" #include "bots.h" -#include "regchannel.h" #include "protocol.h" #include "config.h" #include "channels.h" #include "event.h" +#include "modules/chanserv.h" /* Anope */ Server *Me = NULL; @@ -82,7 +82,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano } IRCD->SendBOB(); - + for (unsigned i = 0; i < Me->GetLinks().size(); ++i) { Server *s = Me->GetLinks()[i]; @@ -159,7 +159,7 @@ Server::~Server() for (unsigned i = this->links.size(); i > 0; --i) this->links[i - 1]->Delete(this->quit_reason); - + Servers::ByName.erase(this->name); if (!this->sid.empty()) Servers::ByID.erase(this->sid); @@ -338,18 +338,18 @@ void Server::Notice(BotInfo *source, const Anope::string &message) Server *Server::Find(const Anope::string &name, bool name_only) { Anope::map<Server *>::iterator it; - + if (!name_only) { it = Servers::ByID.find(name); if (it != Servers::ByID.end()) return it->second; } - + it = Servers::ByName.find(name); if (it != Servers::ByName.end()) return it->second; - + return NULL; } diff --git a/src/socket_transport.cpp b/src/socket_transport.cpp index 1476d0662..515d7f9a9 100644 --- a/src/socket_transport.cpp +++ b/src/socket_transport.cpp @@ -33,7 +33,7 @@ bool BufferedSocket::ProcessRead() return false; if (len < 0) return SocketEngine::IgnoreErrno(); - + tbuffer[len] = 0; this->read_buffer.append(tbuffer); this->recv_len = len; @@ -131,7 +131,7 @@ bool BinarySocket::ProcessRead() int len = this->io->Recv(this, tbuffer, sizeof(tbuffer)); if (len <= 0) return false; - + return this->Read(tbuffer, len); } diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index 8fe8d46a4..3c0c22f40 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -28,7 +28,7 @@ void SocketEngine::Init() if (EngineHandle == -1) throw SocketException("Could not initialize epoll socket engine: " + Anope::LastError()); - + events.resize(DefaultSize); } @@ -46,7 +46,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) bool before_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; s->flags[flag] = set; - + bool now_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; epoll_event ev; @@ -65,7 +65,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) mod = EPOLL_CTL_MOD; else return; - + if (epoll_ctl(EngineHandle, mod, ev.data.fd, &ev) == -1) throw SocketException("Unable to epoll_ctl() fd " + stringify(ev.data.fd) + " to epoll: " + Anope::LastError()); } diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index 977b84b96..5c5c99afe 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -39,7 +39,7 @@ void SocketEngine::Init() if (kq_fd < 0) throw SocketException("Unable to create kqueue engine: " + Anope::LastError()); - + change_events.resize(DefaultSize); event_events.resize(DefaultSize); } @@ -56,7 +56,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) return; s->flags[flag] = set; - + int mod; if (flag == SF_READABLE) mod = EVFILT_READ; diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 944322c27..422959df2 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -113,7 +113,7 @@ void SocketEngine::Process() for (unsigned i = 0, processed = 0; i < events.size() && processed != static_cast<unsigned>(total); ++i) { pollfd *ev = &events[i]; - + if (ev->revents != 0) ++processed; diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index aab84e958..f1f4fb8d8 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -46,7 +46,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) bool before_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; s->flags[flag] = set; - + bool now_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; if (!before_registered && now_registered) diff --git a/src/sockets.cpp b/src/sockets.cpp index f047c5f44..5d84d1a3f 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -277,7 +277,7 @@ bool cidr::operator<(const cidr &other) const { if (this->addr.sa.sa_family != other.addr.sa.sa_family) return this->addr.sa.sa_family < other.addr.sa.sa_family; - + switch (this->addr.sa.sa_family) { case AF_INET: diff --git a/src/tools/anopesmtp.cpp b/src/tools/anopesmtp.cpp index 6ef8e6baf..04aaedc98 100644 --- a/src/tools/anopesmtp.cpp +++ b/src/tools/anopesmtp.cpp @@ -417,7 +417,7 @@ int main(int argc, char *argv[]) if (argc == 1) return 0; - + if (argc == 3 && !strcmp(argv[2], "--debug")) smtp_debug = 1; diff --git a/src/uplink.cpp b/src/uplink.cpp index 12b6c94f9..2f7a03ebd 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -16,6 +16,7 @@ #include "protocol.h" #include "servers.h" #include "event.h" +#include "bots.h" UplinkSocket *UplinkSock = NULL; diff --git a/src/users.cpp b/src/users.cpp index 560536ce4..3b874c0f2 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -14,7 +14,6 @@ #include "services.h" #include "modules.h" #include "users.h" -#include "account.h" #include "protocol.h" #include "servers.h" #include "channels.h" @@ -25,6 +24,7 @@ #include "sockets.h" #include "uplink.h" #include "event.h" +#include "modules/nickserv.h" user_map UserListByNick, UserListByUID; @@ -34,7 +34,7 @@ time_t MaxUserTime = 0; std::list<User *> User::quitting_users; -User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account) +User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *account) { if (snick.empty() || sident.empty() || shost.empty()) throw CoreException("Bad args passed to User::User"); @@ -114,7 +114,7 @@ static void Collide(User *u, const Anope::string &id, const Anope::string &type) CollideKill(u, type); } -User* User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc) +User* User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *nc) { // How IRCds handle collisions varies a lot, for safety well just always kill both sides // With properly set qlines, this can almost never happen anyway @@ -144,7 +144,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) /* Sanity check to make sure we don't segfault */ if (newnick.empty()) throw CoreException("User::ChangeNick() got a bad argument"); - + this->super_admin = false; Log(this, "nick") << "(" << this->realname << ") changed nick to " << newnick; @@ -155,10 +155,13 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) this->nick = newnick; else { - NickAlias *old_na = NickAlias::Find(this->nick); - if (old_na && (this->IsIdentified(true) || this->IsRecognized())) - old_na->last_seen = Anope::CurTime; - + if (NickServ::service) + { + NickServ::Nick *old_na = NickServ::service->FindNick(this->nick); + if (old_na && (this->IsIdentified(true) || this->IsRecognized())) + old_na->last_seen = Anope::CurTime; + } + UserListByNick.erase(this->nick); this->nick = newnick; @@ -173,14 +176,19 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) other = this; on_access = false; - NickAlias *na = NickAlias::Find(this->nick); - if (na) - on_access = na->nc->IsOnAccess(this); - - if (na && na->nc == this->Account()) + if (NickServ::service) { - na->last_seen = Anope::CurTime; - this->UpdateHost(); + NickServ::Nick *na = NickServ::service->FindNick(this->nick); + if (na) + { + on_access = na->nc->IsOnAccess(this); + + if (na->nc == this->Account()) + { + na->last_seen = Anope::CurTime; + this->UpdateHost(); + } + } } } @@ -283,10 +291,14 @@ void User::SetRealname(const Anope::string &srealname) throw CoreException("realname empty in SetRealname"); this->realname = srealname; - NickAlias *na = NickAlias::Find(this->nick); + if (NickServ::service) + { + //XXX event + NickServ::Nick *na = NickServ::service->FindNick(this->nick); - if (na && (this->IsIdentified(true) || this->IsRecognized())) - na->last_realname = srealname; + if (na && (this->IsIdentified(true) || this->IsRecognized())) + na->last_realname = srealname; + } Log(this, "realname") << "changed realname to " << srealname; } @@ -318,7 +330,7 @@ User::~User() Event::OnPostUserLogoff(&Event::PostUserLogoff::OnPostUserLogoff, this); } -void User::SendMessage(BotInfo *source, const char *fmt, ...) +void User::SendMessage(const MessageSource &source, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -333,7 +345,7 @@ void User::SendMessage(BotInfo *source, const char *fmt, ...) va_end(args); } -void User::SendMessage(BotInfo *source, const Anope::string &msg) +void User::SendMessage(const MessageSource &source, const Anope::string &msg) { const char *translated_message = Language::Translate(this, msg.c_str()); @@ -353,7 +365,7 @@ void User::SendMessage(BotInfo *source, const Anope::string &msg) } } -void User::Identify(NickAlias *na) +void User::Identify(NickServ::Nick *na) { if (this->nick.equals_ci(na->nick)) { @@ -374,14 +386,14 @@ void User::Identify(NickAlias *na) if (!this->nc->o->ot->modes.empty()) { this->SetModes(NULL, "%s", this->nc->o->ot->modes.c_str()); - this->SendMessage(NULL, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str()); + this->SendMessage(Me, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str()); UserMode *um = ModeManager::FindUserModeByName("OPER"); if (um && !this->HasMode("OPER") && this->nc->o->ot->modes.find(um->mchar) != Anope::string::npos) IRCD->SendOper(this); } if (IRCD->CanSetVHost && !this->nc->o->vhost.empty()) { - this->SendMessage(NULL, "Changing your vhost to \002%s\002", this->nc->o->vhost.c_str()); + this->SendMessage(Me, "Changing your vhost to \002%s\002", this->nc->o->vhost.c_str()); this->SetDisplayedHost(this->nc->o->vhost); IRCD->SendVhost(this, "", this->nc->o->vhost); } @@ -389,7 +401,7 @@ void User::Identify(NickAlias *na) } -void User::Login(NickCore *core) +void User::Login(NickServ::Account *core) { if (!core || core == this->nc) return; @@ -402,7 +414,7 @@ void User::Login(NickCore *core) if (this->server->IsSynced()) Log(this, "account") << "is now identified as " << this->nc->display; - + Event::OnUserLogin(&Event::UserLogin::OnUserLogin, this); } @@ -410,7 +422,7 @@ void User::Logout() { if (!this->nc) return; - + Log(this, "account") << "is no longer identified as " << this->nc->display; std::list<User *>::iterator it = std::find(this->nc->users.begin(), this->nc->users.end(), this); @@ -420,7 +432,7 @@ void User::Logout() this->nc = NULL; } -NickCore *User::Account() const +NickServ::Account *User::Account() const { return this->nc; } @@ -429,7 +441,7 @@ bool User::IsIdentified(bool check_nick) const { if (check_nick && this->nc) { - NickAlias *na = NickAlias::Find(this->nick); + NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr; return na && *na->nc == *this->nc; } @@ -440,7 +452,7 @@ bool User::IsRecognized(bool check_secure) const { if (check_secure && on_access) { - const NickAlias *na = NickAlias::Find(this->nick); + const NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr; if (!na || na->nc->HasExt("NS_SECURE")) return false; @@ -497,7 +509,8 @@ void User::UpdateHost() if (this->host.empty()) return; - NickAlias *na = NickAlias::Find(this->nick); + //XXX event + NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr; on_access = false; if (na) on_access = na->nc->IsOnAccess(this); diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h index 8d6e7ef9e..f2a496c33 100644 --- a/src/win32/anope_windows.h +++ b/src/win32/anope_windows.h @@ -8,7 +8,7 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. */ - + #ifndef WINDOWS_H #define WINDOWS_H #ifdef _WIN32 @@ -71,7 +71,7 @@ namespace Anope { class string; } - + extern CoreExport void OnStartup(); extern CoreExport void OnShutdown(); extern CoreExport USHORT WindowsGetLanguage(const char *lang); diff --git a/src/win32/dir/dir.cpp b/src/win32/dir/dir.cpp index 21b80824b..16809bd9c 100644 --- a/src/win32/dir/dir.cpp +++ b/src/win32/dir/dir.cpp @@ -7,7 +7,7 @@ #include "dir.h" #include <stdio.h> - + DIR *opendir(const char *path) { char real_path[MAX_PATH]; diff --git a/src/win32/dir/dir.h b/src/win32/dir/dir.h index 5ddf71e7b..4d1433658 100644 --- a/src/win32/dir/dir.h +++ b/src/win32/dir/dir.h @@ -20,7 +20,7 @@ struct DIR WIN32_FIND_DATA data; bool read_first; }; - + DIR *opendir(const char *); dirent *readdir(DIR *); int closedir(DIR *); diff --git a/src/win32/pipe/pipe.cpp b/src/win32/pipe/pipe.cpp index 706ff655e..676909b9a 100644 --- a/src/win32/pipe/pipe.cpp +++ b/src/win32/pipe/pipe.cpp @@ -55,7 +55,7 @@ int pipe(int fds[2]) fds[0] = cfd; fds[1] = afd; - + return 0; } diff --git a/src/win32/resource.h b/src/win32/resource.h index cccb0b4f5..e4fa54b70 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -8,7 +8,7 @@ // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 diff --git a/src/win32/sigaction/sigaction.cpp b/src/win32/sigaction/sigaction.cpp index d5a2d87d1..51615cf39 100644 --- a/src/win32/sigaction/sigaction.cpp +++ b/src/win32/sigaction/sigaction.cpp @@ -7,11 +7,11 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. */ - + #include <windows.h> #include "sigaction.h" #include <signal.h> - + int sigaction(int sig, struct sigaction *action, struct sigaction *old) { if (sig == -1) @@ -28,4 +28,3 @@ } return 0; } -
\ No newline at end of file diff --git a/src/win32/sigaction/sigaction.h b/src/win32/sigaction/sigaction.h index 0e9c2f246..9e74eeffa 100644 --- a/src/win32/sigaction/sigaction.h +++ b/src/win32/sigaction/sigaction.h @@ -7,22 +7,22 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. */ - + #define sigemptyset(x) memset((x), 0, sizeof(*(x))) - + #ifndef SIGHUP # define SIGHUP -1 #endif #ifndef SIGPIPE # define SIGPIPE -1 #endif - + struct sigaction { void (*sa_handler)(int); int sa_flags; int sa_mask; }; - + extern int sigaction(int, struct sigaction *, struct sigaction *); - + diff --git a/src/win32/socket.cpp b/src/win32/socket.cpp index d481515d3..320e46f48 100644 --- a/src/win32/socket.cpp +++ b/src/win32/socket.cpp @@ -85,7 +85,7 @@ int windows_inet_pton(int af, const char *src, void *dst) } return 1; } - + return 0; } diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp index a9e0521d0..319bebf58 100644 --- a/src/win32/windows.cpp +++ b/src/win32/windows.cpp @@ -68,10 +68,10 @@ int gettimeofday(timeval *tv, void *) { SYSTEMTIME st; GetSystemTime(&st); - + tv->tv_sec = Anope::CurTime; tv->tv_usec = st.wMilliseconds; - + return 0; } @@ -243,7 +243,7 @@ int mkstemp(char *input) errno = EEXIST; return -1; } - + int fd = open(input, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE); return fd; } |