summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-27 19:36:37 -0400
committerAdam <Adam@anope.org>2013-05-27 19:36:37 -0400
commit37b3535543b81c3d75c8f62b83d422f0d2fbced0 (patch)
tree8a062415c91d352e4b6bd180cbf238d1f159802d
parentc21e8d9204f9b671177a63d4daa21957bffc1d9f (diff)
Initially attach all modules to all events, and detach them as the events are run if they are not implemented per module
-rw-r--r--include/modules.h410
-rw-r--r--modules/bs_autoassign.cpp2
-rw-r--r--modules/commands/bs_assign.cpp2
-rw-r--r--modules/commands/bs_bot.cpp6
-rw-r--r--modules/commands/bs_kick.cpp4
-rw-r--r--modules/commands/bs_set.cpp1
-rw-r--r--modules/commands/cs_access.cpp16
-rw-r--r--modules/commands/cs_akick.cpp8
-rw-r--r--modules/commands/cs_clone.cpp2
-rw-r--r--modules/commands/cs_drop.cpp2
-rw-r--r--modules/commands/cs_entrymsg.cpp2
-rw-r--r--modules/commands/cs_fantasy_stats.cpp2
-rw-r--r--modules/commands/cs_fantasy_top.cpp2
-rw-r--r--modules/commands/cs_flags.cpp8
-rw-r--r--modules/commands/cs_info.cpp2
-rw-r--r--modules/commands/cs_log.cpp2
-rw-r--r--modules/commands/cs_register.cpp2
-rw-r--r--modules/commands/cs_seen.cpp9
-rw-r--r--modules/commands/cs_set.cpp34
-rw-r--r--modules/commands/cs_set_misc.cpp4
-rw-r--r--modules/commands/cs_suspend.cpp6
-rw-r--r--modules/commands/cs_topic.cpp4
-rw-r--r--modules/commands/cs_xop.cpp10
-rw-r--r--modules/commands/help.cpp4
-rw-r--r--modules/commands/hs_del.cpp4
-rw-r--r--modules/commands/hs_request.cpp2
-rw-r--r--modules/commands/hs_set.cpp4
-rw-r--r--modules/commands/ms_cancel.cpp4
-rw-r--r--modules/commands/ms_del.cpp12
-rw-r--r--modules/commands/ns_access.cpp2
-rw-r--r--modules/commands/ns_ajoin.cpp2
-rw-r--r--modules/commands/ns_cert.cpp2
-rw-r--r--modules/commands/ns_drop.cpp2
-rw-r--r--modules/commands/ns_group.cpp6
-rw-r--r--modules/commands/ns_identify.cpp2
-rw-r--r--modules/commands/ns_info.cpp2
-rw-r--r--modules/commands/ns_logout.cpp2
-rw-r--r--modules/commands/ns_recover.cpp4
-rw-r--r--modules/commands/ns_register.cpp2
-rw-r--r--modules/commands/ns_resetpass.cpp1
-rw-r--r--modules/commands/ns_set.cpp24
-rw-r--r--modules/commands/ns_set_misc.cpp4
-rw-r--r--modules/commands/ns_suspend.cpp6
-rw-r--r--modules/commands/ns_update.cpp2
-rw-r--r--modules/commands/os_akill.cpp6
-rw-r--r--modules/commands/os_defcon.cpp6
-rw-r--r--modules/commands/os_dns.cpp2
-rw-r--r--modules/commands/os_forbid.cpp2
-rw-r--r--modules/commands/os_ignore.cpp2
-rw-r--r--modules/commands/os_login.cpp1
-rw-r--r--modules/commands/os_news.cpp2
-rw-r--r--modules/commands/os_noop.cpp1
-rw-r--r--modules/commands/os_session.cpp6
-rw-r--r--modules/commands/os_sxline.cpp8
-rw-r--r--modules/cs_statusupdate.cpp2
-rw-r--r--modules/database/db_flatfile.cpp2
-rw-r--r--modules/database/db_old.cpp2
-rw-r--r--modules/database/db_plain.cpp15
-rw-r--r--modules/database/db_redis.cpp2
-rw-r--r--modules/database/db_sql.cpp2
-rw-r--r--modules/database/db_sql_live.cpp2
-rw-r--r--modules/encryption/enc_md5.cpp2
-rw-r--r--modules/encryption/enc_none.cpp2
-rw-r--r--modules/encryption/enc_old.cpp2
-rw-r--r--modules/encryption/enc_sha1.cpp2
-rw-r--r--modules/encryption/enc_sha256.cpp2
-rw-r--r--modules/extra/m_chanstats.cpp11
-rw-r--r--modules/extra/m_httpd.cpp2
-rw-r--r--modules/extra/m_ldap.cpp2
-rw-r--r--modules/extra/m_ldap_authentication.cpp4
-rw-r--r--modules/extra/m_ldap_oper.cpp2
-rw-r--r--modules/extra/m_mysql.cpp2
-rw-r--r--modules/extra/m_proxyscan.cpp2
-rw-r--r--modules/extra/m_sql_authentication.cpp4
-rw-r--r--modules/extra/m_sql_oper.cpp2
-rw-r--r--modules/extra/m_sqlite.cpp2
-rw-r--r--modules/extra/m_ssl.cpp2
-rw-r--r--modules/extra/m_xmlrpc.cpp2
-rw-r--r--modules/extra/m_xmlrpc_main.cpp2
-rw-r--r--modules/extra/webcpanel/pages/index.cpp2
-rw-r--r--modules/m_dns.cpp4
-rw-r--r--modules/m_dnsbl.cpp2
-rw-r--r--modules/m_helpchan.cpp2
-rw-r--r--modules/m_redis.cpp2
-rw-r--r--modules/m_rewrite.cpp2
-rw-r--r--modules/protocol/bahamut.cpp1
-rw-r--r--modules/protocol/charybdis.cpp6
-rw-r--r--modules/protocol/hybrid.cpp1
-rw-r--r--modules/protocol/inspircd12.cpp4
-rw-r--r--modules/protocol/inspircd20.cpp4
-rw-r--r--modules/protocol/ngircd.cpp2
-rw-r--r--modules/protocol/plexus.cpp2
-rw-r--r--modules/protocol/unreal.cpp4
-rw-r--r--modules/pseudoclients/botserv.cpp11
-rw-r--r--modules/pseudoclients/chanserv.cpp9
-rw-r--r--modules/pseudoclients/global.cpp2
-rw-r--r--modules/pseudoclients/hostserv.cpp5
-rw-r--r--modules/pseudoclients/memoserv.cpp4
-rw-r--r--modules/pseudoclients/nickserv.cpp10
-rw-r--r--modules/pseudoclients/operserv.cpp2
-rw-r--r--src/access.cpp4
-rw-r--r--src/bots.cpp14
-rw-r--r--src/channels.cpp34
-rw-r--r--src/command.cpp4
-rw-r--r--src/config.cpp2
-rw-r--r--src/init.cpp2
-rw-r--r--src/logger.cpp2
-rw-r--r--src/main.cpp8
-rw-r--r--src/messages.cpp18
-rw-r--r--src/misc.cpp4
-rw-r--r--src/modes.cpp6
-rw-r--r--src/modulemanager.cpp98
-rw-r--r--src/nickalias.cpp2
-rw-r--r--src/nickcore.cpp18
-rw-r--r--src/process.cpp2
-rw-r--r--src/regchannel.cpp18
-rw-r--r--src/serialize.cpp14
-rw-r--r--src/servers.cpp10
-rw-r--r--src/uplink.cpp6
-rw-r--r--src/users.cpp20
120 files changed, 440 insertions, 672 deletions
diff --git a/include/modules.h b/include/modules.h
index 3f99a9114..5463c2ad6 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -56,49 +56,56 @@
/**
* This #define allows us to call a method in all
* loaded modules in a readable simple way, e.g.:
- * 'FOREACH_MOD(I_OnConnect,OnConnect(user));'
+ *
+ * FOREACH_MOD(OnUserConnect, (user, exempt));
*/
-#define FOREACH_MOD(y, x) \
+#define FOREACH_MOD(ename, args) \
if (true) \
{ \
- std::vector<Module *>::iterator safei; \
- for (std::vector<Module *>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
+ static std::vector<Module *> &_modules = ModuleManager::GetEventHandlers(#ename); \
+ for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \
{ \
- safei = _i; \
- ++safei; \
try \
{ \
- (*_i)->x ; \
+ (*_i)->ename args; \
} \
catch (const ModuleException &modexcept) \
{ \
Log() << "Exception caught: " << modexcept.GetReason(); \
} \
- _i = safei; \
+ catch (const NotImplementedException &) \
+ { \
+ Log(LOG_DEBUG_2) << "Detaching event " << #ename << " from " << (*_i)->name; \
+ _i = _modules.erase(_i); \
+ continue; \
+ } \
+ ++_i; \
} \
} \
else \
static_cast<void>(0)
/**
- * This define is similar to the one above but returns a result in MOD_RESULT.
- * The first module to return a nonzero result is the value to be accepted,
- * and any modules after are ignored.
+ * 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(y, x) \
+#define FOREACH_RESULT(ename, ret, args) \
if (true) \
{ \
- std::vector<Module *>::iterator safei; \
- MOD_RESULT = EVENT_CONTINUE; \
- for (std::vector<Module *>::iterator _i = ModuleManager::EventHandlers[y].begin(); _i != ModuleManager::EventHandlers[y].end(); ) \
+ ret = EVENT_CONTINUE; \
+ static std::vector<Module *> &_modules = ModuleManager::GetEventHandlers(#ename); \
+ for (std::vector<Module *>::iterator _i = _modules.begin(); _i != _modules.end();) \
{ \
- safei = _i; \
- ++safei; \
try \
{ \
- EventReturn res = (*_i)->x ; \
- if (res != EVENT_CONTINUE) { \
- MOD_RESULT = res; \
+ EventReturn res = (*_i)->ename args; \
+ if (res != EVENT_CONTINUE) \
+ { \
+ ret = res; \
break; \
} \
} \
@@ -106,12 +113,19 @@ if (true) \
{ \
Log() << "Exception caught: " << modexcept.GetReason(); \
} \
- _i = safei; \
+ catch (const NotImplementedException &) \
+ { \
+ Log(LOG_DEBUG_2) << "Detaching event " << #ename << " from " << (*_i)->name; \
+ _i = _modules.erase(_i); \
+ continue; \
+ } \
+ ++_i; \
} \
} \
else \
static_cast<void>(0)
+
/** Possible return types from events.
*/
enum EventReturn
@@ -195,6 +209,7 @@ class ModuleVersion
int GetPatch() const;
};
+class NotImplementedException : public CoreException { };
/** Every module in Anope is actually a class.
*/
@@ -281,7 +296,7 @@ class CoreExport Module : public Extensible
* @param cu The user, channel, and status of the user being kicked
* @param kickmsg The reason for the kick.
*/
- virtual void OnPreUserKicked(MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) { }
+ virtual void OnPreUserKicked(MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) { throw NotImplementedException(); }
/** Called when a user has been kicked from a channel.
* @param source The kicker
@@ -290,13 +305,13 @@ class CoreExport Module : public Extensible
* @param status The status the kicked user had on the channel before they were kicked</