diff options
| author | Adam <Adam@anope.org> | 2014-04-20 14:35:14 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-04-20 14:35:14 -0400 |
| commit | 26ac315192e0d8a04d50e910697ab794eedf0cc1 (patch) | |
| tree | b9916f14fe35ce5c4de95c4194ca4ea0cb30812f | |
| parent | 0b6476f06ff9ce06545c421143c7d7163c750aa5 (diff) | |
New event system
222 files changed, 3951 insertions, 2138 deletions
diff --git a/include/base.h b/include/base.h index a28695c5f..ad2b3cee6 100644 --- a/include/base.h +++ b/include/base.h @@ -32,13 +32,14 @@ class CoreExport Base class ReferenceBase { - protected: - bool invalid; + static std::set<ReferenceBase *> *references; public: - ReferenceBase() : invalid(false) { } - ReferenceBase(const ReferenceBase &other) : invalid(other.invalid) { } - virtual ~ReferenceBase() { } - inline void Invalidate() { this->invalid = true; } + static void ResetAll(); + + ReferenceBase(); + virtual ~ReferenceBase(); + virtual void Invalidate() anope_abstract; + virtual void Reset() { } }; /** Used to hold pointers to objects that may be deleted. A Reference will @@ -49,8 +50,11 @@ class Reference : public ReferenceBase { protected: T *ref; + + virtual void Check() { } + public: - Reference() : ref(NULL) + Reference() : ref(nullptr) { } @@ -60,19 +64,24 @@ class Reference : public ReferenceBase ref->AddReference(this); } - Reference(const Reference<T> &other) : ReferenceBase(other), ref(other.ref) + Reference(const Reference<T> &other) : ref(other.ref) { - if (operator bool()) + if (ref) ref->AddReference(this); } virtual ~Reference() { - if (operator bool()) - ref->DelReference(this); + if (*this) + this->ref->DelReference(this); } - inline Reference<T>& operator=(const Reference<T> &other) + void Invalidate() override + { + ref = nullptr; + } + + Reference<T>& operator=(const Reference<T> &other) { if (this != &other) { @@ -80,7 +89,6 @@ class Reference : public ReferenceBase this->ref->DelReference(this); this->ref = other.ref; - this->invalid = other.invalid; if (*this) this->ref->AddReference(this); @@ -88,36 +96,31 @@ class Reference : public ReferenceBase return *this; } - /* We explicitly call operator bool here in several places to prevent other - * operators, such operator T*, from being called instead, which will mess - * with any class inheriting from this that overloads this operator. - */ - virtual operator bool() + explicit operator bool() { - if (!this->invalid) - return this->ref != NULL; - return false; + Check(); + return this->ref != nullptr; } - inline operator T*() + operator T*() { - if (operator bool()) + if (*this) return this->ref; - return NULL; + return nullptr; } - inline T* operator->() + T* operator->() { - if (operator bool()) + if (*this) return this->ref; - return NULL; + return nullptr; } - inline T* operator*() + T* operator*() { - if (operator bool()) + if (*this) return this->ref; - return NULL; + return nullptr; } /** Note that we can't have an operator< that returns this->ref < other.ref @@ -132,9 +135,9 @@ class Reference : public ReferenceBase * actually referred to. */ - inline bool operator==(const Reference<T> &other) + bool operator==(const Reference<T> &other) { - if (!this->invalid) + if (*this) return this->ref == other; return false; } diff --git a/include/defs.h b/include/defs.h index 3d8ebf4ff..b53e512d6 100644 --- a/include/defs.h +++ b/include/defs.h @@ -14,7 +14,6 @@ class AccessGroup; class AutoKick; class BotInfo; -class CallBack; class ChanAccess; class Channel; class ChannelInfo; @@ -25,7 +24,6 @@ class Command; class CommandSource; namespace Configuration { struct Conf; } class ConnectionSocket; -namespace DNS { struct Query; } class Entry; class IdentifyRequest; class InfoFormatter; diff --git a/include/event.h b/include/event.h new file mode 100644 index 000000000..b55559b48 --- /dev/null +++ b/include/event.h @@ -0,0 +1,1018 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#pragma once + +#include "service.h" +#include "modules.h" + +struct Events +{ + virtual ~Events() { } +}; + +/* uninstantiated */ +template<typename EventHandler, typename Func, typename Return, typename... Args> +struct Caller; + +/* specialization for void */ +template<typename EventHandler, typename Func, typename... Args> +struct Caller<EventHandler, Func, void, Args...> +{ + void operator()(const std::vector<EventHandler *> &handlers, Func func, Args&&... args) + { + for (EventHandler *eh : handlers) + (eh->*func)(std::forward<Args>(args)...); + } +}; + +/* specialization for EventReturn */ +template<typename EventHandler, typename Func, typename... Args> +struct Caller<EventHandler, Func, EventReturn, Args...> +{ + EventReturn operator()(const std::vector<EventHandler *> &handlers, Func func, Args&&... args) + { + EventReturn ret = EVENT_CONTINUE; + + for (EventHandler *eh : handlers) + { + ret = (eh->*func)(std::forward<Args>(args)...); + if (ret != EVENT_CONTINUE) + return ret; + } + + return ret; + } +}; + +template<typename EventHandler> +class EventHook; + +template<typename EventHandler> +class EventHandlers : public Service +{ + std::vector<EventHandler *> handlers; + friend class EventHook<EventHandler>; + + public: + EventHandlers(Module *o, const Anope::string &ename) : Service(o, "EventHandlers", ename) + { + } + + template<typename Func, typename... Args> + auto operator()(Func func, Args&&... args) -> decltype(((static_cast<EventHandler*>(nullptr))->*func)(args...)) + { + return Caller<EventHandler, Func, decltype(((static_cast<EventHandler*>(nullptr))->*func)(args...)), Args...>()(this->handlers, func, std::forward<Args>(args)...); + } +}; + +template<typename EventHandler> +class EventHandlersReference +{ + ServiceReference<EventHandlers<EventHandler>> ref; + public: + EventHandlersReference(const Anope::string &name) : ref("EventHandlers", name) { } + + explicit operator bool() + { + return !!ref; + } + + template<typename Func, typename... Args> + auto operator()(Func func, Args&&... args) -> decltype(((static_cast<EventHandler*>(nullptr))->*func)(args...)) + { + return (**ref)(func, std::forward<Args>(args)...); + } +}; + +template<typename EventHandler> +class EventHook : public EventHandler +{ + + struct ServiceReferenceListener : ServiceReference<EventHandlers<EventHandler>> + { + EventHook<EventHandler> *eh; + + ServiceReferenceListener(EventHook<EventHandler> *t, const Anope::string &sname) : ServiceReference<EventHandlers<EventHandler>>("EventHandlers", sname), eh(t) + { + } + + void OnAcquire() override + { + if (std::find((*this)->handlers.begin(), (*this)->handlers.end(), eh) == (*this)->handlers.end()) + { + if (eh->priority == Priority::LAST) + (*this)->handlers.push_back(eh); + else + (*this)->handlers.insert((*this)->handlers.begin(), eh); + } + } + } handlers; + + public: + enum class Priority + { + FIRST, + LAST + } + priority; + + EventHook(const Anope::string &name, Priority p = Priority::LAST) : handlers(this, name) + { + handlers.Check(); + } + + ~EventHook() + { + if (!handlers) + return; + + auto it = std::find(handlers->handlers.begin(), handlers->handlers.end(), this); + if (it != handlers->handlers.end()) + handlers->handlers.erase(it); + } +}; + +namespace Event +{ + struct CoreExport PreUserKicked : Events + { + /** Called before a user has been kicked from a channel. + * @param source The kicker + * @param cu The user, channel, and status of the user being kicked + * @param kickmsg The reason for the kick. + */ + virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) anope_abstract; + }; + extern CoreExport EventHandlers<PreUserKicked> OnPreUserKicked; + + struct CoreExport UserKicked : Events + { + /** Called when a user has been kicked from a channel. + * @param source The kicker + * @param target The user being kicked + * @param channel The channel the user was kicked from, which may no longer exist + * @param status The status the kicked user had on the channel before they were kicked + * @param kickmsg The reason for the kick. + */ + virtual void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) anope_abstract; + }; + extern CoreExport EventHandlers<UserKicked> OnUserKicked; + + struct CoreExport PreBotAssign : Events + { + /** Called before a bot is assigned to a channel. + * @param sender The user assigning the bot + * @param ci The channel the bot is to be assigned to. + * @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; + }; + extern CoreExport EventHandlers<PreBotAssign> OnPreBotAssign; + + struct CoreExport BotAssign : Events + { + /** Called when a bot is assigned ot a channel + */ + virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) anope_abstract; + }; + extern CoreExport EventHandlers<BotAssign> OnBotAssign; + + struct CoreExport BotUnAssign : Events + { + /** Called before a bot is unassigned from a channel. + * @param sender The user unassigning the bot + * @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; + }; + extern CoreExport EventHandlers<BotUnAssign> OnBotUnAssign; + + struct CoreExport UserConnect : Events + { + /** Called when a new user connects to the network. + * @param u The connecting user. + * @param exempt set to true/is true if the user should be excepted from bans etc + */ + virtual void OnUserConnect(User *u, bool &exempt) anope_abstract; + }; + extern CoreExport EventHandlers<UserConnect> OnUserConnect; + + struct CoreExport NewServer : Events + { + /** Called when a new server connects to the network. + * @param s The server that has connected to the network + */ + virtual void OnNewServer(Server *s) anope_abstract; + }; + extern CoreExport EventHandlers<NewServer> OnNewServer; + + struct CoreExport UserNickChange : Events + { + /** Called after a user changed the nick + * @param u The user. + * @param oldnick The old nick of the user + */ + virtual void OnUserNickChange(User *u, const Anope::string &oldnick) anope_abstract; + }; + extern CoreExport EventHandlers<UserNickChange> OnUserNickChange; + + + struct CoreExport PreCommand : Events + { + /** Called before a command is due to be executed. + * @param source The source of the command + * @param command The command the user is executing + * @param params The parameters the user is sending + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it + */ + virtual EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) anope_abstract; + }; + extern CoreExport EventHandlers<PreCommand> OnPreCommand; + + struct CoreExport PostCommand : Events + { + /** Called after a command has been executed. + * @param source The source of the command + * @param command The command the user executed + * @param params The parameters the user sent + */ + virtual void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> ¶ms) anope_abstract; + }; + extern CoreExport EventHandlers<PostCommand> OnPostCommand; + + struct CoreExport SaveDatabase : Events + { + /** Called when the databases are saved + */ + virtual void OnSaveDatabase() anope_abstract; + }; + extern CoreExport EventHandlers<SaveDatabase> OnSaveDatabase; + + struct CoreExport LoadDatabase : Events + { + /** Called when the databases are loaded + * @return EVENT_CONTINUE to let other modules continue loading, EVENT_STOP to stop + */ + virtual EventReturn OnLoadDatabase() anope_abstract; + }; + extern CoreExport EventHandlers<LoadDatabase> OnLoadDatabase; + + struct CoreExport Encrypt : Events + { + /** Called when anope needs to check passwords against encryption + * see src/encrypt.c for detailed informations + */ + virtual EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_abstract; + }; + extern CoreExport EventHandlers<Encrypt> OnEncrypt; + + struct CoreExport Decrypt : Events + { + virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) anope_abstract; + }; + extern CoreExport EventHandlers<Decrypt> OnDecrypt; + + + + struct CoreExport CreateBot : Events + { + /** Called when a bot is created or destroyed + */ + virtual void OnCreateBot(BotInfo *bi) anope_abstract; + }; + extern CoreExport EventHandlers<CreateBot> OnCreateBot; + + struct CoreExport DelBot : Events + { + virtual void OnDelBot(BotInfo *bi) anope_abstract; + }; + 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 + * @param u The user + * @param c The channel + */ + virtual void OnPrePartChannel(User *u, Channel *c) anope_abstract; + }; + extern CoreExport EventHandlers<PrePartChannel> OnPrePartChannel; + + struct CoreExport PartChannel : Events + { + /** Called when a user parts a channel + * @param u The user + * @param c The channel, may be NULL if the channel no longer exists + * @param channel The channel name + * @param msg The part reason + */ + virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) anope_abstract; + }; + extern CoreExport EventHandlers<PartChannel> OnPartChannel; + + struct CoreExport LeaveChannel : Events + { + /** Called when a user leaves a channel. + * From either parting, being kicked, or quitting/killed! + * @param u The user + * @param c The channel + */ + virtual void OnLeaveChannel(User *u, Channel *c) anope_abstract; + }; + extern CoreExport EventHandlers<LeaveChannel> OnLeaveChannel; + + struct CoreExport JoinChannel : Events + { + /** Called after a user joins a channel + * If this event triggers the user is allowed to be in the channel, and will + * not be kicked for restricted/akick/forbidden, etc. If you want to kick the user, + * use the CheckKick event instead. + * @param u The user + * @param channel The channel + */ + virtual void OnJoinChannel(User *u, Channel *c) anope_abstract; + }; + extern CoreExport EventHandlers<JoinChannel> OnJoinChannel; + + struct CoreExport TopicUpdated : Events + { + /** Called when a new topic is set + * @param c The channel + * @param setter The user who set the new topic + * @param topic The new topic + */ + virtual void OnTopicUpdated(Channel *c, const Anope::string &user, const Anope::string &topic) anope_abstract; + }; + extern CoreExport EventHandlers<TopicUpdated> OnTopicUpdated; + + struct CoreExport PreServerConnect : Events + { + /** Called before Anope connecs to its uplink + */ + virtual void OnPreServerConnect() anope_abstract; + }; + extern CoreExport EventHandlers<PreServerConnect> OnPreServerConnect; + + struct CoreExport ServerConnect : Events + { + /** Called when Anope connects to its uplink + */ + virtual void OnServerConnect() anope_abstract; + }; + extern CoreExport EventHandlers<ServerConnect> OnServerConnect; + + struct CoreExport PreUplinkSync : Events + { + /** Called when we are almost done synching with the uplink, just before we send the EOB + */ + virtual void OnPreUplinkSync(Server *serv) anope_abstract; + }; + extern CoreExport EventHandlers<PreUplinkSync> OnPreUplinkSync; + + struct CoreExport ServerDisconnect : Events + { + /** Called when Anope disconnects from its uplink, before it tries to reconnect + */ + virtual void OnServerDisconnect() anope_abstract; + }; + extern CoreExport EventHandlers<ServerDisconnect> OnServerDisconnect; + + struct CoreExport Restart : Events + { + /** Called when services restart + */ + virtual void OnRestart() anope_abstract; + }; + extern CoreExport EventHandlers<Restart> OnRestart; + + struct CoreExport Shutdown : Events + { + /** Called when services shutdown + */ + virtual void OnShutdown() anope_abstract; + }; + extern CoreExport EventHandlers<Shutdown> OnShutdown; + + struct CoreExport AddXLine : Events + { + /** Called before a XLine is added + * @param source The source of the XLine + * @param x The XLine + * @param xlm The xline manager it was added to + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it + */ + virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) anope_abstract; + }; + extern CoreExport EventHandlers<AddXLine> OnAddXLine; + + struct CoreExport DelXLine : Events + { + /** Called before a XLine is deleted + * @param source The source of the XLine + * @param x The XLine + * @param xlm The xline manager it was deleted from + */ + virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) anope_abstract; + }; + extern CoreExport EventHandlers<DelXLine> OnDelXLine; + + struct CoreExport IsServicesOperEvent : Events + { + /** Called when a user is checked for whether they are a services oper + * @param u The user + * @return EVENT_ALLOW to allow, anything else to deny + */ + virtual EventReturn IsServicesOper(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<IsServicesOperEvent> OnIsServicesOper; + + struct CoreExport ServerQuit : Events + { + /** Called when a server quits + * @param server The server + */ + virtual void OnServerQuit(Server *server) anope_abstract; + }; + extern CoreExport EventHandlers<ServerQuit> OnServerQuit; + + struct CoreExport UserQuit : Events + { + /** Called when a user quits, or is killed + * @param u The user + * @param msg The quit message + */ + virtual void OnUserQuit(User *u, const Anope::string &msg) anope_abstract; + }; + extern CoreExport EventHandlers<UserQuit> OnUserQuit; + + struct CoreExport PreUserLogoff : Events + { + /** Called when a user is quit, before and after being internally removed from + * This is different from OnUserQuit, which takes place at the time of the quit. + * This happens shortly after when all message processing is finished. + * all lists (channels, user list, etc) + * @param u The user + */ + virtual void OnPreUserLogoff(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<PreUserLogoff> OnPreUserLogoff; + + struct CoreExport PostUserLogoff : Events + { + virtual void OnPostUserLogoff(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<PostUserLogoff> OnPostUserLogoff; + + struct CoreExport AccessDel : Events + { + /** Called after an access entry is deleted from a channel + * @param ci The channel + * @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; + }; + extern CoreExport EventHandlers<AccessDel> OnAccessDel; + + struct CoreExport AccessAdd : Events + { + /** Called when access is added + * @param ci The channel + * @param source The source of the command + * @param access The access changed + */ + virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) anope_abstract; + }; + extern CoreExport EventHandlers<AccessAdd> OnAccessAdd; + + struct CoreExport AccessClear : Events + { + /** Called when the access list is cleared + * @param ci The channel + * @param u The user who cleared the access + */ + virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) anope_abstract; + }; + extern CoreExport EventHandlers<AccessClear> OnAccessClear; + + struct CoreExport ChanRegistered : Events + { + /** Called when a channel is registered + * @param ci The channel + */ + virtual void OnChanRegistered(ChannelInfo *ci) anope_abstract; + }; + extern CoreExport EventHandlers<ChanRegistered> OnChanRegistered; + + + struct CoreExport CreateChan : Events + { + /** Called when a channel is being created, for any reason + * @param ci The channel + */ + virtual void OnCreateChan(ChannelInfo *ci) anope_abstract; + }; + extern CoreExport EventHandlers<CreateChan> OnCreateChan; + + struct CoreExport DelChan : Events + { + /** Called when a channel is being deleted, for any reason + * @param ci The channel + */ + virtual void OnDelChan(ChannelInfo *ci) anope_abstract; + }; + extern CoreExport EventHandlers<DelChan> OnDelChan; + + struct CoreExport ChannelCreate : Events + { + /** Called when a new channel is created + * Note that this channel may not be introduced to the uplink at this point. + * @param c The channel + */ + virtual void OnChannelCreate(Channel *c) anope_abstract; + }; + extern CoreExport EventHandlers<ChannelCreate> OnChannelCreate; + + struct CoreExport ChannelDelete : Events + { + /** Called when a channel is deleted + * @param c The channel + */ + virtual void OnChannelDelete(Channel *c) anope_abstract; + }; + extern CoreExport EventHandlers<ChannelDelete> OnChannelDelete; + + + struct CoreExport CheckKick : Events + { + /** Called after a user join a channel when we decide whether to kick them or not + * @param u The user + * @param c The channel + * @param kick Set to true to kick + * @param mask The mask to ban, if any + * @param reason The reason for the kick + * @return EVENT_STOP to prevent the user from joining by kicking/banning the user + */ + virtual EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_abstract; + }; + extern CoreExport EventHandlers<CheckKick> OnCheckKick; + + struct CoreExport CheckPriv : Events + { + /** Checks if access has the channel privilege 'priv'. + * @param access THe access struct + * @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; + }; + extern CoreExport EventHandlers<CheckPriv> OnCheckPriv; + + struct CoreExport GroupCheckPriv : Events + { + /** Check whether an access group has a privilege + * @param group The group + * @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; + }; + extern CoreExport EventHandlers<GroupCheckPriv> OnGroupCheckPriv; + + struct CoreExport NickIdentify : Events + { + /** Called when a user identifies to a nick + * @param u The user + */ + virtual void OnNickIdentify(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<NickIdentify> OnNickIdentify; + + struct CoreExport UserLogin : Events + { + /** Called when a user is logged into an account + * @param u The user + */ + virtual void OnUserLogin(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<UserLogin> OnUserLogin; + + struct CoreExport NickLogout : Events + { + /** Called when a nick logs out + * @param u The nick + */ + virtual void OnNickLogout(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<NickLogout> OnNickLogout; + + struct CoreExport DelNick : Events + { + /** Called on delnick() + * @ param na pointer to the nickalias + */ + virtual void OnDelNick(NickAlias *na) anope_abstract; + }; + extern CoreExport EventHandlers<DelNick> OnDelNick; + + struct CoreExport NickCoreCreate : Events + { + /** Called when a nickcore is created + * @param nc The nickcore + */ + virtual void OnNickCoreCreate(NickCore *nc) anope_abstract; + }; + extern CoreExport EventHandlers<NickCoreCreate> OnNickCoreCreate; + + struct CoreExport DelCore : Events + { + /** Called on delcore() + * @param nc pointer to the NickCore + */ + virtual void OnDelCore(NickCore *nc) anope_abstract; + }; + extern CoreExport EventHandlers<DelCore> OnDelCore; + + struct CoreExport ChangeCoreDisplay : Events + { + /** Called on change_core_display() + * @param nc pointer to the NickCore + * @param newdisplay the new display + */ + virtual void OnChangeCoreDisplay(NickCore *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 + */ + virtual void OnNickClearAccess(NickCore *nc) anope_abstract; + }; + extern CoreExport EventHandlers<NickClearAccess> OnNickClearAccess; + + struct CoreExport NickAddAccess : Events + { + /** Called when a user adds an entry to their access list + * @param nc The nick + * @param entry The entry + */ + virtual void OnNickAddAccess(NickCore *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 + * @param entry The access mask + */ + virtual void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) anope_abstract; + }; + extern CoreExport EventHandlers<NickEraseAccess> OnNickEraseAccess; + + + + struct CoreExport CheckAuthentication : Events + { + /** Check whether a username and password is correct + * @param u The user trying to identify, if applicable. + * @param req The login request + */ + virtual void OnCheckAuthentication(User *u, IdentifyRequest *req) anope_abstract; + }; + extern CoreExport EventHandlers<CheckAuthentication> OnCheckAuthentication; + + struct CoreExport Fingerprint : Events + { + /** Called when we get informed about a users SSL fingerprint + * when we call this, the fingerprint should already be stored in the user struct + * @param u pointer to the user + */ + virtual void OnFingerprint(User *u) anope_abstract; + }; + extern CoreExport EventHandlers<Fingerprint> OnFingerprint; + + struct CoreExport UserAway : Events + { + /** Called when a user becomes (un)away + * @param message The message, is .empty() if unaway + */ + virtual void OnUserAway(User *u, const Anope::string &message) anope_abstract; + }; + extern CoreExport EventHandlers<UserAway> OnUserAway; + + struct CoreExport Invite : Events + { + /** Called when a user invites one of our users to a channel + * @param source The user doing the inviting + * @param c The channel the user is inviting to + * @param targ The user being invited + */ + virtual void OnInvite(User *source, Channel *c, User *targ) anope_abstract; + }; + extern CoreExport EventHandlers<Invite> OnInvite; + + struct CoreExport SetVhost : Events + { + /** Called when a vhost is set + * @param na The nickalias of the vhost + */ + virtual void OnSetVhost(NickAlias *na) anope_abstract; + }; + extern CoreExport EventHandlers<SetVhost> OnSetVhost; + + struct CoreExport SetDisplayedHost : Events + { + /** Called when a users host changes + * @param u The user + */ + virtual void OnSetDisplayedHost(User *) anope_abstract; + }; + extern CoreExport EventHandlers<SetDisplayedHost> OnSetDisplayedHost; + + struct CoreExport ChannelModeSet : Events + { + /** Called when a mode is set on a channel + * @param c The channel + * @param setter The user or server that is setting the mode + * @param mode The mode + * @param param The mode param, if there is one + * @return EVENT_STOP to make mlock/secureops etc checks not happen + */ + virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) anope_abstract; + }; + extern CoreExport EventHandlers<ChannelModeSet> OnChannelModeSet; + + struct CoreExport ChannelModeUnset : Events + { + /** Called when a mode is unset on a channel + * @param c The channel + * @param setter The user or server that is unsetting the mode + * @param mode The mode + * @param param The mode param, if there is one + * @return EVENT_STOP to make mlock/secureops etc checks not happen + */ + virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) anope_abstract; + }; + extern CoreExport EventHandlers<ChannelModeUnset> OnChannelModeUnset; + + struct CoreExport UserModeSet : Events + { + /** Called when a mode is set on a user + * @param setter who/what is setting the mode + * @param u The user + * @param mname The mode name + */ + virtual void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_abstract; + }; + extern CoreExport EventHandlers<UserModeSet> OnUserModeSet; + + struct CoreExport UserModeUnset : Events + { + /** Called when a mode is unset from a user + * @param setter who/what is setting the mode + * @param u The user + * @param mname The mode name + */ + virtual void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_abstract; + }; + extern CoreExport EventHandlers<UserModeUnset> OnUserModeUnset; + + struct CoreExport ChannelModeAdd : Events + { + /** Called when a channel mode is introducted into Anope + * @param cm The mode + */ + virtual void OnChannelModeAdd(ChannelMode *cm) anope_abstract; + }; + extern CoreExport EventHandlers<ChannelModeAdd> OnChannelModeAdd; + + struct CoreExport UserModeAdd : Events + { + /** Called when a user mode is introducted into Anope + * @param um The mode + */ + virtual void OnUserModeAdd(UserMode *um) anope_abstract; + }; + extern CoreExport EventHandlers<UserModeAdd> OnUserModeAdd; + + struct CoreExport ModuleLoad : Events + { + /** Called after a module is loaded + * @param u The user loading the module, can be NULL + * @param m The module + */ + virtual void OnModuleLoad(User *u, Module *m) anope_abstract; + }; + extern CoreExport EventHandlers<ModuleLoad> OnModuleLoad; + + struct CoreExport ModuleUnload : Events + { + /** Called before a module is unloaded + * @param u The user, can be NULL + * @param m The module + */ + virtual void OnModuleUnload(User *u, Module *m) anope_abstract; + }; + extern CoreExport EventHandlers<ModuleUnload> OnModuleUnload; + + struct CoreExport ServerSync : Events + { + /** Called when a server is synced + * @param s The server, can be our uplink server + */ + virtual void OnServerSync(Server *s) anope_abstract; + }; + extern CoreExport EventHandlers<ServerSync> OnServerSync; + + struct CoreExport UplinkSync : Events + { + /** Called when we sync with our uplink + * @param s Our uplink + */ + virtual void OnUplinkSync(Server *s) anope_abstract; + }; + extern CoreExport EventHandlers<UplinkSync> OnUplinkSync; + + struct CoreExport BotPrivmsg : Events + { + /** Called when we receive a PRIVMSG for one of our clients + * @param u The user sending the PRIVMSG + * @param bi The target of the PRIVMSG + * @param message The message + * @return EVENT_STOP to halt processing + */ + virtual EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) anope_abstract; + }; + extern CoreExport EventHandlers<BotPrivmsg> OnBotPrivmsg; + + struct CoreExport BotNotice : Events + { + /** Called when we receive a NOTICE for one of our clients + * @param u The user sending the NOTICE + * @param bi The target of the NOTICE + * @param message The message + */ + virtual void OnBotNotice(User *u, BotInfo *bi, Anope::string &message) anope_abstract; + }; + extern CoreExport EventHandlers<BotNotice> OnBotNotice; + + struct CoreExport Privmsg : Events + { + /** Called when we receive a PRIVMSG for a registered channel we are in + * @param u The source of the message + * @param c The channel + * @param msg The message + */ + virtual void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_abstract; + }; + extern CoreExport EventHandlers<Privmsg> OnPrivmsg; + + struct CoreExport Log : Events + { + /** Called when a message is logged + * @param l The log message + */ + virtual void OnLog(::Log *l) anope_abstract; + }; + extern CoreExport EventHandlers<Log> OnLog; + + struct CoreExport LogMessage : Events + { + /** Called when a log message is actually logged to a given log info + * The message has already passed validation checks by the LogInfo + * @param li The loginfo whee the message is being logged + * @param l The log message + * @param msg The final formatted message, derived from 'l' + */ + virtual void OnLogMessage(LogInfo *li, const ::Log *l, const Anope::string &msg) anope_abstract; + }; + extern CoreExport EventHandlers<LogMessage> OnLogMessage; + + struct CoreExport CheckModes : Events + { + /** Called when a channels modes are being checked to see if they are allowed, + * mostly to ensure mlock/+r are set. + * @param c The channel + */ + virtual void OnCheckModes(Reference<Channel> &c) anope_abstract; + }; + extern CoreExport EventHandlers<CheckModes> OnCheckModes; + + struct CoreExport ChannelSync : Events + { + /** Called when a channel is synced. + * Channels are synced after a sjoin is finished processing + * for a newly created channel to set the correct modes, topic, + * set. + */ + virtual void OnChannelSync(Channel *c) anope_abstract; + }; + extern CoreExport EventHandlers<ChannelSync> OnChannelSync; + + struct CoreExport SetCorrectModes : Events + { + /** Called to set the correct modes on the user on the given channel + * @param user The user + * @param chan The channel + * @param access The user's access on the channel + * @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; + }; + extern CoreExport EventHandlers<SetCorrectModes> OnSetCorrectModes; + + struct CoreExport SerializeCheck : Events + { + virtual void OnSerializeCheck(Serialize::Type *) anope_abstract; + }; + extern CoreExport EventHandlers<SerializeCheck> OnSerializeCheck; + + struct CoreExport SerializableConstruct : Events + { + virtual void OnSerializableConstruct(Serializable *) anope_abstract; + }; + extern CoreExport EventHandlers<SerializableConstruct> OnSerializableConstruct; + + struct CoreExport SerializableDestruct : Events + { + virtual void OnSerializableDestruct(Serializable *) anope_abstract; + }; + extern CoreExport EventHandlers<SerializableDestruct> OnSerializableDestruct; + + struct CoreExport SerializableUpdate : Events + { + virtual void OnSerializableUpdate(Serializable *) anope_abstract; + }; + extern CoreExport EventHandlers<SerializableUpdate> OnSerializableUpdate; + + struct CoreExport SerializeTypeCreate : Events + { + virtual void OnSerializeTypeCreate(Serialize::Type *) anope_abstract; + }; + extern CoreExport EventHandlers<SerializeTypeCreate> OnSerializeTypeCreate; + + struct CoreExport Message : Events + { + /** Called whenever a message is received from the uplink + * @param source The source of the message + * @param command The command being executed + * @param params Parameters + * @return EVENT_STOP to prevent the protocol module from processing this message + */ + virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector<Anope::string> ¶m) anope_abstract; + }; + extern CoreExport EventHandlers<Message> OnMessage; + + struct CoreExport CanSet : Events + { + /** Called to determine if a chnanel mode can be set by a user + * @param u The user + * @param cm The mode + */ + virtual EventReturn OnCanSet(User *u, const ChannelMode *cm) anope_abstract; + }; + extern CoreExport EventHandlers<CanSet> OnCanSet; + + struct CoreExport CheckDelete : Events + { + virtual EventReturn OnCheckDelete(Channel *) anope_abstract; + }; + extern CoreExport EventHandlers<CheckDelete> OnCheckDelete; + + struct CoreExport ExpireTick : Events + { + /** Called every options:expiretimeout seconds. Should be used to expire nicks, + * channels, etc. + */ + virtual void OnExpireTick() anope_abstract; + }; + extern CoreExport EventHandlers<ExpireTick> OnExpireTick; + +} + diff --git a/include/module.h b/include/module.h index 571cf4a6a..0efbb7334 100644 --- a/include/module.h +++ b/include/module.h @@ -19,6 +19,7 @@ #include "channels.h" #include "commands.h" #include "config.h" +#include "event.h" #include "extensible.h" #include "hashcomp.h" #include "language.h" @@ -43,9 +44,3 @@ #include "uplink.h" #include "users.h" #include "xline.h" - -#include "modules/pseudoclients/chanserv.h" -#include "modules/pseudoclients/global.h" -#include "modules/pseudoclients/memoserv.h" -#include "modules/pseudoclients/nickserv.h" - diff --git a/include/modules.h b/include/modules.h index 05a763b00..56778d4e2 100644 --- a/include/modules.h +++ b/include/modules.h @@ -51,77 +51,6 @@ } #endif -/** - * This #define allows us to call a method in all - * loaded modules in a readable simple way, e.g.: - * - * FOREACH_MOD(OnUserConnect, (user, exempt)); - */ -#define FOREACH_MOD(ename, args) \ -if (true) \ -{ \ - std::vector<Module *> &_modules = ModuleManager::EventHandlers[I_ ## ename]; \ - for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \ - { \ - try \ - { \ - (*_i)->ename args; \ - } \ - catch (const ModuleException &modexcept) \ - { \ - Log() << "Exception caught: " << modexcept.GetReason(); \ - } \ - catch (const NotImplementedException &) \ - { \ - _i = _modules.erase(_i); \ - continue; \ - } \ - ++_i; \ - } \ -} \ -else \ - static_cast<void>(0) - -/** - * This define is similar to the one above but returns a result. - * The first module to return a result other than EVENT_CONTINUE is the value to be accepted, - * and any modules after are ignored. This is used like: - * - * EventReturn MOD_RESULT; - * FOREACH_RESULT(OnUserConnect, MOD_RESULT, (user, exempt)); - */ -#define FOREACH_RESULT(ename, ret, args) \ -if (true) \ -{ \ - ret = EVENT_CONTINUE; \ - std::vector<Module *> &_modules = ModuleManager::EventHandlers[I_ ## ename]; \ - for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \ - { \ - try \ - { \ - EventReturn res = (*_i)->ename args; \ - if (res != EVENT_CONTINUE) \ - { \ - ret = res; \ - break; \ - } \ - } \ - catch (const ModuleException &modexcept) \ - { \ - Log() << "Exception caught: " << modexcept.GetReason(); \ - } \ - catch (const NotImplementedException &) \ - { \ - _i = _modules.erase(_i); \ - continue; \ - } \ - ++_i; \ - } \ -} \ -else \ - static_cast<void>(0) - - /** Possible return types from events. */ enum EventReturn @@ -144,9 +73,6 @@ enum ModuleReturn MOD_ERR_VERSION }; -/** Priority types which can be returned from Module::Prioritize() - */ -enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }; /* Module types, in the order in which they are unloaded. The order these are in is IMPORTANT */ enum { @@ -205,8 +131,6 @@ class ModuleVersion int GetPatch() const; }; -class NotImplementedException : public CoreException { }; - /** Every module in Anope is actually a class. */ class CoreExport Module : public Extensible @@ -283,827 +207,11 @@ class CoreExport Module : public Extensible */ ModuleVersion GetVersion() const; - /* Everything below here are events. Modules must ModuleManager::Attach to these events - * before they will be called. - */ - - /** Called before a user has been kicked from a channel. - * @param source The kicker - * @param cu The user, channel, and status of the user being kicked - * @param kickmsg The reason for the kick. - */ - virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) { throw NotImplementedException(); } - - /** Called when a user has been kicked from a channel. - * @param source The kicker - * @param target The user being kicked - * @param channel The channel the user was kicked from, which may no longer exist - * @param status The status the kicked user had on the channel before they were kicked - * @param kickmsg The reason for the kick. - */ - virtual void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) { throw NotImplementedException(); } - /** Called when Services' configuration is being (re)loaded. * @param conf The config that is being built now and will replace the global Config object * @throws A ConfigException to abort the config (re)loading process. */ - virtual void OnReload(Configuration::Conf *conf) { throw NotImplementedException(); } - - /** Called before a bot is assigned to a channel. - * @param sender The user assigning the bot - * @param ci The channel the bot is to be assigned to. - * @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) { throw NotImplementedException(); } - - /** Called when a bot is assigned ot a channel - */ - virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { throw NotImplementedException(); } - - /** Called before a bot is unassigned from a channel. - * @param sender The user unassigning the bot - * @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) { throw NotImplementedException(); } - - /** Called when a new user connects to the network. - * @param u The connecting user. - * @param exempt set to true/is true if the user should be excepted from bans etc - */ - virtual void OnUserConnect(User *u, bool &exempt) { throw NotImplementedException(); } - - /** Called when a new server connects to the network. - * @param s The server that has connected to the network - */ - virtual void OnNewServer(Server *s) { throw NotImplementedException(); } - - /** Called after a user changed the nick - * @param u The user. - * @param oldnick The old nick of the user - */ - virtual void OnUserNickChange(User *u, const Anope::string &oldnick) { throw NotImplementedException(); } - - /** Called when someone uses the generic/help command - * @param source Command source - * @param params Params - * @return EVENT_STOP to stop processing - */ - virtual EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) { throw NotImplementedException(); } - - /** Called when someone uses the generic/help command - * @param source Command source - * @param params Params - */ - virtual void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) { throw NotImplementedException(); } - - /** Called before a command is due to be executed. - * @param source The source of the command - * @param command The command the user is executing - * @param params The parameters the user is sending - * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it - */ - virtual EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) { throw NotImplementedException(); } - - /** Called after a command has been executed. - * @param source The source of the command - * @param command The command the user executed - * @param params The parameters the user sent - */ - virtual void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> ¶ms) { throw NotImplementedException(); } - - /** Called when the databases are saved - */ - virtual void OnSaveDatabase() { throw NotImplementedException(); } - - /** Called when the databases are loaded - * @return EVENT_CONTINUE to let other modules continue loading, EVENT_STOP to stop - */ - virtual EventReturn OnLoadDatabase() { throw NotImplementedException(); } - - /** Called when anope needs to check passwords against encryption - * see src/encrypt.c for detailed informations - */ - virtual EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { throw NotImplementedException(); } - virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) { throw NotImplementedException(); } - - /** Called on fantasy command - * @param source The source of the command - * @param c The command - * @param ci The channel it's being used in - * @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) { throw NotImplementedException(); } - - /** Called on fantasy command without access - * @param source The source of the command - * @param c The command - * @param ci The channel it's being used in - * @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) { throw NotImplementedException(); } - - /** Called when a bot places a ban - * @param u User being banned - * @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) { throw NotImplementedException(); } - - /** Called before a badword is added to the badword list - * @param ci The channel - * @param bw The badword - */ - virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) { throw NotImplementedException(); } - - /** 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) { throw NotImplementedException(); } - - /** Called when a bot is created or destroyed - */ - virtual void OnCreateBot(BotInfo *bi) { throw NotImplementedException(); } - virtual void OnDelBot(BotInfo *bi) { throw NotImplementedException(); } - - /** 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) { throw NotImplementedException(); } - - /** Called before a user parts a channel - * @param u The user - * @param c The channel - */ - virtual void OnPrePartChannel(User *u, Channel *c) {} - - /** Called when a user parts a channel - * @param u The user - * @param c The channel, may be NULL if the channel no longer exists - * @param channel The channel name - * @param msg The part reason - */ - virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) { throw NotImplementedException(); } - - /** Called when a user leaves a channel. - * From either parting, being kicked, or quitting/killed! - * @param u The user - * @param c The channel - */ - virtual void OnLeaveChannel(User *u, Channel *c) { throw NotImplementedException(); } - - /** Called after a user joins a channel - * If this event triggers the user is allowed to be in the channel, and will - * not be kicked for restricted/akick/forbidden, etc. If you want to kick the user, - * use the CheckKick event instead. - * @param u The user - * @param channel The channel - */ - virtual void OnJoinChannel(User *u, Channel *c) { throw NotImplementedException(); } - - /** Called when a new topic is set - * @param c The channel - * @param setter The user who set the new topic - * @param topic The new topic - */ - virtual void OnTopicUpdated(Channel *c, const Anope::string &user, const Anope::string &topic) { throw NotImplementedException(); } - - /** Called before a channel expires - * @param ci The channel - * @param expire Set to true to allow the chan to expire - */ - virtual void OnPreChanExpire(ChannelInfo *ci, bool &expire) { throw NotImplementedException(); } - - /** Called before a channel expires - * @param ci The channel - */ - virtual void OnChanExpire(ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called before Anope connecs to its uplink - */ - virtual void OnPreServerConnect() { throw NotImplementedException(); } - - /** Called when Anope connects to its uplink - */ - virtual void OnServerConnect() { throw NotImplementedException(); } - - /** Called when we are almost done synching with the uplink, just before we send the EOB - */ - virtual void OnPreUplinkSync(Server *serv) { throw NotImplementedException(); } - - /** Called when Anope disconnects from its uplink, before it tries to reconnect - */ - virtual void OnServerDisconnect() { throw NotImplementedException(); } - - /** Called when services restart - */ - virtual void OnRestart() { throw NotImplementedException(); } - - /** Called when services shutdown - */ - virtual void OnShutdown() { throw NotImplementedException(); } - - /** Called before a nick expires - * @param na The nick - * @param expire Set to true to allow the nick to expire - */ - virtual void OnPreNickExpire(NickAlias *na, bool &expire) { throw NotImplementedException(); } - - /** Called when a nick drops - * @param na The nick - */ - virtual void OnNickExpire(NickAlias *na) { throw NotImplementedException(); } - - /** Called when defcon level changes - * @param level The level - */ - virtual void OnDefconLevel(int level) { throw NotImplementedException(); } - - /** Called after an exception has been added - * @param ex The exception - * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it - */ - virtual EventReturn OnExceptionAdd(Exception *ex) { throw NotImplementedException(); } - - /** Called before an exception is deleted - * @param source The source deleting it - * @param ex The exceotion - */ - virtual void OnExceptionDel(CommandSource &source, Exception *ex) { throw NotImplementedException(); } - - /** Called before a XLine is added - * @param source The source of the XLine - * @param x The XLine - * @param xlm The xline manager it was added to - * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it - */ - virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { throw NotImplementedException(); } - - /** Called before a XLine is deleted - * @param source The source of the XLine - * @param x The XLine - * @param xlm The xline manager it was deleted from - */ - virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { throw NotImplementedException(); } - - /** Called when a user is checked for whether they are a services oper - * @param u The user - * @return EVENT_ALLOW to allow, anything else to deny - */ - virtual EventReturn IsServicesOper(User *u) { throw NotImplementedException(); } - - /** Called when a server quits - * @param server The server - */ - virtual void OnServerQuit(Server *server) { throw NotImplementedException(); } - - /** Called when a user quits, or is killed - * @param u The user - * @param msg The quit message - */ - virtual void OnUserQuit(User *u, const Anope::string &msg) { throw NotImplementedException(); } - - /** Called when a user is quit, before and after being internally removed from - * This is different from OnUserQuit, which takes place at the time of the quit. - * This happens shortly after when all message processing is finished. - * all lists (channels, user list, etc) - * @param u The user - */ - virtual void OnPreUserLogoff(User *u) { throw NotImplementedException(); } - virtual void OnPostUserLogoff(User *u) { throw NotImplementedException(); } - - /** Called when a new bot is made - * @param bi The bot - */ - virtual void OnBotCreate(BotInfo *bi) { throw NotImplementedException(); } - - /** Called when a bot is changed - * @param bi The bot - */ - virtual void OnBotChange(BotInfo *bi) { throw NotImplementedException(); } - - /** Called when a bot is deleted - * @param bi The bot - */ - virtual void OnBotDelete(BotInfo *bi) { throw NotImplementedException(); } - - /** Called after an access entry is deleted from a channel - * @param ci The channel - * @param source The source of the command - * @param access The access entry that was removed - */ - virtual void OnAccessDel(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { throw NotImplementedException(); } - - /** Called when access is added - * @param ci The channel - * @param source The source of the command - * @param access The access changed - */ - virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { throw NotImplementedException(); } - - /** Called when the access list is cleared - * @param ci The channel - * @param u The user who cleared the access - */ - virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) { throw NotImplementedException(); } - - /** Called when a level for a channel is changed - * @param source The source of the command - * @param ci The channel the level was changed on - * @param priv The privilege changed - * @param what The new level - */ - virtual void OnLevelChange(CommandSource &source, ChannelInfo *ci, const Anope::string &priv, int16_t what) { throw NotImplementedException(); } - - /** Called right before a channel is dropped - * @param source The user dropping the channel - * @param ci The channel - */ - virtual EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called when a channel is registered - * @param ci The channel - */ - virtual void OnChanRegistered(ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called when a channel is suspended - * @param ci The channel - */ - virtual void OnChanSuspend(ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called when a channel is unsuspended - * @param ci The channel - */ - virtual void OnChanUnsuspend(ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called when a channel is being created, for any reason - * @param ci The channel - */ - virtual void OnCreateChan(ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called when a channel is being deleted, for any reason - * @param ci The channel - */ - virtual void OnDelChan(ChannelInfo *ci) { throw NotImplementedException(); } - - /** Called when a new channel is created - * Note that this channel may not be introduced to the uplink at this point. - * @param c The channel - */ - virtual void OnChannelCreate(Channel *c) { throw NotImplementedException(); } - - /** Called when a channel is deleted - * @param c The channel - */ - virtual void OnChannelDelete(Channel *c) { throw NotImplementedException(); } - - /** Called after adding an akick to a channel - * @param source The source of the command - * @param ci The channel - * @param ak The akick - */ - virtual void OnAkickAdd(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { throw NotImplementedException(); } - - /** 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) { throw NotImplementedException(); } - - /** Called after a user join a channel when we decide whether to kick them or not - * @param u The user - * @param c The channel - * @param kick Set to true to kick - * @param mask The mask to ban, if any - * @param reason The reason for the kick - * @return EVENT_STOP to prevent the user from joining by kicking/banning the user - */ - virtual EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) { throw NotImplementedException(); } - - /** Called when a user requests info for a channel - * @param source The user requesting info - * @param ci The channel the user is requesting info for - * @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) { throw NotImplementedException(); } - - /** Checks if access has the channel privilege 'priv'. - * @param access THe access struct - * @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) { throw NotImplementedException(); } - - /** Check whether an access group has a privilege - * @param group The group - * @param priv The privilege - * @return MOD_ALLOW to allow, MOD_STOP to stop - */ - virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) { throw NotImplementedException(); } - - /** Called when a nick is dropped - * @param source The source of the command - * @param na The nick - */ - virtual void OnNickDrop(CommandSource &source, NickAlias *na) { throw NotImplementedException(); } - - /** Called when a nick is forbidden - * @param na The nick alias of the forbidden nick - */ - virtual void OnNickForbidden(NickAlias *na) { throw NotImplementedException(); } - - /** Called when a user groups their nick - * @param u The user grouping - * @param target The target they're grouping to - */ - virtual void OnNickGroup(User *u, NickAlias *target) { throw NotImplementedException(); } - - /** Called when a user identifies to a nick - * @param u The user - */ - virtual void OnNickIdentify(User *u) { throw NotImplementedException(); } - - /** Called when a user is logged into an account - * @param u The user - */ - virtual void OnUserLogin(User *u) { throw NotImplementedException(); } - - /** Called when a nick logs out - * @param u The nick - */ - virtual void OnNickLogout(User *u) { throw NotImplementedException(); } - - /** Called when a nick is registered - * @param user The user registering the nick, of any - * @param The nick - */ - virtual void OnNickRegister(User *user, NickAlias *na) { throw NotImplementedException(); } - - /** Called when a nick is suspended - * @param na The nick alias - */ - virtual void OnNickSuspend(NickAlias *na) { throw NotImplementedException(); } - - /** Called when a nick is unsuspneded - * @param na The nick alias - */ - virtual void OnNickUnsuspended(NickAlias *na) { throw NotImplementedException(); } - - /** Called on delnick() - * @ param na pointer to the nickalias - */ - virtual void OnDelNick(NickAlias *na) { throw NotImplementedException(); } - - /** Called when a nickcore is created - * @param nc The nickcore - */ - virtual void OnNickCoreCreate(NickCore *nc) { throw NotImplementedException(); } - - /** Called on delcore() - * @param nc pointer to the NickCore - */ - virtual void OnDelCore(NickCore *nc) { throw NotImplementedException(); } - - /** Called on change_core_display() - * @param nc pointer to the NickCore - * @param newdisplay the new display - */ - virtual void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) { throw NotImplementedException(); } - - /** called from NickCore::ClearAccess() - * @param nc pointer to the NickCore - */ - virtual void OnNickClearAccess(NickCore *nc) { throw NotImplementedException(); } - - /** Called when a user adds an entry to their access list - * @param nc The nick - * @param entry The entry - */ - virtual void OnNickAddAccess(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); } - - /** Called from NickCore::EraseAccess() - * @param nc pointer to the NickCore - * @param entry The access mask - */ - virtual void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); } - - /** called from NickCore::ClearCert() - * @param nc pointer to the NickCore - */ - virtual void OnNickClearCert(NickCore *nc) { throw NotImplementedException(); } - - /** Called when a user adds an entry to their cert list - * @param nc The nick - * @param entry The entry - */ - virtual void OnNickAddCert(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); } - - /** Called from NickCore::EraseCert() - * @param nc pointer to the NickCore - * @param entry The fingerprint - */ - virtual void OnNickEraseCert(NickCore *nc, const Anope::string &entry) { throw NotImplementedException(); } - - /** Called when a user requests info for a nick - * @param source The user requesting info - * @param na The nick the user is requesting info from - * @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) { throw NotImplementedException(); } - - /** Called when a user uses botserv/info on a bot or channel. - */ - virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) { throw NotImplementedException(); } - - /** Check whether a username and password is correct - * @param u The user trying to identify, if applicable. - * @param req The login request - */ - virtual void OnCheckAuthentication(User *u, IdentifyRequest *req) { throw NotImplementedException(); } - - /** Called when a user does /ns update - * @param u The user - */ - virtual void OnNickUpdate(User *u) { throw NotImplementedException(); } - - /** Called when we get informed about a users SSL fingerprint - * when we call this, the fingerprint should already be stored in the user struct - * @param u pointer to the user - */ - virtual void OnFingerprint(User *u) { throw NotImplementedException(); } - - /** Called when a user becomes (un)away - * @param message The message, is .empty() if unaway - */ - virtual void OnUserAway(User *u, const Anope::string &message) { throw NotImplementedException(); } - - /** Called when a user invites one of our users to a channel - * @param source The user doing the inviting - * @param c The channel the user is inviting to - * @param targ The user being invited - */ - virtual void OnInvite(User *source, Channel *c, User *targ) { throw NotImplementedException(); } - - /** Called when a vhost is deleted - * @param na The nickalias of the vhost - */ - virtual void OnDeleteVhost(NickAlias *na) { throw NotImplementedException(); } - - /** Called when a vhost is set - * @param na The nickalias of the vhost - */ - virtual void OnSetVhost(NickAlias *na) { throw NotImplementedException(); } - - /** Called when a users host changes - * @param u The user - */ - virtual void OnSetDisplayedHost(User *) { throw NotImplementedException(); } - - /** Called when a memo is sent - * @param source The source of the memo - * @param target The target of the memo - * @param mi Memo info for target - * @param m The memo - */ - virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) { throw NotImplementedException(); } - - /** Called when a memo is deleted - * @param target The target the memo is being deleted from (nick or channel) - * @param mi The memo info - * @param m The memo - */ - virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) { throw NotImplementedException(); } - - /** Called when a mode is set on a channel - * @param c The channel - * @param setter The user or server that is setting the mode - * @param mode The mode - * @param param The mode param, if there is one - * @return EVENT_STOP to make mlock/secureops etc checks not happen - */ - virtual EventReturn OnChannelModeSet(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) { throw NotImplementedException(); } - - /** Called when a mode is unset on a channel - * @param c The channel - * @param setter The user or server that is unsetting the mode - * @param mode The mode - * @param param The mode param, if there is one - * @return EVENT_STOP to make mlock/secureops etc checks not happen - */ - virtual EventReturn OnChannelModeUnset(Channel *c, MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) { throw NotImplementedException(); } - - /** Called when a mode is set on a user - * @param setter who/what is setting the mode - * @param u The user - * @param mname The mode name - */ - virtual void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) { throw NotImplementedException(); } - - /** Called when a mode is unset from a user - * @param setter who/what is setting the mode - * @param u The user - * @param mname The mode name - */ - virtual void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) { throw NotImplementedException(); } - - /** Called when a channel mode is introducted into Anope - * @param cm The mode - */ - virtual void OnChannelModeAdd(ChannelMode *cm) { throw NotImplementedException(); } - - /** Called when a user mode is introducted into Anope - * @param um The mode - */ - virtual void OnUserModeAdd(UserMode *um) { throw NotImplementedException(); } - - /** Called when a mode is about to be mlocked - * @param ci The channel the mode is being locked on - * @param lock The mode lock - * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock. - */ - virtual EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) { throw NotImplementedException(); } - - /** 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) { throw NotImplementedException(); } - - /** Called after a module is loaded - * @param u The user loading the module, can be NULL - * @param m The module - */ - virtual void OnModuleLoad(User *u, Module *m) { throw NotImplementedException(); } - - /** Called before a module is unloaded - * @param u The user, can be NULL - * @param m The module - */ - virtual void OnModuleUnload(User *u, Module *m) { throw NotImplementedException(); } - - /** Called when a server is synced - * @param s The server, can be our uplink server - */ - virtual void OnServerSync(Server *s) { throw NotImplementedException(); } - - /** Called when we sync with our uplink - * @param s Our uplink - */ - virtual void OnUplinkSync(Server *s) { throw NotImplementedException(); } - - /** Called when we receive a PRIVMSG for one of our clients - * @param u The user sending the PRIVMSG - * @param bi The target of the PRIVMSG - * @param message The message - * @return EVENT_STOP to halt processing - */ - virtual EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &message) { throw NotImplementedException(); } - - /** Called when we receive a NOTICE for one of our clients - * @param u The user sending the NOTICE - * @param bi The target of the NOTICE - * @param message The message - */ - virtual void OnBotNotice(User *u, BotInfo *bi, Anope::string &message) { throw NotImplementedException(); } - - /** Called when we receive a PRIVMSG for a registered channel we are in - * @param u The source of the message - * @param c The channel - * @param msg The message - */ - virtual void OnPrivmsg(User *u, Channel *c, Anope::string &msg) { throw NotImplementedException(); } - - /** Called when a message is logged - * @param l The log message - */ - virtual void OnLog(Log *l) { throw NotImplementedException(); } - - /** Called when a log message is actually logged to a given log info - * The message has already passed validation checks by the LogInfo - * @param li The loginfo whee the message is being logged - * @param l The log message - * @param msg The final formatted message, derived from 'l' - */ - virtual void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) { throw NotImplementedException(); } - - /** Called when a DNS request (question) is recieved. - * @param req The dns request - * @param reply The reply that will be sent - */ - virtual void OnDnsRequest(DNS::Query &req, DNS::Query *reply) { throw NotImplementedException(); } - - /** Called when a channels modes are being checked to see if they are allowed, - * mostly to ensure mlock/+r are set. - * @param c The channel - */ - virtual void OnCheckModes(Reference<Channel> &c) { throw NotImplementedException(); } - - /** Called when a channel is synced. - * Channels are synced after a sjoin is finished processing - * for a newly created channel to set the correct modes, topic, - * set. - */ - virtual void OnChannelSync(Channel *c) { throw NotImplementedException(); } - - /** Called to set the correct modes on the user on the given channel - * @param user The user - * @param chan The channel - * @param access The user's access on the channel - * @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) { throw NotImplementedException(); } - - virtual void OnSerializeCheck(Serialize::Type *) { throw NotImplementedException(); } - virtual void OnSerializableConstruct(Serializable *) { throw NotImplementedException(); } - virtual void OnSerializableDestruct(Serializable *) { throw NotImplementedException(); } - virtual void OnSerializableUpdate(Serializable *) { throw NotImplementedException(); } - virtual void OnSerializeTypeCreate(Serialize::Type *) { throw NotImplementedException(); } - - /** Called when a chanserv/set command is used - * @param source The source of the command - * @param cmd The command - * @param ci The channel the command was used on - * @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) { throw NotImplementedException(); } - - /** Called when a nickserv/set command is used. - * @param source The source of the command - * @param cmd The command - * @param nc The nickcore being modifed - * @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) { throw NotImplementedException(); } - - /** Called whenever a message is received from the uplink - * @param source The source of the message - * @param command The command being executed - * @param params Parameters - * @return EVENT_STOP to prevent the protocol module from processing this message - */ - virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector<Anope::string> ¶m) { throw NotImplementedException(); } - - /** Called to determine if a chnanel mode can be set by a user - * @param u The user - * @param cm The mode - */ - virtual EventReturn OnCanSet(User *u, const ChannelMode *cm) { throw NotImplementedException(); } - - virtual EventReturn OnCheckDelete(Channel *) { throw NotImplementedException(); } - - /** Called every options:expiretimeout seconds. Should be used to expire nicks, - * channels, etc. - */ - virtual void OnExpireTick() { throw NotImplementedException(); } - - /** Called when a nick is validated. That is, to determine if a user is permissted - * to be on the given nick. - * @param u The user - * @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) { throw NotImplementedException(); } -}; - -enum Implementation -{ - I_OnPreUserKicked, I_OnUserKicked, I_OnReload, I_OnPreBotAssign, I_OnBotAssign, I_OnBotUnAssign, I_OnUserConnect, - I_OnNewServer, I_OnUserNickChange, I_OnPreHelp, I_OnPostHelp, I_OnPreCommand, I_OnPostCommand, I_OnSaveDatabase, - I_OnLoadDatabase, I_OnEncrypt, I_OnDecrypt, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, - I_OnBadWordDel, I_OnCreateBot, I_OnDelBot, I_OnBotKick, I_OnPrePartChannel, I_OnPartChannel, I_OnLeaveChannel, - I_OnJoinChannel, I_OnTopicUpdated, I_OnPreChanExpire, I_OnChanExpire, I_OnPreServerConnect, I_OnServerConnect, - I_OnPreUplinkSync, I_OnServerDisconnect, I_OnRestart, I_OnShutdown, I_OnPreNickExpire, I_OnNickExpire, I_OnDefconLevel, - I_OnExceptionAdd, I_OnExceptionDel, I_OnAddXLine, I_OnDelXLine, I_IsServicesOper, I_OnServerQuit, I_OnUserQuit, - I_OnPreUserLogoff, I_OnPostUserLogoff, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnAccessDel, I_OnAccessAdd, - I_OnAccessClear, I_OnLevelChange, I_OnChanDrop, I_OnChanRegistered, I_OnChanSuspend, I_OnChanUnsuspend, - I_OnCreateChan, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick, - I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, I_OnNickDrop, I_OnNickForbidden, I_OnNickGroup, I_OnNickIdentify, - I_OnUserLogin, I_OnNickLogout, I_OnNickRegister, I_OnNickSuspend, I_OnNickUnsuspended, I_OnDelNick, I_OnNickCoreCreate, - I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearCert, - I_OnNickAddCert, I_OnNickEraseCert, I_OnNickInfo, I_OnBotInfo, I_OnCheckAuthentication, I_OnNickUpdate, - I_OnFingerprint, I_OnUserAway, I_OnInvite, I_OnDeleteVhost, I_OnSetVhost, I_OnSetDisplayedHost, I_OnMemoSend, I_OnMemoDel, - I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd, - I_OnMLock, I_OnUnMLock, I_OnModuleLoad, I_OnModuleUnload, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnBotNotice, - I_OnPrivmsg, I_OnLog, I_OnLogMessage, I_OnDnsRequest, I_OnCheckModes, I_OnChannelSync, I_OnSetCorrectModes, - I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate, - I_OnSerializeTypeCreate, I_OnSetChannelOption, I_OnSetNickOption, I_OnMessage, I_OnCanSet, I_OnCheckDelete, - I_OnExpireTick, I_OnNickValidate, - I_SIZE + virtual void OnReload(Configuration::Conf *conf) { } }; /** Used to manage modules. @@ -1111,10 +219,6 @@ enum Implementation class CoreExport ModuleManager { public: - /** Event handler hooks. - */ - static std::vector<Module *> EventHandlers[I_SIZE]; - /** List of all modules loaded in Anope */ static std::list<Module *> Modules; @@ -1159,36 +263,6 @@ class CoreExport ModuleManager */ static void RequireVersion(int major, int minor, int patch); - /** Change the priority of one event in a module. - * Each module event has a list of modules which are attached to that event type. If you wish to be called before or after other specific modules, you may use this - * method (usually within void Module::Prioritize()) to set your events priority. You may use this call in other methods too, however, this is not supported behaviour - * for a module. - * @param mod The module to change the priority of - * @param i The event to change the priority of - * @param s The state you wish to use for this event. Use one of - * PRIO_FIRST to set the event to be first called, PRIO_LAST to set it to be the last called, or PRIO_BEFORE and PRIO_AFTER - * to set it to be before or after one or more other modules. - * @param modules If PRIO_BEFORE or PRIO_AFTER is set in parameter 's', then this contains a list of one or more modules your module must be - * placed before or after. Your module will be placed before the highest priority module in this list for PRIO_BEFORE, or after the lowest - * priority module in this list for PRIO_AFTER. - * @param sz The number of modules being passed for PRIO_BEFORE and PRIO_AFTER. Defaults to 1, as most of the time you will only want to prioritize your module - * to be before or after one other module. - */ - static bool SetPriority(Module *mod, Implementation i, Priority s, Module **modules = NULL, size_t sz = 1); - - /** Change the priority of all events in a module. - * @param mod The module to set the priority of - * @param s The priority of all events in the module. - * Note that with this method, it is not possible to effectively use PRIO_BEFORE or PRIO_AFTER, you should use the more fine tuned - * SetPriority method for this, where you may specify other modules to be prioritized against. - */ - static bool SetPriority(Module *mod, Priority s); - - /** Detach all events from a module (used on unload) - * @param mod Module to detach from - */ - static void DetachAll(Module *mod); - /** Unloading all modules except the protocol module. */ static void UnloadAll(); diff --git a/include/modules/bs_badwords.h b/include/modules/bs_badwords.h index 678512c96..390e502c0 100644 --- a/include/modules/bs_badwords.h +++ b/include/modules/bs_badwords.h @@ -71,3 +71,21 @@ struct BadWords virtual void Check() = 0; }; +namespace Event +{ + struct CoreExport BadWordEvents : Events + { + /** Called before a badword is added to the badword list + * @param ci The channel + * @param bw The badword + */ + virtual void OnBadWordAdd(ChannelInfo *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; + }; +} + diff --git a/include/modules/bs_bot.h b/include/modules/bs_bot.h new file mode 100644 index 000000000..c6d670f35 --- /dev/null +++ b/include/modules/bs_bot.h @@ -0,0 +1,34 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport BotCreate : Events + { + /** Called when a new bot is made + * @param bi The bot + */ + virtual void OnBotCreate(BotInfo *bi) anope_abstract; + }; + + struct CoreExport BotChange : Events + { + /** Called when a bot is changed + * @param bi The bot + */ + virtual void OnBotChange(BotInfo *bi) anope_abstract; + }; + + struct CoreExport BotDelete : Events + { + /** Called when a bot is deleted + * @param bi The bot + */ + virtual void OnBotDelete(BotInfo *bi) anope_abstract; + }; +} diff --git a/include/modules/bs_info.h b/include/modules/bs_info.h new file mode 100644 index 000000000..c9f360dfc --- /dev/null +++ b/include/modules/bs_info.h @@ -0,0 +1,20 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport BotInfoEvent : Events + { + /** 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; + }; + extern CoreExport EventHandlers<BotInfoEvent> OnBotInfo; +} + diff --git a/include/modules/bs_kick.h b/include/modules/bs_kick.h index 61cd987d5..a783b6017 100644 --- a/include/modules/bs_kick.h +++ b/include/modules/bs_kick.h @@ -44,3 +44,17 @@ struct KickerData virtual ~KickerData() { } virtual void Check(ChannelInfo *ci) = 0; }; + +namespace Event +{ + struct CoreExport BotBan : Events + { + /** Called when a bot places a ban + * @param u User being banned + * @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; + }; +} + diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h new file mode 100644 index 000000000..37a96e9e7 --- /dev/null +++ b/include/modules/chanserv.h @@ -0,0 +1,46 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace ChanServ +{ + class ChanServService : public Service + { + public: + ChanServService(Module *m) : Service(m, "ChanServService", "ChanServ") + { + } + + /* 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; + }; + static ServiceReference<ChanServService> service("ChanServService", "ChanServ"); + + namespace Event + { + struct CoreExport PreChanExpire : Events + { + /** Called before a channel expires + * @param ci The channel + * @param expire Set to true to allow the chan to expire + */ + virtual void OnPreChanExpire(ChannelInfo *ci, bool &expire) anope_abstract; + }; + static EventHandlersReference<PreChanExpire> OnPreChanExpire("OnPreChanExpire"); + + struct CoreExport ChanExpire : Events + { + /** Called before a channel expires + * @param ci The channel + */ + virtual void OnChanExpire(ChannelInfo *ci) anope_abstract; + }; + static EventHandlersReference<ChanExpire> OnChanExpire("OnChanExpire"); + } +} diff --git a/include/modules/cs_access.h b/include/modules/cs_access.h new file mode 100644 index 000000000..8c6778799 --- /dev/null +++ b/include/modules/cs_access.h @@ -0,0 +1,22 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport LevelChange : Events + { + /** Called when a level for a channel is changed + * @param source The source of the command + * @param ci The channel the level was changed on + * @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; + }; +} diff --git a/include/modules/cs_akick.h b/include/modules/cs_akick.h new file mode 100644 index 000000000..ab02985c1 --- /dev/null +++ b/include/modules/cs_akick.h @@ -0,0 +1,28 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport Akick : Events + { + /** Called after adding an akick to a channel + * @param source The source of the command + * @param ci The channel + * @param ak The akick + */ + virtual void OnAkickAdd(CommandSource &source, ChannelInfo *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; + }; +} diff --git a/include/modules/cs_drop.h b/include/modules/cs_drop.h new file mode 100644 index 000000000..e2a9ace8a --- /dev/null +++ b/include/modules/cs_drop.h @@ -0,0 +1,20 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport ChanDrop : Events + { + /** Called right before a channel is dropped + * @param source The user dropping the channel + * @param ci The channel + */ + virtual EventReturn OnChanDrop(CommandSource &source, ChannelInfo *ci) anope_abstract; + }; +} diff --git a/include/modules/cs_info.h b/include/modules/cs_info.h new file mode 100644 index 000000000..7f0429387 --- /dev/null +++ b/include/modules/cs_info.h @@ -0,0 +1,23 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport ChanInfo : Events + { + /** Called when a user requests info for a channel + * @param source The user requesting info + * @param ci The channel the user is requesting info for + * @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; + }; +} + diff --git a/include/modules/cs_mode.h b/include/modules/cs_mode.h index 44ffd5a7f..4c1dc5d55 100644 --- a/include/modules/cs_mode.h +++ b/include/modules/cs_mode.h @@ -88,3 +88,23 @@ struct ModeLocks virtual void Check() = 0; }; +namespace Event +{ + struct CoreExport MLockEvents : Events + { + /** Called when a mode is about to be mlocked + * @param ci The channel the mode is being locked on + * @param lock The mode lock + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the mlock. + */ + virtual EventReturn OnMLock(ChannelInfo *ci, 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; + }; +} + diff --git a/include/modules/cs_set.h b/include/modules/cs_set.h new file mode 100644 index 000000000..3ddf2f41c --- /dev/null +++ b/include/modules/cs_set.h @@ -0,0 +1,25 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport SetChannelOption : Events + { + /** Called when a chanserv/set command is used + * @param source The source of the command + * @param cmd The command + * @param ci The channel the command was used on + * @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; + }; + static EventHandlersReference<SetChannelOption> OnSetChannelOption("OnSetChannelOption"); +} + diff --git a/include/modules/dns.h b/include/modules/dns.h index 59fc83e64..e340c3f2b 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -175,6 +175,20 @@ namespace DNS }; } // namespace DNS + +namespace Event +{ + struct CoreExport DnsRequest : Events + { + /** Called when a DNS request (question) is recieved. + * @param req The dns request + * @param reply The reply that will be sent + */ + virtual void OnDnsRequest(DNS::Query &req, DNS::Query *reply) anope_abstract; + }; + static EventHandlersReference<DnsRequest> OnDnsRequest("OnDnsRequest"); +} + #endif // DNS_H diff --git a/include/modules/fantasy.h b/include/modules/fantasy.h new file mode 100644 index 000000000..a7944cef9 --- /dev/null +++ b/include/modules/fantasy.h @@ -0,0 +1,35 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct BotFantasy : Events + { + /** Called on fantasy command + * @param source The source of the command + * @param c The command + * @param ci The channel it's being used in + * @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; + }; + + struct CoreExport BotNoFantasyAccess : Events + { + /** Called on fantasy command without access + * @param source The source of the command + * @param c The command + * @param ci The channel it's being used in + * @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; + }; +} diff --git a/include/modules/global.h b/include/modules/global.h new file mode 100644 index 000000000..f4f4989ae --- /dev/null +++ b/include/modules/global.h @@ -0,0 +1,29 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Global +{ + class GlobalService : public Service + { + public: + GlobalService(Module *m) : Service(m, "GlobalService", "Global") + { + } + + /** Send out a global message to all users + * @param sender Our client which should send the global + * @param source The sender of the global + * @param message The message + */ + virtual void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) = 0; + }; + static ServiceReference<GlobalService> service("GlobalService", "Global"); +} + + diff --git a/include/modules/help.h b/include/modules/help.h new file mode 100644 index 000000000..333e5f9c8 --- /dev/null +++ b/include/modules/help.h @@ -0,0 +1,27 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport Help : Events + { + /** Called when someone uses the generic/help command + * @param source Command source + * @param params Params + * @return EVENT_STOP to stop processing + */ + virtual EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_abstract; + + /** Called when someone uses the generic/help command + * @param source Command source + * @param params Params + */ + virtual void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_abstract; + }; +} diff --git a/include/modules/hs_del.h b/include/modules/hs_del.h new file mode 100644 index 000000000..d4a5c7666 --- /dev/null +++ b/include/modules/hs_del.h @@ -0,0 +1,18 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace Event +{ + struct CoreExport DeleteVhost : Events + { + /** Called when a vhost is deleted + * @param na The nickalias of the vhost + */ + virtual void OnDeleteVhost(NickAlias *na) anope_abstract; + }; +} diff --git a/include/modules/memoserv.h b/include/modules/memoserv.h new file mode 100644 index 000000000..4e5d67de6 --- /dev/null +++ b/include/modules/memoserv.h @@ -0,0 +1,66 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace MemoServ +{ + class MemoServService : public Service + { + public: + enum MemoResult + { + MEMO_SUCCESS, + MEMO_INVALID_TARGET, + 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; + + /** Check for new memos and notify the user if there are any + * @param u The user + */ + virtual void Check(User *u) = 0; + }; + static ServiceReference<MemoServService> service("MemoServService", "MemoServ"); + + namespace Event + { + struct CoreExport MemoSend : Events + { + /** Called when a memo is sent + * @param source The source of the memo + * @param target The target of the memo + * @param mi Memo info for target + * @param m The memo + */ + 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 + * @param target The target the memo is being deleted from (nick or channel) + * @param mi The memo info + * @param m The memo + */ + virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) anope_abstract; + }; + static EventHandlersReference<MemoDel> OnMemoDel("OnMemoDel"); + } +} diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h new file mode 100644 index 000000000..0ede4130e --- /dev/null +++ b/include/modules/nickserv.h @@ -0,0 +1,68 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace NickServ +{ + class NickServService : public Service + { + public: + NickServService(Module *m) : Service(m, "NickServService", "NickServ") + { + } + + virtual void Validate(User *u) anope_abstract; + virtual void Collide(User *u, NickAlias *na) anope_abstract; + virtual void Release(NickAlias *na) anope_abstract; + }; + static ServiceReference<NickServService> service("NickServService", "NickServ"); + + namespace Event + { + struct CoreExport PreNickExpire : Events + { + /** Called before a nick expires + * @param na The nick + * @param expire Set to true to allow the nick to expire + */ + virtual void OnPreNickExpire(NickAlias *na, bool &expire) anope_abstract; + }; + static EventHandlersReference<PreNickExpire> OnPreNickExpire("OnPreNickExpire"); + + struct CoreExport NickExpire : Events + { + /** Called when a nick drops + * @param na The nick + */ + virtual void OnNickExpire(NickAlias *na) anope_abstract; + }; + static EventHandlersReference<NickExpire> OnNickExpire("OnNickExpire"); + + struct CoreExport NickRegister : Events + { + /** Called when a nick is registered + * @param user The user registering the nick, of any + * @param The nick + */ + virtual void OnNickRegister(User *user, NickAlias *na) anope_abstract; + }; + static EventHandlersReference<NickRegister> OnNickRegister("OnNickRegister"); + + struct CoreExport NickValidate : Events + { + /** Called when a nick is validated. That is, to determine if a user is permissted + * to be on the given nick. + * @param u The user + * @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; + }; + static EventHandlersReference<NickValidate> OnNickValidate("OnNickValidate"); + } +} diff --git a/include/modules/ns_cert.h b/include/modules/ns_cert.h index e02b9bd6e..b0614b2e6 100644 --- a/include/modules/ns_cert.h +++ b/include/modules/ns_cert.h @@ -69,3 +69,26 @@ class CertService : public Service virtual NickCore* FindAccountFromCert(const Anope::string &cert) = 0; }; +namespace Event +{ + struct CoreExport NickCertEvents : Events + { + /** Called when a user adds an entry to their cert list + * @param nc The nick + * @param entry The entry + */ + virtual void OnNickAddCert(NickCore *nc, const Anope::string &entry) anope_abstract; + + /** Called from NickCore::EraseCert() + * @param nc pointer to the NickCore + * @param entry The fingerprint + */ + virtual void OnNickEraseCert(NickCore *nc, const Anope::string &entry) anope_abstract; + + /** called from NickCore::ClearCert() + * @param nc pointer to the NickCore + */ + virtual void OnNickClearCert(NickCore *nc) anope_abstract; + }; +} + diff --git a/include/modules/ns_drop.h b/include/modules/ns_drop.h new file mode 100644 index 000000000..2aef2b965 --- /dev/null +++ b/include/modules/ns_drop.h @@ -0,0 +1,21 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace Event +{ + struct CoreExport NickDrop : Events + { + /** Called when a nick is dropped + * @param source The source of the command + * @param na The nick + */ + virtual void OnNickDrop(CommandSource &source, NickAlias *na) anope_abstract; + }; + extern CoreExport EventHandlers<NickDrop> OnNickDrop; +} + diff --git a/include/modules/ns_group.h b/include/modules/ns_group.h new file mode 100644 index 000000000..8b3fa49f9 --- /dev/null +++ b/include/modules/ns_group.h @@ -0,0 +1,20 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport NickGroup : Events + { + /** Called when a user groups their nick + * @param u The user grouping + * @param target The target they're grouping to + */ + virtual void OnNickGroup(User *u, NickAlias *target) anope_abstract; + }; +} diff --git a/include/modules/ns_info.h b/include/modules/ns_info.h new file mode 100644 index 000000000..8fae2b536 --- /dev/null +++ b/include/modules/ns_info.h @@ -0,0 +1,22 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport NickInfo : Events + { + /** Called when a user requests info for a nick + * @param source The user requesting info + * @param na The nick the user is requesting info from + * @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; + }; +} diff --git a/include/modules/ns_set.h b/include/modules/ns_set.h new file mode 100644 index 000000000..a45fa0b5e --- /dev/null +++ b/include/modules/ns_set.h @@ -0,0 +1,24 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport SetNickOption : Events + { + /** Called when a nickserv/set command is used. + * @param source The source of the command + * @param cmd The command + * @param nc The nickcore being modifed + * @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; + }; + static EventHandlersReference<SetNickOption> OnSetNickOption("OnSetNickOption"); +} diff --git a/include/modules/ns_update.h b/include/modules/ns_update.h new file mode 100644 index 000000000..d5d01320a --- /dev/null +++ b/include/modules/ns_update.h @@ -0,0 +1,20 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport NickUpdate : Events + { + /** Called when a user does /ns update + * @param u The user + */ + virtual void OnNickUpdate(User *u) anope_abstract; + }; +} + diff --git a/include/modules/os_defcon.h b/include/modules/os_defcon.h new file mode 100644 index 000000000..81b220eb3 --- /dev/null +++ b/include/modules/os_defcon.h @@ -0,0 +1,20 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport DefconLevel : Events + { + /** Called when defcon level changes + * @param level The level + */ + virtual void OnDefconLevel(int level) anope_abstract; + }; +} + diff --git a/include/modules/os_session.h b/include/modules/os_session.h index ac6bf9395..91548a5c2 100644 --- a/include/modules/os_session.h +++ b/include/modules/os_session.h @@ -51,6 +51,24 @@ class SessionService : public Service static ServiceReference<SessionService> session_service("SessionService", "session"); +namespace Event +{ + struct CoreExport Exception : Events + { + /** Called after an exception has been added + * @param ex The exception + * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it + */ + virtual EventReturn OnExceptionAdd(::Exception *ex) anope_abstract; + + /** Called before an exception is deleted + * @param source The source deleting it + * @param ex The exceotion + */ + virtual void OnExceptionDel(CommandSource &source, ::Exception *ex) anope_abstract; + }; +} + void Exception::Serialize(Serialize::Data &data) const { data["mask"] << this->mask; diff --git a/include/modules/pseudoclients/chanserv.h b/include/modules/pseudoclients/chanserv.h deleted file mode 100644 index e1c3849fd..000000000 --- a/include/modules/pseudoclients/chanserv.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CHANSERV_H -#define CHANSERV_H - -class ChanServService : public Service -{ - public: - ChanServService(Module *m) : Service(m, "ChanServService", "ChanServ") - { - } - - /* 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) = 0; -}; - -#endif // CHANSERV_H - diff --git a/include/modules/pseudoclients/global.h b/include/modules/pseudoclients/global.h deleted file mode 100644 index 1511214c9..000000000 --- a/include/modules/pseudoclients/global.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef GLOBAL_H -#define GLOBAL_H - -class GlobalService : public Service -{ - public: - GlobalService(Module *m) : Service(m, "GlobalService", "Global") - { - } - - /** Send out a global message to all users - * @param sender Our client which should send the global - * @param source The sender of the global - * @param message The message - */ - virtual void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) = 0; -}; - -#endif // GLOBAL_H - diff --git a/include/modules/pseudoclients/memoserv.h b/include/modules/pseudoclients/memoserv.h deleted file mode 100644 index d35d3f8a0..000000000 --- a/include/modules/pseudoclients/memoserv.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef MEMOSERV_H -#define MEMOSERV_H - -class MemoServService : public Service -{ - public: - enum MemoResult - { - MEMO_SUCCESS, - MEMO_INVALID_TARGET, - 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; - - /** Check for new memos and notify the user if there are any - * @param u The user - */ - virtual void Check(User *u) = 0; -}; - -#endif // MEMOSERV_H - diff --git a/include/modules/pseudoclients/nickserv.h b/include/modules/pseudoclients/nickserv.h deleted file mode 100644 index c0238ecfc..000000000 --- a/include/modules/pseudoclients/nickserv.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef NICKSERV_H -#define NICKSERV_H - -class NickServService : public Service -{ - public: - NickServService(Module *m) : Service(m, "NickServService", "NickServ") - { - } - - virtual void Validate(User *u) = 0; - virtual void Collide(User *u, NickAlias *na) = 0; - virtual void Release(NickAlias *na) = 0; -}; - -#endif // NICKSERV_H - diff --git a/include/modules/suspend.h b/include/modules/suspend.h index 1e49b8ad8..bd4eacd3b 100644 --- a/include/modules/suspend.h +++ b/include/modules/suspend.h @@ -1,11 +1,9 @@ /* - * (C) 2003-2014 Anope Team + * (C) 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. */ struct SuspendInfo @@ -16,3 +14,39 @@ struct SuspendInfo SuspendInfo() { } virtual ~SuspendInfo() { } }; + +namespace Event +{ + struct CoreExport ChanSuspend : Events + { + /** Called when a channel is suspended + * @param ci The channel + */ + virtual void OnChanSuspend(ChannelInfo *ci) anope_abstract; + }; + struct CoreExport ChanUnsuspend : Events + { + /** Called when a channel is unsuspended + * @param ci The channel + */ + virtual void OnChanUnsuspend(ChannelInfo *ci) anope_abstract; + }; + extern CoreExport EventHandlers<ChanUnsuspend> OnChanUnsuspend; + + struct CoreExport NickSuspend : Events + { + /** Called when a nick is suspended + * @param na The nick alias + */ + virtual void OnNickSuspend(NickAlias *na) anope_abstract; + }; + + struct CoreExport NickUnsuspended : Events + { + /** Called when a nick is unsuspneded + * @param na The nick alias + */ + virtual void OnNickUnsuspended(NickAlias *na) anope_abstract; + }; +} + diff --git a/include/serialize.h b/include/serialize.h index 4bfdd0cb3..22a9766d2 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -247,7 +247,7 @@ class Serialize::Reference : public ReferenceBase T *ref; public: - Reference() : ref(NULL) + Reference() : ref(nullptr) { } @@ -257,78 +257,55 @@ class Serialize::Reference : public ReferenceBase obj->AddReference(this); } - Reference(const Reference<T> &other) : ReferenceBase(other), ref(other.ref) + Reference(const Reference<T> &other) : ref(other) { - if (ref && !invalid) + if (this->ref) this->ref->AddReference(this); } ~Reference() { - if (ref && !invalid) + if (this->ref) this->ref->DelReference(this); } - inline Reference<T>& operator=(const Reference<T> &other) + void Invalidate() override + { + this->ref = nullptr; + } + + Reference<T>& operator=(const Reference<T> &other) { if (this != &other) { - if (ref && !invalid) + if (ref) this->ref->DelReference(this); this->ref = other.ref; - this->invalid = other.invalid; - if (ref && !invalid) + if (ref) this->ref->AddReference(this); } return *this; } - inline operator bool() const + explicit operator bool() const { - if (!this->invalid) - return this->ref != NULL; - return false; + return this->ref != nullptr; } - inline operator T*() const - { - if (!this->invalid) - { - if (this->ref) - // This can invalidate me - this->ref->QueueUpdate(); - if (!this->invalid) - return this->ref; - } - return NULL; - } + operator T*() const { return Dereference(); } - inline T* operator*() const - { - if (!this->invalid) - { - if (this->ref) - // This can invalidate me - this->ref->QueueUpdate(); - if (!this->invalid) - return this->ref; - } - return NULL; - } + T* operator*() const { return Dereference(); } + T* operator->() const { return Dereference(); } - inline T* operator->() const + private: + T* Dereference() const { - if (!this->invalid) - { - if (this->ref) - // This can invalidate me - this->ref->QueueUpdate(); - if (!this->invalid) - return this->ref; - } - return NULL; + if (this->ref) + // This can invalidate me + this->ref->QueueUpdate(); + return this->ref; } }; diff --git a/include/service.h b/include/service.h index 32686afb5..d8287fc52 100644 --- a/include/service.h +++ b/include/service.h @@ -23,62 +23,21 @@ */ class CoreExport Service : public virtual Base { - static std::map<Anope::string, std::map<Anope::string, Service *> > Services; - static std::map<Anope::string, std::map<Anope::string, Anope::string> > Aliases; + static std::map<Anope::string, std::map<Anope::string, Service *> > *Services; + static std::map<Anope::string, std::map<Anope::string, Anope::string> > *Aliases; - static Service *FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n) - { - std::map<Anope::string, Service *>::const_iterator it = services.find(n); - if (it != services.end()) - return it->second; + static void check(); - if (aliases != NULL) - { - std::map<Anope::string, Anope::string>::const_iterator it2 = aliases->find(n); - if (it2 != aliases->end()) - return FindService(services, aliases, it2->second); - } - - return NULL; - } + static Service *FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n); public: - static Service *FindService(const Anope::string &t, const Anope::string &n) - { - std::map<Anope::string, std::map<Anope::string, Service *> >::const_iterator it = Services.find(t); - if (it == Services.end()) - return NULL; - - std::map<Anope::string, std::map<Anope::string, Anope::string> >::const_iterator it2 = Aliases.find(t); - if (it2 != Aliases.end()) - return FindService(it->second, &it2->second, n); - - return FindService(it->second, NULL, n); - } + static Service *FindService(const Anope::string &t, const Anope::string &n); - static std::vector<Anope::string> GetServiceKeys(const Anope::string &t) - { - std::vector<Anope::string> keys; - std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = Services.find(t); - if (it != Services.end()) - for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) - keys.push_back(it2->first); - return keys; - } + static std::vector<Anope::string> GetServiceKeys(const Anope::string &t); - static void AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v) - { - std::map<Anope::string, Anope::string> &smap = Aliases[t]; - smap[n] = v; - } + static void AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v); - static void DelAlias(const Anope::string &t, const Anope::string &n) - { - std::map<Anope::string, Anope::string> &smap = Aliases[t]; - smap.erase(n); - if (smap.empty()) - Aliases.erase(t); - } + static void DelAlias(const Anope::string &t, const Anope::string &n); Module *owner; /* Service type, which should be the class name (eg "Command") */ @@ -86,31 +45,15 @@ class CoreExport Service : public virtual Base /* Service name, commands are usually named service/command */ Anope::string name; - Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n) - { - this->Register(); - } + Service(Module *o, const Anope::string &t, const Anope::string &n); - virtual ~Service() - { - this->Unregister(); - } + Service(const Service &) = delete; - void Register() - { - std::map<Anope::string, Service *> &smap = Services[this->type]; - if (smap.find(this->name) != smap.end()) - throw ModuleException("Service " + this->type + " with name " + this->name + " already exists"); - smap[this->name] = this; - } + virtual ~Service(); - void Unregister() - { - std::map<Anope::string, Service *> &smap = Services[this->type]; - smap.erase(this->name); - if (smap.empty()) - Services.erase(this->type); - } + void Register(); + + void Unregister(); }; /** Like Reference, but used to refer to Services. @@ -120,6 +63,7 @@ class ServiceReference : public Reference<T> { Anope::string type; Anope::string name; + bool need_check = true; public: ServiceReference() { } @@ -128,45 +72,39 @@ class ServiceReference : public Reference<T> { } - inline void operator=(const Anope::string &n) + void operator=(const Anope::string &n) { this->name = n; - this->invalid = true; } - operator bool() override + void Check() override { - if (this->invalid) - { - this->invalid = false; - this->ref = NULL; - } - if (!this->ref) + if (need_check) { - /* This really could be dynamic_cast in every case, except for when a module - * creates its own service type (that other modules must include the header file - * for), as the core is not compiled with it so there is no RTTI for it. - */ - this->ref = static_cast<T *>(::Service::FindService(this->type, this->name)); + need_check = false; + + this->ref = static_cast<T *>(Service::FindService(this->type, this->name)); if (this->ref) + { this->ref->AddReference(this); + this->OnAcquire(); + } } - return this->ref; } + + void Reset() override + { + need_check = true; + } + + virtual void OnAcquire() { } }; class ServiceAlias { Anope::string t, f; public: - ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from) - { - Service::AddAlias(type, from, to); - } - - ~ServiceAlias() - { - Service::DelAlias(t, f); - } + ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to); + ~ServiceAlias(); }; diff --git a/include/services.h b/include/services.h index 5965cea09..b29773242 100644 --- a/include/services.h +++ b/include/services.h @@ -56,3 +56,5 @@ # include "anope_windows.h" #endif +#define anope_abstract = 0 + diff --git a/modules/bs_autoassign.cpp b/modules/bs_autoassign.cpp index f13843648..e7543d646 100644 --- a/modules/bs_autoassign.cpp +++ b/modules/bs_autoassign.cpp @@ -10,9 +10,11 @@ #include "module.h" class BSAutoAssign : public Module + , public EventHook<Event::ChanRegistered> { public: BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanRegistered>("OnChanRegistered") { } diff --git a/modules/commands/bs_assign.cpp b/modules/commands/bs_assign.cpp index 3bd00a372..90fb7ed56 100644 --- a/modules/commands/bs_assign.cpp +++ b/modules/commands/bs_assign.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/bs_info.h" class CommandBSAssign : public Command { @@ -203,6 +204,8 @@ class CommandBSSetNoBot : public Command }; class BSAssign : public Module + , public EventHook<Event::Invite> + , public EventHook<Event::BotInfoEvent> { ExtensibleItem<bool> nobot; @@ -211,9 +214,13 @@ class BSAssign : public Module CommandBSSetNoBot commandbssetnobot; public: - BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - nobot(this, "BS_NOBOT"), - commandbsassign(this), commandbsunassign(this), commandbssetnobot(this) + BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Invite>("OnInvite") + , EventHook<Event::BotInfoEvent>("OnBotInfoEvent") + , nobot(this, "BS_NOBOT") + , commandbsassign(this) + , commandbsunassign(this) + , commandbssetnobot(this) { } diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 551e89987..082dae0bd 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -12,6 +12,8 @@ #include "module.h" #include "modules/bs_badwords.h" +static EventHandlers<Event::BadWordEvents> *bwevents; + struct BadWordImpl : BadWord, Serializable { BadWordImpl() : Serializable("BadWord") { } @@ -46,7 +48,7 @@ struct BadWordsImpl : BadWords this->badwords->push_back(bw); - FOREACH_MOD(OnBadWordAdd, (ci, bw)); + (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw); return bw; } @@ -71,7 +73,7 @@ struct BadWordsImpl : BadWords if (this->badwords->empty() || index >= this->badwords->size()) return; - FOREACH_MOD(OnBadWordDel, (ci, (*this->badwords)[index])); + (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, (*this->badwords)[index]); delete this->badwords->at(index); } @@ -457,11 +459,16 @@ class BSBadwords : public Module CommandBSBadwords commandbsbadwords; ExtensibleItem<BadWordsImpl> badwords; Serialize::Type badword_type; + EventHandlers<Event::BadWordEvents> events; public: - BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbsbadwords(this), badwords(this, "badwords"), badword_type("BadWord", BadWordImpl::Unserialize) + BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsbadwords(this) + , badwords(this, "badwords") + , badword_type("BadWord", BadWordImpl::Unserialize) + , events(this, "Badwords") { + bwevents = &events; } }; diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index 46550603d..9aa572f00 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -10,10 +10,14 @@ */ #include "module.h" +#include "modules/bs_bot.h" class CommandBSBot : public Command { - private: + EventHandlers<Event::BotCreate> OnBotCreate; + EventHandlers<Event::BotChange> OnBotChange; + EventHandlers<Event::BotDelete> OnBotDelete; + void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &nick = params[1]; @@ -81,8 +85,7 @@ class CommandBSBot : public Command source.Reply(_("%s!%s@%s (%s) added to the bot list."), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); - FOREACH_MOD(OnBotCreate, (bi)); - return; + this->OnBotCreate(&Event::BotCreate::OnBotCreate, bi); } void DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -220,8 +223,7 @@ class CommandBSBot : public Command source.Reply(_("Bot \002%s\002 has been changed to %s!%s@%s (%s)."), oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; - FOREACH_MOD(OnBotChange, (bi)); - return; + this->OnBotChange(&Event::BotChange::OnBotChange, bi); } void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -247,16 +249,16 @@ class CommandBSBot : public Command return; } - FOREACH_MOD(OnBotDelete, (bi)); + this->OnBotDelete(&Event::BotDelete::OnBotDelete, bi); Log(LOG_ADMIN, source, this) << "DEL " << bi->nick; source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str()); delete bi; - return; } + public: - CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6) + CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6), OnBotCreate(creator, "OnBotCreate"), OnBotChange(creator, "OnBotChange"), OnBotDelete(creator, "OnBotDelete") { this->SetDesc(_("Maintains network bot list")); this->SetSyntax(_("\002ADD \037nick\037 \037user\037 \037host\037 \037real\037\002")); @@ -367,8 +369,8 @@ class BSBot : public Module CommandBSBot commandbsbot; public: - BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbsbot(this) + BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsbot(this) { } diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index 2bab21881..2ee130aba 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -72,8 +72,8 @@ class BSBotList : public Module CommandBSBotList commandbsbotlist; public: - BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbsbotlist(this) + BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsbotlist(this) { } diff --git a/modules/commands/bs_control.cpp b/modules/commands/bs_control.cpp index 0843c6150..38745c191 100644 --- a/modules/commands/bs_control.cpp +++ b/modules/commands/bs_control.cpp @@ -136,8 +136,8 @@ class BSControl : public Module CommandBSAct commandbsact; public: - BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbssay(this), commandbsact(this) + BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbssay(this), commandbsact(this) { } diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index b04a62c8f..49775a053 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -10,7 +10,9 @@ * * */ + #include "module.h" +#include "modules/bs_info.h" class CommandBSInfo : public Command { @@ -36,8 +38,10 @@ class CommandBSInfo : public Command buffers.push_back(buf); } + EventHandlers<Event::BotInfoEvent> &onbotinfo; + public: - CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1) + CommandBSInfo(Module *creator, EventHandlers<Event::BotInfoEvent> &event) : Command(creator, "botserv/info", 1, 1), onbotinfo(event) { this->SetSyntax(_("{\037channel\037 | \037nickname\037}")); } @@ -59,7 +63,7 @@ class CommandBSInfo : public Command info[_("Options")] = bi->oper_only ? _("Private") : _("None"); info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)"; - FOREACH_MOD(OnBotInfo, (source, bi, ci, info)); + this->onbotinfo(&Event::BotInfoEvent::OnBotInfo, source, bi, ci, info); std::vector<Anope::string> replies; info.Process(replies); @@ -90,7 +94,7 @@ class CommandBSInfo : public Command Anope::string enabled = Language::Translate(source.nc, _("Enabled")); Anope::string disabled = Language::Translate(source.nc, _("Disabled")); - FOREACH_MOD(OnBotInfo, (source, bi, ci, info)); + this->onbotinfo(&Event::BotInfoEvent::OnBotInfo, source, bi, ci, info); std::vector<Anope::string> replies; info.Process(replies); @@ -123,10 +127,11 @@ class CommandBSInfo : public Command class BSInfo : public Module { CommandBSInfo commandbsinfo; + EventHandlers<Event::BotInfoEvent> onbotinfo; public: - BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbsinfo(this) + BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandbsinfo(this, onbotinfo), onbotinfo(this, "OnBotInfo") { } diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 242043105..3a4d78c93 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -14,6 +14,7 @@ #include "module.h" #include "modules/bs_kick.h" #include "modules/bs_badwords.h" +#include "modules/bs_info.h" static Module *me; @@ -998,6 +999,8 @@ class BanDataPurger : public Timer }; class BSKick : public Module + , public EventHook<Event::BotInfoEvent> + , public EventHook<Event::Privmsg> { ExtensibleItem<BanData> bandata; ExtensibleItem<UserData> userdata; @@ -1020,6 +1023,8 @@ class BSKick : public Module BanDataPurger purger; + EventHandlers<Event::BotBan> onbotban; + BanData::Data &GetBanData(User *u, Channel *c) { BanData *bd = bandata.Require(c); @@ -1056,7 +1061,7 @@ class BSKick : public Module Anope::string mask = ci->GetIdealBan(u); ci->c->SetMode(NULL, "BAN", mask); - FOREACH_MOD(OnBotBan, (u, ci, mask)); + this->onbotban(&Event::BotBan::OnBotBan, u, ci, mask); } } @@ -1077,19 +1082,31 @@ class BSKick : public Module } public: - BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - bandata(this, "bandata"), - userdata(this, "userdata"), - kickerdata(this, "kickerdata"), - - commandbskick(this), - commandbskickamsg(this), commandbskickbadwords(this), commandbskickbolds(this), commandbskickcaps(this), - commandbskickcolors(this), commandbskickflood(this), commandbskickitalics(this), commandbskickrepeat(this), - commandbskickreverse(this), commandbskickunderlines(this), - - commandbssetdontkickops(this), commandbssetdontkickvoices(this), - - purger(this) + BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::BotInfoEvent>("OnBotInfoEvent") + , EventHook<Event::Privmsg>("OnPrivmsg") + , bandata(this, "bandata") + , userdata(this, "userdata") + , kickerdata(this, "kickerdata") + + , commandbskick(this) + , commandbskickamsg(this) + , commandbskickbadwords(this) + , commandbskickbolds(this) + , commandbskickcaps(this) + , commandbskickcolors(this) + , commandbskickflood(this) + , commandbskickitalics(this) + , commandbskickrepeat(this) + , commandbskickreverse(this) + , commandbskickunderlines(this) + + , commandbssetdontkickops(this) + , commandbssetdontkickvoices(this) + + , purger(this) + + , onbotban(this, "OnBotBan") { me = this; diff --git a/modules/commands/bs_set.cpp b/modules/commands/bs_set.cpp index a69ebb8cf..68aaf8d47 100644 --- a/modules/commands/bs_set.cpp +++ b/modules/commands/bs_set.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/bs_kick.h" class CommandBSSet : public Command { @@ -192,15 +193,18 @@ class CommandBSSetPrivate : public Command }; class BSSet : public Module + , public EventHook<Event::BotBan> { CommandBSSet commandbsset; CommandBSSetBanExpire commandbssetbanexpire; CommandBSSetPrivate commandbssetprivate; public: - BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbsset(this), commandbssetbanexpire(this), - commandbssetprivate(this) + BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::BotBan>("OnBotBan") + , commandbsset(this) + , commandbssetbanexpire(this) + , commandbssetprivate(this) { } diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 59e028d6c..3bfbde97d 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/cs_access.h" static std::map<Anope::string, int16_t, ci::less> defaultLevels; @@ -212,7 +213,7 @@ class CommandCSAccess : public Command access->created = Anope::CurTime; ci->AddAccess(access); - FOREACH_MOD(OnAccessAdd, (ci, source, access)); + Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << " with level " << level; if (p != NULL) @@ -298,7 +299,7 @@ class CommandCSAccess : public Command ci->EraseAccess(Number - 1); - FOREACH_MOD(OnAccessDel, (ci, source, access)); + Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, access); delete access; } } @@ -324,7 +325,7 @@ class CommandCSAccess : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << access->mask; ci->EraseAccess(i - 1); - FOREACH_MOD(OnAccessDel, (ci, source, access)); + Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, access); delete access; } return; @@ -475,7 +476,7 @@ class CommandCSAccess : public Command source.Reply(ACCESS_DENIED); else { - FOREACH_MOD(OnAccessClear, (ci, source)); + Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source); ci->ClearAccess(); @@ -646,7 +647,7 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to set " << p->name << " to level " << level; ci->SetLevel(p->name, level); - FOREACH_MOD(OnLevelChange, (source, ci, p->name, level)); + this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); if (level == ACCESS_FOUNDER) source.Reply(_("Level for %s on channel %s changed to founder only."), p->name.c_str(), ci->name.c_str()); @@ -674,7 +675,7 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable " << p->name; ci->SetLevel(p->name, ACCESS_INVALID); - FOREACH_MOD(OnLevelChange, (source, ci, p->name, ACCESS_INVALID)); + this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, ACCESS_INVALID); source.Reply(_("\002%s\002 disabled on channel %s."), p->name.c_str(), ci->name.c_str()); return; @@ -723,14 +724,15 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to reset all levels"; reset_levels(ci); - FOREACH_MOD(OnLevelChange, (source, ci, "ALL", 0)); + this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0); source.Reply(_("Access levels for \002%s\002 reset to defaults."), ci->name.c_str()); - return; } + EventHandlers<Event::LevelChange> &onlevelchange; + public: - CommandCSLevels(Module *creator) : Command(creator, "chanserv/levels", 2, 4) + CommandCSLevels(Module *creator, EventHandlers<Event::LevelChange> &event) : Command(creator, "chanserv/levels", 2, 4), onlevelchange(event) { this->SetDesc(_("Redefine the meanings of access levels")); this->SetSyntax(_("\037channel\037 SET \037type\037 \037level\037")); @@ -829,14 +831,22 @@ class CommandCSLevels : public Command }; class CSAccess : public Module + , public EventHook<Event::CreateChan> + , public EventHook<Event::GroupCheckPriv> { AccessAccessProvider accessprovider; CommandCSAccess commandcsaccess; CommandCSLevels commandcslevels; + EventHandlers<Event::LevelChange> onlevelchange; public: - CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - accessprovider(this), commandcsaccess(this), commandcslevels(this) + CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::CreateChan>("OnCreateChan") + , EventHook<Event::GroupCheckPriv>("OnGroupCheckPriv") + , accessprovider(this) + , commandcsaccess(this) + , commandcslevels(this, onlevelchange) + , onlevelchange(this, "OnLevelChange") { this->SetPermanent(true); diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 1aff37eb5..61bc23181 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/cs_akick.h" class CommandCSAKick : public Command { @@ -160,7 +161,7 @@ class CommandCSAKick : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason; - FOREACH_MOD(OnAkickAdd, (source, ci, akick)); + this->akickevents(&Event::Akick::OnAkickAdd, source, ci, akick); source.Reply(_("\002%s\002 added to %s autokick list."), mask.c_str(), ci->name.c_str()); @@ -185,11 +186,11 @@ class CommandCSAKick : public Command { CommandSource &source; ChannelInfo *ci; - Command *c; + CommandCSAKick *c; unsigned deleted; AccessGroup ag; public: - AkickDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), deleted(0), ag(source.AccessFor(ci)) + 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)) { } @@ -210,7 +211,7 @@ class CommandCSAKick : public Command const AutoKick *akick = ci->GetAkick(number - 1); - FOREACH_MOD(OnAkickDel, (source, ci, akick)); + c->akickevents(&Event::Akick::OnAkickDel, source, ci, akick); bool override = !ag.HasPriv("AKICK"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, c, ci) << "to delete " << (akick->nc ? akick->nc->display : akick->mask); @@ -244,7 +245,7 @@ class CommandCSAKick : public Command bool override = !source.AccessFor(ci).HasPriv("AKICK"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; - FOREACH_MOD(OnAkickDel, (source, ci, ci->GetAkick(i))); + this->akickevents(&Event::Akick::OnAkickDel, source, ci, ci->GetAkick(i)); ci->EraseAkick(i); @@ -416,8 +417,10 @@ class CommandCSAKick : public Command source.Reply(_("Channel %s akick list has been cleared."), ci->name.c_str()); } + EventHandlers<Event::Akick> &akickevents; + public: - CommandCSAKick(Module *creator) : Command(creator, "chanserv/akick", 2, 4) + CommandCSAKick(Module *creator, EventHandlers<Event::Akick> &events) : Command(creator, "chanserv/akick", 2, 4), akickevents(events) { this->SetDesc(_("Maintain the AutoKick list")); this->SetSyntax(_("\037channel\037 ADD {\037nick\037 | \037mask\037} [\037reason\037]")); @@ -509,12 +512,16 @@ class CommandCSAKick : public Command }; class CSAKick : public Module + , public EventHook<Event::CheckKick> { CommandCSAKick commandcsakick; + EventHandlers<Event::Akick> akickevents; public: - CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsakick(this) + CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::CheckKick>("OnCheckKick") + , commandcsakick(this, akickevents) + , akickevents(this, "Akick") { } diff --git a/modules/commands/cs_ban.cpp b/modules/commands/cs_ban.cpp index 3a5e335f1..a6a1f4af6 100644 --- a/modules/commands/cs_ban.cpp +++ b/modules/commands/cs_ban.cpp @@ -217,7 +217,8 @@ class CSBan : public Module CommandCSBan commandcsban; public: - CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsban(this) + CSBan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsban(this) { me = this; } diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp index bfe21783b..e7102091a 100644 --- a/modules/commands/cs_clone.cpp +++ b/modules/commands/cs_clone.cpp @@ -100,7 +100,7 @@ public: else target_ci->last_topic_setter = source.service->nick; - FOREACH_MOD(OnChanRegistered, (target_ci)); + Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, target_ci); source.Reply(_("All settings from \002%s\002 have been cloned to \002%s\002."), channel.c_str(), target.c_str()); } @@ -204,7 +204,8 @@ class CSClone : public Module CommandCSClone commandcsclone; public: - CSClone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsclone(this) + CSClone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsclone(this) { } diff --git a/modules/commands/cs_drop.cpp b/modules/commands/cs_drop.cpp index 03d24a18d..3b6c82ed0 100644 --- a/modules/commands/cs_drop.cpp +++ b/modules/commands/cs_drop.cpp @@ -10,11 +10,14 @@ */ #include "module.h" +#include "modules/cs_drop.h" class CommandCSDrop : public Command { + EventHandlers<Event::ChanDrop> &onchandrop; + public: - CommandCSDrop(Module *creator) : Command(creator, "chanserv/drop", 1, 2) + CommandCSDrop(Module *creator, EventHandlers<Event::ChanDrop> &event) : Command(creator, "chanserv/drop", 1, 2), onchandrop(event) { this->SetDesc(_("Cancel the registration of a channel")); this->SetSyntax(_("\037channel\037 \037channel\037")); @@ -49,8 +52,7 @@ class CommandCSDrop : public Command return; } - EventReturn MOD_RESULT; - FOREACH_RESULT(OnChanDrop, MOD_RESULT, (source, ci)); + EventReturn MOD_RESULT = this->onchandrop(&Event::ChanDrop::OnChanDrop, source, ci); if (MOD_RESULT == EVENT_STOP) return; @@ -84,9 +86,12 @@ class CommandCSDrop : public Command class CSDrop : public Module { CommandCSDrop commandcsdrop; + EventHandlers<Event::ChanDrop> onchandrop; public: - CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsdrop(this) + CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsdrop(this, onchandrop) + , onchandrop(this, "OnChanDrop") { } diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index 5ea267e6f..aa710ef03 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -282,8 +282,8 @@ class CSEnforce : public Module CommandCSEnforce commandcsenforce; public: - CSEnforce(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsenforce(this) + CSEnforce(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsenforce(this) { } diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index d9948a52f..676d7b74a 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -258,15 +258,18 @@ class CommandEntryMessage : public Command }; class CSEntryMessage : public Module + , public EventHook<Event::JoinChannel> { CommandEntryMessage commandentrymsg; ExtensibleItem<EntryMessageListImpl> eml; Serialize::Type entrymsg_type; public: - CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandentrymsg(this), - eml(this, "entrymsg"), entrymsg_type("EntryMsg", EntryMsgImpl::Unserialize) + CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::JoinChannel>("OnJoinChannel") + , commandentrymsg(this) + , eml(this, "entrymsg") + , entrymsg_type("EntryMsg", EntryMsgImpl::Unserialize) { } diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index b2ade785f..1298f74c5 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -244,7 +244,7 @@ class CommandCSFlags : public Command if (current != NULL) { ci->EraseAccess(current_idx - 1); - FOREACH_MOD(OnAccessDel, (ci, source, current)); + Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, current); delete current; Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; source.Reply(_("\002%s\002 removed from the %s access list."), mask.c_str(), ci->name.c_str()); @@ -272,7 +272,7 @@ class CommandCSFlags : public Command ci->AddAccess(access); - FOREACH_MOD(OnAccessAdd, (ci, source, access)); + Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to modify " << mask << "'s flags to " << access->AccessSerialize(); if (p != NULL) @@ -356,7 +356,7 @@ class CommandCSFlags : public Command { ci->ClearAccess(); - FOREACH_MOD(OnAccessClear, (ci, source)); + Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source); source.Reply(_("Channel %s access list has been cleared."), ci->name.c_str()); @@ -457,8 +457,9 @@ class CSFlags : public Module CommandCSFlags commandcsflags; public: - CSFlags(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - accessprovider(this), commandcsflags(this) + CSFlags(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , accessprovider(this) + , commandcsflags(this) { this->SetPermanent(true); diff --git a/modules/commands/cs_getkey.cpp b/modules/commands/cs_getkey.cpp index 187c01c68..6b714d093 100644 --- a/modules/commands/cs_getkey.cpp +++ b/modules/commands/cs_getkey.cpp @@ -64,7 +64,8 @@ class CSGetKey : public Module CommandCSGetKey commandcsgetkey; public: - CSGetKey(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsgetkey(this) + CSGetKey(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsgetkey(this) { } diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp index 06130f15e..d0ae17a7e 100644 --- a/modules/commands/cs_info.cpp +++ b/modules/commands/cs_info.cpp @@ -10,11 +10,14 @@ */ #include "module.h" +#include "modules/cs_info.h" class CommandCSInfo : public Command { + EventHandlers<Event::ChanInfo> &eventonchaninfo; + public: - CommandCSInfo(Module *creator) : Command(creator, "chanserv/info", 1, 2) + CommandCSInfo(Module *creator, EventHandlers<Event::ChanInfo> &event) : Command(creator, "chanserv/info", 1, 2), eventonchaninfo(event) { this->SetDesc(_("Lists information about the named registered channel")); this->SetSyntax(_("\037channel\037")); @@ -60,7 +63,7 @@ class CommandCSInfo : public Command info[_("Ban type")] = stringify(ci->bantype); } - FOREACH_MOD(OnChanInfo, (source, ci, info, show_all)); + this->eventonchaninfo(&Event::ChanInfo::OnChanInfo, source, ci, info, show_all); std::vector<Anope::string> replies; info.Process(replies); @@ -86,10 +89,12 @@ class CommandCSInfo : public Command class CSInfo : public Module { CommandCSInfo commandcsinfo; + EventHandlers<Event::ChanInfo> eventonchaninfo; public: - CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsinfo(this) + CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsinfo(this, eventonchaninfo) + , eventonchaninfo(this, "OnChanInfo") { } diff --git a/modules/commands/cs_invite.cpp b/modules/commands/cs_invite.cpp index 0058f4ee6..6f19042cc 100644 --- a/modules/commands/cs_invite.cpp +++ b/modules/commands/cs_invite.cpp @@ -102,7 +102,8 @@ class CSInvite : public Module CommandCSInvite commandcsinvite; public: - CSInvite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsinvite(this) + CSInvite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsinvite(this) { } diff --git a/modules/commands/cs_kick.cpp b/modules/commands/cs_kick.cpp index 55e0a6718..bfaec6a29 100644 --- a/modules/commands/cs_kick.cpp +++ b/modules/commands/cs_kick.cpp @@ -125,7 +125,8 @@ class CSKick : public Module CommandCSKick commandcskick; public: - CSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcskick(this) + CSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcskick(this) { } diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp index 735a836de..68cca6d42 100644 --- a/modules/commands/cs_list.cpp +++ b/modules/commands/cs_list.cpp @@ -10,6 +10,8 @@ */ #include "module.h" +#include "modules/cs_info.h" +#include "modules/cs_set.h" class CommandCSList : public Command { @@ -190,8 +192,7 @@ class CommandCSSetPrivate : public Command return; } - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + EventReturn MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -235,6 +236,7 @@ class CommandCSSetPrivate : public Command }; class CSList : public Module + , public EventHook<Event::ChanInfo> { CommandCSList commandcslist; CommandCSSetPrivate commandcssetprivate; @@ -242,8 +244,11 @@ class CSList : public Module SerializableExtensibleItem<bool> priv; public: - CSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcslist(this), commandcssetprivate(this), priv(this, "CS_PRIVATE") + CSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanInfo>("OnChanInfo") + , commandcslist(this) + , commandcssetprivate(this) + , priv(this, "CS_PRIVATE") { } diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp index 8fb253321..678a2fd5f 100644 --- a/modules/commands/cs_log.cpp +++ b/modules/commands/cs_log.cpp @@ -11,6 +11,7 @@ #include "module.h" #include "modules/cs_log.h" +#include "modules/memoserv.h" struct LogSettingImpl : LogSetting, Serializable { @@ -280,8 +281,9 @@ public: }; class CSLog : public Module + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::Log> { - ServiceReference<MemoServService> MSService; CommandCSLog commandcslog; ExtensibleItem<LogSettingsImpl> logsettings; Serialize::Type logsetting_type; @@ -294,9 +296,12 @@ class CSLog : public Module std::vector<LogDefault> defaults; public: - CSLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - MSService("MemoServService", "MemoServ"), commandcslog(this), - logsettings(this, "logsettings"), logsetting_type("LogSetting", LogSettingImpl::Unserialize) + CSLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanRegistered>("OnChanRegistered") + , EventHook<Event::Log>("OnLog") + , commandcslog(this) + , logsettings(this, "logsettings") + , logsetting_type("LogSetting", LogSettingImpl::Unserialize) { } @@ -353,7 +358,7 @@ class CSLog : public Module } } - void OnLog(Log *l) override + void OnLog(::Log *l) override { if (l->type != LOG_COMMAND || l->u == NULL || l->c == NULL || l->ci == NULL || !Me || !Me->IsSynced()) return; @@ -381,8 +386,8 @@ class CSLog : public Module Anope::string buffer = l->u->nick + " used " + l->source->command.upper() + " " + l->buf.str(); - if (log->method.equals_ci("MEMO") && MSService && l->ci->WhoSends() != NULL) - MSService->Send(l->ci->WhoSends()->nick, l->ci->name, buffer, true); + if (log->method.equals_ci("MEMO") && MemoServ::service && l->ci->WhoSends() != NULL) + MemoServ::service->Send(l->ci->WhoSends()->nick, l->ci->name, buffer, true); else if (l->source->c) /* Sending a channel message or notice in response to a fantasy command */; else if (log->method.equals_ci("MESSAGE") && l->ci->c) diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp index ed54c5164..2e858b382 100644 --- a/modules/commands/cs_mode.cpp +++ b/modules/commands/cs_mode.cpp @@ -11,6 +11,9 @@ #include "module.h" #include "modules/cs_mode.h" +#include "modules/cs_info.h" + +static EventHandlers<Event::MLockEvents> *events; struct ModeLockImpl : ModeLock, Serializable { @@ -87,7 +90,7 @@ struct ModeLocksImpl : ModeLocks ml->created = created; EventReturn MOD_RESULT; - FOREACH_RESULT(OnMLock, MOD_RESULT, (this->ci, ml)); + MOD_RESULT = (*events)(&Event::MLockEvents::OnMLock, this->ci, ml); if (MOD_RESULT == EVENT_STOP) { delete ml; @@ -115,7 +118,7 @@ struct ModeLocksImpl : ModeLocks continue; EventReturn MOD_RESULT; - FOREACH_RESULT(OnUnMLock, MOD_RESULT, (this->ci, m)); + MOD_RESULT = (*events)(&Event::MLockEvents::OnUnMLock, this->ci, m); if (MOD_RESULT == EVENT_STOP) break; @@ -863,19 +866,29 @@ class CommandCSModes : public Command }; class CSMode : public Module + , public EventHook<Event::CheckModes> + , public EventHook<Event::CreateChan> + , public EventHook<Event::ChanInfo> { CommandCSMode commandcsmode; CommandCSModes commandcsmodes; ExtensibleItem<ModeLocksImpl> modelocks; Serialize::Type modelocks_type; + EventHandlers<Event::MLockEvents> modelockevents; + public: - CSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsmode(this), commandcsmodes(this), - modelocks(this, "modelocks"), - modelocks_type("ModeLock", ModeLockImpl::Unserialize) + CSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::CheckModes>("OnCheckModes") + , EventHook<Event::CreateChan>("OnCreateChan") + , EventHook<Event::ChanInfo>("OnChanInfo") + , commandcsmode(this) + , commandcsmodes(this) + , modelocks(this, "modelocks") + , modelocks_type("ModeLock", ModeLockImpl::Unserialize) + , modelockevents(this, "MLock") { - + events = &modelockevents; } void OnReload(Configuration::Conf *conf) override diff --git a/modules/commands/cs_register.cpp b/modules/commands/cs_register.cpp index dda906fcd..7b2899939 100644 --- a/modules/commands/cs_register.cpp +++ b/modules/commands/cs_register.cpp @@ -75,7 +75,7 @@ class CommandCSRegister : public Command c->SetCorrectModes(u, true); } - FOREACH_MOD(OnChanRegistered, (ci)); + Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, ci); } } @@ -115,8 +115,8 @@ class CSRegister : public Module CommandCSRegister commandcsregister; public: - CSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsregister(this) + CSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsregister(this) { } }; diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index db0195aa3..595b999c9 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -367,12 +367,30 @@ class CommandSeen : public Command }; class CSSeen : public Module + , public EventHook<Event::ExpireTick> + , public EventHook<Event::UserConnect> + , public EventHook<Event::UserNickChange> + , public EventHook<Event::UserQuit> + , public EventHook<Event::JoinChannel> + , public EventHook<Event::PartChannel> + , public EventHook<Event::PreUserKicked> { Serialize::Type seeninfo_type; CommandSeen commandseen; CommandOSSeen commandosseen; + public: - CSSeen(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), seeninfo_type("SeenInfo", SeenInfo::Unserialize), commandseen(this), commandosseen(this) + CSSeen(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ExpireTick>("OnExpireTick") + , EventHook<Event::UserConnect>("OnUserConnect") + , EventHook<Event::UserNickChange>("OnUserNickChange") + , EventHook<Event::UserQuit>("OnUserQuit") + , EventHook<Event::JoinChannel>("OnJoinChannel") + , EventHook<Event::PartChannel>("OnPartChannel") + , EventHook<Event::PreUserKicked>("OnPreUserKicked") + , seeninfo_type("SeenInfo", SeenInfo::Unserialize) + , commandseen(this) + , commandosseen(this) { } diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 503941c82..4beb54070 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -11,6 +11,9 @@ #include "module.h" #include "modules/cs_mode.h" +#include "modules/chanserv.h" +#include "modules/cs_info.h" +#include "modules/cs_set.h" class CommandCSSet : public Command { @@ -87,8 +90,7 @@ class CommandCSSetAutoOp : public Command return; } - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + EventReturn MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -151,7 +153,7 @@ class CommandCSSetBanType : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -219,7 +221,7 @@ class CommandCSSetDescription : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, param)); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -280,7 +282,7 @@ class CommandCSSetFounder : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -349,7 +351,7 @@ class CommandCSSetKeepModes : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -414,7 +416,7 @@ class CommandCSSetPeace : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -486,7 +488,7 @@ class CommandCSSetPersist : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -649,7 +651,7 @@ class CommandCSSetRestricted : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -711,7 +713,7 @@ class CommandCSSetSecure : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -775,7 +777,7 @@ class CommandCSSetSecureFounder : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -839,7 +841,7 @@ class CommandCSSetSecureOps : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -901,7 +903,7 @@ class CommandCSSetSignKick : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -979,7 +981,7 @@ class CommandCSSetSuccessor : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, param)); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -1098,6 +1100,18 @@ class CommandCSSetNoexpire : public Command }; class CSSet : public Module + , public EventHook<Event::CreateChan> + , public EventHook<Event::ChannelCreate> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::CheckKick> + , public EventHook<Event::DelChan> + , public EventHook<Event::ChannelModeSet> + , public EventHook<Event::ChannelModeUnset> + , public EventHook<Event::CheckDelete> + , public EventHook<Event::JoinChannel> + , public EventHook<Event::SetCorrectModes> + , public EventHook<ChanServ::Event::PreChanExpire> + , public EventHook<Event::ChanInfo> { SerializableExtensibleItem<bool> noautoop, peace, securefounder, restricted, secure, secureops, signkick, signkick_level, noexpire; @@ -1210,18 +1224,46 @@ class CSSet : public Module bool persist_lower_ts; public: - CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - noautoop(this, "NOAUTOOP"), peace(this, "PEACE"), - securefounder(this, "SECUREFOUNDER"), restricted(this, "RESTRICTED"), - secure(this, "CS_SECURE"), secureops(this, "SECUREOPS"), signkick(this, "SIGNKICK"), - signkick_level(this, "SIGNKICK_LEVEL"), noexpire(this, "CS_NO_EXPIRE"), - keep_modes(this, "CS_KEEP_MODES"), persist(this, "PERSIST"), - - commandcsset(this), commandcssetautoop(this), commandcssetbantype(this), - commandcssetdescription(this), commandcssetfounder(this), commandcssetkeepmodes(this), - commandcssetpeace(this), commandcssetpersist(this), commandcssetrestricted(this), - commandcssetsecure(this), commandcssetsecurefounder(this), commandcssetsecureops(this), commandcssetsignkick(this), - commandcssetsuccessor(this), commandcssetnoexpire(this) + CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::CreateChan>("OnCreateChan") + , EventHook<Event::ChannelCreate>("OnChannelCreate") + , EventHook<Event::ChannelSync>("OnChannelSync") + , EventHook<Event::CheckKick>("OnCheckKick") + , EventHook<Event::DelChan>("OnDelChan") + , EventHook<Event::ChannelModeSet>("OnChannelModeSet") + , EventHook<Event::ChannelModeUnset>("OnChannelModeUnset") + , EventHook<Event::CheckDelete>("OnCheckDelete") + , EventHook<Event::JoinChannel>("OnJoinChannel") + , EventHook<Event::SetCorrectModes>("OnSetCorrectModes") + , EventHook<ChanServ::Event::PreChanExpire>("OnPreChanExpire") + , EventHook<Event::ChanInfo>("OnChanInfo") + , noautoop(this, "NOAUTOOP") + , peace(this, "PEACE") + , securefounder(this, "SECUREFOUNDER") + , restricted(this, "RESTRICTED") + , secure(this, "CS_SECURE") + , secureops(this, "SECUREOPS") + , signkick(this, "SIGNKICK") + , signkick_level(this, "SIGNKICK_LEVEL") + , noexpire(this, "CS_NO_EXPIRE") + , keep_modes(this, "CS_KEEP_MODES") + , persist(this, "PERSIST") + + , commandcsset(this) + , commandcssetautoop(this) + , commandcssetbantype(this) + , commandcssetdescription(this) + , commandcssetfounder(this) + , commandcssetkeepmodes(this) + , commandcssetpeace(this) + , commandcssetpersist(this) + , commandcssetrestricted(this) + , commandcssetsecure(this) + , commandcssetsecurefounder(this) + , commandcssetsecureops(this) + , commandcssetsignkick(this) + , commandcssetsuccessor(this) + , commandcssetnoexpire(this) { } diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 41abd6138..3d8dbb0dd 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -10,6 +10,8 @@ #include "module.h" #include "modules/set_misc.h" +#include "modules/cs_info.h" +#include "modules/cs_set.h" static Module *me; @@ -112,7 +114,7 @@ class CommandCSSetMisc : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, param)); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -163,13 +165,16 @@ class CommandCSSetMisc : public Command }; class CSSetMisc : public Module + , public EventHook<Event::ChanInfo> { CommandCSSetMisc commandcssetmisc; Serialize::Type csmiscdata_type; public: - CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcssetmisc(this), csmiscdata_type("CSMiscData", CSMiscData::Unserialize) + CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanInfo>("OnChanInfo") + , commandcssetmisc(this) + , csmiscdata_type("CSMiscData", CSMiscData::Unserialize) { me = this; } diff --git a/modules/commands/cs_status.cpp b/modules/commands/cs_status.cpp index 659119d06..bd707d537 100644 --- a/modules/commands/cs_status.cpp +++ b/modules/commands/cs_status.cpp @@ -102,7 +102,8 @@ class CSStatus : public Module CommandCSStatus commandcsstatus; public: - CSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsstatus(this) + CSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsstatus(this) { } }; diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index b7d22ae41..7b604b250 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -11,6 +11,9 @@ #include "module.h" #include "modules/suspend.h" +#include "modules/cs_drop.h" +#include "modules/chanserv.h" +#include "modules/cs_info.h" struct CSSuspendInfo : SuspendInfo, Serializable { @@ -52,8 +55,9 @@ struct CSSuspendInfo : SuspendInfo, Serializable class CommandCSSuspend : public Command { + EventHandlers<Event::ChanSuspend> &onchansuspend; public: - CommandCSSuspend(Module *creator) : Command(creator, "chanserv/suspend", 2, 3) + 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]")); @@ -124,7 +128,7 @@ class CommandCSSuspend : public Command Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); source.Reply(_("Channel \002%s\002 is now suspended."), ci->name.c_str()); - FOREACH_MOD(OnChanSuspend, (ci)); + this->onchansuspend(&Event::ChanSuspend::OnChanSuspend, ci); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -145,8 +149,10 @@ class CommandCSSuspend : public Command class CommandCSUnSuspend : public Command { + EventHandlers<Event::ChanUnsuspend> &onchanunsuspend; + public: - CommandCSUnSuspend(Module *creator) : Command(creator, "chanserv/unsuspend", 1, 1) + CommandCSUnSuspend(Module *creator, EventHandlers<Event::ChanUnsuspend> &event) : Command(creator, "chanserv/unsuspend", 1, 1), onchanunsuspend(event) { this->SetDesc(_("Releases a suspended channel")); this->SetSyntax(_("\037channel\037")); @@ -179,9 +185,7 @@ class CommandCSUnSuspend : public Command source.Reply(_("Channel \002%s\002 is now released."), ci->name.c_str()); - FOREACH_MOD(OnChanUnsuspend, (ci)); - - return; + this->onchanunsuspend(&Event::ChanUnsuspend::OnChanUnsuspend, ci); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -195,16 +199,30 @@ class CommandCSUnSuspend : public Command }; class CSSuspend : public Module + , public EventHook<Event::ChanInfo> + , public EventHook<ChanServ::Event::PreChanExpire> + , public EventHook<Event::CheckKick> + , public EventHook<Event::ChanDrop> { CommandCSSuspend commandcssuspend; CommandCSUnSuspend commandcsunsuspend; ExtensibleItem<CSSuspendInfo> suspend; Serialize::Type suspend_type; + EventHandlers<Event::ChanSuspend> onchansuspend; + EventHandlers<Event::ChanUnsuspend> onchanunsuspend; public: - CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcssuspend(this), commandcsunsuspend(this), suspend(this, "CS_SUSPENDED"), - suspend_type("CSSuspendInfo", CSSuspendInfo::Unserialize) + CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanInfo>("OnChanInfo") + , EventHook<ChanServ::Event::PreChanExpire>("OnPreChanExpire") + , EventHook<Event::CheckKick>("OnCheckKick") + , EventHook<Event::ChanDrop>("OnChanDrop") + , commandcssuspend(this, onchansuspend) + , commandcsunsuspend(this, onchanunsuspend) + , suspend(this, "CS_SUSPENDED") + , suspend_type("CSSuspendInfo", CSSuspendInfo::Unserialize) + , onchansuspend(this, "OnChanSuspend") + , onchanunsuspend(this, "OnChanUnsuspend") { } diff --git a/modules/commands/cs_sync.cpp b/modules/commands/cs_sync.cpp index 0251b95be..d26ff6a7a 100644 --- a/modules/commands/cs_sync.cpp +++ b/modules/commands/cs_sync.cpp @@ -55,9 +55,10 @@ 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) + 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 9b4752d20..2fd1b0a81 100644 --- a/modules/commands/cs_topic.cpp +++ b/modules/commands/cs_topic.cpp @@ -11,6 +11,8 @@ #include "module.h" #include "modules/cs_mode.h" +#include "modules/cs_info.h" +#include "modules/cs_set.h" class CommandCSSetKeepTopic : public Command { @@ -37,7 +39,7 @@ class CommandCSSetKeepTopic : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -89,7 +91,7 @@ class CommandCSTopic : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, "topiclock on")); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock on"); if (MOD_RESULT == EVENT_STOP) return; @@ -106,7 +108,7 @@ class CommandCSTopic : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, "topiclock off")); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock off"); if (MOD_RESULT == EVENT_STOP) return; @@ -198,6 +200,9 @@ class CommandCSTopic : public Command }; class CSTopic : public Module + , public EventHook<Event::ChannelSync> + , public EventHook<Event::TopicUpdated> + , public EventHook<Event::ChanInfo> { CommandCSTopic commandcstopic; CommandCSSetKeepTopic commandcssetkeeptopic; @@ -205,8 +210,14 @@ class CSTopic : public Module SerializableExtensibleItem<bool> topiclock, keeptopic; public: - CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcstopic(this), commandcssetkeeptopic(this), topiclock(this, "TOPICLOCK"), keeptopic(this, "KEEPTOPIC") + CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChannelSync>("OnChannelSync") + , EventHook<Event::TopicUpdated>("OnTopicUpdated") + , EventHook<Event::ChanInfo>("OnChanInfo") + , commandcstopic(this) + , commandcssetkeeptopic(this) + , topiclock(this, "TOPICLOCK") + , keeptopic(this, "KEEPTOPIC") { } diff --git a/modules/commands/cs_unban.cpp b/modules/commands/cs_unban.cpp index 936de6b41..f5e2a6460 100644 --- a/modules/commands/cs_unban.cpp +++ b/modules/commands/cs_unban.cpp @@ -107,8 +107,8 @@ class CSUnban : public Module CommandCSUnban commandcsunban; public: - CSUnban(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsunban(this) + CSUnban(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsunban(this) { } diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 294d46680..282eb1479 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -221,8 +221,9 @@ class CSUpDown : public Module CommandCSDown commandcsdown; public: - CSUpDown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsup(this), commandcsdown(this) + CSUpDown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandcsup(this) + , commandcsdown(this) { } diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 49cb96eb4..84a8fbfb7 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -216,7 +216,7 @@ class CommandCSXOP : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask; - FOREACH_MOD(OnAccessAdd, (ci, source, acc)); + Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, acc); source.Reply(_("\002%s\002 added to %s %s list."), acc->mask.c_str(), ci->name.c_str(), source.command.c_str()); } @@ -325,7 +325,7 @@ class CommandCSXOP : public Command nicks = caccess->mask; ci->EraseAccess(number - 1); - FOREACH_MOD(OnAccessDel, (ci, source, caccess)); + Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, caccess); delete caccess; } } @@ -348,7 +348,7 @@ class CommandCSXOP : public Command source.Reply(_("\002%s\002 deleted from %s %s list."), a->mask.c_str(), ci->name.c_str(), source.command.c_str()); ci->EraseAccess(i); - FOREACH_MOD(OnAccessDel, (ci, source, a)); + Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, a); delete a; return; @@ -475,7 +475,7 @@ class CommandCSXOP : public Command delete ci->EraseAccess(i - 1); } - FOREACH_MOD(OnAccessClear, (ci, source)); + Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source); source.Reply(_("Channel %s %s list has been cleared."), ci->name.c_str(), source.command.c_str()); } @@ -593,8 +593,9 @@ class CSXOP : public Module CommandCSXOP commandcsxop; public: - CSXOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - accessprovider(this), commandcsxop(this) + CSXOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , accessprovider(this) + , commandcsxop(this) { this->SetPermanent(true); diff --git a/modules/commands/gl_global.cpp b/modules/commands/gl_global.cpp index 48152cd0b..5d2d6b61b 100644 --- a/modules/commands/gl_global.cpp +++ b/modules/commands/gl_global.cpp @@ -10,13 +10,12 @@ */ #include "module.h" +#include "modules/global.h" class CommandGLGlobal : public Command { - ServiceReference<GlobalService> GService; - public: - CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1), GService("GlobalService", "Global") + CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1) { this->SetDesc(_("Send a message to all users")); this->SetSyntax(_("\037message\037")); @@ -26,13 +25,14 @@ class CommandGLGlobal : public Command { const Anope::string &msg = params[0]; - if (!GService) - source.Reply("No global reference, is global loaded?"); - else + if (!Global::service) { - Log(LOG_ADMIN, source, this); - GService->SendGlobal(NULL, source.GetNick(), msg); + source.Reply("No global reference, is global loaded?"); + return; } + + Log(LOG_ADMIN, source, this); + Global::service->SendGlobal(NULL, source.GetNick(), msg); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -50,8 +50,8 @@ class GLGlobal : public Module CommandGLGlobal commandglglobal; public: - GLGlobal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandglglobal(this) + GLGlobal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandglglobal(this) { } diff --git a/modules/commands/greet.cpp b/modules/commands/greet.cpp index 52213acec..cacda2d3c 100644 --- a/modules/commands/greet.cpp +++ b/modules/commands/greet.cpp @@ -10,6 +10,9 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/bs_info.h" +#include "modules/ns_set.h" class CommandBSSetGreet : public Command { @@ -100,8 +103,7 @@ class CommandNSSetGreet : public Command } NickCore *nc = na->nc; - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -163,6 +165,9 @@ class CommandNSSASetGreet : public CommandNSSetGreet }; class Greet : public Module + , public EventHook<Event::JoinChannel> + , public EventHook<Event::NickInfo> + , public EventHook<Event::BotInfoEvent> { /* channel setting for whether or not greet should be shown */ SerializableExtensibleItem<bool> bs_greet; @@ -174,11 +179,15 @@ class Greet : public Module CommandNSSASetGreet commandnssasetgreet; public: - Greet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - bs_greet(this, "BS_GREET"), - ns_greet(this, "greet"), - commandbssetgreet(this), - commandnssetgreet(this), commandnssasetgreet(this) + Greet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::JoinChannel>("OnJoinChannel") + , EventHook<Event::NickInfo>("OnNickInfo") + , EventHook<Event::BotInfoEvent>("OnBotInfoEvent") + , bs_greet(this, "BS_GREET") + , ns_greet(this, "greet") + , commandbssetgreet(this) + , commandnssetgreet(this) + , commandnssasetgreet(this) { } diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index 33ac00a60..c23454c25 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/help.h" class CommandHelp : public Command { @@ -27,8 +28,10 @@ class CommandHelp : public Command return NULL; } + EventHandlers<Event::Help> &onhelp; + public: - CommandHelp(Module *creator) : Command(creator, "generic/help", 0) + CommandHelp(Module *creator, EventHandlers<Event::Help> &event) : Command(creator, "generic/help", 0), onhelp(event) { this->SetDesc(_("Displays this list and give information about commands")); this->AllowUnregistered(true); @@ -36,8 +39,7 @@ class CommandHelp : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - EventReturn MOD_RESULT; - FOREACH_RESULT(OnPreHelp, MOD_RESULT, (source, params)); + EventReturn MOD_RESULT = this->onhelp(&Event::Help::OnPreHelp, source, params); if (MOD_RESULT == EVENT_STOP) return; @@ -184,19 +186,19 @@ class CommandHelp : public Command source.Reply(_("No help available for \002%s\002."), params[0].c_str()); } - FOREACH_MOD(OnPostHelp, (source, params)); - - return; + this->onhelp(&Event::Help::OnPostHelp, source, params); } }; class Help : public Module { CommandHelp commandhelp; + EventHandlers<Event::Help> onhelp; public: - Help(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhelp(this) + Help(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhelp(this, onhelp) + , onhelp(this, "Help") { } diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp index 5c74eb8ac..ae0e2e6c2 100644 --- a/modules/commands/hs_del.cpp +++ b/modules/commands/hs_del.cpp @@ -10,11 +10,14 @@ */ #include "module.h" +#include "modules/hs_del.h" class CommandHSDel : public Command { + EventHandlers<Event::DeleteVhost> &OnDeleteVhost; + public: - CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1) + CommandHSDel(Module *creator, EventHandlers<Event::DeleteVhost> &onDeleteVhost) : Command(creator, "hostserv/del", 1, 1), OnDeleteVhost(onDeleteVhost) { this->SetDesc(_("Delete the vhost of another user")); this->SetSyntax(_("\037nick\037")); @@ -33,7 +36,7 @@ class CommandHSDel : public Command if (na) { Log(LOG_ADMIN, source, this) << "for user " << na->nick; - FOREACH_MOD(OnDeleteVhost, (na)); + this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na); na->RemoveVhost(); source.Reply(_("Vhost for \002%s\002 removed."), nick.c_str()); } @@ -53,8 +56,10 @@ class CommandHSDel : public Command class CommandHSDelAll : public Command { + EventHandlers<Event::DeleteVhost> &ondeletevhost; + public: - CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1) + CommandHSDelAll(Module *creator, EventHandlers<Event::DeleteVhost> &event) : Command(creator, "hostserv/delall", 1, 1), ondeletevhost(event) { this->SetDesc(_("Delete the vhost for all nicks in a group")); this->SetSyntax(_("\037nick\037")); @@ -72,7 +77,7 @@ class CommandHSDelAll : public Command NickAlias *na = NickAlias::Find(nick); if (na) { - FOREACH_MOD(OnDeleteVhost, (na)); + this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na); const NickCore *nc = na->nc; for (unsigned i = 0; i < nc->aliases->size(); ++i) { @@ -100,10 +105,13 @@ class HSDel : public Module { CommandHSDel commandhsdel; CommandHSDelAll commandhsdelall; + EventHandlers<Event::DeleteVhost> ondeletevhost; public: - HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhsdel(this), commandhsdelall(this) + HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsdel(this, ondeletevhost) + , commandhsdelall(this, ondeletevhost) + , ondeletevhost(this, "OnDeleteVhost") { } diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp index ca3aa9742..eb1c6d299 100644 --- a/modules/commands/hs_group.cpp +++ b/modules/commands/hs_group.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/ns_group.h" class CommandHSGroup : public Command { @@ -31,7 +32,7 @@ class CommandHSGroup : public Command if (nick) { nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); - FOREACH_MOD(OnSetVhost, (nick)); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, nick); } } setting = false; @@ -77,14 +78,18 @@ class CommandHSGroup : public Command }; class HSGroup : public Module + , public EventHook<Event::SetVhost> + , public EventHook<Event::NickGroup> { CommandHSGroup commandhsgroup; bool syncongroup; bool synconset; public: - HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhsgroup(this) + HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::SetVhost>("OnSetVhost") + , EventHook<Event::NickGroup>("OnNickGroup") + , commandhsgroup(this) { } diff --git a/modules/commands/hs_list.cpp b/modules/commands/hs_list.cpp index 5f9a60110..b5b8aa76a 100644 --- a/modules/commands/hs_list.cpp +++ b/modules/commands/hs_list.cpp @@ -149,8 +149,8 @@ class HSList : public Module CommandHSList commandhslist; public: - HSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhslist(this) + HSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhslist(this) { } }; diff --git a/modules/commands/hs_off.cpp b/modules/commands/hs_off.cpp index 93060432a..c0d51f884 100644 --- a/modules/commands/hs_off.cpp +++ b/modules/commands/hs_off.cpp @@ -53,8 +53,8 @@ class HSOff : public Module CommandHSOff commandhsoff; public: - HSOff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhsoff(this) + HSOff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsoff(this) { } diff --git a/modules/commands/hs_on.cpp b/modules/commands/hs_on.cpp index 182e1013e..4b92bf0be 100644 --- a/modules/commands/hs_on.cpp +++ b/modules/commands/hs_on.cpp @@ -62,8 +62,8 @@ class HSOn : public Module CommandHSOn commandhson; public: - HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhson(this) + HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhson(this) { } diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index f5eb5317d..1e5c98e31 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -16,8 +16,7 @@ */ #include "module.h" - -static ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ"); +#include "modules/memoserv.h" static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost); @@ -202,10 +201,10 @@ class CommandHSActivate : public Command if (req) { na->SetVhost(req->ident, req->host, source.GetNick(), req->time); - FOREACH_MOD(OnSetVhost, (na)); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); - if (Config->GetModule(this->owner)->Get<bool>("memouser") && memoserv) - memoserv->Send(source.service->nick, na->nick, _("[auto memo] Your requested vHost has been approved."), true); + if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service) + MemoServ::service->Send(source.service->nick, na->nick, _("[auto memo] Your requested vHost has been approved."), true); source.Reply(_("vHost for %s has been activated."), na->nick.c_str()); Log(LOG_COMMAND, source, this) << "for " << na->nick << " for vhost " << (!req->ident.empty() ? req->ident + "@" : "") << req->host; @@ -253,7 +252,7 @@ class CommandHSReject : public Command { na->Shrink<HostRequest>("hostrequest"); - if (Config->GetModule(this->owner)->Get<bool>("memouser") && memoserv) + if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service) { Anope::string message; if (!reason.empty()) @@ -261,7 +260,7 @@ class CommandHSReject : public Command else message = _("[auto memo] Your requested vHost has been rejected."); - memoserv->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); + MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); } source.Reply(_("vHost for %s has been rejected."), nick.c_str()); @@ -352,9 +351,13 @@ class HSRequest : public Module Serialize::Type request_type; public: - HSRequest(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandhsrequest(this), commandhsactive(this), - commandhsreject(this), commandhswaiting(this), hostrequest(this, "hostrequest"), request_type("HostRequest", HostRequest::Unserialize) + HSRequest(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsrequest(this) + , commandhsactive(this) + , commandhsreject(this) + , commandhswaiting(this) + , hostrequest(this, "hostrequest") + , request_type("HostRequest", HostRequest::Unserialize) { if (!IRCD || !IRCD->CanSetVHost) @@ -372,7 +375,7 @@ static void req_send_memos(Module *me, CommandSource &source, const Anope::strin else host = vHost; - if (Config->GetModule(me)->Get<bool>("memooper") && memoserv) + if (Config->GetModule(me)->Get<bool>("memooper") && MemoServ::service) for (unsigned i = 0; i < Oper::opers.size(); ++i) { Oper *o = Oper::opers[i]; @@ -383,7 +386,7 @@ static void req_send_memos(Module *me, CommandSource &source, const Anope::strin Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str()); - memoserv->Send(source.service->nick, na->nick, message, true); + MemoServ::service->Send(source.service->nick, na->nick, message, true); } } diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp index 770aa6695..69281b6ec 100644 --- a/modules/commands/hs_set.cpp +++ b/modules/commands/hs_set.cpp @@ -85,7 +85,7 @@ class CommandHSSet : public Command Log(LOG_ADMIN, source, this) << "to set the vhost of " << na->nick << " to " << (!user.empty() ? user + "@" : "") << host; na->SetVhost(user, host, source.GetNick()); - FOREACH_MOD(OnSetVhost, (na)); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); if (!user.empty()) source.Reply(_("VHost for \002%s\002 set to \002%s\002@\002%s\002."), nick.c_str(), user.c_str(), host.c_str()); else @@ -192,7 +192,7 @@ class CommandHSSetAll : public Command na->SetVhost(user, host, source.GetNick()); this->Sync(na); - FOREACH_MOD(OnSetVhost, (na)); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); if (!user.empty()) source.Reply(_("VHost for group \002%s\002 set to \002%s\002@\002%s\002."), nick.c_str(), user.c_str(), host.c_str()); else @@ -219,7 +219,9 @@ class HSSet : public Module CommandHSSetAll commandhssetall; public: - HSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandhsset(this), commandhssetall(this) + HSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsset(this) + , commandhssetall(this) { } diff --git a/modules/commands/ms_cancel.cpp b/modules/commands/ms_cancel.cpp index 86d70732e..09746d0f2 100644 --- a/modules/commands/ms_cancel.cpp +++ b/modules/commands/ms_cancel.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/memoserv.h" class CommandMSCancel : public Command { @@ -46,7 +47,8 @@ class CommandMSCancel : public Command for (int i = mi->memos->size() - 1; i >= 0; --i) if (mi->GetMemo(i)->unread && source.nc->display.equals_ci(mi->GetMemo(i)->sender)) { - FOREACH_MOD(OnMemoDel, (ischan ? ci->name : na->nc->display, mi, mi->GetMemo(i))); + 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; @@ -72,8 +74,8 @@ class MSCancel : public Module CommandMSCancel commandmscancel; public: - MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmscancel(this) + MSCancel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmscancel(this) { } }; diff --git a/modules/commands/ms_check.cpp b/modules/commands/ms_check.cpp index 3cb116088..a534aaca3 100644 --- a/modules/commands/ms_check.cpp +++ b/modules/commands/ms_check.cpp @@ -77,8 +77,8 @@ class MSCheck : public Module CommandMSCheck commandmscheck; public: - MSCheck(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmscheck(this) + MSCheck(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmscheck(this) { } diff --git a/modules/commands/ms_del.cpp b/modules/commands/ms_del.cpp index 4b6c7d95f..e1d329921 100644 --- a/modules/commands/ms_del.cpp +++ b/modules/commands/ms_del.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/memoserv.h" class MemoDelCallback : public NumberList { @@ -26,7 +27,8 @@ class MemoDelCallback : public NumberList if (!number || number > mi->memos->size()) return; - FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(number - 1))); + if (MemoServ::Event::OnMemoDel) + MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(number - 1)); mi->Del(number - 1); source.Reply(_("Memo %d has been deleted."), number); @@ -93,7 +95,8 @@ class CommandMSDel : public Command else if (numstr.equals_ci("LAST")) { /* Delete last memo. */ - FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(mi->memos->size() - 1))); + if (MemoServ::Event::OnMemoDel) + MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(mi->memos->size() - 1)); mi->Del(mi->memos->size() - 1); source.Reply(_("Memo %d has been deleted."), mi->memos->size() + 1); } @@ -102,7 +105,8 @@ class CommandMSDel : public Command /* Delete all memos. */ for (unsigned i = mi->memos->size(); i > 0; --i) { - FOREACH_MOD(OnMemoDel, (ci ? ci->name : source.nc->display, mi, mi->GetMemo(i))); + if (MemoServ::Event::OnMemoDel) + MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(i)); mi->Del(i - 1); } if (!chan.empty()) @@ -141,8 +145,8 @@ class MSDel : public Module CommandMSDel commandmsdel; public: - MSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsdel(this) + MSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsdel(this) { } diff --git a/modules/commands/ms_ignore.cpp b/modules/commands/ms_ignore.cpp index d7683d651..f73a27930 100644 --- a/modules/commands/ms_ignore.cpp +++ b/modules/commands/ms_ignore.cpp @@ -117,8 +117,8 @@ class MSIgnore : public Module CommandMSIgnore commandmsignore; public: - MSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsignore(this) + MSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsignore(this) { } }; diff --git a/modules/commands/ms_info.cpp b/modules/commands/ms_info.cpp index fe008b484..0e7506765 100644 --- a/modules/commands/ms_info.cpp +++ b/modules/commands/ms_info.cpp @@ -204,8 +204,8 @@ class MSInfo : public Module CommandMSInfo commandmsinfo; public: - MSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsinfo(this) + MSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsinfo(this) { } diff --git a/modules/commands/ms_list.cpp b/modules/commands/ms_list.cpp index 936dbc750..e5ca96770 100644 --- a/modules/commands/ms_list.cpp +++ b/modules/commands/ms_list.cpp @@ -154,8 +154,8 @@ class MSList : public Module CommandMSList commandmslist; public: - MSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmslist(this) + MSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmslist(this) { } diff --git a/modules/commands/ms_read.cpp b/modules/commands/ms_read.cpp index 9cc0be881..ba5eda863 100644 --- a/modules/commands/ms_read.cpp +++ b/modules/commands/ms_read.cpp @@ -10,13 +10,12 @@ */ #include "module.h" - -static ServiceReference<MemoServService> MemoServService("MemoServService", "MemoServ"); +#include "modules/memoserv.h" static void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Anope::string &targ) { /* Only send receipt if memos are allowed */ - if (MemoServService && !Anope::ReadOnly) + if (MemoServ::service && !Anope::ReadOnly) { /* Get nick alias for sender */ const NickAlias *na = NickAlias::Find(m->sender); @@ -35,7 +34,7 @@ static void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Ano Anope::string text = Anope::printf(Language::Translate(na->nc, _("\002[auto-memo]\002 The memo you sent to %s has been viewed.")), targ.c_str()); /* Send notification */ - MemoServService->Send(source.GetNick(), m->sender, text, true); + MemoServ::service->Send(source.GetNick(), m->sender, text, true); /* Notify recepient of the memo that a notification has been sent to the sender */ @@ -197,8 +196,8 @@ class MSRead : public Module CommandMSRead commandmsread; public: - MSRead(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsread(this) + MSRead(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsread(this) { } diff --git a/modules/commands/ms_rsend.cpp b/modules/commands/ms_rsend.cpp index 0ecdf5d7e..4cdeb132b 100644 --- a/modules/commands/ms_rsend.cpp +++ b/modules/commands/ms_rsend.cpp @@ -10,11 +10,7 @@ */ #include "module.h" - -namespace -{ - ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ"); -} +#include "modules/memoserv.h" class CommandMSRSend : public Command { @@ -27,7 +23,7 @@ class CommandMSRSend : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - if (!memoserv) + if (!MemoServ::service) return; if (Anope::ReadOnly && !source.IsOper()) @@ -51,12 +47,12 @@ class CommandMSRSend : public Command source.Reply(ACCESS_DENIED); else { - MemoServService::MemoResult result = memoserv->Send(source.GetNick(), nick, text); - if (result == MemoServService::MEMO_INVALID_TARGET) + MemoServ::MemoServService::MemoResult result = MemoServ::service->Send(source.GetNick(), nick, text); + if (result == MemoServ::MemoServService::MEMO_INVALID_TARGET) source.Reply(_("\002%s\002 is not a registered unforbidden nick or channel."), nick.c_str()); - else if (result == MemoServService::MEMO_TOO_FAST) + else if (result == MemoServ::MemoServService::MEMO_TOO_FAST) 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 == MemoServService::MEMO_TARGET_FULL) + 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 { @@ -93,10 +89,10 @@ class MSRSend : public Module CommandMSRSend commandmsrsend; public: - MSRSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsrsend(this) + MSRSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsrsend(this) { - if (!memoserv) + if (!MemoServ::service) throw ModuleException("No MemoServ!"); } }; diff --git a/modules/commands/ms_send.cpp b/modules/commands/ms_send.cpp index 2d796b505..2cf7d476e 100644 --- a/modules/commands/ms_send.cpp +++ b/modules/commands/ms_send.cpp @@ -10,11 +10,7 @@ */ #include "module.h" - -namespace -{ - ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ"); -} +#include "modules/memoserv.h" class CommandMSSend : public Command { @@ -27,7 +23,7 @@ class CommandMSSend : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - if (!memoserv) + if (!MemoServ::service) return; const Anope::string &nick = params[0]; @@ -39,14 +35,14 @@ class CommandMSSend : public Command return; } - MemoServService::MemoResult result = memoserv->Send(source.GetNick(), nick, text); - if (result == MemoServService::MEMO_SUCCESS) + MemoServ::MemoServService::MemoResult result = MemoServ::service->Send(source.GetNick(), nick, text); + if (result == MemoServ::MemoServService::MEMO_SUCCESS) source.Reply(_("Memo sent to \002%s\002."), nick.c_str()); - else if (result == MemoServService::MEMO_INVALID_TARGET) + else if (result == MemoServ::MemoServService::MEMO_INVALID_TARGET) source.Reply(_("\002%s\002 is not a registered unforbidden nick or channel."), nick.c_str()); - else if (result == MemoServService::MEMO_TOO_FAST) + else if (result == MemoServ::MemoServService::MEMO_TOO_FAST) 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 == MemoServService::MEMO_TARGET_FULL) + else if (result == MemoServ::MemoServService::MEMO_TARGET_FULL) source.Reply(_("Sorry, %s currently has too many memos and cannot receive more."), nick.c_str()); } @@ -67,11 +63,11 @@ class MSSend : public Module CommandMSSend commandmssend; public: - MSSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmssend(this) + MSSend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmssend(this) { - if (!memoserv) + if (!MemoServ::service) throw ModuleException("No MemoServ!"); } }; diff --git a/modules/commands/ms_sendall.cpp b/modules/commands/ms_sendall.cpp index a48eb3fa5..c567b0ed3 100644 --- a/modules/commands/ms_sendall.cpp +++ b/modules/commands/ms_sendall.cpp @@ -10,11 +10,7 @@ */ #include "module.h" - -namespace -{ - ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ"); -} +#include "modules/memoserv.h" class CommandMSSendAll : public Command { @@ -27,7 +23,7 @@ class CommandMSSendAll : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - if (!memoserv) + if (!MemoServ::service) return; const Anope::string &text = params[0]; @@ -39,7 +35,7 @@ class CommandMSSendAll : public Command const NickCore *nc = it->second; if (nc != source.nc) - memoserv->Send(source.GetNick(), nc->display, text); + MemoServ::service->Send(source.GetNick(), nc->display, text); } source.Reply(_("A massmemo has been sent to all registered users.")); @@ -59,10 +55,10 @@ class MSSendAll : public Module CommandMSSendAll commandmssendall; public: - MSSendAll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmssendall(this) + MSSendAll(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmssendall(this) { - if (!memoserv) + if (!MemoServ::service) throw ModuleException("No MemoServ!"); } }; diff --git a/modules/commands/ms_set.cpp b/modules/commands/ms_set.cpp index 81388bc3d..5e5591471 100644 --- a/modules/commands/ms_set.cpp +++ b/modules/commands/ms_set.cpp @@ -304,9 +304,12 @@ class MSSet : public Module SerializableExtensibleItem<bool> memo_signon, memo_receive, memo_mail, memo_hardmax; public: - MSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsset(this), memo_signon(this, "MEMO_SIGNON"), memo_receive(this, "MEMO_RECEIVE"), memo_mail(this, "MEMO_MAIL"), - memo_hardmax(this, "MEMO_HARDMAX") + MSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsset(this) + , memo_signon(this, "MEMO_SIGNON") + , memo_receive(this, "MEMO_RECEIVE") + , memo_mail(this, "MEMO_MAIL") + , memo_hardmax(this, "MEMO_HARDMAX") { } diff --git a/modules/commands/ms_staff.cpp b/modules/commands/ms_staff.cpp index e0cfe3f5d..125ef60fc 100644 --- a/modules/commands/ms_staff.cpp +++ b/modules/commands/ms_staff.cpp @@ -10,11 +10,7 @@ */ #include "module.h" - -namespace -{ - ServiceReference<MemoServService> memoserv("MemoServService", "MemoServ"); -} +#include "modules/memoserv.h" class CommandMSStaff : public Command { @@ -27,7 +23,7 @@ class CommandMSStaff : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - if (!memoserv) + if (!MemoServ::service) return; const Anope::string &text = params[0]; @@ -37,7 +33,7 @@ class CommandMSStaff : public Command const NickCore *nc = it->second; if (source.nc != nc && nc->IsServicesOper()) - memoserv->Send(source.GetNick(), nc->display, text, true); + MemoServ::service->Send(source.GetNick(), nc->display, text, true); } } @@ -56,10 +52,10 @@ class MSStaff : public Module CommandMSStaff commandmsstaff; public: - MSStaff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandmsstaff(this) + MSStaff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandmsstaff(this) { - if (!memoserv) + if (!MemoServ::service) throw ModuleException("No MemoServ!"); } }; diff --git a/modules/commands/ns_access.cpp b/modules/commands/ns_access.cpp index facf7cf9c..1df0bbe0e 100644 --- a/modules/commands/ns_access.cpp +++ b/modules/commands/ns_access.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/nickserv.h" class CommandNSAccess : public Command { @@ -187,12 +188,14 @@ class CommandNSAccess : public Command }; class NSAccess : public Module + , public EventHook<NickServ::Event::NickRegister> { CommandNSAccess commandnsaccess; public: - NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsaccess(this) + NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<NickServ::Event::NickRegister>("OnNickRegister") + , commandnsaccess(this) { } diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp index cbbf544e6..0967dbf61 100644 --- a/modules/commands/ns_ajoin.cpp +++ b/modules/commands/ns_ajoin.cpp @@ -298,15 +298,17 @@ class CommandNSAJoin : public Command }; class NSAJoin : public Module + , public EventHook<Event::UserLogin> { CommandNSAJoin commandnsajoin; ExtensibleItem<AJoinList> ajoinlist; Serialize::Type ajoinentry_type; public: - NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsajoin(this), ajoinlist(this, "ajoinlist"), - ajoinentry_type("AJoinEntry", AJoinEntry::Unserialize) + NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserLogin>("OnUserLogin") + , commandnsajoin(this), ajoinlist(this, "ajoinlist") + , ajoinentry_type("AJoinEntry", AJoinEntry::Unserialize) { if (!IRCD || !IRCD->CanSVSJoin) diff --git a/modules/commands/ns_alist.cpp b/modules/commands/ns_alist.cpp index 51f87f156..54216b190 100644 --- a/modules/commands/ns_alist.cpp +++ b/modules/commands/ns_alist.cpp @@ -130,8 +130,8 @@ class NSAList : public Module CommandNSAList commandnsalist; public: - NSAList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsalist(this) + NSAList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsalist(this) { } diff --git a/modules/commands/ns_cert.cpp b/modules/commands/ns_cert.cpp index e8c858f42..bda723981 100644 --- a/modules/commands/ns_cert.cpp +++ b/modules/commands/ns_cert.cpp @@ -11,8 +11,10 @@ #include "module.h" #include "modules/ns_cert.h" +#include "modules/nickserv.h" static Anope::hash_map<NickCore *> certmap; +static EventHandlers<Event::NickCertEvents> *events; struct CertServiceImpl : CertService { @@ -50,7 +52,7 @@ struct NSCertListImpl : NSCertList { this->certs.push_back(entry); certmap[entry] = nc; - FOREACH_MOD(OnNickAddCert, (this->nc, entry)); + (*events)(&Event::NickCertEvents::OnNickAddCert, this->nc, entry); } /** Get an entry from the nick's cert list by index @@ -95,7 +97,7 @@ struct NSCertListImpl : NSCertList std::vector<Anope::string>::iterator it = std::find(this->certs.begin(), this->certs.end(), entry); if (it != this->certs.end()) { - FOREACH_MOD(OnNickEraseCert, (this->nc, entry)); + (*events)(&Event::NickCertEvents::OnNickEraseCert, this->nc, entry); certmap.erase(entry); this->certs.erase(it); } @@ -107,7 +109,7 @@ struct NSCertListImpl : NSCertList */ void ClearCert() override { - FOREACH_MOD(OnNickClearCert, (this->nc)); + (*events)(&Event::NickCertEvents::OnNickClearCert, this->nc); for (unsigned i = 0; i < certs.size(); ++i) certmap.erase(certs[i]); this->certs.clear(); @@ -339,17 +341,28 @@ class CommandNSCert : public Command }; class NSCert : public Module + , public EventHook<Event::Fingerprint> + , public EventHook<NickServ::Event::NickValidate> { CommandNSCert commandnscert; NSCertListImpl::ExtensibleItem certs; CertServiceImpl cs; + EventHandlers<Event::NickCertEvents> onnickservevents; + public: - NSCert(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnscert(this), certs(this, "certificates"), cs(this) + NSCert(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Fingerprint>("OnFingerprint") + , EventHook<NickServ::Event::NickValidate>("OnNickValidate") + , commandnscert(this) + , certs(this, "certificates") + , cs(this) + , onnickservevents(this, "OnNickCert") { if (!IRCD || !IRCD->CanCertFP) throw ModuleException("Your IRCd does not support ssl client certificates"); + + events = &onnickservevents; } void OnFingerprint(User *u) override diff --git a/modules/commands/ns_drop.cpp b/modules/commands/ns_drop.cpp index dc6b00184..fef7682da 100644 --- a/modules/commands/ns_drop.cpp +++ b/modules/commands/ns_drop.cpp @@ -10,11 +10,14 @@ */ #include "module.h" +#include "modules/ns_drop.h" class CommandNSDrop : public Command { + EventHandlers<Event::NickDrop> &onnickdrop; + public: - CommandNSDrop(Module *creator) : Command(creator, "nickserv/drop", 1, 1) + CommandNSDrop(Module *creator, EventHandlers<Event::NickDrop> &event) : Command(creator, "nickserv/drop", 1, 1), onnickdrop(event) { this->SetSyntax(_("\037nickname\037")); this->SetDesc(_("Cancel the registration of a nickname")); @@ -45,7 +48,7 @@ class CommandNSDrop : public Command source.Reply(_("You may not drop other Services Operators' nicknames.")); else { - FOREACH_MOD(OnNickDrop, (source, na)); + this->onnickdrop(&Event::NickDrop::OnNickDrop, source, na); Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; delete na; @@ -74,10 +77,12 @@ class CommandNSDrop : public Command class NSDrop : public Module { CommandNSDrop commandnsdrop; + EventHandlers<Event::NickDrop> onnickdrop; public: - NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsdrop(this) + NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsdrop(this, onnickdrop) + , onnickdrop(this, "OnNickDrop") { } diff --git a/modules/commands/ns_getemail.cpp b/modules/commands/ns_getemail.cpp index 3790bca6a..96845571c 100644 --- a/modules/commands/ns_getemail.cpp +++ b/modules/commands/ns_getemail.cpp @@ -66,9 +66,10 @@ 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) + 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 871b8a685..c9bfc0402 100644 --- a/modules/commands/ns_getpass.cpp +++ b/modules/commands/ns_getpass.cpp @@ -60,8 +60,8 @@ class NSGetPass : public Module CommandNSGetPass commandnsgetpass; public: - NSGetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsgetpass(this) + NSGetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsgetpass(this) { Anope::string tmp_pass = "plain:tmp"; diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp index d8af7d18a..edd12f83d 100644 --- a/modules/commands/ns_group.cpp +++ b/modules/commands/ns_group.cpp @@ -11,16 +11,18 @@ #include "module.h" #include "modules/ns_cert.h" +#include "modules/ns_group.h" class NSGroupRequest : public IdentifyRequest { + EventHandlers<Event::NickGroup> &onnickgroup; CommandSource source; Command *cmd; Anope::string nick; Reference<NickAlias> target; public: - NSGroupRequest(Module *o, CommandSource &src, Command *c, const Anope::string &n, NickAlias *targ, const Anope::string &pass) : IdentifyRequest(o, targ->nc->display, pass), source(src), cmd(c), nick(n), target(targ) { } + 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) { } void OnSuccess() override { @@ -32,7 +34,7 @@ class NSGroupRequest : public IdentifyRequest /* If the nick is already registered, drop it. */ if (na) { - FOREACH_MOD(OnChangeCoreDisplay, (na->nc, u->nick)); + Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->nc, u->nick); delete na; } @@ -44,7 +46,7 @@ class NSGroupRequest : public IdentifyRequest na->time_registered = na->last_seen = Anope::CurTime; u->Login(target->nc); - FOREACH_MOD(OnNickGroup, (u, target)); + this->onnickgroup(&Event::NickGroup::OnNickGroup, u, target); Log(LOG_COMMAND, source, cmd) << "to make " << nick << " join group of " << target->nick << " (" << target->nc->display << ") (email: " << (!target->nc->email.empty() ? target->nc->email : "none") << ")"; source.Reply(_("You are now in the group of \002%s\002."), target->nick.c_str()); @@ -71,8 +73,10 @@ class NSGroupRequest : public IdentifyRequest class CommandNSGroup : public Command { + EventHandlers<Event::NickGroup> &onnickgroup; + public: - CommandNSGroup(Module *creator) : Command(creator, "nickserv/group", 0, 2) + CommandNSGroup(Module *creator, EventHandlers<Event::NickGroup> &event) : Command(creator, "nickserv/group", 0, 2), onnickgroup(event) { this->SetDesc(_("Join a group")); this->SetSyntax(_("\037[target]\037 \037[password]\037")); @@ -165,13 +169,13 @@ class CommandNSGroup : public Command if (ok == false && !pass.empty()) { - NSGroupRequest *req = new NSGroupRequest(owner, source, this, u->nick, target, pass); - FOREACH_MOD(OnCheckAuthentication, (source.GetUser(), req)); + NSGroupRequest *req = new NSGroupRequest(owner, this->onnickgroup, source, this, u->nick, target, pass); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else { - NSGroupRequest req(owner, source, this, u->nick, target, pass); + NSGroupRequest req(owner, this->onnickgroup, source, this, u->nick, target, pass); if (ok) req.OnSuccess(); @@ -372,9 +376,14 @@ class NSGroup : public Module CommandNSUngroup commandnsungroup; CommandNSGList commandnsglist; + EventHandlers<Event::NickGroup> onnickgroup; + public: - NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsgroup(this), commandnsungroup(this), commandnsglist(this) + NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsgroup(this, onnickgroup) + , commandnsungroup(this) + , commandnsglist(this) + , onnickgroup(this, "OnNickGroup") { if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership")) throw ModuleException(modname + " can not be used with options:nonicknameownership enabled"); diff --git a/modules/commands/ns_identify.cpp b/modules/commands/ns_identify.cpp index 3404536e9..5d7ed4c95 100644 --- a/modules/commands/ns_identify.cpp +++ b/modules/commands/ns_identify.cpp @@ -83,7 +83,7 @@ class CommandNSIdentify : public Command else { NSIdentifyRequest *req = new NSIdentifyRequest(owner, source, this, na ? na->nc->display : nick, pass); - FOREACH_MOD(OnCheckAuthentication, (u, req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req); req->Dispatch(); } return; diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp index 75c82bd3e..16f51db07 100644 --- a/modules/commands/ns_info.cpp +++ b/modules/commands/ns_info.cpp @@ -10,11 +10,15 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/ns_set.h" class CommandNSInfo : public Command { + EventHandlers<Event::NickInfo> &onnickinfo; + public: - CommandNSInfo(Module *creator) : Command(creator, "nickserv/info", 0, 2) + CommandNSInfo(Module *creator, EventHandlers<Event::NickInfo> &event) : Command(creator, "nickserv/info", 0, 2), onnickinfo(event) { this->SetDesc(_("Displays information about a given nickname")); this->SetSyntax(_("[\037nickname\037]")); @@ -104,7 +108,7 @@ class CommandNSInfo : public Command } } - FOREACH_MOD(OnNickInfo, (source, na, info, show_hidden)); + this->onnickinfo(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); std::vector<Anope::string> replies; info.Process(replies); @@ -154,8 +158,7 @@ class CommandNSSetHide : public Command } NickCore *nc = na->nc; - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -263,13 +266,20 @@ class NSInfo : public Module CommandNSSetHide commandnssethide; CommandNSSASetHide commandnssasethide; + EventHandlers<Event::NickInfo> onnickinfo; + SerializableExtensibleItem<bool> hide_email, hide_usermask, hide_status, hide_quit; public: - NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsinfo(this), commandnssethide(this), commandnssasethide(this), - hide_email(this, "HIDE_EMAIL"), hide_usermask(this, "HIDE_MASK"), hide_status(this, "HIDE_STATUS"), - hide_quit(this, "HIDE_QUIT") + NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsinfo(this, onnickinfo) + , commandnssethide(this) + , commandnssasethide(this) + , onnickinfo(this, "OnNickInfo") + , hide_email(this, "HIDE_EMAIL") + , hide_usermask(this, "HIDE_MASK") + , hide_status(this, "HIDE_STATUS") + , hide_quit(this, "HIDE_QUIT") { } diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp index 6aedbf666..0037cbcc5 100644 --- a/modules/commands/ns_list.cpp +++ b/modules/commands/ns_list.cpp @@ -10,6 +10,8 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/ns_set.h" class CommandNSList : public Command { @@ -203,8 +205,7 @@ class CommandNSSetPrivate : public Command } NickCore *nc = na->nc; - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -273,6 +274,7 @@ class CommandNSSASetPrivate : public CommandNSSetPrivate class NSList : public Module + , public EventHook<Event::NickInfo> { CommandNSList commandnslist; @@ -282,9 +284,12 @@ class NSList : public Module SerializableExtensibleItem<bool> priv; public: - NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnslist(this), commandnssetprivate(this), commandnssasetprivate(this), - priv(this, "NS_PRIVATE") + NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>("OnNickInfo") + , commandnslist(this) + , commandnssetprivate(this) + , commandnssasetprivate(this) + , priv(this, "NS_PRIVATE") { } diff --git a/modules/commands/ns_logout.cpp b/modules/commands/ns_logout.cpp index 6697e583f..a23fd26d2 100644 --- a/modules/commands/ns_logout.cpp +++ b/modules/commands/ns_logout.cpp @@ -10,8 +10,7 @@ */ #include "module.h" - -static ServiceReference<NickServService> NickServService("NickServService", "NickServ"); +#include "modules/nickserv.h" class CommandNSLogout : public Command { @@ -37,8 +36,8 @@ class CommandNSLogout : public Command source.Reply(_("You can't logout %s, they are a Services Operator."), nick.c_str()); else { - if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServService) - NickServService->Validate(u2); + if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServ::service) + NickServ::service->Validate(u2); u2->super_admin = false; /* Dont let people logout and remain a SuperAdmin */ Log(LOG_COMMAND, source, this) << "to logout " << u2->nick; @@ -54,7 +53,7 @@ class CommandNSLogout : public Command u2->Logout(); /* Send out an event */ - FOREACH_MOD(OnNickLogout, (u2)); + Event::OnNickLogout(&Event::NickLogout::OnNickLogout, u2); } return; } @@ -81,8 +80,8 @@ class NSLogout : public Module CommandNSLogout commandnslogout; public: - NSLogout(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnslogout(this) + NSLogout(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnslogout(this) { } diff --git a/modules/commands/ns_recover.cpp b/modules/commands/ns_recover.cpp index c469fc17b..de83ea619 100644 --- a/modules/commands/ns_recover.cpp +++ b/modules/commands/ns_recover.cpp @@ -11,8 +11,7 @@ #include "module.h" #include "modules/ns_cert.h" - -static ServiceReference<NickServService> nickserv("NickServService", "NickServ"); +#include "modules/nickserv.h" typedef std::map<Anope::string, ChannelStatus> NSRecoverInfo; @@ -40,7 +39,7 @@ class NSRecoverRequest : public IdentifyRequest /* Nick is being held by us, release it */ if (na->HasExt("HELD")) { - nickserv->Release(na); + NickServ::service->Release(na); source.Reply(_("Service's hold on \002%s\002 has been released."), na->nick.c_str()); } else if (!u) @@ -89,13 +88,13 @@ class NSRecoverRequest : public IdentifyRequest } u->SendMessage(source.service, _("This nickname has been recovered by %s."), source.GetNick().c_str()); - if (nickserv) - nickserv->Collide(u, na); + if (NickServ::service) + NickServ::service->Collide(u, na); if (IRCD->CanSVSNick) { /* If we can svsnick then release our hold and svsnick the user using the command */ - nickserv->Release(na); + NickServ::service->Release(na); IRCD->SendForceNickChange(source.GetUser(), GetAccount(), Anope::CurTime); } else @@ -170,7 +169,7 @@ class CommandNSRecover : public Command if (ok == false && !pass.empty()) { NSRecoverRequest *req = new NSRecoverRequest(owner, source, this, na->nick, pass); - FOREACH_MOD(OnCheckAuthentication, (source.GetUser(), req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else @@ -199,13 +198,18 @@ class CommandNSRecover : public Command }; class NSRecover : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::JoinChannel> { CommandNSRecover commandnsrecover; PrimitiveExtensibleItem<NSRecoverInfo> recover; public: - NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsrecover(this), recover(this, "recover") + NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserNickChange>("OnUserNickChange") + , EventHook<Event::JoinChannel>("OnJoinChannel") + , commandnsrecover(this) + , recover(this, "recover") { if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership")) diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index 052a0a799..802292c91 100644 --- a/modules/commands/ns_register.cpp +++ b/modules/commands/ns_register.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/nickserv.h" static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi); @@ -198,7 +199,8 @@ class CommandNSRegister : public Command Log(LOG_COMMAND, source, this) << "to register " << na->nick << " (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; - FOREACH_MOD(OnNickRegister, (source.GetUser(), na)); + if (NickServ::Event::OnNickRegister) + NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na); if (na->nc->GetAccessCount()) source.Reply(_("Nickname \002%s\002 registered under your user@host-mask: %s"), u_nick.c_str(), na->nc->GetAccess(0).c_str()); @@ -331,6 +333,8 @@ class CommandNSResend : public Command }; class NSRegister : public Module + , public EventHook<Event::NickIdentify> + , public EventHook<NickServ::Event::PreNickExpire> { CommandNSRegister commandnsregister; CommandNSConfirm commandnsconfirm; @@ -340,9 +344,14 @@ class NSRegister : public Module SerializableExtensibleItem<Anope::string> passcode; public: - NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsregister(this), commandnsconfirm(this), commandnsrsend(this), unconfirmed(this, "UNCONFIRMED"), - passcode(this, "passcode") + NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickIdentify>("OnNickIdentify") + , EventHook<NickServ::Event::PreNickExpire>("OnPreNickExpire") + , commandnsregister(this) + , commandnsconfirm(this) + , commandnsrsend(this) + , unconfirmed(this, "UNCONFIRMED") + , passcode(this, "passcode") { if (Config->GetModule(this)->Get<const Anope::string>("registration").equals_ci("disable")) throw ModuleException("Module " + this->name + " will not load with registration disabled."); diff --git a/modules/commands/ns_resetpass.cpp b/modules/commands/ns_resetpass.cpp index 7494fca04..af5c43cb7 100644 --- a/modules/commands/ns_resetpass.cpp +++ b/modules/commands/ns_resetpass.cpp @@ -61,13 +61,15 @@ struct ResetInfo }; class NSResetPass : public Module + , public EventHook<Event::PreCommand> { CommandNSResetPass commandnsresetpass; PrimitiveExtensibleItem<ResetInfo> reset; public: - NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsresetpass(this), reset(this, "reset") + NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::PreCommand>("OnPreCommand") + , commandnsresetpass(this), reset(this, "reset") { if (!Config->GetBlock("mail")->Get<bool>("usemail")) throw ModuleException("Not using mail."); diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 013843360..89f3c5e83 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -10,6 +10,9 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/ns_set.h" +#include "modules/nickserv.h" class CommandNSSet : public Command { @@ -247,7 +250,7 @@ class CommandNSSetAutoOp : public Command NickCore *nc = na->nc; EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -349,7 +352,7 @@ class CommandNSSetDisplay : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, user_na->nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, user_na->nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -472,7 +475,7 @@ class CommandNSSetEmail : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -563,7 +566,7 @@ class CommandNSSetKeepModes : public Command NickCore *nc = na->nc; EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -656,7 +659,7 @@ class CommandNSSetKill : public Command NickCore *nc = na->nc; EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -788,7 +791,7 @@ class CommandNSSetLanguage : public Command NickCore *nc = na->nc; EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -903,7 +906,7 @@ class CommandNSSetMessage : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -1001,7 +1004,7 @@ class CommandNSSetSecure : public Command NickCore *nc = na->nc; EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -1123,6 +1126,13 @@ class CommandNSSASetNoexpire : public Command }; class NSSet : public Module + , public EventHook<Event::PreCommand> + , public EventHook<Event::SetCorrectModes> + , public EventHook<NickServ::Event::PreNickExpire> + , public EventHook<Event::NickInfo> + , public EventHook<Event::UserModeSet> + , public EventHook<Event::UserModeUnset> + , public EventHook<Event::UserLogin> { CommandNSSet commandnsset; CommandNSSASet commandnssaset; @@ -1208,25 +1218,46 @@ class NSSet : public Module PrimitiveExtensibleItem<std::pair<Anope::string, Anope::string > > ns_set_email; public: - NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsset(this), commandnssaset(this), - commandnssetautoop(this), commandnssasetautoop(this), - commandnssetdisplay(this), commandnssasetdisplay(this), - commandnssetemail(this), commandnssasetemail(this), - commandnssetkeepmodes(this), commandnssasetkeepmodes(this), - commandnssetkill(this), commandnssasetkill(this), - commandnssetlanguage(this), commandnssasetlanguage(this), - commandnssetmessage(this), commandnssasetmessage(this), - commandnssetpassword(this), commandnssasetpassword(this), - commandnssetsecure(this), commandnssasetsecure(this), - commandnssasetnoexpire(this), - - autoop(this, "AUTOOP"), - killprotect(this, "KILLPROTECT"), kill_quick(this, "KILL_QUICK"), - kill_immed(this, "KILL_IMMED"), message(this, "MSG"), - secure(this, "NS_SECURE"), noexpire(this, "NS_NO_EXPIRE"), - - keep_modes(this, "NS_KEEP_MODES"), ns_set_email(this, "ns_set_email") + NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::PreCommand>("OnPreCommand") + , EventHook<Event::SetCorrectModes>("OnSetCorrectModes") + , EventHook<NickServ::Event::PreNickExpire>("OnPreNickExpire") + , EventHook<Event::NickInfo>("OnNickInfo") + , EventHook<Event::UserModeSet>("OnUserModeSet") + , EventHook<Event::UserModeUnset>("OnUserModeUnset") + , EventHook<Event::UserLogin>("OnUserLogin") + , commandnsset(this) + , commandnssaset(this) + , commandnssetautoop(this) + , commandnssasetautoop(this) + , commandnssetdisplay(this) + , commandnssasetdisplay(this) + , commandnssetemail(this) + , commandnssasetemail(this) + , commandnssetkeepmodes(this) + , commandnssasetkeepmodes(this) + , commandnssetkill(this) + , commandnssasetkill(this) + , commandnssetlanguage(this) + , commandnssasetlanguage(this) + , commandnssetmessage(this) + , commandnssasetmessage(this) + , commandnssetpassword(this) + , commandnssasetpassword(this) + , commandnssetsecure(this) + , commandnssasetsecure(this) + , commandnssasetnoexpire(this) + + , autoop(this, "AUTOOP") + , killprotect(this, "KILLPROTECT") + , kill_quick(this, "KILL_QUICK") + , kill_immed(this, "KILL_IMMED") + , message(this, "MSG") + , secure(this, "NS_SECURE") + , noexpire(this, "NS_NO_EXPIRE") + + , keep_modes(this, "NS_KEEP_MODES") + , ns_set_email(this, "ns_set_email") { } diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp index 73e3b169a..bf3ea8660 100644 --- a/modules/commands/ns_set_misc.cpp +++ b/modules/commands/ns_set_misc.cpp @@ -11,6 +11,8 @@ #include "module.h" #include "modules/set_misc.h" +#include "modules/ns_info.h" +#include "modules/ns_set.h" static Module *me; @@ -112,8 +114,7 @@ class CommandNSSetMisc : public Command } NickCore *nc = na->nc; - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param)); + EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -176,14 +177,18 @@ class CommandNSSASetMisc : public CommandNSSetMisc }; class NSSetMisc : public Module + , public EventHook<Event::NickInfo> { CommandNSSetMisc commandnssetmisc; CommandNSSASetMisc commandnssasetmisc; Serialize::Type nsmiscdata_type; public: - NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnssetmisc(this), commandnssasetmisc(this), nsmiscdata_type("NSMiscData", NSMiscData::Unserialize) + NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>("OnNickInfo") + , commandnssetmisc(this) + , commandnssasetmisc(this) + , nsmiscdata_type("NSMiscData", NSMiscData::Unserialize) { me = this; } diff --git a/modules/commands/ns_status.cpp b/modules/commands/ns_status.cpp index e0f068490..f4c8c7192 100644 --- a/modules/commands/ns_status.cpp +++ b/modules/commands/ns_status.cpp @@ -77,8 +77,8 @@ class NSStatus : public Module CommandNSStatus commandnsstatus; public: - NSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsstatus(this) + NSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsstatus(this) { } diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp index 27bb5c0bb..ca669d537 100644 --- a/modules/commands/ns_suspend.cpp +++ b/modules/commands/ns_suspend.cpp @@ -11,8 +11,8 @@ #include "module.h" #include "modules/suspend.h" - -static ServiceReference<NickServService> nickserv("NickServService", "NickServ"); +#include "modules/ns_info.h" +#include "modules/nickserv.h" struct NSSuspendInfo : SuspendInfo, Serializable { @@ -54,8 +54,10 @@ struct NSSuspendInfo : SuspendInfo, Serializable class CommandNSSuspend : public Command { + EventHandlers<Event::NickSuspend> &onnicksuspend; + public: - CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3) + CommandNSSuspend(Module *creator, EventHandlers<Event::NickSuspend> &event) : Command(creator, "nickserv/suspend", 2, 3), onnicksuspend(event) { this->SetDesc(_("Suspend a given nick")); this->SetSyntax(_("\037nickname\037 [+\037expiry\037] [\037reason\037]")); @@ -128,8 +130,8 @@ class CommandNSSuspend : public Command if (u2) { u2->Logout(); - if (nickserv) - nickserv->Collide(u2, na2); + if (NickServ::service) + NickServ::service->Collide(u2, na2); } } } @@ -137,7 +139,7 @@ class CommandNSSuspend : public Command Log(LOG_ADMIN, source, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); source.Reply(_("Nick %s is now suspended."), nick.c_str()); - FOREACH_MOD(OnNickSuspend, (na)); + this->onnicksuspend(&Event::NickSuspend::OnNickSuspend, na); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -154,8 +156,10 @@ class CommandNSSuspend : public Command class CommandNSUnSuspend : public Command { + EventHandlers<Event::NickUnsuspended> &onnickunsuspend; + public: - CommandNSUnSuspend(Module *creator) : Command(creator, "nickserv/unsuspend", 1, 1) + CommandNSUnSuspend(Module *creator, EventHandlers<Event::NickUnsuspended> &event) : Command(creator, "nickserv/unsuspend", 1, 1), onnickunsuspend(event) { this->SetDesc(_("Unsuspend a given nick")); this->SetSyntax(_("\037nickname\037")); @@ -189,7 +193,7 @@ class CommandNSUnSuspend : public Command source.Reply(_("Nick %s is now released."), nick.c_str()); - FOREACH_MOD(OnNickUnsuspended, (na)); + this->onnickunsuspend(&Event::NickUnsuspended::OnNickUnsuspended, na); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -202,16 +206,28 @@ class CommandNSUnSuspend : public Command }; class NSSuspend : public Module + , public EventHook<Event::NickInfo> + , public EventHook<NickServ::Event::PreNickExpire> + , public EventHook<NickServ::Event::NickValidate> { CommandNSSuspend commandnssuspend; CommandNSUnSuspend commandnsunsuspend; ExtensibleItem<NSSuspendInfo> suspend; Serialize::Type suspend_type; + EventHandlers<Event::NickSuspend> onnicksuspend; + EventHandlers<Event::NickUnsuspended> onnickunsuspend; public: - NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnssuspend(this), commandnsunsuspend(this), suspend(this, "NS_SUSPENDED"), - suspend_type("NSSuspendInfo", NSSuspendInfo::Unserialize) + NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>("OnNickInfo") + , EventHook<NickServ::Event::PreNickExpire>("OnPreNickExpire") + , EventHook<NickServ::Event::NickValidate>("OnNickValidate") + , commandnssuspend(this, onnicksuspend) + , commandnsunsuspend(this, onnickunsuspend) + , suspend(this, "NS_SUSPENDED") + , suspend_type("NSSuspendInfo", NSSuspendInfo::Unserialize) + , onnicksuspend(this, "OnNickSuspend") + , onnickunsuspend(this, "OnNickUnsuspended") { } diff --git a/modules/commands/ns_update.cpp b/modules/commands/ns_update.cpp index 8f5ddc330..1fa9c5b36 100644 --- a/modules/commands/ns_update.cpp +++ b/modules/commands/ns_update.cpp @@ -10,11 +10,14 @@ */ #include "module.h" +#include "modules/ns_update.h" class CommandNSUpdate : public Command { + EventHandlers<Event::NickUpdate> &onnickupdate; + public: - CommandNSUpdate(Module *creator) : Command(creator, "nickserv/update", 0, 0) + CommandNSUpdate(Module *creator, EventHandlers<Event::NickUpdate> &event) : Command(creator, "nickserv/update", 0, 0), onnickupdate(event) { this->SetDesc(_("Updates your current status, i.e. it checks for new memos")); this->RequireUser(true); @@ -31,7 +34,7 @@ class CommandNSUpdate : public Command na->last_seen = Anope::CurTime; } - FOREACH_MOD(OnNickUpdate, (u)); + this->onnickupdate(&Event::NickUpdate::OnNickUpdate, u); source.Reply(_("Status updated (memos, vhost, chmodes, flags).")); } @@ -50,10 +53,12 @@ class CommandNSUpdate : public Command class NSUpdate : public Module { CommandNSUpdate commandnsupdate; + EventHandlers<Event::NickUpdate> onnickupdate; public: - NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandnsupdate(this) + NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandnsupdate(this, onnickupdate) + , onnickupdate(this, "OnNickUpdate") { } diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp index 81dd69ed2..971b284e5 100644 --- a/modules/commands/os_akill.cpp +++ b/modules/commands/os_akill.cpp @@ -174,7 +174,7 @@ class CommandOSAKill : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnAddXLine, MOD_RESULT, (source, x, akills)); + MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, akills); if (MOD_RESULT == EVENT_STOP) { delete x; @@ -225,7 +225,7 @@ class CommandOSAKill : public Command do { - FOREACH_MOD(OnDelXLine, (source, x, akills)); + Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills); Log(LOG_ADMIN, source, this) << "to remove " << x->mask << " from the list"; source.Reply(_("\002%s\002 deleted from the AKILL list."), x->mask.c_str()); @@ -349,7 +349,7 @@ class CommandOSAKill : public Command for (unsigned i = akills->GetCount(); i > 0; --i) { XLine *x = akills->GetEntry(i - 1); - FOREACH_MOD(OnDelXLine, (source, x, akills)); + Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills); akills->DelXLine(x); } @@ -453,8 +453,8 @@ class OSAKill : public Module CommandOSAKill commandosakill; public: - OSAKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosakill(this) + OSAKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosakill(this) { } diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp index ef569912b..060258705 100644 --- a/modules/commands/os_chankill.cpp +++ b/modules/commands/os_chankill.cpp @@ -105,8 +105,8 @@ class OSChanKill : public Module CommandOSChanKill commandoschankill; public: - OSChanKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandoschankill(this) + OSChanKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandoschankill(this) { } diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp index e12338924..e81030bc9 100644 --- a/modules/commands/os_config.cpp +++ b/modules/commands/os_config.cpp @@ -140,8 +140,8 @@ class OSConfig : public Module CommandOSConfig commandosconfig; public: - OSConfig(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosconfig(this) + OSConfig(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosconfig(this) { } diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp index 8b2f8a1c8..ee3a10d13 100644 --- a/modules/commands/os_defcon.cpp +++ b/modules/commands/os_defcon.cpp @@ -11,6 +11,8 @@ #include "module.h" #include "modules/os_session.h" +#include "modules/os_defcon.h" +#include "modules/global.h" enum DefconLevel { @@ -101,16 +103,15 @@ static DefconConfig DConfig; static void runDefCon(); static Anope::string defconReverseModes(const Anope::string &modes); -static ServiceReference<GlobalService> GlobalService("GlobalService", "Global"); - static Timer *timeout; class DefConTimeout : public Timer { + EventHandlers<Event::DefconLevel> &eventdefcon; int level; public: - DefConTimeout(Module *mod, int newlevel) : Timer(mod, DConfig.timeout), level(newlevel) + DefConTimeout(EventHandlers<Event::DefconLevel> &ev, Module *mod, int newlevel) : Timer(mod, DConfig.timeout), eventdefcon(ev), level(newlevel) { timeout = this; } @@ -125,18 +126,18 @@ class DefConTimeout : public Timer if (DConfig.defaultlevel != level) { DConfig.defaultlevel = level; - FOREACH_MOD(OnDefconLevel, (level)); + this->eventdefcon(&Event::DefconLevel::OnDefconLevel, level); Log(Config->GetClient("OperServ"), "operserv/defcon") << "Defcon level timeout, returning to level " << level; - if (DConfig.globalondefcon) + if (DConfig.globalondefcon && Global::service) { if (!DConfig.offmessage.empty()) - GlobalService->SendGlobal(NULL, "", DConfig.offmessage); + Global::service->SendGlobal(NULL, "", DConfig.offmessage); else - GlobalService->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel)); + Global::service->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel)); if (!DConfig.message.empty()) - GlobalService->SendGlobal(NULL, "", DConfig.message); + Global::service->SendGlobal(NULL, "", DConfig.message); } runDefCon(); @@ -170,8 +171,10 @@ class CommandOSDefcon : public Command source.Reply(_("* No new memos sent")); } + EventHandlers<Event::DefconLevel> &ondefconlevel; + public: - CommandOSDefcon(Module *creator) : Command(creator, "operserv/defcon", 1, 1) + CommandOSDefcon(Module *creator, EventHandlers<Event::DefconLevel> &event) : Command(creator, "operserv/defcon", 1, 1), ondefconlevel(event) { this->SetDesc(_("Manipulate the DefCon system")); this->SetSyntax(_("[\0021\002|\0022\002|\0023\002|\0024\002|\0025\002]")); @@ -203,12 +206,12 @@ class CommandOSDefcon : public Command DConfig.defaultlevel = newLevel; - FOREACH_MOD(OnDefconLevel, (newLevel)); + this->ondefconlevel(&Event::DefconLevel::OnDefconLevel, newLevel); delete timeout; if (DConfig.timeout) - timeout = new DefConTimeout(this->module, 5); + timeout = new DefConTimeout(this->ondefconlevel, this->module, 5); source.Reply(_("Services are now at DEFCON \002%d\002."), DConfig.defaultlevel); this->SendLevels(source); @@ -216,15 +219,15 @@ class CommandOSDefcon : public Command /* Global notice the user what is happening. Also any Message that the Admin would like to add. Set in config file. */ - if (DConfig.globalondefcon) + if (DConfig.globalondefcon && Global::service) { if (DConfig.defaultlevel == 5 && !DConfig.offmessage.empty()) - GlobalService->SendGlobal(NULL, "", DConfig.offmessage); + Global::service->SendGlobal(NULL, "", DConfig.offmessage); else if (DConfig.defaultlevel != 5) { - GlobalService->SendGlobal(NULL, "", Anope::printf(_("The Defcon level is now at: \002%d\002"), DConfig.defaultlevel)); + Global::service->SendGlobal(NULL, "", Anope::printf(_("The Defcon level is now at: \002%d\002"), DConfig.defaultlevel)); if (!DConfig.message.empty()) - GlobalService->SendGlobal(NULL, "", DConfig.message); + Global::service->SendGlobal(NULL, "", DConfig.message); } } @@ -245,10 +248,17 @@ class CommandOSDefcon : public Command }; class OSDefcon : public Module + , public EventHook<Event::ChannelModeSet> + , public EventHook<Event::ChannelModeUnset> + , public EventHook<Event::PreCommand> + , public EventHook<Event::UserConnect> + , public EventHook<Event::ChannelModeAdd> + , public EventHook<Event::ChannelSync> { ServiceReference<SessionService> session_service; ServiceReference<XLineManager> akills; CommandOSDefcon commandosdefcon; + EventHandlers<Event::DefconLevel> ondefconlevel; void ParseModeString() { @@ -330,11 +340,26 @@ class OSDefcon : public Module } public: - OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), session_service("SessionService", "session"), akills("XLineManager", "xlinemanager/sgline"), commandosdefcon(this) + OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChannelModeSet>("OnChannelModeSet") + , EventHook<Event::ChannelModeUnset>("OnChannelModeUnset") + , EventHook<Event::PreCommand>("OnPreCommand") + , EventHook<Event::UserConnect>("OnUserConnect") + , EventHook<Event::ChannelModeAdd>("OnChannelModeAdd") + , EventHook<Event::ChannelSync>("OnChannelSync") + , session_service("SessionService", "session") + , akills("XLineManager", "xlinemanager/sgline") + , commandosdefcon(this, ondefconlevel) + , ondefconlevel(this, "OnDefconLevel") { } + ~OSDefcon() + { + delete timeout; + } + void OnReload(Configuration::Conf *conf) override { Configuration::Block *block = conf->GetModule(this); diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index f58c29e98..d76ad451f 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -716,6 +716,11 @@ class CommandOSDNS : public Command }; class ModuleDNS : public Module + , public EventHook<Event::NewServer> + , public EventHook<Event::ServerQuit> + , public EventHook<Event::UserConnect> + , public EventHook<Event::PreUserLogoff> + , public EventHook<Event::DnsRequest> { Serialize::Type zone_type, dns_type; CommandOSDNS commandosdns; @@ -730,9 +735,16 @@ class ModuleDNS : public Module time_t last_warn; public: - ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this), - last_warn(0) + ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::NewServer>("OnNewServer") + , EventHook<Event::ServerQuit>("OnServerQuit") + , EventHook<Event::UserConnect>("OnUserConnect") + , EventHook<Event::PreUserLogoff>("OnPreUserLogoff") + , EventHook<Event::DnsRequest>("OnDnsRequest") + , zone_type("DNSZone", DNSZone::Unserialize) + , dns_type("DNSServer", DNSServer::Unserialize) + , commandosdns(this) + , last_warn(0) { diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index f13b72cf9..1f54f804f 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -11,8 +11,8 @@ #include "module.h" #include "modules/os_forbid.h" - -static ServiceReference<NickServService> nickserv("NickServService", "NickServ"); +#include "modules/nickserv.h" +#include "modules/chanserv.h" struct ForbidDataImpl : ForbidData, Serializable { @@ -147,6 +147,24 @@ class CommandOSForbid : public Command this->SetSyntax("LIST [NICK|CHAN|EMAIL|REGISTER]"); } + void OnUserNickChange(User *u) + { + if (u->HasMode("OPER")) + return; + + ForbidData *d = fs->FindForbid(u->nick, FT_NICK); + if (d != NULL) + { + BotInfo *bi = Config->GetClient("NickServ"); + if (!bi) + bi = Config->GetClient("OperServ"); + if (bi) + u->SendMessage(bi, _("This nickname has been forbidden: %s"), d->reason.c_str()); + if (NickServ::service) + NickServ::service->Collide(u, NULL); + } + } + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { if (!this->fs) @@ -234,7 +252,7 @@ class CommandOSForbid : public Command int na_matches = 0; for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - module->OnUserNickChange(it->second, ""); + this->OnUserNickChange(it->second); for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end;) { @@ -266,7 +284,6 @@ class CommandOSForbid : public Command if (d == NULL) continue; - ServiceReference<ChanServService> chanserv("ChanServService", "ChanServ"); BotInfo *OperServ = Config->GetClient("OperServ"); if (IRCD->CanSQLineChannel && OperServ) { @@ -274,9 +291,9 @@ class CommandOSForbid : public Command XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->reason); IRCD->SendSQLine(NULL, &x); } - else if (chanserv) + else if (ChanServ::service) { - chanserv->Hold(c); + ChanServ::service->Hold(c); } ++chan_matches; @@ -422,14 +439,24 @@ class CommandOSForbid : public Command }; class OSForbid : public Module + , public EventHook<Event::UserConnect> + , public EventHook<Event::UserNickChange> + , public EventHook<Event::CheckKick> + , public EventHook<Event::PreCommand> { MyForbidService forbidService; Serialize::Type forbiddata_type; CommandOSForbid commandosforbid; public: - OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - forbidService(this), forbiddata_type("ForbidData", ForbidDataImpl::Unserialize), commandosforbid(this) + OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserConnect>("OnUserConnect") + , EventHook<Event::UserNickChange>("OnUserNickChange") + , EventHook<Event::CheckKick>("OnCheckKick") + , EventHook<Event::PreCommand>("OnPreCommand") + , forbidService(this) + , forbiddata_type("ForbidData", ForbidDataImpl::Unserialize) + , commandosforbid(this) { } @@ -439,25 +466,12 @@ class OSForbid : public Module if (u->Quitting() || exempt) return; - this->OnUserNickChange(u, ""); + commandosforbid.OnUserNickChange(u); } void OnUserNickChange(User *u, const Anope::string &) override { - if (u->HasMode("OPER")) - return; - - ForbidData *d = this->forbidService.FindForbid(u->nick, FT_NICK); - if (d != NULL) - { - BotInfo *bi = Config->GetClient("NickServ"); - if (!bi) - bi = Config->GetClient("OperServ"); - if (bi) - u->SendMessage(bi, _("This nickname has been forbidden: %s"), d->reason.c_str()); - if (nickserv) - nickserv->Collide(u, NULL); - } + commandosforbid.OnUserNickChange(u); } EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override @@ -469,16 +483,15 @@ class OSForbid : public Module ForbidData *d = this->forbidService.FindForbid(c->name, FT_CHAN); if (d != NULL) { - ServiceReference<ChanServService> chanserv("ChanServService", "ChanServ"); if (IRCD->CanSQLineChannel) { time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s"); XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->reason); IRCD->SendSQLine(NULL, &x); } - else if (chanserv) + else if (ChanServ::service) { - chanserv->Hold(c); + ChanServ::service->Hold(c); } reason = Anope::printf(Language::Translate(u, _("This channel has been forbidden: %s")), d->reason.c_str()); diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index d5a2774bc..fa6537a21 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -392,14 +392,18 @@ class CommandOSIgnore : public Command }; class OSIgnore : public Module + , public EventHook<Event::BotPrivmsg> { Serialize::Type ignoredata_type; OSIgnoreService osignoreservice; CommandOSIgnore commandosignore; public: - OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - ignoredata_type("IgnoreData", IgnoreDataImpl::Unserialize), osignoreservice(this), commandosignore(this) + OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::BotPrivmsg>("OnBotPrivmsg") + , ignoredata_type("IgnoreData", IgnoreDataImpl::Unserialize) + , osignoreservice(this) + , commandosignore(this) { } diff --git a/modules/commands/os_info.cpp b/modules/commands/os_info.cpp index 462fbbc4c..53b5fecd6 100644 --- a/modules/commands/os_info.cpp +++ b/modules/commands/os_info.cpp @@ -7,6 +7,8 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/cs_info.h" struct OperInfo : Serializable { @@ -248,6 +250,8 @@ class CommandOSInfo : public Command }; class OSInfo : public Module + , public EventHook<Event::NickInfo> + , public EventHook<Event::ChanInfo> { CommandOSInfo commandosinfo; ExtensibleItem<OperInfos> oinfo; @@ -270,8 +274,12 @@ class OSInfo : public Module } public: - OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosinfo(this), oinfo(this, "operinfo"), oinfo_type("OperInfo", OperInfo::Unserialize) + OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>("OnNickInfo") + , EventHook<Event::ChanInfo>("OnChanInfo") + , commandosinfo(this) + , oinfo(this, "operinfo") + , oinfo_type("OperInfo", OperInfo::Unserialize) { } diff --git a/modules/commands/os_jupe.cpp b/modules/commands/os_jupe.cpp index 3e0fad425..08fb6a4ce 100644 --- a/modules/commands/os_jupe.cpp +++ b/modules/commands/os_jupe.cpp @@ -70,8 +70,8 @@ class OSJupe : public Module CommandOSJupe commandosjupe; public: - OSJupe(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosjupe(this) + OSJupe(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosjupe(this) { } diff --git a/modules/commands/os_kick.cpp b/modules/commands/os_kick.cpp index 20a967575..a1ae346a9 100644 --- a/modules/commands/os_kick.cpp +++ b/modules/commands/os_kick.cpp @@ -68,8 +68,8 @@ class OSKick : public Module CommandOSKick commandoskick; public: - OSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandoskick(this) + OSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandoskick(this) { } diff --git a/modules/commands/os_kill.cpp b/modules/commands/os_kill.cpp index b36e68df9..491e8b1c4 100644 --- a/modules/commands/os_kill.cpp +++ b/modules/commands/os_kill.cpp @@ -57,8 +57,8 @@ class OSKill : public Module CommandOSKill commandoskill; public: - OSKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandoskill(this) + OSKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandoskill(this) { } diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp index d91b68938..fc077eac9 100644 --- a/modules/commands/os_list.cpp +++ b/modules/commands/os_list.cpp @@ -236,8 +236,9 @@ class OSList : public Module CommandOSUserList commandosuserlist; public: - OSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandoschanlist(this), commandosuserlist(this) + OSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandoschanlist(this) + , commandosuserlist(this) { } diff --git a/modules/commands/os_login.cpp b/modules/commands/os_login.cpp index d21eef468..e55459d24 100644 --- a/modules/commands/os_login.cpp +++ b/modules/commands/os_login.cpp @@ -105,14 +105,18 @@ class CommandOSLogout : public Command }; class OSLogin : public Module + , public EventHook<Event::IsServicesOperEvent> { CommandOSLogin commandoslogin; CommandOSLogout commandoslogout; ExtensibleItem<bool> os_login; public: - OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandoslogin(this), commandoslogout(this), os_login(this, "os_login") + OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::IsServicesOperEvent>("OnIsServicesOperEvent") + , commandoslogin(this) + , commandoslogout(this) + , os_login(this, "os_login") { } diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp index fb9a75637..cba659957 100644 --- a/modules/commands/os_logsearch.cpp +++ b/modules/commands/os_logsearch.cpp @@ -147,8 +147,8 @@ class OSLogSearch : public Module CommandOSLogSearch commandoslogsearch; public: - OSLogSearch(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandoslogsearch(this) + OSLogSearch(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandoslogsearch(this) { } }; diff --git a/modules/commands/os_mode.cpp b/modules/commands/os_mode.cpp index 167f654af..7358e4c78 100644 --- a/modules/commands/os_mode.cpp +++ b/modules/commands/os_mode.cpp @@ -174,8 +174,9 @@ class OSMode : public Module CommandOSUMode commandosumode; public: - OSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosmode(this), commandosumode(this) + OSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosmode(this) + , commandosumode(this) { } diff --git a/modules/commands/os_modinfo.cpp b/modules/commands/os_modinfo.cpp index f8b05bff8..e8c2caa69 100644 --- a/modules/commands/os_modinfo.cpp +++ b/modules/commands/os_modinfo.cpp @@ -204,8 +204,9 @@ class OSModInfo : public Module CommandOSModList commandosmodlist; public: - OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosmodinfo(this), commandosmodlist(this) + OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosmodinfo(this) + , commandosmodlist(this) { } diff --git a/modules/commands/os_module.cpp b/modules/commands/os_module.cpp index f1d113265..c4f814ee3 100644 --- a/modules/commands/os_module.cpp +++ b/modules/commands/os_module.cpp @@ -177,8 +177,10 @@ class OSModule : public Module CommandOSModUnLoad commandosmodunload; public: - OSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosmodload(this), commandosmodreload(this), commandosmodunload(this) + OSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosmodload(this) + , commandosmodreload(this) + , commandosmodunload(this) { this->SetPermanent(true); diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp index 1ecc9773d..62379e30a 100644 --- a/modules/commands/os_news.cpp +++ b/modules/commands/os_news.cpp @@ -370,6 +370,8 @@ class CommandOSRandomNews : public NewsBase static unsigned cur_rand_news = 0; class OSNews : public Module + , public EventHook<Event::UserModeSet> + , public EventHook<Event::UserConnect> { MyNewsService newsservice; Serialize::Type newsitem_type; @@ -428,9 +430,14 @@ class OSNews : public Module } public: - OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - newsservice(this), newsitem_type("NewsItem", MyNewsItem::Unserialize), - commandoslogonnews(this), commandosopernews(this), commandosrandomnews(this) + OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserModeSet>("OnUserModeSet") + , EventHook<Event::UserConnect>("OnUserConnect") + , newsservice(this) + , newsitem_type("NewsItem", MyNewsItem::Unserialize) + , commandoslogonnews(this) + , commandosopernews(this) + , commandosrandomnews(this) { } diff --git a/modules/commands/os_noop.cpp b/modules/commands/os_noop.cpp index 2eb818451..061624724 100644 --- a/modules/commands/os_noop.cpp +++ b/modules/commands/os_noop.cpp @@ -74,13 +74,16 @@ class CommandOSNOOP : public Command }; class OSNOOP : public Module + , public EventHook<Event::UserModeSet> { CommandOSNOOP commandosnoop; PrimitiveExtensibleItem<Anope::string> noop; public: - OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosnoop(this), noop(this, "noop") + OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserModeSet>("OnUserModeSet") + , commandosnoop(this) + , noop(this, "noop") { } diff --git a/modules/commands/os_oline.cpp b/modules/commands/os_oline.cpp index 143924b47..6d1d5d443 100644 --- a/modules/commands/os_oline.cpp +++ b/modules/commands/os_oline.cpp @@ -65,8 +65,8 @@ class OSOLine : public Module CommandOSOLine commandosoline; public: - OSOLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosoline(this) + OSOLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosoline(this) { if (!IRCD || !IRCD->CanSVSO) diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp index cd9eddfdb..a18b022ab 100644 --- a/modules/commands/os_oper.cpp +++ b/modules/commands/os_oper.cpp @@ -235,8 +235,9 @@ class OSOper : public Module CommandOSOper commandosoper; public: - OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - myoper_type("Oper", MyOper::Unserialize), commandosoper(this) + OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , myoper_type("Oper", MyOper::Unserialize) + , commandosoper(this) { } diff --git a/modules/commands/os_reload.cpp b/modules/commands/os_reload.cpp index 140118ba4..647f187b4 100644 --- a/modules/commands/os_reload.cpp +++ b/modules/commands/os_reload.cpp @@ -54,8 +54,8 @@ class OSReload : public Module CommandOSReload commandosreload; public: - OSReload(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosreload(this) + OSReload(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosreload(this) { } diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp index 94a2f9f0f..9cb525b4d 100644 --- a/modules/commands/os_session.cpp +++ b/modules/commands/os_session.cpp @@ -33,6 +33,8 @@ namespace /* Number of bits to use when comparing session IPs */ unsigned ipv4_cidr; unsigned ipv6_cidr; + + EventHandlers<Event::Exception> *events; } class MySessionService : public SessionService @@ -163,7 +165,7 @@ class ExceptionDelCallback : public NumberList static void DoDel(CommandSource &source, unsigned index) { Exception *e = session_service->GetExceptions()[index]; - FOREACH_MOD(OnExceptionDel, (source, e)); + (*events)(&Event::Exception::OnExceptionDel, source, e); session_service->DelException(e); delete e; @@ -372,7 +374,7 @@ class CommandOSException : public Command exception->expires = expires; EventReturn MOD_RESULT; - FOREACH_RESULT(OnExceptionAdd, MOD_RESULT, (exception)); + MOD_RESULT = (*events)(&Event::Exception::OnExceptionAdd, exception); if (MOD_RESULT == EVENT_STOP) delete exception; else @@ -627,20 +629,32 @@ class CommandOSException : public Command }; class OSSession : public Module + , public EventHook<Event::UserConnect> + , public EventHook<Event::UserQuit> + , public EventHook<Event::ExpireTick> { Serialize::Type exception_type; MySessionService ss; CommandOSSession commandossession; CommandOSException commandosexception; ServiceReference<XLineManager> akills; + EventHandlers<Event::Exception> exceptionevents; public: - OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - exception_type("Exception", Exception::Unserialize), ss(this), commandossession(this), commandosexception(this), akills("XLineManager", "xlinemanager/sgline") + OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserConnect>("OnUserConnect", EventHook<Event::UserConnect>::Priority::FIRST) + , EventHook<Event::UserQuit>("OnUserQuit", EventHook<Event::UserQuit>::Priority::FIRST) + , EventHook<Event::ExpireTick>("OnExpireTick", EventHook<Event::ExpireTick>::Priority::FIRST) + , exception_type("Exception", Exception::Unserialize) + , ss(this) + , commandossession(this) + , commandosexception(this) + , akills("XLineManager", "xlinemanager/sgline") + , exceptionevents(this, "Exception") { this->SetPermanent(true); - ModuleManager::SetPriority(this, PRIORITY_FIRST); + events = &exceptionevents; } void OnReload(Configuration::Conf *conf) override diff --git a/modules/commands/os_set.cpp b/modules/commands/os_set.cpp index 1f8959408..bc58b7dc1 100644 --- a/modules/commands/os_set.cpp +++ b/modules/commands/os_set.cpp @@ -258,8 +258,8 @@ class OSSet : public Module CommandOSSet commandosset; public: - OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosset(this) + OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosset(this) { } }; diff --git a/modules/commands/os_stats.cpp b/modules/commands/os_stats.cpp index c5ab3459c..d55bdb1dc 100644 --- a/modules/commands/os_stats.cpp +++ b/modules/commands/os_stats.cpp @@ -253,8 +253,9 @@ class OSStats : public Module Stats stats_saver; public: - OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosstats(this), stats_type("Stats", Stats::Unserialize) + OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosstats(this) + , stats_type("Stats", Stats::Unserialize) { } diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index 20b937bb0..43ae2b7d4 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -93,7 +93,7 @@ class CommandOSSXLineBase : public Command return; } - FOREACH_MOD(OnDelXLine, (source, x, this->xlm())); + Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, this->xlm()); SXLineDelCallback::DoDel(this->xlm(), source, x); source.Reply(_("\002%s\002 deleted from the %s list."), mask.c_str(), source.command.c_str()); @@ -202,7 +202,7 @@ class CommandOSSXLineBase : public Command void OnClear(CommandSource &source) { - FOREACH_MOD(OnDelXLine, (source, NULL, this->xlm())); + Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, nullptr, this->xlm()); for (unsigned i = this->xlm()->GetCount(); i > 0; --i) { @@ -372,7 +372,7 @@ class CommandOSSNLine : public CommandOSSXLineBase } EventReturn MOD_RESULT; - FOREACH_RESULT(OnAddXLine, MOD_RESULT, (source, x, this->xlm())); + MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm()); if (MOD_RESULT == EVENT_STOP) { delete x; @@ -570,7 +570,7 @@ class CommandOSSQLine : public CommandOSSXLineBase } EventReturn MOD_RESULT; - FOREACH_RESULT(OnAddXLine, MOD_RESULT, (source, x, this->xlm())); + MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm()); if (MOD_RESULT == EVENT_STOP) { delete x; diff --git a/modules/commands/os_update.cpp b/modules/commands/os_update.cpp index 50be11d85..3f0d07d17 100644 --- a/modules/commands/os_update.cpp +++ b/modules/commands/os_update.cpp @@ -42,8 +42,8 @@ class OSUpdate : public Module CommandOSUpdate commandosupdate; public: - OSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandosupdate(this) + OSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandosupdate(this) { } diff --git a/modules/cs_statusupdate.cpp b/modules/cs_statusupdate.cpp index 2696d6c1a..58498ff40 100644 --- a/modules/cs_statusupdate.cpp +++ b/modules/cs_statusupdate.cpp @@ -8,9 +8,13 @@ #include "module.h" class StatusUpdate : public Module + , public EventHook<Event::AccessAdd> + , public EventHook<Event::AccessDel> { public: StatusUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::AccessAdd>("OnAccessAdd") + , EventHook<Event::AccessDel>("OnAccessDel") { } diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index c4b2254c8..50f1412b1 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -103,6 +103,11 @@ class LoadData : public Serialize::Data }; class DBFlatFile : public Module, public Pipe + , public EventHook<Event::Restart> + , public EventHook<Event::Shutdown> + , public EventHook<Event::LoadDatabase> + , public EventHook<Event::SaveDatabase> + , public EventHook<Event::SerializeTypeCreate> { /* Day the last backup was on */ int last_day; @@ -167,7 +172,15 @@ class DBFlatFile : public Module, public Pipe } public: - DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), last_day(0), loaded(false), child_pid(-1) + DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::Restart>("OnRestart") + , EventHook<Event::Shutdown>("OnShutdown") + , EventHook<Event::LoadDatabase>("OnLoadDatabase") + , EventHook<Event::SaveDatabase>("OnSaveDatabase") + , EventHook<Event::SerializeTypeCreate>("OnSerializeTypeCreate") + , last_day(0) + , loaded(false) + , child_pid(-1) { } diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp index 82f26e064..f80d55d5a 100644 --- a/modules/database/db_old.cpp +++ b/modules/database/db_old.cpp @@ -1294,16 +1294,21 @@ static void LoadNews() } class DBOld : public Module + , public EventHook<Event::LoadDatabase> + , public EventHook<Event::UplinkSync> { PrimitiveExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit; PrimitiveExtensibleItem<Anope::string> mlock_key; public: - DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), - mlock_on(this, "mlock_on"), mlock_off(this, "mlock_off"), mlock_limit(this, "mlock_limit"), mlock_key(this, "mlock_key") + DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>("OnLoadDatabase") + , EventHook<Event::UplinkSync>("OnUplinkSync") + , mlock_on(this, "mlock_on") + , mlock_off(this, "mlock_off") + , mlock_limit(this, "mlock_limit") + , mlock_key(this, "mlock_key") { - - hashm = Config->GetModule(this)->Get<const Anope::string>("hash"); if (hashm != "md5" && hashm != "oldmd5" && hashm != "sha1" && hashm != "plain" && hashm != "sha256") diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp index d7585bc32..81b1f083f 100644 --- a/modules/database/db_redis.cpp +++ b/modules/database/db_redis.cpp @@ -121,6 +121,11 @@ class SubscriptionListener : public Interface }; class DatabaseRedis : public Module, public Pipe + , public EventHook<Event::LoadDatabase> + , public EventHook<Event::SerializeTypeCreate> + , public EventHook<Event::SerializableConstruct> + , public EventHook<Event::SerializableDestruct> + , public EventHook<Event::SerializableUpdate> { SubscriptionListener sl; std::set<Serializable *> updated_items; @@ -128,7 +133,13 @@ class DatabaseRedis : public Module, public Pipe public: ServiceReference<Provider> redis; - DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sl(this) + DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>("OnLoadDatabase") + , EventHook<Event::SerializeTypeCreate>("OnSerializeTypeCreate") + , EventHook<Event::SerializableConstruct>("OnSerializableConstruct") + , EventHook<Event::SerializableDestruct>("OnSerializableDestruct") + , EventHook<Event::SerializableUpdate>("OnSerializableUpdate") + , sl(this) { me = this; diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 34ae7cfea..5d213cb9a 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -55,6 +55,13 @@ public: }; class DBSQL : public Module, public Pipe + , public EventHook<Event::Shutdown> + , public EventHook<Event::Restart> + , public EventHook<Event::LoadDatabase> + , public EventHook<Event::SerializableConstruct> + , public EventHook<Event::SerializableDestruct> + , public EventHook<Event::SerializableUpdate> + , public EventHook<Event::SerializeTypeCreate> { ServiceReference<Provider> sql; SQLSQLInterface sqlinterface; @@ -89,7 +96,19 @@ class DBSQL : public Module, public Pipe } public: - DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), sql("", ""), sqlinterface(this), shutting_down(false), loading_databases(false), loaded(false), imported(false) + DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::Shutdown>("OnShutdown") + , EventHook<Event::Restart>("OnRestart") + , EventHook<Event::LoadDatabase>("OnLoadDatabase") + , EventHook<Event::SerializableConstruct>("OnSerializableConstruct") + , EventHook<Event::SerializableDestruct>("OnSerializableDestruct") + , EventHook<Event::SerializableUpdate>("OnSerializableUpdate") + , EventHook<Event::SerializeTypeCreate>("OnSerializeTypeCreate") + , sqlinterface(this) + , shutting_down(false) + , loading_databases(false) + , loaded(false) + , imported(false) { diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index 0099ff5e2..ad10f0a7d 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -4,6 +4,13 @@ using namespace SQL; class DBMySQL : public Module, public Pipe + , public EventHook<Event::LoadDatabase> + , public EventHook<Event::Shutdown> + , public EventHook<Event::Restart> + , public EventHook<Event::SerializableConstruct> + , public EventHook<Event::SerializableDestruct> + , public EventHook<Event::SerializeCheck> + , public EventHook<Event::SerializableUpdate> { private: Anope::string prefix; @@ -64,7 +71,14 @@ class DBMySQL : public Module, public Pipe } public: - DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), SQL("", "") + DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>("OnLoadDatabase") + , EventHook<Event::Shutdown>("OnShutdown") + , EventHook<Event::Restart>("OnRestart") + , EventHook<Event::SerializableConstruct>("OnSerializableConstruct") + , EventHook<Event::SerializableDestruct>("OnSerializableDestruct") + , EventHook<Event::SerializeCheck>("OnSerializeCheck") + , EventHook<Event::SerializableUpdate>("OnSerializableUpdate") { this->lastwarn = 0; this->ro = false; diff --git a/modules/encryption/enc_bcrypt.cpp b/modules/encryption/enc_bcrypt.cpp index 8ed5695ac..020bafe6e 100644 --- a/modules/encryption/enc_bcrypt.cpp +++ b/modules/encryption/enc_bcrypt.cpp @@ -841,6 +841,8 @@ char *_crypt_gensalt_blowfish_rn(const char *prefix, unsigned long count, #include "modules/encryption.h" class EBCRYPT : public Module + , public EventHook<Event::Encrypt> + , public EventHook<Event::CheckAuthentication> { unsigned int rounds; @@ -873,8 +875,10 @@ class EBCRYPT : public Module } public: - EBCRYPT(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR | EXTRA), - rounds(10) + EBCRYPT(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR | EXTRA) + , EventHook<Event::Encrypt>("OnEncrypt") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") + , rounds(10) { // Test a pre-calculated hash bool test = Compare("Test!", "$2a$10$x9AQFAQScY0v9KF2suqkEOepsHFrG.CXHbIXI.1F28SfSUb56A/7K"); diff --git a/modules/encryption/enc_md5.cpp b/modules/encryption/enc_md5.cpp index b49390d56..838c5712f 100644 --- a/modules/encryption/enc_md5.cpp +++ b/modules/encryption/enc_md5.cpp @@ -338,12 +338,16 @@ class MD5Provider : public Encryption::Provider }; class EMD5 : public Module + , public EventHook<Event::Encrypt> + , public EventHook<Event::CheckAuthentication> { MD5Provider md5provider; public: - EMD5(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR), - md5provider(this) + EMD5(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>("OnEncrypt") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") + , md5provider(this) { } diff --git a/modules/encryption/enc_none.cpp b/modules/encryption/enc_none.cpp index ae698914c..1346177f7 100644 --- a/modules/encryption/enc_none.cpp +++ b/modules/encryption/enc_none.cpp @@ -10,9 +10,15 @@ #include "module.h" class ENone : public Module + , public EventHook<Event::Encrypt> + , public EventHook<Event::Decrypt> + , public EventHook<Event::CheckAuthentication> { public: ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>("OnEncrypt") + , EventHook<Event::Decrypt>("OnDecrypt") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") { } diff --git a/modules/encryption/enc_old.cpp b/modules/encryption/enc_old.cpp index 89c228b1d..b885eb777 100644 --- a/modules/encryption/enc_old.cpp +++ b/modules/encryption/enc_old.cpp @@ -35,14 +35,18 @@ class OldMD5Provider : public Encryption::Provider }; class EOld : public Module + , public EventHook<Event::Encrypt> + , public EventHook<Event::CheckAuthentication> { OldMD5Provider oldmd5provider; inline static char XTOI(char c) { return c > 9 ? c - 'A' + 10 : c - '0'; } public: - EOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR), - oldmd5provider(this) + EOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>("OnEncrypt") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") + , oldmd5provider(this) { ModuleManager::LoadModule("enc_md5", User::Find(creator)); diff --git a/modules/encryption/enc_sha1.cpp b/modules/encryption/enc_sha1.cpp index 79d657493..f65b5d5ea 100644 --- a/modules/encryption/enc_sha1.cpp +++ b/modules/encryption/enc_sha1.cpp @@ -193,12 +193,16 @@ class SHA1Provider : public Encryption::Provider }; class ESHA1 : public Module + , public EventHook<Event::Encrypt> + , public EventHook<Event::CheckAuthentication> { SHA1Provider sha1provider; public: - ESHA1(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR), - sha1provider(this) + ESHA1(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>("OnEncrypt") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") + , sha1provider(this) { } diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp index 8be792346..9cd682c57 100644 --- a/modules/encryption/enc_sha256.cpp +++ b/modules/encryption/enc_sha256.cpp @@ -237,6 +237,8 @@ class SHA256Provider : public Encryption::Provider }; class ESHA256 : public Module + , public EventHook<Event::Encrypt> + , public EventHook<Event::CheckAuthentication> { SHA256Provider sha256provider; @@ -273,8 +275,10 @@ class ESHA256 : public Module } public: - ESHA256(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR), - sha256provider(this) + ESHA256(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>("OnEncrypt") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") + , sha256provider(this) { diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp index eb5589032..1615d855c 100644 --- a/modules/extra/m_ldap.cpp +++ b/modules/extra/m_ldap.cpp @@ -444,11 +444,13 @@ class LDAPService : public LDAPProvider, public Thread, public Condition }; class ModuleLDAP : public Module, public Pipe + , public EventHook<Event::ModuleUnload> { std::map<Anope::string, LDAPService *> LDAPServices; public: ModuleLDAP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>("OnModuleUnload") { me = this; diff --git a/modules/extra/m_ldap_authentication.cpp b/modules/extra/m_ldap_authentication.cpp index 1a4feb232..abd5cc33c 100644 --- a/modules/extra/m_ldap_authentication.cpp +++ b/modules/extra/m_ldap_authentication.cpp @@ -1,5 +1,6 @@ #include "module.h" #include "modules/ldap.h" +#include "modules/nickserv.h" static Module *me; @@ -104,7 +105,7 @@ class IdentifyInterface : public LDAPInterface { na = new NickAlias(ii->req->GetAccount(), new NickCore(ii->req->GetAccount())); na->last_realname = ii->user ? ii->user->realname : ii->req->GetAccount(); - FOREACH_MOD(OnNickRegister, (ii->user, na)); + NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na); BotInfo *NickServ = Config->GetClient("NickServ"); if (ii->user && NickServ) ii->user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->nick.c_str()); @@ -202,6 +203,10 @@ class OnRegisterInterface : public LDAPInterface }; class NSIdentifyLDAP : public Module + , public EventHook<Event::PreCommand> + , public EventHook<Event::CheckAuthentication> + , public EventHook<Event::NickIdentify> + , public EventHook<NickServ::Event::NickRegister> { ServiceReference<LDAPProvider> ldap; IdentifyInterface iinterface; @@ -214,14 +219,20 @@ class NSIdentifyLDAP : public Module Anope::string disable_register_reason; Anope::string disable_email_reason; public: - NSIdentifyLDAP(const Anope::string &modname, const Anope::string &creator) : - Module(modname, creator, EXTRA | VENDOR), ldap("LDAPProvider", "ldap/main"), iinterface(this), oninterface(this), orinterface(this), - dn(this, "m_ldap_authentication_dn") + + NSIdentifyLDAP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::PreCommand>("OnPreCommand", EventHook<Event::PreCommand>::Priority::FIRST) + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication", EventHook<Event::CheckAuthentication>::Priority::FIRST) + , EventHook<Event::NickIdentify>("OnNickIdentify", EventHook<Event::NickIdentify>::Priority::FIRST) + , EventHook<NickServ::Event::NickRegister>("OnNickRegister", EventHook<NickServ::Event::NickRegister>::Priority::FIRST) + , ldap("LDAPProvider", "ldap/main") + , iinterface(this) + , oninterface(this) + , orinterface(this) + , dn(this, "m_ldap_authentication_dn") { me = this; - - ModuleManager::SetPriority(this, PRIORITY_FIRST); } void OnReload(Configuration::Conf *config) override diff --git a/modules/extra/m_ldap_oper.cpp b/modules/extra/m_ldap_oper.cpp index e265bfd9d..7c6db48f5 100644 --- a/modules/extra/m_ldap_oper.cpp +++ b/modules/extra/m_ldap_oper.cpp @@ -76,6 +76,8 @@ class IdentifyInterface : public LDAPInterface }; class LDAPOper : public Module + , public EventHook<Event::NickIdentify> + , public EventHook<Event::DelCore> { ServiceReference<LDAPProvider> ldap; IdentifyInterface iinterface; @@ -85,8 +87,11 @@ class LDAPOper : public Module Anope::string basedn; Anope::string filter; public: - LDAPOper(const Anope::string &modname, const Anope::string &creator) : - Module(modname, creator, EXTRA | VENDOR), ldap("LDAPProvider", "ldap/main"), iinterface(this) + LDAPOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::NickIdentify>("OnNickIdentify") + , EventHook<Event::DelCore>("OnDelCore") + , ldap("LDAPProvider", "ldap/main") + , iinterface(this) { } diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp index 808cdd264..d0db90195 100644 --- a/modules/extra/m_mysql.cpp +++ b/modules/extra/m_mysql.cpp @@ -153,7 +153,9 @@ class DispatcherThread : public Thread, public Condition class ModuleSQL; static ModuleSQL *me; -class ModuleSQL : public Module, public Pipe +class ModuleSQL : public Module + , public Pipe + , public EventHook<Event::ModuleUnload> { /* SQL connections */ std::map<Anope::string, MySQLService *> MySQLServices; @@ -166,6 +168,7 @@ class ModuleSQL : public Module, public Pipe DispatcherThread *DThread; ModuleSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>("OnModuleUnload") { me = this; diff --git a/modules/extra/m_sasl_dh-aes.cpp b/modules/extra/m_sasl_dh-aes.cpp index 0a73f7788..f3294bfc1 100644 --- a/modules/extra/m_sasl_dh-aes.cpp +++ b/modules/extra/m_sasl_dh-aes.cpp @@ -160,7 +160,7 @@ class DHAES : public Mechanism return Err(sess, pubkey); SASL::IdentifyRequest* req = new SASL::IdentifyRequest(this->owner, m.source, username, password); - FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); BN_free(pubkey); @@ -174,8 +174,8 @@ class ModuleSASLDHAES : public Module DHAES dhaes; public: - ModuleSASLDHAES(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA), - dhaes(this) + ModuleSASLDHAES(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA) + , dhaes(this) { } }; diff --git a/modules/extra/m_sasl_dh-blowfish.cpp b/modules/extra/m_sasl_dh-blowfish.cpp index b310c1089..b32e8855e 100644 --- a/modules/extra/m_sasl_dh-blowfish.cpp +++ b/modules/extra/m_sasl_dh-blowfish.cpp @@ -170,7 +170,7 @@ class DHBS : public Mechanism return Err(sess, pubkey); SASL::IdentifyRequest* req = new SASL::IdentifyRequest(this->owner, m.source, username, password); - FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); BN_free(pubkey); @@ -184,8 +184,8 @@ class ModuleSASLDHBS : public Module DHBS dhbs; public: - ModuleSASLDHBS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA), - dhbs(this) + ModuleSASLDHBS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA) + , dhbs(this) { } }; diff --git a/modules/extra/m_sql_authentication.cpp b/modules/extra/m_sql_authentication.cpp index b3c0fd6b7..65f0f2800 100644 --- a/modules/extra/m_sql_authentication.cpp +++ b/modules/extra/m_sql_authentication.cpp @@ -1,5 +1,6 @@ #include "module.h" #include "modules/sql.h" +#include "modules/nickserv.h" static Module *me; @@ -42,7 +43,7 @@ class SQLAuthenticationResult : public SQL::Interface if (na == NULL) { na = new NickAlias(req->GetAccount(), new NickCore(req->GetAccount())); - FOREACH_MOD(OnNickRegister, (user, na)); + 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()); } @@ -66,6 +67,8 @@ class SQLAuthenticationResult : public SQL::Interface }; class ModuleSQLAuthentication : public Module + , public EventHook<Event::PreCommand> + , public EventHook<Event::CheckAuthentication> { Anope::string engine; Anope::string query; @@ -75,6 +78,8 @@ class ModuleSQLAuthentication : public Module public: ModuleSQLAuthentication(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::PreCommand>("OnPreCommand") + , EventHook<Event::CheckAuthentication>("OnCheckAuthentication") { me = this; diff --git a/modules/extra/m_sql_log.cpp b/modules/extra/m_sql_log.cpp index 475ff1253..496ecb5e6 100644 --- a/modules/extra/m_sql_log.cpp +++ b/modules/extra/m_sql_log.cpp @@ -11,12 +11,14 @@ #include "modules/sql.h" class SQLLog : public Module + , public EventHook<Event::LogMessage> { std::set<Anope::string> inited; Anope::string table; public: SQLLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA) + , EventHook<Event::LogMessage>("OnLogMessage") { } diff --git a/modules/extra/m_sql_oper.cpp b/modules/extra/m_sql_oper.cpp index 01d1fa174..90fab856a 100644 --- a/modules/extra/m_sql_oper.cpp +++ b/modules/extra/m_sql_oper.cpp @@ -90,6 +90,7 @@ class SQLOperResult : public SQL::Interface }; class ModuleSQLOper : public Module + , public EventHook<Event::NickIdentify> { Anope::string engine; Anope::string query; @@ -97,7 +98,8 @@ class ModuleSQLOper : public Module ServiceReference<SQL::Provider> SQL; public: - ModuleSQLOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + ModuleSQLOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), + EventHook<Event::NickIdentify>("OnNickIdentify") { } diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp index 1e9fdad7b..c0f503141 100644 --- a/modules/extra/m_sqlite.cpp +++ b/modules/extra/m_sqlite.cpp @@ -63,6 +63,7 @@ class ModuleSQLite : public Module { /* SQL connections */ std::map<Anope::string, SQLiteService *> SQLiteServices; + public: ModuleSQLite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) { diff --git a/modules/extra/m_ssl_gnutls.cpp b/modules/extra/m_ssl_gnutls.cpp index 8ad6ee684..492536c5c 100644 --- a/modules/extra/m_ssl_gnutls.cpp +++ b/modules/extra/m_ssl_gnutls.cpp @@ -293,6 +293,7 @@ namespace GnuTLS } class GnuTLSModule : public Module + , public EventHook<Event::PreServerConnect> { GnuTLS::Init libinit; @@ -300,7 +301,10 @@ class GnuTLSModule : public Module GnuTLS::X509CertCredentials *cred; MySSLService service; - GnuTLSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), cred(NULL), service(this, "ssl") + GnuTLSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::PreServerConnect>("OnPreServerConnect") + , cred(NULL) + , service(this, "ssl") { me = this; this->SetPermanent(true); diff --git a/modules/extra/m_ssl_openssl.cpp b/modules/extra/m_ssl_openssl.cpp index 4e35c0dbf..3344f1d28 100644 --- a/modules/extra/m_ssl_openssl.cpp +++ b/modules/extra/m_ssl_openssl.cpp @@ -81,13 +81,16 @@ class SSLSocketIO : public SocketIO class SSLModule; static SSLModule *me; class SSLModule : public Module + , public EventHook<Event::PreServerConnect> { Anope::string certfile, keyfile; public: MySSLService service; - SSLModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), service(this, "ssl") + SSLModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::PreServerConnect>("OnPreServerConnect") + , service(this, "ssl") { me = this; diff --git a/modules/extra/stats/cs_fantasy_top.cpp b/modules/extra/stats/cs_fantasy_top.cpp index 7f4092fe2..540a4f3d9 100644 --- a/modules/extra/stats/cs_fantasy_top.cpp +++ b/modules/extra/stats/cs_fantasy_top.cpp @@ -151,7 +151,7 @@ class CSTop : public Module { source.Reply(_("%2lu \002%-16s\002 letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"), i+1, res.Get(i, "nick").c_str(), res.Get(i, "letters").c_str(), - res.Get(i, "words").c_str(), res.Get(i, "line").c_str(), + res.Get(i, "words").c_str(), res.Get(i, "line").c_str(), res.Get(i, "smileys").c_str(), res.Get(i, "actions").c_str()); } } diff --git a/modules/extra/stats/m_chanstats.cpp b/modules/extra/stats/m_chanstats.cpp index a1674bce3..e80c3e456 100644 --- a/modules/extra/stats/m_chanstats.cpp +++ b/modules/extra/stats/m_chanstats.cpp @@ -20,7 +20,7 @@ class CommandCSSetChanstats : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -73,7 +73,7 @@ class CommandNSSetChanstats : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, na->nc, param)); + MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, na->nc, param); if (MOD_RESULT == EVENT_STOP) return; diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp index 1e8bc4e10..e89b35365 100644 --- a/modules/fantasy.cpp +++ b/modules/fantasy.cpp @@ -10,6 +10,7 @@ */ #include "module.h" +#include "modules/fantasy.h" class CommandBSSetFantasy : public Command { @@ -81,14 +82,22 @@ class CommandBSSetFantasy : public Command }; class Fantasy : public Module + , public EventHook<Event::Privmsg> { SerializableExtensibleItem<bool> fantasy; CommandBSSetFantasy commandbssetfantasy; + EventHandlers<Event::BotFantasy> OnBotFantasy; + EventHandlers<Event::BotNoFantasyAccess> OnBotNoFantasyAccess; + public: - Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - fantasy(this, "BS_FANTASY"), commandbssetfantasy(this) + Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Privmsg>("OnPrivmsg") + , fantasy(this, "BS_FANTASY") + , commandbssetfantasy(this) + , OnBotFantasy(this, "OnBotFantasy") + , OnBotNoFantasyAccess(this, "OnBotNoFantasyAccess") { } @@ -168,11 +177,11 @@ class Fantasy : public Module EventReturn MOD_RESULT; if (has_fantasia) { - FOREACH_RESULT(OnBotFantasy, MOD_RESULT, (source, cmd, c->ci, params)); + MOD_RESULT = this->OnBotFantasy(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params); } else { - FOREACH_RESULT(OnBotNoFantasyAccess, MOD_RESULT, (source, cmd, c->ci, params)); + MOD_RESULT = this->OnBotNoFantasyAccess(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params); } if (MOD_RESULT == EVENT_STOP || !has_fantasia) @@ -181,7 +190,7 @@ class Fantasy : public Module if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission)) return; - FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, cmd, params)); + MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, cmd, params); if (MOD_RESULT == EVENT_STOP) return; @@ -189,7 +198,7 @@ class Fantasy : public Module cmd->Execute(source, params); if (!nc_reference) source.nc = NULL; - FOREACH_MOD(OnPostCommand, (source, cmd, params)); + Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, cmd, params); } void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) diff --git a/modules/m_dns.cpp b/modules/m_dns.cpp index eaf9ba428..dfe44516a 100644 --- a/modules/m_dns.cpp +++ b/modules/m_dns.cpp @@ -823,7 +823,7 @@ class MyManager : public Manager, public Timer } } - FOREACH_MOD(OnDnsRequest, (recv_packet, packet)); + Event::OnDnsRequest(&Event::DnsRequest::OnDnsRequest, recv_packet, packet); for (unsigned i = 0; i < recv_packet.questions.size(); ++i) { @@ -1004,6 +1004,7 @@ class MyManager : public Manager, public Timer }; class ModuleDNS : public Module + , public EventHook<Event::ModuleUnload> { MyManager manager; @@ -1014,7 +1015,9 @@ class ModuleDNS : public Module std::vector<std::pair<Anope::string, short> > notify; public: - ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), manager(this) + ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>("OnModuleUnload") + , manager(this) { } diff --git a/modules/m_dnsbl.cpp b/modules/m_dnsbl.cpp index 414598441..c5dd94f21 100644 --- a/modules/m_dnsbl.cpp +++ b/modules/m_dnsbl.cpp @@ -80,6 +80,7 @@ class DNSBLResolver : public Request }; class ModuleDNSBL : public Module + , public EventHook<Event::UserConnect> { std::vector<Blacklist> blacklists; bool check_on_connect; @@ -88,6 +89,7 @@ class ModuleDNSBL : public Module public: ModuleDNSBL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA) + , EventHook<Event::UserConnect>("OnUserConnect") { } diff --git a/modules/m_helpchan.cpp b/modules/m_helpchan.cpp index 1cde06c5a..07c9ff142 100644 --- a/modules/m_helpchan.cpp +++ b/modules/m_helpchan.cpp @@ -8,9 +8,11 @@ #include "module.h" class HelpChannel : public Module + , public EventHook<Event::ChannelModeSet> { public: HelpChannel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChannelModeSet>("OnChannelModeSet") { } diff --git a/modules/m_httpd.cpp b/modules/m_httpd.cpp index 88244b03b..314badc55 100644 --- a/modules/m_httpd.cpp +++ b/modules/m_httpd.cpp @@ -334,11 +334,14 @@ class MyHTTPProvider : public HTTPProvider, public Timer }; class HTTPD : public Module + , public EventHook<Event::ModuleLoad> { ServiceReference<SSLService> sslref; std::map<Anope::string, MyHTTPProvider *> providers; public: - HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), sslref("SSLService", "ssl") + HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleLoad>("OnModuleLoad") + , sslref("SSLService", "ssl") { } diff --git a/modules/m_proxyscan.cpp b/modules/m_proxyscan.cpp index 9918c4232..c67bb620f 100644 --- a/modules/m_proxyscan.cpp +++ b/modules/m_proxyscan.cpp @@ -189,6 +189,7 @@ class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket }; class ModuleProxyScan : public Module + , public EventHook<Event::UserConnect> { Anope::string listen_ip; unsigned short listen_port; @@ -217,8 +218,9 @@ class ModuleProxyScan : public Module } connectionTimeout; public: - ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - connectionTimeout(this, 5) + ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::UserConnect>("OnUserConnect") + , connectionTimeout(this, 5) { diff --git a/modules/m_redis.cpp b/modules/m_redis.cpp index 2dff7382e..1869cf0dc 100644 --- a/modules/m_redis.cpp +++ b/modules/m_redis.cpp @@ -521,11 +521,13 @@ bool RedisSocket::Read(const char *buffer, size_t l) class ModuleRedis : public Module + , public EventHook<Event::ModuleUnload> { std::map<Anope::string, MyRedisService *> services; public: ModuleRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>("OnModuleUnload") { } diff --git a/modules/m_rewrite.cpp b/modules/m_rewrite.cpp index b12331665..940308c12 100644 --- a/modules/m_rewrite.cpp +++ b/modules/m_rewrite.cpp @@ -153,7 +153,8 @@ class ModuleRewrite : public Module RewriteCommand cmdrewrite; public: - ModuleRewrite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA), cmdrewrite(this) + ModuleRewrite(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA) + , cmdrewrite(this) { } diff --git a/modules/m_sasl.cpp b/modules/m_sasl.cpp index b8ecbc3a0..e38e865ff 100644 --- a/modules/m_sasl.cpp +++ b/modules/m_sasl.cpp @@ -44,7 +44,7 @@ class Plain : public Mechanism return; SASL::IdentifyRequest *req = new SASL::IdentifyRequest(this->owner, m.source, acc, pass); - FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); } } @@ -254,8 +254,10 @@ class ModuleSASL : public Module External *external; public: - ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - sasl(this), plain(this), external(NULL) + ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , sasl(this) + , plain(this) + , external(NULL) { try { diff --git a/modules/m_xmlrpc.cpp b/modules/m_xmlrpc.cpp index 2d2814143..e92650a89 100644 --- a/modules/m_xmlrpc.cpp +++ b/modules/m_xmlrpc.cpp @@ -161,8 +161,9 @@ class ModuleXMLRPC : public Module public: MyXMLRPCServiceInterface xmlrpcinterface; - ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - httpref("HTTPProvider", "httpd/main"), xmlrpcinterface(this, "xmlrpc") + ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , httpref("HTTPProvider", "httpd/main") + , xmlrpcinterface(this, "xmlrpc") { if (!httpref) throw ModuleException("Unable to find http reference, is m_httpd loaded?"); diff --git a/modules/m_xmlrpc_main.cpp b/modules/m_xmlrpc_main.cpp index 0f46f09e1..011b2d250 100644 --- a/modules/m_xmlrpc_main.cpp +++ b/modules/m_xmlrpc_main.cpp @@ -117,7 +117,7 @@ class MyXMLRPCEvent : public XMLRPCEvent else { XMLRPCIdentifyRequest *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password); - FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); return false; } diff --git a/modules/ns_maxemail.cpp b/modules/ns_maxemail.cpp index fe4746927..a7e2f29ac 100644 --- a/modules/ns_maxemail.cpp +++ b/modules/ns_maxemail.cpp @@ -13,6 +13,7 @@ #include "module.h" class NSMaxEmail : public Module + , public EventHook<Event::PreCommand> { bool CheckLimitReached(CommandSource &source, const Anope::string &email) { @@ -52,6 +53,7 @@ class NSMaxEmail : public Module public: NSMaxEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::PreCommand>("OnPreCommand") { } diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 439bfd387..5c1a23426 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -466,6 +466,7 @@ struct IRCDMessageTopic : IRCDMessage }; class ProtoBahamut : public Module + , public EventHook<Event::UserNickChange> { BahamutIRCdProto ircd_proto; @@ -535,15 +536,35 @@ class ProtoBahamut : public Module } public: - ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), - message_join(this), message_kick(this), message_kill(this), message_motd(this), message_notice(this), - message_part(this), message_ping(this), message_privmsg(this), message_quit(this), - message_squit(this), message_stats(this), message_time(this), message_version(this), message_whois(this), - - message_burst(this), message_mode(this, "MODE"), message_svsmode(this, "SVSMODE"), - message_nick(this), message_server(this), message_sjoin(this), message_topic(this) + ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>("OnUserNickChange") + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_burst(this) + , message_mode(this, "MODE") + , message_svsmode(this, "SVSMODE") + , message_nick(this) + , message_server(this) + , message_sjoin(this) + , message_topic(this) { this->AddModes(); diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index eed63edbf..68bf31e76 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -175,7 +175,7 @@ struct IRCDMessageEncap : IRCDMessage if (params[1] == "CERTFP") { u->fingerprint = params[2]; - FOREACH_MOD(OnFingerprint, (u)); + Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); } /* * Received: :42X ENCAP * SASL 42XAAAAAH * S PLAIN @@ -258,6 +258,8 @@ struct IRCDMessagePass : IRCDMessage }; class ProtoCharybdis : public Module + , public EventHook<Event::ChannelSync> + , public EventHook<Event::MLockEvents> { Module *m_ratbox; @@ -321,24 +323,44 @@ class ProtoCharybdis : public Module } public: - ProtoCharybdis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), - message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this), - message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), - message_time(this), message_topic(this), message_version(this), message_whois(this), - - message_bmask("IRCDMessage", "charybdis/bmask", "ratbox/bmask"), - message_join("IRCDMessage", "charybdis/join", "ratbox/join"), - message_nick("IRCDMessage", "charybdis/nick", "ratbox/nick"), - message_pong("IRCDMessage", "charybdis/pong", "ratbox/pong"), - message_sid("IRCDMessage", "charybdis/sid", "ratbox/sid"), - message_sjoin("IRCDMessage", "charybdis/sjoin", "ratbox/sjoin"), - message_tb("IRCDMessage", "charybdis/tb", "ratbox/tb"), - message_tmode("IRCDMessage", "charybdis/tmode", "ratbox/tmode"), - message_uid("IRCDMessage", "charybdis/uid", "ratbox/uid"), - - message_encap(this), message_euid(this), message_pass(this), message_server(this) + ProtoCharybdis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::ChannelSync>("OnChannelSync") + , EventHook<Event::MLockEvents>("MLock") + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + + , message_bmask("IRCDMessage", "charybdis/bmask", "ratbox/bmask") + , message_join("IRCDMessage", "charybdis/join", "ratbox/join") + , message_nick("IRCDMessage", "charybdis/nick", "ratbox/nick") + , message_pong("IRCDMessage", "charybdis/pong", "ratbox/pong") + , message_sid("IRCDMessage", "charybdis/sid", "ratbox/sid") + , message_sjoin("IRCDMessage", "charybdis/sjoin", "ratbox/sjoin") + , message_tb("IRCDMessage", "charybdis/tb", "ratbox/tb") + , message_tmode("IRCDMessage", "charybdis/tmode", "ratbox/tmode") + , message_uid("IRCDMessage", "charybdis/uid", "ratbox/uid") + + , message_encap(this) + , message_euid(this) + , message_pass(this) + , message_server(this) { diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index dc5261403..d2b5b935a 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -558,11 +558,12 @@ struct IRCDMessageCertFP: IRCDMessage User *u = source.GetUser(); u->fingerprint = params[0]; - FOREACH_MOD(OnFingerprint, (u)); + Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); } }; class ProtoHybrid : public Module + , public EventHook<Event::UserNickChange> { HybridProto ircd_proto; @@ -651,16 +652,42 @@ class ProtoHybrid : public Module } public: - ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), - message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this), - message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), - message_time(this), message_topic(this), message_version(this), message_whois(this), - message_bmask(this), message_eob(this), message_join(this), - message_nick(this), message_pass(this), message_pong(this), message_server(this), message_sid(this), - message_sjoin(this), message_svsmode(this), message_tburst(this), message_tmode(this), message_uid(this), - message_certfp(this) + ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>("OnUserNickChange") + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + , message_bmask(this) + , message_eob(this) + , message_join(this) + , message_nick(this) + , message_pass(this) + , message_pong(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_svsmode(this) + , message_tburst(this) + , message_tmode(this) + , message_uid(this) + , message_certfp(this) { if (Config->GetModule(this)) this->AddModes(); diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 7949fd610..77ebb2fe6 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -12,6 +12,7 @@ #include "module.h" #include "modules/sasl.h" #include "modules/cs_mode.h" +#include "modules/cs_set.h" struct SASLUser { @@ -1188,7 +1189,7 @@ struct IRCDMessageMetadata : IRCDMessage { u->fingerprint = data.substr(pos1, pos2 - pos1); } - FOREACH_MOD(OnFingerprint, (u)); + Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); } } else if (params[0][0] == '#') @@ -1424,6 +1425,12 @@ struct IRCDMessageUID : IRCDMessage }; class ProtoInspIRCd20 : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::DelChan> + , public EventHook<Event::MLockEvents> + , public EventHook<Event::SetChannelOption> { InspIRCd20Proto ircd_proto; ExtensibleItem<bool> ssl; @@ -1472,16 +1479,48 @@ class ProtoInspIRCd20 : public Module } public: - ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), ssl(this, "ssl"), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), - message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_stats(this), message_topic(this), - - message_capab(this), message_encap(this), message_endburst(this), - message_fhost(this), message_fident(this), message_fjoin(this), message_fmode(this), message_ftopic(this), - message_idle(this), message_metadata(this), message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this), - message_server(this), message_squit(this), message_time(this), message_uid(this) + ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>("OnUserNickChange") + , EventHook<Event::ChannelSync>("OnChannelSync") + , EventHook<Event::ChanRegistered>("OnChanRegistered") + , EventHook<Event::DelChan>("OnDelChan") + , EventHook<Event::MLockEvents>("MLock") + , EventHook<Event::SetChannelOption>("OnSetChannelOption") + , ircd_proto(this) + , ssl(this, "ssl") + , message_away(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_stats(this) + , message_topic(this) + + , message_capab(this) + , message_encap(this) + , message_endburst(this) + , message_fhost(this) + , message_fident(this) + , message_fjoin(this) + , message_fmode(this) + , message_ftopic(this) + , message_idle(this) + , message_metadata(this) + , message_mode(this) + , message_nick(this) + , message_opertype(this) + , message_rsquit(this) + , message_server(this) + , message_squit(this) + , message_time(this) + , message_uid(this) { } diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index 998d83921..06790b2af 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -352,7 +352,7 @@ struct IRCDMessageMetadata : IRCDMessage else if (params[1].equals_cs("certfp")) { u->fingerprint = params[2]; - FOREACH_MOD(OnFingerprint, (u)); + Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); } else if (params[1].equals_cs("cloakhost")) { @@ -586,6 +586,7 @@ struct IRCDMessageTopic : IRCDMessage class ProtongIRCd : public Module + , public EventHook<Event::UserNickChange> { ngIRCdProto ircd_proto; @@ -666,16 +667,38 @@ class ProtongIRCd : public Module } public: - ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this), - message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), - message_squery(this, "SQUERY"), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_005(this), message_376(this), message_chaninfo(this), message_join(this), message_metadata(this), - message_mode(this), message_nick(this), message_njoin(this), message_pong(this), message_server(this), - message_topic(this) + ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>("OnUserNickChange") + , ircd_proto(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_squery(this, "SQUERY") + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_005(this) + , message_376(this) + , message_chaninfo(this) + , message_join(this) + , message_metadata(this) + , message_mode(this) + , message_nick(this) + , message_njoin(this) + , message_pong(this) + , message_server(this) + , message_topic(this) { Servers::Capab.insert("QS"); diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index a7ff0ae88..e4cc26e6a 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -204,7 +204,7 @@ struct IRCDMessageEncap : IRCDMessage if (u) { u->fingerprint = params[3]; - FOREACH_MOD(OnFingerprint, (u)); + Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); } } return; @@ -382,20 +382,41 @@ class ProtoPlexus : public Module } public: - ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this), - message_mode(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), - message_quit(this), message_squit(this), message_stats(this), message_time(this), message_topic(this), message_version(this), - message_whois(this), - - message_bmask("IRCDMessage", "plexus/bmask", "hybrid/bmask"), message_eob("IRCDMessage", "plexus/eob", "hybrid/eob"), - message_join("IRCDMessage", "plexus/join", "hybrid/join"), message_nick("IRCDMessage", "plexus/nick", "hybrid/nick"), - message_sid("IRCDMessage", "plexus/sid", "hybrid/sid"), - message_sjoin("IRCDMessage", "plexus/sjoin", "hybrid/sjoin"), message_tburst("IRCDMessage", "plexus/tburst", "hybrid/tburst"), - message_tmode("IRCDMessage", "plexus/tmode", "hybrid/tmode"), - - message_encap(this), message_pass(this), message_server(this), message_uid(this) + ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + + , message_bmask("IRCDMessage", "plexus/bmask", "hybrid/bmask") + , message_eob("IRCDMessage", "plexus/eob", "hybrid/eob") + , message_join("IRCDMessage", "plexus/join", "hybrid/join") + , message_nick("IRCDMessage", "plexus/nick", "hybrid/nick") + , message_sid("IRCDMessage", "plexus/sid", "hybrid/sid") + , message_sjoin("IRCDMessage", "plexus/sjoin", "hybrid/sjoin") + , message_tburst("IRCDMessage", "plexus/tburst", "hybrid/tburst") + , message_tmode("IRCDMessage", "plexus/tmode", "hybrid/tmode") + + , message_encap(this) + , message_pass(this) + , message_server(this) + , message_uid(this) { if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK) diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index ef09b9553..5cc80742f 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -289,19 +289,41 @@ class ProtoRatbox : public Module } public: - ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), - message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this), - message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), - message_time(this), message_topic(this), message_version(this), message_whois(this), - - message_bmask("IRCDMessage", "ratbox/bmask", "hybrid/bmask"), message_join("IRCDMessage", "ratbox/join", "hybrid/join"), - message_nick("IRCDMessage", "ratbox/nick", "hybrid/nick"), message_pong("IRCDMessage", "ratbox/pong", "hybrid/pong"), - message_sid("IRCDMessage", "ratbox/sid", "hybrid/sid"), message_sjoin("IRCDMessage", "ratbox/sjoin", "hybrid/sjoin"), - message_tmode("IRCDMessage", "ratbox/tmode", "hybrid/tmode"), - - message_encap(this), message_pass(this), message_server(this), message_tburst(this), message_uid(this) + ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + + , message_bmask("IRCDMessage", "ratbox/bmask", "hybrid/bmask") + , message_join("IRCDMessage", "ratbox/join", "hybrid/join") + , message_nick("IRCDMessage", "ratbox/nick", "hybrid/nick") + , message_pong("IRCDMessage", "ratbox/pong", "hybrid/pong") + , message_sid("IRCDMessage", "ratbox/sid", "hybrid/sid") + , message_sjoin("IRCDMessage", "ratbox/sjoin", "hybrid/sjoin") + , message_tmode("IRCDMessage", "ratbox/tmode", "hybrid/tmode") + + , message_encap(this) + , message_pass(this) + , message_server(this) + , message_tburst(this) + , message_uid(this) { if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK) diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index 395b4dfcc..eec4601ce 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -1091,6 +1091,11 @@ struct IRCDMessageUmode2 : IRCDMessage }; class ProtoUnreal : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::DelChan> + , public EventHook<Event::MLockEvents> { UnrealIRCdProto ircd_proto; @@ -1173,22 +1178,53 @@ class ProtoUnreal : public Module } public: - ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), - message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this), message_mode(this, "MODE"), - message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this), - message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this), - message_sjoin(this), message_topic(this), message_umode2(this) + ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>("OnUserNickChange", EventHook<Event::UserNickChange>::Priority::FIRST) + , EventHook<Event::ChannelSync>("OnChannelSync", EventHook<Event::ChannelSync>::Priority::FIRST) + , EventHook<Event::ChanRegistered>("OnChanRegistered", EventHook<Event::ChanRegistered>::Priority::FIRST) + , EventHook<Event::DelChan>("OnDelChan", EventHook<Event::DelChan>::Priority::FIRST) + , EventHook<Event::MLockEvents>("MLock", EventHook<Event::MLockEvents>::Priority::FIRST) + , ircd_proto(this) + , message_away(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_capab(this) + , message_chghost(this) + , message_chgident(this) + , message_chgname(this) + , message_mode(this, "MODE") + , message_svsmode(this, "SVSMODE") + , message_svs2mode(this, "SVS2MODE") + , message_netinfo(this) + , message_nick(this) + , message_pong(this) + , message_sasl(this) + , message_sdesc(this) + , message_sethost(this) + , message_setident(this) + , message_setname(this) + , message_server(this) + , message_sjoin(this) + , message_topic(this) + , message_umode2(this) { this->AddModes(); - - ModuleManager::SetPriority(this, PRIORITY_FIRST); } void OnReload(Configuration::Conf *conf) override diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv.cpp index cd09ed227..dbaf7b8d2 100644 --- a/modules/pseudoclients/botserv.cpp +++ b/modules/pseudoclients/botserv.cpp @@ -10,15 +10,35 @@ */ #include "module.h" +#include "modules/help.h" class BotServCore : public Module + , public EventHook<Event::SetCorrectModes> + , public EventHook<Event::BotAssign> + , public EventHook<Event::JoinChannel> + , public EventHook<Event::LeaveChannel> + , public EventHook<Event::Help> + , public EventHook<Event::ChannelModeSet> + , public EventHook<Event::CreateChan> + , public EventHook<Event::UserKicked> + , public EventHook<Event::CreateBot> { Reference<BotInfo> BotServ; ExtensibleRef<bool> persist, inhabit; public: - BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - persist("PERSIST"), inhabit("inhabit") + BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook<Event::SetCorrectModes>("OnSetCorrectModes") + , EventHook<Event::BotAssign>("OnBotAssign") + , EventHook<Event::JoinChannel>("OnJoinChannel") + , EventHook<Event::LeaveChannel>("OnLeaveChannel") + , EventHook<Event::Help>("Help") + , EventHook<Event::ChannelModeSet>("OnChannelModeSet") + , EventHook<Event::CreateChan>("OnCreateChan") + , EventHook<Event::UserKicked>("OnUserKicked") + , EventHook<Event::CreateBot>("OnCreateBot") + , persist("PERSIST") + , inhabit("inhabit") { } diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp index 1d6e1090c..7c607e251 100644 --- a/modules/pseudoclients/chanserv.cpp +++ b/modules/pseudoclients/chanserv.cpp @@ -11,18 +11,66 @@ #include "module.h" #include "modules/cs_mode.h" - -class ChanServCore : public Module, public ChanServService +#include "modules/help.h" +#include "modules/bs_bot.h" +#include "modules/chanserv.h" +#include "modules/cs_info.h" + +class ChanServCore : public Module + , public ChanServ::ChanServService + , public EventHook<Event::BotDelete> + , public EventHook<Event::BotPrivmsg> + , public EventHook<Event::DelCore> + , public EventHook<Event::DelChan> + , public EventHook<Event::Help> + , public EventHook<Event::CheckModes> + , public EventHook<Event::CreateChan> + , public EventHook<Event::CanSet> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::Log> + , public EventHook<Event::ExpireTick> + , public EventHook<Event::CheckDelete> + , public EventHook<Event::PreUplinkSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::JoinChannel> + , public EventHook<Event::ChannelModeSet> + , public EventHook<Event::ChanInfo> + , public EventHook<Event::SetCorrectModes> { Reference<BotInfo> ChanServ; std::vector<Anope::string> defaults; ExtensibleItem<bool> inhabit; ExtensibleRef<bool> persist; bool always_lower; + EventHandlers<ChanServ::Event::PreChanExpire> OnPreChanExpire; + EventHandlers<ChanServ::Event::ChanExpire> OnChanExpire; public: - ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - ChanServService(this), inhabit(this, "inhabit"), persist("PERSIST"), always_lower(false) + ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , ChanServService(this) + , EventHook<Event::BotDelete>("OnBotDelete") + , EventHook<Event::BotPrivmsg>("OnBotPrivmsg") + , EventHook<Event::DelCore>("OnDelCore") + , EventHook<Event::DelChan>("OnDelChan") + , EventHook<Event::Help>("OnHelp") + , EventHook<Event::CheckModes>("OnCheckModes") + , EventHook<Event::CreateChan>("OnCreateChan") + , EventHook<Event::CanSet>("OnCanSet") + , EventHook<Event::ChannelSync>("OnChannelSync") + , EventHook<Event::Log>("OnLog") + , EventHook<Event::ExpireTick>("OnExpireTick") + , EventHook<Event::CheckDelete>("OnCheckDelete") + , EventHook<Event::PreUplinkSync>("OnPreUplinkSync") + , EventHook<Event::ChanRegistered>("OnChanRegistered") + , EventHook<Event::JoinChannel>("OnJoinChannel") + , EventHook<Event::ChannelModeSet>("OnChannelModeSet") + , EventHook<Event::ChanInfo>("OnChanInfo") + , EventHook<Event::SetCorrectModes>("OnSetCorrectModes") + , inhabit(this, "inhabit") + , persist("PERSIST") + , always_lower(false) + , OnPreChanExpire(this, "OnPreChanExpire") + , OnChanExpire(this, "OnChanExpire") { } @@ -167,13 +215,13 @@ class ChanServCore : public Module, public ChanServService if (newowner) { - Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display; + ::Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display; ci->SetFounder(newowner); ci->SetSuccessor(NULL); } else { - Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display; + ::Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display; delete ci; continue; @@ -318,7 +366,7 @@ class ChanServCore : public Module, public ChanServService } } - void OnLog(Log *l) override + void OnLog(::Log *l) override { if (l->type == LOG_CHANNEL) l->bi = ChanServ; @@ -351,12 +399,12 @@ class ChanServCore : public Module, public ChanServService expire = true; } - FOREACH_MOD(OnPreChanExpire, (ci, expire)); + this->OnPreChanExpire(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire); if (expire) { - Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->name << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "(none)") << ")"; - FOREACH_MOD(OnChanExpire, (ci)); + ::Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->name << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "(none)") << ")"; + this->OnChanExpire(&ChanServ::Event::ChanExpire::OnChanExpire, ci); delete ci; } } @@ -425,7 +473,7 @@ class ChanServCore : public Module, public ChanServService { if (always_lower && c->ci && c->creation_time > c->ci->time_registered) { - Log(LOG_DEBUG) << "Changing TS of " << c->name << " from " << c->creation_time << " to " << c->ci->time_registered; + ::Log(LOG_DEBUG) << "Changing TS of " << c->name << " from " << c->creation_time << " to " << c->ci->time_registered; c->creation_time = c->ci->time_registered; IRCD->SendChannel(c); c->Reset(); diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp index fe15a3ef9..e7577db47 100644 --- a/modules/pseudoclients/global.cpp +++ b/modules/pseudoclients/global.cpp @@ -10,8 +10,15 @@ */ #include "module.h" - -class GlobalCore : public Module, public GlobalService +#include "modules/help.h" +#include "modules/global.h" + +class GlobalCore : public Module + , public Global::GlobalService + , public EventHook<Event::Restart> + , public EventHook<Event::Shutdown> + , public EventHook<Event::NewServer> + , public EventHook<Event::Help> { Reference<BotInfo> Global; @@ -24,8 +31,12 @@ class GlobalCore : public Module, public GlobalService } public: - GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - GlobalService(this) + GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , GlobalService(this) + , EventHook<Event::Restart>("OnRestart") + , EventHook<Event::Shutdown>("OnShutdown") + , EventHook<Event::NewServer>("OnNewServer") + , EventHook<Event::Help>("OnHelp") { } @@ -90,6 +101,10 @@ class GlobalCore : public Module, public GlobalService source.Reply(_("%s commands:"), Global->nick.c_str()); return EVENT_CONTINUE; } + + void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + } }; MODULE_INIT(GlobalCore) diff --git a/modules/pseudoclients/hostserv.cpp b/modules/pseudoclients/hostserv.cpp index 9d9130fa6..373275e59 100644 --- a/modules/pseudoclients/hostserv.cpp +++ b/modules/pseudoclients/hostserv.cpp @@ -10,12 +10,26 @@ */ #include "module.h" +#include "modules/ns_update.h" +#include "modules/hs_del.h" +#include "modules/help.h" class HostServCore : public Module + , public EventHook<Event::UserLogin> + , public EventHook<Event::NickUpdate> + , public EventHook<Event::Help> + , public EventHook<Event::SetVhost> + , 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") + , EventHook<Event::NickUpdate>("OnNickUpdate") + , EventHook<Event::Help>("OnHelp") + , EventHook<Event::SetVhost>("OnSetVhost") + , EventHook<Event::DeleteVhost>("OnDeleteVhost") { if (!IRCD || !IRCD->CanSetVHost) throw ModuleException("Your IRCd does not support vhosts"); @@ -79,6 +93,10 @@ class HostServCore : public Module return EVENT_CONTINUE; } + void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + } + void OnSetVhost(NickAlias *na) override { if (Config->GetModule(this)->Get<bool>("activate_on_set")) diff --git a/modules/pseudoclients/memoserv.cpp b/modules/pseudoclients/memoserv.cpp index 71f5e64d0..c9b11d294 100644 --- a/modules/pseudoclients/memoserv.cpp +++ b/modules/pseudoclients/memoserv.cpp @@ -10,10 +10,24 @@ */ #include "module.h" - -class MemoServCore : public Module, public MemoServService +#include "modules/ns_update.h" +#include "modules/help.h" +#include "modules/bs_bot.h" +#include "modules/memoserv.h" + +class MemoServCore : public Module, public MemoServ::MemoServService + , public EventHook<Event::NickCoreCreate> + , public EventHook<Event::CreateChan> + , public EventHook<Event::BotDelete> + , public EventHook<Event::NickIdentify> + , public EventHook<Event::JoinChannel> + , public EventHook<Event::UserAway> + , public EventHook<Event::NickUpdate> + , public EventHook<Event::Help> { Reference<BotInfo> MemoServ; + EventHandlers<MemoServ::Event::MemoSend> onmemosend; + EventHandlers<MemoServ::Event::MemoDel> onmemodel; bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m) { @@ -36,8 +50,18 @@ class MemoServCore : public Module, public MemoServService } public: - MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - MemoServService(this) + MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , MemoServ::MemoServService(this) + , EventHook<Event::NickCoreCreate>("OnNickCoreCreate") + , EventHook<Event::CreateChan>("OnCreateChan") + , EventHook<Event::BotDelete>("OnBotDelete") + , EventHook<Event::NickIdentify>("OnNickIdentify") + , EventHook<Event::JoinChannel>("OnJoinChannel") + , EventHook<Event::UserAway>("OnUserAway") + , EventHook<Event::NickUpdate>("OnNickUpdate") + , EventHook<Event::Help>("OnHelp") + , onmemosend(this, "OnMemoSend") + , onmemodel(this, "OnMemoDel") { } @@ -74,7 +98,7 @@ class MemoServCore : public Module, public MemoServService m->text = message; m->unread = true; - FOREACH_MOD(OnMemoSend, (source, target, mi, m)); + this->onmemosend(&MemoServ::Event::MemoSend::OnMemoSend, source, target, mi, m); if (ischan) { diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp index d8b55a9d5..f29b1aa02 100644 --- a/modules/pseudoclients/nickserv.cpp +++ b/modules/pseudoclients/nickserv.cpp @@ -10,18 +10,23 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/ns_group.h" +#include "modules/ns_update.h" +#include "modules/help.h" +#include "modules/nickserv.h" /** Timer for colliding nicks to force people off of nicknames */ class NickServCollide : public Timer { - NickServService *service; + NickServ::NickServService *service; Reference<User> u; time_t ts; Reference<NickAlias> na; public: - NickServCollide(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, NickAlias *nick, time_t delay) : Timer(delay), service(nss), u(user), ts(user->timestamp), na(nick) { } @@ -91,11 +96,32 @@ class NickServRelease : public User, public Timer void Tick(time_t t) override { } }; -class NickServCore : public Module, public NickServService +class NickServCore : public Module, public NickServ::NickServService + , public EventHook<Event::Shutdown> + , public EventHook<Event::Restart> + , public EventHook<Event::UserLogin> + , public EventHook<Event::DelNick> + , public EventHook<Event::DelCore> + , public EventHook<Event::ChangeCoreDisplay> + , public EventHook<Event::NickIdentify> + , public EventHook<Event::NickGroup> + , public EventHook<Event::NickUpdate> + , public EventHook<Event::UserConnect> + , public EventHook<Event::PostUserLogoff> + , public EventHook<Event::ServerSync> + , public EventHook<Event::UserNickChange> + , public EventHook<Event::UserModeSet> + , public EventHook<Event::Help> + , public EventHook<Event::ExpireTick> + , public EventHook<Event::NickInfo> { Reference<BotInfo> NickServ; std::vector<Anope::string> defaults; ExtensibleItem<bool> held, collided; + EventHandlers<NickServ::Event::PreNickExpire> onprenickexpire; + EventHandlers<NickServ::Event::NickExpire> onnickexpire; + EventHandlers<NickServ::Event::NickRegister> onnickregister; + EventHandlers<NickServ::Event::NickValidate> onnickvalidate; void OnCancel(User *u, NickAlias *na) { @@ -113,8 +139,31 @@ class NickServCore : public Module, public NickServService } public: - NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - NickServService(this), held(this, "HELD"), collided(this, "COLLIDED") + NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , NickServ::NickServService(this) + , EventHook<Event::Shutdown>("OnShutdown") + , EventHook<Event::Restart>("OnRestart") + , EventHook<Event::UserLogin>("OnUserLogin") + , EventHook<Event::DelNick>("OnDelNick") + , EventHook<Event::DelCore>("OnDelCore") + , EventHook<Event::ChangeCoreDisplay>("OnChangeCoreDisplay") + , EventHook<Event::NickIdentify>("OnNickIdentify") + , EventHook<Event::NickGroup>("OnNickGroup") + , EventHook<Event::NickUpdate>("OnNickUpdate") + , EventHook<Event::UserConnect>("OnUserConnect") + , EventHook<Event::PostUserLogoff>("OnPostUserLogoff") + , EventHook<Event::ServerSync>("OnServerSync") + , EventHook<Event::UserNickChange>("OnUserNickChange") + , EventHook<Event::UserModeSet>("OnUserModeSet") + , EventHook<Event::Help>("OnHelp") + , EventHook<Event::ExpireTick>("OnExpireTick") + , EventHook<Event::NickInfo>("OnNickInfo") + , held(this, "HELD") + , collided(this, "COLLIDED") + , onprenickexpire(this, "OnPreNickExpire") + , onnickexpire(this, "OnNickExpire") + , onnickregister(this, "OnNickRegister") + , onnickvalidate(this, "OnNickValidate") { } @@ -143,8 +192,7 @@ class NickServCore : public Module, public NickServService if (!na) return; - EventReturn MOD_RESULT; - FOREACH_RESULT(OnNickValidate, MOD_RESULT, (u, na)); + EventReturn MOD_RESULT = this->onnickvalidate(&NickServ::Event::NickValidate::OnNickValidate, u, na); if (MOD_RESULT == EVENT_STOP) { this->Collide(u, na); @@ -306,7 +354,7 @@ class NickServCore : public Module, public NickServService IRCD->SendLogout(user); user->RemoveMode(NickServ, "REGISTERED"); user->Logout(); - FOREACH_MOD(OnNickLogout, (user)); + Event::OnNickLogout(&Event::NickLogout::OnNickLogout, user); } nc->users.clear(); } @@ -515,12 +563,12 @@ class NickServCore : public Module, public NickServService if (nickserv_expire && Anope::CurTime - na->last_seen >= nickserv_expire) expire = true; - FOREACH_MOD(OnPreNickExpire, (na, expire)); + 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) << ")"; - FOREACH_MOD(OnNickExpire, (na)); + this->onnickexpire(&NickServ::Event::NickExpire::OnNickExpire, na); delete na; } } diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index 7b43436f7..91d7f1add 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -10,6 +10,8 @@ */ #include "module.h" +#include "modules/help.h" +#include "modules/nickserv.h" class SGLineManager : public XLineManager { @@ -23,7 +25,7 @@ class SGLineManager : public XLineManager void OnExpire(const XLine *x) override { - Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired"; + ::Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired"; } void Send(User *u, XLine *x) override @@ -68,10 +70,8 @@ class SGLineManager : public XLineManager class SQLineManager : public XLineManager { - ServiceReference<NickServService> nickserv; - public: - SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q'), nickserv("NickServService", "NickServ") { } + SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q') { } void OnMatch(User *u, XLine *x) override { @@ -80,7 +80,7 @@ class SQLineManager : public XLineManager void OnExpire(const XLine *x) override { - Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->mask << "\002 has expired"; + ::Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->mask << "\002 has expired"; } void Send(User *u, XLine *x) override @@ -89,8 +89,8 @@ class SQLineManager : public XLineManager { if (!u) ; - else if (nickserv) - nickserv->Collide(u, NULL); + else if (NickServ::service) + NickServ::service->Collide(u, NULL); else u->Kill(Config->GetClient("OperServ"), "Q-Lined: " + x->reason); } @@ -144,7 +144,7 @@ class SNLineManager : public XLineManager void OnExpire(const XLine *x) override { - Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->mask << "\002 has expired"; + ::Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->mask << "\002 has expired"; } void Send(User *u, XLine *x) override @@ -171,6 +171,15 @@ class SNLineManager : public XLineManager }; class OperServCore : public Module + , public EventHook<Event::BotPrivmsg> + , public EventHook<Event::ServerQuit> + , public EventHook<Event::UserModeSet> + , public EventHook<Event::UserModeUnset> + , public EventHook<Event::UserConnect> + , public EventHook<Event::UserNickChange> + , public EventHook<Event::CheckKick> + , public EventHook<Event::Help> + , public EventHook<Event::Log> { Reference<BotInfo> OperServ; SGLineManager sglines; @@ -178,8 +187,19 @@ class OperServCore : public Module SNLineManager snlines; public: - OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - sglines(this), sqlines(this), snlines(this) + OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook<Event::BotPrivmsg>("OnBotPrivmsg") + , EventHook<Event::ServerQuit>("OnServerQuit") + , EventHook<Event::UserModeSet>("OnUserModeSet") + , EventHook<Event::UserModeUnset>("OnUserModeUnset") + , EventHook<Event::UserConnect>("OnUserConnect") + , EventHook<Event::UserNickChange>("OnUserNickChange") + , EventHook<Event::CheckKick>("OnCheckKick") + , EventHook<Event::Help>("OnHelp") + , EventHook<Event::Log>("OnLog") + , sglines(this) + , sqlines(this) + , snlines(this) { /* Yes, these are in this order for a reason. Most violent->least violent. */ @@ -218,7 +238,7 @@ class OperServCore : public Module if (bi == OperServ && !u->HasMode("OPER") && Config->GetModule(this)->Get<bool>("opersonly")) { u->SendMessage(bi, ACCESS_DENIED); - Log(bi, "bados") << "Denied access to " << bi->nick << " from " << u->GetMask() << " (non-oper)"; + ::Log(bi, "bados") << "Denied access to " << bi->nick << " from " << u->GetMask() << " (non-oper)"; return EVENT_STOP; } @@ -228,19 +248,19 @@ class OperServCore : public Module void OnServerQuit(Server *server) override { if (server->IsJuped()) - Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName(); + ::Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName(); } void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override { if (mname == "OPER") - Log(u, "oper", OperServ) << "is now an IRC operator."; + ::Log(u, "oper", OperServ) << "is now an IRC operator."; } void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override { if (mname == "OPER") - Log(u, "oper", OperServ) << "is no longer an IRC operator"; + ::Log(u, "oper", OperServ) << "is no longer an IRC operator"; } void OnUserConnect(User *u, bool &exempt) override @@ -276,7 +296,11 @@ class OperServCore : public Module return EVENT_CONTINUE; } - void OnLog(Log *l) override + void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + } + + void OnLog(::Log *l) override { if (l->type == LOG_SERVER) l->bi = OperServ; diff --git a/modules/webcpanel/pages/index.cpp b/modules/webcpanel/pages/index.cpp index debedd551..0b2ce3d9c 100644 --- a/modules/webcpanel/pages/index.cpp +++ b/modules/webcpanel/pages/index.cpp @@ -87,7 +87,7 @@ bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page // Rate limit check. WebpanelRequest *req = new WebpanelRequest(me, reply, message, server, page_name, client, replacements, user, pass); - FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); return false; } diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp index d5acfbf67..17a64529b 100644 --- a/modules/webcpanel/webcpanel.cpp +++ b/modules/webcpanel/webcpanel.cpp @@ -43,14 +43,31 @@ class ModuleWebCPanel : public Module public: - ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - panel(this, "webcpanel"), id(this, "webcpanel_id"), ip(this, "webcpanel_ip"), - style_css("style.css", "/static/style.css", "text/css"), logo_png("logo.png", "/static/logo.png", "image/png"), cubes_png("cubes.png", "/static/cubes.png", "image/png"), favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon"), - index("/"), logout("/logout"), _register("/register"), confirm("/confirm"), - nickserv_info("NickServ", "/nickserv/info"), nickserv_cert("NickServ", "/nickserv/cert"), nickserv_access("NickServ", "/nickserv/access"), nickserv_alist("NickServ", "/nickserv/alist"), - chanserv_info("ChanServ", "/chanserv/info"), chanserv_set("ChanServ", "/chanserv/set"), chanserv_access("ChanServ", "/chanserv/access"), chanserv_akick("ChanServ", "/chanserv/akick"), - chanserv_modes("ChanServ", "/chanserv/modes"), chanserv_drop("ChanServ", "/chanserv/drop"), memoserv_memos("MemoServ", "/memoserv/memos"), hostserv_request("HostServ", "/hostserv/request"), - operserv_akill("OperServ", "/operserv/akill") + ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , panel(this, "webcpanel") + , id(this, "webcpanel_id") + , ip(this, "webcpanel_ip") + , style_css("style.css", "/static/style.css", "text/css") + , logo_png("logo.png", "/static/logo.png", "image/png") + , cubes_png("cubes.png", "/static/cubes.png", "image/png") + , favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon") + , index("/") + , logout("/logout") + , _register("/register") + , confirm("/confirm") + , nickserv_info("NickServ", "/nickserv/info") + , nickserv_cert("NickServ", "/nickserv/cert") + , nickserv_access("NickServ", "/nickserv/access") + , nickserv_alist("NickServ", "/nickserv/alist") + , chanserv_info("ChanServ", "/chanserv/info") + , chanserv_set("ChanServ", "/chanserv/set") + , chanserv_access("ChanServ", "/chanserv/access") + , chanserv_akick("ChanServ", "/chanserv/akick") + , chanserv_modes("ChanServ", "/chanserv/modes") + , chanserv_drop("ChanServ", "/chanserv/drop") + , memoserv_memos("MemoServ", "/memoserv/memos") + , hostserv_request("HostServ", "/hostserv/request") + , operserv_akill("OperServ", "/operserv/akill") { me = this; diff --git a/src/access.cpp b/src/access.cpp index 1b90bb59f..26c8dee27 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -16,6 +16,7 @@ #include "users.h" #include "account.h" #include "protocol.h" +#include "event.h" static struct { @@ -312,8 +313,7 @@ AccessGroup::AccessGroup() : std::vector<ChanAccess *>() static bool HasPriv(const AccessGroup &ag, const ChanAccess *access, const Anope::string &name) { - EventReturn MOD_RESULT; - FOREACH_RESULT(OnCheckPriv, MOD_RESULT, (access, 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; @@ -353,7 +353,7 @@ bool AccessGroup::HasPriv(const Anope::string &name) const return true; EventReturn MOD_RESULT; - FOREACH_RESULT(OnGroupCheckPriv, MOD_RESULT, (this, name)); + MOD_RESULT = Event::OnGroupCheckPriv(&Event::GroupCheckPriv::OnGroupCheckPriv, this, name); if (MOD_RESULT != EVENT_CONTINUE) return MOD_RESULT == EVENT_ALLOW; diff --git a/src/base.cpp b/src/base.cpp index 1b6a560d7..0fcd868bc 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -11,8 +11,28 @@ #include "anope.h" #include "service.h" -std::map<Anope::string, std::map<Anope::string, Service *> > Service::Services; -std::map<Anope::string, std::map<Anope::string, Anope::string> > Service::Aliases; +std::map<Anope::string, std::map<Anope::string, Service *> > *Service::Services = NULL; +std::map<Anope::string, std::map<Anope::string, Anope::string> > *Service::Aliases = NULL; +std::set<ReferenceBase *> *ReferenceBase::references = NULL; + +ReferenceBase::ReferenceBase() +{ + if (references == NULL) + references = new std::set<ReferenceBase *>(); + references->insert(this); +} + +ReferenceBase::~ReferenceBase() +{ + references->erase(this); +} + +void ReferenceBase::ResetAll() +{ + if (references) + for (ReferenceBase *b : *references) + b->Reset(); +} Base::Base() : references(NULL) { diff --git a/src/bots.cpp b/src/bots.cpp index 77b7d1c35..b2feb9c4e 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -18,6 +18,7 @@ #include "config.h" #include "language.h" #include "serialize.h" +#include "event.h" Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo"); @@ -31,7 +32,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A if (!this->uid.empty()) (*BotListByUID)[this->uid] = this; - FOREACH_MOD(OnCreateBot, (this)); + Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this); // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -49,7 +50,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A BotInfo::~BotInfo() { - FOREACH_MOD(OnDelBot, (this)); + Event::OnDelBot(&Event::DelBot::OnDelBot, this); // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -152,7 +153,7 @@ const std::set<ChannelInfo *> &BotInfo::GetChannels() const void BotInfo::Assign(User *u, ChannelInfo *ci) { EventReturn MOD_RESULT; - FOREACH_RESULT(OnPreBotAssign, MOD_RESULT, (u, ci, this)); + MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this); if (MOD_RESULT == EVENT_STOP) return; @@ -162,13 +163,13 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) ci->bi = this; this->channels->insert(ci); - FOREACH_MOD(OnBotAssign, (u, ci, this)); + Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this); } void BotInfo::UnAssign(User *u, ChannelInfo *ci) { EventReturn MOD_RESULT; - FOREACH_RESULT(OnBotUnAssign, MOD_RESULT, (u, ci)); + MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci); if (MOD_RESULT == EVENT_STOP) return; @@ -198,7 +199,7 @@ void BotInfo::Join(Channel *c, ChannelStatus *status) if (IRCD) IRCD->SendJoin(this, c, status); - FOREACH_MOD(OnJoinChannel, (this, c)); + Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, this, c); } void BotInfo::Join(const Anope::string &chname, ChannelStatus *status) @@ -214,7 +215,7 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); - FOREACH_MOD(OnPartChannel, (this, c, c->name, reason)); + Event::OnPartChannel(&Event::PartChannel::OnPartChannel, this, c, c->name, reason); c->DeleteUser(this); } diff --git a/src/channels.cpp b/src/channels.cpp index 37d04c44e..94f7d49a6 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -25,6 +25,7 @@ #include "sockets.h" #include "language.h" #include "uplink.h" +#include "event.h" channel_map ChannelList; @@ -47,12 +48,12 @@ Channel::Channel(const Anope::string &nname, time_t ts) if (Me && Me->IsSynced()) Log(NULL, this, "create"); - FOREACH_MOD(OnChannelCreate, (this)); + Event::OnChannelCreate(&Event::ChannelCreate::OnChannelCreate, this); } Channel::~Channel() { - FOREACH_MOD(OnChannelDelete, (this)); + Event::OnChannelDelete(&Event::ChannelDelete::OnChannelDelete, this); ModeManager::StackerDel(this); @@ -98,7 +99,7 @@ void Channel::Reset() void Channel::Sync() { syncing = false; - FOREACH_MOD(OnChannelSync, (this)); + Event::OnChannelSync(&Event::ChannelSync::OnChannelSync, this); CheckModes(); } @@ -116,7 +117,7 @@ void Channel::CheckModes() } Reference<Channel> ref = this; - FOREACH_MOD(OnCheckModes, (ref)); + Event::OnCheckModes(&Event::CheckModes::OnCheckModes, ref); } bool Channel::CheckDelete() @@ -132,7 +133,7 @@ bool Channel::CheckDelete() return false; EventReturn MOD_RESULT; - FOREACH_RESULT(OnCheckDelete, MOD_RESULT, (this)); + MOD_RESULT = Event::OnCheckDelete(&Event::CheckDelete::OnCheckDelete, this); return MOD_RESULT != EVENT_STOP && this->users.empty(); } @@ -156,7 +157,7 @@ void Channel::DeleteUser(User *user) if (user->server && user->server->IsSynced() && !user->Quitting()) Log(user, this, "leave"); - FOREACH_MOD(OnLeaveChannel, (user, this)); + Event::OnLeaveChannel(&Event::LeaveChannel::OnLeaveChannel, user, this); ChanUserContainer *cu = user->FindChannel(this); if (!this->users.erase(user)) @@ -279,7 +280,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop if (cc) cc->status.AddMode(cm->mchar); - FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param); /* Enforce secureops, etc */ if (enforce_mlock && MOD_RESULT != EVENT_STOP) @@ -306,7 +307,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop cml->OnAdd(this, param); } - FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param); /* Check if we should enforce mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) @@ -347,7 +348,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A if (cc) cc->status.DelMode(cm->mchar); - FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param); if (enforce_mlock && MOD_RESULT != EVENT_STOP) this->SetCorrectModes(u, false); @@ -374,7 +375,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A cml->OnDel(this, param); } - FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param); if (cm->name == "PERM") { @@ -738,9 +739,9 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic Anope::string this_name = this->name; ChannelStatus status = cu->status; - FOREACH_MOD(OnPreUserKicked, (source, cu, reason)); + Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason); this->DeleteUser(target); /* This can delete this; */ - FOREACH_MOD(OnUserKicked, (source, target, this_name, status, reason)); + Event::OnUserKicked(&Event::UserKicked::OnUserKicked, source, target, this_name, status, reason); } bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) @@ -759,7 +760,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) bi = this->ci->WhoSends(); EventReturn MOD_RESULT; - FOREACH_RESULT(OnBotKick, MOD_RESULT, (bi, this, u, buf)); + MOD_RESULT = Event::OnBotKick(&Event::BotKick::OnBotKick, bi, this, u, buf); if (MOD_RESULT == EVENT_STOP) return false; IRCD->SendKick(bi, this, u, "%s", buf); @@ -778,7 +779,7 @@ void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string Log(LOG_DEBUG) << "Topic of " << this->name << " changed by " << (u ? u->nick : user) << " to " << newtopic; - FOREACH_MOD(OnTopicUpdated, (this, user, this->topic)); + Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, this, user, this->topic); } void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts) @@ -794,7 +795,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop /* Now that the topic is set update the time set. This is *after* we set it so the protocol modules are able to tell the old last set time */ this->topic_time = Anope::CurTime; - FOREACH_MOD(OnTopicUpdated, (this, user, this->topic)); + Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, this, user, this->topic); } void Channel::SetCorrectModes(User *user, bool give_modes) @@ -812,7 +813,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes) /* Initially only take modes if the channel is being created by a non netmerge */ bool take_modes = this->syncing && user->server->IsSynced(); - FOREACH_MOD(OnSetCorrectModes, (user, this, u_access, give_modes, take_modes)); + Event::OnSetCorrectModes(&Event::SetCorrectModes::OnSetCorrectModes, user, this, u_access, give_modes, take_modes); /* Never take modes from ulines */ if (user->server->IsULined()) @@ -884,7 +885,7 @@ bool Channel::CheckKick(User *user) Anope::string mask, reason; EventReturn MOD_RESULT; - FOREACH_RESULT(OnCheckKick, MOD_RESULT, (user, this, mask, reason)); + MOD_RESULT = Event::OnCheckKick(&Event::CheckKick::OnCheckKick, user, this, mask, reason); if (MOD_RESULT != EVENT_STOP) return false; diff --git a/src/command.cpp b/src/command.cpp index 6aa2f744b..5241e9316 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -17,6 +17,7 @@ #include "access.h" #include "regchannel.h" #include "channels.h" +#include "event.h" CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) @@ -261,7 +262,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) source.permission = info.permission; EventReturn MOD_RESULT; - FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, c, params)); + MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, c, params); if (MOD_RESULT == EVENT_STOP) return; @@ -281,7 +282,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) } c->Execute(source, params); - FOREACH_MOD(OnPostCommand, (source, c, params)); + Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, c, params); } bool Command::FindCommandFromService(const Anope::string &command_service, BotInfo* &bot, Anope::string &name) diff --git a/src/config.cpp b/src/config.cpp index 6473cf830..97abbbe0e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,6 +17,7 @@ #include "opertype.h" #include "channels.h" #include "hashcomp.h" +#include "event.h" using namespace Configuration; @@ -130,7 +131,8 @@ Conf::Conf() : Block("") this->LoadConf(f); } - FOREACH_MOD(OnReload, (this)); + for (Module *m : ModuleManager::Modules) + m->OnReload(this); /* Check for modified values that aren't allowed to be modified */ if (Config) diff --git a/src/event.cpp b/src/event.cpp new file mode 100644 index 000000000..c13118dc4 --- /dev/null +++ b/src/event.cpp @@ -0,0 +1,103 @@ +/* Modular support + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#include "services.h" +#include "event.h" + +using namespace Event; + +EventHandlers<PreUserKicked> Event::OnPreUserKicked(nullptr, "OnPreUserKicked"); +EventHandlers<UserKicked> Event::OnUserKicked(nullptr, "OnUserKicked"); +EventHandlers<PreBotAssign> Event::OnPreBotAssign(nullptr, "OnPreBotAssign"); +EventHandlers<BotAssign> Event::OnBotAssign(nullptr, "OnBotAssign"); +EventHandlers<BotUnAssign> Event::OnBotUnAssign(nullptr, "OnBotUnAssign"); +EventHandlers<UserConnect> Event::OnUserConnect(nullptr, "OnUserConnect"); +EventHandlers<NewServer> Event::OnNewServer(nullptr, "OnNewServer"); +EventHandlers<UserNickChange> Event::OnUserNickChange(nullptr, "OnUserNickChange"); +EventHandlers<PreCommand> Event::OnPreCommand(nullptr, "OnPreCommand"); +EventHandlers<PostCommand> Event::OnPostCommand(nullptr, "OnPostCommand"); +EventHandlers<SaveDatabase> Event::OnSaveDatabase(nullptr, "OnSaveDatabase"); +EventHandlers<LoadDatabase> Event::OnLoadDatabase(nullptr, "OnLoadDatabase"); +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"); +EventHandlers<JoinChannel> Event::OnJoinChannel(nullptr, "OnJoinChannel"); +EventHandlers<TopicUpdated> Event::OnTopicUpdated(nullptr, "OnTopicUpdated"); +EventHandlers<PreServerConnect> Event::OnPreServerConnect(nullptr, "OnPreServerConnect"); +EventHandlers<ServerConnect> Event::OnServerConnect(nullptr, "OnServerConnect"); +EventHandlers<PreUplinkSync> Event::OnPreUplinkSync(nullptr, "OnPreUplinkSync"); +EventHandlers<ServerDisconnect> Event::OnServerDisconnect(nullptr, "OnServerDisconnect"); +EventHandlers<Restart> Event::OnRestart(nullptr, "OnRestart"); +EventHandlers<Shutdown> Event::OnShutdown(nullptr, "OnShutdown"); +EventHandlers<AddXLine> Event::OnAddXLine(nullptr, "OnAddXLine"); +EventHandlers<DelXLine> Event::OnDelXLine(nullptr, "OnDelXLine"); +EventHandlers<IsServicesOperEvent> Event::OnIsServicesOper(nullptr, "OnIsServicesOper"); +EventHandlers<ServerQuit> Event::OnServerQuit(nullptr, "OnServerQuit"); +EventHandlers<UserQuit> Event::OnUserQuit(nullptr, "OnUserQuit"); +EventHandlers<PreUserLogoff> Event::OnPreUserLogoff(nullptr, "OnPreUserLogoff"); +EventHandlers<PostUserLogoff> Event::OnPostUserLogoff(nullptr, "OnPostUserLogoff"); +EventHandlers<AccessDel> Event::OnAccessDel(nullptr, "OnAccessDel"); +EventHandlers<AccessAdd> Event::OnAccessAdd(nullptr, "OnAccessAdd"); +EventHandlers<AccessClear> Event::OnAccessClear(nullptr, "OnAccessClear"); +EventHandlers<ChanRegistered> Event::OnChanRegistered(nullptr, "OnChanRegistered"); +EventHandlers<CreateChan> Event::OnCreateChan(nullptr, "OnCreateChan"); +EventHandlers<DelChan> Event::OnDelChan(nullptr, "OnDelChan"); +EventHandlers<ChannelCreate> Event::OnChannelCreate(nullptr, "OnChannelCreate"); +EventHandlers<ChannelDelete> Event::OnChannelDelete(nullptr, "OnChannelDelete"); +EventHandlers<CheckKick> Event::OnCheckKick(nullptr, "OnCheckKick"); +EventHandlers<CheckPriv> Event::OnCheckPriv(nullptr, "OnCheckPriv"); +EventHandlers<GroupCheckPriv> Event::OnGroupCheckPriv(nullptr, "OnGroupCheckPriv"); +EventHandlers<NickIdentify> Event::OnNickIdentify(nullptr, "OnNickIdentify"); +EventHandlers<UserLogin> Event::OnUserLogin(nullptr, "OnUserLogin"); +EventHandlers<NickLogout> Event::OnNickLogout(nullptr, "OnNickLogout"); +EventHandlers<DelNick> Event::OnDelNick(nullptr, "OnDelNick"); +EventHandlers<NickCoreCreate> Event::OnNickCoreCreate(nullptr, "OnNickCoreCreate"); +EventHandlers<DelCore> Event::OnDelCore(nullptr, "OnDelCore"); +EventHandlers<ChangeCoreDisplay> Event::OnChangeCoreDisplay(nullptr, "OnChangeCoreDisplay"); +EventHandlers<NickClearAccess> Event::OnNickClearAccess(nullptr, "OnNickClearAccess"); +EventHandlers<NickAddAccess> Event::OnNickAddAccess(nullptr, "OnNickAddAccess"); +EventHandlers<NickEraseAccess> Event::OnNickEraseAccess(nullptr, "OnNickEraseAccess"); +EventHandlers<CheckAuthentication> Event::OnCheckAuthentication(nullptr, "OnCheckAuthentication"); +EventHandlers<Fingerprint> Event::OnFingerprint(nullptr, "OnFingerprint"); +EventHandlers<UserAway> Event::OnUserAway(nullptr, "OnUserAway"); +EventHandlers<Invite> Event::OnInvite(nullptr, "OnInvite"); +EventHandlers<SetVhost> Event::OnSetVhost(nullptr, "OnSetVhost"); +EventHandlers<SetDisplayedHost> Event::OnSetDisplayedHost(nullptr, "OnSetDisplayedHost"); +EventHandlers<ChannelModeSet> Event::OnChannelModeSet(nullptr, "OnChannelModeSet"); +EventHandlers<ChannelModeUnset> Event::OnChannelModeUnset(nullptr, "OnChannelModeUnset"); +EventHandlers<UserModeSet> Event::OnUserModeSet(nullptr, "OnUserModeSet"); +EventHandlers<UserModeUnset> Event::OnUserModeUnset(nullptr, "OnUserModeUnset"); +EventHandlers<ChannelModeAdd> Event::OnChannelModeAdd(nullptr, "OnChannelModeAdd"); +EventHandlers<UserModeAdd> Event::OnUserModeAdd(nullptr, "OnUserModeAdd"); +EventHandlers<ModuleLoad> Event::OnModuleLoad(nullptr, "OnModuleLoad"); +EventHandlers<ModuleUnload> Event::OnModuleUnload(nullptr, "OnModuleUnload"); +EventHandlers<ServerSync> Event::OnServerSync(nullptr, "OnServerSync"); +EventHandlers<UplinkSync> Event::OnUplinkSync(nullptr, "OnUplinkSync"); +EventHandlers<BotPrivmsg> Event::OnBotPrivmsg(nullptr, "OnBotPrivmsg"); +EventHandlers<BotNotice> Event::OnBotNotice(nullptr, "OnBotNotice"); +EventHandlers<Privmsg> Event::OnPrivmsg(nullptr, "OnPrivmsg"); +EventHandlers<Event::Log> Event::OnLog(nullptr, "OnLog"); +EventHandlers<LogMessage> Event::OnLogMessage(nullptr, "OnLogMessage"); +EventHandlers<CheckModes> Event::OnCheckModes(nullptr, "OnCheckModes"); +EventHandlers<ChannelSync> Event::OnChannelSync(nullptr, "OnChannelSync"); +EventHandlers<SetCorrectModes> Event::OnSetCorrectModes(nullptr, "OnSetCorrectModes"); +EventHandlers<SerializeCheck> Event::OnSerializeCheck(nullptr, "OnSerializeCheck"); +EventHandlers<SerializableConstruct> Event::OnSerializableConstruct(nullptr, "OnSerializableConstruct"); +EventHandlers<SerializableDestruct> Event::OnSerializableDestruct(nullptr, "OnSerializableDestruct"); +EventHandlers<SerializableUpdate> Event::OnSerializableUpdate(nullptr, "OnSerializableUpdate"); +EventHandlers<SerializeTypeCreate> Event::OnSerializeTypeCreate(nullptr, "OnSerializeTypeCreate"); +EventHandlers<Message> Event::OnMessage(nullptr, "OnMessage"); +EventHandlers<CanSet> Event::OnCanSet(nullptr, "OnCanSet"); +EventHandlers<CheckDelete> Event::OnCheckDelete(nullptr, "OnCheckDelete"); +EventHandlers<ExpireTick> Event::OnExpireTick(nullptr, "OnExpireTick"); diff --git a/src/init.cpp b/src/init.cpp index f62ef083a..cd06a5194 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -19,6 +19,7 @@ #include "socketengine.h" #include "servers.h" #include "language.h" +#include "event.h" #ifndef _WIN32 #include <sys/wait.h> @@ -535,7 +536,7 @@ void Anope::Init(int ac, char **av) /* Load up databases */ Log() << "Loading databases..."; EventReturn MOD_RESULT; - FOREACH_RESULT(OnLoadDatabase, MOD_RESULT, ()); + MOD_RESULT = Event::OnLoadDatabase(&Event::LoadDatabase::OnLoadDatabase); static_cast<void>(MOD_RESULT); Log() << "Databases loaded"; diff --git a/src/logger.cpp b/src/logger.cpp index 445e71949..1aa530f82 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -21,6 +21,7 @@ #include "servers.h" #include "uplink.h" #include "protocol.h" +#include "event.h" #ifndef _WIN32 #include <sys/time.h> @@ -129,7 +130,7 @@ Log::~Log() else if (this->type == LOG_TERMINAL) std::cout << this->BuildPrefix() << this->buf.str() << std::endl; - FOREACH_MOD(OnLog, (this)); + Event::OnLog(&Event::Log::OnLog, this); if (Config) for (unsigned i = 0; i < Config->LogInfos.size(); ++i) @@ -347,7 +348,7 @@ void LogInfo::ProcessMessage(const Log *l) const Anope::string &buffer = l->BuildPrefix() + l->buf.str(); - FOREACH_MOD(OnLogMessage, (this, l, buffer)); + Event::OnLogMessage(&Event::LogMessage::OnLogMessage, this, l, buffer); for (unsigned i = 0; i < this->targets.size(); ++i) { diff --git a/src/main.cpp b/src/main.cpp index 86d135ca8..8a61835b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include "bots.h" #include "socketengine.h" #include "uplink.h" +#include "event.h" #ifndef _WIN32 #include <limits.h> @@ -60,7 +61,7 @@ class ExpireTimer : public Timer void Tick(time_t) override { - FOREACH_MOD(OnExpireTick, ()); + Event::OnExpireTick(&Event::ExpireTick::OnExpireTick); } }; @@ -70,7 +71,7 @@ void Anope::SaveDatabases() return; Log(LOG_DEBUG) << "Saving databases"; - FOREACH_MOD(OnSaveDatabase, ()); + Event::OnSaveDatabase(&Event::SaveDatabase::OnSaveDatabase); } /** The following comes from InspIRCd to get the full path of the Anope executable @@ -181,11 +182,11 @@ int main(int ac, char **av, char **envp) if (Anope::Restarting) { - FOREACH_MOD(OnRestart, ()); + Event::OnRestart(&Event::Restart::OnRestart); } else { - FOREACH_MOD(OnShutdown, ()); + Event::OnShutdown(&Event::Shutdown::OnShutdown); } if (Anope::QuitReason.empty()) diff --git a/src/messages.cpp b/src/messages.cpp index bb699a18e..b4da470bf 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -20,12 +20,13 @@ #include "messages.h" #include "servers.h" #include "channels.h" +#include "event.h" using namespace Message; void Away::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - FOREACH_MOD(OnUserAway, (source.GetUser(), params.empty() ? "" : params[0])); + Event::OnUserAway(&Event::UserAway::OnUserAway, source.GetUser(), params.empty() ? "" : params[0]); } void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -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; - FOREACH_MOD(OnInvite, (source.GetUser(), c, targ)); + Event::OnInvite(&Event::Invite::OnInvite, source.GetUser(), c, targ); } void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -79,9 +80,9 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) ++it; Anope::string channame = cc->chan->name; - FOREACH_MOD(OnPrePartChannel, (user, cc->chan)); + Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, user, cc->chan); cc->chan->DeleteUser(user); - FOREACH_MOD(OnPartChannel, (user, Channel::Find(channame), channame, "")); + Event::OnPartChannel(&Event::PartChannel::OnPartChannel, user, Channel::Find(channame), channame, ""); } continue; } @@ -140,7 +141,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co */ c->SetCorrectModes(u, true); - FOREACH_MOD(OnJoinChannel, (u, c)); + Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, u, c); } /* Channel is done syncing */ @@ -259,7 +260,7 @@ void Notice::Run(MessageSource &source, const std::vector<Anope::string> ¶ms BotInfo *bi = BotInfo::Find(params[0]); if (!bi) return; - FOREACH_MOD(OnBotNotice, (u, bi, message)); + Event::OnBotNotice(&Event::BotNotice::OnBotNotice, u, bi, message); } } @@ -279,10 +280,10 @@ void Part::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) continue; Log(u, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason"); - FOREACH_MOD(OnPrePartChannel, (u, c)); + Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, u, c); Anope::string ChannelName = c->name; c->DeleteUser(u); - FOREACH_MOD(OnPartChannel, (u, c, ChannelName, !reason.empty() ? reason : "")); + Event::OnPartChannel(&Event::PartChannel::OnPartChannel, u, c, ChannelName, !reason.empty() ? reason : ""); } } @@ -303,7 +304,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m Channel *c = Channel::Find(receiver); if (c) { - FOREACH_MOD(OnPrivmsg, (u, c, message)); + Event::OnPrivmsg(&Event::Privmsg::OnPrivmsg, u, c, message); } } else @@ -351,7 +352,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m } EventReturn MOD_RESULT; - FOREACH_RESULT(OnBotPrivmsg, MOD_RESULT, (u, bi, message)); + MOD_RESULT = Event::OnBotPrivmsg(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message); if (MOD_RESULT == EVENT_STOP) return; diff --git a/src/misc.cpp b/src/misc.cpp index ee7724941..7e5121ed6 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -18,6 +18,7 @@ #include "bots.h" #include "language.h" #include "sockets.h" +#include "event.h" #include <errno.h> #include <sys/types.h> @@ -501,7 +502,7 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case void Anope::Encrypt(const Anope::string &src, Anope::string &dest) { EventReturn MOD_RESULT; - FOREACH_RESULT(OnEncrypt, MOD_RESULT, (src, dest)); + MOD_RESULT = Event::OnEncrypt(&Event::Encrypt::OnEncrypt, src, dest); static_cast<void>(MOD_RESULT); } @@ -516,7 +517,7 @@ bool Anope::Decrypt(const Anope::string &src, Anope::string &dest) Anope::string hashm(src.begin(), src.begin() + pos); EventReturn MOD_RESULT; - FOREACH_RESULT(OnDecrypt, MOD_RESULT, (hashm, src, dest)); + MOD_RESULT = Event::OnDecrypt(&Event::Decrypt::OnDecrypt, hashm, src, dest); if (MOD_RESULT == EVENT_ALLOW) return true; diff --git a/src/modes.cpp b/src/modes.cpp index 13cda797f..c8908820c 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -14,6 +14,7 @@ #include "protocol.h" #include "channels.h" #include "uplink.h" +#include "event.h" struct StackerInfo; @@ -138,7 +139,7 @@ ChannelMode::ChannelMode(const Anope::string &cm, char mch) : Mode(cm, MC_CHANNE bool ChannelMode::CanSet(User *u) const { EventReturn MOD_RESULT; - FOREACH_RESULT(OnCanSet, MOD_RESULT, (u, this)); + MOD_RESULT = Event::OnCanSet(&Event::CanSet::OnCanSet, u, this); return MOD_RESULT != EVENT_STOP; } @@ -335,7 +336,7 @@ bool ModeManager::AddUserMode(UserMode *um) UserModesByName[um->name] = um; - FOREACH_MOD(OnUserModeAdd, (um)); + Event::OnUserModeAdd(&Event::UserModeAdd::OnUserModeAdd, um); return true; } @@ -369,7 +370,7 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) ChannelModesByName[cm->name] = cm; - FOREACH_MOD(OnChannelModeAdd, (cm)); + Event::OnChannelModeAdd(&Event::ChannelModeAdd::OnChannelModeAdd, cm); return true; } diff --git a/src/module.cpp b/src/module.cpp index d57538e59..eabf6c0aa 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -64,8 +64,6 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt Module::~Module() { - /* Detach all event hooks for this module */ - ModuleManager::DetachAll(this); IdentifyRequest::ModuleUnload(this); /* Clear any active timers this module has */ TimerManager::DeleteTimersFor(this); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 07ac46ee1..c70e58ecf 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -12,6 +12,7 @@ #include "users.h" #include "regchannel.h" #include "config.h" +#include "event.h" #include <sys/types.h> #include <sys/stat.h> @@ -22,7 +23,6 @@ #endif std::list<Module *> ModuleManager::Modules; -std::vector<Module *> ModuleManager::EventHandlers[I_SIZE]; #ifdef _WIN32 void ModuleManager::CleanupRuntimeDirectory() @@ -243,17 +243,10 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) DeleteModule(m); return MOD_ERR_EXCEPTION; } - catch (const NotImplementedException &ex) - { - } Log(LOG_DEBUG) << "Module " << modname << " loaded."; - /* Attach module to all events */ - for (unsigned i = 0; i < I_SIZE; ++i) - EventHandlers[i].push_back(m); - - FOREACH_MOD(OnModuleLoad, (u, m)); + Event::OnModuleLoad(&Event::ModuleLoad::OnModuleLoad, u, m); return MOD_ERR_OK; } @@ -263,7 +256,7 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u) if (!m) return MOD_ERR_PARAMS; - FOREACH_MOD(OnModuleUnload, (u, m)); + Event::OnModuleUnload(&Event::ModuleUnload::OnModuleUnload, u, m); return DeleteModule(m); } @@ -350,119 +343,6 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) return MOD_ERR_OK; } -void ModuleManager::DetachAll(Module *mod) -{ - for (unsigned i = 0; i < I_SIZE; ++i) - { - std::vector<Module *> &mods = EventHandlers[i]; - std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod); - if (it2 != mods.end()) - mods.erase(it2); - } -} - -bool ModuleManager::SetPriority(Module *mod, Priority s) -{ - for (unsigned i = 0; i < I_SIZE; ++i) - SetPriority(mod, static_cast<Implementation>(i), s); - - return true; -} - -bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Module **modules, size_t sz) -{ - /** To change the priority of a module, we first find its position in the vector, - * then we find the position of the other modules in the vector that this module - * wants to be before/after. We pick off either the first or last of these depending - * on which they want, and we make sure our module is *at least* before or after - * the first or last of this subset, depending again on the type of priority. - */ - - /* Locate our module. This is O(n) but it only occurs on module load so we're - * not too bothered about it - */ - size_t source = 0; - bool found = false; - for (size_t x = 0, end = EventHandlers[i].size(); x != end; ++x) - if (EventHandlers[i][x] == mod) - { - source = x; - found = true; - break; - } - - /* Eh? this module doesnt exist, probably trying to set priority on an event - * theyre not attached to. - */ - if (!found) - return false; - - size_t swap_pos = 0; - bool swap = true; - switch (s) - { - /* Dummy value */ - case PRIORITY_DONTCARE: - swap = false; - break; - /* Module wants to be first, sod everything else */ - case PRIORITY_FIRST: - swap_pos = 0; - break; - /* Module is submissive and wants to be last... awww. */ - case PRIORITY_LAST: - if (EventHandlers[i].empty()) - swap_pos = 0; - else - swap_pos = EventHandlers[i].size() - 1; - break; - /* Place this module after a set of other modules */ - case PRIORITY_AFTER: - /* Find the latest possible position */ - swap_pos = 0; - swap = false; - for (size_t x = 0, end = EventHandlers[i].size(); x != end; ++x) - for (size_t n = 0; n < sz; ++n) - if (modules[n] && EventHandlers[i][x] == modules[n] && x >= swap_pos && source <= swap_pos) - { - swap_pos = x; - swap = true; - } - break; - /* Place this module before a set of other modules */ - case PRIORITY_BEFORE: - swap_pos = EventHandlers[i].size() - 1; - swap = false; - for (size_t x = 0, end = EventHandlers[i].size(); x != end; ++x) - for (size_t n = 0; n < sz; ++n) - if (modules[n] && EventHandlers[i][x] == modules[n] && x <= swap_pos && source >= swap_pos) - { - swap = true; - swap_pos = x; - } - } - - /* Do we need to swap? */ - if (swap && swap_pos != source) - { - /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */ - int incrmnt = 1; - - if (source > swap_pos) - incrmnt = -1; - - for (unsigned j = source; j != swap_pos; j += incrmnt) - { - if (j + incrmnt > EventHandlers[i].size() - 1 || (!j && incrmnt == -1)) - continue; - - std::swap(EventHandlers[i][j], EventHandlers[i][j + incrmnt]); - } - } - - return true; -} - void ModuleManager::UnloadAll() { std::vector<Anope::string> modules; diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 9f3651c12..dfe06a176 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -18,6 +18,7 @@ #include "users.h" #include "servers.h" #include "config.h" +#include "event.h" Serialize::Checker<nickalias_map> NickAliasList("NickAlias"); @@ -51,7 +52,7 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Serial NickAlias::~NickAlias() { - FOREACH_MOD(OnDelNick, (this)); + Event::OnDelNick(&Event::DelNick::OnDelNick, this); /* Accept nicks that have no core, because of database load functions */ if (this->nc) diff --git a/src/nickcore.cpp b/src/nickcore.cpp index c055491db..dc20f2731 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -14,6 +14,7 @@ #include "modules.h" #include "account.h" #include "config.h" +#include "event.h" Serialize::Checker<nickcore_map> NickCoreList("NickCore"); @@ -33,12 +34,12 @@ NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), if (old == NickCoreList->size()) Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?"; - FOREACH_MOD(OnNickCoreCreate, (this)); + Event::OnNickCoreCreate(&Event::NickCoreCreate::OnNickCoreCreate, this); } NickCore::~NickCore() { - FOREACH_MOD(OnDelCore, (this)); + Event::OnDelCore(&Event::DelCore::OnDelCore, this); if (!this->chanaccess->empty()) Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!"; @@ -156,7 +157,7 @@ void NickCore::SetDisplay(const NickAlias *na) if (na->nc != this || na->nick == this->display) return; - FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick)); + Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->nick); /* Remove the core from the list */ NickCoreList->erase(this->display); @@ -174,7 +175,7 @@ bool NickCore::IsServicesOper() const void NickCore::AddAccess(const Anope::string &entry) { this->access.push_back(entry); - FOREACH_MOD(OnNickAddAccess, (this, entry)); + Event::OnNickAddAccess(&Event::NickAddAccess::OnNickAddAccess, this, entry); } Anope::string NickCore::GetAccess(unsigned entry) const @@ -203,7 +204,7 @@ void NickCore::EraseAccess(const Anope::string &entry) for (unsigned i = 0, end = this->access.size(); i < end; ++i) if (this->access[i] == entry) { - FOREACH_MOD(OnNickEraseAccess, (this, entry)); + Event::OnNickEraseAccess(&Event::NickEraseAccess::OnNickEraseAccess, this, entry); this->access.erase(this->access.begin() + i); break; } @@ -211,7 +212,7 @@ void NickCore::EraseAccess(const Anope::string &entry) void NickCore::ClearAccess() { - FOREACH_MOD(OnNickClearAccess, (this)); + Event::OnNickClearAccess(&Event::NickClearAccess::OnNickClearAccess, this); this->access.clear(); } diff --git a/src/process.cpp b/src/process.cpp index 16373b144..2308dc47d 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -15,6 +15,7 @@ #include "servers.h" #include "users.h" #include "regchannel.h" +#include "event.h" void Anope::Process(const Anope::string &buffer) { @@ -70,7 +71,7 @@ void Anope::Process(const Anope::string &buffer) MessageSource src(source); EventReturn MOD_RESULT; - FOREACH_RESULT(OnMessage, MOD_RESULT, (src, command, params)); + MOD_RESULT = Event::OnMessage(&Event::Message::OnMessage, src, command, params); if (MOD_RESULT == EVENT_STOP) return; diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 0228196a0..7551266b0 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -19,6 +19,7 @@ #include "config.h" #include "bots.h" #include "servers.h" +#include "event.h" Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo"); @@ -123,7 +124,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf if (old == RegisteredChannelList->size()) Log(LOG_DEBUG) << "Duplicate channel " << this->name << " in registered channel table?"; - FOREACH_MOD(OnCreateChan, (this)); + Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); } ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), @@ -162,12 +163,12 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), this->AddAkick(takick->creator, takick->mask, takick->reason, takick->addtime, takick->last_used); } - FOREACH_MOD(OnCreateChan, (this)); + Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); } ChannelInfo::~ChannelInfo() { - FOREACH_MOD(OnDelChan, (this)); + Event::OnDelChan(&Event::DelChan::OnDelChan, this); Log(LOG_DEBUG) << "Deleting channel " << this->name; diff --git a/src/serialize.cpp b/src/serialize.cpp index 521704df4..0cb6ec196 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -20,6 +20,7 @@ #include "regchannel.h" #include "xline.h" #include "access.h" +#include "event.h" using namespace Serialize; @@ -54,7 +55,7 @@ Serializable::Serializable(const Anope::string &serialize_type) : last_commit(0) this->s_iter = SerializableItems->end(); --this->s_iter; - FOREACH_MOD(OnSerializableConstruct, (this)); + Event::OnSerializableConstruct(&Event::SerializableConstruct::OnSerializableConstruct, this); } Serializable::Serializable(const Serializable &other) : last_commit(0), last_commit_time(0), id(0), redis_ignore(0) @@ -65,12 +66,12 @@ Serializable::Serializable(const Serializable &other) : last_commit(0), last_com this->s_type = other.s_type; - FOREACH_MOD(OnSerializableConstruct, (this)); + Event::OnSerializableConstruct(&Event::SerializableConstruct::OnSerializableConstruct, this); } Serializable::~Serializable() { - FOREACH_MOD(OnSerializableDestruct, (this)); + Event::OnSerializableDestruct(&Event::SerializableDestruct::OnSerializableDestruct, this); SerializableItems->erase(this->s_iter); } @@ -83,10 +84,10 @@ Serializable &Serializable::operator=(const Serializable &) void Serializable::QueueUpdate() { /* Schedule updater */ - FOREACH_MOD(OnSerializableUpdate, (this)); + Event::OnSerializableUpdate(&Event::SerializableUpdate::OnSerializableUpdate, this); /* Check for modifications now - this can delete this object! */ - FOREACH_MOD(OnSerializeCheck, (this->GetSerializableType())); + Event::OnSerializeCheck(&Event::SerializeCheck::OnSerializeCheck, this->GetSerializableType()); } bool Serializable::IsCached(Serialize::Data &data) @@ -119,7 +120,7 @@ Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), un TypeOrder.push_back(this->name); Types[this->name] = this; - FOREACH_MOD(OnSerializeTypeCreate, (this)); + Event::OnSerializeTypeCreate(&Event::SerializeTypeCreate::OnSerializeTypeCreate, this); } Type::~Type() @@ -137,7 +138,7 @@ Serializable *Type::Unserialize(Serializable *obj, Serialize::Data &data) void Type::Check() { - FOREACH_MOD(OnSerializeCheck, (this)); + Event::OnSerializeCheck(&Event::SerializeCheck::OnSerializeCheck, this); } time_t Type::GetTimestamp() const diff --git a/src/servers.cpp b/src/servers.cpp index 3f698815c..5e55d4c28 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -19,6 +19,7 @@ #include "protocol.h" #include "config.h" #include "channels.h" +#include "event.h" /* Anope */ Server *Me = NULL; @@ -133,7 +134,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano } } - FOREACH_MOD(OnNewServer, (this)); + Event::OnNewServer(&Event::NewServer::OnNewServer, this); } Server::~Server() @@ -168,7 +169,7 @@ void Server::Delete(const Anope::string &reason) { this->quit_reason = reason; this->quitting = true; - FOREACH_MOD(OnServerQuit, (this)); + Event::OnServerQuit(&Event::ServerQuit::OnServerQuit, this); delete this; } @@ -256,7 +257,7 @@ void Server::Sync(bool sync_links) Log(this, "sync") << "is done syncing"; - FOREACH_MOD(OnServerSync, (this)); + Event::OnServerSync(&Event::ServerSync::OnServerSync, this); if (sync_links && !this->links.empty()) { @@ -268,7 +269,7 @@ void Server::Sync(bool sync_links) if (me) { - FOREACH_MOD(OnPreUplinkSync, (this)); + Event::OnPreUplinkSync(&Event::PreUplinkSync::OnPreUplinkSync, this); } for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end;) @@ -285,7 +286,7 @@ void Server::Sync(bool sync_links) IRCD->SendEOB(); Me->Sync(false); - FOREACH_MOD(OnUplinkSync, (this)); + Event::OnUplinkSync(&Event::UplinkSync::OnUplinkSync, this); if (!Anope::NoFork && Anope::AtTerm()) { diff --git a/src/service.cpp b/src/service.cpp new file mode 100644 index 000000000..cfa9a17c7 --- /dev/null +++ b/src/service.cpp @@ -0,0 +1,126 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + + +#include "services.h" +#include "service.h" + +void Service::check() +{ + if (Services || Aliases) + return; + + Services = new std::map<Anope::string, std::map<Anope::string, Service *> >(); + Aliases = new std::map<Anope::string, std::map<Anope::string, Anope::string> >; +} + +Service *Service::FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n) +{ + std::map<Anope::string, Service *>::const_iterator it = services.find(n); + if (it != services.end()) + return it->second; + + if (aliases != NULL) + { + std::map<Anope::string, Anope::string>::const_iterator it2 = aliases->find(n); + if (it2 != aliases->end()) + return FindService(services, aliases, it2->second); + } + + return NULL; +} + +Service *Service::FindService(const Anope::string &t, const Anope::string &n) +{ + check(); + + std::map<Anope::string, std::map<Anope::string, Service *> >::const_iterator it = (*Services).find(t); + if (it == (*Services).end()) + return NULL; + + std::map<Anope::string, std::map<Anope::string, Anope::string> >::const_iterator it2 = (*Aliases).find(t); + if (it2 != (*Aliases).end()) + return FindService(it->second, &it2->second, n); + + return FindService(it->second, NULL, n); +} + +std::vector<Anope::string> Service::GetServiceKeys(const Anope::string &t) +{ + check(); + + std::vector<Anope::string> keys; + std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = (*Services).find(t); + if (it != (*Services).end()) + for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) + keys.push_back(it2->first); + return keys; +} + +void Service::AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v) +{ + check(); + + std::map<Anope::string, Anope::string> &smap = (*Aliases)[t]; + smap[n] = v; +} + +void Service::DelAlias(const Anope::string &t, const Anope::string &n) +{ + check(); + + std::map<Anope::string, Anope::string> &smap = (*Aliases)[t]; + smap.erase(n); + if (smap.empty()) + (*Aliases).erase(t); +} + +Service::Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n) +{ + this->Register(); +} + +Service::~Service() +{ + this->Unregister(); +} + +void Service::Register() +{ + check(); + + std::map<Anope::string, Service *> &smap = (*Services)[this->type]; + if (smap.find(this->name) != smap.end()) + throw ModuleException("Service " + this->type + " with name " + this->name + " already exists"); + smap[this->name] = this; + + ReferenceBase::ResetAll(); +} + +void Service::Unregister() +{ + check(); + + std::map<Anope::string, Service *> &smap = (*Services)[this->type]; + smap.erase(this->name); + if (smap.empty()) + (*Services).erase(this->type); +} + +ServiceAlias::ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from) +{ + Service::AddAlias(type, from, to); +} + +ServiceAlias::~ServiceAlias() +{ + Service::DelAlias(t, f); +} + + diff --git a/src/uplink.cpp b/src/uplink.cpp index 80727487a..12b6c94f9 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -15,6 +15,7 @@ #include "config.h" #include "protocol.h" #include "servers.h" +#include "event.h" UplinkSocket *UplinkSock = NULL; @@ -52,7 +53,7 @@ void Uplink::Connect() new UplinkSocket(); if (!Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost").empty()) UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost")); - FOREACH_MOD(OnPreServerConnect, ()); + Event::OnPreServerConnect(&Event::PreServerConnect::OnPreServerConnect); Anope::string ip = Anope::Resolve(u.host, u.ipv6 ? AF_INET6 : AF_INET); Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << "), port " << u.port; UplinkSock->Connect(ip, u.port); @@ -67,7 +68,7 @@ UplinkSocket::~UplinkSocket() { if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced()) { - FOREACH_MOD(OnServerDisconnect, ()); + Event::OnServerDisconnect(&Event::ServerDisconnect::OnServerDisconnect); for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { @@ -133,7 +134,7 @@ void UplinkSocket::OnConnect() { Log(LOG_TERMINAL) << "Successfully connected to uplink #" << (Anope::CurrentUplink + 1) << " " << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port; IRCD->SendConnect(); - FOREACH_MOD(OnServerConnect, ()); + Event::OnServerConnect(&Event::ServerConnect::OnServerConnect); } void UplinkSocket::OnError(const Anope::string &error) diff --git a/src/users.cpp b/src/users.cpp index 97c850111..560536ce4 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -24,6 +24,7 @@ #include "language.h" #include "sockets.h" #include "uplink.h" +#include "event.h" user_map UserListByNick, UserListByUID; @@ -85,7 +86,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: bool exempt = false; if (server && server->IsULined()) exempt = true; - FOREACH_MOD(OnUserConnect, (this, exempt)); + Event::OnUserConnect(&Event::UserConnect::OnUserConnect, this, exempt); } static void CollideKill(User *target, const Anope::string &reason) @@ -183,7 +184,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) } } - FOREACH_MOD(OnUserNickChange, (this, old)); + Event::OnUserNickChange(&Event::UserNickChange::OnUserNickChange, this, old); } void User::SetDisplayedHost(const Anope::string &shost) @@ -195,7 +196,7 @@ void User::SetDisplayedHost(const Anope::string &shost) Log(this, "host") << "changed vhost to " << shost; - FOREACH_MOD(OnSetDisplayedHost, (this)); + Event::OnSetDisplayedHost(&Event::SetDisplayedHost::OnSetDisplayedHost, this); this->UpdateHost(); } @@ -299,7 +300,7 @@ User::~User() --this->server->users; } - FOREACH_MOD(OnPreUserLogoff, (this)); + Event::OnPreUserLogoff(&Event::PreUserLogoff::OnPreUserLogoff, this); ModeManager::StackerDel(this); this->Logout(); @@ -314,7 +315,7 @@ User::~User() if (!this->uid.empty()) UserListByUID.erase(this->uid); - FOREACH_MOD(OnPostUserLogoff, (this)); + Event::OnPostUserLogoff(&Event::PostUserLogoff::OnPostUserLogoff, this); } void User::SendMessage(BotInfo *source, const char *fmt, ...) @@ -366,7 +367,7 @@ void User::Identify(NickAlias *na) this->Login(na->nc); - FOREACH_MOD(OnNickIdentify, (this)); + Event::OnNickIdentify(&Event::NickIdentify::OnNickIdentify, this); if (this->IsServicesOper()) { @@ -402,7 +403,7 @@ void User::Login(NickCore *core) if (this->server->IsSynced()) Log(this, "account") << "is now identified as " << this->nc->display; - FOREACH_MOD(OnUserLogin, (this)); + Event::OnUserLogin(&Event::UserLogin::OnUserLogin, this); } void User::Logout() @@ -470,7 +471,7 @@ bool User::IsServicesOper() } EventReturn MOD_RESULT; - FOREACH_RESULT(IsServicesOper, MOD_RESULT, (this)); + MOD_RESULT = Event::OnIsServicesOper(&Event::IsServicesOperEvent::IsServicesOper, this); if (MOD_RESULT == EVENT_STOP) return false; @@ -528,7 +529,7 @@ void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anop if (um->name == "CLOAK" || um->name == "VHOST") this->UpdateHost(); - FOREACH_MOD(OnUserModeSet, (source, this, um->name)); + Event::OnUserModeSet(&Event::UserModeSet::OnUserModeSet, source, this, um->name); } void User::RemoveModeInternal(const MessageSource &source, UserMode *um) @@ -547,7 +548,7 @@ void User::RemoveModeInternal(const MessageSource &source, UserMode *um) this->UpdateHost(); } - FOREACH_MOD(OnUserModeUnset, (source, this, um->name)); + Event::OnUserModeUnset(&Event::UserModeUnset::OnUserModeUnset, source, this, um->name); } void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string ¶m) @@ -734,7 +735,7 @@ void User::Quit(const Anope::string &reason) return; } - FOREACH_MOD(OnUserQuit, (this, reason)); + Event::OnUserQuit(&Event::UserQuit::OnUserQuit, this, reason); this->quit = true; quitting_users.push_back(this); |
