diff options
| author | Adam <Adam@anope.org> | 2014-05-28 12:07:29 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-05-28 12:07:54 -0400 |
| commit | f29e1cf383529a1a29f02b0669d973f5ee0b7a66 (patch) | |
| tree | 3c33db276dc9328235bbd572641521ed44458176 /include | |
| parent | 1253c70e0682fa1490c99c3d2869049a0e3fa2e0 (diff) | |
Move most of the core pseudoclient logic to modules
Diffstat (limited to 'include')
51 files changed, 1187 insertions, 977 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; /* Wh |
