From f29e1cf383529a1a29f02b0669d973f5ee0b7a66 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 28 May 2014 12:07:29 -0400 Subject: Move most of the core pseudoclient logic to modules --- include/access.h | 169 ------------ include/account.h | 279 -------------------- include/anope.h | 10 +- include/bots.h | 10 +- include/channels.h | 17 +- include/commands.h | 12 +- include/config.h | 2 - include/defs.h | 26 +- include/event.h | 70 ++--- include/language.h | 4 +- include/lists.h | 8 +- include/logger.h | 6 +- include/mail.h | 4 +- include/memo.h | 53 ---- include/messages.h | 68 ++--- include/modes.h | 6 +- include/module.h | 9 +- include/modules/botserv.h | 22 ++ include/modules/bs_badwords.h | 4 +- include/modules/bs_info.h | 2 +- include/modules/bs_kick.h | 4 +- include/modules/chanserv.h | 595 +++++++++++++++++++++++++++++++++++++++++- include/modules/cs_access.h | 2 +- include/modules/cs_akick.h | 34 ++- include/modules/cs_drop.h | 2 +- include/modules/cs_info.h | 2 +- include/modules/cs_mode.h | 4 +- include/modules/cs_set.h | 2 +- include/modules/dns.h | 42 +-- include/modules/fantasy.h | 4 +- include/modules/hs_del.h | 2 +- include/modules/memoserv.h | 58 +++- include/modules/nickserv.h | 288 +++++++++++++++++++- include/modules/ns_cert.h | 16 +- include/modules/ns_drop.h | 2 +- include/modules/ns_group.h | 2 +- include/modules/ns_info.h | 2 +- include/modules/ns_set.h | 2 +- include/modules/os_ignore.h | 2 +- include/modules/os_news.h | 6 +- include/modules/os_session.h | 2 +- include/modules/redis.h | 2 +- include/modules/sasl.h | 20 +- include/modules/ssl.h | 2 +- include/modules/suspend.h | 8 +- include/modules/xmlrpc.h | 2 +- include/opertype.h | 5 +- include/protocol.h | 4 +- include/regchannel.h | 246 ----------------- include/users.h | 19 +- include/version.cpp | 2 +- 51 files changed, 1187 insertions(+), 977 deletions(-) delete mode 100644 include/access.h delete mode 100644 include/account.h delete mode 100644 include/memo.h create mode 100644 include/modules/botserv.h delete mode 100644 include/regchannel.h (limited to 'include') 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 Privileges; - public: - static void AddPrivilege(Privilege p); - static void RemovePrivilege(Privilege &p); - static Privilege *FindPrivilege(const Anope::string &name); - static std::vector &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 Providers; - public: - static const std::list& GetProviders(); -}; - -/* Represents one entry of an access list on a channel. */ -class CoreExport ChanAccess : public Serializable -{ - public: - typedef std::multimap 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 Path; - - /* The provider that created this access entry */ - AccessProvider *provider; - /* Channel this access entry is on */ - Serialize::Reference ci; - /* account this access entry is for, if any */ - Serialize::Reference 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 -{ - 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_map; -typedef Anope::hash_map nickcore_map; - -extern CoreExport Serialize::Checker NickAliasList; -extern CoreExport Serialize::Checker 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 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 > 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 access; - MemoInfo memos; - std::map last_modes; - - /* Nicknames registered that are grouped to this account. - * for n in aliases, n->nc == this. - */ - Serialize::Checker > 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 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 &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 holds; - bool dispatched; - bool success; - - static std::set 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_map; +typedef Anope::hash_map botinfo_map; extern CoreExport Serialize::Checker BotListByNick, BotListByUID; @@ -23,7 +23,7 @@ extern CoreExport Serialize::Checker BotListByNick, BotListByUID; class CoreExport BotInfo : public User, public Serializable { /* Channels this bot is assigned to */ - Serialize::Checker > channels; + Serialize::Checker > 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 &GetChannels() const; + const std::set &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 ci; + Serialize::Reference 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 u; public: /* The account executing the command */ - Reference nc; + Reference 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 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 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 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 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 OnBotUnAssign; @@ -297,19 +298,6 @@ namespace Event }; extern CoreExport EventHandlers 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 ListEntry; private: - NickCore *nc; + NickServ::Account *nc; std::vector columns; std::vector 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 > replies; unsigned longest; public: - InfoFormatter(NickCore *nc); + InfoFormatter(NickServ::Account *nc); void Process(std::vector &); 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 > memos; - std::vector 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 ¶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 ¶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 ¶ms) override; }; @@ -47,15 +47,15 @@ namespace Message void Run(MessageSource &source, const std::vector ¶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 ¶ms) override; - + typedef std::pair 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 &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 ¶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 ¶ms) override; }; @@ -86,14 +86,14 @@ namespace Message void Run(MessageSource &source, const std::vector ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 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 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; + + 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 &GetPrivileges() anope_abstract; + virtual void ClearPrivileges() anope_abstract; + + virtual std::vector& GetProviders() anope_abstract; + + virtual void Destruct(ChanAccess *) anope_abstract; + virtual void Serialize(const ChanAccess *, Serialize::Data &data) anope_abstract; + //XXX + typedef std::multimap Set; + typedef std::pair Path; + virtual bool Matches(const ChanAccess *, const User *u, const NickServ::Account *acc, Path &p) anope_abstract; }; static ServiceReference 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 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 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 references; + Serialize::Reference founder; /* Channel founder */ + Serialize::Reference successor; /* Who gets the channel if the founder nick is dropped or expires */ + Serialize::Checker > access; /* List of authorized users */ + Serialize::Checker > akick; /* List of users to kickban */ + Anope::map 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 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 + */