From 0e758a2ac23dc4a001e8e126cec14588da9a9769 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 28 Jul 2016 21:29:35 -0400 Subject: Allow serializable fields to use storage in the respective objects. Split service management code nito a proper servicemanager. Make service references managed instead of lazy lookup. Also made events and serializable use service manager instead of their respective systems for management --- cmake/Anope.cmake | 6 +- data/chanserv.example.conf | 5 - data/modules.example.conf | 82 --- include/accessgroup.h | 43 ++ include/bots.h | 27 +- include/commands.h | 2 + include/config.h | 2 +- include/event.h | 632 +++++++++++------- include/extensible.h | 11 +- include/module.h | 1 + include/modules.h | 7 +- include/modules/botserv.h | 1 - include/modules/botserv/badwords.h | 18 +- include/modules/botserv/bot.h | 15 +- include/modules/botserv/info.h | 6 +- include/modules/botserv/kick.h | 28 +- include/modules/chanserv.h | 226 +------ include/modules/chanserv/access.h | 42 +- include/modules/chanserv/akick.h | 11 +- include/modules/chanserv/drop.h | 5 +- include/modules/chanserv/entrymsg.h | 5 +- include/modules/chanserv/info.h | 5 +- include/modules/chanserv/log.h | 11 +- include/modules/chanserv/main/chanaccess.h | 31 + include/modules/chanserv/mode.h | 22 +- include/modules/chanserv/set.h | 6 +- include/modules/chanserv/set_misc.h | 7 +- include/modules/chanserv/suspend.h | 17 +- include/modules/dns.h | 13 +- include/modules/encryption.h | 4 +- include/modules/fantasy.h | 10 +- include/modules/global.h | 5 +- include/modules/help.h | 5 +- include/modules/hostserv/del.h | 5 +- include/modules/httpd.h | 7 +- include/modules/memoserv.h | 34 +- include/modules/nickserv.h | 46 +- include/modules/nickserv/access.h | 5 +- include/modules/nickserv/ajoin.h | 6 +- include/modules/nickserv/cert.h | 16 +- include/modules/nickserv/drop.h | 6 +- include/modules/nickserv/group.h | 5 +- include/modules/nickserv/info.h | 5 +- include/modules/nickserv/set.h | 6 +- include/modules/nickserv/set_misc.h | 6 +- include/modules/nickserv/suspend.h | 15 +- include/modules/nickserv/update.h | 5 +- include/modules/operserv/defcon.h | 5 +- include/modules/operserv/dns.h | 15 +- include/modules/operserv/forbid.h | 12 +- include/modules/operserv/ignore.h | 13 +- include/modules/operserv/info.h | 8 +- include/modules/operserv/news.h | 19 +- include/modules/operserv/session.h | 14 +- include/modules/redis.h | 4 +- include/modules/sasl.h | 75 +-- include/modules/sql.h | 12 +- include/modules/ssl.h | 4 +- include/modules/xmlrpc.h | 4 +- include/opertype.h | 30 +- include/protocol.h | 4 + include/serialize.h | 426 ++++++++---- include/service.h | 162 +++-- include/services.h | 5 + include/users.h | 2 - include/xline.h | 53 +- modules/CMakeLists.txt | 57 +- modules/botserv/assign.cpp | 4 +- modules/botserv/autoassign.cpp | 1 + modules/botserv/badwords.cpp | 33 +- modules/botserv/bot.cpp | 13 +- modules/botserv/botlist.cpp | 2 +- modules/botserv/info.cpp | 12 +- modules/botserv/kick.cpp | 159 +++-- modules/botserv/main/botserv.cpp | 29 +- modules/botserv/set.cpp | 3 +- modules/chanserv/CMakeLists.txt | 2 + modules/chanserv/access.cpp | 912 ++++++++++++++++++++++++++ modules/chanserv/akick.cpp | 43 +- modules/chanserv/clone.cpp | 11 +- modules/chanserv/cs_access.old | 941 --------------------------- modules/chanserv/cs_flags.old | 528 --------------- modules/chanserv/cs_xop.old | 659 ------------------- modules/chanserv/drop.cpp | 10 +- modules/chanserv/entrymsg.cpp | 31 +- modules/chanserv/flags.cpp | 531 +++++++++++++++ modules/chanserv/info.cpp | 10 +- modules/chanserv/list.cpp | 9 +- modules/chanserv/log.cpp | 48 +- modules/chanserv/main/chanaccess.cpp | 58 +- modules/chanserv/main/chanaccess.h | 30 - modules/chanserv/main/chanaccesstype.h | 19 +- modules/chanserv/main/channel.cpp | 68 +- modules/chanserv/main/channel.h | 17 +- modules/chanserv/main/channeltype.cpp | 32 +- modules/chanserv/main/channeltype.h | 28 +- modules/chanserv/main/chanserv.cpp | 70 +- modules/chanserv/main/level.h | 6 + modules/chanserv/main/leveltype.h | 8 +- modules/chanserv/main/mode.h | 5 + modules/chanserv/main/modetype.h | 8 +- modules/chanserv/mode.cpp | 66 +- modules/chanserv/register.cpp | 15 +- modules/chanserv/seen.cpp | 1 + modules/chanserv/set.cpp | 91 +-- modules/chanserv/set_misc.cpp | 22 +- modules/chanserv/statusupdate.cpp | 8 +- modules/chanserv/suspend.cpp | 57 +- modules/chanserv/topic.cpp | 13 +- modules/chanserv/unban.cpp | 2 +- modules/chanserv/xop.cpp | 658 +++++++++++++++++++ modules/database/CMakeLists.txt | 1 + modules/database/flatfile.cpp | 7 +- modules/database/old.cpp | 140 ++-- modules/database/redis.cpp | 28 +- modules/database/sql.cpp | 100 ++- modules/dns.cpp | 3 +- modules/dnsbl.cpp | 17 +- modules/encryption/bcrypt.cpp | 2 + modules/encryption/md5.cpp | 2 + modules/encryption/none.cpp | 3 + modules/encryption/old.cpp | 13 +- modules/encryption/sha1.cpp | 2 + modules/encryption/sha256.cpp | 2 + modules/extra/ldap_authentication.cpp | 2 +- modules/extra/mysql.cpp | 5 +- modules/extra/sasl_dh-aes.cpp | 2 +- modules/extra/sasl_dh-blowfish.cpp | 2 +- modules/extra/sql_authentication.cpp | 2 +- modules/extra/stats/chanstats.cpp | 4 +- modules/fantasy.cpp | 21 +- modules/global/global.cpp | 6 +- modules/global/main/global.cpp | 4 + modules/greet.cpp | 9 +- modules/help.cpp | 16 +- modules/helpchan.cpp | 1 + modules/hostserv/del.cpp | 20 +- modules/hostserv/group.cpp | 6 +- modules/hostserv/list.cpp | 2 +- modules/hostserv/main/hostserv.cpp | 5 + modules/hostserv/request.cpp | 99 +-- modules/hostserv/set.cpp | 6 +- modules/httpd.cpp | 8 +- modules/memoserv/cancel.cpp | 5 +- modules/memoserv/del.cpp | 9 +- modules/memoserv/ignore.cpp | 4 +- modules/memoserv/main/ignore.h | 5 + modules/memoserv/main/ignoretype.cpp | 6 +- modules/memoserv/main/memo.h | 9 +- modules/memoserv/main/memoinfo.cpp | 4 +- modules/memoserv/main/memoinfo.h | 5 + modules/memoserv/main/memoinfotype.cpp | 6 +- modules/memoserv/main/memoserv.cpp | 49 +- modules/memoserv/main/memotype.cpp | 14 +- modules/memoserv/rsend.cpp | 3 +- modules/memoserv/set.cpp | 10 +- modules/nickserv/access.cpp | 31 +- modules/nickserv/ajoin.cpp | 28 +- modules/nickserv/alist.cpp | 2 +- modules/nickserv/cert.cpp | 33 +- modules/nickserv/drop.cpp | 10 +- modules/nickserv/group.cpp | 44 +- modules/nickserv/identify.cpp | 6 +- modules/nickserv/info.cpp | 23 +- modules/nickserv/list.cpp | 7 +- modules/nickserv/logout.cpp | 3 +- modules/nickserv/main/account.cpp | 10 +- modules/nickserv/main/account.h | 4 + modules/nickserv/main/accounttype.cpp | 13 +- modules/nickserv/main/identifyrequest.cpp | 11 + modules/nickserv/main/identifyrequest.h | 1 + modules/nickserv/main/mode.h | 5 + modules/nickserv/main/modetype.h | 6 +- modules/nickserv/main/nick.cpp | 8 +- modules/nickserv/main/nick.h | 8 + modules/nickserv/main/nickserv.cpp | 67 +- modules/nickserv/main/nicktype.cpp | 28 +- modules/nickserv/maxemail.cpp | 7 +- modules/nickserv/recover.cpp | 8 +- modules/nickserv/register.cpp | 45 +- modules/nickserv/resetpass.cpp | 3 +- modules/nickserv/set.cpp | 71 +- modules/nickserv/set_misc.cpp | 22 +- modules/nickserv/suspend.cpp | 57 +- modules/nickserv/update.cpp | 10 +- modules/operserv/akill.cpp | 25 +- modules/operserv/chankill.cpp | 13 +- modules/operserv/defcon.cpp | 59 +- modules/operserv/dns.cpp | 187 +++--- modules/operserv/forbid.cpp | 49 +- modules/operserv/ignore.cpp | 28 +- modules/operserv/info.cpp | 28 +- modules/operserv/login.cpp | 3 +- modules/operserv/logsearch.cpp | 2 +- modules/operserv/main/operserv.cpp | 46 +- modules/operserv/modinfo.cpp | 15 +- modules/operserv/module.cpp | 2 +- modules/operserv/news.cpp | 34 +- modules/operserv/noop.cpp | 3 +- modules/operserv/oper.cpp | 2 +- modules/operserv/reload.cpp | 2 +- modules/operserv/session.cpp | 67 +- modules/operserv/set.cpp | 2 +- modules/operserv/stats.cpp | 108 ++- modules/operserv/sxline.cpp | 30 +- modules/protocol/bahamut.cpp | 9 +- modules/protocol/charybdis.cpp | 2 +- modules/protocol/hybrid.cpp | 23 +- modules/protocol/inspircd20.cpp | 34 +- modules/protocol/ngircd.cpp | 3 +- modules/protocol/plexus.cpp | 11 +- modules/protocol/ratbox.cpp | 8 +- modules/protocol/unreal.cpp | 35 +- modules/proxyscan.cpp | 380 ----------- modules/redis.cpp | 7 +- modules/sasl.cpp | 85 ++- modules/webcpanel/pages/chanserv/access.cpp | 6 +- modules/webcpanel/pages/chanserv/drop.cpp | 2 +- modules/webcpanel/pages/chanserv/utils.cpp | 2 +- modules/webcpanel/pages/hostserv/request.cpp | 2 +- modules/webcpanel/pages/index.cpp | 2 +- modules/webcpanel/pages/logout.cpp | 4 +- modules/webcpanel/pages/nickserv/access.cpp | 2 +- modules/webcpanel/pages/nickserv/alist.cpp | 2 +- modules/webcpanel/pages/nickserv/cert.cpp | 5 +- modules/webcpanel/pages/nickserv/info.cpp | 2 +- modules/webcpanel/pages/operserv/akill.cpp | 5 +- modules/webcpanel/pages/operserv/akill.h | 2 + modules/webcpanel/webcpanel.cpp | 6 +- modules/webcpanel/webcpanel.h | 6 +- modules/xmlrpc.cpp | 6 +- modules/xmlrpc_main.cpp | 9 +- src/accessgroup.cpp | 106 +++ src/base.cpp | 3 +- src/bots.cpp | 38 +- src/channels.cpp | 33 +- src/command.cpp | 17 +- src/config.cpp | 29 +- src/event.cpp | 101 +-- src/extensible.cpp | 6 +- src/init.cpp | 10 +- src/logger.cpp | 20 +- src/main.cpp | 8 +- src/messages.cpp | 30 +- src/misc.cpp | 11 +- src/modes.cpp | 19 +- src/modulemanager.cpp | 8 +- src/opertype.cpp | 6 +- src/process.cpp | 7 +- src/serialize.cpp | 180 +++-- src/servers.cpp | 10 +- src/service.cpp | 106 +-- src/service_manager.cpp | 144 ++++ src/uplink.cpp | 6 +- src/users.cpp | 57 +- src/xline.cpp | 70 +- 256 files changed, 5905 insertions(+), 5400 deletions(-) create mode 100644 include/accessgroup.h create mode 100644 include/modules/chanserv/main/chanaccess.h create mode 100644 modules/chanserv/access.cpp delete mode 100644 modules/chanserv/cs_access.old delete mode 100644 modules/chanserv/cs_flags.old delete mode 100644 modules/chanserv/cs_xop.old create mode 100644 modules/chanserv/flags.cpp delete mode 100644 modules/chanserv/main/chanaccess.h create mode 100644 modules/chanserv/xop.cpp delete mode 100644 modules/proxyscan.cpp create mode 100644 src/accessgroup.cpp create mode 100644 src/service_manager.cpp diff --git a/cmake/Anope.cmake b/cmake/Anope.cmake index 7e125692e..ccc734ed9 100644 --- a/cmake/Anope.cmake +++ b/cmake/Anope.cmake @@ -90,7 +90,7 @@ macro(add_to_cpack_ignored_files ITEM) endif() endmacro() -macro(calculate_dependencies SRC) +macro(calculate_dependencies SRC DEPENDENCIES) file(STRINGS ${SRC} REQUIRED_LIBRARIES REGEX "/\\*[ \t]*Dependencies:[ \t]*.*[ \t]*\\*/") # Iterate through those lines foreach(REQUIRED_LIBRARY ${REQUIRED_LIBRARIES}) @@ -99,9 +99,7 @@ macro(calculate_dependencies SRC) string(REGEX REPLACE "," ";" REQUIRED_LIBRARY ${REQUIRED_LIBRARY}) # Iterate through the libraries given foreach(LIBRARY ${REQUIRED_LIBRARY}) - get_filename_component(TARGNAME ${SRC} NAME_WE) - target_link_libraries(${TARGNAME} ${LIBRARY}) - add_dependencies(${TARGNAME} ${LIBRARY}) + list(APPEND ${DEPENDENCIES} "${LIBRARY}") endforeach() endforeach() endmacro() diff --git a/data/chanserv.example.conf b/data/chanserv.example.conf index 719f8ac9e..c65be299f 100644 --- a/data/chanserv.example.conf +++ b/data/chanserv.example.conf @@ -154,11 +154,6 @@ module */ disallow_hostmask_access = false - /* - * If set, prevents channels from being on access lists. - */ - disallow_channel_access = false - /* * If set, ChanServ will always lower the timestamp of registered channels to their registration date. * This prevents several race conditions where unauthorized users can join empty registered channels and set diff --git a/data/modules.example.conf b/data/modules.example.conf index 10c6255f9..89166e619 100644 --- a/data/modules.example.conf +++ b/data/modules.example.conf @@ -428,88 +428,6 @@ module { name = "help" } rewrite_description = "Clears all users from a channel" } -/* - * proxyscan - * - * This module allows you to scan connecting clients for open proxies. - * Note that using this will allow users to get the IP of your services. - * - * Currently the two supported proxy types are HTTP and SOCKS5. - * - * The proxy scanner works by attempting to connect to clients when they - * connect to the network, and if they have a proxy running instruct it to connect - * back to services. If services are able to connect through the proxy to itself - * then it knows it is an insecure proxy, and will ban it. - */ -#module -{ - name = "proxyscan" - - /* - * The target IP services tells the proxy to connect back to. This must be a publicly - * available IP that remote proxies can connect to. - */ - #target_ip = "127.0.0.1" - - /* - * The port services tells the proxy to connect to. - */ - target_port = 7226 - - /* - * The listen IP services listen on for incoming connections from suspected proxies. - * This probably will be the same as target_ip, but may not be if you are behind a firewall (NAT). - */ - #listen_ip = "127.0.0.1" - - /* - * The port services should listen on for incoming connections from suspected proxies. - * This most likely will be the same as target_port. - */ - listen_port = 7226 - - /* - * An optional notice sent to clients upon connect. - */ - #connect_notice = "We will now scan your host for insecure proxies. If you do not consent to this scan please disconnect immediately." - - /* - * Who the notice should be sent from. - */ - #connect_source = "OperServ" - - /* - * If set, OperServ will add infected clients to the akill list. Without it, OperServ simply sends - * a timed G/K-line to the IRCd and forgets about it. Can be useful if your akill list is being filled up by bots. - */ - add_to_akill = yes - - /* - * How long before connections should be timed out. - */ - timeout = 5 - - proxyscan - { - /* The type of proxy to check for. A comma separated list is allowed. */ - type = "HTTP" - - /* The ports to check. */ - port = "80,8080" - - /* How long to set the ban for. */ - time = 4h - - /* - * The reason to ban the user for. - * %h is replaced with the type of proxy found. - * %i is replaced with the IP of proxy found. - * %p is replaced with the port. - */ - reason = "You have an open proxy running on your host (%t:%i:%p)" - } -} - /* * sasl * diff --git a/include/accessgroup.h b/include/accessgroup.h new file mode 100644 index 000000000..bc3d1a81e --- /dev/null +++ b/include/accessgroup.h @@ -0,0 +1,43 @@ +#include "modules/chanserv.h" + +#pragma once + +namespace ChanServ +{ + +/* A group of access entries. This is used commonly, for example with ChanServ::Channel::AccessFor, + * to show what access a user has on a channel because users can match multiple access entries. + */ +class CoreExport AccessGroup : public std::vector +{ + public: + /* Channel these access entries are on */ + ChanServ::Channel *ci = nullptr; + /* Account these entries affect, if any */ + const NickServ::Account *nc = nullptr; + /* super_admin always gets all privs. founder is a special case where ci->founder == nc */ + bool super_admin = false, founder = false; + + /** Check if this access group has a certain privilege. Eg, it + * will check every ChanAccess entry of this group for any that + * has the given privilege. + * @param priv The privilege + * @return true if any entry has the given privilege + */ + bool HasPriv(const Anope::string &priv); + + /** Get the "highest" access entry from this group of entries. + * The highest entry is determined by the entry that has the privilege + * with the highest rank (see Privilege::rank). + * @return The "highest" entry + */ + ChanAccess *Highest(); + + /* Comparison operators to other AccessGroups */ + bool operator>(AccessGroup &other); + bool operator<(AccessGroup &other); + bool operator>=(AccessGroup &other); + bool operator<=(AccessGroup &other); +}; + +} // namespace ChanServ \ No newline at end of file diff --git a/include/bots.h b/include/bots.h index 80efd8872..d708d8948 100644 --- a/include/bots.h +++ b/include/bots.h @@ -120,12 +120,19 @@ class CoreExport ServiceBot : public LocalUser class BotInfo : public Serialize::Object { + friend class BotInfoType; + + Anope::string nick, user, host, realname; + time_t created = 0; + bool operonly = false; + public: + static constexpr const char *const NAME = "botinfo"; + ServiceBot *bot; Configuration::Block *conf = nullptr; - BotInfo(Serialize::TypeBase *type) : Serialize::Object(type) { } - BotInfo(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { } + using Serialize::Object::Object; void Delete() override; @@ -155,16 +162,14 @@ class BotInfoType : public Serialize::Type Serialize::Field created; Serialize::Field operonly; - BotInfoType() : Serialize::Type(nullptr, "BotInfo") - , nick(this, "nick") - , user(this, "user") - , host(this, "host") - , realname(this, "realname") - , created(this, "created") - , operonly(this, "operonly") + BotInfoType() : Serialize::Type(nullptr) + , nick(this, "nick", &BotInfo::nick) + , user(this, "user", &BotInfo::user) + , host(this, "host", &BotInfo::host) + , realname(this, "realname", &BotInfo::realname) + , created(this, "created", &BotInfo::created) + , operonly(this, "operonly", &BotInfo::operonly) { } }; -static Serialize::TypeReference botinfo("BotInfo"); - diff --git a/include/commands.h b/include/commands.h index e94cffae1..18f36c5d1 100644 --- a/include/commands.h +++ b/include/commands.h @@ -116,6 +116,8 @@ class CoreExport Command : public Service /* Module which owns us */ Module *module; + static constexpr const char *NAME = "Command"; + protected: /** Create a new command. * @param owner The owner of the command diff --git a/include/config.h b/include/config.h index 4fe5a94d5..84f47ecb3 100644 --- a/include/config.h +++ b/include/config.h @@ -129,7 +129,7 @@ namespace Configuration unsigned int LineWrap; std::vector Usermodes; std::vector Channelmodes; - unsigned char CaseMapUpper[256], CaseMapLower[256]; + unsigned char CaseMapUpper[256] = { 0 }, CaseMapLower[256] = { 0 }; /* module configuration blocks */ std::map modules; diff --git a/include/event.h b/include/event.h index f7934b84a..2d5ce55b8 100644 --- a/include/event.h +++ b/include/event.h @@ -1,6 +1,8 @@ /* * - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team + * (C) 2016 Adam + * * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -10,6 +12,7 @@ #pragma once #include "service.h" +#include "base.h" /** Possible return types from events. */ @@ -20,9 +23,10 @@ enum EventReturn EVENT_ALLOW }; -struct Events +class Events : public Service { - virtual ~Events() = default; + public: + Events(Module *o, const Anope::string &ename) : Service(o, ename) { } }; /* uninstantiated */ @@ -59,101 +63,94 @@ struct Caller } }; -template -struct EventName; - template class EventHook; template -class EventHandlers : public Service +class EventDispatcher { - std::vector handlers; - friend class EventHook; + static_assert(std::is_base_of::value, ""); + + ServiceReferenceList handlers; public: - EventHandlers(Module *o) : Service(o, "EventHandlers", EventName::name) - { - } + EventDispatcher(const Anope::string &name) : handlers(name) { } template - auto operator()(Func func, Args&&... args) -> decltype(((static_cast(nullptr))->*func)(args...)) + auto Dispatch(Func func, Args&&... args) -> decltype(((static_cast(nullptr))->*func)(args...)) { - return Caller(nullptr))->*func)(args...)), Args...>()(this->handlers, func, std::forward(args)...); + const std::vector h = this->handlers.GetServices(); + return Caller(nullptr))->*func)(args...)), Args...>()(h, func, std::forward(args)...); } }; template -class EventHandlersReference +class EventHook : public EventHandler { - ServiceReference> ref; - public: - EventHandlersReference() : ref("EventHandlers", EventName::name) { } + static_assert(std::is_base_of::value, ""); - explicit operator bool() + public: + enum class Priority { - return !!ref; + FIRST, + LAST } + priority; - template - auto operator()(Func func, Args&&... args) -> decltype(((static_cast(nullptr))->*func)(args...)) + EventHook(Module *creator) : EventHook(creator, Priority::LAST) { } + + EventHook(Module *creator, Priority p) + : EventHandler(creator, EventHandler::NAME) + , priority(p) { - return (**ref)(func, std::forward(args)...); +#warning "priority doesnt work" } }; -template -class EventHook : public EventHandler +class EventManager { + Anope::hash_map *> cache; - struct ServiceReferenceListener : ServiceReference> + template + EventDispatcher *GetDispatcher(const Anope::string &name) { - EventHook *eh; + auto it = cache.find(name); + if (it != cache.end()) + return reinterpret_cast *>(it->second); - ServiceReferenceListener(EventHook *t, const Anope::string &sname) : ServiceReference>("EventHandlers", sname), eh(t) - { - } + auto dispatcher = new EventDispatcher(name); + cache[name] = reinterpret_cast *>(dispatcher); + return dispatcher; + } - 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; + static EventManager *eventManager; public: - enum class Priority + template< + typename Type, + typename Function, + typename... Args + > + auto Dispatch(Function Type::*func, Args&&... args) -> decltype(((static_cast(nullptr))->*func)(args...)) { - FIRST, - LAST - } - priority; + static_assert(std::is_base_of::value, ""); - EventHook(Priority p = Priority::LAST) : handlers(this, EventName::name), priority(p) - { - handlers.Check(); + EventDispatcher *dispatcher = GetDispatcher(Type::NAME); + return dispatcher->Dispatch(func, std::forward(args)...); } - ~EventHook() - { - if (!handlers) - return; - - auto it = std::find(handlers->handlers.begin(), handlers->handlers.end(), this); - if (it != handlers->handlers.end()) - handlers->handlers.erase(it); - } + static void Init(); + static EventManager *Get(); }; namespace Event { struct CoreExport PreUserKicked : Events { + static constexpr const char *NAME = "preuserkicked"; + + using Events::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 @@ -162,10 +159,13 @@ namespace Event */ virtual EventReturn OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) anope_abstract; }; - extern CoreExport EventHandlers OnPreUserKicked; struct CoreExport UserKicked : Events { + static constexpr const char *NAME = "userkicked"; + + using Events::Events; + /** Called when a user has been kicked from a channel. * @param source The kicker * @param target The user being kicked @@ -175,10 +175,13 @@ namespace Event */ virtual void OnUserKicked(const MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) anope_abstract; }; - extern CoreExport EventHandlers OnUserKicked; struct CoreExport PreBotAssign : Events { + static constexpr const char *NAME = "prebotassign"; + + using Events::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. @@ -187,18 +190,24 @@ namespace Event */ virtual EventReturn OnPreBotAssign(User *sender, ChanServ::Channel *ci, ServiceBot *bi) anope_abstract; }; - extern CoreExport EventHandlers OnPreBotAssign; struct CoreExport BotAssign : Events { + static constexpr const char *NAME = "botassign"; + + using Events::Events; + /** Called when a bot is assigned ot a channel */ virtual void OnBotAssign(User *sender, ChanServ::Channel *ci, ServiceBot *bi) anope_abstract; }; - extern CoreExport EventHandlers OnBotAssign; struct CoreExport BotUnAssign : Events { + static constexpr const char *NAME = "botunassign"; + + using Events::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 @@ -206,40 +215,51 @@ namespace Event */ virtual EventReturn OnBotUnAssign(User *sender, ChanServ::Channel *ci) anope_abstract; }; - extern CoreExport EventHandlers OnBotUnAssign; struct CoreExport UserConnect : Events { + static constexpr const char *NAME = "userconnect"; + + using Events::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 OnUserConnect; struct CoreExport NewServer : Events { + static constexpr const char *NAME = "newserver"; + + using Events::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 OnNewServer; struct CoreExport UserNickChange : Events { + static constexpr const char *NAME = "usernickchange"; + + using Events::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 OnUserNickChange; - struct CoreExport PreCommand : Events { + static constexpr const char *NAME = "precommand"; + + using Events::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 @@ -248,10 +268,13 @@ namespace Event */ virtual EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector ¶ms) anope_abstract; }; - extern CoreExport EventHandlers OnPreCommand; struct CoreExport PostCommand : Events { + static constexpr const char *NAME = "postcommand"; + + using Events::Events; + /** Called after a command has been executed. * @param source The source of the command * @param command The command the user executed @@ -259,68 +282,90 @@ namespace Event */ virtual void OnPostCommand(CommandSource &source, Command *command, const std::vector ¶ms) anope_abstract; }; - extern CoreExport EventHandlers OnPostCommand; struct CoreExport SaveDatabase : Events { + static constexpr const char *NAME = "savedatabase"; + + using Events::Events; + /** Called when the databases are saved */ virtual void OnSaveDatabase() anope_abstract; }; - extern CoreExport EventHandlers OnSaveDatabase; struct CoreExport LoadDatabase : Events { + static constexpr const char *NAME = "loaddatabase"; + + using Events::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 OnLoadDatabase; struct CoreExport Encrypt : Events { + static constexpr const char *NAME = "encrypt"; + + using Events::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 OnEncrypt; struct CoreExport Decrypt : Events { - virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) anope_abstract; - }; - extern CoreExport EventHandlers OnDecrypt; + static constexpr const char *NAME = "decrypt"; + using Events::Events; + virtual EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) anope_abstract; + }; struct CoreExport CreateBot : Events { + static constexpr const char *NAME = "createbot"; + + using Events::Events; + /** Called when a bot is created or destroyed */ virtual void OnCreateBot(ServiceBot *bi) anope_abstract; }; - extern CoreExport EventHandlers OnCreateBot; struct CoreExport DelBot : Events { + static constexpr const char *NAME = "delbot"; + + using Events::Events; + virtual void OnDelBot(ServiceBot *bi) anope_abstract; }; - extern CoreExport EventHandlers OnDelBot; struct CoreExport PrePartChannel : Events { + static constexpr const char *NAME = "prepartchannel"; + + using Events::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 OnPrePartChannel; struct CoreExport PartChannel : Events { + static constexpr const char *NAME = "partchannel"; + + using Events::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 @@ -329,10 +374,13 @@ namespace Event */ virtual void OnPartChannel(User *u, Channel *c, const Anope::string &channel, const Anope::string &msg) anope_abstract; }; - extern CoreExport EventHandlers OnPartChannel; struct CoreExport LeaveChannel : Events { + static constexpr const char *NAME = "leavechannel"; + + using Events::Events; + /** Called when a user leaves a channel. * From either parting, being kicked, or quitting/killed! * @param u The user @@ -340,10 +388,13 @@ namespace Event */ virtual void OnLeaveChannel(User *u, Channel *c) anope_abstract; }; - extern CoreExport EventHandlers OnLeaveChannel; struct CoreExport JoinChannel : Events { + static constexpr const char *NAME = "joinchannel"; + + using Events::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, @@ -353,10 +404,13 @@ namespace Event */ virtual void OnJoinChannel(User *u, Channel *c) anope_abstract; }; - extern CoreExport EventHandlers OnJoinChannel; struct CoreExport TopicUpdated : Events { + static constexpr const char *NAME = "topicupdated"; + + using Events::Events; + /** Called when a new topic is set * @param source * @param c The channel @@ -365,58 +419,79 @@ namespace Event */ virtual void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) anope_abstract; }; - extern CoreExport EventHandlers OnTopicUpdated; struct CoreExport PreServerConnect : Events { + static constexpr const char *NAME = "preserverconnect"; + + using Events::Events; + /** Called before Anope connecs to its uplink */ virtual void OnPreServerConnect() anope_abstract; }; - extern CoreExport EventHandlers OnPreServerConnect; struct CoreExport ServerConnect : Events { + static constexpr const char *NAME = "serverconnect"; + + using Events::Events; + /** Called when Anope connects to its uplink */ virtual void OnServerConnect() anope_abstract; }; - extern CoreExport EventHandlers OnServerConnect; struct CoreExport PreUplinkSync : Events { + static constexpr const char *NAME = "preuplinksync"; + + using Events::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 OnPreUplinkSync; struct CoreExport ServerDisconnect : Events { + static constexpr const char *NAME = "serverdisconnect"; + + using Events::Events; + /** Called when Anope disconnects from its uplink, before it tries to reconnect */ virtual void OnServerDisconnect() anope_abstract; }; - extern CoreExport EventHandlers OnServerDisconnect; struct CoreExport Restart : Events { + static constexpr const char *NAME = "restart"; + + using Events::Events; + /** Called when services restart */ virtual void OnRestart() anope_abstract; }; - extern CoreExport EventHandlers OnRestart; struct CoreExport Shutdown : Events { + static constexpr const char *NAME = "shutdown"; + + using Events::Events; + /** Called when services shutdown */ virtual void OnShutdown() anope_abstract; }; - extern CoreExport EventHandlers OnShutdown; struct CoreExport AddXLine : Events { + static constexpr const char *NAME = "addxline"; + + using Events::Events; + /** Called before a XLine is added * @param source The source of the XLine * @param x The XLine @@ -425,10 +500,13 @@ namespace Event */ virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) anope_abstract; }; - extern CoreExport EventHandlers OnAddXLine; struct CoreExport DelXLine : Events { + static constexpr const char *NAME = "delxline"; + + using Events::Events; + /** Called before a XLine is deleted * @param source The source of the XLine * @param x The XLine @@ -436,39 +514,51 @@ namespace Event */ virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) anope_abstract; }; - extern CoreExport EventHandlers OnDelXLine; struct CoreExport IsServicesOperEvent : Events { + static constexpr const char *NAME = "isservicesoper"; + + using Events::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 OnIsServicesOper; struct CoreExport ServerQuit : Events { + static constexpr const char *NAME = "serverquit"; + + using Events::Events; + /** Called when a server quits * @param server The server */ virtual void OnServerQuit(Server *server) anope_abstract; }; - extern CoreExport EventHandlers OnServerQuit; struct CoreExport UserQuit : Events { + static constexpr const char *NAME = "userquit"; + + using Events::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 OnUserQuit; struct CoreExport PreUserLogoff : Events { + static constexpr const char *NAME = "preuserlogoff"; + + using Events::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. @@ -477,16 +567,22 @@ namespace Event */ virtual void OnPreUserLogoff(User *u) anope_abstract; }; - extern CoreExport EventHandlers OnPreUserLogoff; struct CoreExport PostUserLogoff : Events { + static constexpr const char *NAME = "postuserlogoff"; + + using Events::Events; + virtual void OnPostUserLogoff(User *u) anope_abstract; }; - extern CoreExport EventHandlers OnPostUserLogoff; struct CoreExport AccessDel : Events { + static constexpr const char *NAME = "accessdel"; + + using Events::Events; + /** Called after an access entry is deleted from a channel * @param ci The channel * @param source The source of the command @@ -494,10 +590,13 @@ namespace Event */ virtual void OnAccessDel(ChanServ::Channel *ci, CommandSource &source, ChanServ::ChanAccess *access) anope_abstract; }; - extern CoreExport EventHandlers OnAccessDel; struct CoreExport AccessAdd : Events { + static constexpr const char *NAME = "accessadd"; + + using Events::Events; + /** Called when access is added * @param ci The channel * @param source The source of the command @@ -505,68 +604,75 @@ namespace Event */ virtual void OnAccessAdd(ChanServ::Channel *ci, CommandSource &source, ChanServ::ChanAccess *access) anope_abstract; }; - extern CoreExport EventHandlers OnAccessAdd; struct CoreExport AccessClear : Events { + static constexpr const char *NAME = "accessclear"; + + using Events::Events; + /** Called when the access list is cleared * @param ci The channel * @param u The user who cleared the access */ virtual void OnAccessClear(ChanServ::Channel *ci, CommandSource &source) anope_abstract; }; - extern CoreExport EventHandlers OnAccessClear; struct CoreExport ChanRegistered : Events { - /** Called when a channel is registered - * @param ci The channel - */ - virtual void OnChanRegistered(ChanServ::Channel *ci) anope_abstract; - }; - extern CoreExport EventHandlers OnChanRegistered; + static constexpr const char *NAME = "chanregistered"; + using Events::Events; - struct CoreExport CreateChan : Events - { - /** Called when a channel is being created, for any reason + /** Called when a channel is registered * @param ci The channel */ - virtual void OnCreateChan(ChanServ::Channel *ci) anope_abstract; + virtual void OnChanRegistered(ChanServ::Channel *ci) anope_abstract; }; - extern CoreExport EventHandlers OnCreateChan; struct CoreExport DelChan : Events { + static constexpr const char *NAME = "delchan"; + + using Events::Events; + /** Called when a channel is being deleted, for any reason * @param ci The channel */ virtual void OnDelChan(ChanServ::Channel *ci) anope_abstract; }; - extern CoreExport EventHandlers OnDelChan; struct CoreExport ChannelCreate : Events { + static constexpr const char *NAME = "channelcreate"; + + using Events::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 OnChannelCreate; struct CoreExport ChannelDelete : Events { + static constexpr const char *NAME = "channeldelete"; + + using Events::Events; + /** Called when a channel is deleted * @param c The channel */ virtual void OnChannelDelete(Channel *c) anope_abstract; }; - extern CoreExport EventHandlers OnChannelDelete; - struct CoreExport CheckKick : Events { + static constexpr const char *NAME = "checkkick"; + + using Events::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 @@ -577,10 +683,13 @@ namespace Event */ virtual EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) anope_abstract; }; - extern CoreExport EventHandlers OnCheckKick; struct CoreExport CheckPriv : Events { + static constexpr const char *NAME = "checkpriv"; + + using Events::Events; + /** Checks if access has the channel privilege 'priv'. * @param access THe access struct * @param priv The privilege being checked for @@ -588,10 +697,13 @@ namespace Event */ virtual EventReturn OnCheckPriv(const ChanServ::ChanAccess *access, const Anope::string &priv) anope_abstract; }; - extern CoreExport EventHandlers OnCheckPriv; struct CoreExport GroupCheckPriv : Events { + static constexpr const char *NAME = "groupcheckpriv"; + + using Events::Events; + /** Check whether an access group has a privilege * @param group The group * @param priv The privilege @@ -599,134 +711,162 @@ namespace Event */ virtual EventReturn OnGroupCheckPriv(const ChanServ::AccessGroup *group, const Anope::string &priv) anope_abstract; }; - extern CoreExport EventHandlers OnGroupCheckPriv; struct CoreExport NickIdentify : Events { + static constexpr const char *NAME = "nickidentify"; + + using Events::Events; + /** Called when a user identifies to a nick * @param u The user */ virtual void OnNickIdentify(User *u) anope_abstract; }; - extern CoreExport EventHandlers OnNickIdentify; struct CoreExport UserLogin : Events { + static constexpr const char *NAME = "userlogin"; + + using Events::Events; + /** Called when a user is logged into an account * @param u The user */ virtual void OnUserLogin(User *u) anope_abstract; }; - extern CoreExport EventHandlers OnUserLogin; struct CoreExport NickLogout : Events { + static constexpr const char *NAME = "nicklogout"; + + using Events::Events; + /** Called when a nick logs out * @param u The nick */ virtual void OnNickLogout(User *u) anope_abstract; }; - extern CoreExport EventHandlers OnNickLogout; struct CoreExport DelNick : Events { + static constexpr const char *NAME = "delnick"; + + using Events::Events; + /** Called on delnick() - * @ param na pointer to the nickalias + * @param na pointer to the nickalias */ virtual void OnDelNick(NickServ::Nick *na) anope_abstract; }; - extern CoreExport EventHandlers OnDelNick; - - struct CoreExport NickCoreCreate : Events - { - /** Called when a nickcore is created - * @param nc The nickcore - */ - virtual void OnNickCoreCreate(NickServ::Account *nc) anope_abstract; - }; - extern CoreExport EventHandlers OnNickCoreCreate; struct CoreExport DelCore : Events { + static constexpr const char *NAME = "delcore"; + + using Events::Events; + /** Called on delcore() * @param nc pointer to the NickServ::Account */ virtual void OnDelCore(NickServ::Account *nc) anope_abstract; }; - extern CoreExport EventHandlers OnDelCore; struct CoreExport ChangeCoreDisplay : Events { + static constexpr const char *NAME = "changecoredisplay"; + + using Events::Events; + /** Called on change_core_display() * @param nc pointer to the NickServ::Account * @param newdisplay the new display */ virtual void OnChangeCoreDisplay(NickServ::Account *nc, const Anope::string &newdisplay) anope_abstract; }; - extern CoreExport EventHandlers OnChangeCoreDisplay; struct CoreExport NickClearAccess : Events { + static constexpr const char *NAME = "nickclearaccess"; + + using Events::Events; + /** called from NickServ::Account::ClearAccess() * @param nc pointer to the NickServ::Account */ virtual void OnNickClearAccess(NickServ::Account *nc) anope_abstract; }; - extern CoreExport EventHandlers OnNickClearAccess; struct CoreExport NickAddAccess : Events { + static constexpr const char *NAME = "nickaddaccess"; + + using Events::Events; + /** Called when a user adds an entry to their access list * @param nc The nick * @param entry The entry */ virtual void OnNickAddAccess(NickServ::Account *nc, const Anope::string &entry) anope_abstract; }; - extern CoreExport EventHandlers OnNickAddAccess; struct CoreExport NickEraseAccess : Events { + static constexpr const char *NAME = "nickeraseaccess"; + + using Events::Events; + /** Called from NickServ::Account::EraseAccess() * @param nc pointer to the NickServ::Account * @param entry The access mask */ virtual void OnNickEraseAccess(NickServ::Account *nc, const Anope::string &entry) anope_abstract; }; - extern CoreExport EventHandlers OnNickEraseAccess; - - struct CoreExport CheckAuthentication : Events { + static constexpr const char *NAME = "checkauthentication"; + + using Events::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, NickServ::IdentifyRequest *req) anope_abstract; }; - extern CoreExport EventHandlers OnCheckAuthentication; struct CoreExport Fingerprint : Events { + static constexpr const char *NAME = "fingerprint"; + + using Events::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 OnFingerprint; struct CoreExport UserAway : Events { + static constexpr const char *NAME = "useraway"; + + using Events::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 OnUserAway; struct CoreExport Invite : Events { + static constexpr const char *NAME = "invite"; + + using Events::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 @@ -734,28 +874,37 @@ namespace Event */ virtual void OnInvite(User *source, Channel *c, User *targ) anope_abstract; }; - extern CoreExport EventHandlers OnInvite; struct CoreExport SetVhost : Events { + static constexpr const char *NAME = "setvhost"; + + using Events::Events; + /** Called when a vhost is set * @param na The nickalias of the vhost */ virtual void OnSetVhost(NickServ::Nick *na) anope_abstract; }; - extern CoreExport EventHandlers OnSetVhost; struct CoreExport SetDisplayedHost : Events { + static constexpr const char *NAME = "setdisplayedhost"; + + using Events::Events; + /** Called when a users host changes * @param u The user */ virtual void OnSetDisplayedHost(User *) anope_abstract; }; - extern CoreExport EventHandlers OnSetDisplayedHost; struct CoreExport ChannelModeSet : Events { + static constexpr const char *NAME = "channelmodeset"; + + using Events::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 @@ -765,10 +914,13 @@ namespace Event */ virtual EventReturn OnChannelModeSet(Channel *c, const MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) anope_abstract; }; - extern CoreExport EventHandlers OnChannelModeSet; struct CoreExport ChannelModeUnset : Events { + static constexpr const char *NAME = "channelmodeunset"; + + using Events::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 @@ -778,10 +930,13 @@ namespace Event */ virtual EventReturn OnChannelModeUnset(Channel *c, const MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) anope_abstract; }; - extern CoreExport EventHandlers OnChannelModeUnset; struct CoreExport UserModeSet : Events { + static constexpr const char *NAME = "usermodeset"; + + using Events::Events; + /** Called when a mode is set on a user * @param setter who/what is setting the mode * @param u The user @@ -789,10 +944,13 @@ namespace Event */ virtual void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_abstract; }; - extern CoreExport EventHandlers OnUserModeSet; struct CoreExport UserModeUnset : Events { + static constexpr const char *NAME = "usermodeunset"; + + using Events::Events; + /** Called when a mode is unset from a user * @param setter who/what is setting the mode * @param u The user @@ -800,66 +958,87 @@ namespace Event */ virtual void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_abstract; }; - extern CoreExport EventHandlers OnUserModeUnset; struct CoreExport ChannelModeAdd : Events { + static constexpr const char *NAME = "channelmodeadd"; + + using Events::Events; + /** Called when a channel mode is introducted into Anope * @param cm The mode */ virtual void OnChannelModeAdd(ChannelMode *cm) anope_abstract; }; - extern CoreExport EventHandlers OnChannelModeAdd; struct CoreExport UserModeAdd : Events { + static constexpr const char *NAME = "usermodeadd"; + + using Events::Events; + /** Called when a user mode is introducted into Anope * @param um The mode */ virtual void OnUserModeAdd(UserMode *um) anope_abstract; }; - extern CoreExport EventHandlers OnUserModeAdd; struct CoreExport ModuleLoad : Events { + static constexpr const char *NAME = "moduleload"; + + using Events::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 OnModuleLoad; struct CoreExport ModuleUnload : Events { + static constexpr const char *NAME = "moduleunload"; + + using Events::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 OnModuleUnload; struct CoreExport ServerSync : Events { + static constexpr const char *NAME = "serversync"; + + using Events::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 OnServerSync; struct CoreExport UplinkSync : Events { + static constexpr const char *NAME = "uplinksync"; + + using Events::Events; + /** Called when we sync with our uplink * @param s Our uplink */ virtual void OnUplinkSync(Server *s) anope_abstract; }; - extern CoreExport EventHandlers OnUplinkSync; struct CoreExport BotPrivmsg : Events { + static constexpr const char *NAME = "botprivmsg"; + + using Events::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 @@ -868,10 +1047,13 @@ namespace Event */ virtual EventReturn OnBotPrivmsg(User *u, ServiceBot *bi, Anope::string &message) anope_abstract; }; - extern CoreExport EventHandlers OnBotPrivmsg; struct CoreExport BotNotice : Events { + static constexpr const char *NAME = "botnotice"; + + using Events::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 @@ -879,10 +1061,13 @@ namespace Event */ virtual void OnBotNotice(User *u, ServiceBot *bi, Anope::string &message) anope_abstract; }; - extern CoreExport EventHandlers OnBotNotice; struct CoreExport Privmsg : Events { + static constexpr const char *NAME = "privmsg"; + + using Events::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 @@ -890,19 +1075,25 @@ namespace Event */ virtual void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_abstract; }; - extern CoreExport EventHandlers OnPrivmsg; struct CoreExport Log : Events { + static constexpr const char *NAME = "log"; + + using Events::Events; + /** Called when a message is logged * @param l The log message */ virtual void OnLog(::Log *l) anope_abstract; }; - extern CoreExport EventHandlers OnLog; struct CoreExport LogMessage : Events { + static constexpr const char *NAME = "logmessage"; + + using Events::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 @@ -911,20 +1102,26 @@ namespace Event */ virtual void OnLogMessage(LogInfo *li, const ::Log *l, const Anope::string &msg) anope_abstract; }; - extern CoreExport EventHandlers OnLogMessage; struct CoreExport CheckModes : Events { + static constexpr const char *NAME = "checkmodes"; + + using Events::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 &c) anope_abstract; }; - extern CoreExport EventHandlers OnCheckModes; struct CoreExport ChannelSync : Events { + static constexpr const char *NAME = "channelsync"; + + using Events::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, @@ -932,10 +1129,13 @@ namespace Event */ virtual void OnChannelSync(Channel *c) anope_abstract; }; - extern CoreExport EventHandlers OnChannelSync; struct CoreExport SetCorrectModes : Events { + static constexpr const char *NAME = "setcorrectmodes"; + + using Events::Events; + /** Called to set the correct modes on the user on the given channel * @param user The user * @param chan The channel @@ -945,10 +1145,13 @@ namespace Event */ virtual void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) anope_abstract; }; - extern CoreExport EventHandlers OnSetCorrectModes; struct CoreExport Message : Events { + static constexpr const char *NAME = "message"; + + using Events::Events; + /** Called whenever a message is received from the uplink * @param source The source of the message * @param command The command being executed @@ -957,35 +1160,47 @@ namespace Event */ virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector ¶m) anope_abstract; }; - extern CoreExport EventHandlers OnMessage; struct CoreExport CanSet : Events { + static constexpr const char *NAME = "canset"; + + using Events::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 OnCanSet; struct CoreExport CheckDelete : Events { + static constexpr const char *NAME = "checkdelete"; + + using Events::Events; + virtual EventReturn OnCheckDelete(Channel *) anope_abstract; }; - extern CoreExport EventHandlers OnCheckDelete; struct CoreExport ExpireTick : Events { + static constexpr const char *NAME = "expiretick"; + + using Events::Events; + /** Called every options:expiretimeout seconds. Should be used to expire nicks, * channels, etc. */ virtual void OnExpireTick() anope_abstract; }; - extern CoreExport EventHandlers OnExpireTick; struct CoreExport SerializeEvents : Events { + static constexpr const char *NAME = "serialize"; + + using Events::Events; + virtual EventReturn OnSerializeList(Serialize::TypeBase *type, std::vector &ids) anope_abstract; virtual EventReturn OnSerializeFind(Serialize::TypeBase *type, Serialize::FieldBase *field, const Anope::string &value, Serialize::ID &id) anope_abstract; @@ -1014,91 +1229,4 @@ namespace Event virtual void OnSerializableCreate(Serialize::Object *) anope_abstract; }; - extern CoreExport EventHandlers OnSerialize; } - -template<> struct EventName { static constexpr const char *const name = "OnPreUserKicked"; }; -template<> struct EventName { static constexpr const char *const name = "OnUserKicked"; }; -template<> struct EventName { static constexpr const char *const name = "OnPreBotAssign"; }; -template<> struct EventName { static constexpr const char *const name = "OnBotAssign"; }; -template<> struct EventName { static constexpr const char *const name = "OnBotUnAssign"; }; -template<> struct EventName { static constexpr const char *const name = "OnUserConnect"; }; -template<> struct EventName { static constexpr const char *const name = "OnNewServer"; }; -template<> struct EventName { static constexpr const char *const name = "OnUserNickChange"; }; -template<> struct EventName { static constexpr const char *const name = "OnPreCommand"; }; -template<> struct EventName { static constexpr const char *const name = "OnPostCommand"; }; -template<> struct EventName { static constexpr const char *const name = "OnSaveDatabase"; }; -template<> struct EventName { static constexpr const char *const name = "OnLoadDatabase"; }; -template<> struct EventName { static constexpr const char *const name = "OnEncrypt"; }; -template<> struct EventName { static constexpr const char *const name = "OnDecrypt"; }; -template<> struct EventName { static constexpr const char *const name = "OnCreateBot"; }; -template<> struct EventName { static constexpr const char *const name = "OnDelBot"; }; -template<> struct EventName { static constexpr const char *const name = "OnPrePartChannel"; }; -template<> struct EventName { static constexpr const char *const name = "OnPartChannel"; }; -template<> struct EventName { static constexpr const char *const name = "OnLeaveChannel"; }; -template<> struct EventName { stati