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 /include | |
| parent | 0b6476f06ff9ce06545c421143c7d7163c750aa5 (diff) | |
New event system
Diffstat (limited to 'include')
39 files changed, 1845 insertions, 1200 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 + |
