summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-07-28 21:29:35 -0400
committerAdam <Adam@anope.org>2016-07-28 21:29:35 -0400
commit0e758a2ac23dc4a001e8e126cec14588da9a9769 (patch)
tree45df813323e023c5c89db7279426c4ad0943b4a9
parenta3c8afae00c54d5b95c620248b51f90679d7d53f (diff)
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
-rw-r--r--cmake/Anope.cmake6
-rw-r--r--data/chanserv.example.conf5
-rw-r--r--data/modules.example.conf82
-rw-r--r--include/accessgroup.h43
-rw-r--r--include/bots.h27
-rw-r--r--include/commands.h2
-rw-r--r--include/config.h2
-rw-r--r--include/event.h632
-rw-r--r--include/extensible.h11
-rw-r--r--include/module.h1
-rw-r--r--include/modules.h7
-rw-r--r--include/modules/botserv.h1
-rw-r--r--include/modules/botserv/badwords.h18
-rw-r--r--include/modules/botserv/bot.h15
-rw-r--r--include/modules/botserv/info.h6
-rw-r--r--include/modules/botserv/kick.h28
-rw-r--r--include/modules/chanserv.h226
-rw-r--r--include/modules/chanserv/access.h42
-rw-r--r--include/modules/chanserv/akick.h11
-rw-r--r--include/modules/chanserv/drop.h5
-rw-r--r--include/modules/chanserv/entrymsg.h5
-rw-r--r--include/modules/chanserv/info.h5
-rw-r--r--include/modules/chanserv/log.h11
-rw-r--r--include/modules/chanserv/main/chanaccess.h (renamed from modules/chanserv/main/chanaccess.h)3
-rw-r--r--include/modules/chanserv/mode.h22
-rw-r--r--include/modules/chanserv/set.h6
-rw-r--r--include/modules/chanserv/set_misc.h7
-rw-r--r--include/modules/chanserv/suspend.h17
-rw-r--r--include/modules/dns.h13
-rw-r--r--include/modules/encryption.h4
-rw-r--r--include/modules/fantasy.h10
-rw-r--r--include/modules/global.h5
-rw-r--r--include/modules/help.h5
-rw-r--r--include/modules/hostserv/del.h5
-rw-r--r--include/modules/httpd.h7
-rw-r--r--include/modules/memoserv.h34
-rw-r--r--include/modules/nickserv.h46
-rw-r--r--include/modules/nickserv/access.h5
-rw-r--r--include/modules/nickserv/ajoin.h6
-rw-r--r--include/modules/nickserv/cert.h16
-rw-r--r--include/modules/nickserv/drop.h6
-rw-r--r--include/modules/nickserv/group.h5
-rw-r--r--include/modules/nickserv/info.h5
-rw-r--r--include/modules/nickserv/set.h6
-rw-r--r--include/modules/nickserv/set_misc.h6
-rw-r--r--include/modules/nickserv/suspend.h15
-rw-r--r--include/modules/nickserv/update.h5
-rw-r--r--include/modules/operserv/defcon.h5
-rw-r--r--include/modules/operserv/dns.h15
-rw-r--r--include/modules/operserv/forbid.h12
-rw-r--r--include/modules/operserv/ignore.h13
-rw-r--r--include/modules/operserv/info.h8
-rw-r--r--include/modules/operserv/news.h19
-rw-r--r--include/modules/operserv/session.h14
-rw-r--r--include/modules/redis.h4
-rw-r--r--include/modules/sasl.h75
-rw-r--r--include/modules/sql.h12
-rw-r--r--include/modules/ssl.h4
-rw-r--r--include/modules/xmlrpc.h4
-rw-r--r--include/opertype.h30
-rw-r--r--include/protocol.h4
-rw-r--r--include/serialize.h426
-rw-r--r--include/service.h162
-rw-r--r--include/services.h5
-rw-r--r--include/users.h2
-rw-r--r--include/xline.h53
-rw-r--r--modules/CMakeLists.txt57
-rw-r--r--modules/botserv/assign.cpp4
-rw-r--r--modules/botserv/autoassign.cpp1
-rw-r--r--modules/botserv/badwords.cpp33
-rw-r--r--modules/botserv/bot.cpp13
-rw-r--r--modules/botserv/botlist.cpp2
-rw-r--r--modules/botserv/info.cpp12
-rw-r--r--modules/botserv/kick.cpp159
-rw-r--r--modules/botserv/main/botserv.cpp29
-rw-r--r--modules/botserv/set.cpp3
-rw-r--r--modules/chanserv/CMakeLists.txt2
-rw-r--r--modules/chanserv/access.cpp (renamed from modules/chanserv/cs_access.old)141
-rw-r--r--modules/chanserv/akick.cpp43
-rw-r--r--modules/chanserv/clone.cpp11
-rw-r--r--modules/chanserv/drop.cpp10
-rw-r--r--modules/chanserv/entrymsg.cpp31
-rw-r--r--modules/chanserv/flags.cpp (renamed from modules/chanserv/cs_flags.old)51
-rw-r--r--modules/chanserv/info.cpp10
-rw-r--r--modules/chanserv/list.cpp9
-rw-r--r--modules/chanserv/log.cpp48
-rw-r--r--modules/chanserv/main/chanaccess.cpp58
-rw-r--r--modules/chanserv/main/chanaccesstype.h19
-rw-r--r--modules/chanserv/main/channel.cpp68
-rw-r--r--modules/chanserv/main/channel.h17
-rw-r--r--modules/chanserv/main/channeltype.cpp32
-rw-r--r--modules/chanserv/main/channeltype.h28
-rw-r--r--modules/chanserv/main/chanserv.cpp70
-rw-r--r--modules/chanserv/main/level.h6
-rw-r--r--modules/chanserv/main/leveltype.h8
-rw-r--r--modules/chanserv/main/mode.h5
-rw-r--r--modules/chanserv/main/modetype.h8
-rw-r--r--modules/chanserv/mode.cpp66
-rw-r--r--modules/chanserv/register.cpp15
-rw-r--r--modules/chanserv/seen.cpp1
-rw-r--r--modules/chanserv/set.cpp91
-rw-r--r--modules/chanserv/set_misc.cpp22
-rw-r--r--modules/chanserv/statusupdate.cpp8
-rw-r--r--modules/chanserv/suspend.cpp57
-rw-r--r--modules/chanserv/topic.cpp13
-rw-r--r--modules/chanserv/unban.cpp2
-rw-r--r--modules/chanserv/xop.cpp (renamed from modules/chanserv/cs_xop.old)55
-rw-r--r--modules/database/CMakeLists.txt1
-rw-r--r--modules/database/flatfile.cpp7
-rw-r--r--modules/database/old.cpp140
-rw-r--r--modules/database/redis.cpp28
-rw-r--r--modules/database/sql.cpp100
-rw-r--r--modules/dns.cpp3
-rw-r--r--modules/dnsbl.cpp17
-rw-r--r--modules/encryption/bcrypt.cpp2
-rw-r--r--modules/encryption/md5.cpp2
-rw-r--r--modules/encryption/none.cpp3
-rw-r--r--modules/encryption/old.cpp13
-rw-r--r--modules/encryption/sha1.cpp2
-rw-r--r--modules/encryption/sha256.cpp2
-rw-r--r--modules/extra/ldap_authentication.cpp2
-rw-r--r--modules/extra/mysql.cpp5
-rw-r--r--modules/extra/sasl_dh-aes.cpp2
-rw-r--r--modules/extra/sasl_dh-blowfish.cpp2
-rw-r--r--modules/extra/sql_authentication.cpp2
-rw-r--r--modules/extra/stats/chanstats.cpp4
-rw-r--r--modules/fantasy.cpp21
-rw-r--r--modules/global/global.cpp6
-rw-r--r--modules/global/main/global.cpp4
-rw-r--r--modules/greet.cpp9
-rw-r--r--modules/help.cpp16
-rw-r--r--modules/helpchan.cpp1
-rw-r--r--modules/hostserv/del.cpp20
-rw-r--r--modules/hostserv/group.cpp6
-rw-r--r--modules/hostserv/list.cpp2
-rw-r--r--modules/hostserv/main/hostserv.cpp5
-rw-r--r--modules/hostserv/request.cpp99
-rw-r--r--modules/hostserv/set.cpp6
-rw-r--r--modules/httpd.cpp8
-rw-r--r--modules/memoserv/cancel.cpp5
-rw-r--r--modules/memoserv/del.cpp9
-rw-r--r--modules/memoserv/ignore.cpp4
-rw-r--r--modules/memoserv/main/ignore.h5
-rw-r--r--modules/memoserv/main/ignoretype.cpp6
-rw-r--r--modules/memoserv/main/memo.h9
-rw-r--r--modules/memoserv/main/memoinfo.cpp4
-rw-r--r--modules/memoserv/main/memoinfo.h5
-rw-r--r--modules/memoserv/main/memoinfotype.cpp6
-rw-r--r--modules/memoserv/main/memoserv.cpp49
-rw-r--r--modules/memoserv/main/memotype.cpp14
-rw-r--r--modules/memoserv/rsend.cpp3
-rw-r--r--modules/memoserv/set.cpp10
-rw-r--r--modules/nickserv/access.cpp31
-rw-r--r--modules/nickserv/ajoin.cpp28
-rw-r--r--modules/nickserv/alist.cpp2
-rw-r--r--modules/nickserv/cert.cpp33
-rw-r--r--modules/nickserv/drop.cpp10
-rw-r--r--modules/nickserv/group.cpp44
-rw-r--r--modules/nickserv/identify.cpp6
-rw-r--r--modules/nickserv/info.cpp23
-rw-r--r--modules/nickserv/list.cpp7
-rw-r--r--modules/nickserv/logout.cpp3
-rw-r--r--modules/nickserv/main/account.cpp10
-rw-r--r--modules/nickserv/main/account.h4
-rw-r--r--modules/nickserv/main/accounttype.cpp13
-rw-r--r--modules/nickserv/main/identifyrequest.cpp11
-rw-r--r--modules/nickserv/main/identifyrequest.h1
-rw-r--r--modules/nickserv/main/mode.h5
-rw-r--r--modules/nickserv/main/modetype.h6
-rw-r--r--modules/nickserv/main/nick.cpp8
-rw-r--r--modules/nickserv/main/nick.h8
-rw-r--r--modules/nickserv/main/nickserv.cpp67
-rw-r--r--modules/nickserv/main/nicktype.cpp28
-rw-r--r--modules/nickserv/maxemail.cpp7
-rw-r--r--modules/nickserv/recover.cpp8
-rw-r--r--modules/nickserv/register.cpp45
-rw-r--r--modules/nickserv/resetpass.cpp3
-rw-r--r--modules/nickserv/set.cpp71
-rw-r--r--modules/nickserv/set_misc.cpp22
-rw-r--r--modules/nickserv/suspend.cpp57
-rw-r--r--modules/nickserv/update.cpp10
-rw-r--r--modules/operserv/akill.cpp25
-rw-r--r--modules/operserv/chankill.cpp13
-rw-r--r--modules/operserv/defcon.cpp59
-rw-r--r--modules/operserv/dns.cpp187
-rw-r--r--modules/operserv/forbid.cpp49
-rw-r--r--modules/operserv/ignore.cpp28
-rw-r--r--modules/operserv/info.cpp28
-rw-r--r--modules/operserv/login.cpp3
-rw-r--r--modules/operserv/logsearch.cpp2
-rw-r--r--modules/operserv/main/operserv.cpp46
-rw-r--r--modules/operserv/modinfo.cpp15
-rw-r--r--modules/operserv/module.cpp2
-rw-r--r--modules/operserv/news.cpp34
-rw-r--r--modules/operserv/noop.cpp3
-rw-r--r--modules/operserv/oper.cpp2
-rw-r--r--modules/operserv/reload.cpp2
-rw-r--r--modules/operserv/session.cpp67
-rw-r--r--modules/operserv/set.cpp2
-rw-r--r--modules/operserv/stats.cpp108
-rw-r--r--modules/operserv/sxline.cpp30
-rw-r--r--modules/protocol/bahamut.cpp9
-rw-r--r--modules/protocol/charybdis.cpp2
-rw-r--r--modules/protocol/hybrid.cpp23
-rw-r--r--modules/protocol/inspircd20.cpp34
-rw-r--r--modules/protocol/ngircd.cpp3
-rw-r--r--modules/protocol/plexus.cpp11
-rw-r--r--modules/protocol/ratbox.cpp8
-rw-r--r--modules/protocol/unreal.cpp35
-rw-r--r--modules/proxyscan.cpp380
-rw-r--r--modules/redis.cpp7
-rw-r--r--modules/sasl.cpp85
-rw-r--r--modules/webcpanel/pages/chanserv/access.cpp6
-rw-r--r--modules/webcpanel/pages/chanserv/drop.cpp2
-rw-r--r--modules/webcpanel/pages/chanserv/utils.cpp2
-rw-r--r--modules/webcpanel/pages/hostserv/request.cpp2
-rw-r--r--modules/webcpanel/pages/index.cpp2
-rw-r--r--modules/webcpanel/pages/logout.cpp4
-rw-r--r--modules/webcpanel/pages/nickserv/access.cpp2
-rw-r--r--modules/webcpanel/pages/nickserv/alist.cpp2
-rw-r--r--modules/webcpanel/pages/nickserv/cert.cpp5
-rw-r--r--modules/webcpanel/pages/nickserv/info.cpp2
-rw-r--r--modules/webcpanel/pages/operserv/akill.cpp5
-rw-r--r--modules/webcpanel/pages/operserv/akill.h2
-rw-r--r--modules/webcpanel/webcpanel.cpp6
-rw-r--r--modules/webcpanel/webcpanel.h6
-rw-r--r--modules/xmlrpc.cpp6
-rw-r--r--modules/xmlrpc_main.cpp9
-rw-r--r--src/accessgroup.cpp106
-rw-r--r--src/base.cpp3
-rw-r--r--src/bots.cpp38
-rw-r--r--src/channels.cpp33
-rw-r--r--src/command.cpp17
-rw-r--r--src/config.cpp29
-rw-r--r--src/event.cpp101
-rw-r--r--src/extensible.cpp6
-rw-r--r--src/init.cpp10
-rw-r--r--src/logger.cpp20
-rw-r--r--src/main.cpp8
-rw-r--r--src/messages.cpp30
-rw-r--r--src/misc.cpp11
-rw-r--r--src/modes.cpp19
-rw-r--r--src/modulemanager.cpp8
-rw-r--r--src/opertype.cpp6
-rw-r--r--src/process.cpp7
-rw-r--r--src/serialize.cpp180
-rw-r--r--src/servers.cpp10
-rw-r--r--src/service.cpp106
-rw-r--r--src/service_manager.cpp144
-rw-r--r--src/uplink.cpp6
-rw-r--r--src/users.cpp57
-rw-r--r--src/xline.cpp70
252 files changed, 3885 insertions, 3380 deletions
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
@@ -155,11 +155,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
* modes etc. prior to services deopping them.
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
@@ -429,88 +429,6 @@ module { name = "help" }
}
/*
- * 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
*
* Some IRCds allow "SASL" authentication to let users identify to Services
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<ChanAccess *>
+{
+ 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<BotInfo>
Serialize::Field<BotInfo, time_t> created;
Serialize::Field<BotInfo, bool> operonly;
- BotInfoType() : Serialize::Type<BotInfo>(nullptr, "BotInfo")
- , nick(this, "nick")
- , user(this, "user")
- , host(this, "host")
- , realname(this, "realname")
- , created(this, "created")
- , operonly(this, "operonly")
+ BotInfoType() : Serialize::Type<BotInfo>(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("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<Usermode> Usermodes;
std::vector<Channelmode> Channelmodes;
- unsigned char CaseMapUpper[256], CaseMapLower[256];
+ unsigned char CaseMapUpper[256] = { 0 }, CaseMapLower[256] = { 0 };
/* module configuration blocks */
std::map<Anope::string, Block *> 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 <Adam@anope.org>
+ *
* 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<EventHandler, Func, EventReturn, Args...>
}
};
-template<typename T>
-struct EventName;
-
template<typename EventHandler>
class EventHook;
template<typename EventHandler>
-class EventHandlers : public Service
+class EventDispatcher
{
- std::vector<EventHandler *> handlers;
- friend class EventHook<EventHandler>;
+ static_assert(std::is_base_of<Events, EventHandler>::value, "");
+
+ ServiceReferenceList<EventHandler> handlers;
public:
- EventHandlers(Module *o) : Service(o, "EventHandlers", EventName<EventHandler>::name)
- {
- }
+ EventDispatcher(const Anope::string &name) : handlers(name) { }
template<typename Func, typename... Args>
- auto operator()(Func func, Args&&... args) -> decltype(((static_cast<EventHandler*>(nullptr))->*func)(args...))
+ auto Dispatch(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)...);
+ const std::vector<EventHandler *> h = this->handlers.GetServices();
+ return Caller<EventHandler, Func, decltype(((static_cast<EventHandler*>(nullptr))->*func)(args...)), Args...>()(h, func, std::forward<Args>(args)...);
}
};
template<typename EventHandler>
-class EventHandlersReference
+class EventHook : public EventHandler
{
- ServiceReference<EventHandlers<EventHandler>> ref;
- public:
- EventHandlersReference() : ref("EventHandlers", EventName<EventHandler>::name) { }
+ static_assert(std::is_base_of<Events, EventHandler>::value, "");
- explicit operator bool()
+ public:
+ enum class Priority
{
- return !!ref;
+ FIRST,
+ LAST
}
+ priority;
- template<typename Func, typename... Args>
- auto operator()(Func func, Args&&... args) -> decltype(((static_cast<EventHandler*>(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>(args)...);
+#warning "priority doesnt work"
}
};
-template<typename EventHandler>
-class EventHook : public EventHandler
+class EventManager
{
+ Anope::hash_map<EventDispatcher<Events> *> cache;
- struct ServiceReferenceListener : ServiceReference<EventHandlers<EventHandler>>
+ template<typename T>
+ EventDispatcher<T> *GetDispatcher(const Anope::string &name)
{
- EventHook<EventHandler> *eh;
+ auto it = cache.find(name);
+ if (it != cache.end())
+ return reinterpret_cast<EventDispatcher<T> *>(it->second);
- ServiceReferenceListener(EventHook<EventHandler> *t, const Anope::string &sname) : ServiceReference<EventHandlers<EventHandler>>("EventHandlers", sname), eh(t)
- {
- }
+ auto dispatcher = new EventDispatcher<T>(name);
+ cache[name] = reinterpret_cast<EventDispatcher<Events> *>(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<Type*>(nullptr))->*func)(args...))
{
- FIRST,
- LAST
- }
- priority;
+ static_assert(std::is_base_of<Events, Type>::value, "");
- EventHook(Priority p = Priority::LAST) : handlers(this, EventName<EventHandler>::name), priority(p)
- {
- handlers.Check();
+ EventDispatcher<Type> *dispatcher = GetDispatcher<Type>(Type::NAME);
+ return dispatcher->Dispatch(func, std::forward<Args>(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<PreUserKicked> 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<UserKicked> 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<PreBotAssign> 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<BotAssign> 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<BotUnAssign> 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<UserConnect> 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<NewServer> 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<UserNickChange> 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<Anope::string> &params) anope_abstract;
};
- extern CoreExport EventHandlers<PreCommand> 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<Anope::string> &params) anope_abstract;
};
- extern CoreExport EventHandlers<PostCommand> 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<SaveDatabase> 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<LoadDatabase> 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<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;
+ 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<CreateBot> OnCreateBot;
struct CoreExport DelBot : Events
{
+ static constexpr const char *NAME = "delbot";
+
+ using Events::Events;
+
virtual void OnDelBot(ServiceBot *bi) anope_abstract;
};
- extern CoreExport EventHandlers<DelBot> 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<PrePartChannel> 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<PartChannel> 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<LeaveChannel> 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<JoinChannel> 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<TopicUpdated> 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<PreServerConnect> 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<ServerConnect> 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<PreUplinkSync> 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<ServerDisconnect> 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<Restart> 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<Shutdown> 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<AddXLine> 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<DelXLine> 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<IsServicesOperEvent> 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<ServerQuit> 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<UserQuit> 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<PreUserLogoff> OnPreUserLogoff;
struct CoreExport PostUserLogoff : Events
{
+ static constexpr const char *NAME = "postuserlogoff";
+
+ using Events::Events;
+
virtual void OnPostUserLogoff(User *u) anope_abstract;
};
- extern CoreExport EventHandlers<PostUserLogoff> 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<AccessDel> 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<AccessAdd> 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<AccessClear> 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<ChanRegistered> 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<CreateChan> 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<DelChan> 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<ChannelCreate> 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<ChannelDelete> 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<CheckKick> 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<CheckPriv> 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<GroupCheckPriv> 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<NickIdentify> 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<UserLogin> 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<NickLogout> 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<DelNick> 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<NickCoreCreate> 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<DelCore> 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<ChangeCoreDisplay> 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<NickClearAccess> 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<NickAddAccess> 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<NickEraseAccess> 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<CheckAuthentication> 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<Fingerprint> 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<UserAway> 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<Invite> 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<SetVhost> 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<SetDisplayedHost> 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 &param) anope_abstract;
};
- extern CoreExport EventHandlers<ChannelModeSet> 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 &param) anope_abstract;
};
- extern CoreExport EventHandlers<ChannelModeUnset> 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<UserModeSet> 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<UserModeUnset> 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<ChannelModeAdd> 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<UserModeAdd> 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<ModuleLoad> 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<ModuleUnload> 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<ServerSync> 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<UplinkSync> 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<BotPrivmsg> 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<BotNotice> 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<Privmsg> 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<Log> 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<LogMessage> 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<Channel> &c) anope_abstract;
};
- extern CoreExport EventHandlers<CheckModes> 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<ChannelSync> 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<SetCorrectModes> 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<Anope::string> &param) anope_abstract;
};
- extern CoreExport EventHandlers<Message> 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<CanSet> OnCanSet;
struct CoreExport CheckDelete : Events
{
+ static constexpr const char *NAME = "checkdelete";
+
+ using Events::Events;
+
virtual EventReturn OnCheckDelete(Channel *) anope_abstract;
};
- extern CoreExport EventHandlers<CheckDelete> 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<ExpireTick> OnExpireTick;
struct CoreExport SerializeEvents : Events
{
+ static constexpr const char *NAME = "serialize";
+
+ using Events::Events;
+
virtual EventReturn OnSerializeList(Serialize::TypeBase *type, std::vector<Serialize::ID> &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<SerializeEvents> OnSerialize;
}
-
-template<> struct EventName<Event::PreUserKicked> { static constexpr const char *const name = "OnPreUserKicked"; };
-template<> struct EventName<Event::UserKicked> { static constexpr const char *const name = "OnUserKicked"; };
-template<> struct EventName<Event::PreBotAssign> { static constexpr const char *const name = "OnPreBotAssign"; };
-template<> struct EventName<Event::BotAssign> { static constexpr const char *const name = "OnBotAssign"; };
-template<> struct EventName<Event::BotUnAssign> { static constexpr const char *const name = "OnBotUnAssign"; };
-template<> struct EventName<Event::UserConnect> { static constexpr const char *const name = "OnUserConnect"; };
-template<> struct EventName<Event::NewServer> { static constexpr const char *const name = "OnNewServer"; };
-template<> struct EventName<Event::UserNickChange> { static constexpr const char *const name = "OnUserNickChange"; };
-template<> struct EventName<Event::PreCommand> { static constexpr const char *const name = "OnPreCommand"; };
-template<> struct EventName<Event::PostCommand> { static constexpr const char *const name = "OnPostCommand"; };
-template<> struct EventName<Event::SaveDatabase> { static constexpr const char *const name = "OnSaveDatabase"; };
-template<> struct EventName<Event::LoadDatabase> { static constexpr const char *const name = "OnLoadDatabase"; };
-template<> struct EventName<Event::Encrypt> { static constexpr const char *const name = "OnEncrypt"; };
-template<> struct EventName<Event::Decrypt> { static constexpr const char *const name = "OnDecrypt"; };
-template<> struct EventName<Event::CreateBot> { static constexpr const char *const name = "OnCreateBot"; };
-template<> struct EventName<Event::DelBot> { static constexpr const char *const name = "OnDelBot"; };
-template<> struct EventName<Event::PrePartChannel> { static constexpr const char *const name = "OnPrePartChannel"; };
-template<> struct EventName<Event::PartChannel> { static constexpr const char *const name = "OnPartChannel"; };
-template<> struct EventName<Event::LeaveChannel> { static constexpr const char *const name = "OnLeaveChannel"; };
-template<> struct EventName<Event::JoinChannel> { static constexpr const char *const name = "OnJoinChannel"; };
-template<> struct EventName<Event::TopicUpdated> { static constexpr const char *const name = "OnTopicUpdated"; };
-template<> struct EventName<Event::PreServerConnect> { static constexpr const char *const name = "OnPreServerConnect"; };
-template<> struct EventName<Event::ServerConnect> { static constexpr const char *const name = "OnServerConnect"; };
-template<> struct EventName<Event::PreUplinkSync> { static constexpr const char *const name = "OnPreUplinkSync"; };
-template<> struct EventName<Event::ServerDisconnect> { static constexpr const char *const name = "OnServerDisconnect"; };
-template<> struct EventName<Event::Restart> { static constexpr const char *const name = "OnRestart"; };
-template<> struct EventName<Event::Shutdown> { static constexpr const char *const name = "OnShutdown"; };
-template<> struct EventName<Event::AddXLine> { static constexpr const char *const name = "OnAddXLine"; };
-template<> struct EventName<Event::DelXLine> { static constexpr const char *const name = "OnDelXLine"; };
-template<> struct EventName<Event::IsServicesOperEvent> { static constexpr const char *const name = "OnIsServicesOper"; };
-template<> struct EventName<Event::ServerQuit> { static constexpr const char *const name = "OnServerQuit"; };
-template<> struct EventName<Event::UserQuit> { static constexpr const char *const name = "OnUserQuit"; };
-template<> struct EventName<Event::PreUserLogoff> { static constexpr const char *const name = "OnPreUserLogoff"; };
-template<> struct EventName<Event::PostUserLogoff> { static constexpr const char *const name = "OnPostUserLogoff"; };
-template<> struct EventName<Event::AccessDel> { static constexpr const char *const name = "OnAccessDel"; };
-template<> struct EventName<Event::AccessAdd> { static constexpr const char *const name = "OnAccessAdd"; };
-template<> struct EventName<Event::AccessClear> { static constexpr const char *const name = "OnAccessClear"; };
-template<> struct EventName<Event::ChanRegistered> { static constexpr const char *const name = "OnChanRegistered"; };
-template<> struct EventName<Event::CreateChan> { static constexpr const char *const name = "OnCreateChan"; };
-template<> struct EventName<Event::DelChan> { static constexpr const char *const name = "OnDelChan"; };
-template<> struct EventName<Event::ChannelCreate> { static constexpr const char *const name = "OnChannelCreate"; };
-template<> struct EventName<Event::ChannelDelete> { static constexpr const char *const name = "OnChannelDelete"; };
-template<> struct EventName<Event::CheckKick> { static constexpr const char *const name = "OnCheckKick"; };
-template<> struct EventName<Event::CheckPriv> { static constexpr const char *const name = "OnCheckPriv"; };
-template<> struct EventName<Event::GroupCheckPriv> { static constexpr const char *const name = "OnGroupCheckPriv"; };
-template<> struct EventName<Event::NickIdentify> { static constexpr const char *const name = "OnNickIdentify"; };
-template<> struct EventName<Event::UserLogin> { static constexpr const char *const name = "OnUserLogin"; };
-template<> struct EventName<Event::NickLogout> { static constexpr const char *const name = "OnNickLogout"; };
-template<> struct EventName<Event::DelNick> { static constexpr const char *const name = "OnDelNick"; };
-template<> struct EventName<Event::NickCoreCreate> { static constexpr const char *const name = "OnNickCoreCreate"; };
-template<> struct EventName<Event::DelCore> { static constexpr const char *const name = "OnDelCore"; };
-template<> struct EventName<Event::ChangeCoreDisplay> { static constexpr const char *const name = "OnChangeCoreDisplay"; };
-template<> struct EventName<Event::NickClearAccess> { static constexpr const char *const name = "OnNickClearAccess"; };
-template<> struct EventName<Event::NickAddAccess> { static constexpr const char *const name = "OnNickAddAccess"; };
-template<> struct EventName<Event::NickEraseAccess> { static constexpr const char *const name = "OnNickEraseAccess"; };
-template<> struct EventName<Event::CheckAuthentication> { static constexpr const char *const name = "OnCheckAuthentication"; };
-template<> struct EventName<Event::Fingerprint> { static constexpr const char *const name = "OnFingerprint"; };
-template<> struct EventName<Event::UserAway> { static constexpr const char *const name = "OnUserAway"; };
-template<> struct EventName<Event::Invite> { static constexpr const char *const name = "OnInvite"; };
-template<> struct EventName<Event::SetVhost> { static constexpr const char *const name = "OnSetVhost"; };
-template<> struct EventName<Event::SetDisplayedHost> { static constexpr const char *const name = "OnSetDisplayedHost"; };
-template<> struct EventName<Event::ChannelModeSet> { static constexpr const char *const name = "OnChannelModeSet"; };
-template<> struct EventName<Event::ChannelModeUnset> { static constexpr const char *const name = "OnChannelModeUnset"; };
-template<> struct EventName<Event::UserModeSet> { static constexpr const char *const name = "OnUserModeSet"; };
-template<> struct EventName<Event::UserModeUnset> { static constexpr const char *const name = "OnUserModeUnset"; };
-template<> struct EventName<Event::ChannelModeAdd> { static constexpr const char *const name = "OnChannelModeAdd"; };
-template<> struct EventName<Event::UserModeAdd> { static constexpr const char *const name = "OnUserModeAdd"; };
-template<> struct EventName<Event::ModuleLoad> { static constexpr const char *const name = "OnModuleLoad"; };
-template<> struct EventName<Event::ModuleUnload> { static constexpr const char *const name = "OnModuleUnload"; };
-template<> struct EventName<Event::ServerSync> { static constexpr const char *const name = "OnServerSync"; };
-template<> struct EventName<Event::UplinkSync> { static constexpr const char *const name = "OnUplinkSync"; };
-template<> struct EventName<Event::BotPrivmsg> { static constexpr const char *const name = "OnBotPrivmsg"; };
-template<> struct EventName<Event::BotNotice> { static constexpr const char *const name = "OnBotNotice"; };
-template<> struct EventName<Event::Privmsg> { static constexpr const char *const name = "OnPrivmsg"; };
-template<> struct EventName<Event::Log> { static constexpr const char *const name = "OnLog"; };
-template<> struct EventName<Event::LogMessage> { static constexpr const char *const name = "OnLogMessage"; };
-template<> struct EventName<Event::CheckModes> { static constexpr const char *const name = "OnCheckModes"; };
-template<> struct EventName<Event::ChannelSync> { static constexpr const char *const name = "OnChannelSync"; };
-template<> struct EventName<Event::SetCorrectModes> { static constexpr const char *const name = "OnSetCorrectModes"; };
-template<> struct EventName<Event::Message> { static constexpr const char *const name = "OnMessage"; };
-template<> struct EventName<Event::CanSet> { static constexpr const char *const name = "OnCanSet"; };
-template<> struct EventName<Event::CheckDelete> { static constexpr const char *const name = "OnCheckDelete"; };
-template<> struct EventName<Event::ExpireTick> { static constexpr const char *const name = "OnExpireTick"; };
-template<> struct EventName<Event::SerializeEvents> { static constexpr const char *const name = "OnSerialize"; };
-
diff --git a/include/extensible.h b/include/extensible.h
index 4faff818b..35e051173 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -22,10 +22,11 @@ class CoreExport ExtensibleBase : public Service
ExtensibleBase(Module *m, const Anope::string &n);
ExtensibleBase(Module *m, const Anope::string &t, const Anope::string &n);
- ~ExtensibleBase();
public:
virtual void Unset(Extensible *obj) anope_abstract;
+
+ static constexpr const char *NAME = "Extensible";
};
class CoreExport Extensible
@@ -40,7 +41,7 @@ class CoreExport Extensible
template<typename T> T* Extend(const Anope::string &name, const T &what);
- template<typename T> void ShrinkOK(const Anope::string &name);
+ template<typename T> void Shrink(const Anope::string &name);
};
template<typename T>
@@ -116,8 +117,7 @@ class ExtensibleItem : public ExtensibleBase
template<typename T>
struct ExtensibleRef : ServiceReference<ExtensibleItem<T>>
{
- ExtensibleRef(const Anope::string &n) : ServiceReference<ExtensibleItem<T>>("Extensible", n) { }
- ExtensibleRef(const Anope::string &t, const Anope::string &n) : ServiceReference<ExtensibleItem<T>>(t, n) { }
+ ExtensibleRef(const Anope::string &n) : ServiceReference<ExtensibleItem<T>>(n) { }
};
template<typename T>
@@ -146,8 +146,7 @@ T* Extensible::Extend(const Anope::string &name, const T &what)
}
template<typename T>
-//XXX
-void Extensible::ShrinkOK(const Anope::string &name)
+void Extensible::Shrink(const Anope::string &name)
{
ExtensibleRef<T> ref(name);
if (ref)
diff --git a/include/module.h b/include/module.h
index bb7f1c815..2a5dab6e2 100644
--- a/include/module.h
+++ b/include/module.h
@@ -45,3 +45,4 @@
#include "modules/nickserv.h"
#include "modules/botserv.h"
#include "modules/memoserv.h"
+#include "accessgroup.h"
diff --git a/include/modules.h b/include/modules.h
index e885a800e..e5539a27c 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -79,7 +79,7 @@ template<class ModuleClass> void ModuleInfo(ModuleDef *moddef) { }
{ \
delete def; \
} \
- static ModuleVersionC ModuleVersion() \
+ static ModuleVersionC AnopeModuleVersion() \
{ \
ModuleVersionC ver; \
ver.version_major = VERSION_MAJOR; \
@@ -87,12 +87,13 @@ template<class ModuleClass> void ModuleInfo(ModuleDef *moddef) { }
ver.version_patch = VERSION_PATCH; \
return ver; \
} \
- extern "C" DllExport struct AnopeModule AnopeMod = \
+ extern "C" DllExport struct AnopeModule AnopeMod; \
+ struct AnopeModule AnopeMod = \
{ \
ANOPE_MODAPI_VER, \
CreateModuleDef, \
DeleteModuleDef, \
- ModuleVersion \
+ AnopeModuleVersion \
};
enum ModuleReturn
diff --git a/include/modules/botserv.h b/include/modules/botserv.h
index 09183b53a..d19dea2ac 100644
--- a/include/modules/botserv.h
+++ b/include/modules/botserv.h
@@ -18,5 +18,4 @@ namespace BotServ
}
};
- static ServiceReference<BotServService> service("BotServService", "BotServ");
}
diff --git a/include/modules/botserv/badwords.h b/include/modules/botserv/badwords.h
index 87986ee62..6f2205a97 100644
--- a/include/modules/botserv/badwords.h
+++ b/include/modules/botserv/badwords.h
@@ -31,6 +31,8 @@ class BadWord : public Serialize::Object
protected:
using Serialize::Object::Object;
public:
+ static constexpr const char *NAME = "badword";
+
virtual ~BadWord() = default;
virtual ChanServ::Channel *GetChannel() anope_abstract;
@@ -43,11 +45,12 @@ class BadWord : public Serialize::Object
virtual void SetType(const BadWordType &) anope_abstract;
};
-static Serialize::TypeReference<BadWord> badword("BadWord");
-
-struct BadWords : public Service
+class BadWords : public Service
{
- BadWords(Module *me) : Service(me, "BadWords", "badwords") { }
+ public:
+ static constexpr const char *NAME = "badwords";
+
+ BadWords(Module *me) : Service(me, NAME) { }
/** Add a badword to the badword list
* @param word The badword
@@ -79,12 +82,14 @@ struct BadWords : public Service
virtual void ClearBadWords(ChanServ::Channel *) anope_abstract;
};
-static ServiceReference<BadWords> badwords("BadWords", "badwords");
-
namespace Event
{
struct CoreExport BadWordEvents : Events
{
+ static constexpr const char *NAME = "badwords";
+
+ using Events::Events;
+
/** Called before a badword is added to the badword list
* @param ci The channel
* @param bw The badword
@@ -99,4 +104,3 @@ namespace Event
};
}
-template<> struct EventName<Event::BadWordEvents> { static constexpr const char *const name = "Badwords"; };
diff --git a/include/modules/botserv/bot.h b/include/modules/botserv/bot.h
index fe6534309..e07b75f9a 100644
--- a/include/modules/botserv/bot.h
+++ b/include/modules/botserv/bot.h
@@ -10,6 +10,10 @@ namespace Event
{
struct CoreExport BotCreate : Events
{
+ static constexpr const char *NAME = "botcreate";
+
+ using Events::Events;
+
/** Called when a new bot is made
* @param bi The bot
*/
@@ -18,6 +22,10 @@ namespace Event
struct CoreExport BotChange : Events
{
+ static constexpr const char *NAME = "botchange";
+
+ using Events::Events;
+
/** Called when a bot is changed
* @param bi The bot
*/
@@ -26,6 +34,10 @@ namespace Event
struct CoreExport BotDelete : Events
{
+ static constexpr const char *NAME = "botdelete";
+
+ using Events::Events;
+
/** Called when a bot is deleted
* @param bi The bot
*/
@@ -33,6 +45,3 @@ namespace Event
};
}
-template<> struct EventName<Event::BotCreate> { static constexpr const char *const name = "OnBotCreate"; };
-template<> struct EventName<Event::BotChange> { static constexpr const char *const name = "OnBotChange"; };
-template<> struct EventName<Event::BotDelete> { static constexpr const char *const name = "OnBotDelete"; };
diff --git a/include/modules/botserv/info.h b/include/modules/botserv/info.h
index 1ebd58c89..92bac8892 100644
--- a/include/modules/botserv/info.h
+++ b/include/modules/botserv/info.h
@@ -11,11 +11,13 @@ namespace Event
{
struct CoreExport ServiceBotEvent : Events
{
+ static constexpr const char *NAME = "servicebotevent";
+
+ using Events::Events;
+
/** Called when a user uses botserv/info on a bot or channel.
*/
virtual void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) anope_abstract;
};
- extern CoreExport EventHandlers<ServiceBotEvent> OnServiceBot;
}
-template<> struct EventName<Event::ServiceBotEvent> { static constexpr const char *const name = "OnServiceBot"; };
diff --git a/include/modules/botserv/kick.h b/include/modules/botserv/kick.h
index 1346d7427..4d0461739 100644
--- a/include/modules/botserv/kick.h
+++ b/include/modules/botserv/kick.h
@@ -1,14 +1,10 @@
/* BotServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
- *
- *
*/
class KickerData : public Serialize::Object
@@ -17,6 +13,8 @@ class KickerData : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "kickerdata";
+
virtual ChanServ::Channel *GetChannel() anope_abstract;
virtual void SetChannel(ChanServ::Channel *) anope_abstract;
@@ -102,15 +100,16 @@ class KickerData : public Serialize::Object
virtual void SetDontKickVoices(const bool &) anope_abstract;
};
-static Serialize::TypeReference<KickerData> kickerdata("KickerData");
-
inline KickerData *GetKickerData(ChanServ::Channel *ci)
{
- KickerData *kd = ci->GetRef<KickerData *>(kickerdata);
- if (!kd && kickerdata)
+ KickerData *kd = ci->GetRef<KickerData *>();
+ if (!kd)
{
- kd = kickerdata.Create();
- kd->SetChannel(ci);
+ kd = Serialize::New<KickerData *>();
+ if (kd != nullptr)
+ {
+ kd->SetChannel(ci);
+ }
}
return kd;
}
@@ -119,6 +118,10 @@ namespace Event
{
struct CoreExport BotBan : Events
{
+ static constexpr const char *NAME = "botban";
+
+ using Events::Events;
+
/** Called when a bot places a ban
* @param u User being banned
* @param ci Channel the ban is placed on
@@ -127,6 +130,3 @@ namespace Event
virtual void OnBotBan(User *u, ChanServ::Channel *ci, const Anope::string &mask) anope_abstract;
};
}
-
-template<> struct EventName<Event::BotBan> { static constexpr const char *const name = "OnBotBan"; };
-
diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h
index 35fc3c332..88a8ac3b9 100644
--- a/include/modules/chanserv.h
+++ b/include/modules/chanserv.h
@@ -90,6 +90,8 @@ namespace ChanServ
class Level : public Serialize::Object
{
public:
+ static constexpr const char *const NAME = "level";
+
using Serialize::Object::Object;
virtual Channel *GetChannel() anope_abstract;
@@ -102,11 +104,11 @@ namespace ChanServ
virtual void SetLevel(const int &) anope_abstract;
};
- static Serialize::TypeReference<Level> level("Level");
-
class Mode : public Serialize::Object
{
public:
+ static constexpr const char *const NAME = "mlockmode";
+
using Serialize::Object::Object;
virtual Channel *GetChannel() anope_abstract;
@@ -119,12 +121,12 @@ namespace ChanServ
virtual void SetParam(const Anope::string &) anope_abstract;
};
- static Serialize::TypeReference<Mode> mode("CSKeepMode");
-
class ChanServService : public Service
{
public:
- ChanServService(Module *m) : Service(m, "ChanServService", "ChanServ")
+ static constexpr const char *NAME = "chanserv";
+
+ ChanServService(Module *m) : Service(m, NAME)
{
}
@@ -142,7 +144,8 @@ namespace ChanServ
virtual std::vector<Privilege> &GetPrivileges() anope_abstract;
virtual void ClearPrivileges() anope_abstract;
};
- static ServiceReference<ChanServService> service("ChanServService", "ChanServ");
+
+ extern ChanServService *service;
inline Channel *Find(const Anope::string name)
{
@@ -153,22 +156,28 @@ namespace ChanServ
{
struct CoreExport PreChanExpire : Events
{
+ static constexpr const char *NAME = "prechanexpire";
+
+ using Events::Events;
+
/** Called before a channel expires
* @param ci The channel
* @param expire Set to true to allow the chan to expire
*/
virtual void OnPreChanExpire(Channel *ci, bool &expire) anope_abstract;
};
- static EventHandlersReference<PreChanExpire> OnPreChanExpire;
struct CoreExport ChanExpire : Events
{
+ static constexpr const char *NAME = "chanexpire";
+
+ using Events::Events;
+
/** Called before a channel expires
* @param ci The channel
*/
virtual void OnChanExpire(Channel *ci) anope_abstract;
};
- static EventHandlersReference<ChanExpire> OnChanExpire;
}
/* It matters that Base is here before Extensible (it is inherited by Serializable)
@@ -182,6 +191,8 @@ namespace ChanServ
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "channel";
+
virtual Anope::string GetName() anope_abstract;
virtual void SetName(const Anope::string &) anope_abstract;
@@ -247,6 +258,7 @@ namespace ChanServ
if (ChanServ)
return ChanServ;
+#warning "if(this)"
//XXX
// if (!BotListByNick->empty())
// return BotListByNick->begin()->second;
@@ -274,11 +286,6 @@ namespace ChanServ
*/
virtual unsigned GetAccessCount() /*const*/ anope_abstract;
- /** Get the number of access entries for this channel,
- * including those that are on other channels.
- */
- virtual unsigned GetDeepAccessCount() const anope_abstract;
-
/** Clear the entire channel access list
*
* Clears the entire access list by deleting every item and then clearing the vector.
@@ -350,8 +357,6 @@ namespace ChanServ
virtual MemoServ::MemoInfo *GetMemos() anope_abstract;
};
- static Serialize::TypeReference<Channel> channel("ChannelInfo");
-
enum
{
ACCESS_INVALID = -10000,
@@ -362,15 +367,14 @@ namespace ChanServ
class CoreExport ChanAccess : public Serialize::Object
{
public:
- typedef std::multimap<ChanAccess *, ChanAccess *> Set;
- /* shows the 'path' taken to determine if an access entry matches a user
- * .first are access entries checked
- * .second are access entries which match
- */
- typedef std::pair<Set, Set> Path;
+ static constexpr const char *const NAME = "access";
- ChanAccess(Serialize::TypeBase *type) : Serialize::Object(type) { }
- ChanAccess(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { }
+ Channel *channel = nullptr;
+ Serialize::Object *object = nullptr;
+ Anope::string creator, mask;
+ time_t last_seen = 0, created = 0;
+
+ using Serialize::Object::Object;
virtual Channel *GetChannel() anope_abstract;
virtual void SetChannel(Channel *ci) anope_abstract;
@@ -396,9 +400,8 @@ namespace ChanServ
/** Check if this access entry matches the given user or account
* @param u The user
* @param acc The account
- * @param p The path to the access object which matches will be put here
*/
- virtual bool Matches(const User *u, NickServ::Account *acc, Path &p) anope_abstract;
+ virtual bool Matches(const User *u, NickServ::Account *acc) anope_abstract;
/** Check if this access entry has the given privilege.
* @param name The privilege name
@@ -417,7 +420,7 @@ namespace ChanServ
virtual void AccessUnserialize(const Anope::string &data) anope_abstract;
/* Comparison operators to other Access entries */
- bool operator>(ChanAccess &other)
+ virtual bool operator>(ChanAccess &other)
{
const std::vector<Privilege> &privs = service->GetPrivileges();
for (unsigned i = privs.size(); i > 0; --i)
@@ -434,7 +437,7 @@ namespace ChanServ
return false;
}
- bool operator<(ChanAccess &other)
+ virtual bool operator<(ChanAccess &other)
{
const std::vector<Privilege> &privs = service->GetPrivileges();
for (unsigned i = privs.size(); i > 0; --i)
@@ -461,174 +464,5 @@ namespace ChanServ
return !(*this > other);
}
};
-
- static Serialize::TypeReference<ChanAccess> chanaccess("ChanAccess");
-
- /* 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<ChanAccess *>
- {
- public:
- /* Channel these access entries are on */
- ChanServ::Channel *ci;
- /* Path from these entries to other entries that they depend on */
- ChanAccess::Path path;
- /* Account these entries affect, if any */
- const NickServ::Account *nc;
- /* super_admin always gets all privs. founder is a special case where ci->founder == nc */
- bool super_admin, founder;
-
- AccessGroup()
- {
- this->ci = NULL;
- this->nc = NULL;
- this->super_admin = this->founder = false;
- }
-
- private:
- bool HasPriv(ChanAccess *access, const Anope::string &name)
- {
- EventReturn MOD_RESULT = ::Event::OnCheckPriv(&::Event::CheckPriv::OnCheckPriv, access, name);
- if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name))
- {
- typedef std::multimap<ChanAccess *, ChanAccess *> P;
- std::pair<P::const_iterator, P::const_iterator> it = this->path.second.equal_range(access);
- if (it.first != it.second)
- /* check all of the paths for this entry */
- for (; it.first != it.second; ++it.first)
- {
- ChanAccess *a = it.first->second;
- /* if only one path fully matches then we are ok */
- if (HasPriv(a, name))
- return true;
- }
- else
- /* entry is the end of a chain, all entries match, ok */
- return true;
- }
-
- /* entry does not match or none of the chains fully match */
- return false;
- }
-
- public:
- /** 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)
- {
- if (this->super_admin)
- return true;
- else if (!ci || ci->GetLevel(priv) == ACCESS_INVALID)
- return false;
-
- /* Privileges prefixed with auto are understood to be given
- * automatically. Sometimes founders want to not automatically
- * obtain privileges, so we will let them */
- bool auto_mode = !priv.find("AUTO");
-
- /* Only grant founder privilege if this isn't an auto mode or if they don't match any entries in this group */
- if ((!auto_mode || this->empty()) && this->founder)
- return true;
-
- EventReturn MOD_RESULT;
- MOD_RESULT = ::Event::OnGroupCheckPriv(&::Event::GroupCheckPriv::OnGroupCheckPriv, this, priv);
- if (MOD_RESULT != EVENT_CONTINUE)
- return MOD_RESULT == EVENT_ALLOW;
-
- for (unsigned i = this->size(); i > 0; --i)
- {
- ChanAccess *access = this->at(i - 1);
-
- if (HasPriv(access, priv))
- return true;
- }
-
- return false;
- }
-
- /** 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()
- {
- ChanAccess *highest = NULL;
- for (unsigned i = 0; i < this->size(); ++i)
- if (highest == NULL || *this->at(i) > *highest)
- highest = this->at(i);
- return highest;
- }
-
- /* Comparison operators to other AccessGroups */
- bool operator>(AccessGroup &other)
- {
- if (other.super_admin)
- return false;
- else if (this->super_admin)
- return true;
- else if (other.founder)
- return false;
- else if (this->founder)
- return true;
-
- const std::vector<Privilege> &privs = service->GetPrivileges();
- for (unsigned i = privs.size(); i > 0; --i)
- {
- bool this_p = this->HasPriv(privs[i - 1].name),
- other_p = other.HasPriv(privs[i - 1].name);
-
- if (!this_p && !other_p)
- continue;
-
- return this_p && !other_p;
- }
-
- return false;
- }
-
- bool operator<(AccessGroup &other)
- {
- if (this->super_admin)
- return false;
- else if (other.super_admin)
- return true;
- else if (this->founder)
- return false;
- else if (other.founder)
- return true;
-
- const std::vector<Privilege> &privs = service->GetPrivileges();
- for (unsigned i = privs.size(); i > 0; --i)
- {
- bool this_p = this->HasPriv(privs[i - 1].name),
- other_p = other.HasPriv(privs[i - 1].name);
-
- if (!this_p && !other_p)
- continue;
-
- return !this_p && other_p;
- }
-
- return false;
- }
-
- bool operator>=(AccessGroup &other)
- {
- return !(*this < other);
- }
-
- bool operator<=(AccessGroup &other)
- {
- return !(*this > other);
- }
- };
}
-template<> struct EventName<ChanServ::Event::PreChanExpire> { static constexpr const char *const name = "OnPreChanExpire"; };
-template<> struct EventName<ChanServ::Event::ChanExpire> { static constexpr const char *const name = "OnChanExpire"; };
diff --git a/include/modules/chanserv/access.h b/include/modules/chanserv/access.h
index 54eb3f353..35fad81d3 100644
--- a/include/modules/chanserv/access.h
+++ b/include/modules/chanserv/access.h
@@ -7,14 +7,16 @@
*
*/
-static Serialize::TypeReference<ChanServ::ChanAccess> accesschanaccess("AccessChanAccess");
-static Serialize::TypeReference<ChanServ::ChanAccess> flagschanaccess("FlagsChanAccess");
-static Serialize::TypeReference<ChanServ::ChanAccess> xopchanaccess("XOPChanAccess");
+#include "main/chanaccess.h"
namespace Event
{
struct CoreExport LevelChange : Events
{
+ static constexpr const char *NAME = "levelchange";
+
+ using Events::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
@@ -25,4 +27,36 @@ namespace Event
};
}
-template<> struct EventName<Event::LevelChange> { static constexpr const char *const name = "OnLevelChange"; };
+class AccessChanAccess : public ChanAccessImpl
+{
+ public:
+ static constexpr const char *NAME = "accesschanaccess";
+
+ using ChanAccessImpl::ChanAccessImpl;
+
+ virtual int GetLevel() anope_abstract;
+ virtual void SetLevel(const int &) anope_abstract;
+};
+
+class XOPChanAccess : public ChanAccessImpl
+{
+ public:
+ static constexpr const char *NAME = "xopchanaccess";
+
+ using ChanAccessImpl::ChanAccessImpl;
+
+ virtual const Anope::string &GetType() anope_abstract;
+ virtual void SetType(const Anope::string &) anope_abstract;
+};
+
+class FlagsChanAccess : public ChanAccessImpl
+{
+ public:
+ static constexpr const char *NAME = "flagschanaccess";
+
+ using ChanAccessImpl::ChanAccessImpl;
+
+ virtual const Anope::string &GetFlags() anope_abstract;
+ virtual void SetFlags(const Anope::string &) anope_abstract;
+};
+
diff --git a/include/modules/chanserv/akick.h b/include/modules/chanserv/akick.h
index 966dac15b..cc7f0aaec 100644
--- a/include/modules/chanserv/akick.h
+++ b/include/modules/chanserv/akick.h
@@ -1,6 +1,6 @@
/*
*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -15,6 +15,8 @@ class CoreExport AutoKick : public Serialize::Object
protected:
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "akick";
+
virtual ~AutoKick() = default;
virtual ChanServ::Channel *GetChannel() anope_abstract;
@@ -39,12 +41,14 @@ class CoreExport AutoKick : public Serialize::Object
virtual void SetLastUsed(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<AutoKick> autokick("AutoKick");
-
namespace Event
{
struct CoreExport Akick : Events
{
+ static constexpr const char *NAME = "akick";
+
+ using Events::Events;
+
/** Called after adding an akick to a channel
* @param source The source of the command
* @param ci The channel
@@ -61,4 +65,3 @@ namespace Event
};
}
-template<> struct EventName<Event::Akick> { static constexpr const char *const name = "Akick"; };
diff --git a/include/modules/chanserv/drop.h b/include/modules/chanserv/drop.h
index db231059b..50f2627c2 100644
--- a/include/modules/chanserv/drop.h
+++ b/include/modules/chanserv/drop.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport ChanDrop : Events
{
+ static constexpr const char *NAME = "chandrop";
+
+ using Events::Events;
+
/** Called right before a channel is dropped
* @param source The user dropping the channel
* @param ci The channel
@@ -19,4 +23,3 @@ namespace Event
};
}
-template<> struct EventName<Event::ChanDrop> { static constexpr const char *const name = "OnChanDrop"; };
diff --git a/include/modules/chanserv/entrymsg.h b/include/modules/chanserv/entrymsg.h
index b5804068f..452057509 100644
--- a/include/modules/chanserv/entrymsg.h
+++ b/include/modules/chanserv/entrymsg.h
@@ -1,5 +1,5 @@
/*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -12,6 +12,8 @@ class EntryMsg : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "entrymsg";
+
virtual ChanServ::Channel *GetChannel() anope_abstract;
virtual void SetChannel(ChanServ::Channel *) anope_abstract;
@@ -25,5 +27,4 @@ class EntryMsg : public Serialize::Object
virtual void SetWhen(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<EntryMsg> entrymsg("EntryMsg");
diff --git a/include/modules/chanserv/info.h b/include/modules/chanserv/info.h
index f80e3daf2..d487e3075 100644
--- a/include/modules/chanserv/info.h
+++ b/include/modules/chanserv/info.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport ChanInfo : Events
{
+ static constexpr const char *NAME = "chaninfo";
+
+ using Events::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
@@ -21,4 +25,3 @@ namespace Event
};
}
-template<> struct EventName<Event::ChanInfo> { static constexpr const char *const name = "OnChanInfo"; };
diff --git a/include/modules/chanserv/log.h b/include/modules/chanserv/log.h
index d940f5e87..b579a05ed 100644
--- a/include/modules/chanserv/log.h
+++ b/include/modules/chanserv/log.h
@@ -1,12 +1,10 @@
/* ChanServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
+ *
*/
class LogSetting : public Serialize::Object
@@ -15,6 +13,8 @@ class LogSetting : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "logsetting";
+
virtual ChanServ::Channel *GetChannel() anope_abstract;
virtual void SetChannel(ChanServ::Channel *) anope_abstract;
@@ -39,6 +39,3 @@ class LogSetting : public Serialize::Object
virtual time_t GetCreated() anope_abstract;
virtual void SetCreated(const time_t &) anope_abstract;
};
-
-static Serialize::TypeReference<LogSetting> logsetting("LogSetting");
-
diff --git a/modules/chanserv/main/chanaccess.h b/include/modules/chanserv/main/chanaccess.h
index bb65f79c5..7a297c405 100644
--- a/modules/chanserv/main/chanaccess.h
+++ b/include/modules/chanserv/main/chanaccess.h
@@ -1,3 +1,4 @@
+#pragma once
class ChanAccessImpl : public ChanServ::ChanAccess
{
@@ -26,5 +27,5 @@ class ChanAccessImpl : public ChanServ::ChanAccess
Anope::string Mask() override;
NickServ::Account *GetAccount() override;
- bool Matches(const User *u, NickServ::Account *acc, Path &p) override;
+ bool Matches(const User *u, NickServ::Account *acc) override;
};
diff --git a/include/modules/chanserv/mode.h b/include/modules/chanserv/mode.h
index 4c7965e2a..78b7d861f 100644
--- a/include/modules/chanserv/mode.h
+++ b/include/modules/chanserv/mode.h
@@ -1,12 +1,10 @@
/* ChanServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
+ *
*/
class ModeLock : public Serialize::Object
@@ -15,6 +13,8 @@ class ModeLock : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "modelock";
+
virtual ChanServ::Channel *GetChannel() anope_abstract;
virtual void SetChannel(ChanServ::Channel *) anope_abstract;
@@ -34,12 +34,12 @@ class ModeLock : public Serialize::Object
virtual void SetCreated(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<ModeLock> modelock("ModeLock");
-
class ModeLocks : public Service
{
public:
- ModeLocks(Module *me) : Service(me, "ModeLocks", "mlocks") { }
+ static constexpr const char *NAME = "mlocks";
+
+ ModeLocks(Module *me) : Service(me, NAME) { }
typedef std::vector<ModeLock *> ModeList;
@@ -98,12 +98,14 @@ class ModeLocks : public Service
virtual Anope::string GetMLockAsString(ChanServ::Channel *, bool complete) const anope_abstract;
};
-static ServiceReference<ModeLocks> mlocks("ModeLocks", "mlocks");
-
namespace Event
{
struct CoreExport MLockEvents : Events
{
+ static constexpr const char *NAME = "mlockevents";
+
+ using Events::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
@@ -119,5 +121,3 @@ namespace Event
virtual EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) anope_abstract;
};
}
-
-template<> struct EventName<Event::MLockEvents> { static constexpr const char *const name = "MLock"; };
diff --git a/include/modules/chanserv/set.h b/include/modules/chanserv/set.h
index a0e81c888..1c5de3227 100644
--- a/include/modules/chanserv/set.h
+++ b/include/modules/chanserv/set.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport SetChannelOption : Events
{
+ static constexpr const char *NAME = "setchanneloption";
+
+ using Events::Events;
+
/** Called when a chanserv/set command is used
* @param source The source of the command
* @param cmd The command
@@ -20,7 +24,5 @@ namespace Event
*/
virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) anope_abstract;
};
- static EventHandlersReference<SetChannelOption> OnSetChannelOption;
}
-template<> struct EventName<Event::SetChannelOption> { static constexpr const char *const name = "OnSetChannelOption"; };
diff --git a/include/modules/chanserv/set_misc.h b/include/modules/chanserv/set_misc.h
index 65b92cc89..bdde80213 100644
--- a/include/modules/chanserv/set_misc.h
+++ b/include/modules/chanserv/set_misc.h
@@ -1,5 +1,5 @@
/*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -11,6 +11,8 @@ class CSMiscData : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "csmiscdata";
+
virtual ChanServ::Channel *GetChannel() anope_abstract;
virtual void SetChannel(ChanServ::Channel *) anope_abstract;
@@ -20,6 +22,3 @@ class CSMiscData : public Serialize::Object
virtual Anope::string GetData() anope_abstract;
virtual void SetData(const Anope::string &) anope_abstract;
};
-
-static Serialize::TypeReference<CSMiscData> csmiscdata("CSMiscData");
-
diff --git a/include/modules/chanserv/suspend.h b/include/modules/chanserv/suspend.h
index 27187ea09..93702c107 100644
--- a/include/modules/chanserv/suspend.h
+++ b/include/modules/chanserv/suspend.h
@@ -1,5 +1,5 @@
/*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -12,6 +12,8 @@ class CSSuspendInfo : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "cssuspendinfo";
+
virtual ChanServ::Channel *GetChannel() anope_abstract;
virtual void SetChannel(ChanServ::Channel *) anope_abstract;
@@ -28,12 +30,14 @@ class CSSuspendInfo : public Serialize::Object
virtual void SetExpires(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<CSSuspendInfo> cssuspendinfo("CSSuspendInfo");
-
namespace Event
{
struct CoreExport ChanSuspend : Events
{
+ static constexpr const char *NAME = "chansuspend";
+
+ using Events::Events;
+
/** Called when a channel is suspended
* @param ci The channel
*/
@@ -41,13 +45,14 @@ namespace Event
};
struct CoreExport ChanUnsuspend : Events
{
+ static constexpr const char *NAME = "chanunsuspend";
+
+ using Events::Events;
+
/** Called when a channel is unsuspended
* @param ci The channel
*/
virtual void OnChanUnsuspend(ChanServ::Channel *ci) anope_abstract;
};
- extern CoreExport EventHandlers<ChanUnsuspend> OnChanUnsuspend;
}
-template<> struct EventName<Event::ChanSuspend> { static constexpr const char *const name = "OnChanSuspend"; };
-template<> struct EventName<Event::ChanUnsuspend> { static constexpr const char *const name = "OnChanUnsuspend"; };
diff --git a/include/modules/dns.h b/include/modules/dns.h
index f1ee94f87..e39f1ada8 100644
--- a/include/modules/dns.h
+++ b/include/modules/dns.h
@@ -118,7 +118,9 @@ namespace DNS
class Manager : public Service
{
public:
- Manager(Module *creator) : Service(creator, "DNS::Manager", "dns/manager") { }
+ static constexpr const char *NAME = "dns/manager";
+
+ Manager(Module *creator) : Service(creator, NAME) { }
virtual ~Manager() { }
virtual void Process(Request *req) anope_abstract;
@@ -131,8 +133,6 @@ namespace DNS
virtual uint32_t GetSerial() const anope_abstract;
};
- static ServiceReference<DNS::Manager> manager("DNS::Manager", "dns/manager");
-
/** A DNS query.
*/
class Request : public Timer, public Question
@@ -182,17 +182,18 @@ namespace Event
{
struct CoreExport DnsRequest : Events
{
+ static constexpr const char *NAME = "dnsrequest";
+
+ using Events::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;
}
-template<> struct EventName<Event::DnsRequest> { static constexpr const char *const name = "OnDnsRequest"; };
-
#endif // DNS_H
diff --git a/include/modules/encryption.h b/include/modules/encryption.h
index 3fe06cc2b..eb9ab8d62 100644
--- a/include/modules/encryption.h
+++ b/include/modules/encryption.h
@@ -27,7 +27,9 @@ namespace Encryption
class Provider : public Service
{
public:
- Provider(Module *creator, const Anope::string &sname) : Service(creator, "Encryption::Provider", sname) { }
+ static constexpr const char *NAME = "hash";
+
+ Provider(Module *creator, const Anope::string &sname) : Service(creator, NAME, sname) { }
virtual ~Provider() { }
virtual Context *CreateContext(IV * = NULL) anope_abstract;
diff --git a/include/modules/fantasy.h b/include/modules/fantasy.h
index 1bdd8afdc..7c41a4065 100644
--- a/include/modules/fantasy.h
+++ b/include/modules/fantasy.h
@@ -11,6 +11,10 @@ namespace Event
{
struct BotFantasy : Events
{
+ static constexpr const char *NAME = "botfantasy";
+
+ using Events::Events;
+
/** Called on fantasy command
* @param source The source of the command
* @param c The command
@@ -23,6 +27,10 @@ namespace Event
struct CoreExport BotNoFantasyAccess : Events
{
+ static constexpr const char *NAME = "botnofantasyaccess";
+
+ using Events::Events;
+
/** Called on fantasy command without access
* @param source The source of the command
* @param c The command
@@ -34,5 +42,3 @@ namespace Event
};
}
-template<> struct EventName<Event::BotFantasy> { static constexpr const char *const name = "OnBotFantasy"; };
-template<> struct EventName<Event::BotNoFantasyAccess> { static constexpr const char *const name = "OnBotNoFantasyAccess"; };
diff --git a/include/modules/global.h b/include/modules/global.h
index adac905cc..03e3cccc6 100644
--- a/include/modules/global.h
+++ b/include/modules/global.h
@@ -12,7 +12,9 @@ namespace Global
class GlobalService : public Service
{
public:
- GlobalService(Module *m) : Service(m, "GlobalService", "Global")
+ static constexpr const char *NAME = "global";
+
+ GlobalService(Module *m) : Service(m, NAME)
{
}
@@ -23,7 +25,6 @@ namespace Global
*/
virtual void SendGlobal(ServiceBot *sender, const Anope::string &source, const Anope::string &message) anope_abstract;
};
- static ServiceReference<GlobalService> service("GlobalService", "Global");
}
diff --git a/include/modules/help.h b/include/modules/help.h
index df81aecbf..2b9c84983 100644
--- a/include/modules/help.h
+++ b/include/modules/help.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport Help : Events
{
+ static constexpr const char *NAME = "help";
+
+ using Events::Events;
+
/** Called when someone uses the generic/help command
* @param source Command source
* @param params Params
@@ -26,4 +30,3 @@ namespace Event
};
}
-template<> struct EventName<Event::Help> { static constexpr const char *const name = "Help"; };
diff --git a/include/modules/hostserv/del.h b/include/modules/hostserv/del.h
index 9b2ea39ef..23b8537e8 100644
--- a/include/modules/hostserv/del.h
+++ b/include/modules/hostserv/del.h
@@ -10,6 +10,10 @@ namespace Event
{
struct CoreExport DeleteVhost : Events
{
+ static constexpr const char *NAME = "deletevhost";
+
+ using Events::Events;
+
/** Called when a vhost is deleted
* @param na The nickalias of the vhost
*/
@@ -17,4 +21,3 @@ namespace Event
};
}
-template<> struct EventName<Event::DeleteVhost> { static constexpr const char *const name = "OnDeleteVhost"; };
diff --git a/include/modules/httpd.h b/include/modules/httpd.h
index 33e21a0b7..aea00826d 100644
--- a/include/modules/httpd.h
+++ b/include/modules/httpd.h
@@ -132,11 +132,16 @@ class HTTPProvider : public ListenSocket, public Service
Anope::string ip;
unsigned short port;
bool ssl;
+
public:
+ static constexpr const char *NAME = "http";
+
Anope::string ext_ip;
std::vector<Anope::string> ext_headers;
- HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, bool s) : ListenSocket(i, p, i.find(':') != Anope::string::npos), Service(c, "HTTPProvider", n), ip(i), port(p), ssl(s) { }
+ HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, bool s)
+ : ListenSocket(i, p, i.find(':') != Anope::string::npos)
+ , Service(c, NAME, n), ip(i), port(p), ssl(s) { }
const Anope::string &GetIP() const
{
diff --git a/include/modules/memoserv.h b/include/modules/memoserv.h
index b7d49ad3a..e84276039 100644
--- a/include/modules/memoserv.h
+++ b/include/modules/memoserv.h
@@ -17,6 +17,8 @@ namespace MemoServ
class MemoServService : public Service
{
public:
+ static constexpr const char *NAME = "memoserv";
+
enum MemoResult
{
MEMO_SUCCESS,
@@ -25,7 +27,7 @@ namespace MemoServ
MEMO_TARGET_FULL
};
- MemoServService(Module *m) : Service(m, "MemoServService", "MemoServ")
+ MemoServService(Module *m) : Service(m, "MemoServService", NAME)
{
}
@@ -42,17 +44,19 @@ namespace MemoServ
*/
virtual void Check(User *u) anope_abstract;
- virtual Memo *CreateMemo() anope_abstract;
virtual MemoInfo *GetMemoInfo(const Anope::string &targ, bool &is_registered, bool &is_chan, bool create) anope_abstract;
-
- virtual Ignore *CreateIgnore() anope_abstract;
};
- static ServiceReference<MemoServService> service("MemoServService", "MemoServ");
+
+ extern MemoServService *service;
namespace Event
{
struct CoreExport MemoSend : Events
{
+ static constexpr const char *NAME = "memosend";
+
+ using Events::Events;
+
/** Called when a memo is sent
* @param source The source of the memo
* @param target The target of the memo
@@ -61,10 +65,13 @@ namespace MemoServ
*/
virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) anope_abstract;
};
- static EventHandlersReference<MemoSend> OnMemoSend;
struct CoreExport MemoDel : Events
{
+ static constexpr const char *NAME = "memodel";
+
+ using Events::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
@@ -72,7 +79,6 @@ namespace MemoServ
*/
virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) anope_abstract;
};
- static EventHandlersReference<MemoDel> OnMemoDel;
}
class Memo : public Serialize::Object
@@ -81,6 +87,8 @@ namespace MemoServ
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "memo";
+
virtual MemoInfo *GetMemoInfo() anope_abstract;
virtual void SetMemoInfo(MemoInfo *) anope_abstract;
@@ -100,8 +108,6 @@ namespace MemoServ
virtual void SetReceipt(const bool &) anope_abstract;
};
- static Serialize::TypeReference<Memo> memo("Memo");
-
/* Memo info structures. Since both nicknames and channels can have memos,
* we encapsulate memo data in a MemoInfo to make it easier to handle.
*/
@@ -111,6 +117,7 @@ namespace MemoServ
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "memoinfo";
virtual Memo *GetMemo(unsigned index) anope_abstract;
@@ -130,23 +137,18 @@ namespace MemoServ
virtual std::vector<Ignore *> GetIgnores() anope_abstract;
};
- static Serialize::TypeReference<MemoInfo> memoinfo("MemoInfo");
-
class Ignore : public Serialize::Object
{
protected:
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "memoignore";
+
virtual MemoInfo *GetMemoInfo() anope_abstract;
virtual void SetMemoInfo(MemoInfo *) anope_abstract;
virtual Anope::string GetMask() anope_abstract;
virtual void SetMask(const Anope::string &mask) anope_abstract;
};
-
- static Serialize::TypeReference<Ignore> ignore("MemoIgnore");
}
-
-template<> struct EventName<MemoServ::Event::MemoSend> { static constexpr const char *const name = "OnMemoSend"; };
-template<> struct EventName<MemoServ::Event::MemoDel> { static constexpr const char *const name = "OnMemoDel"; };
diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h
index 5c9cfb341..ef291ec95 100644
--- a/include/modules/nickserv.h
+++ b/include/modules/nickserv.h
@@ -45,7 +45,8 @@ namespace NickServ
virtual Nick *FindNick(const Anope::string &nick) anope_abstract;
virtual Account *FindAccount(const Anope::string &acc) anope_abstract;
};
- static ServiceReference<NickServService> service("NickServService", "NickServ");
+
+ extern NickServService *service;
inline Nick *FindNick(const Anope::string &nick)
{
@@ -61,25 +62,35 @@ namespace NickServ
{
struct CoreExport PreNickExpire : Events
{
+ static constexpr const char *NAME = "prenickexpire";
+
+ using Events::Events;
+
/** Called before a nick expires
* @param na The nick
* @param expire Set to true to allow the nick to expire
*/
virtual void OnPreNickExpire(Nick *na, bool &expire) anope_abstract;
};
- static EventHandlersReference<PreNickExpire> OnPreNickExpire;
struct CoreExport NickExpire : Events
{
+ static constexpr const char *NAME = "nickexpire";
+
+ using Events::Events;
+
/** Called when a nick drops
* @param na The nick
*/
virtual void OnNickExpire(Nick *na) anope_abstract;
};
- static EventHandlersReference<NickExpire> OnNickExpire;
struct CoreExport NickRegister : Events
{
+ static constexpr const char *NAME = "nickregister";
+
+ using Events::Events;
+
/** Called when a nick is registered
* @param user The user registering the nick, of any
* @param The nick
@@ -87,16 +98,22 @@ namespace NickServ
*/
virtual void OnNickRegister(User *user, Nick *na, const Anope::string &password) anope_abstract;
};
- static EventHandlersReference<NickRegister> OnNickRegister;
struct CoreExport NickConfirm : Events
{
+ static constexpr const char *NAME = "nickconfirm";
+
+ using Events::Events;
+
virtual void OnNickConfirm(User *, Account *) anope_abstract;
};
- static EventHandlersReference<NickConfirm> OnNickConfirm;
struct CoreExport NickValidate : Events
{
+ static constexpr const char *NAME = "nickvalidate";
+
+ using Events::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
@@ -105,7 +122,6 @@ namespace NickServ
*/
virtual EventReturn OnNickValidate(User *u, Nick *na) anope_abstract;
};
- static EventHandlersReference<NickValidate> OnNickValidate;
}
/* A registered nickname.
@@ -117,6 +133,8 @@ namespace NickServ
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "nick";
+
virtual Anope::string GetNick() anope_abstract;
virtual void SetNick(const Anope::string &) anope_abstract;
@@ -164,8 +182,6 @@ namespace NickServ
virtual void SetVhostCreated(const time_t &) anope_abstract;
};
- static Serialize::TypeReference<Nick> nick("NickAlias");
-
/* A registered account. Each account must have a Nick with the same nick as the
* account's display.
* It matters that Base is here before Extensible (it is inherited by Serializable)
@@ -173,6 +189,8 @@ namespace NickServ
class CoreExport Account : public Serialize::Object
{
public:
+ static constexpr const char *const NAME = "account";
+
/* Set if this user is a services operattor. o->ot must exist. */
Serialize::Reference<Oper> o;
@@ -222,8 +240,6 @@ namespace NickServ
virtual unsigned int GetChannelCount() anope_abstract;
};
- static Serialize::TypeReference<Account> account("NickCore");
-
/* A request to check if an account/password is valid. These can exist for
* extended periods due to the time some authentication modules take.
*/
@@ -287,6 +303,8 @@ namespace NickServ
class Mode : public Serialize::Object
{
public:
+ static constexpr const char *const NAME = "mode";
+
using Serialize::Object::Object;
virtual Account *GetAccount() anope_abstract;
@@ -296,12 +314,4 @@ namespace NickServ
virtual void SetMode(const Anope::string &) anope_abstract;
};
- static Serialize::TypeReference<Mode> mode("NSKeepMode");
-
}
-
-template<> struct EventName<NickServ::Event::PreNickExpire> { static constexpr const char *const name = "OnPreNickExpire"; };
-template<> struct EventName<NickServ::Event::NickExpire> { static constexpr const char *const name = "OnNickExpire"; };
-template<> struct EventName<NickServ::Event::NickRegister> { static constexpr const char *const name = "OnNickRegister"; };
-template<> struct EventName<NickServ::Event::NickConfirm> { static constexpr const char *const name = "OnNickConfirm"; };
-template<> struct EventName<NickServ::Event::NickValidate> { static constexpr const char *const name = "OnNickValidate"; };
diff --git a/include/modules/nickserv/access.h b/include/modules/nickserv/access.h
index 73a625f3d..716b22927 100644
--- a/include/modules/nickserv/access.h
+++ b/include/modules/nickserv/access.h
@@ -1,6 +1,6 @@
/*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -9,6 +9,8 @@
class NickAccess : public Serialize::Object
{
public:
+ static constexpr const char *const NAME = "nsaccess";
+
using Serialize::Object::Object;
virtual NickServ::Account *GetAccount() anope_abstract;
@@ -18,5 +20,4 @@ class NickAccess : public Serialize::Object
virtual void SetMask(const Anope::string &) anope_abstract;
};
-static Serialize::TypeReference<NickAccess> nsaccess("NSAccess");
diff --git a/include/modules/nickserv/ajoin.h b/include/modules/nickserv/ajoin.h
index 7b4cc20e5..342be9e4f 100644
--- a/include/modules/nickserv/ajoin.h
+++ b/include/modules/nickserv/ajoin.h
@@ -1,9 +1,10 @@
/*
*
- * (C) 2013-2014 Anope Team
+ * (C) 2013-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
+ *
*/
class AutoJoin : public Serialize::Object
@@ -12,6 +13,8 @@ class AutoJoin : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "autojoin";
+
virtual NickServ::Account *GetOwner() anope_abstract;
virtual void SetOwner(NickServ::Account *acc) anope_abstract;
@@ -22,4 +25,3 @@ class AutoJoin : public Serialize::Object
virtual void SetKey(const Anope::string &k) anope_abstract;
};
-static Serialize::TypeReference<AutoJoin> autojoin("AutoJoin");
diff --git a/include/modules/nickserv/cert.h b/include/modules/nickserv/cert.h
index be75fb9bf..9bb21a565 100644
--- a/include/modules/nickserv/cert.h
+++ b/include/modules/nickserv/cert.h
@@ -14,7 +14,9 @@ class NSCertEntry;
class CertService : public Service
{
public:
- CertService(Module *c) : Service(c, "CertService", "certs") { }
+ static constexpr const char *NAME = "certs";
+
+ CertService(Module *c) : Service(c, NAME) { }
virtual NickServ::Account* FindAccountFromCert(const Anope::string &cert) anope_abstract;
@@ -23,11 +25,11 @@ class CertService : public Service
virtual NSCertEntry *FindCert(const std::vector<NSCertEntry *> &cl, const Anope::string &certfp) anope_abstract;
};
-static ServiceReference<CertService> certservice("CertService", "certs");
-
class NSCertEntry : public Serialize::Object
{
public:
+ static constexpr const char *NAME = "nscert";
+
using Serialize::Object::Object;
virtual NickServ::Account *GetAccount() anope_abstract;
@@ -37,12 +39,14 @@ class NSCertEntry : public Serialize::Object
virtual void SetCert(const Anope::string &) anope_abstract;
};
-static Serialize::TypeReference<NSCertEntry> certentry("NSCertEntry");
-
namespace Event
{
struct CoreExport NickCertEvents : Events
{
+ static constexpr const char *NAME = "nickcertevents";
+
+ using Events::Events;
+
/** Called when a user adds an entry to their cert list
* @param nc The nick
* @param entry The entry
@@ -62,5 +66,3 @@ namespace Event
};
}
-
-template<> struct EventName<Event::NickCertEvents> { static constexpr const char *const name = "OnNickCert"; };
diff --git a/include/modules/nickserv/drop.h b/include/modules/nickserv/drop.h
index bae9d77b6..096458510 100644
--- a/include/modules/nickserv/drop.h
+++ b/include/modules/nickserv/drop.h
@@ -10,13 +10,15 @@ namespace Event
{
struct CoreExport NickDrop : Events
{
+ static constexpr const char *NAME = "nickdrop";
+
+ using Events::Events;
+
/** Called when a nick is dropped
* @param source The source of the command
* @param na The nick
*/
virtual void OnNickDrop(CommandSource &source, NickServ::Nick *na) anope_abstract;
};
- extern CoreExport EventHandlers<NickDrop> OnNickDrop;
}
-template<> struct EventName<Event::NickDrop> { static constexpr const char *const name = "OnNickDrop"; };
diff --git a/include/modules/nickserv/group.h b/include/modules/nickserv/group.h
index caa568a9e..b4648498f 100644
--- a/include/modules/nickserv/group.h
+++ b/include/modules/nickserv/group.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport NickGroup : Events
{
+ static constexpr const char *NAME = "nickgroup";
+
+ using Events::Events;
+
/** Called when a user groups their nick
* @param u The user grouping
* @param target The target they're grouping to
@@ -19,4 +23,3 @@ namespace Event
};
}
-template<> struct EventName<Event::NickGroup> { static constexpr const char *const name = "OnNickGroup"; };
diff --git a/include/modules/nickserv/info.h b/include/modules/nickserv/info.h
index e816cc356..c9177c1c7 100644
--- a/include/modules/nickserv/info.h
+++ b/include/modules/nickserv/info.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport NickInfo : Events
{
+ static constexpr const char *NAME = "nickinfo";
+
+ using Events::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
@@ -21,4 +25,3 @@ namespace Event
};
}
-template<> struct EventName<Event::NickInfo> { static constexpr const char *const name = "OnNickInfo"; };
diff --git a/include/modules/nickserv/set.h b/include/modules/nickserv/set.h
index c6b86032b..c8438be3a 100644
--- a/include/modules/nickserv/set.h
+++ b/include/modules/nickserv/set.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport SetNickOption : Events
{
+ static constexpr const char *NAME = "setnickoption";
+
+ using Events::Events;
+
/** Called when a nickserv/set command is used.
* @param source The source of the command
* @param cmd The command
@@ -20,7 +24,5 @@ namespace Event
*/
virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickServ::Account *nc, const Anope::string &setting) anope_abstract;
};
- static EventHandlersReference<SetNickOption> OnSetNickOption;
}
-template<> struct EventName<Event::SetNickOption> { static constexpr const char *const name = "OnSetNickOption"; };
diff --git a/include/modules/nickserv/set_misc.h b/include/modules/nickserv/set_misc.h
index 18d49dd0f..9bf593c7f 100644
--- a/include/modules/nickserv/set_misc.h
+++ b/include/modules/nickserv/set_misc.h
@@ -1,5 +1,5 @@
/*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -11,6 +11,8 @@ class NSMiscData : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "nsmiscdata";
+
virtual NickServ::Account *GetAccount() anope_abstract;
virtual void SetAccount(NickServ::Account *) anope_abstract;
@@ -21,5 +23,3 @@ class NSMiscData : public Serialize::Object
virtual void SetData(const Anope::string &) anope_abstract;
};
-static Serialize::TypeReference<NSMiscData> nsmiscdata("NSMiscData");
-
diff --git a/include/modules/nickserv/suspend.h b/include/modules/nickserv/suspend.h
index fcfc0265d..2cd8faab6 100644
--- a/include/modules/nickserv/suspend.h
+++ b/include/modules/nickserv/suspend.h
@@ -12,6 +12,8 @@ class NSSuspendInfo : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "nssuspendinfo";
+
virtual NickServ::Account *GetAccount() anope_abstract;
virtual void SetAccount(NickServ::Account *) anope_abstract;
@@ -28,12 +30,14 @@ class NSSuspendInfo : public Serialize::Object
virtual void SetExpires(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<NSSuspendInfo> nssuspendinfo("NSSuspendInfo");
-
namespace Event
{
struct CoreExport NickSuspend : Events
{
+ static constexpr const char *NAME = "nicksuspend";
+
+ using Events::Events;
+
/** Called when a nick is suspended
* @param na The nick alias
*/
@@ -42,12 +46,13 @@ namespace Event
struct CoreExport NickUnsuspend : Events
{
+ static constexpr const char *NAME = "nickunsuspend";
+
+ using Events::Events;
+
/** Called when a nick is unsuspneded
* @param na The nick alias
*/
virtual void OnNickUnsuspend(NickServ::Nick *na) anope_abstract;
};
}
-
-template<> struct EventName<Event::NickSuspend> { static constexpr const char *const name = "OnNickSuspend"; };
-template<> struct EventName<Event::NickUnsuspend> { static constexpr const char *const name = "OnNickUnsuspend"; };
diff --git a/include/modules/nickserv/update.h b/include/modules/nickserv/update.h
index ce75c33ac..531c1d237 100644
--- a/include/modules/nickserv/update.h
+++ b/include/modules/nickserv/update.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport NickUpdate : Events
{
+ static constexpr const char *NAME = "nickupdate";
+
+ using Events::Events;
+
/** Called when a user does /ns update
* @param u The user
*/
@@ -18,4 +22,3 @@ namespace Event
};
}
-template<> struct EventName<Event::NickUpdate> { static constexpr const char *const name = "OnNickUpdate"; };
diff --git a/include/modules/operserv/defcon.h b/include/modules/operserv/defcon.h
index f980d5008..f46609db3 100644
--- a/include/modules/operserv/defcon.h
+++ b/include/modules/operserv/defcon.h
@@ -11,6 +11,10 @@ namespace Event
{
struct CoreExport DefconLevel : Events
{
+ static constexpr const char *NAME = "defconlevel";
+
+ using Events::Events;
+
/** Called when defcon level changes
* @param level The level
*/
@@ -18,4 +22,3 @@ namespace Event
};
}
-template<> struct EventName<Event::DefconLevel> { static constexpr const char *const name = "OnDefconLevel"; };
diff --git a/include/modules/operserv/dns.h b/include/modules/operserv/dns.h
index d76cd3d62..a6f4e33b2 100644
--- a/include/modules/operserv/dns.h
+++ b/include/modules/operserv/dns.h
@@ -13,18 +13,20 @@ class DNSZone : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "dnszone";
+
virtual Anope::string GetName() anope_abstract;
virtual void SetName(const Anope::string &) anope_abstract;
};
-static Serialize::TypeReference<DNSZone> dnszone("DNSZone");
-
class DNSServer : public Serialize::Object
{
protected:
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "dnsserver";
+
virtual DNSZone *GetZone() anope_abstract;
virtual void SetZone(DNSZone *) anope_abstract;
@@ -38,14 +40,14 @@ class DNSServer : public Serialize::Object
virtual void SetPool(const bool &) anope_abstract;
};
-static Serialize::TypeReference<DNSServer> dnsserver("DNSServer");
-
class DNSZoneMembership : public Serialize::Object
{
protected:
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "dnszonemembership";
+
virtual DNSServer *GetServer() anope_abstract;
virtual void SetServer(DNSServer *) anope_abstract;
@@ -53,14 +55,14 @@ class DNSZoneMembership : public Serialize::Object
virtual void SetZone(DNSZone *) anope_abstract;
};
-static Serialize::TypeReference<DNSZoneMembership> dnszonemembership("DNSZoneMembership");
-
class DNSIP : public Serialize::Object
{
protected:
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "dnsip";
+
virtual DNSServer *GetServer() anope_abstract;
virtual void SetServer(DNSServer *) anope_abstract;
@@ -68,5 +70,4 @@ class DNSIP : public Serialize::Object
virtual void SetIP(const Anope::string &) anope_abstract;
};
-static Serialize::TypeReference<DNSIP> dnsip("DNSIP");
diff --git a/include/modules/operserv/forbid.h b/include/modules/operserv/forbid.h
index 9b21defec..9fb1cd692 100644
--- a/include/modules/operserv/forbid.h
+++ b/include/modules/operserv/forbid.h
@@ -1,9 +1,10 @@
/*
*
- * (C) 2013-2014 Anope Team
+ * (C) 2013-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
+ *
*/
enum ForbidType
@@ -21,6 +22,8 @@ class ForbidData : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *NAME = "forbid";
+
virtual Anope::string GetMask() anope_abstract;
virtual void SetMask(const Anope::string &) anope_abstract;
@@ -43,14 +46,13 @@ class ForbidData : public Serialize::Object
class ForbidService : public Service
{
public:
- ForbidService(Module *m) : Service(m, "ForbidService", "forbid") { }
+ static constexpr const char *NAME = "forbid";
+
+ ForbidService(Module *m) : Service(m, NAME) { }
virtual ForbidData *FindForbid(const Anope::string &mask, ForbidType type) anope_abstract;
virtual std::vector<ForbidData *> GetForbids() anope_abstract;
};
-static ServiceReference<ForbidService> forbid_service("ForbidService", "forbid");
-
-static Serialize::TypeReference<ForbidData> forbiddata("ForbidData");
diff --git a/include/modules/operserv/ignore.h b/include/modules/operserv/ignore.h
index 2326b5575..ab793c533 100644
--- a/include/modules/operserv/ignore.h
+++ b/include/modules/operserv/ignore.h
@@ -13,6 +13,8 @@
class Ignore : public Serialize::Object
{
public:
+ static constexpr const char *NAME = "ignore";
+
using Serialize::Object::Object;
virtual Anope::string GetMask() anope_abstract;
@@ -28,16 +30,13 @@ class Ignore : public Serialize::Object
virtual void SetTime(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<Ignore> ignoretype("IgnoreData");
-
class IgnoreService : public Service
{
- protected:
- IgnoreService(Module *c) : Service(c, "IgnoreService", "ignore") { }
-
public:
+ static constexpr const char *NAME = "ignore";
+
+ IgnoreService(Module *c) : Service(c, NAME) { }
+
virtual Ignore *Find(const Anope::string &mask) anope_abstract;
};
-static ServiceReference<IgnoreService> ignore_service("IgnoreService", "ignore");
-
diff --git a/include/modules/operserv/info.h b/include/modules/operserv/info.h
index 6e819158d..6b3674bc1 100644
--- a/include/modules/operserv/info.h
+++ b/include/modules/operserv/info.h
@@ -1,9 +1,10 @@
/*
*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
+ *
*/
class OperInfo : public Serialize::Object
@@ -12,6 +13,8 @@ class OperInfo : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *const NAME = "operinfo";
+
virtual Serialize::Object *GetTarget() anope_abstract;
virtual void SetTarget(Serialize::Object *) anope_abstract;
@@ -24,6 +27,3 @@ class OperInfo : public Serialize::Object
virtual time_t GetCreated() anope_abstract;
virtual void SetCreated(const time_t &) anope_abstract;
};
-
-static Serialize::TypeReference<OperInfo> operinfo("OperInfo");
-
diff --git a/include/modules/operserv/news.h b/include/modules/operserv/news.h
index 07627b1bc..43f7a1aaf 100644
--- a/include/modules/operserv/news.h
+++ b/include/modules/operserv/news.h
@@ -1,5 +1,13 @@
-#ifndef OS_NEWS
-#define OS_NEWS
+/*
+ *
+ * (C) 2016 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ */
+
+#pragma once
enum NewsType
{
@@ -11,6 +19,8 @@ enum NewsType
class NewsItem : public Serialize::Object
{
public:
+ static constexpr const char *const NAME = "newsitem";
+
using Serialize::Object::Object;
virtual NewsType GetNewsType() anope_abstract;
@@ -25,8 +35,3 @@ class NewsItem : public Serialize::Object
virtual time_t GetTime() anope_abstract;
virtual void SetTime(const time_t &) anope_abstract;
};
-
-static Serialize::TypeReference<NewsItem> newsitem("NewsItem");
-
-#endif // OS_NEWS
-
diff --git a/include/modules/operserv/session.h b/include/modules/operserv/session.h
index b9afd196e..1afa9e48a 100644
--- a/include/modules/operserv/session.h
+++ b/include/modules/operserv/session.h
@@ -16,6 +16,7 @@ class Exception : public Serialize::Object
using Serialize::Object::Object;
public:
+ static constexpr const char *NAME = "exception";
virtual Anope::string GetMask() anope_abstract;
virtual void SetMask(const Anope::string &) anope_abstract;
@@ -36,14 +37,14 @@ class Exception : public Serialize::Object
virtual void SetExpires(const time_t &) anope_abstract;
};
-static Serialize::TypeReference<Exception> exception("Exception");
-
class SessionService : public Service
{
public:
+ static constexpr const char *NAME = "session";
+
typedef std::unordered_map<cidr, Session *, cidr::hash> SessionMap;
- SessionService(Module *m) : Service(m, "SessionService", "session") { }
+ SessionService(Module *m) : Service(m, NAME) { }
virtual Exception *FindException(User *u) anope_abstract;
@@ -54,12 +55,14 @@ class SessionService : public Service
virtual SessionMap &GetSessions() anope_abstract;
};
-static ServiceReference<SessionService> session_service("SessionService", "session");
-
namespace Event
{
struct CoreExport Exception : Events
{
+ static constexpr const char *NAME = "exception";
+
+ using Events::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
@@ -74,4 +77,3 @@ namespace Event
};
}
-template<> struct EventName<Event::Exception> { static constexpr const char *const name = "Exception"; };
diff --git a/include/modules/redis.h b/include/modules/redis.h
index 3ee13346c..a1181782a 100644
--- a/include/modules/redis.h
+++ b/include/modules/redis.h
@@ -68,7 +68,9 @@ namespace Redis
class Provider : public Service
{
public:
- Provider(Module *c, const Anope::string &n) : Service(c, "Redis::Provider", n) { }
+ static constexpr const char *NAME = "redis";
+
+ Provider(Module *c, const Anope::string &n) : Service(c, NAME, n) { }
virtual void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) anope_abstract;
virtual void SendCommand(Interface *i, const Anope::string &str) anope_abstract;
diff --git a/include/modules/sasl.h b/include/modules/sasl.h
index 85e512310..4d0f6be44 100644
--- a/include/modules/sasl.h
+++ b/include/modules/sasl.h
@@ -1,6 +1,6 @@
/*
*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -23,7 +23,9 @@ namespace SASL
class Service : public ::Service
{
public:
- Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { }
+ static constexpr const char *NAME = "sasl";
+
+ Service(Module *o) : ::Service(o, NAME) { }
virtual void ProcessMessage(const Message &) anope_abstract;
@@ -40,84 +42,55 @@ namespace SASL
virtual void RemoveSession(Session *) anope_abstract;
};
- static ServiceReference<SASL::Service> sasl("SASL::Service", "sasl");
-
- struct Session
+ class Session
{
+ SASL::Service *service;
+
+ public:
time_t created;
Anope::string uid;
Reference<Mechanism> mech;
- Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { }
+ Session(SASL::Service *s, Mechanism *m, const Anope::string &u) : service(s), created(Anope::CurTime), uid(u), mech(m) { }
+
virtual ~Session()
{
- if (sasl)
- sasl->RemoveSession(this);
+ service->RemoveSession(this);
}
};
/* PLAIN, EXTERNAL, etc */
class Mechanism : public ::Service
{
+ SASL::Service *service;
+
public:
- Mechanism(Module *o, const Anope::string &sname) : Service(o, "SASL::Mechanism", sname) { }
+ static constexpr const char *NAME = "sasl/mechanism";
+
+ Mechanism(SASL::Service *s, Module *o, const Anope::string &sname) : Service(o, NAME, sname), service(s) { }
+
+ SASL::Service *GetService() const { return service; }
- virtual Session* CreateSession(const Anope::string &uid) { return new Session(this, uid); }
+ virtual Session* CreateSession(const Anope::string &uid) { return new Session(service, this, uid); }
virtual void ProcessMessage(Session *session, const Message &) anope_abstract;
virtual ~Mechanism()
{
- if (sasl)
- sasl->DeleteSessions(this, true);
+ service->DeleteSessions(this, true);
}
};
class IdentifyRequestListener : public NickServ::IdentifyRequestListener
{
+ SASL::Service *service = nullptr;
Anope::string uid;
public:
- IdentifyRequestListener(const Anope::string &id) : uid(id) { }
+ IdentifyRequestListener(SASL::Service *s, const Anope::string &id) : service(s), uid(id) { }
- void OnSuccess(NickServ::IdentifyRequest *req) override
- {
- if (!sasl)
- return;
-
- NickServ::Nick *na = NickServ::FindNick(req->GetAccount());
- if (!na || na->GetAccount()->HasFieldS("NS_SUSPENDED"))
- return OnFail(req);
-
- Session *s = sasl->GetSession(uid);
- if (s)
- {
- Log(Config->GetClient("NickServ")) << "A user identified to account " << req->GetAccount() << " using SASL";
- sasl->Succeed(s, na->GetAccount());
- delete s;
- }
- }
+ void OnSuccess(NickServ::IdentifyRequest *req) override;
- void OnFail(NickServ::IdentifyRequest *req) override
- {
- if (!sasl)
- return;
-
- Session *s = sasl->GetSession(uid);
- if (s)
- {
- sasl->Fail(s);
- delete s;
- }
-
- Anope::string accountstatus;
- NickServ::Nick *na = NickServ::FindNick(req->GetAccount());
- if (!na)
- accountstatus = "nonexistent ";
- else if (na->GetAccount()->HasFieldS("NS_SUSPENDED"))
- accountstatus = "suspended ";
-
- Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << req->GetAccount() << " using SASL";
- }
+ void OnFail(NickServ::IdentifyRequest *req) override;
};
}
diff --git a/include/modules/sql.h b/include/modules/sql.h
index 49c92ccd0..cc747566d 100644
--- a/include/modules/sql.h
+++ b/include/modules/sql.h
@@ -71,6 +71,14 @@ namespace SQL
qd.escape = false;
qd.null = true;
}
+
+ Anope::string Unsafe() const
+ {
+ Anope::string q = query;
+ for (auto it = parameters.begin(); it != parameters.end(); ++it)
+ q = q.replace_all_cs("@" + it->first + "@", it->second.data);
+ return q;
+ }
};
/** A result from a SQL query
@@ -172,7 +180,9 @@ namespace SQL
class Provider : public Service
{
public:
- Provider(Module *c, const Anope::string &n) : Service(c, "SQL::Provider", n) { }
+ static constexpr const char *NAME = "sql";
+
+ Provider(Module *c, const Anope::string &n) : Service(c, NAME, n) { }
virtual void Run(Interface *i, const Query &query) anope_abstract;
diff --git a/include/modules/ssl.h b/include/modules/ssl.h
index c0fcb02a7..ea38d1c3f 100644
--- a/include/modules/ssl.h
+++ b/include/modules/ssl.h
@@ -2,7 +2,9 @@
class SSLService : public Service
{
public:
- SSLService(Module *o, const Anope::string &n) : Service(o, "SSLService", n) { }
+ static constexpr const char *NAME = "ssl";
+
+ SSLService(Module *o, const Anope::string &n) : Service(o, NAME, n) { }
virtual void Init(Socket *s) anope_abstract;
};
diff --git a/include/modules/xmlrpc.h b/include/modules/xmlrpc.h
index 14ec7e997..41c9e832c 100644
--- a/include/modules/xmlrpc.h
+++ b/include/modules/xmlrpc.h
@@ -27,7 +27,9 @@ class XMLRPCEvent
class XMLRPCServiceInterface : public Service
{
public:
- XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, "XMLRPCServiceInterface", sname) { }
+ static constexpr const char *NAME = "XMLRPCServiceInterface";
+
+ XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, NAME) { }
virtual void Register(XMLRPCEvent *event) anope_abstract;
diff --git a/include/opertype.h b/include/opertype.h
index e00e892a6..1c619eed2 100644
--- a/include/opertype.h
+++ b/include/opertype.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
- * Copyright (C) 2008-2014 Anope Team <team@anope.org>
+ * Copyright (C) 2008-2016 Anope Team <team@anope.org>
*
* Please read COPYING and README for further details.
*
@@ -13,11 +13,17 @@
class Oper : public Serialize::Object
{
+ friend class OperBlockType;
+
+ Anope::string name, password, certfp, host, vhost, type;
+ bool require_oper = false;
+
public:
+ static constexpr const char *const NAME = "oper";
+
Configuration::Conf *conf = nullptr;
- Oper(Serialize::TypeBase *type) : Serialize::Object(type) { }
- Oper(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { }
+ using Serialize::Object::Object;
Anope::string GetName();
void SetName(const Anope::string &);
@@ -53,20 +59,18 @@ class OperBlockType : public Serialize::Type<Oper>
Serialize::Field<Oper, Anope::string> name, password, certfp, host, vhost, type;
Serialize::Field<Oper, bool> require_oper;
- OperBlockType() : Serialize::Type<Oper>(nullptr, "Oper")
- , name(this, "name")
- , password(this, "password")
- , certfp(this, "certfp")
- , host(this, "host")
- , vhost(this, "vhost")
- , type(this, "type")
- , require_oper(this, "require_oper")
+ OperBlockType() : Serialize::Type<Oper>(nullptr)
+ , name(this, "name", &Oper::name)
+ , password(this, "password", &Oper::password)
+ , certfp(this, "certfp", &Oper::certfp)
+ , host(this, "host", &Oper::host)
+ , vhost(this, "vhost", &Oper::vhost)
+ , type(this, "type", &Oper::type)
+ , require_oper(this, "require_oper", &Oper::require_oper)
{
}
};
-static Serialize::TypeReference<Oper> operblock("Oper");
-
class CoreExport OperType
{
private:
diff --git a/include/protocol.h b/include/protocol.h
index 7af41ec2b..2e11166ee 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -24,6 +24,8 @@ class CoreExport IRCDProto : public Service
protected:
IRCDProto(Module *creator, const Anope::string &proto_name);
public:
+ static constexpr const char *NAME = "ircdproto";
+
virtual ~IRCDProto();
virtual void SendSVSKillInternal(const MessageSource &, User *, const Anope::string &);
@@ -274,6 +276,8 @@ class CoreExport IRCDMessage : public Service
unsigned param_count;
std::set<IRCDMessageFlag> flags;
public:
+ static constexpr const char *NAME = "IRCDMessage";
+
IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0);
unsigned GetParamCount() const;
virtual void Run(MessageSource &, const std::vector<Anope::string> &params) anope_abstract;
diff --git a/include/serialize.h b/include/serialize.h
index 1dc4d4e26..3ee9ce376 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -1,13 +1,10 @@
/*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- *
*/
#pragma once
@@ -22,7 +19,6 @@ namespace Serialize
class Object;
class TypeBase;
- class AbstractType;
class FieldBase;
template<typename> class FieldTypeBase;
@@ -32,9 +28,7 @@ namespace Serialize
template<typename T, typename> class Type;
template<typename T> class Reference;
- template<typename T> class TypeReference;
- extern std::map<Anope::string, Serialize::TypeBase *> Types;
// by id
extern std::unordered_map<ID, Object *> objects;
extern std::vector<FieldBase *> serializableFields;
@@ -42,7 +36,16 @@ namespace Serialize
extern Object *GetID(ID id);
template<typename T>
- inline std::vector<T> GetObjects(Serialize::TypeBase *type);
+ inline T GetObject();
+
+ template<typename T>
+ inline std::vector<T> GetObjects(const Anope::string &name);
+
+ template<typename T>
+ inline std::vector<T> GetObjects();
+
+ template<typename T>
+ inline T New();
extern void Clear();
@@ -61,6 +64,12 @@ namespace Serialize
return other == e.other && field == e.field && direction == e.direction;
}
};
+
+ extern std::multimap<Anope::string, Anope::string> child_types;
+
+ extern void SetParent(const Anope::string &child, const Anope::string &parent);
+
+ extern std::vector<Serialize::TypeBase *> GetTypes(const Anope::string &name);
}
class CoreExport Serialize::Object : public Extensible, public virtual Base
@@ -73,13 +82,12 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
std::map<TypeBase *, std::vector<Edge>> edges;
- std::vector<Serialize::Edge> GetRefs(TypeBase *);
+ std::vector<Edge> GetRefs(TypeBase *);
- protected:
+ public:
Object(TypeBase *type);
Object(TypeBase *type, ID);
- public:
virtual ~Object();
virtual void Delete();
@@ -91,38 +99,58 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
void RemoveEdge(Object *other, FieldBase *field);
+ /**
+ * Get an object of type T that this object references.
+ */
template<typename T>
- T GetRef(TypeBase *type)
+ T GetRef()
{
- std::vector<T> t = GetRefs<T>(type);
+ std::vector<T> t = GetRefs<T>();
return !t.empty() ? t[0] : nullptr;
}
-
+
+ /**
+ * Gets all objects of type T that this object references
+ */
template<typename T>
- std::vector<T> GetRefs(TypeBase *type);
+ std::vector<T> GetRefs();
+ /**
+ * Get the value of a field on this object.
+ */
template<
- typename Type, // inherits from Serialize::Type
- template<typename, typename> class Field,
- typename TypeImpl, // implementation of Type
+ typename Type,
+ template<typename, typename> class Field, // Field type being read
+ typename TypeImpl,
typename T // type of the Extensible
>
T Get(Field<TypeImpl, T> Type::*field)
{
+ static_assert(std::is_base_of<Object, TypeImpl>::value, "");
+ static_assert(std::is_base_of<Serialize::TypeBase, Type>::value, "");
+
Type *t = static_cast<Type *>(s_type);
Field<TypeImpl, T>& f = t->*field;
return f.GetField(f.Upcast(this));
}
- /* the return value can't be inferred by the compiler so we supply this function to allow us to specify it */
+ /**
+ * Get the value of a field on this object. Allows specifying return
+ * type if the return type can't be inferred.
+ */
template<typename Ret, typename Field, typename Type>
Ret Get(Field Type::*field)
{
+ static_assert(std::is_base_of<Serialize::TypeBase, Type>::value, "");
+
Type *t = static_cast<Type *>(s_type);
Field& f = t->*field;
return f.GetField(f.Upcast(this));
}
+ /**
+ * Set the value of a field on this object
+ */
template<
typename Type,
template<typename, typename> class Field,
@@ -131,14 +159,22 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
>
void Set(Field<TypeImpl, T> Type::*field, const T& value)
{
+ static_assert(std::is_base_of<Object, TypeImpl>::value, "");
+ static_assert(std::is_base_of<Serialize::TypeBase, Type>::value, "");
+
Type *t = static_cast<Type *>(s_type);
Field<TypeImpl, T>& f = t->*field;
f.SetField(f.Upcast(this), value);
}
+ /**
+ * Set the value of a field on this object
+ */
template<typename Field, typename Type, typename T>
void Set(Field Type::*field, const T& value)
{
+ static_assert(std::is_base_of<Serialize::TypeBase, Type>::value, "");
+
Type *t = static_cast<Type *>(s_type);
Field& f = t->*field;
f.SetField(f.Upcast(this), value);
@@ -149,12 +185,19 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
*/
TypeBase* GetSerializableType() const { return this->s_type; }
+ /** Set the value of a field on this object, by field name
+ */
template<typename T>
void SetS(const Anope::string &name, const T &what);
+ /** Unset a field on this object, by field name
+ */
template<typename T>
void UnsetS(const Anope::string &name);
+ /** Test if a field is set. Only useful with extensible fields,
+ * which can unset (vs set to the default value)
+ */
bool HasFieldS(const Anope::string &name);
};
@@ -162,16 +205,14 @@ class CoreExport Serialize::TypeBase : public Service
{
Anope::string name;
- TypeBase *parent = nullptr;
- std::vector<TypeBase *> children;
-
/* Owner of this type. Used for placing objects of this type in separate databases
* based on what module, if any, owns it.
*/
Module *owner;
public:
- std::vector<FieldBase *> fields;
+ static constexpr const char *NAME = "typebase";
+
std::set<Object *> objects;
TypeBase(Module *owner, const Anope::string &n);
@@ -179,20 +220,19 @@ class CoreExport Serialize::TypeBase : public Service
void Unregister();
- protected:
- void SetParent(TypeBase *other);
-
- public:
/** Gets the name for this type
* @return The name, eg "NickAlias"
*/
const Anope::string &GetName() { return this->name; }
+ /**
+ * Get all objects of the given type
+ */
template<typename T>
std::vector<T> List()
{
std::vector<ID> ids;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeList, this, ids);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeList, this, ids);
if (result == EVENT_ALLOW)
{
std::vector<T> o;
@@ -205,44 +245,39 @@ class CoreExport Serialize::TypeBase : public Service
return o;
}
- return GetObjects<T>(this);
+ return GetObjects<T>();
}
+ /** Create a new object of this type.
+ */
virtual Object *Create() anope_abstract;
+
+ /** Get or otherwise create an object of this type
+ * with the given ID.
+ */
virtual Object *Require(Serialize::ID) anope_abstract;
+ /** Find a field on this type
+ */
FieldBase *GetField(const Anope::string &name);
- Module* GetOwner() const { return this->owner; }
+ /** Get all fields of this type
+ */
+ std::vector<FieldBase *> GetFields();
- std::vector<TypeBase *> GetSubTypes();
+ Module* GetOwner() const { return this->owner; }
static TypeBase *Find(const Anope::string &name);
static const std::map<Anope::string, TypeBase *>& GetTypes();
};
-class Serialize::AbstractType : public Serialize::TypeBase
-{
- public:
- using Serialize::TypeBase::TypeBase;
-
- Object *Create() override
- {
- return nullptr;
- }
-
- Object *Require(ID id) override
- {
- return nullptr;
- }
-};
-
template<typename T, typename Base = Serialize::TypeBase>
class Serialize::Type : public Base
{
public:
- using Base::Base;
+ Type(Module *module) : Base(module, T::NAME) { }
+ Type(Module *module, const Anope::string &name) : Base(module, name) { }
Object *Create() override
{
@@ -267,25 +302,12 @@ class Serialize::Type : public Base
}
};
-template<typename T>
-class Serialize::TypeReference : public ServiceReference<Serialize::TypeBase>
-{
- public:
- TypeReference(const Anope::string &name) : ServiceReference<Serialize::TypeBase>("Serialize::Type", name) { }
-
- T* Create()
- {
- TypeBase *t = *this;
- return static_cast<T *>(t->Create());
- }
-
- TypeBase *ToType()
- {
- TypeBase *t = *this;
- return t;
- }
-};
-
+/** A reference to a serializable object. Serializable objects may not always
+ * exist in memory at all times, like if they exist in an external database,
+ * so you can't hold pointers to them. Instead, hold a Serialize::Reference
+ * which will properly fetch the object on demand from the underlying database
+ * system.
+ */
template<typename T>
class Serialize::Reference
{
@@ -331,7 +353,7 @@ class Serialize::Reference
if (targ != nullptr && targ->GetSerializableType() == type)
return anope_dynamic_static_cast<T*>(targ);
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeDeref, id, type);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeDeref, id, type);
if (result == EVENT_ALLOW)
return anope_dynamic_static_cast<T *>(type->Require(id));
@@ -339,33 +361,40 @@ class Serialize::Reference
}
};
-class Serialize::FieldBase
+/** A field, associated with a type.
+ */
+class Serialize::FieldBase : public Service
{
public:
- struct Listener : ServiceReference<TypeBase>
- {
- FieldBase *base;
+ static constexpr const char *NAME = "fieldbase";
- Listener(FieldBase *b, const ServiceReference<TypeBase> &t) : ServiceReference<TypeBase>(t), base(b) { }
+ Anope::string serialize_type; // type the field is on
+ Anope::string serialize_name; // field name
- void OnAcquire() override;
- } type;
-
- Module *creator;
- Anope::string name;
+ /** For fields which reference other Objects. If true, when
+ * the object the field references gets deleted, this object
+ * gets deleted too.
+ */
bool depends;
- bool unregister = false;
- FieldBase(Module *, const Anope::string &, const ServiceReference<Serialize::TypeBase> &, bool);
+ FieldBase(Module *, const Anope::string &, const Anope::string &, bool);
virtual ~FieldBase();
void Unregister();
- const Anope::string &GetName() { return name; }
+ /** Serialize value of this field on the given object to string form
+ */
virtual Anope::string SerializeToString(Object *s) anope_abstract;
+
+ /** Unserialize value of this field on the given object from string form
+ */
virtual void UnserializeFromString(Object *s, const Anope::string &) anope_abstract;
- virtual void CacheMiss(Object *) anope_abstract;
+ /** Test if the given object has the given field, only usefil for extensible fields
+ */
virtual bool HasFieldS(Object *) anope_abstract;
+
+ /** Unset this field on the given object
+ */
virtual void UnsetS(Object *) anope_abstract;
};
@@ -375,33 +404,115 @@ class Serialize::FieldTypeBase : public FieldBase
public:
using FieldBase::FieldBase;
+ /** Set this field to the given value on the given object.
+ */
virtual void SetFieldS(Object *, const T &) anope_abstract;
};
-template<typename TypeImpl, typename T>
+/** Base class for serializable fields and serializable object fields.
+ */
+template<
+ typename TypeImpl, // Serializable type
+ typename T // actual type of field
+>
class Serialize::CommonFieldBase : public FieldTypeBase<T>
{
+ static_assert(std::is_base_of<Object, TypeImpl>::value, "");
+
+ /** Extensible storage for value of fields. Only used if field
+ * isn't set. Note extensible fields can be "unset", where field
+ * pointers are never unset, but are T().
+ */
+ ExtensibleItem<T> *ext = nullptr;
+
+ /** Field pointer to storage in the TypeImpl object for
+ * this field.
+ */
+ T TypeImpl::*field = nullptr;
+
protected:
- ExtensibleItem<T> ext;
+ /** Set the value of a field in storage
+ */
+ void Set_(TypeImpl *object, const T &value)
+ {
+ if (field != nullptr)
+ object->*field = value;
+ else if (ext != nullptr)
+ ext->Set(object, value);
+ else
+ throw CoreException("No field or ext");
+ }
+
+ /* Get the value of a field from storage
+ */
+ T* Get_(TypeImpl *object)
+ {
+ if (field != nullptr)
+ return &(object->*field);
+ else if (ext != nullptr)
+ return ext->Get(object);
+ else
+ throw CoreException("No field or ext");
+ }
+
+ /** Unset a field from storage
+ */
+ void Unset_(TypeImpl *object)
+ {
+ if (field != nullptr)
+ object->*field = T();
+ else if (ext != nullptr)
+ ext->Unset(object);
+ else
+ throw CoreException("No field or ext");
+ }
+
+ /** Check is a field is set. Only useful for
+ * extensible storage. Returns true for field storage.
+ */
+ bool HasField_(TypeImpl *object)
+ {
+ if (field != nullptr)
+ return true;
+ else if (ext != nullptr)
+ return ext->HasExt(object);
+ else
+ throw CoreException("No field or ext");
+ }
public:
- CommonFieldBase(Serialize::TypeBase *t, const Anope::string &n, bool depends)
- : FieldTypeBase<T>(t->GetOwner(), n, ServiceReference<Serialize::TypeBase>("Serialize::Type", t->GetName()), depends)
- , ext(t->GetOwner(), t->GetName(), n)
+ CommonFieldBase(Serialize::TypeBase *t, const Anope::string &n, bool d)
+ : FieldTypeBase<T>(t->GetOwner(), n, t->GetName(), d)
+ {
+ ext = new ExtensibleItem<T>(t->GetOwner(), t->GetName(), n);
+ }
+
+ CommonFieldBase(Module *creator, const Anope::string &n, bool d)
+ : FieldTypeBase<T>(creator, n, TypeImpl::NAME, d)
{
+ ext = new ExtensibleItem<T>(creator, TypeImpl::NAME, n);
}
- CommonFieldBase(Module *creator, Serialize::TypeReference<TypeImpl> &typeref, const Anope::string &n, bool depends)
- : FieldTypeBase<T>(creator, n, typeref, depends)
- , ext(creator, typeref.GetName(), n)
+ CommonFieldBase(Serialize::TypeBase *t,
+ const Anope::string &n,
+ T TypeImpl::*f,
+ bool d)
+ : FieldTypeBase<T>(t->GetOwner(), n, t->GetName(), d)
+ , field(f)
{
}
- void CacheMiss(Object *s) override
+ ~CommonFieldBase()
{
- ext.Set(s, T());
+ delete ext;
}
+ /** Get the value of this field on the given object
+ */
+ virtual T GetField(TypeImpl *) anope_abstract;
+
+ /** Unset this field on the given object
+ */
virtual void UnsetField(TypeImpl *) anope_abstract;
void UnsetS(Object *s) override
@@ -409,26 +520,36 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
UnsetField(Upcast(s));
}
+ bool HasFieldS(Object *s) override
+ {
+ return HasField(Upcast(s));
+ }
+
+ /** Cast a serializable object of type Object to type TypeImpl,
+ * if appropriate
+ */
TypeImpl* Upcast(Object *s)
{
- if (this->type != s->GetSerializableType())
+ if (this->serialize_type != s->GetSerializableType()->GetName())
+ {
return nullptr;
+ }
return anope_dynamic_static_cast<TypeImpl *>(s);
}
- bool HasFieldS(Object *s) override
- {
- return HasField(Upcast(s));
- }
-
bool HasField(TypeImpl *s)
{
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeHasField, s, this);
- return result != EVENT_CONTINUE;
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeHasField, s, this);
+ if (result != EVENT_CONTINUE)
+ return true;
+
+ return this->HasField_(s);
}
};
+/** Class for all fields that aren't to other serializable objects
+ */
template<typename TypeImpl, typename T>
class Serialize::Field : public CommonFieldBase<TypeImpl, T>
{
@@ -437,28 +558,39 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
{
}
- Field(Module *creator, TypeReference<TypeImpl> &typeref, const Anope::string &n) : CommonFieldBase<TypeImpl, T>(creator, typeref, n, false)
+ Field(Module *creator, const Anope::string &n) : CommonFieldBase<TypeImpl, T>(creator, n, false)
+ {
+ }
+
+ Field(TypeBase *t, const Anope::string &n, T TypeImpl::*f) : CommonFieldBase<TypeImpl, T>(t, n, f, false)
{
}
T GetField(TypeImpl *s)
{
- T* t = this->ext.Get(s);
- if (t)
+ T* t = this->Get_(s);
+
+ // If we have a non-default value for this field it is up to date and cached
+ if (t && *t != T())
return *t;
+ // Query modules
Anope::string value;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeGet, s, this, value);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeGet, s, this, value);
if (result == EVENT_ALLOW)
{
// module returned us data, so we unserialize it
T t2 = this->Unserialize(value);
- this->ext.Set(s, t2);
+ // Cache
+ this->Set_(s, t2);
return t2;
}
+ if (t)
+ return *t;
+
return T();
}
@@ -470,16 +602,16 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
virtual void SetField(TypeImpl *s, const T &value)
{
Anope::string strvalue = this->Serialize(value);
- Event::OnSerialize(&Event::SerializeEvents::OnSerializeSet, s, this, strvalue);
+ EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeSet, s, this, strvalue);
- this->ext.Set(s, value);
+ this->Set_(s, value);
}
void UnsetField(TypeImpl *s) override
{
- Event::OnSerialize(&Event::SerializeEvents::OnSerializeUnset, s, this);
+ EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeUnset, s, this);
- this->ext.Unset(s);
+ this->Unset_(s);
}
Anope::string Serialize(const T& t)
@@ -490,13 +622,14 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
}
catch (const ConvertException &)
{
+ Log(LOG_DEBUG) << "Unable to stringify " << t;
return "";
}
}
T Unserialize(const Anope::string &str)
{
- if (str.empty()) // for caching not set
+ if (str.empty())
return T();
try
@@ -546,6 +679,8 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
}
};
+/** Class for all fields that contain a reference to another serializable object.
+ */
template<typename TypeImpl, typename T>
class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
{
@@ -554,28 +689,38 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
{
}
+ ObjectField(TypeBase *t, const Anope::string &n, T TypeImpl::*field, bool d = false) : CommonFieldBase<TypeImpl, T>(t, n, field, d)
+ {
+ }
+
T GetField(TypeImpl *s)
{
- T *t = this->ext.Get(s);
- if (t)
+ T *t = this->Get_(s);
+ if (t && *t != nullptr)
return *t;
Anope::string type;
ID sid;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeGetSerializable, s, this, type, sid);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeGetSerializable, s, this, type, sid);
if (result != EVENT_CONTINUE)
{
Serialize::TypeBase *base = Serialize::TypeBase::Find(type);
if (base == nullptr)
+ {
+ Log(LOG_DEBUG_2) << "OnSerializeGetSerializable returned unknown type " << type;
return nullptr;
+ }
T t2 = result == EVENT_ALLOW ? static_cast<T>(base->Require(sid)) : nullptr;
- this->ext.Set(s, t2);
+ this->Set_(s, t2);
return t2;
}
+ if (t)
+ return *t;
+
return T();
}
@@ -586,13 +731,13 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
virtual void SetField(TypeImpl *s, T value)
{
- Event::OnSerialize(&Event::SerializeEvents::OnSerializeSetSerializable, s, this, value);
+ EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeSetSerializable, s, this, value);
- T *old = this->ext.Get(s);
+ T *old = this->Get_(s);
if (old != nullptr && *old != nullptr)
s->RemoveEdge(*old, this);
- this->ext.Set(s, value);
+ this->Set_(s, value);
if (value != nullptr)
s->AddEdge(value, this);
@@ -600,9 +745,9 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
void UnsetField(TypeImpl *s) override
{
- Event::OnSerialize(&Event::SerializeEvents::OnSerializeUnsetSerializable, s, this);
+ EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeUnsetSerializable, s, this);
- this->ext.Unset(s);
+ this->Unset_(s);
}
Anope::string SerializeToString(Object *s) override
@@ -650,11 +795,18 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
};
template<typename T>
-std::vector<T> Serialize::GetObjects(Serialize::TypeBase *type)
+T Serialize::GetObject()
+{
+ std::vector<T> v = GetObjects<T>();
+ return v.empty() ? nullptr : v[0];
+}
+
+template<typename T>
+std::vector<T> Serialize::GetObjects(const Anope::string &name)
{
std::vector<T> objs;
- for (TypeBase *t : type->GetSubTypes())
+ for (TypeBase *t : GetTypes(name))
for (Object *s : t->objects)
objs.push_back(anope_dynamic_static_cast<T>(s));
@@ -662,17 +814,41 @@ std::vector<T> Serialize::GetObjects(Serialize::TypeBase *type)
}
template<typename T>
-std::vector<T> Serialize::Object::GetRefs(Serialize::TypeBase *type)
+std::vector<T> Serialize::GetObjects()
{
- std::vector<T> objs;
+ const char* const name = std::remove_pointer<T>::type::NAME;
+ return GetObjects<T>(name);
+}
+
+template<typename T>
+T Serialize::New()
+{
+ const char* const name = std::remove_pointer<T>::type::NAME;
+ Serialize::TypeBase *type = TypeBase::Find(name);
if (type == nullptr)
{
- Log(LOG_DEBUG) << "GetRefs for unknown type on #" << this->id << " type " << s_type->GetName();
+ Log(LOG_DEBUG) << "Serialize::New with unknown type " << name;
+ return nullptr;
+ }
+
+ return static_cast<T>(type->Create());
+}
+
+template<typename T>
+std::vector<T> Serialize::Object::GetRefs()
+{
+ const char* const name = std::remove_pointer<T>::type::NAME;
+ std::vector<Serialize::TypeBase *> types = GetTypes(name);
+ std::vector<T> objs;
+
+ if (types.empty())
+ {
+ Log(LOG_DEBUG) << "GetRefs for unknown type on #" << this->id << " type " << s_type->GetName() << " named " << name;
return objs;
}
- for (Serialize::TypeBase *t : type->GetSubTypes())
+ for (Serialize::TypeBase *t : types)
for (const Serialize::Edge &edge : GetRefs(t))
if (!edge.direction)
objs.push_back(anope_dynamic_static_cast<T>(edge.other));
diff --git a/include/service.h b/include/service.h
index 748be4dc5..a295b407e 100644
--- a/include/service.h
+++ b/include/service.h
@@ -1,13 +1,12 @@
/*
*
* (C) 2003-2014 Anope Team
+ * (C) 2016 Adam <Adam@anope.org>
+ *
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- *
*/
#pragma once
@@ -23,86 +22,150 @@
*/
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;
+ Module *owner;
+ /* Service type, which should be the class name (eg "Command") */
+ Anope::string type;
+ /* Service name, commands are usually named service/command */
+ Anope::string name;
- static void check();
+ public:
+ Service(Module *o, const Anope::string &t, const Anope::string &n);
+
+ Service(Module *o, const Anope::string &t) : Service(o, t, "") { }
- static Service *FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n);
+ virtual ~Service();
- public:
- static Service *FindService(const Anope::string &t, const Anope::string &n);
+ Module *GetOwner() const { return owner; }
- static std::vector<Anope::string> GetServiceKeys(const Anope::string &t);
+ const Anope::string &GetType() const { return type; }
- static void AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v);
+ const Anope::string &GetName() const { return name; }
+};
- static void DelAlias(const Anope::string &t, const Anope::string &n);
+class ServiceReferenceBase
+{
+ Anope::string type, name;
- Module *owner;
- /* Service type, which should be the class name (eg "Command") */
- Anope::string type;
- /* Service name, commands are usually named service/command */
- Anope::string name;
+ protected:
+ std::vector<Service *> services;
- Service(Module *o, const Anope::string &t, const Anope::string &n);
+ public:
- Service(const Service &) = delete;
+ ServiceReferenceBase() = default;
- virtual ~Service();
+ ServiceReferenceBase(const Anope::string &_type, const Anope::string &_name);
+ ServiceReferenceBase(const Anope::string &_type);
+
+ virtual ~ServiceReferenceBase();
+
+ explicit operator bool() const
+ {
+ return !this->services.empty();
+ }
- void Register();
+ const Anope::string &GetType() const { return type; }
+ const Anope::string &GetName() const { return name; }
- void Unregister();
+ Service *GetService() const { return services.empty() ? nullptr : services[0]; }
+ const std::vector<Service *> &GetServices() const { return services; }
+ void SetService(Service *service);
+ void SetServices(const std::vector<Service *> &s);
};
-/** Like Reference, but used to refer to Services.
- */
template<typename T>
-class ServiceReference : public Reference<T>
+class ServiceReference : public ServiceReferenceBase
{
- Anope::string type;
- Anope::string name;
- bool need_check = true;
+ static_assert(std::is_base_of<Service, T>::value, "");
public:
- ServiceReference() { }
+ ServiceReference() : ServiceReferenceBase(T::NAME) { }
+ ServiceReference(const Anope::string &n) : ServiceReferenceBase(T::NAME, n) { }
- ServiceReference(const Anope::string &t, const Anope::string &n) : type(t), name(n)
+ operator T*() const
{
+ return static_cast<T*>(GetService());
}
- const Anope::string &GetName() const
+ T* operator->() const
{
- return name;
+ return static_cast<T*>(GetService());
}
- void operator=(const Anope::string &n)
+ T* operator*() const
{
- this->name = n;
+ return static_cast<T*>(GetService());
}
+};
+
+template<typename T>
+class ServiceReferenceList : public ServiceReferenceBase
+{
+ static_assert(std::is_base_of<Service, T>::value, "");
- void Check() override
+ public:
+ using ServiceReferenceBase::ServiceReferenceBase;
+
+ std::vector<T *> GetServices() const
{
- if (need_check)
- {
- need_check = false;
-
- this->ref = static_cast<T *>(Service::FindService(this->type, this->name));
- if (this->ref)
- {
- this->ref->AddReference(this);
- this->OnAcquire();
- }
- }
+ std::vector<T *> out;
+ std::transform(services.begin(), services.end(), std::back_inserter(out), [](Service *e) { return static_cast<T *>(e); });
+ return out;
}
+};
+
+class ServiceManager
+{
+ std::vector<ServiceReferenceBase *> references; // managed references
+ std::vector<Service *> services; // all registered services
+
+ /* Lookup services for a reference */
+ void Lookup(ServiceReferenceBase *reference);
+
+ /* Lookup services for all managed references */
+ void LookupAll();
+
+ std::vector<Service *> FindServices(const Anope::string &type);
+
+ static ServiceManager *manager;
- void Reset() override
+ public:
+ Service *FindService(const Anope::string &name);
+ Service *FindService(const Anope::string &type, const Anope::string &name);
+
+ template<typename T>
+ std::vector<T> FindServices()
+ {
+ static_assert(std::is_base_of<Service, typename std::remove_pointer<T>::type>::value, "");
+ const char *type = std::remove_pointer<T>::type::NAME;
+ std::vector<Service *> s = FindServices(type);
+ std::vector<T> out;
+ std::transform(s.begin(), s.end(), std::back_inserter(out), [](Service *e) { return static_cast<T>(e); });
+ return out;
+ }
+
+ template<typename T>
+ T FindService(const Anope::string &name)
{
- need_check = true;
+ static_assert(std::is_base_of<Service, typename std::remove_pointer<T>::type>::value, "");
+ const char *type = std::remove_pointer<T>::type::NAME;
+ return static_cast<T>(FindService(type, name));
}
- virtual void OnAcquire() { }
+ void AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v);
+
+ void DelAlias(const Anope::string &t, const Anope::string &n);
+
+ void Register(Service *service);
+
+ void Unregister(Service *service);
+
+ void RegisterReference(ServiceReferenceBase *reference);
+
+ void UnregisterReference(ServiceReferenceBase *reference);
+
+ static void Init();
+ static ServiceManager *Get();
+ static void Destroy();
};
class ServiceAlias
@@ -112,4 +175,3 @@ class ServiceAlias
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 ad9a4c78c..0617f126d 100644
--- a/include/services.h
+++ b/include/services.h
@@ -57,5 +57,10 @@
# include "anope_windows.h"
#endif
+#ifndef DEBUG_BUILD
+# define NDEBUG
+#endif
+#include <assert.h>
+
#define anope_abstract = 0
diff --git a/include/users.h b/include/users.h
index 656ab667c..f631b102c 100644
--- a/include/users.h
+++ b/include/users.h
@@ -25,8 +25,6 @@ typedef Anope::hash_map<User *> user_map;
extern CoreExport user_map UserListByNick, UserListByUID;
extern CoreExport int OperCount;
-extern CoreExport unsigned MaxUserCount;
-extern CoreExport time_t MaxUserTime;
enum class UserType
{
diff --git a/include/xline.h b/include/xline.h
index 4fb5c1384..aaf8b80f4 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -18,20 +18,25 @@ class CoreExport XLine : public Serialize::Object
{
void Recache();
Anope::string nick, user, host, real;
+
+ friend class XLineType;
+
+ Anope::string type, mask, by, reason, id;
+ time_t created = 0, expires = 0;
+
public:
+ static constexpr const char *const NAME = "xline";
+
cidr *c = nullptr;
std::regex *regex = nullptr;
- XLineManager *manager = nullptr;
- XLine(const Anope::string &mask, const Anope::string &reason = "", const Anope::string &uid = "");
-
- XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid = "");
-
- XLine(Serialize::TypeBase *type) : Serialize::Object(type) { }
- XLine(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { }
+ using Serialize::Object::Object;
~XLine();
+ void SetType(const Anope::string &);
+ Anope::string GetType();
+
void SetMask(const Anope::string &);
Anope::string GetMask();
@@ -59,23 +64,31 @@ class CoreExport XLine : public Serialize::Object
bool HasNickOrReal() const;
bool IsRegex();
-};
-static Serialize::TypeReference<XLine> xline("XLine");
+ XLineManager *GetManager();
+};
-class XLineType : public Serialize::AbstractType
+class XLineType : public Serialize::Type<XLine>
{
public:
- Serialize::Field<XLine, Anope::string> mask, by, reason, id;
+ Serialize::Field<XLine, Anope::string> type;
+ struct Mask : Serialize::Field<XLine, Anope::string>
+ {
+ using Serialize::Field<XLine, Anope::string>::Field;
+
+ void SetField(XLine *s, const Anope::string &value) override;
+ } mask;
+ Serialize::Field<XLine, Anope::string> by, reason, id;
Serialize::Field<XLine, time_t> created, expires;
- XLineType(Module *m, const Anope::string &n) : Serialize::AbstractType(m, n)
- , mask(this, "mask")
- , by(this, "by")
- , reason(this, "reason")
- , id(this, "id")
- , created(this, "created")
- , expires(this, "expires")
+ XLineType(Module *m) : Serialize::Type<XLine>(m)
+ , type(this, "type", &XLine::type)
+ , mask(this, "mask", &XLine::mask)
+ , by(this, "by", &XLine::by)
+ , reason(this, "reason", &XLine::reason)
+ , id(this, "id", &XLine::id)
+ , created(this, "created", &XLine::created)
+ , expires(this, "expires", &XLine::expires)
{
}
};
@@ -85,6 +98,8 @@ class CoreExport XLineManager : public Service
{
char type;
public:
+ static constexpr const char *NAME = "xlinemanager";
+
/* List of XLine managers we check users against in XLineManager::CheckAll */
static std::vector<XLineManager *> XLineManagers;
@@ -130,6 +145,8 @@ class CoreExport XLineManager : public Service
*/
std::vector<XLine *> GetXLines() const;
+ inline unsigned int GetCount() const { return GetXLines().size(); }
+
/** Add an entry to this XLineManager
* @param x The entry
*/
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
index 1851f47b9..7a31c1ccb 100644
--- a/modules/CMakeLists.txt
+++ b/modules/CMakeLists.txt
@@ -22,9 +22,11 @@ macro(build_modules SRC)
file(RELATIVE_PATH DEST "${Anope_SOURCE_DIR}/modules" ${SRC})
if(DEST)
- set(TARG "module_${DEST}.${SO}")
+ set(TARG "anope_${DEST}.${SO}")
+ set(OUT_NAME "${DEST}_${SO}")
else()
- set(TARG "module_${SO}")
+ set(TARG "anope_${SO}")
+ set(OUT_NAME "${SO}")
endif()
# Reset linker flags
@@ -40,14 +42,14 @@ macro(build_modules SRC)
set(WIN32_MEMORY)
endif()
# Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand
- add_library(${TARG} MODULE ${MODULE_SRC})
+ add_library(${TARG} SHARED ${MODULE_SRC})
# Windows requires this because it's weird
if(WIN32)
set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\" /OPT:NOREF")
else()
set(WIN32_NO_LIBS)
endif()
- set_target_properties(${TARG} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON OUTPUT_NAME "${SO}")
+ set_target_properties(${TARG} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" OUTPUT_NAME "${OUT_NAME}" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON)
add_dependencies(${TARG} ${PROGRAM_NAME})
if(GETTEXT_FOUND)
add_dependencies(${TARG} module_language)
@@ -60,15 +62,41 @@ macro(build_modules SRC)
elseif(APPLE)
target_link_libraries(${TARG} ${PROGRAM_NAME})
endif()
- calculate_dependencies(${MODULE_SRC})
# Set the module to be installed to the module directory under the data directory
- install(TARGETS ${TARG} DESTINATION ${LIB_DIR}/modules/${DEST})
+ install(TARGETS ${TARG} DESTINATION ${LIB_DIR}/modules)
endif()
endif()
endforeach()
endif()
endmacro()
+macro(build_modules_dependencies SRC)
+ file(GLOB MODULES_SRCS "${SRC}/*")
+ foreach(MODULE_SRC ${MODULES_SRCS})
+ if(NOT IS_DIRECTORY "${MODULE_SRC}")
+ string(REGEX MATCH "\\.cpp$" CPP ${MODULE_SRC})
+ if(CPP)
+ file(RELATIVE_PATH FNAME ${SRC} ${MODULE_SRC})
+ # Convert the real source file extension to have a .so extension
+ string(REGEX REPLACE "\\.cpp$" "" SO ${FNAME})
+
+ file(RELATIVE_PATH DEST "${Anope_SOURCE_DIR}/modules" ${SRC})
+ if(DEST)
+ set(TARG "anope_${DEST}.${SO}")
+ else()
+ set(TARG "anope_${SO}")
+ endif()
+
+ set(DEPS)
+ calculate_dependencies(${MODULE_SRC} DEPS)
+ foreach(DEP ${DEPS})
+ target_link_libraries(${TARG} ${DEP})
+ endforeach()
+ endif()
+ endif()
+ endforeach()
+endmacro()
+
macro(build_subdir)
file(GLOB_RECURSE MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
list(SORT MODULES_SUBDIR_SRCS)
@@ -77,14 +105,15 @@ macro(build_subdir)
get_filename_component(DIR_NAME ${DEST} DIRECTORY)
get_filename_component(FOLDER_NAME ${DEST} NAME)
if(DIR_NAME)
- set(SO "${DIR_NAME}.${FOLDER_NAME}")
+ set(SO "anope_${DIR_NAME}.${FOLDER_NAME}")
else()
- set(SO "${FOLDER_NAME}")
+ set(SO "anope_${FOLDER_NAME}")
endif()
# Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though)
set_source_files_properties(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
+ set(DEPS)
# Iterate through the source files in the subdirectory
foreach(SRC ${MODULES_SUBDIR_SRCS})
# Reset linker flags
@@ -93,7 +122,7 @@ macro(build_subdir)
set(TEMP_DEPENDENCIES)
# Calculate the library dependencies for the given source file
calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES)
- calculate_dependencies(${SRC})
+ calculate_dependencies(${SRC} DEPS)
# Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append
if(TEMP_DEPENDENCIES)
@@ -119,13 +148,16 @@ macro(build_subdir)
endif()
# Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand
- add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS})
- set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON OUTPUT_NAME "${FOLDER_NAME}")
+ add_library(${SO} SHARED ${MODULES_SUBDIR_SRCS})
+ set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON OUTPUT_NAME "${DIR_NAME}_${FOLDER_NAME}")
add_dependencies(${SO} ${PROGRAM_NAME})
if(GETTEXT_FOUND)
add_dependencies(${SO} module_language)
endif()
target_link_libraries(${SO} ${SUBDIR_EXTRA_DEPENDS})
+ foreach(DEP ${DEPS})
+ target_link_libraries(${SO} ${DEP})
+ endforeach()
# For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set its version
if(WIN32)
target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
@@ -134,8 +166,9 @@ macro(build_subdir)
target_link_libraries(${SO} ${PROGRAM_NAME})
endif()
- install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules/${DIR_NAME})
+ install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules)
endmacro()
build_modules(${CMAKE_CURRENT_SOURCE_DIR})
+build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp
index 1d2755ad5..96e8b0821 100644
--- a/modules/botserv/assign.cpp
+++ b/modules/botserv/assign.cpp
@@ -227,8 +227,10 @@ class BSAssign : public Module
public:
BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::Invite>(this)
+ , EventHook<Event::ServiceBotEvent>(this)
- , nobot(this, botinfo, "BS_NOBOT")
+ , nobot(this, "BS_NOBOT")
, commandbsassign(this)
, commandbsunassign(this)
diff --git a/modules/botserv/autoassign.cpp b/modules/botserv/autoassign.cpp
index 8978499ed..4b5074abe 100644
--- a/modules/botserv/autoassign.cpp
+++ b/modules/botserv/autoassign.cpp
@@ -14,6 +14,7 @@ class BSAutoAssign : public Module
{
public:
BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChanRegistered>(this)
{
}
diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp
index afdc2e09f..94cf8803a 100644
--- a/modules/botserv/badwords.cpp
+++ b/modules/botserv/badwords.cpp
@@ -12,24 +12,25 @@
#include "module.h"
#include "modules/botserv/badwords.h"
-static EventHandlers<Event::BadWordEvents> *bwevents;
-
class BadWordImpl : public BadWord
{
+ friend class BadWordsType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string word;
+ BadWordType type;
+
public:
BadWordImpl(Serialize::TypeBase *type) : BadWord(type) { }
BadWordImpl(Serialize::TypeBase *type, Serialize::ID id) : BadWord(type, id) { }
ChanServ::Channel *GetChannel() override;
-
void SetChannel(ChanServ::Channel *c) override;
Anope::string GetWord() override;
-
void SetWord(const Anope::string &w) override;
BadWordType GetType() override;
-
void SetType(const BadWordType &t) override;
};
@@ -40,10 +41,10 @@ class BadWordsType : public Serialize::Type<BadWordImpl>
Serialize::Field<BadWordImpl, Anope::string> word;
Serialize::Field<BadWordImpl, BadWordType> type;
- BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me, "BadWord")
- , channel(this, "ci", true)
- , word(this, "word")
- , type(this, "type")
+ BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me)
+ , channel(this, "ci", &BadWordImpl::channel, true)
+ , word(this, "word", &BadWordImpl::word)
+ , type(this, "type", &BadWordImpl::type)
{
}
};
@@ -84,19 +85,19 @@ struct BadWordsImpl : BadWords
BadWord* AddBadWord(ChanServ::Channel *ci, const Anope::string &word, BadWordType type) override
{
- BadWord *bw = badword.Create();
+ BadWord *bw = Serialize::New<BadWord *>();
bw->SetChannel(ci);
bw->SetWord(word);
bw->SetType(type);
- (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw);
+ EventManager::Get()->Dispatch(&Event::BadWordEvents::OnBadWordAdd, ci, bw);
return bw;
}
std::vector<BadWord *> GetBadWords(ChanServ::Channel *ci) override
{
- return ci->GetRefs<BadWord *>(badword);
+ return ci->GetRefs<BadWord *>();
}
BadWord* GetBadWord(ChanServ::Channel *ci, unsigned index) override
@@ -117,7 +118,7 @@ struct BadWordsImpl : BadWords
return;
BadWord *bw = bws[index];
- (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, bw);
+ EventManager::Get()->Dispatch(&Event::BadWordEvents::OnBadWordDel, ci, bw);
delete bw;
}
@@ -131,7 +132,8 @@ struct BadWordsImpl : BadWords
class CommandBSBadwords : public Command
{
- private:
+ ServiceReference<BadWords> badwords;
+
void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word)
{
bool override = !source.AccessFor(ci).HasPriv("BADWORDS");
@@ -448,17 +450,14 @@ class BSBadwords : public Module
{
CommandBSBadwords commandbsbadwords;
BadWordsImpl badwords;
- EventHandlers<Event::BadWordEvents> events;
BadWordsType bwtype;
public:
BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
, commandbsbadwords(this)
, badwords(this)
- , events(this)
, bwtype(this)
{
- bwevents = &events;
}
};
diff --git a/modules/botserv/bot.cpp b/modules/botserv/bot.cpp
index b2630bfcb..027df87fa 100644
--- a/modules/botserv/bot.cpp
+++ b/modules/botserv/bot.cpp
@@ -14,10 +14,6 @@
class CommandBSBot : public Command
{
- EventHandlers<Event::BotCreate> OnBotCreate;
- EventHandlers<Event::BotChange> OnBotChange;
- EventHandlers<Event::BotDelete> OnBotDelete;
-
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &nick = params[1];
@@ -93,7 +89,7 @@ class CommandBSBot : public Command
source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname);
- this->OnBotCreate(&Event::BotCreate::OnBotCreate, bi);
+ EventManager::Get()->Dispatch(&Event::BotCreate::OnBotCreate, bi);
}
void DoChange(CommandSource &source, const std::vector<Anope::string> &params)
@@ -247,7 +243,7 @@ class CommandBSBot : public Command
source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname);
Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname;
- this->OnBotChange(&Event::BotChange::OnBotChange, bi);
+ EventManager::Get()->Dispatch(&Event::BotChange::OnBotChange, bi);
}
void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
@@ -273,7 +269,7 @@ class CommandBSBot : public Command
return;
}
- this->OnBotDelete(&Event::BotDelete::OnBotDelete, bi);
+ EventManager::Get()->Dispatch(&Event::BotDelete::OnBotDelete, bi);
Log(LOG_ADMIN, source, this) << "DEL " << bi->nick;
@@ -283,9 +279,6 @@ class CommandBSBot : public Command
public:
CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6)
- , OnBotCreate(creator)
- , OnBotChange(creator)
- , OnBotDelete(creator)
{
this->SetDesc(_("Maintains network bot list"));
this->SetSyntax(_("\002ADD \037nicknae\037 \037username\037 \037hostname\037 \037realname\037\002"));
diff --git a/modules/botserv/botlist.cpp b/modules/botserv/botlist.cpp
index ce899719e..26b23a9fc 100644
--- a/modules/botserv/botlist.cpp
+++ b/modules/botserv/botlist.cpp
@@ -26,7 +26,7 @@ class CommandBSBotList : public Command
list.AddColumn(_("Nick")).AddColumn(_("Mask"));
- for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo))
+ for (BotInfo *bi : Serialize::GetObjects<BotInfo *>())
{
if (source.HasPriv("botserv/administration") || !bi->GetOperOnly())
{
diff --git a/modules/botserv/info.cpp b/modules/botserv/info.cpp
index 19fe0a775..85100a4ec 100644
--- a/modules/botserv/info.cpp
+++ b/modules/botserv/info.cpp
@@ -16,10 +16,8 @@
class CommandBSInfo : public Command
{
- EventHandlers<Event::ServiceBotEvent> &onbotinfo;
-
public:
- CommandBSInfo(Module *creator, EventHandlers<Event::ServiceBotEvent> &event) : Command(creator, "botserv/info", 1, 1), onbotinfo(event)
+ CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1)
{
this->SetSyntax(_("{\037channel\037 | \037nickname\037}"));
}
@@ -41,7 +39,7 @@ class CommandBSInfo : public Command
info[_("Options")] = bi->bi->GetOperOnly() ? _("Private") : _("None");
info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)";
- this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info);
+ EventManager::Get()->Dispatch(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info);
std::vector<Anope::string> replies;
info.Process(replies);
@@ -72,7 +70,7 @@ class CommandBSInfo : public Command
Anope::string enabled = Language::Translate(source.nc, _("Enabled"));
Anope::string disabled = Language::Translate(source.nc, _("Disabled"));
- this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info);
+ EventManager::Get()->Dispatch(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info);
std::vector<Anope::string> replies;
info.Process(replies);
@@ -102,12 +100,10 @@ class CommandBSInfo : public Command
class BSInfo : public Module
{
CommandBSInfo commandbsinfo;
- EventHandlers<Event::ServiceBotEvent> onbotinfo;
public:
BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandbsinfo(this, onbotinfo)
- , onbotinfo(this)
+ , commandbsinfo(this)
{
}
diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp
index f61c7eb94..00fd36b88 100644
--- a/modules/botserv/kick.cpp
+++ b/modules/botserv/kick.cpp
@@ -1,14 +1,9 @@
/* BotServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
- *
- *
*/
#include "module.h"
@@ -35,6 +30,41 @@ enum TTBType
class KickerDataImpl : public KickerData
{
+ friend class KickerDataType;
+
+ ChanServ::Channel *channel = nullptr;
+
+ bool amsgs = false,
+ badwords = false,
+ bolds = false,
+ caps = false,
+ colors = false,
+ flood = false,
+ italics = false,
+ repeat = false,
+ reverses = false,
+ underlines = false;
+
+ int16_t ttb_bolds = 0,
+ ttb_colors = 0,
+ ttb_reverses = 0,
+ ttb_underlines = 0,
+ ttb_badwords = 0,
+ ttb_caps = 0,
+ ttb_flood = 0,
+ ttb_repeat = 0,
+ ttb_italics = 0,
+ ttb_amsgs = 0;
+
+ int16_t capsmin = 0,
+ capspercent = 0,
+ floodlines = 0,
+ floodsecs = 0,
+ repeattimes = 0;
+
+ bool dontkickops = false,
+ dontkickvoices = false;
+
public:
KickerDataImpl(Serialize::TypeBase *type) : KickerData(type) { }
KickerDataImpl(Serialize::TypeBase *type, Serialize::ID id) : KickerData(type, id) { }
@@ -128,42 +158,66 @@ class KickerDataType : public Serialize::Type<KickerDataImpl>
{
public:
Serialize::ObjectField<KickerDataImpl, ChanServ::Channel *> channel;
- Serialize::Field<KickerDataImpl, bool> amsgs, badwords, bolds, caps, colors, flood, italics, repeat, reverses, underlines;
- Serialize::Field<KickerDataImpl, int16_t> ttb_bolds, ttb_colors, ttb_reverses, ttb_underlines, ttb_badwords, ttb_caps, ttb_flood, ttb_repeat, ttb_italics, ttb_amsgs,
- capsmin, capspercent,
- floodlines, floodsecs,
- repeattimes;
- Serialize::Field<KickerDataImpl, bool> dontkickops, dontkickvoices;
-
- KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner, "KickerData")
- , channel(this, "channel", true)
- , amsgs(this, "amsgs")
- , badwords(this, "badwords")
- , bolds(this, "bolds")
- , caps(this, "caps")
- , colors(this, "colors")
- , flood(this, "flood")
- , italics(this, "italics")
- , repeat(this, "repeat")
- , reverses(this, "reverses")
- , underlines(this, "underlines")
- , ttb_bolds(this, "ttb_bolds")
- , ttb_colors(this, "ttb_colors")
- , ttb_reverses(this, "ttb_reverses")
- , ttb_underlines(this, "ttb_underlines")
- , ttb_badwords(this, "ttb_badwords")
- , ttb_caps(this, "ttb_caps")
- , ttb_flood(this, "ttb_flood")
- , ttb_repeat(this, "ttb_repeat")
- , ttb_italics(this, "ttb_italics")
- , ttb_amsgs(this, "ttb_amsgs")
- , capsmin(this, "capsmin")
- , capspercent(this, "capspercent")
- , floodlines(this, "floodlines")
- , floodsecs(this, "floodsecs")
- , repeattimes(this, "repeattimes")
- , dontkickops(this, "dontkickops")
- , dontkickvoices(this, "dontkickvoices")
+
+ Serialize::Field<KickerDataImpl, bool> amsgs,
+ badwords,
+ bolds,
+ caps,
+ colors,
+ flood,
+ italics,
+ repeat,
+ reverses,
+ underlines;
+
+ Serialize::Field<KickerDataImpl, int16_t> ttb_bolds,
+ ttb_colors,
+ ttb_reverses,
+ ttb_underlines,
+ ttb_badwords,
+ ttb_caps,
+ ttb_flood,
+ ttb_repeat,
+ ttb_italics,
+ ttb_amsgs,
+ capsmin,
+ capspercent,
+ floodlines,
+ floodsecs,
+ repeattimes;
+
+ Serialize::Field<KickerDataImpl, bool> dontkickops,
+ dontkickvoices;
+
+ KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner)
+ , channel(this, "channel", &KickerDataImpl::channel, true)
+ , amsgs(this, "amsgs", &KickerDataImpl::amsgs)
+ , badwords(this, "badwords", &KickerDataImpl::badwords)
+ , bolds(this, "bolds", &KickerDataImpl::bolds)
+ , caps(this, "caps", &KickerDataImpl::caps)
+ , colors(this, "colors", &KickerDataImpl::colors)
+ , flood(this, "flood", &KickerDataImpl::flood)
+ , italics(this, "italics", &KickerDataImpl::italics)
+ , repeat(this, "repeat", &KickerDataImpl::repeat)
+ , reverses(this, "reverses", &KickerDataImpl::reverses)
+ , underlines(this, "underlines", &KickerDataImpl::underlines)
+ , ttb_bolds(this, "ttb_bolds", &KickerDataImpl::ttb_bolds)
+ , ttb_colors(this, "ttb_colors", &KickerDataImpl::ttb_colors)
+ , ttb_reverses(this, "ttb_reverses", &KickerDataImpl::ttb_reverses)
+ , ttb_underlines(this, "ttb_underlines", &KickerDataImpl::ttb_underlines)
+ , ttb_badwords(this, "ttb_badwords", &KickerDataImpl::ttb_badwords)
+ , ttb_caps(this, "ttb_caps", &KickerDataImpl::ttb_caps)
+ , ttb_flood(this, "ttb_flood", &KickerDataImpl::ttb_flood)
+ , ttb_repeat(this, "ttb_repeat", &KickerDataImpl::ttb_repeat)
+ , ttb_italics(this, "ttb_italics", &KickerDataImpl::ttb_italics)
+ , ttb_amsgs(this, "ttb_amsgs", &KickerDataImpl::ttb_amsgs)
+ , capsmin(this, "capsmin", &KickerDataImpl::capsmin)
+ , capspercent(this, "capspercent", &KickerDataImpl::capspercent)
+ , floodlines(this, "floodlines", &KickerDataImpl::floodlines)
+ , floodsecs(this, "floodsecs", &KickerDataImpl::floodsecs)
+ , repeattimes(this, "repeattimes", &KickerDataImpl::repeattimes)
+ , dontkickops(this, "dontkickops", &KickerDataImpl::dontkickops)
+ , dontkickvoices(this, "dontkickvoices", &KickerDataImpl::dontkickvoices)
{
}
};
@@ -477,7 +531,7 @@ class CommandBSKick : public Command
if (c_name.find_ci(this_name + " ") == 0)
{
- ServiceReference<Command> command("Command", info.name);
+ ServiceReference<Command> command(info.name);
if (command)
{
source.command = c_name;
@@ -556,7 +610,7 @@ class CommandBSKickBase : public Command
void Process(CommandSource &source, ChanServ::Channel *ci, const Anope::string &param, const Anope::string &ttb, void (KickerData::*setter)(const bool &), void (KickerData::*ttbsetter)(const int16_t &), const Anope::string &optname)
{
- KickerData *kd = ci->GetRef<KickerData *>(kickerdata);
+ KickerData *kd = ci->GetRef<KickerData *>();
if (param.equals_ci("ON"))
{
@@ -1195,7 +1249,7 @@ class BanDataPurger : public Timer
{
bd->purge();
if (bd->empty())
- c->ShrinkOK<BanData>("bandata");
+ c->Shrink<BanData>("bandata");
}
}
}
@@ -1226,8 +1280,8 @@ class BSKick : public Module
CommandBSSetDontKickVoices commandbssetdontkickvoices;
BanDataPurger purger;
-
- EventHandlers<Event::BotBan> onbotban;
+
+ ServiceReference<BadWords> badwords;
BanData::Data &GetBanData(User *u, Channel *c)
{
@@ -1260,7 +1314,7 @@ class BSKick : public Module
Anope::string mask = ci->GetIdealBan(u);
ci->c->SetMode(NULL, "BAN", mask);
- this->onbotban(&Event::BotBan::OnBotBan, u, ci, mask);
+ EventManager::Get()->Dispatch(&Event::BotBan::OnBotBan, u, ci, mask);
}
if (!ci->c->FindUser(u))
@@ -1279,6 +1333,9 @@ class BSKick : public Module
public:
BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ServiceBotEvent>(this)
+ , EventHook<Event::Privmsg>(this)
+
, bandata(this, "bandata")
, userdata(this, "userdata")
@@ -1300,8 +1357,6 @@ class BSKick : public Module
, commandbssetdontkickvoices(this)
, purger(this)
-
- , onbotban(this)
{
me = this;
}
@@ -1313,7 +1368,7 @@ class BSKick : public Module
Anope::string enabled = Language::Translate(source.nc, _("Enabled"));
Anope::string disabled = Language::Translate(source.nc, _("Disabled"));
- KickerData *kd = ci->GetRef<KickerData *>(&kdtype);
+ KickerData *kd = ci->GetRef<KickerData *>();
if (kd && kd->GetBadwords())
{
@@ -1434,7 +1489,7 @@ class BSKick : public Module
ChanServ::Channel *ci = c->ci;
if (ci == NULL)
return;
- KickerData *kd = c->ci->GetRef<KickerData *>(&kdtype);
+ KickerData *kd = c->ci->GetRef<KickerData *>();
if (kd == NULL)
return;
diff --git a/modules/botserv/main/botserv.cpp b/modules/botserv/main/botserv.cpp
index 0b51691fc..a297db153 100644
--- a/modules/botserv/main/botserv.cpp
+++ b/modules/botserv/main/botserv.cpp
@@ -20,17 +20,25 @@ class BotServCore : public Module, public BotServ::BotServService
, public EventHook<Event::LeaveChannel>
, public EventHook<Event::Help>
, public EventHook<Event::ChannelModeSet>
- , public EventHook<Event::CreateChan>
+ , public EventHook<Event::ChanRegistered>
, public EventHook<Event::UserKicked>
, public EventHook<Event::CreateBot>
{
Reference<ServiceBot> BotServ;
- ExtensibleRef<bool> persist, inhabit;//XXX?
+ ExtensibleRef<bool> inhabit;
public:
BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
, BotServ::BotServService(this)
- , persist("PERSIST")
+ , EventHook<Event::SetCorrectModes>(this)
+ , EventHook<Event::BotAssign>(this)
+ , EventHook<Event::JoinChannel>(this)
+ , EventHook<Event::LeaveChannel>(this)
+ , EventHook<Event::Help>(this)
+ , EventHook<Event::ChannelModeSet>(this)
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::UserKicked>(this)
+ , EventHook<Event::CreateBot>(this)
, inhabit("inhabit")
{
}
@@ -119,7 +127,7 @@ class BotServCore : public Module, public BotServ::BotServService
void OnLeaveChannel(User *u, Channel *c) override
{
/* Channel is persistent, it shouldn't be deleted and the service bot should stay */
- if (c->ci && persist && persist->HasExt(c->ci))
+ if (c->ci && c->ci->HasFieldS("PERSIST"))
return;
/* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediately
@@ -132,9 +140,14 @@ class BotServCore : public Module, public BotServ::BotServService
if (inhabit && inhabit->HasExt(c))
return;
- /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */
- if (c->ci && c->ci->GetBot() && u != c->ci->GetBot() && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(c->ci->GetBot()))
- c->ci->GetBot()->Part(c->ci->c);
+ if (c->ci)
+ {
+ ServiceBot *bot = c->ci->GetBot();
+
+ /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */
+ if (bot && u != bot && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(bot))
+ bot->Part(c);
+ }
}
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
@@ -201,7 +214,7 @@ class BotServCore : public Module, public BotServ::BotServService
return EVENT_CONTINUE;
}
- void OnCreateChan(ChanServ::Channel *ci) override
+ void OnChanRegistered(ChanServ::Channel *ci) override
{
/* Set default bot flags */
spacesepstream sep(Config->GetModule(this)->Get<Anope::string>("defaults", "greet fantasy"));
diff --git a/modules/botserv/set.cpp b/modules/botserv/set.cpp
index b480108af..ee8426e65 100644
--- a/modules/botserv/set.cpp
+++ b/modules/botserv/set.cpp
@@ -40,7 +40,7 @@ class CommandBSSet : public Command
const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
- ServiceReference<Command> command("Command", info.name);
+ ServiceReference<Command> command(info.name);
if (command)
{
// XXX dup
@@ -203,6 +203,7 @@ class BSSet : public Module
public:
BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::BotBan>(this)
, commandbsset(this)
, commandbssetbanexpire(this)
, commandbssetprivate(this)
diff --git a/modules/chanserv/CMakeLists.txt b/modules/chanserv/CMakeLists.txt
index cd225a94d..afefd9d26 100644
--- a/modules/chanserv/CMakeLists.txt
+++ b/modules/chanserv/CMakeLists.txt
@@ -1 +1,3 @@
+#add_subdirs(${CMAKE_CURRENT_SOURCE_DIR})
build_modules(${CMAKE_CURRENT_SOURCE_DIR})
+build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/chanserv/cs_access.old b/modules/chanserv/access.cpp
index 8e35772a6..c7fc9bace 100644
--- a/modules/chanserv/cs_access.old
+++ b/modules/chanserv/access.cpp
@@ -1,26 +1,30 @@
/* ChanServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
*/
+/* Dependencies: anope_chanserv.main */
#include "module.h"
#include "modules/chanserv.h"
-#include "modules/cs_access.h"
-#include "main/chanaccess.h"
+#include "modules/chanserv/access.h"
+#include "modules/chanserv/main/chanaccess.h"
#include "main/chanaccesstype.h"
-class AccessChanAccess : public ChanAccessImpl
+class AccessChanAccessImpl : public AccessChanAccess
{
+ friend class AccessChanAccessType;
+
+ int level = 0;
+
public:
- AccessChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { }
- AccessChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { }
+ static constexpr const char *NAME = "accesschanaccess";
+
+ using AccessChanAccess::AccessChanAccess;
int GetLevel();
void SetLevel(const int &);
@@ -46,7 +50,6 @@ class AccessChanAccess : public ChanAccessImpl
}
}
-#if 0
bool operator>(ChanServ::ChanAccess &other) override
{
if (this->GetSerializableType() != other.GetSerializableType())
@@ -62,18 +65,17 @@ class AccessChanAccess : public ChanAccessImpl
else
return this->GetLevel() < anope_dynamic_static_cast<AccessChanAccess *>(&other)->GetLevel();
}
-#endif
};
-class AccessChanAccessType : public Serialize::Type<AccessChanAccess, ChanAccessType>
+class AccessChanAccessType : public ChanAccessType<AccessChanAccessImpl>
{
public:
- Serialize::Field<AccessChanAccess, int> level;
+ Serialize::Field<AccessChanAccessImpl, int> level;
- AccessChanAccessType(Module *me) : Serialize::Type<AccessChanAccess, ChanAccessType>(me, "AccessChanAccess")
- , level(this, "level")
+ AccessChanAccessType(Module *me) : ChanAccessType<AccessChanAccessImpl>(me)
+ , level(this, "level", &AccessChanAccessImpl::level)
{
- SetParent(ChanServ::chanaccess);
+ Serialize::SetParent(AccessChanAccess::NAME, ChanServ::ChanAccess::NAME);
}
};
@@ -121,75 +123,51 @@ class CommandCSAccess : public Command
ChanServ::AccessGroup u_access = source.AccessFor(ci);
ChanServ::ChanAccess *highest = u_access.Highest();
- AccessChanAccess tmp_access(nullptr);
- tmp_access.SetChannel(ci);
- tmp_access.SetLevel(level);
+ AccessChanAccess *access = Serialize::New<AccessChanAccess *>();
+ access->SetChannel(ci);
+ access->SetLevel(level);
bool override = false;
- if ((!highest || *highest <= tmp_access) && !u_access.founder)
+ if ((!highest || *highest <= *access) && !u_access.founder)
{
if (source.HasPriv("chanserv/access/modify"))
+ {
override = true;
+ }
else
{
source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to add someone at level \002{1}\002."), ci->GetName(), level);
+ access->Delete();
return;
}
}
- NickServ::Nick *na = nullptr;
- ChanServ::Channel *targ_ci = nullptr;
-
- if (IRCD->IsChannelValid(mask))
- {
- if (Config->GetModule("chanserv")->Get<bool>("disallow_channel_access"))
- {
- source.Reply(_("Channels may not be on access lists."));
- return;
- }
-
- targ_ci = ChanServ::Find(mask);
- if (targ_ci == NULL)
- {
- source.Reply(_("Channel \002{0}\002 isn't registered."), mask);
- return;
- }
+ access->Delete();
- if (ci == targ_ci)
- {
- source.Reply(_("You can't add a channel to its own access list."));
- return;
- }
+ NickServ::Nick *na = NickServ::FindNick(mask);
- mask = targ_ci->GetName();
- }
- else
+ if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access"))
{
- na = NickServ::FindNick(mask);
+ source.Reply(_("Masks and unregistered users may not be on access lists."));
+ return;
+ }
- if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access"))
+ if (mask.find_first_of("!*@") == Anope::string::npos && !na)
+ {
+ User *targ = User::Find(mask, true);
+ if (targ != NULL)
+ mask = "*!*@" + targ->GetDisplayedHost();
+ else
{
- source.Reply(_("Masks and unregistered users may not be on access lists."));
+ source.Reply(_("\002{0}\002 isn't registered."), mask);
return;
}
-
- if (mask.find_first_of("!*@") == Anope::string::npos && !na)
- {
- User *targ = User::Find(mask, true);
- if (targ != NULL)
- mask = "*!*@" + targ->GetDisplayedHost();
- else
- {
- source.Reply(_("\002{0}\002 isn't registered."), mask);
- return;
- }
- }
-
- if (na)
- mask = na->GetNick();
}
+ if (na)
+ mask = na->GetNick();
+
for (unsigned i = ci->GetAccessCount(); i > 0; --i)
{
ChanServ::ChanAccess *access = ci->GetAccess(i - 1);
@@ -207,17 +185,15 @@ class CommandCSAccess : public Command
}
unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
- if (access_max && ci->GetDeepAccessCount() >= access_max)
+ if (access_max && ci->GetAccessCount() >= access_max)
{
source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max);
return;
}
- AccessChanAccess *access = anope_dynamic_static_cast<AccessChanAccess *>(accesschanaccess.Create());
+ access = Serialize::New<AccessChanAccess *>();
if (na)
access->SetObj(na->GetAccount());
- else if (targ_ci)
- access->SetObj(targ_ci);
access->SetChannel(ci);
access->SetMask(mask);
access->SetCreator(source.GetNick());
@@ -225,7 +201,7 @@ class CommandCSAccess : public Command
access->SetLastSeen(0);
access->SetCreated(Anope::CurTime);
- Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access);
+ EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access);
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << " with level " << level;
if (p != NULL)
@@ -286,7 +262,7 @@ class CommandCSAccess : public Command
else
nicks = access->Mask();
- Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, access);
+ EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access);
delete access;
},
[&]()
@@ -324,7 +300,7 @@ class CommandCSAccess : public Command
bool override = !u_access.founder && !u_access.HasPriv("ACCESS_CHANGE") && !access->Mask().equals_ci(source.nc->GetDisplay());
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << access->Mask();
- Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, access);
+ EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access);
delete access;
}
return;
@@ -359,8 +335,7 @@ class CommandCSAccess : public Command
if (ci->c)
for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
{
- ChanServ::ChanAccess::Path p;
- if (access->Matches(cit->second->user, cit->second->user->Account(), p))
+ if (access->Matches(cit->second->user, cit->second->user->Account()))
timebuf = "Now";
}
if (timebuf.empty())
@@ -394,8 +369,7 @@ class CommandCSAccess : public Command
if (ci->c)
for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
{
- ChanServ::ChanAccess::Path p;
- if (access->Matches(cit->second->user, cit->second->user->Account(), p))
+ if (access->Matches(cit->second->user, cit->second->user->Account()))
timebuf = "Now";
}
if (timebuf.empty())
@@ -467,7 +441,7 @@ class CommandCSAccess : public Command
return;
}
- Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source);
+ EventManager::Get()->Dispatch(&Event::AccessClear::OnAccessClear, ci, source);
ci->ClearAccess();
@@ -513,9 +487,9 @@ class CommandCSAccess : public Command
has_access = true;
else if (is_list && source.HasPriv("chanserv/access/list"))
has_access = true;
- else if (is_list && source.AccessFor(ci).HasPriv("ACCESS_LIST"))
+ else if (is_list && access.HasPriv("ACCESS_LIST"))
has_access = true;
- else if (source.AccessFor(ci).HasPriv("ACCESS_CHANGE"))
+ else if (access.HasPriv("ACCESS_CHANGE"))
has_access = true;
else if (is_del)
{
@@ -689,7 +663,7 @@ class CommandCSLevels : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to set " << p->name << " to level " << level;
ci->SetLevel(p->name, level);
- this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, level);
+ EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, level);
if (level == ChanServ::ACCESS_FOUNDER)
source.Reply(_("Level for privilege \002{0}\002 on channel \002{1}\002 changed to \002founder only\002."), p->name, ci->GetName());
@@ -717,7 +691,7 @@ class CommandCSLevels : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable " << p->name;
ci->SetLevel(p->name, ChanServ::ACCESS_INVALID);
- this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID);
+ EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID);
source.Reply(_("Privileged \002{0}\002 disabled on channel \002{1}\002."), p->name, ci->GetName());
return;
@@ -772,15 +746,13 @@ class CommandCSLevels : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to reset all levels";
ci->ClearLevels();
- this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0);
+ EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0);
source.Reply(_("Levels for \002{0}\002 reset to defaults."), ci->GetName());
}
- EventHandlers<Event::LevelChange> &onlevelchange;
-
public:
- CommandCSLevels(Module *creator, EventHandlers<Event::LevelChange> &event) : Command(creator, "chanserv/levels", 2, 4), onlevelchange(event)
+ CommandCSLevels(Module *creator) : Command(creator, "chanserv/levels", 2, 4)
{
this->SetDesc(_("Redefine the meanings of access levels"));
this->SetSyntax(_("\037channel\037 SET \037privilege\037 \037level\037"));
@@ -905,14 +877,13 @@ class CSAccess : public Module
{
CommandCSAccess commandcsaccess;
CommandCSLevels commandcslevels;
- EventHandlers<Event::LevelChange> onlevelchange;
AccessChanAccessType accesschanaccesstype;
public:
CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::GroupCheckPriv>(this)
, commandcsaccess(this)
- , commandcslevels(this, onlevelchange)
- , onlevelchange(this)
+ , commandcslevels(this)
, accesschanaccesstype(this)
{
this->SetPermanent(true);
diff --git a/modules/chanserv/akick.cpp b/modules/chanserv/akick.cpp
index 68adec8df..24bf9bc2d 100644
--- a/modules/chanserv/akick.cpp
+++ b/modules/chanserv/akick.cpp
@@ -14,6 +14,13 @@
class AutoKickImpl : public AutoKick
{
+ friend class AutoKickType;
+
+ ChanServ::Channel *channel = nullptr;
+ NickServ::Account *account = nullptr;
+ Anope::string mask, reason, creator;
+ time_t addtime = 0, last_time = 0;
+
public:
AutoKickImpl(Serialize::TypeBase *type) : AutoKick(type) { }
AutoKickImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoKick(type, id) { }
@@ -54,14 +61,14 @@ class AutoKickType : public Serialize::Type<AutoKickImpl>
Serialize::Field<AutoKickImpl, time_t> last_time;
AutoKickType(Module *me)
- : Serialize::Type<AutoKickImpl>(me, "AutoKick")
- , ci(this, "ci", true)
- , mask(this, "mask")
- , nc(this, "nc", true)
- , reason(this, "reason")
- , creator(this, "creator")
- , addtime(this, "addtime")
- , last_time(this, "last_time")
+ : Serialize::Type<AutoKickImpl>(me)
+ , ci(this, "ci", &AutoKickImpl::channel, true)
+ , mask(this, "mask", &AutoKickImpl::mask)
+ , nc(this, "nc", &AutoKickImpl::account, true)
+ , reason(this, "reason", &AutoKickImpl::reason)
+ , creator(this, "creator", &AutoKickImpl::creator)
+ , addtime(this, "addtime", &AutoKickImpl::addtime)
+ , last_time(this, "last_time", &AutoKickImpl::last_time)
{
}
};
@@ -226,6 +233,7 @@ class CommandCSAKick : public Command
}
else if (ci->HasFieldS("PEACE"))
{
+#warning "peace"
#if 0
/* Match against all currently online users with equal or
* higher access. - Viper */
@@ -273,9 +281,9 @@ class CommandCSAKick : public Command
}
}
- if (ci->GetAkickCount() >= Config->GetModule(this->owner)->Get<unsigned>("autokickmax"))
+ if (ci->GetAkickCount() >= Config->GetModule(this->GetOwner())->Get<unsigned>("autokickmax"))
{
- source.Reply(_("Sorry, you can only have \002{0}\002 autokick masks on a channel."), Config->GetModule(this->owner)->Get<unsigned>("autokickmax"));
+ source.Reply(_("Sorry, you can only have \002{0}\002 autokick masks on a channel."), Config->GetModule(this->GetOwner())->Get<unsigned>("autokickmax"));
return;
}
@@ -287,7 +295,7 @@ class CommandCSAKick : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason;
- this->akickevents(&Event::Akick::OnAkickAdd, source, ci, ak);
+ EventManager::Get()->Dispatch(&Event::Akick::OnAkickAdd, source, ci, ak);
source.Reply(_("\002{0}\002 added to \002{1}\002 autokick list."), mask, ci->GetName());
@@ -318,7 +326,7 @@ class CommandCSAKick : public Command
AutoKick *ak = ci->GetAkick(number - 1);
- this->akickevents(&Event::Akick::OnAkickDel, source, ci, ak);
+ EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ak);
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << (ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask());
@@ -358,7 +366,7 @@ class CommandCSAKick : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask;
- this->akickevents(&Event::Akick::OnAkickDel, source, ci, ci->GetAkick(i));
+ EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ci->GetAkick(i));
delete ci->GetAkick(i);
@@ -520,10 +528,8 @@ class CommandCSAKick : public Command
source.Reply(_("The autokick list of \002{0}\002 has been cleared."), ci->GetName());
}
- EventHandlers<Event::Akick> &akickevents;
-
public:
- CommandCSAKick(Module *creator, EventHandlers<Event::Akick> &events) : Command(creator, "chanserv/akick", 2, 4), akickevents(events)
+ CommandCSAKick(Module *creator) : Command(creator, "chanserv/akick", 2, 4)
{
this->SetDesc(_("Maintain the AutoKick list"));
this->SetSyntax(_("\037channel\037 ADD {\037nick\037 | \037mask\037} [\037reason\037]"));
@@ -665,13 +671,12 @@ class CSAKick : public Module
, public EventHook<Event::CheckKick>
{
CommandCSAKick commandcsakick;
- EventHandlers<Event::Akick> akickevents;
AutoKickType akick_type;
public:
CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandcsakick(this, akickevents)
- , akickevents(this)
+ , EventHook<Event::CheckKick>(this)
+ , commandcsakick(this)
, akick_type(this)
{
}
diff --git a/modules/chanserv/clone.cpp b/modules/chanserv/clone.cpp
index 0cc1b2739..06b5c1a2b 100644
--- a/modules/chanserv/clone.cpp
+++ b/modules/chanserv/clone.cpp
@@ -15,6 +15,9 @@
class CommandCSClone : public Command
{
+ ServiceReference<BadWords> badwords;
+
+#warning "levels hasnt been merged"
#if 0
void CopyLevels(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci)
{
@@ -88,7 +91,7 @@ public:
if (what.empty())
{
target_ci->Delete();
- target_ci = ChanServ::channel.Create();
+ target_ci = Serialize::New<ChanServ::Channel *>();
target_ci->SetName(target);
ChanServ::registered_channel_map& map = ChanServ::service->GetChannels();
map[target_ci->GetName()] = target_ci;
@@ -115,9 +118,11 @@ public:
target_ci->SetLastTopicTime(target_ci->c->topic_time);
}
else
+ {
target_ci->SetLastTopicSetter(source.service->nick);
+ }
- Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, target_ci);
+ EventManager::Get()->Dispatch(&Event::ChanRegistered::OnChanRegistered, target_ci);
source.Reply(_("All settings from \002{0}\002 have been cloned to \002{0}\002."), channel, target);
}
@@ -134,7 +139,7 @@ public:
{
ChanServ::ChanAccess *taccess = ci->GetAccess(i);
- if (access_max && target_ci->GetDeepAccessCount() >= access_max)
+ if (access_max && target_ci->GetAccessCount() >= access_max)
break;
if (masks.count(taccess->Mask()))
diff --git a/modules/chanserv/drop.cpp b/modules/chanserv/drop.cpp
index cb2036694..bbda47dbf 100644
--- a/modules/chanserv/drop.cpp
+++ b/modules/chanserv/drop.cpp
@@ -14,10 +14,8 @@
class CommandCSDrop : public Command
{
- EventHandlers<Event::ChanDrop> &onchandrop;
-
public:
- CommandCSDrop(Module *creator, EventHandlers<Event::ChanDrop> &event) : Command(creator, "chanserv/drop", 1, 2), onchandrop(event)
+ CommandCSDrop(Module *creator) : Command(creator, "chanserv/drop", 1, 2)
{
this->SetDesc(_("Cancel the registration of a channel"));
this->SetSyntax(_("\037channel\037 \037channel\037"));
@@ -52,7 +50,7 @@ class CommandCSDrop : public Command
return;
}
- EventReturn MOD_RESULT = this->onchandrop(&Event::ChanDrop::OnChanDrop, source, ci);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChanDrop::OnChanDrop, source, ci);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -87,12 +85,10 @@ class CommandCSDrop : public Command
class CSDrop : public Module
{
CommandCSDrop commandcsdrop;
- EventHandlers<Event::ChanDrop> onchandrop;
public:
CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandcsdrop(this, onchandrop)
- , onchandrop(this)
+ , commandcsdrop(this)
{
}
diff --git a/modules/chanserv/entrymsg.cpp b/modules/chanserv/entrymsg.cpp
index ac46809fd..6abd6706a 100644
--- a/modules/chanserv/entrymsg.cpp
+++ b/modules/chanserv/entrymsg.cpp
@@ -14,6 +14,12 @@
class EntryMsgImpl : public EntryMsg
{
+ friend class EntryMsgType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string creator, message;
+ time_t when = 0;
+
public:
EntryMsgImpl(Serialize::TypeBase *type) : EntryMsg(type) { }
EntryMsgImpl(Serialize::TypeBase *type, Serialize::ID id) : EntryMsg(type, id) { }
@@ -38,11 +44,11 @@ class EntryMsgType : public Serialize::Type<EntryMsgImpl>
Serialize::Field<EntryMsgImpl, Anope::string> creator, message;
Serialize::Field<EntryMsgImpl, time_t> when;
- EntryMsgType(Module *me) : Serialize::Type<EntryMsgImpl>(me, "EntryMsg")
- , chan(this, "chan", true)
- , creator(this, "creator")
- , message(this, "message")
- , when(this, "when")
+ EntryMsgType(Module *me) : Serialize::Type<EntryMsgImpl>(me)
+ , chan(this, "chan", &EntryMsgImpl::channel, true)
+ , creator(this, "creator", &EntryMsgImpl::creator)
+ , message(this, "message", &EntryMsgImpl::message)
+ , when(this, "when", &EntryMsgImpl::when)
{
}
};
@@ -92,7 +98,7 @@ class CommandEntryMessage : public Command
private:
void DoList(CommandSource &source, ChanServ::Channel *ci)
{
- std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(entrymsg);
+ std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>();
if (messages.empty())
{
@@ -126,15 +132,15 @@ class CommandEntryMessage : public Command
void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message)
{
- std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(entrymsg);
+ std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>();
- if (messages.size() >= Config->GetModule(this->owner)->Get<unsigned>("maxentries"))
+ if (messages.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("maxentries"))
{
source.Reply(_("The entry message list for \002{0}\002 is full."), ci->GetName());
return;
}
- EntryMsg *msg = entrymsg.Create();
+ EntryMsg *msg = Serialize::New<EntryMsg *>();
msg->SetChannel(ci);
msg->SetCreator(source.GetNick());
msg->SetMessage(message);
@@ -144,7 +150,7 @@ class CommandEntryMessage : public Command
void DoDel(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message)
{
- std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(entrymsg);
+ std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>();
if (!message.is_pos_number_only())
source.Reply(("Entry message \002{0}\002 not found on channel \002{1}\002."), message, ci->GetName());
@@ -173,7 +179,7 @@ class CommandEntryMessage : public Command
void DoClear(CommandSource &source, ChanServ::Channel *ci)
{
- for (EntryMsg *e : ci->GetRefs<EntryMsg *>(entrymsg))
+ for (EntryMsg *e : ci->GetRefs<EntryMsg *>())
delete e;
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove all messages";
@@ -254,6 +260,7 @@ class CSEntryMessage : public Module
public:
CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::JoinChannel>(this)
, commandentrymsg(this)
, entrymsg_type(this)
{
@@ -262,7 +269,7 @@ class CSEntryMessage : public Module
void OnJoinChannel(User *u, Channel *c) override
{
if (u && c && c->ci && u->server->IsSynced())
- for (EntryMsg *msg : c->ci->GetRefs<EntryMsg *>(entrymsg))
+ for (EntryMsg *msg : c->ci->GetRefs<EntryMsg *>())
u->SendMessage(c->ci->WhoSends(), "[{0}] {1}", c->ci->GetName(), msg->GetMessage());
}
};
diff --git a/modules/chanserv/cs_flags.old b/modules/chanserv/flags.cpp
index 8bca8581f..cb6f68522 100644
--- a/modules/chanserv/cs_flags.old
+++ b/modules/chanserv/flags.cpp
@@ -5,25 +5,29 @@
*
* 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.
*/
+/* Dependencies: anope_chanserv.main */
+
#include "module.h"
-#include "modules/cs_access.h"
-#include "main/chanaccess.h"
+#include "modules/chanserv.h"
+#include "modules/chanserv/access.h"
+#include "modules/chanserv/main/chanaccess.h"
#include "main/chanaccesstype.h"
static std::map<Anope::string, char> defaultFlags;
-class FlagsChanAccess : public ChanAccessImpl
+class FlagsChanAccessImpl : public FlagsChanAccess
{
+ friend class FlagsChanAccessType;
+
+ Anope::string flags;
+
public:
- FlagsChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { }
- FlagsChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { }
+ using FlagsChanAccess::FlagsChanAccess;
- Anope::string GetFlags();
- void SetFlags(const Anope::string &);
+ const Anope::string &GetFlags() override;
+ void SetFlags(const Anope::string &) override;
bool HasPriv(const Anope::string &priv) override
{
@@ -43,7 +47,7 @@ class FlagsChanAccess : public ChanAccessImpl
static Anope::string DetermineFlags(ChanServ::ChanAccess *access)
{
- if (access->GetSerializableType()->GetName() != "FlagsChanAccess")
+ if (access->GetSerializableType()->GetName() != NAME)
return access->AccessSerialize();
std::set<char> buffer;
@@ -59,20 +63,19 @@ class FlagsChanAccess : public ChanAccessImpl
}
};
-class FlagsChanAccessType : public Serialize::Type<FlagsChanAccess, ChanAccessType>
+class FlagsChanAccessType : public ChanAccessType<FlagsChanAccessImpl>
{
public:
- Serialize::Field<FlagsChanAccess, Anope::string> flags;
- //Serialize::Field<FlagsChanAccess, std::set<char>>> flags; XXX?
+ Serialize::Field<FlagsChanAccessImpl, Anope::string> flags;
- FlagsChanAccessType(Module *me) : Serialize::Type<FlagsChanAccess, ChanAccessType>(me, "FlagsChanAccess")
- , flags(this, "flags")
+ FlagsChanAccessType(Module *me) : ChanAccessType<FlagsChanAccessImpl>(me)
+ , flags(this, "flags", &FlagsChanAccessImpl::flags)
{
- SetParent(ChanServ::chanaccess);
+ Serialize::SetParent(FlagsChanAccess::NAME, ChanServ::ChanAccess::NAME);
}
};
-Anope::string FlagsChanAccess::GetFlags()
+const Anope::string &FlagsChanAccess::GetFlags()
{
return Get(&FlagsChanAccessType::flags);
}
@@ -169,7 +172,7 @@ class CommandCSFlags : public Command
}
current = access;
- Anope::string cur_flags = FlagsChanAccess::DetermineFlags(access);
+ Anope::string cur_flags = FlagsChanAccessImpl::DetermineFlags(access);
for (unsigned j = cur_flags.length(); j > 0; --j)
current_flags.insert(cur_flags[j - 1]);
break;
@@ -177,7 +180,7 @@ class CommandCSFlags : public Command
}
unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
- if (access_max && ci->GetDeepAccessCount() >= access_max)
+ if (access_max && ci->GetAccessCount() >= access_max)
{
source.Reply(_("Sorry, you can only have \002{0}\002 access entries on a channel, including access entries from other channels."), access_max);
return;
@@ -252,7 +255,7 @@ class CommandCSFlags : public Command
{
if (current != NULL)
{
- Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, current);
+ EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, current);
delete current;
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask;
source.Reply(_("\002{0}\002 removed from the access list of \002{1}\002."), mask, ci->GetName());
@@ -264,7 +267,7 @@ class CommandCSFlags : public Command
return;
}
- FlagsChanAccess *access = anope_dynamic_static_cast<FlagsChanAccess *>(flagschanaccess.Create());
+ FlagsChanAccess *access = Serialize::New<FlagsChanAccess *>();
if (na)
access->SetObj(na->GetAccount());
else if (targ_ci)
@@ -279,7 +282,7 @@ class CommandCSFlags : public Command
if (current != NULL)
delete current;
- Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access);
+ EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access);
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to modify " << mask << "'s flags to " << access->AccessSerialize();
if (p != NULL)
@@ -311,7 +314,7 @@ class CommandCSFlags : public Command
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
{
ChanServ::ChanAccess *access = ci->GetAccess(i);
- const Anope::string &flags = FlagsChanAccess::DetermineFlags(access);
+ const Anope::string &flags = FlagsChanAccessImpl::DetermineFlags(access);
if (!arg.empty())
{
@@ -365,7 +368,7 @@ class CommandCSFlags : public Command
ci->ClearAccess();
- Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source);
+ EventManager::Get()->Dispatch(&Event::AccessClear::OnAccessClear, ci, source);
source.Reply(_("The access list of \002{0}\002 has been cleared."), ci->GetName());
diff --git a/modules/chanserv/info.cpp b/modules/chanserv/info.cpp
index 4f3895cc4..c48368598 100644
--- a/modules/chanserv/info.cpp
+++ b/modules/chanserv/info.cpp
@@ -14,10 +14,8 @@
class CommandCSInfo : public Command
{
- EventHandlers<Event::ChanInfo> &eventonchaninfo;
-
public:
- CommandCSInfo(Module *creator, EventHandlers<Event::ChanInfo> &event) : Command(creator, "chanserv/info", 1, 2), eventonchaninfo(event)
+ CommandCSInfo(Module *creator) : Command(creator, "chanserv/info", 1, 2)
{
this->SetDesc(_("Lists information about the specified registered channel"));
this->SetSyntax(_("\037channel\037"));
@@ -63,7 +61,7 @@ class CommandCSInfo : public Command
info[_("Ban type")] = stringify(ci->GetBanType());
}
- this->eventonchaninfo(&Event::ChanInfo::OnChanInfo, source, ci, info, show_all);
+ EventManager::Get()->Dispatch(&Event::ChanInfo::OnChanInfo, source, ci, info, show_all);
std::vector<Anope::string> replies;
info.Process(replies);
@@ -83,12 +81,10 @@ class CommandCSInfo : public Command
class CSInfo : public Module
{
CommandCSInfo commandcsinfo;
- EventHandlers<Event::ChanInfo> eventonchaninfo;
public:
CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandcsinfo(this, eventonchaninfo)
- , eventonchaninfo(this)
+ , commandcsinfo(this)
{
}
diff --git a/modules/chanserv/list.cpp b/modules/chanserv/list.cpp
index ad0460239..28ce5f7e6 100644
--- a/modules/chanserv/list.cpp
+++ b/modules/chanserv/list.cpp
@@ -16,6 +16,8 @@
class CommandCSList : public Command
{
+ ServiceReference<ModeLocks> mlocks;
+
public:
CommandCSList(Module *creator) : Command(creator, "chanserv/list", 1, 2)
{
@@ -68,7 +70,7 @@ class CommandCSList : public Command
}
Anope::string spattern = "#" + pattern;
- unsigned listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50");
+ unsigned listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50");
source.Reply(_("List of entries matching \002{0}\002:"), pattern);
@@ -194,7 +196,7 @@ class CommandCSSetPrivate : public Command
return;
}
- EventReturn MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -240,10 +242,11 @@ class CSList : public Module
CommandCSList commandcslist;
CommandCSSetPrivate commandcssetprivate;
- ExtensibleItem<bool> priv; // XXX
+ Serialize::Field<ChanServ::Channel, bool> priv;
public:
CSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChanInfo>(this)
, commandcslist(this)
, commandcssetprivate(this)
, priv(this, "CS_PRIVATE")
diff --git a/modules/chanserv/log.cpp b/modules/chanserv/log.cpp
index 43ed76291..b31d515f7 100644
--- a/modules/chanserv/log.cpp
+++ b/modules/chanserv/log.cpp
@@ -15,6 +15,12 @@
class LogSettingImpl : public LogSetting
{
+ friend class LogSettingType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string service_name, command_service, command_name, method, extra, creator;
+ time_t created = 0;
+
public:
LogSettingImpl(Serialize::TypeBase *type) : LogSetting(type) { }
LogSettingImpl(Serialize::TypeBase *type, Serialize::ID id) : LogSetting(type, id) { }
@@ -51,15 +57,15 @@ class LogSettingType : public Serialize::Type<LogSettingImpl>
Serialize::Field<LogSettingImpl, Anope::string> service_name, command_service, command_name, method, extra, creator;
Serialize::Field<LogSettingImpl, time_t> created;
- LogSettingType(Module *me) : Serialize::Type<LogSettingImpl>(me, "LogSetting")
- , ci(this, "ci", true)
- , service_name(this, "service_name")
- , command_service(this, "command_service")
- , command_name(this, "command_name")
- , method(this, "method")
- , extra(this, "extra")
- , creator(this, "creator")
- , created(this, "created")
+ LogSettingType(Module *me) : Serialize::Type<LogSettingImpl>(me)
+ , ci(this, "ci", &LogSettingImpl::channel, true)
+ , service_name(this, "service_name", &LogSettingImpl::service_name)
+ , command_service(this, "command_service", &LogSettingImpl::command_service)
+ , command_name(this, "command_name", &LogSettingImpl::command_name)
+ , method(this, "method", &LogSettingImpl::method)
+ , extra(this, "extra", &LogSettingImpl::extra)
+ , creator(this, "creator", &LogSettingImpl::creator)
+ , created(this, "created", &LogSettingImpl::created)
{
}
};
@@ -173,7 +179,7 @@ public:
if (params.size() == 1)
{
- std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>(logsetting);
+ std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>();
if (ls.empty())
{
source.Reply(_("There currently are no logging configurations for \002{0}\002."), ci->GetName());
@@ -235,7 +241,7 @@ public:
/* Get service name from command */
service_name = bi->commands[command_name].name;
}
- else if (ServiceReference<Command>("Command", command.lower()))
+ else if (ServiceReference<Command>(command.lower()))
{
/* This is the service name, don't use any specific command */
service_name = command;
@@ -263,7 +269,7 @@ public:
bool override = !source.AccessFor(ci).HasPriv("SET");
- std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>(logsetting);
+ std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>();
for (unsigned i = ls.size(); i > 0; --i)
{
LogSetting *log = ls[i - 1];
@@ -286,7 +292,7 @@ public:
}
}
- LogSetting *log = logsetting.Create();
+ LogSetting *log = Serialize::New<LogSetting *>();
log->SetChannel(ci);
log->SetServiceName(service_name);
if (bi)
@@ -335,6 +341,7 @@ class CSLog : public Module
{
CommandCSLog commandcslog;
LogSettingType logtype;
+ ServiceReference<MemoServ::MemoServService> memoserv;
struct LogDefault
{
@@ -345,6 +352,8 @@ class CSLog : public Module
public:
CSLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::Log>(this)
, commandcslog(this)
, logtype(this)
{
@@ -379,7 +388,7 @@ class CSLog : public Module
{
LogDefault &d = defaults[i];
- LogSetting *log = logsetting.Create();
+ LogSetting *log = Serialize::New<LogSetting *>();
log->SetChannel(ci);
if (!d.service.empty())
@@ -408,13 +417,13 @@ class CSLog : public Module
if (l->type != LOG_COMMAND || l->u == NULL || l->c == NULL || l->ci == NULL || !Me || !Me->IsSynced())
return;
- std::vector<LogSetting *> ls = l->ci->GetRefs<LogSetting *>(logsetting);
+ std::vector<LogSetting *> ls = l->ci->GetRefs<LogSetting *>();
for (unsigned i = 0; i < ls.size(); ++i)
{
LogSetting *log = ls[i];
/* wrong command */
- if (log->GetServiceName() != l->c->name)
+ if (log->GetServiceName() != l->c->GetName())
continue;
/* if a command name is given check the service and the command */
@@ -430,14 +439,15 @@ class CSLog : public Module
Anope::string buffer = l->u->nick + " used " + l->source->command.upper() + " " + l->buf.str();
- if (log->GetMethod().equals_ci("MEMO") && MemoServ::service && l->ci->WhoSends() != NULL)
- MemoServ::service->Send(l->ci->WhoSends()->nick, l->ci->GetName(), buffer, true);
+ if (log->GetMethod().equals_ci("MEMO") && memoserv && l->ci->WhoSends() != NULL)
+ memoserv->Send(l->ci->WhoSends()->nick, l->ci->GetName(), buffer, true);
else if (l->source->c)
/* Sending a channel message or notice in response to a fantasy command */;
else if (log->GetMethod().equals_ci("MESSAGE") && l->ci->c)
{
IRCD->SendPrivmsg(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, "%s", buffer.c_str());
- //l->ci->WhoSends()->lastmsg = Anope::CurTime; XXX
+#warning "fix idletimes"
+ //l->ci->WhoSends()->lastmsg = Anope::CurTime;
}
else if (log->GetMethod().equals_ci("NOTICE") && l->ci->c)
IRCD->SendNotice(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, "%s", buffer.c_str());
diff --git a/modules/chanserv/main/chanaccess.cpp b/modules/chanserv/main/chanaccess.cpp
index 1601260c2..4d70fb30b 100644
--- a/modules/chanserv/main/chanaccess.cpp
+++ b/modules/chanserv/main/chanaccess.cpp
@@ -1,65 +1,65 @@
#include "module.h"
-#include "chanaccess.h"
+#include "modules/chanserv/main/chanaccess.h"
#include "chanaccesstype.h"
ChanServ::Channel *ChanAccessImpl::GetChannel()
{
- return Get(&ChanAccessType::ci);
+ return Get(&ChanAccessType<ChanServ::ChanAccess>::ci);
}
void ChanAccessImpl::SetChannel(ChanServ::Channel *ci)
{
- Object::Set(&ChanAccessType::ci, ci);
+ Object::Set(&ChanAccessType<ChanServ::ChanAccess>::ci, ci);
}
Anope::string ChanAccessImpl::GetCreator()
{
- return Get(&ChanAccessType::creator);
+ return Get(&ChanAccessType<ChanServ::ChanAccess>::creator);
}
void ChanAccessImpl::SetCreator(const Anope::string &c)
{
- Object::Set(&ChanAccessType::creator, c);
+ Object::Set(&ChanAccessType<ChanServ::ChanAccess>::creator, c);
}
time_t ChanAccessImpl::GetLastSeen()
{
- return Get(&ChanAccessType::last_seen);
+ return Get(&ChanAccessType<ChanServ::ChanAccess>::last_seen);
}
void ChanAccessImpl::SetLastSeen(const time_t &t)
{
- Object::Set(&ChanAccessType::last_seen, t);
+ Object::Set(&ChanAccessType<ChanServ::ChanAccess>::last_seen, t);
}
time_t ChanAccessImpl::GetCreated()
{
- return Get(&ChanAccessType::created);
+ return Get(&ChanAccessType<ChanServ::ChanAccess>::created);
}
void ChanAccessImpl::SetCreated(const time_t &t)
{
- Object::Set(&ChanAccessType::created, t);
+ Object::Set(&ChanAccessType<ChanServ::ChanAccess>::created, t);
}
Anope::string ChanAccessImpl::GetMask()
{
- return Get(&ChanAccessType::mask);
+ return Get(&ChanAccessType<ChanServ::ChanAccess>::mask);
}
void ChanAccessImpl::SetMask(const Anope::string &n)
{
- Object::Set(&ChanAccessType::mask, n);
+ Object::Set(&ChanAccessType<ChanServ::ChanAccess>::mask, n);
}
Serialize::Object *ChanAccessImpl::GetObj()
{
- return Get(&ChanAccessType::obj);
+ return Get(&ChanAccessType<ChanServ::ChanAccess>::obj);
}
void ChanAccessImpl::SetObj(Serialize::Object *o)
{
- Object::Set(&ChanAccessType::obj, o);
+ Object::Set(&ChanAccessType<ChanServ::ChanAccess>::obj, o);
}
Anope::string ChanAccessImpl::Mask()
@@ -72,13 +72,13 @@ Anope::string ChanAccessImpl::Mask()
NickServ::Account *ChanAccessImpl::GetAccount()
{
- if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account)
+ if (!GetObj() || GetObj()->GetSerializableType()->GetName() != NickServ::Account::NAME)
return nullptr;
return anope_dynamic_static_cast<NickServ::Account *>(GetObj());
}
-bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p)
+bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc)
{
if (this->GetAccount())
return this->GetAccount() == acc;
@@ -93,35 +93,9 @@ bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p)
}
if (acc)
- for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>())
if (Anope::Match(na->GetNick(), this->Mask()))
return true;
- if (IRCD->IsChannelValid(this->Mask()))
- {
- ChanServ::Channel *tci = ChanServ::Find(this->Mask());
- if (tci)
- {
- for (unsigned i = 0; i < tci->GetAccessCount(); ++i)
- {
- ChanServ::ChanAccess *a = tci->GetAccess(i);
- std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(this, a);
-
- std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(this);
- for (; range.first != range.second; ++range.first)
- if (range.first->first == pair.first && range.first->second == pair.second)
- goto cont;
-
- p.first.insert(pair);
- if (a->Matches(u, acc, p))
- p.second.insert(pair);
-
- cont:;
- }
-
- return p.second.count(this) > 0;
- }
- }
-
return false;
}
diff --git a/modules/chanserv/main/chanaccesstype.h b/modules/chanserv/main/chanaccesstype.h
index ca8dc1b79..f679669f1 100644
--- a/modules/chanserv/main/chanaccesstype.h
+++ b/modules/chanserv/main/chanaccesstype.h
@@ -1,6 +1,9 @@
-class ChanAccessType : public Serialize::AbstractType
+template<typename T>
+class ChanAccessType : public Serialize::Type<T>
{
+ static_assert(std::is_base_of<ChanServ::ChanAccess, T>::value, "");
+
public:
Serialize::ObjectField<ChanServ::ChanAccess, ChanServ::Channel *> ci;
Serialize::Field<ChanServ::ChanAccess, Anope::string> mask;
@@ -9,13 +12,13 @@ class ChanAccessType : public Serialize::AbstractType
Serialize::Field<ChanServ::ChanAccess, time_t> last_seen;
Serialize::Field<ChanServ::ChanAccess, time_t> created;
- ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name)
- , ci(this, "ci", true)
- , mask(this, "mask")
- , obj(this, "obj", true)
- , creator(this, "creator")
- , last_seen(this, "last_seen")
- , created(this, "created")
+ ChanAccessType(Module *me) : Serialize::Type<T>(me)
+ , ci(this, "ci", &ChanServ::ChanAccess::channel, true)
+ , mask(this, "mask", &ChanServ::ChanAccess::mask)
+ , obj(this, "obj", &ChanServ::ChanAccess::object, true)
+ , creator(this, "creator", &ChanServ::ChanAccess::creator)
+ , last_seen(this, "last_seen", &ChanServ::ChanAccess::last_seen)
+ , created(this, "created", &ChanServ::ChanAccess::created)
{
}
};
diff --git a/modules/chanserv/main/channel.cpp b/modules/chanserv/main/channel.cpp
index 7190b8bd9..490a0306f 100644
--- a/modules/chanserv/main/channel.cpp
+++ b/modules/chanserv/main/channel.cpp
@@ -14,13 +14,6 @@
#include "channeltype.h"
#include "modules/chanserv/akick.h"
-ChannelImpl::ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname) : ChanServ::Channel(type)
-{
- SetName(chname);
- SetTimeRegistered(Anope::CurTime);
- SetLastUsed(Anope::CurTime);
-}
-
ChannelImpl::~ChannelImpl()
{
ChanServ::registered_channel_map& map = ChanServ::service->GetChannels();
@@ -29,7 +22,7 @@ ChannelImpl::~ChannelImpl()
void ChannelImpl::Delete()
{
- Event::OnDelChan(&Event::DelChan::OnDelChan, this);
+ EventManager::Get()->Dispatch(&Event::DelChan::OnDelChan, this);
Log(LOG_DEBUG) << "Deleting channel " << this->GetName();
@@ -165,7 +158,7 @@ void ChannelImpl::SetBot(ServiceBot *bi)
MemoServ::MemoInfo *ChannelImpl::GetMemos()
{
- return GetRef<MemoServ::MemoInfo *>(MemoServ::memoinfo);
+ return GetRef<MemoServ::MemoInfo *>();
}
void ChannelImpl::SetFounder(NickServ::Account *nc)
@@ -190,7 +183,7 @@ NickServ::Account *ChannelImpl::GetSuccessor()
ChanServ::ChanAccess *ChannelImpl::GetAccess(unsigned index)
{
- std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess);
+ std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>();
return a.size() > index ? a[index] : nullptr;
}
@@ -217,7 +210,7 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(const User *u, bool updateLastUsed)
for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
{
ChanServ::ChanAccess *a = this->GetAccess(i);
- if (a->Matches(u, u->Account(), group.path))
+ if (a->Matches(u, u->Account()))
group.push_back(a);
}
@@ -244,7 +237,7 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(NickServ::Account *nc, bool updateL
for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
{
ChanServ::ChanAccess *a = this->GetAccess(i);
- if (a->Matches(NULL, nc, group.path))
+ if (a->Matches(NULL, nc))
group.push_back(a);
}
@@ -259,45 +252,18 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(NickServ::Account *nc, bool updateL
unsigned ChannelImpl::GetAccessCount()
{
- return GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess).size();
-}
-
-unsigned ChannelImpl::GetDeepAccessCount() const
-{
- return 0;
-#if 0
- ChanServ::ChanAccess::Path path;
- for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
- {
- ChanServ::ChanAccess *a = this->GetAccess(i);
- a->Matches(NULL, NULL, path);
- }
-
- unsigned count = this->GetAccessCount();
- std::set<const ChanServ::Channel *> channels;
- channels.insert(this);
- for (ChanServ::ChanAccess::Set::iterator it = path.first.begin(); it != path.first.end(); ++it)
- {
- const ChanServ::Channel *ci = it->first->GetChannel();
- if (!channels.count(ci))
- {
- channels.count(ci);
- count += ci->GetAccessCount();
- }
- }
- return count;
-#endif
+ return GetRefs<ChanServ::ChanAccess *>().size();
}
void ChannelImpl::ClearAccess()
{
- for (ChanServ::ChanAccess *a : GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess))
+ for (ChanServ::ChanAccess *a : GetRefs<ChanServ::ChanAccess *>())
a->Delete();
}
AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t, time_t lu)
{
- AutoKick *ak = ::autokick.Create();
+ AutoKick *ak = Serialize::New<AutoKick *>();
ak->SetChannel(this);
ak->SetAccount(akicknc);
ak->SetReason(reason);
@@ -310,7 +276,7 @@ AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *ak
AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu)
{
- AutoKick *ak = ::autokick.Create();
+ AutoKick *ak = Serialize::New<AutoKick *>();
ak->SetChannel(this);
ak->SetMask(mask);
ak->SetReason(reason);
@@ -323,25 +289,25 @@ AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string &
AutoKick *ChannelImpl::GetAkick(unsigned index)
{
- std::vector<AutoKick *> a = GetRefs<AutoKick *>(autokick);
+ std::vector<AutoKick *> a = GetRefs<AutoKick *>();
return a.size() > index ? a[index] : nullptr;
}
unsigned ChannelImpl::GetAkickCount()
{
- std::vector<AutoKick *> t = GetRefs<AutoKick *>(autokick);
+ std::vector<AutoKick *> t = GetRefs<AutoKick *>();
return t.size();
}
void ChannelImpl::ClearAkick()
{
- for (AutoKick *ak : GetRefs<AutoKick *>(autokick))
+ for (AutoKick *ak : GetRefs<AutoKick *>())
ak->Delete();
}
int16_t ChannelImpl::GetLevel(const Anope::string &priv)
{
- for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level))
+ for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>())
if (l->GetName() == priv)
return l->GetLevel();
@@ -357,7 +323,7 @@ int16_t ChannelImpl::GetLevel(const Anope::string &priv)
void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level)
{
- for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level))
+ for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>())
if (l->GetName() == priv)
{
l->SetLevel(level);
@@ -371,7 +337,7 @@ void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level)
return;
}
- ChanServ::Level *l = ChanServ::level.Create();
+ ChanServ::Level *l = Serialize::New<ChanServ::Level *>();
l->SetChannel(this);
l->SetName(priv);
l->SetLevel(level);
@@ -379,7 +345,7 @@ void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level)
void ChannelImpl::RemoveLevel(const Anope::string &priv)
{
- for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level))
+ for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>())
if (l->GetName() == priv)
{
l->Delete();
@@ -389,7 +355,7 @@ void ChannelImpl::RemoveLevel(const Anope::string &priv)
void ChannelImpl::ClearLevels()
{
- for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level))
+ for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>())
l->Delete();
}
diff --git a/modules/chanserv/main/channel.h b/modules/chanserv/main/channel.h
index 86e42a8f9..801891821 100644
--- a/modules/chanserv/main/channel.h
+++ b/modules/chanserv/main/channel.h
@@ -2,10 +2,20 @@
class ChannelImpl : public ChanServ::Channel
{
+ friend class ChannelType;
+
+ NickServ::Account *founder = nullptr, *successor = nullptr;
+ Anope::string name, desc;
+ time_t time_registered = 0, last_used = 0;
+ Anope::string last_topic, last_topic_setter;
+ time_t last_topic_time = 0;
+ int16_t bantype = 0;
+ time_t banexpire = 0;
+ BotInfo *bi = nullptr;
+
public:
ChannelImpl(Serialize::TypeBase *type) : ChanServ::Channel(type) { }
ChannelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Channel(type, id) { }
- ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname);
~ChannelImpl();
void Delete() override;
@@ -44,16 +54,17 @@ class ChannelImpl : public ChanServ::Channel
MemoServ::MemoInfo *GetMemos() override;
- bool IsFounder(const User *user) override;
void SetFounder(NickServ::Account *nc) override;
NickServ::Account *GetFounder() override;
+
void SetSuccessor(NickServ::Account *nc) override;
NickServ::Account *GetSuccessor() override;
+
+ bool IsFounder(const User *user) override;
ChanServ::ChanAccess *GetAccess(unsigned index) /*const*/ override;
ChanServ::AccessGroup AccessFor(const User *u, bool = true) override;
ChanServ::AccessGroup AccessFor(NickServ::Account *nc, bool = true) override;
unsigned GetAccessCount()/* const*/ override;
- unsigned GetDeepAccessCount() const override;
void ClearAccess() override;
AutoKick* AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override;
AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override;
diff --git a/modules/chanserv/main/channeltype.cpp b/modules/chanserv/main/channeltype.cpp
index 4143285a8..0c65b1bb1 100644
--- a/modules/chanserv/main/channeltype.cpp
+++ b/modules/chanserv/main/channeltype.cpp
@@ -1,29 +1,29 @@
#include "module.h"
#include "channeltype.h"
-ChannelType::ChannelType(Module *me) : Serialize::Type<ChannelImpl>(me, "ChannelInfo")
- , name(this, "name")
- , desc(this, "desc")
- , time_registered(this, "time_registered")
- , last_used(this, "last_used")
- , last_topic(this, "last_topic")
- , last_topic_setter(this, "last_topic_setter")
- , last_topic_time(this, "last_topic_time")
- , bantype(this, "bantype")
- , banexpire(this, "banexpire")
- , founder(this, "founder")
- , successor(this, "successor")
- , bi(this, "bi")
+ChannelType::ChannelType(Module *me) : Serialize::Type<ChannelImpl>(me)
+ , name(this, "name", &ChannelImpl::name)
+ , desc(this, "desc", &ChannelImpl::desc)
+ , time_registered(this, "time_registered", &ChannelImpl::time_registered)
+ , last_used(this, "last_used", &ChannelImpl::last_used)
+ , last_topic(this, "last_topic", &ChannelImpl::last_topic)
+ , last_topic_setter(this, "last_topic_setter", &ChannelImpl::last_topic_setter)
+ , last_topic_time(this, "last_topic_time", &ChannelImpl::last_topic_time)
+ , bantype(this, "bantype", &ChannelImpl::bantype)
+ , banexpire(this, "banexpire", &ChannelImpl::banexpire)
+ , founder(this, "founder", &ChannelImpl::founder)
+ , successor(this, "successor", &ChannelImpl::successor)
+ , bi(this, "bi", &ChannelImpl::bi)
{
}
-void ChannelType::Name::SetField(ChanServ::Channel *c, const Anope::string &value)
+void ChannelType::Name::SetField(ChannelImpl *c, const Anope::string &value)
{
ChanServ::registered_channel_map& map = ChanServ::service->GetChannels();
map.erase(GetField(c));
- Serialize::Field<ChanServ::Channel, Anope::string>::SetField(c, value);
+ Serialize::Field<ChannelImpl, Anope::string>::SetField(c, value);
map[value] = c;
}
@@ -31,7 +31,7 @@ void ChannelType::Name::SetField(ChanServ::Channel *c, const Anope::string &valu
ChanServ::Channel *ChannelType::FindChannel(const Anope::string &chan)
{
Serialize::ID id;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->name, chan, id);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->name, chan, id);
if (result == EVENT_ALLOW)
return RequireID(id);
diff --git a/modules/chanserv/main/channeltype.h b/modules/chanserv/main/channeltype.h
index 7bc22a8f6..06d6410f8 100644
--- a/modules/chanserv/main/channeltype.h
+++ b/modules/chanserv/main/channeltype.h
@@ -4,29 +4,29 @@ class ChannelType : public Serialize::Type<ChannelImpl>
{
public:
/* Channel name */
- struct Name : Serialize::Field<ChanServ::Channel, Anope::string>
+ struct Name : Serialize::Field<ChannelImpl, Anope::string>
{
- using Serialize::Field<ChanServ::Channel, Anope::string>::Field;
+ using Serialize::Field<ChannelImpl, Anope::string>::Field;
- void SetField(ChanServ::Channel *c, const Anope::string &value) override;
+ void SetField(ChannelImpl *c, const Anope::string &value) override;
} name;
- Serialize::Field<ChanServ::Channel, Anope::string> desc;
- Serialize::Field<ChanServ::Channel, time_t> time_registered;
- Serialize::Field<ChanServ::Channel, time_t> last_used;
+ Serialize::Field<ChannelImpl, Anope::string> desc;
+ Serialize::Field<ChannelImpl, time_t> time_registered;
+ Serialize::Field<ChannelImpl, time_t> last_used;
- Serialize::Field<ChanServ::Channel, Anope::string> last_topic;
- Serialize::Field<ChanServ::Channel, Anope::string> last_topic_setter;
- Serialize::Field<ChanServ::Channel, time_t> last_topic_time;
+ Serialize::Field<ChannelImpl, Anope::string> last_topic;
+ Serialize::Field<ChannelImpl, Anope::string> last_topic_setter;
+ Serialize::Field<ChannelImpl, time_t> last_topic_time;
- Serialize::Field<ChanServ::Channel, int16_t> bantype;
- Serialize::Field<ChanServ::Channel, time_t> banexpire;
+ Serialize::Field<ChannelImpl, int16_t> bantype;
+ Serialize::Field<ChannelImpl, time_t> banexpire;
/* Channel founder */
- Serialize::ObjectField<ChanServ::Channel, NickServ::Account *> founder;
+ Serialize::ObjectField<ChannelImpl, NickServ::Account *> founder;
/* Who gets the channel if the founder nick is dropped or expires */
- Serialize::ObjectField<ChanServ::Channel, NickServ::Account *> successor;
+ Serialize::ObjectField<ChannelImpl, NickServ::Account *> successor;
- Serialize::ObjectField<ChanServ::Channel, BotInfo *> bi;
+ Serialize::ObjectField<ChannelImpl, BotInfo *> bi;
ChannelType(Module *);
diff --git a/modules/chanserv/main/chanserv.cpp b/modules/chanserv/main/chanserv.cpp
index 9336b7c53..f579ec0ae 100644
--- a/modules/chanserv/main/chanserv.cpp
+++ b/modules/chanserv/main/chanserv.cpp
@@ -20,7 +20,7 @@
#include "leveltype.h"
#include "modetype.h"
#include "chanaccesstype.h"
-#include "chanaccess.h"
+#include "modules/chanserv/main/chanaccess.h"
class ChanServCore : public Module
, public ChanServ::ChanServService
@@ -31,7 +31,6 @@ class ChanServCore : public Module
, public EventHook<Event::DelChan>
, public EventHook<Event::Help>
, public EventHook<Event::CheckModes>
- , public EventHook<Event::CreateChan>
, public EventHook<Event::CanSet>
, public EventHook<Event::ChannelSync>
, public EventHook<Event::Log>
@@ -47,30 +46,48 @@ class ChanServCore : public Module
Reference<ServiceBot> ChanServ;
std::vector<Anope::string> defaults;
ExtensibleItem<bool> inhabit;
- ExtensibleRef<bool> persist;//XXX?
bool always_lower;
- EventHandlers<ChanServ::Event::PreChanExpire> OnPreChanExpire;
- EventHandlers<ChanServ::Event::ChanExpire> OnChanExpire;
std::vector<ChanServ::Privilege> Privileges;
ChanServ::registered_channel_map registered_channels;
ChannelType channel_type;
- ChanAccessType chanaccess_type;
+// ChanAccessType chanaccess_type;
LevelType level_type;
CSModeType mode_type;
public:
ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
, ChanServService(this)
+ , EventHook<Event::ChannelCreate>(this)
+ , EventHook<Event::BotDelete>(this)
+ , EventHook<Event::BotPrivmsg>(this)
+ , EventHook<Event::DelCore>(this)
+ , EventHook<Event::DelChan>(this)
+ , EventHook<Event::Help>(this)
+ , EventHook<Event::CheckModes>(this)
+ , EventHook<Event::CanSet>(this)
+ , EventHook<Event::ChannelSync>(this)
+ , EventHook<Event::Log>(this)
+ , EventHook<Event::ExpireTick>(this)
+ , EventHook<Event::CheckDelete>(this)
+ , EventHook<Event::PreUplinkSync>(this)
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::JoinChannel>(this)
+ , EventHook<Event::ChannelModeSet>(this)
+ , EventHook<Event::ChanInfo>(this)
+ , EventHook<Event::SetCorrectModes>(this)
, inhabit(this, "inhabit")
- , persist("PERSIST")
, always_lower(false)
- , OnPreChanExpire(this)
- , OnChanExpire(this)
, channel_type(this)
- , chanaccess_type(this, "ChanAccess")
+// , chanaccess_type(this)
, level_type(this)
, mode_type(this)
{
+ ChanServ::service = this;
+ }
+
+ ~ChanServCore()
+ {
+ ChanServ::service = nullptr;
}
ChanServ::Channel *Find(const Anope::string &name) override
@@ -143,7 +160,7 @@ class ChanServCore : public Module
if (inhabit.HasExt(c))
return;
- new ChanServTimer(ChanServ, inhabit, this->owner, c);
+ new ChanServTimer(ChanServ, inhabit, this, c);
}
void AddPrivilege(ChanServ::Privilege p) override
@@ -265,7 +282,7 @@ class ChanServCore : public Module
void OnDelCore(NickServ::Account *nc) override
{
unsigned int max_reg = Config->GetModule(this)->Get<unsigned int>("maxregistered");
- for (ChanServ::Channel *ci : nc->GetRefs<ChanServ::Channel *>(ChanServ::channel))
+ for (ChanServ::Channel *ci : nc->GetRefs<ChanServ::Channel *>())
{
if (ci->GetFounder() == nc)
{
@@ -336,7 +353,7 @@ class ChanServCore : public Module
{
/* remove access entries that are this channel */
- for (ChanServ::Channel *c : ci->GetRefs<ChanServ::Channel *>(ChanServ::channel))
+ for (ChanServ::Channel *c : ci->GetRefs<ChanServ::Channel *>())
{
for (unsigned j = 0; j < c->GetAccessCount(); ++j)
{
@@ -412,13 +429,6 @@ class ChanServCore : public Module
}
}
- void OnCreateChan(ChanServ::Channel *ci) override
- {
- /* Set default chan flags */
- for (unsigned i = 0; i < defaults.size(); ++i)
- ci->SetS<bool>(defaults[i].upper(), true);
- }
-
EventReturn OnCanSet(User *u, const ChannelMode *cm) override
{
if (Config->GetModule(this)->Get<Anope::string>("nomlock").find(cm->mchar) != Anope::string::npos
@@ -429,7 +439,7 @@ class ChanServCore : public Module
void OnChannelSync(Channel *c) override
{
- bool perm = c->HasMode("PERM") || (c->ci && persist && persist->HasExt(c->ci));
+ bool perm = c->HasMode("PERM") || (c->ci && c->ci->HasFieldS("PERSIST"));
if (!perm && !c->botchannel && (c->users.empty() || (c->users.size() == 1 && c->users.begin()->second->user->server == Me)))
{
this->Hold(c);
@@ -466,12 +476,12 @@ class ChanServCore : public Module
expire = true;
}
- this->OnPreChanExpire(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire);
+ EventManager::Get()->Dispatch(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire);
if (expire)
{
::Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->GetName() << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "(none)") << ")";
- this->OnChanExpire(&ChanServ::Event::ChanExpire::OnChanExpire, ci);
+ EventManager::Get()->Dispatch(&ChanServ::Event::ChanExpire::OnChanExpire, ci);
delete ci;
}
}
@@ -488,12 +498,10 @@ class ChanServCore : public Module
void OnPreUplinkSync(Server *serv) override
{
- if (!persist)
- return;
/* Find all persistent channels and create them, as we are about to finish burst to our uplink */
for (ChanServ::Channel *ci : channel_type.List<ChanServ::Channel *>())
{
- if (persist->HasExt(ci))
+ if (ci->HasFieldS("PERSIST"))
{
bool c;
ci->c = Channel::FindOrCreate(ci->GetName(), c, ci->GetTimeRegistered());
@@ -521,13 +529,17 @@ class ChanServCore : public Module
void OnChanRegistered(ChanServ::Channel *ci) override
{
- if (!persist || !ci->c)
+ /* Set default chan flags */
+ for (unsigned i = 0; i < defaults.size(); ++i)
+ ci->SetS<bool>(defaults[i].upper(), true);
+
+ if (!ci->c)
return;
/* Mark the channel as persistent */
if (ci->c->HasMode("PERM"))
- persist->Set(ci, true);
+ ci->SetS("PERSIST", true);
/* Persist may be in def cflags, set it here */
- else if (persist->HasExt(ci))
+ else if (ci->HasFieldS("PERSIST"))
ci->c->SetMode(NULL, "PERM");
}
diff --git a/modules/chanserv/main/level.h b/modules/chanserv/main/level.h
index 4521fceef..6c6397270 100644
--- a/modules/chanserv/main/level.h
+++ b/modules/chanserv/main/level.h
@@ -1,6 +1,12 @@
class LevelImpl : public ChanServ::Level
{
+ friend class LevelType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string name;
+ int level = 0;
+
public:
LevelImpl(Serialize::TypeBase *type) : ChanServ::Level(type) { }
LevelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Level(type, id) { }
diff --git a/modules/chanserv/main/leveltype.h b/modules/chanserv/main/leveltype.h
index 12e4c132f..ad6962f42 100644
--- a/modules/chanserv/main/leveltype.h
+++ b/modules/chanserv/main/leveltype.h
@@ -7,10 +7,10 @@ class LevelType : public Serialize::Type<LevelImpl>
Serialize::Field<LevelImpl, Anope::string> name;
Serialize::Field<LevelImpl, int> level;
- LevelType(Module *creator) : Serialize::Type<LevelImpl>(creator, "Level")
- , channel(this, "channel", true)
- , name(this, "name")
- , level(this, "level")
+ LevelType(Module *creator) : Serialize::Type<LevelImpl>(creator)
+ , channel(this, "channel", &LevelImpl::channel, true)
+ , name(this, "name", &LevelImpl::name)
+ , level(this, "level", &LevelImpl::level)
{
}
};
diff --git a/modules/chanserv/main/mode.h b/modules/chanserv/main/mode.h
index cd94e5ad1..8923a18ae 100644
--- a/modules/chanserv/main/mode.h
+++ b/modules/chanserv/main/mode.h
@@ -1,6 +1,11 @@
class ModeImpl : public ChanServ::Mode
{
+ friend class CSModeType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string mode, param;
+
public:
ModeImpl(Serialize::TypeBase *type) : ChanServ::Mode(type) { }
ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Mode(type, id) { }
diff --git a/modules/chanserv/main/modetype.h b/modules/chanserv/main/modetype.h
index b30c0491f..b03764e32 100644
--- a/modules/chanserv/main/modetype.h
+++ b/modules/chanserv/main/modetype.h
@@ -6,10 +6,10 @@ class CSModeType : public Serialize::Type<ModeImpl>
Serialize::ObjectField<ModeImpl, ChanServ::Channel *> channel;
Serialize::Field<ModeImpl, Anope::string> mode, param;
- CSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator, "CSKeepMode")
- , channel(this, "channel", true)
- , mode(this, "mode")
- , param(this, "param")
+ CSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator)
+ , channel(this, "channel", &ModeImpl::channel, true)
+ , mode(this, "mode", &ModeImpl::mode)
+ , param(this, "param", &ModeImpl::param)
{
}
};
diff --git a/modules/chanserv/mode.cpp b/modules/chanserv/mode.cpp
index eb1350e5a..529f02727 100644
--- a/modules/chanserv/mode.cpp
+++ b/modules/chanserv/mode.cpp
@@ -13,10 +13,15 @@
#include "modules/chanserv/mode.h"
#include "modules/chanserv/info.h"
-static EventHandlers<Event::MLockEvents> *events;
-
class ModeLockImpl : public ModeLock
{
+ friend class ModeLockType;
+
+ ChanServ::Channel *channel = nullptr;
+ bool set = false;
+ Anope::string name, param, setter;
+ time_t created = 0;
+
public:
ModeLockImpl(Serialize::TypeBase *type) : ModeLock(type) { }
ModeLockImpl(Serialize::TypeBase *type, Serialize::ID id) : ModeLock(type, id) { }
@@ -48,13 +53,13 @@ class ModeLockType : public Serialize::Type<ModeLockImpl>
Serialize::Field<ModeLockImpl, Anope::string> name, param, setter;
Serialize::Field<ModeLockImpl, time_t> created;
- ModeLockType(Module *me) : Serialize::Type<ModeLockImpl>(me, "ModeLock")
- , ci(this, "ci", true)
- , set(this, "set")
- , name(this, "name")
- , param(this, "param")
- , setter(this, "setter")
- , created(this, "created")
+ ModeLockType(Module *me) : Serialize::Type<ModeLockImpl>(me)
+ , ci(this, "ci", &ModeLockImpl::channel, true)
+ , set(this, "set", &ModeLockImpl::set)
+ , name(this, "name", &ModeLockImpl::name)
+ , param(this, "param", &ModeLockImpl::param)
+ , setter(this, "setter", &ModeLockImpl::setter)
+ , created(this, "created", &ModeLockImpl::created)
{
}
};
@@ -129,14 +134,14 @@ class ModeLocksImpl : public ModeLocks
if (!mode)
return false;
- for (ModeLock *ml : ci->GetRefs<ModeLock *>(modelock))
+ for (ModeLock *ml : ci->GetRefs<ModeLock *>())
if (ml->GetName() == mode->name && ml->GetSet() == status && ml->GetParam() == param)
return true;
return false;
}
- bool SetMLock(ChanServ::Channel *ci, ChannelMode *mode, bool status, const Anope::string &param, Anope::string setter, time_t created = Anope::CurTime) override
+ bool SetMLock(ChanServ::Channel *ci, ChannelMode *mode, bool status, const Anope::string &param = "", Anope::string setter = "", time_t created = Anope::CurTime) override
{
if (!mode)
return false;
@@ -146,16 +151,15 @@ class ModeLocksImpl : public ModeLocks
if (setter.empty())
setter = ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "Unknown";
- ModeLock *ml = modelock.Create();
+ ModeLock *ml = Serialize::New<ModeLock *>();
ml->SetChannel(ci);
ml->SetSet(status);
- ml->SetName(name);
+ ml->SetName(mode->name);
ml->SetParam(param);
ml->SetSetter(setter);
ml->SetCreated(created);
- EventReturn MOD_RESULT;
- MOD_RESULT = (*events)(&Event::MLockEvents::OnMLock, ci, ml);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::MLockEvents::OnMLock, ci, ml);
if (MOD_RESULT == EVENT_STOP)
{
delete ml;
@@ -170,7 +174,7 @@ class ModeLocksImpl : public ModeLocks
if (!mode)
return false;
- for (ModeLock *m : ci->GetRefs<ModeLockImpl *>(modelock))
+ for (ModeLock *m : ci->GetRefs<ModeLockImpl *>())
if (m->GetName() == mode->name)
{
// For list or status modes, we must check the parameter
@@ -178,8 +182,7 @@ class ModeLocksImpl : public ModeLocks
if (m->GetParam() != param)
continue;
- EventReturn MOD_RESULT;
- MOD_RESULT = (*events)(&Event::MLockEvents::OnUnMLock, ci, m);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::MLockEvents::OnUnMLock, ci, m);
if (MOD_RESULT == EVENT_STOP)
break;
@@ -192,19 +195,19 @@ class ModeLocksImpl : public ModeLocks
void ClearMLock(ChanServ::Channel *ci) override
{
- for (ModeLock *m : ci->GetRefs<ModeLock *>(modelock))
+ for (ModeLock *m : ci->GetRefs<ModeLock *>())
delete m;
}
ModeList GetMLock(ChanServ::Channel *ci) const override
{
- return ci->GetRefs<ModeLock *>(modelock);
+ return ci->GetRefs<ModeLock *>();
}
std::list<ModeLock *> GetModeLockList(ChanServ::Channel *ci, const Anope::string &name) override
{
std::list<ModeLock *> mlist;
- for (ModeLock *m : ci->GetRefs<ModeLock *>(modelock))
+ for (ModeLock *m : ci->GetRefs<ModeLock *>())
if (m->GetName() == name)
mlist.push_back(m);
return mlist;
@@ -212,7 +215,7 @@ class ModeLocksImpl : public ModeLocks
ModeLock *GetMLock(ChanServ::Channel *ci, const Anope::string &mname, const Anope::string &param = "") override
{
- for (ModeLock *m : ci->GetRefs<ModeLock *>(modelock))
+ for (ModeLock *m : ci->GetRefs<ModeLock *>())
if (m->GetName() == mname && m->GetParam() == param)
return m;
@@ -223,7 +226,7 @@ class ModeLocksImpl : public ModeLocks
{
Anope::string pos = "+", neg = "-", params;
- for (ModeLock *ml : ci->GetRefs<ModeLock *>(modelock))
+ for (ModeLock *ml : ci->GetRefs<ModeLock *>())
{
ChannelMode *cm = ModeManager::FindChannelModeByName(ml->GetName());
@@ -250,6 +253,8 @@ class ModeLocksImpl : public ModeLocks
class CommandCSMode : public Command
{
+ ServiceReference<ModeLocks> mlocks;
+
bool CanSet(CommandSource &source, ChanServ::Channel *ci, ChannelMode *cm, bool self)
{
if (!ci || !cm || cm->type != MODE_STATUS)
@@ -321,7 +326,7 @@ class CommandCSMode : public Command
source.Reply(_("Missing parameter for mode \002{0}\002."), cm->mchar);
else if (cm->type == MODE_LIST && ci->c && IRCD->GetMaxListFor(ci->c) && ci->c->HasMode(cm->name) >= IRCD->GetMaxListFor(ci->c))
source.Reply(_("List for mode \002{0}\002 is full."), cm->mchar);
- else if (ci->GetRefs<ModeLock *>(modelock).size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "32"))
+ else if (ci->GetRefs<ModeLock *>().size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("max", "32"))
source.Reply(_("The mode lock list of \002{0}\002 is full."), ci->GetName());
else
{
@@ -854,17 +859,16 @@ class CSMode : public Module
ModeLocksImpl modelock;
ModeLockType modelock_type;
- EventHandlers<Event::MLockEvents> modelockevents;
-
public:
CSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::CheckModes>(this)
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::ChanInfo>(this)
, commandcsmode(this)
, commandcsmodes(this)
, modelock(this)
, modelock_type(this)
- , modelockevents(this)
{
- events = &modelockevents;
}
void OnReload(Configuration::Conf *conf) override
@@ -896,7 +900,7 @@ class CSMode : public Module
if (!c || !c->ci)
return;
- ModeLocks::ModeList locks = mlocks->GetMLock(c->ci);
+ ModeLocks::ModeList locks = modelock.GetMLock(c->ci);
for (ModeLock *ml : locks)
{
ChannelMode *cm = ModeManager::FindChannelModeByName(ml->GetName());
@@ -980,7 +984,7 @@ class CSMode : public Module
continue;
}
- mlocks->SetMLock(ci, cm, add, param);
+ modelock.SetMLock(ci, cm, add, param);
}
}
}
@@ -990,7 +994,7 @@ class CSMode : public Module
if (!show_hidden)
return;
- const Anope::string &m = mlocks->GetMLockAsString(ci, true);
+ const Anope::string &m = modelock.GetMLockAsString(ci, true);
if (!m.empty())
info[_("Mode lock")] = m;
}
diff --git a/modules/chanserv/register.cpp b/modules/chanserv/register.cpp
index eb2832074..f342ba43b 100644
--- a/modules/chanserv/register.cpp
+++ b/modules/chanserv/register.cpp
@@ -88,12 +88,19 @@ class CommandCSRegister : public Command
return;
}
- if (!ChanServ::service)
+ ci = Serialize::New<ChanServ::Channel *>();
+ if (ci == nullptr)
return;
- ci = ChanServ::channel.Create();
+
ci->SetName(chan);
ci->SetFounder(nc);
ci->SetDesc(chdesc);
+ ci->SetTimeRegistered(Anope::CurTime);
+ ci->SetLastUsed(Anope::CurTime);
+ ci->SetBanType(2);
+
+ ci->c = c; // XXX? this isnt set on reconstrubted objects?
+ c->ci = ci;
if (c && !c->topic.empty())
{
@@ -102,7 +109,9 @@ class CommandCSRegister : public Command
ci->SetLastTopicTime(c->topic_time);
}
else
+ {
ci->SetLastTopicSetter(source.service->nick);
+ }
Log(LOG_COMMAND, source, this, ci);
source.Reply(_("Channel \002{0}\002 registered under your account: \002{1}\002"), chan, nc->GetDisplay());
@@ -114,7 +123,7 @@ class CommandCSRegister : public Command
if (u)
c->SetCorrectModes(u, true);
- Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, ci);
+ EventManager::Get()->Dispatch(&Event::ChanRegistered::OnChanRegistered, ci);
}
}
diff --git a/modules/chanserv/seen.cpp b/modules/chanserv/seen.cpp
index b97ffe238..7a5cd80c1 100644
--- a/modules/chanserv/seen.cpp
+++ b/modules/chanserv/seen.cpp
@@ -10,6 +10,7 @@
*/
+#warning "this is disabled"
#if 0
#include "module.h"
diff --git a/modules/chanserv/set.cpp b/modules/chanserv/set.cpp
index a56afa141..b4af25831 100644
--- a/modules/chanserv/set.cpp
+++ b/modules/chanserv/set.cpp
@@ -17,6 +17,8 @@
class CommandCSSet : public Command
{
+ ServiceReference<ModeLocks> mlocks;
+
public:
CommandCSSet(Module *creator) : Command(creator, "chanserv/set", 2, 3)
{
@@ -45,7 +47,7 @@ class CommandCSSet : public Command
const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
- ServiceReference<Command> c("Command", info.name);
+ ServiceReference<Command> c(info.name);
// XXX dup
if (!c)
@@ -95,7 +97,7 @@ class CommandCSSetAutoOp : public Command
return;
}
- EventReturn MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -155,7 +157,7 @@ class CommandCSSetBanType : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -222,7 +224,7 @@ class CommandCSSetDescription : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -280,7 +282,7 @@ class CommandCSSetFounder : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -349,7 +351,7 @@ class CommandCSSetKeepModes : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -367,7 +369,7 @@ class CommandCSSetKeepModes : public Command
if (ci->c)
for (const std::pair<Anope::string, Anope::string> &p : ci->c->GetModes())
{
- ChanServ::Mode *mode = ChanServ::mode.Create();
+ ChanServ::Mode *mode = Serialize::New<ChanServ::Mode *>();
mode->SetChannel(ci);
mode->SetMode(p.first);
mode->SetParam(p.second);
@@ -378,7 +380,7 @@ class CommandCSSetKeepModes : public Command
Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to disable keep modes";
ci->UnsetS<bool>("CS_KEEP_MODES");
source.Reply(_("Keep modes for \002{0}\002 is now \002off\002."), ci->GetName());
- for (ChanServ::Mode *m : ci->GetRefs<ChanServ::Mode *>(ChanServ::mode))
+ for (ChanServ::Mode *m : ci->GetRefs<ChanServ::Mode *>())
m->Delete();
}
else
@@ -420,7 +422,7 @@ class CommandCSSetPeace : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -464,6 +466,8 @@ inline static Anope::string BotModes()
class CommandCSSetPersist : public Command
{
+ ServiceReference<ModeLocks> mlocks;
+
public:
CommandCSSetPersist(Module *creator, const Anope::string &cname = "chanserv/set/persist") : Command(creator, cname, 2, 2)
{
@@ -490,7 +494,7 @@ class CommandCSSetPersist : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -632,7 +636,7 @@ class CommandCSSetRestricted : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -693,7 +697,7 @@ class CommandCSSetSecure : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -755,7 +759,7 @@ class CommandCSSetSecureFounder : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -821,7 +825,7 @@ class CommandCSSetSecureOps : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -883,7 +887,7 @@ class CommandCSSetSignKick : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -956,7 +960,7 @@ class CommandCSSetSuccessor : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -1065,7 +1069,7 @@ class CommandCSSetNoexpire : public Command
};
class CSSet : public Module
- , public EventHook<Event::CreateChan>
+ , public EventHook<Event::ChanRegistered>
, public EventHook<Event::ChannelSync>
, public EventHook<Event::CheckKick>
, public EventHook<Event::DelChan>
@@ -1101,18 +1105,28 @@ class CSSet : public Module
public:
CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
-
- , noautoop(this, ChanServ::channel, "NOAUTOOP")
- , peace(this, ChanServ::channel, "PEACE")
- , securefounder(this, ChanServ::channel, "SECUREFOUNDER")
- , restricted(this, ChanServ::channel, "RESTRICTED")
- , secure(this, ChanServ::channel, "CS_SECURE")
- , secureops(this, ChanServ::channel, "SECUREOPS")
- , signkick(this, ChanServ::channel, "SIGNKICK")
- , signkick_level(this, ChanServ::channel, "SIGNKICK_LEVEL")
- , noexpire(this, ChanServ::channel, "CS_NO_EXPIRE")
- , keep_modes(this, ChanServ::channel, "CS_KEEP_MODES")
- , persist(this, ChanServ::channel, "PERSIST")
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::ChannelSync>(this)
+ , EventHook<Event::CheckKick>(this)
+ , EventHook<Event::DelChan>(this)
+ , EventHook<Event::ChannelModeSet>(this)
+ , EventHook<Event::ChannelModeUnset>(this)
+ , EventHook<Event::JoinChannel>(this)
+ , EventHook<Event::SetCorrectModes>(this)
+ , EventHook<ChanServ::Event::PreChanExpire>(this)
+ , EventHook<Event::ChanInfo>(this)
+
+ , noautoop(this, "NOAUTOOP")
+ , peace(this, "PEACE")
+ , securefounder(this, "SECUREFOUNDER")
+ , restricted(this, "RESTRICTED")
+ , secure(this, "CS_SECURE")
+ , secureops(this, "SECUREOPS")
+ , signkick(this, "SIGNKICK")
+ , signkick_level(this, "SIGNKICK_LEVEL")
+ , noexpire(this, "CS_NO_EXPIRE")
+ , keep_modes(this, "CS_KEEP_MODES")
+ , persist(this, "PERSIST")
, commandcsset(this)
, commandcssetautoop(this)
@@ -1139,7 +1153,7 @@ class CSSet : public Module
persist_lower_ts = conf->GetModule(this)->Get<bool>("persist_lower_ts");
}
- void OnCreateChan(ChanServ::Channel *ci) override
+ void OnChanRegistered(ChanServ::Channel *ci) override
{
ci->SetBanType(Config->GetModule(this)->Get<int>("defbantype", "2"));
}
@@ -1147,7 +1161,7 @@ class CSSet : public Module
void OnChannelSync(Channel *c) override
{
if (c->ci && keep_modes.HasExt(c->ci))
- for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>(ChanServ::mode))
+ for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>())
c->SetMode(c->ci->WhoSends(), m->GetMode(), m->GetParam());
}
@@ -1177,12 +1191,15 @@ class CSSet : public Module
if (mode->name == "PERM")
persist.Set(c->ci, true);
- if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && ChanServ::mode && (!inhabit || !inhabit->HasExt(c)))
+ if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c)))
{
- ChanServ::Mode *m = ChanServ::mode.Create();
- m->SetChannel(c->ci);
- m->SetMode(mode->name);
- m->SetParam(param);
+ ChanServ::Mode *m = Serialize::New<ChanServ::Mode *>();
+ if (m != nullptr)
+ {
+ m->SetChannel(c->ci);
+ m->SetMode(mode->name);
+ m->SetParam(param);
+ }
}
}
@@ -1198,7 +1215,7 @@ class CSSet : public Module
}
if (c->ci && mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c)))
- for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>(ChanServ::mode))
+ for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>())
if (m->GetMode() == mode->name && m->GetParam().equals_ci(param))
m->Delete();
diff --git a/modules/chanserv/set_misc.cpp b/modules/chanserv/set_misc.cpp
index 71087138a..af7c52650 100644
--- a/modules/chanserv/set_misc.cpp
+++ b/modules/chanserv/set_misc.cpp
@@ -17,6 +17,11 @@ static Anope::map<Anope::string> descriptions;
class CSMiscDataImpl : public CSMiscData
{
+ friend class CSMiscDataType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string name, data;
+
public:
CSMiscDataImpl(Serialize::TypeBase *type) : CSMiscData(type) { }
CSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : CSMiscData(type, id) { }
@@ -37,10 +42,10 @@ class CSMiscDataType : public Serialize::Type<CSMiscDataImpl>
Serialize::ObjectField<CSMiscDataImpl, ChanServ::Channel *> owner;
Serialize::Field<CSMiscDataImpl, Anope::string> name, data;
- CSMiscDataType(Module *me) : Serialize::Type<CSMiscDataImpl>(me, "CSMiscData")
- , owner(this, "owner", true)
- , name(this, "name")
- , data(this, "data")
+ CSMiscDataType(Module *me) : Serialize::Type<CSMiscDataImpl>(me)
+ , owner(this, "owner", &CSMiscDataImpl::channel, true)
+ , name(this, "name", &CSMiscDataImpl::name)
+ , data(this, "data", &CSMiscDataImpl::data)
{
}
};
@@ -110,7 +115,7 @@ class CommandCSSetMisc : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -123,7 +128,7 @@ class CommandCSSetMisc : public Command
Anope::string scommand = GetAttribute(source.command);
/* remove existing */
- for (CSMiscData *data : ci->GetRefs<CSMiscData *>(csmiscdata))
+ for (CSMiscData *data : ci->GetRefs<CSMiscData *>())
if (data->GetName() == scommand)
{
data->Delete();
@@ -132,7 +137,7 @@ class CommandCSSetMisc : public Command
if (!param.empty())
{
- CSMiscData *data = csmiscdata.Create();
+ CSMiscData *data = Serialize::New<CSMiscData *>();
data->SetChannel(ci);
data->SetName(scommand);
data->SetData(param);
@@ -175,6 +180,7 @@ class CSSetMisc : public Module
public:
CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChanInfo>(this)
, commandcssetmisc(this)
, type(this)
{
@@ -203,7 +209,7 @@ class CSSetMisc : public Module
void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool) override
{
- for (CSMiscData *data : ci->GetRefs<CSMiscData *>(csmiscdata))
+ for (CSMiscData *data : ci->GetRefs<CSMiscData *>())
info[data->GetName()] = data->GetData();
}
};
diff --git a/modules/chanserv/statusupdate.cpp b/modules/chanserv/statusupdate.cpp
index e2e37c60d..354664e3e 100644
--- a/modules/chanserv/statusupdate.cpp
+++ b/modules/chanserv/statusupdate.cpp
@@ -13,6 +13,8 @@ class StatusUpdate : public Module
{
public:
StatusUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::AccessAdd>(this)
+ , EventHook<Event::AccessDel>(this)
{
}
@@ -24,8 +26,7 @@ class StatusUpdate : public Module
{
User *user = it->second->user;
- ChanServ::ChanAccess::Path p;
- if (user->server != Me && access->Matches(user, user->Account(), p))
+ if (user->server != Me && access->Matches(user, user->Account()))
{
ChanServ::AccessGroup ag = ci->AccessFor(user);
@@ -48,8 +49,7 @@ class StatusUpdate : public Module
{
User *user = it->second->user;
- ChanServ::ChanAccess::Path p;
- if (user->server != Me && access->Matches(user, user->Account(), p))
+ if (user->server != Me && access->Matches(user, user->Account()))
{
ChanServ::AccessGroup ag = ci->AccessFor(user);
diff --git a/modules/chanserv/suspend.cpp b/modules/chanserv/suspend.cpp
index 44259f341..dbfcafa3f 100644
--- a/modules/chanserv/suspend.cpp
+++ b/modules/chanserv/suspend.cpp
@@ -17,6 +17,12 @@
class CSSuspendInfoImpl : public CSSuspendInfo
{
+ friend class CSSuspendType;
+
+ ChanServ::Channel *channel = nullptr;
+ Anope::string by, reason;
+ time_t when = 0, expires = 0;
+
public:
CSSuspendInfoImpl(Serialize::TypeBase *type) : CSSuspendInfo(type) { }
CSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : CSSuspendInfo(type, id) { }
@@ -44,12 +50,12 @@ class CSSuspendType : public Serialize::Type<CSSuspendInfoImpl>
Serialize::Field<CSSuspendInfoImpl, Anope::string> by, reason;
Serialize::Field<CSSuspendInfoImpl, time_t> when, expires;
- CSSuspendType(Module *me) : Serialize::Type<CSSuspendInfoImpl>(me, "CSSuspendInfo")
- , channel(this, "chan", true)
- , by(this, "by")
- , reason(this, "reason")
- , when(this, "time")
- , expires(this, "expires")
+ CSSuspendType(Module *me) : Serialize::Type<CSSuspendInfoImpl>(me)
+ , channel(this, "chan", &CSSuspendInfoImpl::channel, true)
+ , by(this, "by", &CSSuspendInfoImpl::by)
+ , reason(this, "reason", &CSSuspendInfoImpl::reason)
+ , when(this, "time", &CSSuspendInfoImpl::when)
+ , expires(this, "expires", &CSSuspendInfoImpl::expires)
{
}
};
@@ -106,9 +112,8 @@ void CSSuspendInfoImpl::SetExpires(const time_t &e)
class CommandCSSuspend : public Command
{
- EventHandlers<Event::ChanSuspend> &onchansuspend;
public:
- CommandCSSuspend(Module *creator, EventHandlers<Event::ChanSuspend> &event) : Command(creator, "chanserv/suspend", 2, 3), onchansuspend(event)
+ CommandCSSuspend(Module *creator) : Command(creator, "chanserv/suspend", 2, 3)
{
this->SetDesc(_("Prevent a channel from being used preserving channel data and settings"));
this->SetSyntax(_("\037channel\037 [+\037expiry\037] [\037reason\037]"));
@@ -119,7 +124,7 @@ class CommandCSSuspend : public Command
const Anope::string &chan = params[0];
Anope::string expiry = params[1];
Anope::string reason = params.size() > 2 ? params[2] : "";
- time_t expiry_secs = Config->GetModule(this->owner)->Get<time_t>("expire");
+ time_t expiry_secs = Config->GetModule(this->GetOwner())->Get<time_t>("expire");
if (!expiry.empty() && expiry[0] != '+')
{
@@ -147,14 +152,14 @@ class CommandCSSuspend : public Command
return;
}
- CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo);
+ CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>();
if (si)
{
source.Reply(_("\002{0}\002 is already suspended."), ci->GetName());
return;
}
- si = cssuspendinfo.Create();
+ si = Serialize::New<CSSuspendInfo *>();
si->SetChannel(ci);
si->SetBy(source.GetNick());
si->SetReason(reason);
@@ -180,7 +185,7 @@ class CommandCSSuspend : public Command
Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never");
source.Reply(_("Channel \002{0}\002 is now suspended."), ci->GetName());
- this->onchansuspend(&Event::ChanSuspend::OnChanSuspend, ci);
+ EventManager::Get()->Dispatch(&Event::ChanSuspend::OnChanSuspend, ci);
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
@@ -194,10 +199,8 @@ class CommandCSSuspend : public Command
class CommandCSUnSuspend : public Command
{
- EventHandlers<Event::ChanUnsuspend> &onchanunsuspend;
-
public:
- CommandCSUnSuspend(Module *creator, EventHandlers<Event::ChanUnsuspend> &event) : Command(creator, "chanserv/unsuspend", 1, 1), onchanunsuspend(event)
+ CommandCSUnSuspend(Module *creator) : Command(creator, "chanserv/unsuspend", 1, 1)
{
this->SetDesc(_("Releases a suspended channel"));
this->SetSyntax(_("\037channel\037"));
@@ -217,7 +220,7 @@ class CommandCSUnSuspend : public Command
return;
}
- CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo);
+ CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>();
if (!si)
{
source.Reply(_("Channel \002{0}\002 isn't suspended."), ci->GetName());
@@ -230,7 +233,7 @@ class CommandCSUnSuspend : public Command
source.Reply(_("Channel \002%s\002 is now released."), ci->GetName().c_str());
- this->onchanunsuspend(&Event::ChanUnsuspend::OnChanUnsuspend, ci);
+ EventManager::Get()->Dispatch(&Event::ChanUnsuspend::OnChanUnsuspend, ci);
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
@@ -248,8 +251,6 @@ class CSSuspend : public Module
{
CommandCSSuspend commandcssuspend;
CommandCSUnSuspend commandcsunsuspend;
- EventHandlers<Event::ChanSuspend> onchansuspend;
- EventHandlers<Event::ChanUnsuspend> onchanunsuspend;
std::vector<Anope::string> show;
CSSuspendType cst;
@@ -268,17 +269,19 @@ class CSSuspend : public Module
public:
CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandcssuspend(this, onchansuspend)
- , commandcsunsuspend(this, onchanunsuspend)
- , onchansuspend(this)
- , onchanunsuspend(this)
+ , EventHook<Event::ChanInfo>(this)
+ , EventHook<ChanServ::Event::PreChanExpire>(this)
+ , EventHook<Event::CheckKick>(this)
+ , EventHook<Event::ChanDrop>(this)
+ , commandcssuspend(this)
+ , commandcsunsuspend(this)
, cst(this)
{
}
void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) override
{
- CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo);
+ CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>();
if (!si)
return;
@@ -296,7 +299,7 @@ class CSSuspend : public Module
void OnPreChanExpire(ChanServ::Channel *ci, bool &expire) override
{
- CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo);
+ CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>();
if (!si)
return;
@@ -316,7 +319,7 @@ class CSSuspend : public Module
EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
{
- if (u->HasMode("OPER") || !c->ci || !c->ci->GetRef<CSSuspendInfo *>(cssuspendinfo))
+ if (u->HasMode("OPER") || !c->ci || !c->ci->GetRef<CSSuspendInfo *>())
return EVENT_CONTINUE;
reason = Language::Translate(u, _("This channel may not be used."));
@@ -325,7 +328,7 @@ class CSSuspend : public Module
EventReturn OnChanDrop(CommandSource &source, ChanServ::Channel *ci) override
{
- CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo);
+ CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>();
if (si && !source.HasCommand("chanserv/drop"))
{
source.Reply(_("Channel \002{0}\002 is currently suspended."), ci->GetName());
diff --git a/modules/chanserv/topic.cpp b/modules/chanserv/topic.cpp
index aab3f8dbf..6559b4d25 100644
--- a/modules/chanserv/topic.cpp
+++ b/modules/chanserv/topic.cpp
@@ -42,7 +42,7 @@ class CommandCSSetKeepTopic : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -90,7 +90,7 @@ class CommandCSTopic : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock on");
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock on");
if (MOD_RESULT == EVENT_STOP)
return;
@@ -107,7 +107,7 @@ class CommandCSTopic : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock off");
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock off");
if (MOD_RESULT == EVENT_STOP)
return;
@@ -211,10 +211,15 @@ class CSTopic : public Module
CommandCSTopic commandcstopic;
CommandCSSetKeepTopic commandcssetkeeptopic;
- /*Serializable*/ExtensibleItem<bool> topiclock, keeptopic;
+ Serialize::Field<ChanServ::Channel, bool> topiclock, keeptopic;
+
+ ServiceReference<ModeLocks> mlocks;
public:
CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChannelSync>(this)
+ , EventHook<Event::TopicUpdated>(this)
+ , EventHook<Event::ChanInfo>(this)
, commandcstopic(this)
, commandcssetkeeptopic(this)
, topiclock(this, "TOPICLOCK")
diff --git a/modules/chanserv/unban.cpp b/modules/chanserv/unban.cpp
index 73391ac30..3cd4ba3e2 100644
--- a/modules/chanserv/unban.cpp
+++ b/modules/chanserv/unban.cpp
@@ -36,7 +36,7 @@ class CommandCSUnban : public Command
unsigned count = 0;
- for (ChanServ::Channel *ci : source.GetAccount()->GetRefs<ChanServ::Channel *>(ChanServ::channel))
+ for (ChanServ::Channel *ci : source.GetAccount()->GetRefs<ChanServ::Channel *>())
{
if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN"))
continue;
diff --git a/modules/chanserv/cs_xop.old b/modules/chanserv/xop.cpp
index 8c133697a..149676e73 100644
--- a/modules/chanserv/cs_xop.old
+++ b/modules/chanserv/xop.cpp
@@ -5,14 +5,14 @@
*
* 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.
*/
+/* Dependencies: anope_chanserv.main */
#include "module.h"
-#include "modules/cs_access.h"
-#include "main/chanaccess.h"
+#include "modules/chanserv.h"
+#include "modules/chanserv/access.h"
+#include "modules/chanserv/main/chanaccess.h"
#include "main/chanaccesstype.h"
namespace
@@ -21,14 +21,17 @@ namespace
std::map<Anope::string, std::vector<Anope::string> > permissions;
}
-class XOPChanAccess : public ChanAccessImpl
+class XOPChanAccessImpl : public XOPChanAccess
{
+ friend class XOPChanAccessType;
+
+ Anope::string type;
+
public:
- XOPChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { }
- XOPChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { }
+ using XOPChanAccess::XOPChanAccess;
- Anope::string GetType();
- void SetType(const Anope::string &);
+ const Anope::string &GetType() override;
+ void SetType(const Anope::string &) override;
bool HasPriv(const Anope::string &priv) override
{
@@ -53,7 +56,7 @@ class XOPChanAccess : public ChanAccessImpl
static Anope::string DetermineLevel(ChanServ::ChanAccess *access)
{
- if (access->GetSerializableType()->GetName() == "XOPChanAccess")
+ if (access->GetSerializableType()->GetName() == NAME)
{
XOPChanAccess *xaccess = anope_dynamic_static_cast<XOPChanAccess *>(access);
return xaccess->GetType();
@@ -84,19 +87,19 @@ class XOPChanAccess : public ChanAccessImpl
};
-class XOPChanAccessType : public Serialize::Type<XOPChanAccess, ChanAccessType>
+class XOPChanAccessType : public ChanAccessType<XOPChanAccessImpl>
{
public:
- Serialize::Field<XOPChanAccess, Anope::string> type;
+ Serialize::Field<XOPChanAccessImpl, Anope::string> type;
- XOPChanAccessType(Module *me) : Serialize::Type<XOPChanAccess, ChanAccessType>(me, "XOPChanAccess")
- , type(this, "type")
+ XOPChanAccessType(Module *me) : ChanAccessType<XOPChanAccessImpl>(me)
+ , type(this, "type", &XOPChanAccessImpl::type)
{
- SetParent(ChanServ::chanaccess);
+ Serialize::SetParent(XOPChanAccess::NAME, ChanServ::ChanAccess::NAME);
}
};
-Anope::string XOPChanAccess::GetType()
+const Anope::string &XOPChanAccess::GetType()
{
return Get(&XOPChanAccessType::type);
}
@@ -125,16 +128,12 @@ class CommandCSXOP : public Command
return;
}
- XOPChanAccess tmp_access(NULL);
- tmp_access.SetChannel(ci);
- tmp_access.SetType(source.command.upper());
-
ChanServ::AccessGroup access = source.AccessFor(ci);
ChanServ::ChanAccess *highest = access.Highest();
bool override = false;
std::vector<Anope::string>::iterator cmd_it = std::find(order.begin(), order.end(), source.command.upper()),
- access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccess::DetermineLevel(highest)) : order.end();
+ access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccessImpl::DetermineLevel(highest)) : order.end();
if (!access.founder && (!access.HasPriv("ACCESS_CHANGE") || cmd_it <= access_it))
{
@@ -217,13 +216,13 @@ class CommandCSXOP : public Command
}
unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
- if (access_max && ci->GetDeepAccessCount() >= access_max)
+ if (access_max && ci->GetAccessCount() >= access_max)
{
source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max);
return;
}
- XOPChanAccess *acc = anope_dynamic_static_cast<XOPChanAccess *>(xopchanaccess.Create());
+ XOPChanAccess *acc = Serialize::New<XOPChanAccess *>();
if (na)
acc->SetObj(na->GetAccount());
else if (targ_ci)
@@ -237,7 +236,7 @@ class CommandCSXOP : public Command
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask;
- Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, acc);
+ EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, acc);
source.Reply(_("\002%s\002 added to %s %s list."), acc->Mask(), ci->GetName().c_str(), source.command.c_str());
}
@@ -281,7 +280,7 @@ class CommandCSXOP : public Command
}
std::vector<Anope::string>::iterator cmd_it = std::find(order.begin(), order.end(), source.command.upper()),
- access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccess::DetermineLevel(highest)) : order.end();
+ access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccessImpl::DetermineLevel(highest)) : order.end();
if (!mask.equals_ci(nc->GetDisplay()) && !access.founder && (!access.HasPriv("ACCESS_CHANGE") || cmd_it <= access_it))
{
@@ -317,7 +316,7 @@ class CommandCSXOP : public Command
else
nicks = caccess->Mask();
- Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, caccess);
+ EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, caccess);
delete caccess;
},
[&]()
@@ -350,7 +349,7 @@ class CommandCSXOP : public Command
source.Reply(_("\002%s\002 deleted from %s %s list."), a->Mask().c_str(), ci->GetName().c_str(), source.command.c_str());
- Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, a);
+ EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, a);
delete a;
return;
@@ -467,7 +466,7 @@ class CommandCSXOP : public Command
delete access;
}
- Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source);
+ EventManager::Get()->Dispatch(&Event::AccessClear::OnAccessClear, ci, source);
source.Reply(_("Channel %s %s list has been cleared."), ci->GetName().c_str(), source.command.c_str());
}
diff --git a/modules/database/CMakeLists.txt b/modules/database/CMakeLists.txt
index cd225a94d..9a236d6d0 100644
--- a/modules/database/CMakeLists.txt
+++ b/modules/database/CMakeLists.txt
@@ -1 +1,2 @@
build_modules(${CMAKE_CURRENT_SOURCE_DIR})
+build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/database/flatfile.cpp b/modules/database/flatfile.cpp
index 122134960..b250be294 100644
--- a/modules/database/flatfile.cpp
+++ b/modules/database/flatfile.cpp
@@ -80,6 +80,8 @@ class DBFlatFile : public Module
public:
DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR)
+ , EventHook<Event::LoadDatabase>(this)
+ , EventHook<Event::SaveDatabase>(this)
, last_day(0)
, loaded(false)
{
@@ -182,8 +184,9 @@ class DBFlatFile : public Module
f << "OBJECT " << s_type->GetName() << "\n";
f << "ID " << object->id << "\n";
- for (Serialize::FieldBase *field : s_type->fields)
- f << "DATA " << field->GetName() << " " << field->SerializeToString(object) << "\n";
+ for (Serialize::FieldBase *field : s_type->GetFields())
+ if (field->HasFieldS(object)) // for ext
+ f << "DATA " << field->serialize_name << " " << field->SerializeToString(object) << "\n";
f << "END\n";
}
}
diff --git a/modules/database/old.cpp b/modules/database/old.cpp
index 27fb3565d..5e94cde02 100644
--- a/modules/database/old.cpp
+++ b/modules/database/old.cpp
@@ -8,6 +8,8 @@
* Based on the original code of Services by Andy Church.
*/
+/* Dependencies: anope_chanserv.access */
+
#include "module.h"
#include "modules/operserv/session.h"
#include "modules/botserv/kick.h"
@@ -159,6 +161,8 @@ enum
static void process_mlock(ChanServ::Channel *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key)
{
+ ServiceReference<ModeLocks> mlocks;
+
if (!mlocks)
return;
@@ -463,7 +467,7 @@ static void LoadNicks()
READ(read_string(buffer, f));
- NickServ::Account *nc = NickServ::account.Create();
+ NickServ::Account *nc = Serialize::New<NickServ::Account *>();
nc->SetDisplay(buffer);
const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email",
@@ -532,9 +536,9 @@ static void LoadNicks()
nc->SetS<bool>("HIDE_STATUS", true);
if (u32 & OLD_NI_SUSPENDED)
{
- if (nssuspendinfo)
+ NSSuspendInfo *si = Serialize::New<NSSuspendInfo *>();
+ if (si)
{
- NSSuspendInfo *si = nssuspendinfo.Create();
si->SetAccount(nc);
}
}
@@ -594,9 +598,9 @@ static void LoadNicks()
{
READ(read_string(buffer, f));
- if (nsaccess)
+ NickAccess *a = Serialize::New<NickAccess *>();
+ if (a)
{
- NickAccess *a = nsaccess.Create();
a->SetAccount(nc);
a->SetMask(buffer);
}
@@ -610,7 +614,7 @@ static void LoadNicks()
mi->SetMemoMax(i16);
for (int16_t j = 0; j < i16; ++j)
{
- MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr;
+ MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>();
READ(read_uint32(&u32, f));
uint16_t flags;
READ(read_uint16(&flags, f));
@@ -664,28 +668,26 @@ static void LoadNicks()
if (tmpu16 & OLD_NS_VERBOTEN)
{
- if (!forbiddata)
+ if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos)
{
delete nc;
continue;
}
- if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos)
+ ForbidData *d = Serialize::New<ForbidData *>();
+ if (d)
{
- delete nc;
- continue;
+ d->SetMask(nc->GetDisplay());
+ d->SetCreator(last_usermask);
+ d->SetReason(last_realname);
+ d->SetType(FT_NICK);
}
-
- ForbidData *d = forbiddata.Create();
- d->SetMask(nc->GetDisplay());
- d->SetCreator(last_usermask);
- d->SetReason(last_realname);
- d->SetType(FT_NICK);
+
delete nc;
continue;
}
- NickServ::Nick *na = NickServ::nick.Create();
+ NickServ::Nick *na = Serialize::New<NickServ::Nick *>();
na->SetNick(nick);
na->SetAccount(nc);
na->SetLastUsermask(last_usermask);
@@ -756,9 +758,8 @@ static void LoadBots()
READ(read_int16(&chancount, f));
ServiceBot *bi = ServiceBot::Find(nick, true);
- //XXX
- // if (!bi)
- // bi = new ServiceBot(nick, user, host, real);
+ if (!bi)
+ bi = new ServiceBot(nick, user, host, real);
bi->bi->SetCreated(created);
if (flags & OLD_BI_PRIVATE)
@@ -772,10 +773,13 @@ static void LoadBots()
static void LoadChannels()
{
- if (!ChanServ::service)
+ ServiceReference<BadWords> badwords;
+ ServiceReference<ChanServ::ChanServService> chanserv;
+
+ if (!chanserv)
return;
- ServiceReference<ForbidService> forbid("ForbidService", "forbid");
+ ServiceReference<ForbidService> forbid;
dbFILE *f = open_db_read("ChanServ", "chan.db", 16);
if (f == NULL)
return;
@@ -786,7 +790,7 @@ static void LoadChannels()
Anope::string buffer;
char namebuf[64];
READ(read_buffer(namebuf, f));
- ChanServ::Channel *ci = ChanServ::channel.Create();
+ ChanServ::Channel *ci = Serialize::New<ChanServ::Channel *>();
ci->SetName(namebuf);
const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder",
@@ -860,9 +864,9 @@ static void LoadChannels()
READ(read_string(forbidreason, f));
if (tmpu32 & OLD_CI_SUSPENDED)
{
- if (cssuspendinfo)
+ CSSuspendInfo *si = Serialize::New<CSSuspendInfo *>();
+ if (si)
{
- CSSuspendInfo *si = cssuspendinfo.Create();
si->SetChannel(ci);
si->SetBy(forbidby);
}
@@ -903,13 +907,11 @@ static void LoadChannels()
if (xop)
{
- if (xopchanaccess)
- access = xopchanaccess.Create();
+ access = Serialize::New<XOPChanAccess *>();
}
else
{
- if (accesschanaccess)
- access = accesschanaccess.Create();
+ access = Serialize::New<AccessChanAccess *>();
}
if (access)
@@ -998,7 +1000,7 @@ static void LoadChannels()
{
READ(read_uint32(&tmpu32, f));
READ(read_uint16(&tmpu16, f));
- MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr;
+ MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>();
READ(read_int32(&tmp32, f));
if (m)
m->SetTime(tmp32);
@@ -1015,9 +1017,9 @@ static void LoadChannels()
READ(read_string(buffer, f));
if (!buffer.empty())
{
- if (entrymsg)
+ EntryMsg *e = Serialize::New<EntryMsg *>();
+ if (e)
{
- EntryMsg *e = entrymsg.Create();
e->SetChannel(ci);
e->SetCreator("Unknown");
e->SetMessage(buffer);
@@ -1129,23 +1131,21 @@ static void LoadChannels()
if (forbid_chan)
{
- if (!forbiddata)
+ if (ci->GetName().find_first_of("?*") != Anope::string::npos)
{
delete ci;
continue;
}
- if (ci->GetName().find_first_of("?*") != Anope::string::npos)
+ ForbidData *d = Serialize::New<ForbidData *>();
+ if (d)
{
- delete ci;
- continue;
+ d->SetMask(ci->GetName());
+ d->SetCreator(forbidby);
+ d->SetReason(forbidreason);
+ d->SetType(FT_CHAN);
}
-
- ForbidData *d = forbiddata.Create();
- d->SetMask(ci->GetName());
- d->SetCreator(forbidby);
- d->SetReason(forbidreason);
- d->SetType(FT_CHAN);
+
delete ci;
continue;
}
@@ -1198,8 +1198,14 @@ static void LoadOper()
if (!akill)
continue;
- XLine *x = new XLine(user + "@" + host, by, expires, reason, XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(user + "@" + host);
+ x->SetBy(by);
+ x->SetExpires(expires);
+ x->SetReason(reason);
+ x->SetID(XLineManager::GenerateUID());
x->SetCreated(seton);
+
akill->AddXLine(x);
}
@@ -1218,8 +1224,14 @@ static void LoadOper()
if (!snline)
continue;
- XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(by);
+ x->SetExpires(expires);
+ x->SetReason(reason);
+ x->SetID(XLineManager::GenerateUID());
x->SetCreated(seton);
+
snline->AddXLine(x);
}
@@ -1238,8 +1250,14 @@ static void LoadOper()
if (!sqline)
continue;
- XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(by);
+ x->SetExpires(expires);
+ x->SetReason(reason);
+ x->SetID(XLineManager::GenerateUID());
x->SetCreated(seton);
+
sqline->AddXLine(x);
}
@@ -1258,8 +1276,14 @@ static void LoadOper()
if (!szline)
continue;
- XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(by);
+ x->SetExpires(expires);
+ x->SetReason(reason);
+ x->SetID(XLineManager::GenerateUID());
x->SetCreated(seton);
+
szline->AddXLine(x);
}
@@ -1268,9 +1292,6 @@ static void LoadOper()
static void LoadExceptions()
{
- if (!session_service)
- return;
-
dbFILE *f = open_db_read("OperServ", "exception.db", 9);
if (f == NULL)
return;
@@ -1291,9 +1312,9 @@ static void LoadExceptions()
READ(read_int32(&time, f));
READ(read_int32(&expires, f));
- if (exception && session_service)
+ Exception *e = Serialize::New<Exception *>();
+ if (e)
{
- Exception *e = exception.Create();
e->SetMask(mask);
e->SetLimit(limit);
e->SetWho(who);
@@ -1308,9 +1329,6 @@ static void LoadExceptions()
static void LoadNews()
{
- if (!newsitem)
- return;
-
dbFILE *f = open_db_read("OperServ", "news.db", 9);
if (f == NULL)
@@ -1322,7 +1340,10 @@ static void LoadNews()
for (int16_t i = 0; i < n; i++)
{
int16_t type;
- NewsItem *ni = newsitem.Create();
+ NewsItem *ni = Serialize::New<NewsItem *>();
+
+ if (!ni)
+ break;
READ(read_int16(&type, f));
@@ -1362,11 +1383,13 @@ class DBOld : public Module
, public EventHook<Event::LoadDatabase>
, public EventHook<Event::UplinkSync>
{
- ExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit;
+ ExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit; // XXX these are no longer required because of confmodes
ExtensibleItem<Anope::string> mlock_key;
public:
DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR)
+ , EventHook<Event::LoadDatabase>(this)
+ , EventHook<Event::UplinkSync>(this)
, mlock_on(this, "mlock_on")
, mlock_off(this, "mlock_off")
, mlock_limit(this, "mlock_limit")
@@ -1424,5 +1447,10 @@ class DBOld : public Module
}
};
+template<> void ModuleInfo<DBOld>(ModuleDef *def)
+{
+ def->Depends("chanserv.access");
+}
+
MODULE_INIT(DBOld)
diff --git a/modules/database/redis.cpp b/modules/database/redis.cpp
index 72f25a16e..bb5103b4c 100644
--- a/modules/database/redis.cpp
+++ b/modules/database/redis.cpp
@@ -65,6 +65,8 @@ class DatabaseRedis : public Module
ServiceReference<Provider> redis;
DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR)
+ , EventHook<Event::LoadDatabase>(this)
+ , EventHook<Event::SerializeEvents>(this)
, sl(this)
{
me = this;
@@ -73,7 +75,7 @@ class DatabaseRedis : public Module
void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
- this->redis = ServiceReference<Provider>("Redis::Provider", block->Get<Anope::string>("engine", "redis/main"));
+ this->redis = ServiceReference<Provider>(block->Get<Anope::string>("engine", "redis/main"));
}
EventReturn OnLoadDatabase() override
@@ -136,7 +138,7 @@ class DatabaseRedis : public Module
redis->StartTransaction();
const Anope::string &old = field->SerializeToString(object);
- args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + old, stringify(object->id) };
+ args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) };
redis->SendCommand(nullptr, args);
// add object to type set
@@ -144,15 +146,15 @@ class DatabaseRedis : public Module
redis->SendCommand(nullptr, args);
// add key to key set
- args = { "SADD", "keys:" + stringify(object->id), field->GetName() };
+ args = { "SADD", "keys:" + stringify(object->id), field->serialize_name };
redis->SendCommand(nullptr, args);
// set value
- args = { "SET", "values:" + stringify(object->id) + ":" + field->GetName(), value };
+ args = { "SET", "values:" + stringify(object->id) + ":" + field->serialize_name, value };
redis->SendCommand(nullptr, args);
// lookup
- args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + value, stringify(object->id) };
+ args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(object->id) };
redis->SendCommand(nullptr, args);
redis->CommitTransaction();
@@ -172,11 +174,11 @@ class DatabaseRedis : public Module
redis->StartTransaction();
const Anope::string &old = field->SerializeToString(object);
- args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + old, stringify(object->id) };
+ args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) };
redis->SendCommand(nullptr, args);
// remove field from set
- args = { "SREM", "keys:" + stringify(object->id), field->GetName() };
+ args = { "SREM", "keys:" + stringify(object->id), field->serialize_name };
redis->SendCommand(nullptr, args);
redis->CommitTransaction();
@@ -219,17 +221,17 @@ class DatabaseRedis : public Module
redis->StartTransaction();
- for (Serialize::FieldBase *field : obj->GetSerializableType()->fields)
+ for (Serialize::FieldBase *field : obj->GetSerializableType()->GetFields())
{
Anope::string value = field->SerializeToString(obj);
- args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + value, stringify(obj->id) };
+ args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(obj->id) };
redis->SendCommand(nullptr, args);
- args = { "DEL", "values:" + stringify(obj->id) + ":" + field->GetName() };
+ args = { "DEL", "values:" + stringify(obj->id) + ":" + field->serialize_name };
redis->SendCommand(nullptr, args);
- args = { "SREM", "keys:" + stringify(obj->id), field->GetName() };
+ args = { "SREM", "keys:" + stringify(obj->id), field->serialize_name };
redis->SendCommand(nullptr, args);
}
@@ -308,7 +310,7 @@ void ObjectLoader::OnResult(const Reply &r)
void FieldLoader::OnResult(const Reply &r)
{
- Log(LOG_DEBUG_2) << "redis: Setting field " << field->GetName() << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << r.bulk;
+ Log(LOG_DEBUG_2) << "redis: Setting field " << field->serialize_name << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << r.bulk;
field->UnserializeFromString(obj, r.bulk);
delete this;
@@ -366,7 +368,7 @@ void SubscriptionListener::OnResult(const Reply &r)
return;
}
- Log(LOG_DEBUG_2) << "redis: Setting field " << field->GetName() << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << value;
+ Log(LOG_DEBUG_2) << "redis: Setting field " << field->serialize_name << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << value;
field->UnserializeFromString(obj, value);
}
else if (command == "create")
diff --git a/modules/database/sql.cpp b/modules/database/sql.cpp
index fed0050e4..2d1a61afa 100644
--- a/modules/database/sql.cpp
+++ b/modules/database/sql.cpp
@@ -11,11 +11,26 @@ class DBMySQL : public Module, public Pipe
bool inited = false;
Anope::string prefix;
ServiceReference<Provider> SQL;
+ std::unordered_multimap<Serialize::Object *, Serialize::FieldBase *> cache;
+
+ void CacheMiss(Serialize::Object *object, Serialize::FieldBase *field)
+ {
+ cache.insert(std::make_pair(object, field));
+ }
+
+ bool IsCacheMiss(Serialize::Object *object, Serialize::FieldBase *field)
+ {
+ auto range = cache.equal_range(object);
+ for (auto it = range.first; it != range.second; ++it)
+ if (it->second == field)
+ return true;
+ return false;
+ }
Result Run(const Query &query)
{
if (!SQL)
- ;//XXX
+ return Result();
if (!inited)
{
@@ -24,6 +39,8 @@ class DBMySQL : public Module, public Pipe
SQL->RunQuery(q);
}
+ Log(LOG_DEBUG_2) << query.Unsafe();
+
return SQL->RunQuery(query);
}
@@ -50,6 +67,7 @@ class DBMySQL : public Module, public Pipe
public:
DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR)
+ , EventHook<Event::SerializeEvents>(this)
{
}
@@ -57,12 +75,13 @@ class DBMySQL : public Module, public Pipe
{
Commit();
Serialize::Clear();
+ cache.clear();
}
void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
- this->SQL = ServiceReference<Provider>("SQL::Provider", block->Get<Anope::string>("engine"));
+ this->SQL = ServiceReference<Provider>(block->Get<Anope::string>("engine"));
this->prefix = block->Get<Anope::string>("prefix", "anope_db_");
inited = false;
}
@@ -94,13 +113,13 @@ class DBMySQL : public Module, public Pipe
for (Query &q : SQL->CreateTable(prefix, type->GetName()))
Run(q);
- for (Query &q : SQL->AlterTable(prefix, type->GetName(), field->GetName(), false))
+ for (Query &q : SQL->AlterTable(prefix, type->GetName(), field->serialize_name, false))
Run(q);
- for (const Query &q : SQL->CreateIndex(prefix + type->GetName(), field->GetName()))
+ for (const Query &q : SQL->CreateIndex(prefix + type->GetName(), field->serialize_name))
Run(q);
- Query query("SELECT `id` FROM `" + prefix + type->GetName() + "` WHERE `" + field->GetName() + "` = @value@");
+ Query query("SELECT `id` FROM `" + prefix + type->GetName() + "` WHERE `" + field->serialize_name + "` = @value@");
query.SetValue("value", value);
Result res = Run(query);
if (res.Rows())
@@ -120,14 +139,14 @@ class DBMySQL : public Module, public Pipe
{
StartTransaction();
- Query query = "SELECT `" + field->GetName() + "` FROM `" + prefix + object->GetSerializableType()->GetName() + "` WHERE `id` = @id@";
+ Query query = "SELECT `" + field->serialize_name + "` FROM `" + prefix + object->GetSerializableType()->GetName() + "` WHERE `id` = @id@";
query.SetValue("id", object->id);
Result res = Run(query);
if (res.Rows() == 0)
return false;
- v = res.GetValue(0, field->GetName());
+ v = res.GetValue(0, field->serialize_name);
return true;
}
@@ -136,9 +155,12 @@ class DBMySQL : public Module, public Pipe
{
SQL::Result::Value v;
+ if (IsCacheMiss(object, field))
+ return EVENT_CONTINUE;
+
if (!GetValue(object, field, v))
{
- field->CacheMiss(object);
+ CacheMiss(object, field);
return EVENT_CONTINUE;
}
@@ -175,7 +197,7 @@ class DBMySQL : public Module, public Pipe
Result res = Run(query);
for (int i = 0; i < res.Rows(); ++i)
{
- Serialize::ID id = convertTo<Serialize::ID>(res.Get(i, "id"));
+ Serialize::ID id = convertTo<Serialize::ID>(res.Get(i, "id")); // object edge is on
if (id == object->id)
{
@@ -184,11 +206,26 @@ class DBMySQL : public Module, public Pipe
Anope::string f = res.Get(i, "field");
id = convertTo<Serialize::ID>(res.Get(i, "other_id"));
- //XXX sanity checks
Serialize::FieldBase *obj_field = object->GetSerializableType()->GetField(f);
+ if (obj_field == nullptr)
+ {
+ Log(LOG_DEBUG) << "Unable to find field " << f << " on " << object->GetSerializableType()->GetName();
+ continue;
+ }
Serialize::TypeBase *obj_type = Serialize::TypeBase::Find(t);
+ if (obj_type == nullptr)
+ {
+ Log(LOG_DEBUG) << "Unable to find type " << t;
+ continue;
+ }
+
Serialize::Object *other = obj_type->Require(id);
+ if (other == nullptr)
+ {
+ Log(LOG_DEBUG) << "Unable to require id " << id << " type " << obj_type->GetName();
+ continue;
+ }
edges.emplace_back(other, obj_field, true);
}
@@ -198,10 +235,26 @@ class DBMySQL : public Module, public Pipe
Anope::string t = res.Get(i, "type");
Anope::string f = res.Get(i, "field");
- //XXX sanity checks
Serialize::TypeBase *obj_type = Serialize::TypeBase::Find(t);
+ if (obj_type == nullptr)
+ {
+ Log(LOG_DEBUG) << "Unable to find type " << t;
+ continue;
+ }
+
Serialize::FieldBase *obj_field = obj_type->GetField(f);
+ if (obj_field == nullptr)
+ {
+ Log(LOG_DEBUG) << "Unable to find field " << f << " on " << obj_type->GetName();
+ continue;
+ }
+
Serialize::Object *other = obj_type->Require(id);
+ if (other == nullptr)
+ {
+ Log(LOG_DEBUG) << "Unable to require id " << id << " type " << obj_type->GetName();
+ continue;
+ }
// other type, other field,
edges.emplace_back(other, obj_field, false);
@@ -227,8 +280,8 @@ class DBMySQL : public Module, public Pipe
{
StartTransaction();
- Query query = "SELECT `" + field->GetName() + "`,j1.type AS " + field->GetName() + "_type FROM `" + prefix + object->GetSerializableType()->GetName() + "` "
- "JOIN `" + prefix + "objects` AS j1 ON " + prefix + object->GetSerializableType()->GetName() + "." + field->GetName() + " = j1.id "
+ Query query = "SELECT `" + field->serialize_name + "`,j1.type AS " + field->serialize_name + "_type FROM `" + prefix + object->GetSerializableType()->GetName() + "` "
+ "JOIN `" + prefix + "objects` AS j1 ON " + prefix + object->GetSerializableType()->GetName() + "." + field->serialize_name + " = j1.id "
"WHERE " + prefix + object->GetSerializableType()->GetName() + ".id = @id@";
query.SetValue("id", object->id);
Result res = Run(query);
@@ -236,10 +289,10 @@ class DBMySQL : public Module, public Pipe
if (res.Rows() == 0)
return EVENT_CONTINUE;
- type = res.Get(0, field->GetName() + "_type");
+ type = res.Get(0, field->serialize_name + "_type");
try
{
- value = convertTo<Serialize::ID>(res.Get(0, field->GetName()));
+ value = convertTo<Serialize::ID>(res.Get(0, field->serialize_name));
}
catch (const ConvertException &ex)
{
@@ -260,15 +313,15 @@ class DBMySQL : public Module, public Pipe
for (Query &q : SQL->CreateTable(prefix, object->GetSerializableType()->GetName()))
Run(q);
- for (Query &q : SQL->AlterTable(prefix, object->GetSerializableType()->GetName(), field->GetName(), is_object))
+ for (Query &q : SQL->AlterTable(prefix, object->GetSerializableType()->GetName(), field->serialize_name, is_object))
Run(q);
Query q;
q.SetValue("id", object->id);
if (value)
- q.SetValue(field->GetName(), *value);
+ q.SetValue(field->serialize_name, *value);
else
- q.SetNull(field->GetName());
+ q.SetNull(field->serialize_name);
for (Query &q2 : SQL->Replace(prefix + object->GetSerializableType()->GetName(), q, { "id" }))
Run(q2);
@@ -294,7 +347,7 @@ class DBMySQL : public Module, public Pipe
DoSet(object, field, true, &v);
Query query;
- query.SetValue("field", field->GetName());
+ query.SetValue("field", field->serialize_name);
query.SetValue("id", object->id);
query.SetValue("other_id", value->id);
@@ -307,7 +360,7 @@ class DBMySQL : public Module, public Pipe
Query query("DELETE FROM `" + prefix + "edges` WHERE `id` = @id@ AND `field` = @field@");
query.SetValue("id", object->id);
- query.SetValue("field", field->GetName());
+ query.SetValue("field", field->serialize_name);
Run(query);
}
@@ -317,18 +370,16 @@ class DBMySQL : public Module, public Pipe
EventReturn OnSerializeUnset(Serialize::Object *object, Serialize::FieldBase *field) override
{
DoSet(object, field, false, nullptr);
- field->CacheMiss(object);
return EVENT_STOP;
}
EventReturn OnSerializeUnsetSerializable(Serialize::Object *object, Serialize::FieldBase *field) override
{
DoSet(object, field, true, nullptr);
- field->CacheMiss(object);
Query query("DELETE FROM `" + prefix + "edges` WHERE `id` = @id@ AND `field` = @field@");
query.SetValue("id", object->id);
- query.SetValue("field", field->GetName());
+ query.SetValue("field", field->serialize_name);
Run(query);
return EVENT_STOP;
@@ -343,6 +394,9 @@ class DBMySQL : public Module, public Pipe
EventReturn OnSerializableGetId(Serialize::ID &id) override
{
+ if (!SQL)
+ return EVENT_CONTINUE;
+
StartTransaction();
id = SQL->GetID(prefix);
diff --git a/modules/dns.cpp b/modules/dns.cpp
index 1ea70a6ed..fe993c271 100644
--- a/modules/dns.cpp
+++ b/modules/dns.cpp
@@ -835,7 +835,7 @@ class MyManager : public Manager, public Timer
}
}
- Event::OnDnsRequest(&Event::DnsRequest::OnDnsRequest, recv_packet, packet);
+ EventManager::Get()->Dispatch(&Event::DnsRequest::OnDnsRequest, recv_packet, packet);
for (unsigned i = 0; i < recv_packet.questions.size(); ++i)
{
@@ -1028,6 +1028,7 @@ class ModuleDNS : public Module
public:
ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
+ , EventHook<Event::ModuleUnload>(this)
, manager(this)
{
diff --git a/modules/dnsbl.cpp b/modules/dnsbl.cpp
index 49739a80c..7d60a9f45 100644
--- a/modules/dnsbl.cpp
+++ b/modules/dnsbl.cpp
@@ -10,8 +10,6 @@
using namespace DNS;
-static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-
struct Blacklist
{
struct Reply
@@ -41,12 +39,13 @@ struct Blacklist
class DNSBLResolver : public Request
{
+ ServiceReference<XLineManager> &akills;
Reference<User> user;
Blacklist blacklist;
bool add_to_akill;
public:
- DNSBLResolver(Module *c, User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : Request(DNS::manager, c, host, QUERY_A, true), user(u), blacklist(b), add_to_akill(add_akill) { }
+ DNSBLResolver(ServiceReference<XLineManager> &a, Module *c, DNS::Manager *manager, User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : Request(manager, c, host, QUERY_A, true), akills(a), user(u), blacklist(b), add_to_akill(add_akill) { }
void OnLookupComplete(const Query *record) override
{
@@ -81,7 +80,7 @@ class DNSBLResolver : public Request
ServiceBot *OperServ = Config->GetClient("OperServ");
Log(creator, "dnsbl", OperServ) << user->GetMask() << " (" << addr << ") appears in " << this->blacklist.name;
- XLine *x = new XLine(xline);
+ XLine *x = Serialize::New<XLine *>();
x->SetMask("*@" + addr);
x->SetBy(OperServ ? OperServ->nick : "m_dnsbl");
x->SetCreated(Anope::CurTime);
@@ -105,14 +104,18 @@ class DNSBLResolver : public Request
class ModuleDNSBL : public Module
, public EventHook<Event::UserConnect>
{
+ ServiceReference<DNS::Manager> manager;
std::vector<Blacklist> blacklists;
std::set<Anope::string> exempts;
bool check_on_connect;
bool check_on_netburst;
bool add_to_akill;
+ ServiceReference<XLineManager> akill;
public:
ModuleDNSBL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA)
+ , EventHook<Event::UserConnect>(this)
+ , akill("sgline")
{
}
@@ -158,7 +161,7 @@ class ModuleDNSBL : public Module
void OnUserConnect(User *user, bool &exempt) override
{
- if (exempt || user->Quitting() || (!this->check_on_connect && !Me->IsSynced()) || !DNS::manager)
+ if (exempt || user->Quitting() || (!this->check_on_connect && !Me->IsSynced()) || !manager)
return;
if (!this->check_on_netburst && !user->server->IsSynced())
@@ -186,8 +189,8 @@ class ModuleDNSBL : public Module
DNSBLResolver *res = NULL;
try
{
- res = new DNSBLResolver(this, user, b, dnsbl_host, this->add_to_akill);
- DNS::manager->Process(res);
+ res = new DNSBLResolver(akill, this, manager, user, b, dnsbl_host, this->add_to_akill);
+ manager->Process(res);
}
catch (const SocketException &ex)
{
diff --git a/modules/encryption/bcrypt.cpp b/modules/encryption/bcrypt.cpp
index 74d729491..ed003f883 100644
--- a/modules/encryption/bcrypt.cpp
+++ b/modules/encryption/bcrypt.cpp
@@ -877,6 +877,8 @@ class EBCRYPT : public Module
public:
EBCRYPT(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+ , EventHook<Event::Encrypt>(this)
+ , EventHook<Event::CheckAuthentication>(this)
, rounds(10)
{
// Test a pre-calculated hash
diff --git a/modules/encryption/md5.cpp b/modules/encryption/md5.cpp
index a92f5a4f9..0bf3942ec 100644
--- a/modules/encryption/md5.cpp
+++ b/modules/encryption/md5.cpp
@@ -345,6 +345,8 @@ class EMD5 : public Module
public:
EMD5(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+ , EventHook<Event::Encrypt>(this)
+ , EventHook<Event::CheckAuthentication>(this)
, md5provider(this)
{
if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
diff --git a/modules/encryption/none.cpp b/modules/encryption/none.cpp
index 8164534eb..c51bcb9ae 100644
--- a/modules/encryption/none.cpp
+++ b/modules/encryption/none.cpp
@@ -16,6 +16,9 @@ class ENone : public Module
{
public:
ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+ , EventHook<Event::Encrypt>(this)
+ , EventHook<Event::Decrypt>(this)
+ , EventHook<Event::CheckAuthentication>(this)
{
}
diff --git a/modules/encryption/old.cpp b/modules/encryption/old.cpp
index 4e3e70f7d..fc4598887 100644
--- a/modules/encryption/old.cpp
+++ b/modules/encryption/old.cpp
@@ -12,12 +12,15 @@
#include "module.h"
#include "modules/encryption.h"
-static ServiceReference<Encryption::Provider> md5("Encryption::Provider", "md5");
-
class OldMD5Provider : public Encryption::Provider
{
+ ServiceReference<Encryption::Provider> md5;
+
public:
- OldMD5Provider(Module *creator) : Encryption::Provider(creator, "oldmd5") { }
+ OldMD5Provider(Module *creator) : Encryption::Provider(creator, "oldmd5")
+ , md5("md5")
+ {
+ }
Encryption::Context *CreateContext(Encryption::IV *iv) override
{
@@ -39,12 +42,16 @@ class EOld : public Module
, public EventHook<Event::CheckAuthentication>
{
OldMD5Provider oldmd5provider;
+ ServiceReference<Encryption::Provider> md5;
inline static char XTOI(char c) { return c > 9 ? c - 'A' + 10 : c - '0'; }
public:
EOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+ , EventHook<Event::Encrypt>(this)
+ , EventHook<Event::CheckAuthentication>(this)
, oldmd5provider(this)
+ , md5("md5")
{
if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
throw ModuleException("enc_old is deprecated and can not be used as a primary encryption method");
diff --git a/modules/encryption/sha1.cpp b/modules/encryption/sha1.cpp
index a99bc834e..85fc9a5f2 100644
--- a/modules/encryption/sha1.cpp
+++ b/modules/encryption/sha1.cpp
@@ -200,6 +200,8 @@ class ESHA1 : public Module
public:
ESHA1(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+ , EventHook<Event::Encrypt>(this)
+ , EventHook<Event::CheckAuthentication>(this)
, sha1provider(this)
{
if (ModuleManager::FindFirstOf(ENCRYPTION) == this)
diff --git a/modules/encryption/sha256.cpp b/modules/encryption/sha256.cpp
index a138b3756..226cf0feb 100644
--- a/modules/encryption/sha256.cpp
+++ b/modules/encryption/sha256.cpp
@@ -275,6 +275,8 @@ class ESHA256 : public Module
public:
ESHA256(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
+ , EventHook<Event::Encrypt>(this)
+ , EventHook<Event::CheckAuthentication>(this)
, sha256provider(this)
{
diff --git a/modules/extra/ldap_authentication.cpp b/modules/extra/ldap_authentication.cpp
index dd63fd3fb..ac4b9dd4e 100644
--- a/modules/extra/ldap_authentication.cpp
+++ b/modules/extra/ldap_authentication.cpp
@@ -97,7 +97,7 @@ class IdentifyInterface : public LDAPInterface
{
na = new NickServ::Nick(ii->req->GetAccount(), new NickServ::Account(ii->req->GetAccount()));
na->SetLastRealname(ii->user ? ii->user->realname : ii->req->GetAccount());
- NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na, ii->req->GetPassword());;
+ NickServ::EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na, ii->req->GetPassword());;
ServiceBot *NickServ = Config->GetClient("NickServ");
if (ii->user && NickServ)
ii->user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->GetNick().c_str());
diff --git a/modules/extra/mysql.cpp b/modules/extra/mysql.cpp
index 843a2ba0a..11a5e1f15 100644
--- a/modules/extra/mysql.cpp
+++ b/modules/extra/mysql.cpp
@@ -182,6 +182,7 @@ class ModuleSQL : public Module
DispatcherThread *DThread;
ModuleSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
+ , EventHook<Event::ModuleUnload>(this)
{
me = this;
@@ -526,9 +527,9 @@ void MySQLService::Connect()
bool connect = mysql_real_connect(this->sql, this->server.c_str(), this->user.c_str(), this->password.c_str(), this->database.c_str(), this->port, NULL, CLIENT_MULTI_RESULTS);
if (!connect)
- throw SQL::Exception("Unable to connect to MySQL service " + this->name + ": " + mysql_error(this->sql));
+ throw SQL::Exception("Unable to connect to MySQL service " + this->GetName() + ": " + mysql_error(this->sql));
- Log(LOG_DEBUG) << "Successfully connected to MySQL service " << this->name << " at " << this->server << ":" << this->port;
+ Log(LOG_DEBUG) << "Successfully connected to MySQL service " << this->GetName() << " at " << this->server << ":" << this->port;
}
diff --git a/modules/extra/sasl_dh-aes.cpp b/modules/extra/sasl_dh-aes.cpp
index dd06d118b..b4920aeb4 100644
--- a/modules/extra/sasl_dh-aes.cpp
+++ b/modules/extra/sasl_dh-aes.cpp
@@ -161,7 +161,7 @@ class DHAES : public Mechanism
return Err(sess, pubkey);
SASL::IdentifyRequest* req = new SASL::IdentifyRequest(this->owner, m.source, username, password);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
req->Dispatch();
BN_free(pubkey);
diff --git a/modules/extra/sasl_dh-blowfish.cpp b/modules/extra/sasl_dh-blowfish.cpp
index f6e4b27b3..e3e0eb4f9 100644
--- a/modules/extra/sasl_dh-blowfish.cpp
+++ b/modules/extra/sasl_dh-blowfish.cpp
@@ -171,7 +171,7 @@ class DHBS : public Mechanism
return Err(sess, pubkey);
SASL::IdentifyRequest* req = new SASL::IdentifyRequest(this->owner, m.source, username, password);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
req->Dispatch();
BN_free(pubkey);
diff --git a/modules/extra/sql_authentication.cpp b/modules/extra/sql_authentication.cpp
index 1c2dbe729..a7d5b206f 100644
--- a/modules/extra/sql_authentication.cpp
+++ b/modules/extra/sql_authentication.cpp
@@ -43,7 +43,7 @@ class SQLAuthenticationResult : public SQL::Interface
if (na == NULL)
{
na = new NickServ::Nick(req->GetAccount(), new NickServ::Account(req->GetAccount()));
- NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, user, na, "");
+ NickServ::EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, user, na, "");
if (user && NickServ)
user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->GetNick().c_str());
}
diff --git a/modules/extra/stats/chanstats.cpp b/modules/extra/stats/chanstats.cpp
index 687c077b5..65a198449 100644
--- a/modules/extra/stats/chanstats.cpp
+++ b/modules/extra/stats/chanstats.cpp
@@ -20,7 +20,7 @@ class CommandCSSetChanstats : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -73,7 +73,7 @@ class CommandNSSetChanstats : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, na->GetAccount(), param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, na->GetAccount(), param);
if (MOD_RESULT == EVENT_STOP)
return;
diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp
index 3730f7e70..1a9127beb 100644
--- a/modules/fantasy.cpp
+++ b/modules/fantasy.cpp
@@ -77,7 +77,7 @@ class CommandBSSetFantasy : public Command
"Note that users wanting to use fantaisist\n"
"commands MUST have enough access for both\n"
"the FANTASIA and the command they are executing."),
- Config->GetModule(this->owner)->Get<Anope::string>("fantasycharacter", "!").c_str());
+ Config->GetModule(this->GetOwner())->Get<Anope::string>("fantasycharacter", "!").c_str());
return true;
}
};
@@ -90,15 +90,12 @@ class Fantasy : public Module
CommandBSSetFantasy commandbssetfantasy;
- EventHandlers<Event::BotFantasy> OnBotFantasy;
- EventHandlers<Event::BotNoFantasyAccess> OnBotNoFantasyAccess;
-
public:
Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , fantasy(this, ChanServ::channel, "BS_FANTASY")
+ , EventHook<Event::Privmsg>(this)
+ , EventHook<Event::ServiceBotEvent>(this)
+ , fantasy(this, "BS_FANTASY")
, commandbssetfantasy(this)
- , OnBotFantasy(this)
- , OnBotNoFantasyAccess(this)
{
}
@@ -156,7 +153,7 @@ class Fantasy : public Module
return;
const CommandInfo &info = it->second;
- ServiceReference<Command> cmd("Command", info.name);
+ ServiceReference<Command> cmd(info.name);
if (!cmd)
{
Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for non-existent service " << info.name << "!";
@@ -194,11 +191,11 @@ class Fantasy : public Module
EventReturn MOD_RESULT;
if (has_fantasia)
{
- MOD_RESULT = this->OnBotFantasy(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params);
}
else
{
- MOD_RESULT = this->OnBotNoFantasyAccess(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params);
}
if (MOD_RESULT == EVENT_STOP || !has_fantasia)
@@ -207,7 +204,7 @@ class Fantasy : public Module
if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission))
return;
- MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, cmd, params);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, cmd, params);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -215,7 +212,7 @@ class Fantasy : public Module
cmd->Execute(source, params);
if (!nc_reference)
source.nc = NULL;
- Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, cmd, params);
+ EventManager::Get()->Dispatch(&Event::PostCommand::OnPostCommand, source, cmd, params);
}
void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override
diff --git a/modules/global/global.cpp b/modules/global/global.cpp
index d6106b2be..9461dff75 100644
--- a/modules/global/global.cpp
+++ b/modules/global/global.cpp
@@ -14,6 +14,8 @@
class CommandGLGlobal : public Command
{
+ ServiceReference<Global::GlobalService> service;
+
public:
CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1)
{
@@ -25,14 +27,14 @@ class CommandGLGlobal : public Command
{
const Anope::string &msg = params[0];
- if (!Global::service)
+ if (!service)
{
source.Reply("No global reference, is global loaded?");
return;
}
Log(LOG_ADMIN, source, this);
- Global::service->SendGlobal(NULL, source.GetNick(), msg);
+ service->SendGlobal(NULL, source.GetNick(), msg);
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
diff --git a/modules/global/main/global.cpp b/modules/global/main/global.cpp
index f31605acb..57905c1d7 100644
--- a/modules/global/main/global.cpp
+++ b/modules/global/main/global.cpp
@@ -32,6 +32,10 @@ class GlobalCore : public Module
public:
GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
+ , EventHook<Event::Restart>(this)
+ , EventHook<Event::Shutdown>(this)
+ , EventHook<Event::NewServer>(this)
+ , EventHook<Event::Help>(this)
, GlobalService(this)
{
}
diff --git a/modules/greet.cpp b/modules/greet.cpp
index 69039849c..26834afa5 100644
--- a/modules/greet.cpp
+++ b/modules/greet.cpp
@@ -101,7 +101,7 @@ class CommandNSSetGreet : public Command
}
NickServ::Account *nc = na->GetAccount();
- EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -170,8 +170,11 @@ class Greet : public Module
public:
Greet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , bs_greet(this, ChanServ::channel, "BS_GREET")
- , ns_greet(this, NickServ::account, "greet")
+ , EventHook<Event::JoinChannel>(this)
+ , EventHook<Event::NickInfo>(this)
+ , EventHook<Event::ServiceBotEvent>(this)
+ , bs_greet(this, "BS_GREET")
+ , ns_greet(this, "greet")
, commandbssetgreet(this)
, commandnssetgreet(this)
, commandnssasetgreet(this)
diff --git a/modules/help.cpp b/modules/help.cpp
index debb25837..0e544dc1e 100644
--- a/modules/help.cpp
+++ b/modules/help.cpp
@@ -26,10 +26,8 @@ class CommandHelp : public Command
return NULL;
}
- EventHandlers<Event::Help> &onhelp;
-
public:
- CommandHelp(Module *creator, EventHandlers<Event::Help> &event) : Command(creator, "generic/help", 0), onhelp(event)
+ CommandHelp(Module *creator) : Command(creator, "generic/help", 0)
{
this->SetDesc(_("Displays this list and give information about commands"));
this->AllowUnregistered(true);
@@ -37,7 +35,7 @@ class CommandHelp : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
- EventReturn MOD_RESULT = this->onhelp(&Event::Help::OnPreHelp, source, params);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::Help::OnPreHelp, source, params);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -70,7 +68,7 @@ class CommandHelp : public Command
if (cmd != it->first && map.count(cmd))
continue;
- ServiceReference<Command> c("Command", info.name);
+ ServiceReference<Command> c(info.name);
if (!c)
continue;
@@ -133,7 +131,7 @@ class CommandHelp : public Command
const CommandInfo &info = it->second;
- ServiceReference<Command> c("Command", info.name);
+ ServiceReference<Command> c(info.name);
if (!c)
continue;
@@ -176,19 +174,17 @@ class CommandHelp : public Command
source.Reply(_("No help available for \002{0}\002."), params[0]);
}
- this->onhelp(&Event::Help::OnPostHelp, source, params);
+ EventManager::Get()->Dispatch(&Event::Help::OnPostHelp, source, params);
}
};
class Help : public Module
{
CommandHelp commandhelp;
- EventHandlers<Event::Help> onhelp;
public:
Help(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandhelp(this, onhelp)
- , onhelp(this)
+ , commandhelp(this)
{
}
diff --git a/modules/helpchan.cpp b/modules/helpchan.cpp
index 3897b2b5a..11ec4247d 100644
--- a/modules/helpchan.cpp
+++ b/modules/helpchan.cpp
@@ -12,6 +12,7 @@ class HelpChannel : public Module
{
public:
HelpChannel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::ChannelModeSet>(this)
{
}
diff --git a/modules/hostserv/del.cpp b/modules/hostserv/del.cpp
index 0830cd5b5..37823b1b7 100644
--- a/modules/hostserv/del.cpp
+++ b/modules/hostserv/del.cpp
@@ -14,10 +14,8 @@
class CommandHSDel : public Command
{
- EventHandlers<Event::DeleteVhost> &OnDeleteVhost;
-
public:
- CommandHSDel(Module *creator, EventHandlers<Event::DeleteVhost> &onDeleteVhost) : Command(creator, "hostserv/del", 1, 1), OnDeleteVhost(onDeleteVhost)
+ CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1)
{
this->SetDesc(_("Delete the vhost of another user"));
this->SetSyntax(_("\037user\037"));
@@ -37,7 +35,7 @@ class CommandHSDel : public Command
}
Log(LOG_ADMIN, source, this) << "for user " << na->GetNick();
- this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na);
+ EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na);
na->RemoveVhost();
source.Reply(_("Vhost for \002{0}\002 has been removed."), na->GetNick());
}
@@ -51,10 +49,8 @@ class CommandHSDel : public Command
class CommandHSDelAll : public Command
{
- EventHandlers<Event::DeleteVhost> &ondeletevhost;
-
public:
- CommandHSDelAll(Module *creator, EventHandlers<Event::DeleteVhost> &event) : Command(creator, "hostserv/delall", 1, 1), ondeletevhost(event)
+ CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1)
{
this->SetDesc(_("Delete the vhost for all nicks in a group"));
this->SetSyntax(_("\037group\037"));
@@ -73,10 +69,10 @@ class CommandHSDelAll : public Command
return;
}
- this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na);
+ EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na);
NickServ::Account *nc = na->GetAccount();
- for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>())
na2->RemoveVhost();
Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->GetDisplay();
source.Reply(_("Vhosts for group \002{0}\002 have been removed."), nc->GetDisplay());
@@ -93,13 +89,11 @@ class HSDel : public Module
{
CommandHSDel commandhsdel;
CommandHSDelAll commandhsdelall;
- EventHandlers<Event::DeleteVhost> ondeletevhost;
public:
HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandhsdel(this, ondeletevhost)
- , commandhsdelall(this, ondeletevhost)
- , ondeletevhost(this)
+ , commandhsdel(this)
+ , commandhsdelall(this)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
diff --git a/modules/hostserv/group.cpp b/modules/hostserv/group.cpp
index 3aff66e27..01e8ad722 100644
--- a/modules/hostserv/group.cpp
+++ b/modules/hostserv/group.cpp
@@ -26,10 +26,10 @@ class CommandHSGroup : public Command
return;
setting = true;
- for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>())
{
nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, nick);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, nick);
}
setting = false;
}
@@ -84,6 +84,8 @@ class HSGroup : public Module
public:
HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::SetVhost>(this)
+ , EventHook<Event::NickGroup>(this)
, commandhsgroup(this)
{
if (!IRCD || !IRCD->CanSetVHost)
diff --git a/modules/hostserv/list.cpp b/modules/hostserv/list.cpp
index 738f9f1bd..e77d8d9fa 100644
--- a/modules/hostserv/list.cpp
+++ b/modules/hostserv/list.cpp
@@ -53,7 +53,7 @@ class CommandHSList : public Command
}
}
- unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50");
+ unsigned display_counter = 0, listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50");
ListFormatter list(source.GetAccount());
list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created"));
diff --git a/modules/hostserv/main/hostserv.cpp b/modules/hostserv/main/hostserv.cpp
index 8fdfa560e..345d2cf97 100644
--- a/modules/hostserv/main/hostserv.cpp
+++ b/modules/hostserv/main/hostserv.cpp
@@ -25,6 +25,11 @@ class HostServCore : public Module
public:
HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
+ , EventHook<Event::UserLogin>(this)
+ , EventHook<Event::NickUpdate>(this)
+ , EventHook<Event::Help>(this)
+ , EventHook<Event::SetVhost>(this)
+ , EventHook<Event::DeleteVhost>(this)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp
index 8a064a84c..25f3de12b 100644
--- a/modules/hostserv/request.cpp
+++ b/modules/hostserv/request.cpp
@@ -1,7 +1,7 @@
/*
*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -11,11 +11,17 @@
#include "module.h"
#include "modules/memoserv.h"
-static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost);
-
class HostRequest : public Serialize::Object
{
+ friend class HostRequestType;
+
+ NickServ::Nick *na = nullptr;
+ Anope::string ident, host;
+ time_t time = 0;
+
public:
+ static constexpr const char *const NAME = "hostrequest";
+
HostRequest(Serialize::TypeBase *type) : Serialize::Object(type) { }
HostRequest(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { }
@@ -39,11 +45,11 @@ class HostRequestType : public Serialize::Type<HostRequest>
Serialize::Field<HostRequest, Anope::string> ident, host;
Serialize::Field<HostRequest, time_t> time;
- HostRequestType(Module *me) : Serialize::Type<HostRequest>(me, "HostRequest")
- , na(this, "na", true)
- , ident(this, "ident")
- , host(this, "host")
- , time(this, "time")
+ HostRequestType(Module *me) : Serialize::Type<HostRequest>(me)
+ , na(this, "na", &HostRequest::na, true)
+ , ident(this, "ident", &HostRequest::ident)
+ , host(this, "host", &HostRequest::host)
+ , time(this, "time", &HostRequest::time)
{
}
};
@@ -88,10 +94,32 @@ void HostRequest::SetTime(const time_t &t)
Set(&HostRequestType::time, t);
}
-static Serialize::TypeReference<HostRequest> hostrequest("HostRequest");
-
class CommandHSRequest : public Command
{
+ ServiceReference<MemoServ::MemoServService> memoserv;
+
+ void SendMemos(CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost)
+ {
+ Anope::string host;
+
+ if (!vIdent.empty())
+ host = vIdent + "@" + vHost;
+ else
+ host = vHost;
+
+ if (Config->GetModule(GetOwner())->Get<bool>("memooper") && memoserv)
+ for (Oper *o : Serialize::GetObjects<Oper *>())
+ {
+ NickServ::Nick *na = NickServ::FindNick(o->GetName());
+ if (!na)
+ continue;
+
+ Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str());
+
+ memoserv->Send(source.service->nick, na->GetNick(), message, true);
+ }
+ }
+
public:
CommandHSRequest(Module *creator) : Command(creator, "hostserv/request", 1, 1)
{
@@ -174,21 +202,21 @@ class CommandHSRequest : public Command
}
time_t send_delay = Config->GetModule("memoserv")->Get<time_t>("senddelay");
- if (Config->GetModule(this->owner)->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime)
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime)
{
source.Reply(_("Please wait %d seconds before requesting a new vHost."), send_delay);
u->lastmemosend = Anope::CurTime;
return;
}
- HostRequest *req = hostrequest.Create();
+ HostRequest *req = Serialize::New<HostRequest *>();
req->SetNick(na);
req->SetIdent(user);
req->SetHost(host);
req->SetTime(Anope::CurTime);
source.Reply(_("Your vhost has been requested."));
- req_send_memos(owner, source, user, host);
+ this->SendMemos(source, user, host);
Log(LOG_COMMAND, source, this) << "to request new vhost " << (!user.empty() ? user + "@" : "") << host;
}
@@ -201,6 +229,8 @@ class CommandHSRequest : public Command
class CommandHSActivate : public Command
{
+ ServiceReference<MemoServ::MemoServService> memoserv;
+
public:
CommandHSActivate(Module *creator) : Command(creator, "hostserv/activate", 1, 1)
{
@@ -233,10 +263,10 @@ class CommandHSActivate : public Command
}
na->SetVhost(req->GetIdent(), req->GetHost(), source.GetNick(), req->GetTime());
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na);
- if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service)
- MemoServ::service->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true);
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv)
+ memoserv->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true);
source.Reply(_("Vhost for \002{0}\002 has been activated."), na->GetNick());
Log(LOG_COMMAND, source, this) << "for " << na->GetNick() << " for vhost " << (!req->GetIdent().empty() ? req->GetIdent() + "@" : "") << req->GetHost();
@@ -246,7 +276,7 @@ class CommandHSActivate : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Activate the requested vhost for the given user."));
- if (Config->GetModule(this->owner)->Get<bool>("memouser"))
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser"))
source.Reply(_("A memo informing the user will also be sent."));
return true;
@@ -255,6 +285,8 @@ class CommandHSActivate : public Command
class CommandHSReject : public Command
{
+ ServiceReference<MemoServ::MemoServService> memoserv;
+
public:
CommandHSReject(Module *creator) : Command(creator, "hostserv/reject", 1, 2)
{
@@ -289,7 +321,7 @@ class CommandHSReject : public Command
req->Delete();
- if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service)
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv)
{
Anope::string message;
if (!reason.empty())
@@ -297,7 +329,7 @@ class CommandHSReject : public Command
else
message = _("[auto memo] Your requested vHost has been rejected.");
- MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true);
+ memoserv->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true);
}
source.Reply(_("Vhost for \002{0}\002 has been rejected."), na->GetNick());
@@ -307,7 +339,7 @@ class CommandHSReject : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Reject the requested vhost for the given user."));
- if (Config->GetModule(this->owner)->Get<bool>("memouser"))
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser"))
source.Reply(_("A memo informing the user will also be sent, which includes the reason for the rejection if supplied."));
return true;
@@ -325,12 +357,12 @@ class CommandHSWaiting : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
unsigned counter = 0;
- unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax");
+ unsigned display_counter = 0, listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax");
ListFormatter list(source.GetAccount());
list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created"));
- for (HostRequest *hr : Serialize::GetObjects<HostRequest *>(hostrequest))
+ for (HostRequest *hr : Serialize::GetObjects<HostRequest *>())
{
if (!listmax || display_counter < listmax)
{
@@ -388,27 +420,4 @@ class HSRequest : public Module
}
};
-static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost)
-{
- Anope::string host;
- std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end;
-
- if (!vIdent.empty())
- host = vIdent + "@" + vHost;
- else
- host = vHost;
-
- if (Config->GetModule(me)->Get<bool>("memooper") && MemoServ::service)
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
- {
- NickServ::Nick *na = NickServ::FindNick(o->GetName());
- if (!na)
- continue;
-
- Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str());
-
- MemoServ::service->Send(source.service->nick, na->GetNick(), message, true);
- }
-}
-
MODULE_INIT(HSRequest)
diff --git a/modules/hostserv/set.cpp b/modules/hostserv/set.cpp
index a86afead4..e7f42e630 100644
--- a/modules/hostserv/set.cpp
+++ b/modules/hostserv/set.cpp
@@ -86,7 +86,7 @@ class CommandHSSet : public Command
Log(LOG_ADMIN, source, this) << "to set the vhost of " << na->GetNick() << " to " << (!user.empty() ? user + "@" : "") << host;
na->SetVhost(user, host, source.GetNick());
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na);
if (!user.empty())
source.Reply(_("Vhost for \002{0}\002 set to \002{0}\002@\002{1}\002."), nick, user, host);
else
@@ -107,7 +107,7 @@ class CommandHSSetAll : public Command
if (!na || !na->HasVhost())
return;
- for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>())
nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
}
@@ -184,7 +184,7 @@ class CommandHSSetAll : public Command
na->SetVhost(user, host, source.GetNick());
this->Sync(na);
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na);
if (!user.empty())
source.Reply(_("Vhost for group \002{0}\002 set to \002{1}\002@\002{2}\002."), nick.c_str(), user.c_str(), host.c_str());
else
diff --git a/modules/httpd.cpp b/modules/httpd.cpp
index 1627ef133..ea0327316 100644
--- a/modules/httpd.cpp
+++ b/modules/httpd.cpp
@@ -340,7 +340,7 @@ class HTTPD : public Module
std::map<Anope::string, MyHTTPProvider *> providers;
public:
HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
- , sslref("SSLService", "ssl")
+ , EventHook<Event::ModuleLoad>(this)
{
}
@@ -445,10 +445,10 @@ class HTTPD : public Module
HTTPProvider *p = it->second;
++it;
- if (existing.count(p->name) == 0)
+ if (existing.count(p->GetName()) == 0)
{
- Log(this) << "Removing HTTP server " << p->name;
- this->providers.erase(p->name);
+ Log(this) << "Removing HTTP server " << p->GetName();
+ this->providers.erase(p->GetName());
delete p;
}
}
diff --git a/modules/memoserv/cancel.cpp b/modules/memoserv/cancel.cpp
index e3da82581..fe61fe18c 100644
--- a/modules/memoserv/cancel.cpp
+++ b/modules/memoserv/cancel.cpp
@@ -32,7 +32,7 @@ class CommandMSCancel : public Command
const Anope::string &nname = params[0];
bool ischan, isregistered;
- MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(name, ischan, isregistered, false);
+ MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(nname, ischan, isregistered, false);
if (!isregistered)
{
@@ -57,8 +57,7 @@ class CommandMSCancel : public Command
MemoServ::Memo *m = memos[i];
if (m->GetUnread() && source.nc->GetDisplay().equals_ci(m->GetSender()))
{
- if (MemoServ::Event::OnMemoDel)
- MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->GetName() : na->GetAccount()->GetDisplay(), mi, m);
+ EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->GetName() : na->GetAccount()->GetDisplay(), mi, m);
mi->Del(i);
source.Reply(_("Your last memo to \002{0}\002 has been cancelled."), nname);
return;
diff --git a/modules/memoserv/del.cpp b/modules/memoserv/del.cpp
index 79af11adc..dffa3c8cd 100644
--- a/modules/memoserv/del.cpp
+++ b/modules/memoserv/del.cpp
@@ -81,8 +81,7 @@ class CommandMSDel : public Command
if (!number || number > memos.size())
return;
- if (MemoServ::Event::OnMemoDel)
- MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(number - 1));
+ EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(number - 1));
mi->Del(number - 1);
source.Reply(_("Memo \002{0}\002 has been deleted."), number);
@@ -92,8 +91,7 @@ class CommandMSDel : public Command
else if (numstr.equals_ci("LAST"))
{
/* Delete last memo. */
- if (MemoServ::Event::OnMemoDel)
- MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(memos.size() - 1));
+ EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(memos.size() - 1));
mi->Del(memos.size() - 1);
source.Reply(_("Memo \002{0}\002 has been deleted."), memos.size() + 1);
}
@@ -103,8 +101,7 @@ class CommandMSDel : public Command
std::for_each(memos.begin(), memos.end(),
[&](MemoServ::Memo *m)
{
- if (MemoServ::Event::OnMemoDel)
- MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, m);
+ EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, m);
delete m;
});
if (!chan.empty())
diff --git a/modules/memoserv/ignore.cpp b/modules/memoserv/ignore.cpp
index c454444ea..7dad842cf 100644
--- a/modules/memoserv/ignore.cpp
+++ b/modules/memoserv/ignore.cpp
@@ -66,7 +66,7 @@ class CommandMSIgnore : public Command
if (command.equals_ci("ADD") && !param.empty())
{
- if (ignores.size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "32"))
+ if (ignores.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("max", "32"))
{
source.Reply(_("Sorry, the memo ignore list for \002{0}\002 is full."), channel);
return;
@@ -79,7 +79,7 @@ class CommandMSIgnore : public Command
return;
}
- MemoServ::Ignore *ign = MemoServ::service->CreateIgnore();
+ MemoServ::Ignore *ign = Serialize::New<MemoServ::Ignore *>();
ign->SetMemoInfo(mi);
ign->SetMask(param);
diff --git a/modules/memoserv/main/ignore.h b/modules/memoserv/main/ignore.h
index c98b44adf..0147cc2be 100644
--- a/modules/memoserv/main/ignore.h
+++ b/modules/memoserv/main/ignore.h
@@ -2,6 +2,11 @@
class IgnoreImpl : public MemoServ::Ignore
{
+ friend class IgnoreType;
+
+ MemoServ::MemoInfo *memoinfo = nullptr;
+ Anope::string mask;
+
public:
IgnoreImpl(Serialize::TypeBase *type) : MemoServ::Ignore(type) { }
IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Ignore(type, id) { }
diff --git a/modules/memoserv/main/ignoretype.cpp b/modules/memoserv/main/ignoretype.cpp
index 375f83272..015925b5f 100644
--- a/modules/memoserv/main/ignoretype.cpp
+++ b/modules/memoserv/main/ignoretype.cpp
@@ -1,9 +1,9 @@
#include "module.h"
#include "ignoretype.h"
-IgnoreType::IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me, "MemoIgnore")
- , mi(this, "mi", true)
- , mask(this, "mask")
+IgnoreType::IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me)
+ , mi(this, "mi", &IgnoreImpl::memoinfo, true)
+ , mask(this, "mask", &IgnoreImpl::mask)
{
}
diff --git a/modules/memoserv/main/memo.h b/modules/memoserv/main/memo.h
index 1a230c1e9..c0000259a 100644
--- a/modules/memoserv/main/memo.h
+++ b/modules/memoserv/main/memo.h
@@ -2,11 +2,16 @@
class MemoImpl : public MemoServ::Memo
{
+ friend class MemoType;
+
+ MemoServ::MemoInfo *memoinfo = nullptr;
+ Anope::string text, sender;
+ time_t time = 0;
+ bool unread = false, receipt = false;
+
public:
MemoImpl(Serialize::TypeBase *type) : MemoServ::Memo(type) { }
MemoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Memo(type, id) { }
- //using MemoServ::Memo::Memo;
-// MemoImpl();
~MemoImpl();
MemoServ::MemoInfo *GetMemoInfo() override;
diff --git a/modules/memoserv/main/memoinfo.cpp b/modules/memoserv/main/memoinfo.cpp
index 45d95533e..5f3b4cccc 100644
--- a/modules/memoserv/main/memoinfo.cpp
+++ b/modules/memoserv/main/memoinfo.cpp
@@ -53,11 +53,11 @@ void MemoInfoImpl::SetMemoMax(const int16_t &i)
std::vector<MemoServ::Memo *> MemoInfoImpl::GetMemos()
{
- return GetRefs<MemoServ::Memo *>(MemoServ::memo);
+ return GetRefs<MemoServ::Memo *>();
}
std::vector<MemoServ::Ignore *> MemoInfoImpl::GetIgnores()
{
- return GetRefs<MemoServ::Ignore *>(MemoServ::ignore);
+ return GetRefs<MemoServ::Ignore *>();
}
diff --git a/modules/memoserv/main/memoinfo.h b/modules/memoserv/main/memoinfo.h
index 22ea0734f..42f5483ac 100644
--- a/modules/memoserv/main/memoinfo.h
+++ b/modules/memoserv/main/memoinfo.h
@@ -2,6 +2,11 @@
class MemoInfoImpl : public MemoServ::MemoInfo
{
+ friend class MemoInfoType;
+
+ Serialize::Object *owner = nullptr;
+ int16_t memomax = 0;
+
public:
MemoInfoImpl(Serialize::TypeBase *type) : MemoServ::MemoInfo(type) { }
MemoInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::MemoInfo(type, id) { }
diff --git a/modules/memoserv/main/memoinfotype.cpp b/modules/memoserv/main/memoinfotype.cpp
index 7eb3af72c..ff387e883 100644
--- a/modules/memoserv/main/memoinfotype.cpp
+++ b/modules/memoserv/main/memoinfotype.cpp
@@ -1,9 +1,9 @@
#include "module.h"
#include "memoinfotype.h"
-MemoInfoType::MemoInfoType(Module *me) : Serialize::Type<MemoInfoImpl>(me, "MemoInfo")
- , owner(this, "owner", true)
- , memomax(this, "memomax")
+MemoInfoType::MemoInfoType(Module *me) : Serialize::Type<MemoInfoImpl>(me)
+ , owner(this, "owner", &MemoInfoImpl::owner, true)
+ , memomax(this, "memomax", &MemoInfoImpl::memomax)
{
}
diff --git a/modules/memoserv/main/memoserv.cpp b/modules/memoserv/main/memoserv.cpp
index ed3939ef7..79344b25e 100644
--- a/modules/memoserv/main/memoserv.cpp
+++ b/modules/memoserv/main/memoserv.cpp
@@ -14,16 +14,13 @@
#include "modules/help.h"
#include "modules/botserv/bot.h"
#include "modules/memoserv.h"
-//#include "memoinfo.h"
-//#include "memo.h"
-//#include "ignore.h"
#include "memotype.h"
#include "memoinfotype.h"
#include "ignoretype.h"
class MemoServCore : public Module, public MemoServ::MemoServService
- , public EventHook<Event::NickCoreCreate>
- , public EventHook<Event::CreateChan>
+ , public EventHook<NickServ::Event::NickRegister>
+ , public EventHook<Event::ChanRegistered>
, public EventHook<Event::BotDelete>
, public EventHook<Event::NickIdentify>
, public EventHook<Event::JoinChannel>
@@ -32,8 +29,6 @@ class MemoServCore : public Module, public MemoServ::MemoServService
, public EventHook<Event::Help>
{
Reference<ServiceBot> MemoServ;
- EventHandlers<MemoServ::Event::MemoSend> onmemosend;
- EventHandlers<MemoServ::Event::MemoDel> onmemodel;
MemoInfoType memoinfo_type;
MemoType memo_type;
@@ -62,8 +57,16 @@ class MemoServCore : public Module, public MemoServ::MemoServService
public:
MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
, MemoServ::MemoServService(this)
- , onmemosend(this)
- , onmemodel(this)
+
+ , EventHook<NickServ::Event::NickRegister>(this)
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::BotDelete>(this)
+ , EventHook<Event::NickIdentify>(this)
+ , EventHook<Event::JoinChannel>(this)
+ , EventHook<Event::UserAway>(this)
+ , EventHook<Event::NickUpdate>(this)
+ , EventHook<Event::Help>(this)
+
, memoinfo_type(this)
, memo_type(this)
, ignore_type(this)
@@ -95,14 +98,14 @@ class MemoServCore : public Module, public MemoServ::MemoServService
if (sender != NULL)
sender->lastmemosend = Anope::CurTime;
- MemoServ::Memo *m = new MemoImpl(&memo_type);
+ MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>();
m->SetMemoInfo(mi);
m->SetSender(source);
m->SetTime(Anope::CurTime);
m->SetText(message);
m->SetUnread(true);
- this->onmemosend(&MemoServ::Event::MemoSend::OnMemoSend, source, target, mi, m);
+ EventManager::Get()->Dispatch(&MemoServ::Event::MemoSend::OnMemoSend, source, target, mi, m);
if (ischan)
{
@@ -160,16 +163,6 @@ class MemoServCore : public Module, public MemoServ::MemoServService
}
}
- MemoServ::Memo *CreateMemo() override
- {
- return new MemoImpl(&memo_type);
- }
-
- MemoServ::Ignore *CreateIgnore() override
- {
- return new IgnoreImpl(&ignore_type);
- }
-
MemoServ::MemoInfo *GetMemoInfo(const Anope::string &target, bool &is_registered, bool &ischan, bool create) override
{
if (!target.empty() && target[0] == '#')
@@ -181,7 +174,7 @@ class MemoServCore : public Module, public MemoServ::MemoServService
is_registered = true;
if (create && !ci->GetMemos())
{
- MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type);
+ MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>();
mi->SetOwner(ci);
}
return ci->GetMemos();
@@ -198,7 +191,7 @@ class MemoServCore : public Module, public MemoServ::MemoServService
is_registered = true;
if (create && !na->GetAccount()->GetMemos())
{
- MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type);
+ MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>();
mi->SetOwner(na->GetAccount());
}
return na->GetAccount()->GetMemos();
@@ -224,16 +217,16 @@ class MemoServCore : public Module, public MemoServ::MemoServService
MemoServ = bi;
}
- void OnNickCoreCreate(NickServ::Account *nc) override
+ void OnNickRegister(User *, NickServ::Nick *na, const Anope::string &) override
{
- MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type);
- mi->SetOwner(mi);
+ MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>();
+ mi->SetOwner(na->GetAccount());
mi->SetMemoMax(Config->GetModule(this)->Get<int>("maxmemos"));
}
- void OnCreateChan(ChanServ::Channel *ci) override
+ void OnChanRegistered(ChanServ::Channel *ci) override
{
- MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type);
+ MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>();
mi->SetOwner(ci);
mi->SetMemoMax(Config->GetModule(this)->Get<int>("maxmemos"));
}
diff --git a/modules/memoserv/main/memotype.cpp b/modules/memoserv/main/memotype.cpp
index c9144bbaa..57cf3ba31 100644
--- a/modules/memoserv/main/memotype.cpp
+++ b/modules/memoserv/main/memotype.cpp
@@ -1,13 +1,13 @@
#include "module.h"
#include "memotype.h"
-MemoType::MemoType(Module *me) : Serialize::Type<MemoImpl>(me, "Memo")
- , mi(this, "mi", true)
- , time(this, "time")
- , sender(this, "sender")
- , text(this, "text")
- , unread(this, "unread")
- , receipt(this, "receipt")
+MemoType::MemoType(Module *me) : Serialize::Type<MemoImpl>(me)
+ , mi(this, "mi", &MemoImpl::memoinfo, true)
+ , time(this, "time", &MemoImpl::time)
+ , sender(this, "sender", &MemoImpl::sender)
+ , text(this, "text", &MemoImpl::text)
+ , unread(this, "unread", &MemoImpl::unread)
+ , receipt(this, "receipt", &MemoImpl::receipt)
{
}
diff --git a/modules/memoserv/rsend.cpp b/modules/memoserv/rsend.cpp
index 16f6105fa..887c87cc6 100644
--- a/modules/memoserv/rsend.cpp
+++ b/modules/memoserv/rsend.cpp
@@ -23,6 +23,7 @@ class CommandMSRSend : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
+#warning "this is completely disabled"
#if 0
if (!MemoServ::service)
return;
@@ -44,7 +45,7 @@ class CommandMSRSend : public Command
return;
}
- if (Config->GetModule(this->owner)->Get<bool>("operonly") && !source.IsServicesOper())
+ if (Config->GetModule(this->GetOwner())->Get<bool>("operonly") && !source.IsServicesOper())
source.Reply(_("Access denied. This command is for operators only."));
else
{
diff --git a/modules/memoserv/set.cpp b/modules/memoserv/set.cpp
index c924d0ea0..361ebeba3 100644
--- a/modules/memoserv/set.cpp
+++ b/modules/memoserv/set.cpp
@@ -301,11 +301,11 @@ class MSSet : public Module
public:
MSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
, commandmsset(this)
- , memo_signon(this, NickServ::account, "MEMO_SIGNON")
- , memo_receive(this, NickServ::account, "MEMO_RECEIVE")
- , memo_mail(this, NickServ::account, "MEMO_MAIL")
- , memo_hardmax_nick(this, NickServ::account, "MEMO_HARDMAX")
- , memo_hardmax_channel(this, ChanServ::channel, "MEMO_HARDMAX")
+ , memo_signon(this, "MEMO_SIGNON")
+ , memo_receive(this, "MEMO_RECEIVE")
+ , memo_mail(this, "MEMO_MAIL")
+ , memo_hardmax_nick(this, "MEMO_HARDMAX")
+ , memo_hardmax_channel(this, "MEMO_HARDMAX")
{
}
diff --git a/modules/nickserv/access.cpp b/modules/nickserv/access.cpp
index 0e405484c..f29b98904 100644
--- a/modules/nickserv/access.cpp
+++ b/modules/nickserv/access.cpp
@@ -15,6 +15,11 @@
class NickAccessImpl : public NickAccess
{
+ friend class NickAccessType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string mask;
+
public:
NickAccessImpl(Serialize::TypeBase *type) : NickAccess(type) { }
NickAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : NickAccess(type, id) { }
@@ -32,9 +37,9 @@ class NickAccessType : public Serialize::Type<NickAccessImpl>
Serialize::ObjectField<NickAccessImpl, NickServ::Account *> account;
Serialize::Field<NickAccessImpl, Anope::string> mask;
- NickAccessType(Module *creator) : Serialize::Type<NickAccessImpl>(creator, "NSAccess")
- , account(this, "account", true)
- , mask(this, "mask")
+ NickAccessType(Module *creator) : Serialize::Type<NickAccessImpl>(creator)
+ , account(this, "account", &NickAccessImpl::account, true)
+ , mask(this, "mask", &NickAccessImpl::mask)
{
}
};
@@ -76,11 +81,11 @@ class CommandNSAccess : public Command
return;
}
- std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>(nsaccess);
+ std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>();
- if (access.size() >= Config->GetModule(this->owner)->Get<unsigned>("accessmax", "32"))
+ if (access.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("accessmax", "32"))
{
- source.Reply(_("Sorry, the maximum of \002{0}\002 access entries has been reached."), Config->GetModule(this->owner)->Get<unsigned>("accessmax"));
+ source.Reply(_("Sorry, the maximum of \002{0}\002 access entries has been reached."), Config->GetModule(this->GetOwner())->Get<unsigned>("accessmax"));
return;
}
@@ -91,7 +96,7 @@ class CommandNSAccess : public Command
return;
}
- NickAccess *a = nsaccess.Create();
+ NickAccess *a = Serialize::New<NickAccess *>();
a->SetAccount(nc);
a->SetMask(mask);
@@ -113,7 +118,7 @@ class CommandNSAccess : public Command
return;
}
- for (NickAccess *a : nc->GetRefs<NickAccess *>(nsaccess))
+ for (NickAccess *a : nc->GetRefs<NickAccess *>())
if (a->GetMask().equals_ci(mask))
{
a->Delete();
@@ -128,7 +133,7 @@ class CommandNSAccess : public Command
void DoList(CommandSource &source, NickServ::Account *nc, const Anope::string &mask)
{
- std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>(nsaccess);
+ std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>();
if (access.empty())
{
source.Reply(_("The access list of \002{0}\002 is empty."), nc->GetDisplay());
@@ -236,6 +241,7 @@ class NSAccess : public Module
public:
NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<NickServ::Event::NickRegister>(this)
, commandnsaccess(this)
, nick_type(this)
{
@@ -245,11 +251,12 @@ class NSAccess : public Module
{
if (u && Config->GetModule(this)->Get<bool>("addaccessonreg"))
{
- NickAccess *a = nsaccess.Create();
+ NickAccess *a = Serialize::New<NickAccess *>();
a->SetAccount(na->GetAccount());
a->SetMask(u->Mask());
- //XXX?
-// source.Reply(_("\002{0}\002 has been registered under your hostmask: \002{1}\002"), u_nick, na->GetAccount()->GetAccess(0));
+
+ u->SendMessage(Config->GetClient("NickServ"),
+ _("\002{0}\002 has been registered under your hostmask: \002{1}\002"), na->GetNick(), a->GetMask());
}
}
};
diff --git a/modules/nickserv/ajoin.cpp b/modules/nickserv/ajoin.cpp
index 0b074a84a..fc5e9b198 100644
--- a/modules/nickserv/ajoin.cpp
+++ b/modules/nickserv/ajoin.cpp
@@ -14,6 +14,11 @@
class AutoJoinImpl : public AutoJoin
{
+ friend class AutoJoinType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string channel, key;
+
public:
AutoJoinImpl(Serialize::TypeBase *type) : AutoJoin(type) { }
AutoJoinImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoJoin(type, id) { }
@@ -34,10 +39,10 @@ class AutoJoinType : public Serialize::Type<AutoJoinImpl>
Serialize::ObjectField<AutoJoinImpl, NickServ::Account *> owner;
Serialize::Field<AutoJoinImpl, Anope::string> channel, key;
- AutoJoinType(Module *me) : Serialize::Type<AutoJoinImpl>(me, "AutoJoin")
- , owner(this, "owner", true)
- , channel(this, "channel")
- , key(this, "key")
+ AutoJoinType(Module *me) : Serialize::Type<AutoJoinImpl>(me)
+ , owner(this, "owner", &AutoJoinImpl::account, true)
+ , channel(this, "channel", &AutoJoinImpl::channel)
+ , key(this, "key", &AutoJoinImpl::key)
{
}
};
@@ -76,7 +81,7 @@ class CommandNSAJoin : public Command
{
void DoList(CommandSource &source, NickServ::Account *nc)
{
- std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(autojoin);
+ std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>();
if (channels.empty())
{
@@ -107,7 +112,7 @@ class CommandNSAJoin : public Command
void DoAdd(CommandSource &source, NickServ::Account *nc, const Anope::string &chans, const Anope::string &keys)
{
- std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(autojoin);
+ std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>();
Anope::string addedchans;
Anope::string alreadyadded;
@@ -123,9 +128,9 @@ class CommandNSAJoin : public Command
if (channels[i]->GetChannel().equals_ci(chan))
break;
- if (channels.size() >= Config->GetModule(this->owner)->Get<unsigned>("ajoinmax"))
+ if (channels.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("ajoinmax"))
{
- source.Reply(_("Sorry, the maximum of \002{0}\002 auto join entries has been reached."), Config->GetModule(this->owner)->Get<unsigned>("ajoinmax"));
+ source.Reply(_("Sorry, the maximum of \002{0}\002 auto join entries has been reached."), Config->GetModule(this->GetOwner())->Get<unsigned>("ajoinmax"));
return;
}
@@ -143,7 +148,7 @@ class CommandNSAJoin : public Command
continue;
}
- AutoJoin *entry = autojoin.Create();
+ AutoJoin *entry = Serialize::New<AutoJoin *>();
entry->SetOwner(nc);
entry->SetChannel(chan);
entry->SetKey(key);
@@ -174,7 +179,7 @@ class CommandNSAJoin : public Command
void DoDel(CommandSource &source, NickServ::Account *nc, const Anope::string &chans)
{
- std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(autojoin);
+ std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>();
Anope::string delchans;
Anope::string notfoundchans;
commasepstream sep(chans);
@@ -282,6 +287,7 @@ class NSAJoin : public Module
public:
NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserLogin>(this)
, commandnsajoin(this)
, ajtype(this)
{
@@ -297,7 +303,7 @@ class NSAJoin : public Module
if (!NickServ)
return;
- std::vector<AutoJoin *> channels = u->Account()->GetRefs<AutoJoin *>(autojoin);
+ std::vector<AutoJoin *> channels = u->Account()->GetRefs<AutoJoin *>();
if (channels.empty())
return;
diff --git a/modules/nickserv/alist.cpp b/modules/nickserv/alist.cpp
index e4aaff38b..f80af7cb1 100644
--- a/modules/nickserv/alist.cpp
+++ b/modules/nickserv/alist.cpp
@@ -47,7 +47,7 @@ class CommandNSAList : public Command
list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Access")).AddColumn(_("Description"));
- std::vector<ChanServ::Channel *> chans = nc->GetRefs<ChanServ::Channel *>(ChanServ::channel);
+ std::vector<ChanServ::Channel *> chans = nc->GetRefs<ChanServ::Channel *>();
std::sort(chans.begin(), chans.end(), ChannelSort);
for (ChanServ::Channel *ci : chans)
{
diff --git a/modules/nickserv/cert.cpp b/modules/nickserv/cert.cpp
index 23487f305..6df85aacd 100644
--- a/modules/nickserv/cert.cpp
+++ b/modules/nickserv/cert.cpp
@@ -14,7 +14,6 @@
#include "modules/nickserv.h"
static Anope::hash_map<NickServ::Account *> certmap;
-static EventHandlers<Event::NickCertEvents> *events;
class CertServiceImpl : public CertService
{
@@ -31,7 +30,7 @@ class CertServiceImpl : public CertService
bool Matches(User *u, NickServ::Account *nc) override
{
- std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry);
+ std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>();
return !u->fingerprint.empty() && FindCert(cl, u->fingerprint);
}
@@ -46,6 +45,11 @@ class CertServiceImpl : public CertService
class NSCertEntryImpl : public NSCertEntry
{
+ friend class NSCertEntryType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string cert;
+
public:
NSCertEntryImpl(Serialize::TypeBase *type) : NSCertEntry(type) { }
NSCertEntryImpl(Serialize::TypeBase *type, Serialize::ID id) : NSCertEntry(type, id) { }
@@ -95,9 +99,9 @@ class NSCertEntryType : public Serialize::Type<NSCertEntryImpl>
}
} mask;
- NSCertEntryType(Module *me) : Serialize::Type<NSCertEntryImpl>(me, "NSCertEntry")
- , nc(this, "nc", true)
- , mask(this, "mask")
+ NSCertEntryType(Module *me) : Serialize::Type<NSCertEntryImpl>(me)
+ , nc(this, "nc", &NSCertEntryImpl::account, true)
+ , mask(this, "mask", &NSCertEntryImpl::cert)
{
}
};
@@ -141,8 +145,8 @@ class CommandNSCert : public Command
void DoAdd(CommandSource &source, NickServ::Account *nc, Anope::string certfp)
{
- std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry);
- unsigned max = Config->GetModule(this->owner)->Get<unsigned>("max", "5");
+ std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>();
+ unsigned max = Config->GetModule(this->GetOwner())->Get<unsigned>("max", "5");
if (cl.size() >= max)
{
@@ -175,9 +179,11 @@ class CommandNSCert : public Command
return;
}
- NSCertEntry *e = certentry.Create();
+ NSCertEntry *e = Serialize::New<NSCertEntry *>();
e->SetAccount(nc);
e->SetCert(certfp);
+
+ // XXX fire events
Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to ADD certificate fingerprint " << certfp << " to " << nc->GetDisplay();
source.Reply(_("\002{0}\002 added to the certificate list of \002{1}\002."), certfp, nc->GetDisplay());
@@ -185,7 +191,7 @@ class CommandNSCert : public Command
void DoDel(CommandSource &source, NickServ::Account *nc, Anope::string certfp)
{
- std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry);
+ std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>();
if (certfp.empty())
{
@@ -215,7 +221,7 @@ class CommandNSCert : public Command
void DoList(CommandSource &source, NickServ::Account *nc)
{
- std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry);
+ std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>();
if (cl.empty())
{
@@ -309,18 +315,15 @@ class NSCert : public Module
CommandNSCert commandnscert;
CertServiceImpl cs;
- EventHandlers<Event::NickCertEvents> onnickservevents;
-
public:
NSCert(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::Fingerprint>(this)
+ , EventHook<NickServ::Event::NickValidate>(this)
, commandnscert(this)
, cs(this)
- , onnickservevents(this)
{
if (!IRCD || !IRCD->CanCertFP)
throw ModuleException("Your IRCd does not support ssl client certificates");
-
- events = &onnickservevents;
}
void OnFingerprint(User *u) override
diff --git a/modules/nickserv/drop.cpp b/modules/nickserv/drop.cpp
index e1eba9a3c..e45f1e2ea 100644
--- a/modules/nickserv/drop.cpp
+++ b/modules/nickserv/drop.cpp
@@ -14,10 +14,8 @@
class CommandNSDrop : public Command
{
- EventHandlers<Event::NickDrop> &onnickdrop;
-
public:
- CommandNSDrop(Module *creator, EventHandlers<Event::NickDrop> &event) : Command(creator, "nickserv/drop", 1, 1), onnickdrop(event)
+ CommandNSDrop(Module *creator) : Command(creator, "nickserv/drop", 1, 1)
{
this->SetSyntax(_("\037nickname\037"));
this->SetDesc(_("Cancel the registration of a nickname"));
@@ -54,7 +52,7 @@ class CommandNSDrop : public Command
return;
}
- this->onnickdrop(&Event::NickDrop::OnNickDrop, source, na);
+ EventManager::Get()->Dispatch(&Event::NickDrop::OnNickDrop, source, na);
Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->GetNick() << " (group: " << na->GetAccount()->GetDisplay() << ") (email: " << (!na->GetAccount()->GetEmail().empty() ? na->GetAccount()->GetEmail() : "none") << ")";
na->Delete();
@@ -77,12 +75,10 @@ class CommandNSDrop : public Command
class NSDrop : public Module
{
CommandNSDrop commandnsdrop;
- EventHandlers<Event::NickDrop> onnickdrop;
public:
NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandnsdrop(this, onnickdrop)
- , onnickdrop(this)
+ , commandnsdrop(this)
{
}
diff --git a/modules/nickserv/group.cpp b/modules/nickserv/group.cpp
index 3a50d0306..5c9fb326f 100644
--- a/modules/nickserv/group.cpp
+++ b/modules/nickserv/group.cpp
@@ -15,14 +15,13 @@
class NSGroupRequestListener : public NickServ::IdentifyRequestListener
{
- EventHandlers<Event::NickGroup> &onnickgroup;
CommandSource source;
Command *cmd;
Anope::string nick;
Reference<NickServ::Nick> target;
public:
- NSGroupRequestListener(EventHandlers<Event::NickGroup> &event, CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : onnickgroup(event), source(src), cmd(c), nick(n), target(targ) { }
+ NSGroupRequestListener(CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : source(src), cmd(c), nick(n), target(targ) { }
void OnSuccess(NickServ::IdentifyRequest *) override
{
@@ -34,11 +33,11 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener
/* If the nick is already registered, drop it. */
if (na)
{
- Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->GetAccount(), u->nick);
+ EventManager::Get()->Dispatch(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->GetAccount(), u->nick);
delete na;
}
- na = NickServ::nick.Create();
+ na = Serialize::New<NickServ::Nick *>();
na->SetNick(nick);
na->SetAccount(target->GetAccount());
na->SetLastUsermask(u->GetIdent() + "@" + u->GetDisplayedHost());
@@ -47,7 +46,7 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener
na->SetTimeRegistered(Anope::CurTime);
u->Login(target->GetAccount());
- this->onnickgroup(&Event::NickGroup::OnNickGroup, u, target);
+ EventManager::Get()->Dispatch(&Event::NickGroup::OnNickGroup, u, target);
Log(LOG_COMMAND, source, cmd) << "to make " << nick << " join group of " << target->GetNick() << " (" << target->GetAccount()->GetDisplay() << ") (email: " << (!target->GetAccount()->GetEmail().empty() ? target->GetAccount()->GetEmail() : "none") << ")";
source.Reply(_("You are now in the group of \002{0}\002."), target->GetNick());
@@ -69,10 +68,10 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener
class CommandNSGroup : public Command
{
- EventHandlers<Event::NickGroup> &onnickgroup;
-
+ ServiceReference<CertService> certservice;
+
public:
- CommandNSGroup(Module *creator, EventHandlers<Event::NickGroup> &event) : Command(creator, "nickserv/group", 0, 2), onnickgroup(event)
+ CommandNSGroup(Module *creator) : Command(creator, "nickserv/group", 0, 2)
{
this->SetDesc(_("Join a group"));
this->SetSyntax(_("\037[target]\037 \037[password]\037"));
@@ -115,7 +114,7 @@ class CommandNSGroup : public Command
}
if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks"))
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
{
if (!u->HasMode("OPER") && u->nick.find_ci(o->GetName()) != Anope::string::npos)
{
@@ -127,7 +126,7 @@ class CommandNSGroup : public Command
NickServ::Nick *target, *na = NickServ::FindNick(u->nick);
const Anope::string &guestnick = Config->GetModule("nickserv")->Get<Anope::string>("guestnickprefix", "Guest");
time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay");
- unsigned maxaliases = Config->GetModule(this->owner)->Get<unsigned>("maxaliases");
+ unsigned maxaliases = Config->GetModule(this->GetOwner())->Get<unsigned>("maxaliases");
if (!(target = NickServ::FindNick(nick)))
{
source.Reply(_("\002{0}\002 isn't registered."), nick);
@@ -147,7 +146,7 @@ class CommandNSGroup : public Command
return;
}
- if (na && Config->GetModule(this->owner)->Get<bool>("nogroupchange"))
+ if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange"))
{
source.Reply(_("Your nick is already registered."));
return;
@@ -165,13 +164,13 @@ class CommandNSGroup : public Command
return;
}
- if (na && Config->GetModule(this->owner)->Get<bool>("nogroupchange"))
+ if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange"))
{
source.Reply(_("You are already registered."));
return;
}
- if (maxaliases && target->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick).size() >= maxaliases && !target->GetAccount()->IsServicesOper())
+ if (maxaliases && target->GetAccount()->GetRefs<NickServ::Nick *>().size() >= maxaliases && !target->GetAccount()->IsServicesOper())
{
source.Reply(_("There are too many nicknames in your group."));
return;
@@ -194,13 +193,13 @@ class CommandNSGroup : public Command
if (ok == false && !pass.empty())
{
- NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(onnickgroup, source, this, u->nick, target), owner, target->GetAccount()->GetDisplay(), pass);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
+ NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(source, this, u->nick, target), this->GetOwner(), target->GetAccount()->GetDisplay(), pass);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
req->Dispatch();
}
else
{
- NSGroupRequestListener req(onnickgroup, source, this, u->nick, target);
+ NSGroupRequestListener req(source, this, u->nick, target);
if (ok)
req.OnSuccess(nullptr);
@@ -238,7 +237,7 @@ class CommandNSUngroup : public Command
Anope::string nick = !params.empty() ? params[0] : "";
NickServ::Nick *na = NickServ::FindNick(!nick.empty() ? nick : u->nick);
- if (u->Account()->GetRefs<NickServ::Nick *>(NickServ::nick).size() == 1)
+ if (u->Account()->GetRefs<NickServ::Nick *>().size() == 1)
{
source.Reply(_("Your nickname is not grouped to anything, so you can't ungroup it."));
return;
@@ -260,9 +259,9 @@ class CommandNSUngroup : public Command
NickServ::Account *oldcore = na->GetAccount();
if (na->GetNick().equals_ci(oldcore->GetDisplay()))
- oldcore->SetDisplay(oldcore->GetRef<NickServ::Nick *>(NickServ::nick));
+ oldcore->SetDisplay(oldcore->GetRef<NickServ::Nick *>());
- NickServ::Account *nc = NickServ::account.Create();
+ NickServ::Account *nc = Serialize::New<NickServ::Account *>();
nc->SetDisplay(na->GetNick());
na->SetAccount(nc);
@@ -319,7 +318,7 @@ class CommandNSGList : public Command
list.AddColumn(_("Nick")).AddColumn(_("Expires"));
time_t nickserv_expire = Config->GetModule("nickserv")->Get<time_t>("expire", "21d"),
unconfirmed_expire = Config->GetModule("nickserv")->Get<time_t>("unconfirmedexpire", "1d");
- for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>())
{
Anope::string expires;
if (na2->HasFieldS("NS_NO_EXPIRE"))
@@ -368,14 +367,11 @@ class NSGroup : public Module
CommandNSUngroup commandnsungroup;
CommandNSGList commandnsglist;
- EventHandlers<Event::NickGroup> onnickgroup;
-
public:
NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandnsgroup(this, onnickgroup)
+ , commandnsgroup(this)
, commandnsungroup(this)
, commandnsglist(this)
- , onnickgroup(this)
{
if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership"))
throw ModuleException(modname + " can not be used with options:nonicknameownership enabled");
diff --git a/modules/nickserv/identify.cpp b/modules/nickserv/identify.cpp
index 122378d8a..a9b1f9284 100644
--- a/modules/nickserv/identify.cpp
+++ b/modules/nickserv/identify.cpp
@@ -89,15 +89,15 @@ class CommandNSIdentify : public Command
return;
}
- unsigned int maxlogins = Config->GetModule(this->owner)->Get<unsigned int>("maxlogins");
+ unsigned int maxlogins = Config->GetModule(this->GetOwner())->Get<unsigned int>("maxlogins");
if (na && maxlogins && na->GetAccount()->users.size() >= maxlogins)
{
source.Reply(_("Account \002{0}\002 has already reached the maximum number of simultaneous logins ({1})."), na->GetAccount()->GetDisplay(), maxlogins);
return;
}
- NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), owner, na ? na->GetAccount()->GetDisplay() : nick, pass);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req);
+ NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), this->GetOwner(), na ? na->GetAccount()->GetDisplay() : nick, pass);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, u, req);
req->Dispatch();
}
diff --git a/modules/nickserv/info.cpp b/modules/nickserv/info.cpp
index 0bc712ac9..02be72f2b 100644
--- a/modules/nickserv/info.cpp
+++ b/modules/nickserv/info.cpp
@@ -15,10 +15,8 @@
class CommandNSInfo : public Command
{
- EventHandlers<Event::NickInfo> &onnickinfo;
-
public:
- CommandNSInfo(Module *creator, EventHandlers<Event::NickInfo> &event) : Command(creator, "nickserv/info", 0, 2), onnickinfo(event)
+ CommandNSInfo(Module *creator) : Command(creator, "nickserv/info", 0, 2)
{
this->SetDesc(_("Displays information about a given nickname"));
this->SetSyntax(_("[\037nickname\037]"));
@@ -60,7 +58,7 @@ class CommandNSInfo : public Command
source.Reply(_("\002{0}\002 has not confirmed their account."), na->GetNick());
if (na->GetAccount()->IsServicesOper() && (show_hidden || !na->GetAccount()->HasFieldS("HIDE_STATUS")))
- source.Reply(_("\002{0}\002 is a Services Operator of type \002{0}\002."), na->GetNick(), na->GetAccount()->o->GetType()->GetName());
+ source.Reply(_("\002{0}\002 is a Services Operator of type \002{1}\002."), na->GetNick(), na->GetAccount()->o->GetType()->GetName());
InfoFormatter info(source.nc);
@@ -112,7 +110,7 @@ class CommandNSInfo : public Command
}
}
- this->onnickinfo(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden);
+ EventManager::Get()->Dispatch(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden);
std::vector<Anope::string> replies;
info.Process(replies);
@@ -161,7 +159,7 @@ class CommandNSSetHide : public Command
}
NickServ::Account *nc = na->GetAccount();
- EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -259,20 +257,17 @@ class NSInfo : public Module
CommandNSSetHide commandnssethide;
CommandNSSASetHide commandnssasethide;
- EventHandlers<Event::NickInfo> onnickinfo;
-
Serialize::Field<NickServ::Account, bool> hide_email, hide_usermask, hide_status, hide_quit;
public:
NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandnsinfo(this, onnickinfo)
+ , commandnsinfo(this)
, commandnssethide(this)
, commandnssasethide(this)
- , onnickinfo(this)
- , hide_email(this, NickServ::account, "HIDE_EMAIL")
- , hide_usermask(this, NickServ::account, "HIDE_MASK")
- , hide_status(this, NickServ::account, "HIDE_STATUS")
- , hide_quit(this, NickServ::account, "HIDE_QUIT")
+ , hide_email(this, "HIDE_EMAIL")
+ , hide_usermask(this, "HIDE_MASK")
+ , hide_status(this, "HIDE_STATUS")
+ , hide_quit(this, "HIDE_QUIT")
{
}
diff --git a/modules/nickserv/list.cpp b/modules/nickserv/list.cpp
index 53a3a9394..c6758d583 100644
--- a/modules/nickserv/list.cpp
+++ b/modules/nickserv/list.cpp
@@ -31,7 +31,7 @@ class CommandNSList : public Command
bool is_servadmin = source.HasCommand("nickserv/list");
int count = 0, from = 0, to = 0;
bool suspended, nsnoexpire, unconfirmed;
- unsigned listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50");
+ unsigned listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50");
suspended = nsnoexpire = unconfirmed = false;
@@ -200,7 +200,7 @@ class CommandNSSetPrivate : public Command
}
NickServ::Account *nc = na->GetAccount();
- EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -270,10 +270,11 @@ class NSList : public Module
public:
NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::NickInfo>(this)
, commandnslist(this)
, commandnssetprivate(this)
, commandnssasetprivate(this)
- , priv(this, NickServ::account, "NS_PRIVATE")
+ , priv(this, "NS_PRIVATE")
{
}
diff --git a/modules/nickserv/logout.cpp b/modules/nickserv/logout.cpp
index 9bcb543fc..2afc65124 100644
--- a/modules/nickserv/logout.cpp
+++ b/modules/nickserv/logout.cpp
@@ -46,6 +46,7 @@ class CommandNSLogout : public Command
return;
}
+#warning "revalidate"
#if 0
if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServ::service)
NickServ::service->Validate(u2);
@@ -64,7 +65,7 @@ class CommandNSLogout : public Command
u2->Logout();
/* Send out an event */
- Event::OnNickLogout(&Event::NickLogout::OnNickLogout, u2);
+ EventManager::Get()->Dispatch(&Event::NickLogout::OnNickLogout, u2);
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
diff --git a/modules/nickserv/main/account.cpp b/modules/nickserv/main/account.cpp
index d74154d97..bfde7f15b 100644
--- a/modules/nickserv/main/account.cpp
+++ b/modules/nickserv/main/account.cpp
@@ -22,7 +22,7 @@ AccountImpl::~AccountImpl()
void AccountImpl::Delete()
{
- Event::OnDelCore(&Event::DelCore::OnDelCore, this);
+ EventManager::Get()->Dispatch(&Event::DelCore::OnDelCore, this);
for (unsigned i = users.size(); i > 0; --i)
users[i - 1]->Logout();
@@ -72,7 +72,7 @@ void AccountImpl::SetLanguage(const Anope::string &lang)
MemoServ::MemoInfo *AccountImpl::GetMemos()
{
- return GetRef<MemoServ::MemoInfo *>(MemoServ::memoinfo);
+ return GetRef<MemoServ::MemoInfo *>();
}
void AccountImpl::SetDisplay(NickServ::Nick *na)
@@ -80,7 +80,7 @@ void AccountImpl::SetDisplay(NickServ::Nick *na)
if (na->GetAccount() != this || na->GetNick() == this->GetDisplay())
return;
- Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->GetNick());
+ EventManager::Get()->Dispatch(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->GetNick());
NickServ::nickcore_map& map = NickServ::service->GetAccountMap();
@@ -109,7 +109,7 @@ bool AccountImpl::IsOnAccess(User *u)
if (!u->GetCloakedHost().empty())
buf3 = u->GetIdent() + "@" + u->GetCloakedHost();
- for (NickAccess *access : GetRefs<NickAccess *>(nsaccess))
+ for (NickAccess *access : GetRefs<NickAccess *>())
{
Anope::string a = access->GetMask();
if (Anope::Match(buf, a) || (!buf2.empty() && Anope::Match(buf2, a)) || (!buf3.empty() && Anope::Match(buf3, a)))
@@ -121,7 +121,7 @@ bool AccountImpl::IsOnAccess(User *u)
unsigned int AccountImpl::GetChannelCount()
{
unsigned int i = 0;
- for (ChanServ::Channel *c : GetRefs<ChanServ::Channel *>(ChanServ::channel))
+ for (ChanServ::Channel *c : GetRefs<ChanServ::Channel *>())
if (c->GetFounder() == this)
++i;
return i;
diff --git a/modules/nickserv/main/account.h b/modules/nickserv/main/account.h
index 584548563..69edce0db 100644
--- a/modules/nickserv/main/account.h
+++ b/modules/nickserv/main/account.h
@@ -2,6 +2,10 @@
class AccountImpl : public NickServ::Account
{
+ friend class AccountType;
+
+ Anope::string display, password, email, language;
+
public:
AccountImpl(Serialize::TypeBase *type) : NickServ::Account(type) { }
AccountImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Account(type, id) { }
diff --git a/modules/nickserv/main/accounttype.cpp b/modules/nickserv/main/accounttype.cpp
index 3dad436b4..4f2c59d80 100644
--- a/modules/nickserv/main/accounttype.cpp
+++ b/modules/nickserv/main/accounttype.cpp
@@ -1,12 +1,11 @@
#include "module.h"
#include "accounttype.h"
-//#include "account.h"
-AccountType::AccountType(Module *me) : Serialize::Type<AccountImpl>(me, "NickCore")
- , display(this, "display")
- , pass(this, "pass")
- , email(this, "email")
- , language(this, "language")
+AccountType::AccountType(Module *me) : Serialize::Type<AccountImpl>(me)
+ , display(this, "display", &AccountImpl::display)
+ , pass(this, "pass", &AccountImpl::password)
+ , email(this, "email", &AccountImpl::email)
+ , language(this, "language", &AccountImpl::language)
{
}
@@ -29,7 +28,7 @@ void AccountType::Display::SetField(AccountImpl *acc, const Anope::string &disp)
NickServ::Account *AccountType::FindAccount(const Anope::string &acc)
{
Serialize::ID id;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->display, acc, id);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->display, acc, id);
if (result == EVENT_ALLOW)
return RequireID(id);
diff --git a/modules/nickserv/main/identifyrequest.cpp b/modules/nickserv/main/identifyrequest.cpp
index 4fc2f9989..3d014965b 100644
--- a/modules/nickserv/main/identifyrequest.cpp
+++ b/modules/nickserv/main/identifyrequest.cpp
@@ -49,3 +49,14 @@ void IdentifyRequestImpl::Dispatch()
else
dispatched = true;
}
+
+void IdentifyRequestImpl::Unload(Module *m)
+{
+ if (this->GetOwner() != m)
+ return;
+
+ if (!success)
+ l->OnFail(this);
+ delete this;
+}
+
diff --git a/modules/nickserv/main/identifyrequest.h b/modules/nickserv/main/identifyrequest.h
index e74d3129e..03857da96 100644
--- a/modules/nickserv/main/identifyrequest.h
+++ b/modules/nickserv/main/identifyrequest.h
@@ -10,4 +10,5 @@ class IdentifyRequestImpl : public NickServ::IdentifyRequest
void Release(Module *m) override;
void Success(Module *m) override;
void Dispatch() override;
+ void Unload(Module *);
};
diff --git a/modules/nickserv/main/mode.h b/modules/nickserv/main/mode.h
index 9fc4c331e..df72e1823 100644
--- a/modules/nickserv/main/mode.h
+++ b/modules/nickserv/main/mode.h
@@ -1,6 +1,11 @@
class ModeImpl : public NickServ::Mode
{
+ friend class NSModeType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string mode;
+
public:
ModeImpl(Serialize::TypeBase *type) : NickServ::Mode(type) { }
ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Mode(type, id) { }
diff --git a/modules/nickserv/main/modetype.h b/modules/nickserv/main/modetype.h
index 0c4aefecc..5796614d4 100644
--- a/modules/nickserv/main/modetype.h
+++ b/modules/nickserv/main/modetype.h
@@ -6,9 +6,9 @@ class NSModeType : public Serialize::Type<ModeImpl>
Serialize::ObjectField<ModeImpl, NickServ::Account *> account;
Serialize::Field<ModeImpl, Anope::string> mode;
- NSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator, "NSKeepMode")
- , account(this, "account", true)
- , mode(this, "mode")
+ NSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator)
+ , account(this, "account", &ModeImpl::account, true)
+ , mode(this, "mode", &ModeImpl::mode)
{
}
};
diff --git a/modules/nickserv/main/nick.cpp b/modules/nickserv/main/nick.cpp
index 0ac55ff93..95cef63da 100644
--- a/modules/nickserv/main/nick.cpp
+++ b/modules/nickserv/main/nick.cpp
@@ -1,12 +1,10 @@
/*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
*
*/
@@ -22,12 +20,12 @@ NickImpl::~NickImpl()
void NickImpl::Delete()
{
- Event::OnDelNick(&Event::DelNick::OnDelNick, this);
+ EventManager::Get()->Dispatch(&Event::DelNick::OnDelNick, this);
if (this->GetAccount())
{
/* Next: see if our core is still useful. */
- std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick);
+ std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>();
auto it = std::find(aliases.begin(), aliases.end(), this);
if (it != aliases.end())
diff --git a/modules/nickserv/main/nick.h b/modules/nickserv/main/nick.h
index 043d7c052..fa8e7bcc5 100644
--- a/modules/nickserv/main/nick.h
+++ b/modules/nickserv/main/nick.h
@@ -1,6 +1,14 @@
class NickImpl : public NickServ::Nick
{
+ friend class NickType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string nick, last_quit, last_realname, last_usermask, last_realhost;
+ time_t time_registered = 0, last_seen = 0;
+ Anope::string vhost_ident, vhost_host, vhost_creator;
+ time_t vhost_created = 0;
+
public:
NickImpl(Serialize::TypeBase *type) : NickServ::Nick(type) { }
NickImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Nick(type, id) { }
diff --git a/modules/nickserv/main/nickserv.cpp b/modules/nickserv/main/nickserv.cpp
index 85ac34b12..434e4324c 100644
--- a/modules/nickserv/main/nickserv.cpp
+++ b/modules/nickserv/main/nickserv.cpp
@@ -138,16 +138,12 @@ class NickServCore : public Module, public NickServ::NickServService
, public EventHook<Event::ExpireTick>
, public EventHook<Event::NickInfo>
, public EventHook<Event::ModuleUnload>
- , public EventHook<Event::NickCoreCreate>
+ , public EventHook<NickServ::Event::NickRegister>
, public EventHook<Event::UserQuit>
{
Reference<ServiceBot> NickServ;
std::vector<Anope::string> defaults;
ExtensibleItem<bool> held, collided;
- EventHandlers<NickServ::Event::PreNickExpire> onprenickexpire;
- EventHandlers<NickServ::Event::NickExpire> onnickexpire;
- EventHandlers<NickServ::Event::NickRegister> onnickregister;
- EventHandlers<NickServ::Event::NickValidate> onnickvalidate;
std::set<NickServ::IdentifyRequest *> identifyrequests;
NickServ::nickalias_map NickList;
NickServ::nickcore_map AccountList;
@@ -173,21 +169,41 @@ class NickServCore : public Module, public NickServ::NickServService
public:
NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
, NickServ::NickServService(this)
+
+ , EventHook<Event::Shutdown>(this)
+ , EventHook<Event::Restart>(this)
+ , EventHook<Event::UserLogin>(this)
+ , EventHook<Event::DelNick>(this)
+ , EventHook<Event::DelCore>(this)
+ , EventHook<Event::ChangeCoreDisplay>(this)
+ , EventHook<Event::NickIdentify>(this)
+ , EventHook<Event::NickGroup>(this)
+ , EventHook<Event::NickUpdate>(this)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::PostUserLogoff>(this)
+ , EventHook<Event::ServerSync>(this)
+ , EventHook<Event::UserNickChange>(this)
+ , EventHook<Event::UserModeSet>(this)
+ , EventHook<Event::Help>(this)
+ , EventHook<Event::ExpireTick>(this)
+ , EventHook<Event::NickInfo>(this)
+ , EventHook<Event::ModuleUnload>(this)
+ , EventHook<NickServ::Event::NickRegister>(this)
+ , EventHook<Event::UserQuit>(this)
+
, held(this, "HELD")
, collided(this, "COLLIDED")
- , onprenickexpire(this)
- , onnickexpire(this)
- , onnickregister(this)
- , onnickvalidate(this)
, nick_type(this)
, account_type(this)
, mode_type(this)
{
+ NickServ::service = this;
}
~NickServCore()
{
OnShutdown();
+ NickServ::service = nullptr;
}
void OnShutdown() override
@@ -210,7 +226,7 @@ class NickServCore : public Module, public NickServ::NickServService
if (!na)
return;
- EventReturn MOD_RESULT = this->onnickvalidate(&NickServ::Event::NickValidate::OnNickValidate, u, na);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&NickServ::Event::NickValidate::OnNickValidate, u, na);
if (MOD_RESULT == EVENT_STOP)
{
this->Collide(u, na);
@@ -412,7 +428,7 @@ class NickServCore : public Module, public NickServ::NickServService
IRCD->SendLogout(user);
user->RemoveMode(NickServ, "REGISTERED");
user->Logout();
- Event::OnNickLogout(&Event::NickLogout::OnNickLogout, user);
+ EventManager::Get()->Dispatch(&Event::NickLogout::OnNickLogout, user);
}
}
@@ -588,11 +604,11 @@ class NickServCore : public Module, public NickServ::NickServService
"nickname(s)."), NickServ->nick.c_str());
}
- void OnNickCoreCreate(NickServ::Account *nc) override
+ void OnNickRegister(User *, NickServ::Nick *na, const Anope::string &) override
{
/* Set default flags */
for (unsigned i = 0; i < defaults.size(); ++i)
- nc->SetS<bool>(defaults[i].upper(), true);
+ na->GetAccount()->SetS<bool>(defaults[i].upper(), true);
}
void OnUserQuit(User *u, const Anope::string &msg) override
@@ -627,12 +643,12 @@ class NickServCore : public Module, public NickServ::NickServService
if (nickserv_expire && Anope::CurTime - na->GetLastSeen() >= nickserv_expire)
expire = true;
- this->onprenickexpire(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire);
+ EventManager::Get()->Dispatch(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire);
if (expire)
{
Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->GetNick() << " (group: " << na->GetAccount()->GetDisplay() << ") (e-mail: " << (na->GetAccount()->GetEmail().empty() ? "none" : na->GetAccount()->GetEmail()) << ")";
- this->onnickexpire(&NickServ::Event::NickExpire::OnNickExpire, na);
+ EventManager::Get()->Dispatch(&NickServ::Event::NickExpire::OnNickExpire, na);
delete na;
}
}
@@ -657,27 +673,10 @@ class NickServCore : public Module, public NickServ::NickServService
{
for (std::set<NickServ::IdentifyRequest *>::iterator it = identifyrequests.begin(), it_end = identifyrequests.end(); it != it_end;)
{
- NickServ::IdentifyRequest *ir = *it;
+ IdentifyRequestImpl *ir = anope_dynamic_static_cast<IdentifyRequestImpl *>(*it);
++it;
- ir->Release(m);
-#if 0
- ir->holds.erase(m);
- if (ir->holds.empty() && ir->dispatched)
- {
- if (!ir->success)
- ir->OnFail();
- delete ir;
- continue;
- }
-
- if (ir->GetOwner() == m)
- {
- if (!ir->success)
- ir->OnFail();
- delete ir;
- }
-#endif
+ ir->Unload(m);
}
}
};
diff --git a/modules/nickserv/main/nicktype.cpp b/modules/nickserv/main/nicktype.cpp
index 9607aaa2f..7d9b34ac1 100644
--- a/modules/nickserv/main/nicktype.cpp
+++ b/modules/nickserv/main/nicktype.cpp
@@ -1,19 +1,19 @@
#include "module.h"
#include "nicktype.h"
-NickType::NickType(Module *me) : Serialize::Type<NickImpl>(me, "NickAlias")
- , nick(this, "nick")
- , last_quit(this, "last_quit")
- , last_realname(this, "last_realname")
- , last_usermask(this, "last_usermask")
- , last_realhost(this, "last_realhost")
- , time_registered(this, "time_registered")
- , last_seen(this, "last_seen")
- , vhost_ident(this, "vhost_ident")
- , vhost_host(this, "vhost_host")
- , vhost_creator(this, "vhost_creator")
- , vhost_created(this, "vhost_created")
- , nc(this, "nc")
+NickType::NickType(Module *me) : Serialize::Type<NickImpl>(me)
+ , nick(this, "nick", &NickImpl::nick)
+ , last_quit(this, "last_quit", &NickImpl::last_quit)
+ , last_realname(this, "last_realname", &NickImpl::last_realname)
+ , last_usermask(this, "last_usermask", &NickImpl::last_usermask)
+ , last_realhost(this, "last_realhost", &NickImpl::last_realhost)
+ , time_registered(this, "time_registered", &NickImpl::time_registered)
+ , last_seen(this, "last_seen", &NickImpl::last_seen)
+ , vhost_ident(this, "vhost_ident", &NickImpl::vhost_ident)
+ , vhost_host(this, "vhost_host", &NickImpl::vhost_host)
+ , vhost_creator(this, "vhost_creator", &NickImpl::vhost_creator)
+ , vhost_created(this, "vhost_created", &NickImpl::vhost_created)
+ , nc(this, "nc", &NickImpl::account)
{
}
@@ -32,7 +32,7 @@ void NickType::Nick::SetField(NickImpl *na, const Anope::string &value)
NickServ::Nick *NickType::FindNick(const Anope::string &n)
{
Serialize::ID id;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->nick, n, id);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->nick, n, id);
if (result == EVENT_ALLOW)
return RequireID(id);
diff --git a/modules/nickserv/maxemail.cpp b/modules/nickserv/maxemail.cpp
index 38054f819..34f83741d 100644
--- a/modules/nickserv/maxemail.cpp
+++ b/modules/nickserv/maxemail.cpp
@@ -49,6 +49,7 @@ class NSMaxEmail : public Module
public:
NSMaxEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::PreCommand>(this)
{
}
@@ -57,17 +58,17 @@ class NSMaxEmail : public Module
if (source.IsOper())
return EVENT_CONTINUE;
- if (command->name == "nickserv/register")
+ if (command->GetName() == "nickserv/register")
{
if (this->CheckLimitReached(source, params.size() > 1 ? params[1] : ""))
return EVENT_STOP;
}
- else if (command->name == "nickserv/set/email")
+ else if (command->GetName() == "nickserv/set/email")
{
if (this->CheckLimitReached(source, params.size() > 0 ? params[0] : ""))
return EVENT_STOP;
}
- else if (command->name == "nickserv/ungroup" && source.GetAccount())
+ else if (command->GetName() == "nickserv/ungroup" && source.GetAccount())
{
if (this->CheckLimitReached(source, source.GetAccount()->GetEmail()))
return EVENT_STOP;
diff --git a/modules/nickserv/recover.cpp b/modules/nickserv/recover.cpp
index c95d3f135..9a6ddd64e 100644
--- a/modules/nickserv/recover.cpp
+++ b/modules/nickserv/recover.cpp
@@ -124,6 +124,8 @@ class NSRecoverRequestListener : public NickServ::IdentifyRequestListener
class CommandNSRecover : public Command
{
+ ServiceReference<CertService> certservice;
+
public:
CommandNSRecover(Module *creator) : Command(creator, "nickserv/recover", 1, 2)
{
@@ -170,8 +172,8 @@ class CommandNSRecover : public Command
if (ok == false && !pass.empty())
{
- NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), owner, na->GetNick(), pass);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
+ NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), GetOwner(), na->GetNick(), pass);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
req->Dispatch();
}
else
@@ -204,6 +206,8 @@ class NSRecover : public Module
public:
NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserNickChange>(this)
+ , EventHook<Event::JoinChannel>(this)
, commandnsrecover(this)
, recover(this, "recover")
{
diff --git a/modules/nickserv/register.cpp b/modules/nickserv/register.cpp
index c7e6e5af2..e8255ca1a 100644
--- a/modules/nickserv/register.cpp
+++ b/modules/nickserv/register.cpp
@@ -44,8 +44,7 @@ class CommandNSConfirm : public Command
}
na->GetAccount()->UnsetS<bool>("UNCONFIRMED");
- if (NickServ::Event::OnNickConfirm)
- NickServ::Event::OnNickConfirm(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), na->GetAccount());
+ EventManager::Get()->Dispatch(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), na->GetAccount());
Log(LOG_ADMIN, source, this) << "to confirm nick " << na->GetNick() << " (" << na->GetAccount()->GetDisplay() << ")";
source.Reply(_("\002{0}\002 has been confirmed."), na->GetNick());
}
@@ -59,12 +58,12 @@ class CommandNSConfirm : public Command
}
NickServ::Account *nc = source.nc;
- nc->ShrinkOK<Anope::string>("passcode");
+ nc->Shrink<Anope::string>("passcode");
Log(LOG_COMMAND, source, this) << "to confirm their email";
source.Reply(_("Your email address of \002{0}\002 has been confirmed."), source.nc->GetEmail());
nc->UnsetS<bool>("UNCONFIRMED");
- if (NickServ::Event::OnNickConfirm)
- NickServ::Event::OnNickConfirm(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), nc);
+
+ EventManager::Get()->Dispatch(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), nc);
if (source.GetUser())
{
@@ -115,7 +114,7 @@ class CommandNSRegister : public Command
size_t nicklen = u_nick.length();
Anope::string pass = params[0];
Anope::string email = params.size() > 1 ? params[1] : "";
- const Anope::string &nsregister = Config->GetModule(this->owner)->Get<Anope::string>("registration");
+ const Anope::string &nsregister = Config->GetModule(this->GetOwner())->Get<Anope::string>("registration");
if (Anope::ReadOnly)
{
@@ -129,7 +128,7 @@ class CommandNSRegister : public Command
return;
}
- time_t nickregdelay = Config->GetModule(this->owner)->Get<time_t>("nickregdelay");
+ time_t nickregdelay = Config->GetModule(this->GetOwner())->Get<time_t>("nickregdelay");
time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay");
if (u && !u->HasMode("OPER") && nickregdelay && Anope::CurTime - u->timestamp < nickregdelay)
{
@@ -162,11 +161,11 @@ class CommandNSRegister : public Command
}
if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks"))
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
{
if (!source.IsOper() && u_nick.find_ci(o->GetName()) != Anope::string::npos)
{
- source.Reply(_("\002{0}\002 may not be registered."), u_nick);
+ source.Reply(_("\002{0}\002 may not be registered because it is too similar to an operator nick."), u_nick);
return;
}
}
@@ -210,12 +209,15 @@ class CommandNSRegister : public Command
return;
}
- NickServ::Account *nc = NickServ::account.Create();
+ NickServ::Account *nc = Serialize::New<NickServ::Account *>();
nc->SetDisplay(u_nick);
- NickServ::Nick *na = NickServ::nick.Create();
+ NickServ::Nick *na = Serialize::New<NickServ::Nick *>();
na->SetNick(u_nick);
na->SetAccount(nc);
+ na->SetTimeRegistered(Anope::CurTime);
+ na->SetLastSeen(Anope::CurTime);
+
Anope::string epass;
Anope::Encrypt(pass, epass);
nc->SetPassword(epass);
@@ -252,8 +254,7 @@ class CommandNSRegister : public Command
}
}
- if (NickServ::Event::OnNickRegister)
- NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na, pass);
+ EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na, pass);
if (u)
{
@@ -296,7 +297,7 @@ class CommandNSResend : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
- if (!Config->GetModule(this->owner)->Get<Anope::string>("registration").equals_ci("mail"))
+ if (!Config->GetModule(this->GetOwner())->Get<Anope::string>("registration").equals_ci("mail"))
{
source.Reply(_("Access denied."));
return;
@@ -316,7 +317,7 @@ class CommandNSResend : public Command
return;
}
- if (Anope::CurTime < source.nc->lastmail + Config->GetModule(this->owner)->Get<time_t>("resenddelay"))
+ if (Anope::CurTime < source.nc->lastmail + Config->GetModule(this->GetOwner())->Get<time_t>("resenddelay"))
{
source.Reply(_("Cannot send mail now; please retry a little later."));
return;
@@ -324,7 +325,7 @@ class CommandNSResend : public Command
if (!SendRegmail(source.GetUser(), na, source.service))
{
- Log(this->owner) << "Unable to resend registration verification code for " << source.GetNick();
+ Log(this->GetOwner()) << "Unable to resend registration verification code for " << source.GetNick();
return;
}
@@ -335,7 +336,7 @@ class CommandNSResend : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
- if (!Config->GetModule(this->owner)->Get<Anope::string>("registration").equals_ci("mail"))
+ if (!Config->GetModule(this->GetOwner())->Get<Anope::string>("registration").equals_ci("mail"))
return false;
source.Reply(_("This command will resend you the registration confirmation email."));
@@ -344,7 +345,7 @@ class CommandNSResend : public Command
void OnServHelp(CommandSource &source) override
{
- if (Config->GetModule(this->owner)->Get<Anope::string>("registration").equals_ci("mail"))
+ if (Config->GetModule(this->GetOwner())->Get<Anope::string>("registration").equals_ci("mail"))
Command::OnServHelp(source);
}
};
@@ -362,14 +363,16 @@ class NSRegister : public Module
public:
NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::NickIdentify>(this)
+ , EventHook<NickServ::Event::PreNickExpire>(this)
, commandnsregister(this)
, commandnsconfirm(this)
, commandnsrsend(this)
- , unconfirmed(this, NickServ::account, "UNCONFIRMED")
- , passcode(this, NickServ::account, "passcode")
+ , unconfirmed(this, "UNCONFIRMED")
+ , passcode(this, "passcode")
{
if (Config->GetModule(this)->Get<Anope::string>("registration").equals_ci("disable"))
- throw ModuleException("Module " + this->name + " will not load with registration disabled.");
+ throw ModuleException("Module " + Module::name + " will not load with registration disabled.");
}
void OnNickIdentify(User *u) override
diff --git a/modules/nickserv/resetpass.cpp b/modules/nickserv/resetpass.cpp
index 3be5a4c06..4f8fa5136 100644
--- a/modules/nickserv/resetpass.cpp
+++ b/modules/nickserv/resetpass.cpp
@@ -67,6 +67,7 @@ class NSResetPass : public Module
public:
NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::PreCommand>(this)
, commandnsresetpass(this), reset(this, "reset")
{
if (!Config->GetBlock("mail")->Get<bool>("usemail"))
@@ -75,7 +76,7 @@ class NSResetPass : public Module
EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
- if (command->name == "nickserv/confirm" && params.size() > 1)
+ if (command->GetName() == "nickserv/confirm" && params.size() > 1)
{
if (Anope::ReadOnly)
{
diff --git a/modules/nickserv/set.cpp b/modules/nickserv/set.cpp
index 337bdab9d..93d2dcc57 100644
--- a/modules/nickserv/set.cpp
+++ b/modules/nickserv/set.cpp
@@ -1,12 +1,10 @@
/* NickServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
*/
#include "module.h"
@@ -44,7 +42,7 @@ class CommandNSSet : public Command
if (c_name.find_ci(this_name + " ") == 0)
{
- ServiceReference<Command> c("Command", info.name);
+ ServiceReference<Command> c(info.name);
// XXX dup
if (!c)
continue;
@@ -96,7 +94,7 @@ class CommandNSSASet : public Command
if (c_name.find_ci(this_name + " ") == 0)
{
- ServiceReference<Command> command("Command", info.name);
+ ServiceReference<Command> command(info.name);
if (command)
{
source.command = c_name;
@@ -254,7 +252,7 @@ class CommandNSSetAutoOp : public Command
NickServ::Account *nc = na->GetAccount();
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -347,7 +345,7 @@ class CommandNSSetDisplay : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, user_na->GetAccount(), param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, user_na->GetAccount(), param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -468,7 +466,7 @@ class CommandNSSetEmail : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -550,7 +548,7 @@ class CommandNSSetKeepModes : public Command
NickServ::Account *nc = na->GetAccount();
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -635,7 +633,7 @@ class CommandNSSetKill : public Command
NickServ::Account *nc = na->GetAccount();
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -657,7 +655,7 @@ class CommandNSSetKill : public Command
}
else if (param.equals_ci("IMMED"))
{
- if (Config->GetModule(this->owner)->Get<bool>("allowkillimmed"))
+ if (Config->GetModule(this->GetOwner())->Get<bool>("allowkillimmed"))
{
nc->SetS<bool>("KILLPROTECT",true);
nc->UnsetS<bool>("KILL_QUICK");
@@ -749,7 +747,7 @@ class CommandNSSetLanguage : public Command
NickServ::Account *nc = na->GetAccount();
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -854,7 +852,7 @@ class CommandNSSetMessage : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -949,7 +947,7 @@ class CommandNSSetSecure : public Command
NickServ::Account *nc = na->GetAccount();
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -1105,10 +1103,16 @@ class NSSet : public Module
/* email, passcode */
ExtensibleItem<std::pair<Anope::string, Anope::string > > ns_set_email;
- EventHandlers<Event::SetNickOption> onsetnickoption;
-
public:
NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::PreCommand>(this)
+ , EventHook<Event::SetCorrectModes>(this)
+ , EventHook<NickServ::Event::PreNickExpire>(this)
+ , EventHook<Event::NickInfo>(this)
+ , EventHook<Event::UserModeSet>(this)
+ , EventHook<Event::UserModeUnset>(this)
+ , EventHook<Event::UserLogin>(this)
+
, commandnsset(this)
, commandnssaset(this)
, commandnssetautoop(this)
@@ -1131,18 +1135,16 @@ class NSSet : public Module
, commandnssasetsecure(this)
, commandnssasetnoexpire(this)
- , autoop(this, NickServ::account, "AUTOOP")
- , keep_modes(this, NickServ::account, "NS_KEEP_MODES")
- , killprotect(this, NickServ::account, "KILLPROTECT")
- , kill_quick(this, NickServ::account, "KILL_QUICK")
- , kill_immed(this, NickServ::account, "KILL_IMMED")
- , message(this, NickServ::account, "MSG")
- , secure(this, NickServ::account, "NS_SECURE")
- , noexpire(this, NickServ::nick, "NS_NO_EXPIRE")
+ , autoop(this, "AUTOOP")
+ , keep_modes(this, "NS_KEEP_MODES")
+ , killprotect(this, "KILLPROTECT")
+ , kill_quick(this, "KILL_QUICK")
+ , kill_immed(this, "KILL_IMMED")
+ , message(this, "MSG")
+ , secure(this, "NS_SECURE")
+ , noexpire(this, "NS_NO_EXPIRE")
, ns_set_email(this, "ns_set_email")
-
- , onsetnickoption(this)
{
}
@@ -1151,7 +1153,7 @@ class NSSet : public Module
{
NickServ::Account *uac = source.nc;
- if (command->name == "nickserv/confirm" && !params.empty() && uac)
+ if (command->GetName() == "nickserv/confirm" && !params.empty() && uac)
{
std::pair<Anope::string, Anope::string> *n = ns_set_email.Get(uac);
if (n)
@@ -1210,11 +1212,14 @@ class NSSet : public Module
void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
{
- if (u->Account() && setter.GetUser() == u && NickServ::mode)
+ if (u->Account() && setter.GetUser() == u)
{
- NickServ::Mode *m = NickServ::mode.Create();
- m->SetAccount(u->Account());
- m->SetMode(mname);
+ NickServ::Mode *m = Serialize::New<NickServ::Mode *>();
+ if (m != nullptr)
+ {
+ m->SetAccount(u->Account());
+ m->SetMode(mname);
+ }
}
}
@@ -1222,7 +1227,7 @@ class NSSet : public Module
{
if (u->Account() && setter.GetUser() == u)
{
- for (NickServ::Mode *m : u->Account()->GetRefs<NickServ::Mode *>(NickServ::mode))
+ for (NickServ::Mode *m : u->Account()->GetRefs<NickServ::Mode *>())
if (m->GetMode() == mname)
m->Delete();
}
@@ -1231,7 +1236,7 @@ class NSSet : public Module
void OnUserLogin(User *u) override
{
if (keep_modes.HasExt(u->Account()))
- for (NickServ::Mode *mode : u->Account()->GetRefs<NickServ::Mode *>(NickServ::mode))
+ for (NickServ::Mode *mode : u->Account()->GetRefs<NickServ::Mode *>())
{
UserMode *um = ModeManager::FindUserModeByName(mode->GetMode());
/* if the null user can set the mode, then it's probably safe */
diff --git a/modules/nickserv/set_misc.cpp b/modules/nickserv/set_misc.cpp
index 347ae034c..2c6ea317c 100644
--- a/modules/nickserv/set_misc.cpp
+++ b/modules/nickserv/set_misc.cpp
@@ -18,6 +18,11 @@ static Anope::map<Anope::string> descriptions;
class NSMiscDataImpl : public NSMiscData
{
+ friend class NSMiscDataType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string name, data;
+
public:
NSMiscDataImpl(Serialize::TypeBase *type) : NSMiscData(type) { }
NSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : NSMiscData(type, id) { }
@@ -38,10 +43,10 @@ class NSMiscDataType : public Serialize::Type<NSMiscDataImpl>
Serialize::ObjectField<NSMiscDataImpl, NickServ::Account *> owner;
Serialize::Field<NSMiscDataImpl, Anope::string> name, data;
- NSMiscDataType(Module *me) : Serialize::Type<NSMiscDataImpl>(me, "NSMiscData")
- , owner(this, "nc", true)
- , name(this, "name")
- , data(this, "data")
+ NSMiscDataType(Module *me) : Serialize::Type<NSMiscDataImpl>(me)
+ , owner(this, "nc", &NSMiscDataImpl::account, true)
+ , name(this, "name", &NSMiscDataImpl::name)
+ , data(this, "data", &NSMiscDataImpl::data)
{
}
};
@@ -108,14 +113,14 @@ class CommandNSSetMisc : public Command
}
NickServ::Account *nc = na->GetAccount();
- EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param);
if (MOD_RESULT == EVENT_STOP)
return;
Anope::string scommand = GetAttribute(source.command);
/* remove existing */
- for (NSMiscData *data : nc->GetRefs<NSMiscData *>(nsmiscdata))
+ for (NSMiscData *data : nc->GetRefs<NSMiscData *>())
if (data->GetName() == scommand)
{
data->Delete();
@@ -124,7 +129,7 @@ class CommandNSSetMisc : public Command
if (!param.empty())
{
- NSMiscData *data = nsmiscdata.Create();
+ NSMiscData *data = Serialize::New<NSMiscData *>();
data->SetAccount(nc);
data->SetName(scommand);
data->SetData(param);
@@ -186,6 +191,7 @@ class NSSetMisc : public Module
public:
NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::NickInfo>(this)
, commandnssetmisc(this)
, commandnssasetmisc(this)
, type(this)
@@ -217,7 +223,7 @@ class NSSetMisc : public Module
void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool) override
{
- for (NSMiscData *data : na->GetAccount()->GetRefs<NSMiscData *>(nsmiscdata))
+ for (NSMiscData *data : na->GetAccount()->GetRefs<NSMiscData *>())
info[data->GetName()] = data->GetData();
}
};
diff --git a/modules/nickserv/suspend.cpp b/modules/nickserv/suspend.cpp
index b56e68f97..c33556e76 100644
--- a/modules/nickserv/suspend.cpp
+++ b/modules/nickserv/suspend.cpp
@@ -16,6 +16,12 @@
class NSSuspendInfoImpl : public NSSuspendInfo
{
+ friend class NSSuspendType;
+
+ NickServ::Account *account = nullptr;
+ Anope::string by, reason;
+ time_t when = 0, expires =0;
+
public:
NSSuspendInfoImpl(Serialize::TypeBase *type) : NSSuspendInfo(type) { }
NSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : NSSuspendInfo(type, id) { }
@@ -43,12 +49,12 @@ class NSSuspendType : public Serialize::Type<NSSuspendInfoImpl>
Serialize::Field<NSSuspendInfoImpl, Anope::string> by, reason;
Serialize::Field<NSSuspendInfoImpl, time_t> when, expires;
- NSSuspendType(Module *me) : Serialize::Type<NSSuspendInfoImpl>(me, "NSSuspendInfo")
- , account(this, "nick", true)
- , by(this, "by")
- , reason(this, "reason")
- , when(this, "time")
- , expires(this, "expires")
+ NSSuspendType(Module *me) : Serialize::Type<NSSuspendInfoImpl>(me)
+ , account(this, "nick", &NSSuspendInfoImpl::account, true)
+ , by(this, "by", &NSSuspendInfoImpl::by)
+ , reason(this, "reason", &NSSuspendInfoImpl::reason)
+ , when(this, "when", &NSSuspendInfoImpl::when)
+ , expires(this, "expires", &NSSuspendInfoImpl::expires)
{
}
};
@@ -105,10 +111,8 @@ void NSSuspendInfoImpl::SetExpires(const time_t &e)
class CommandNSSuspend : public Command
{
- EventHandlers<Event::NickSuspend> &onnicksuspend;
-
public:
- CommandNSSuspend(Module *creator, EventHandlers<Event::NickSuspend> &event) : Command(creator, "nickserv/suspend", 2, 3), onnicksuspend(event)
+ CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3)
{
this->SetDesc(_("Suspend a given nick"));
this->SetSyntax(_("\037account\037 [+\037expiry\037] [\037reason\037]"));
@@ -120,7 +124,7 @@ class CommandNSSuspend : public Command
const Anope::string &nick = params[0];
Anope::string expiry = params[1];
Anope::string reason = params.size() > 2 ? params[2] : "";
- time_t expiry_secs = Config->GetModule(this->owner)->Get<time_t>("suspendexpire");
+ time_t expiry_secs = Config->GetModule(this->GetOwner())->Get<time_t>("suspendexpire");
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
@@ -154,7 +158,7 @@ class CommandNSSuspend : public Command
return;
}
- NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo);
+ NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>();
if (!si)
{
source.Reply(_("\002%s\002 is already suspended."), na->GetAccount()->GetDisplay().c_str());
@@ -163,14 +167,14 @@ class CommandNSSuspend : public Command
NickServ::Account *nc = na->GetAccount();
- si = nssuspendinfo.Create();
+ si = Serialize::New<NSSuspendInfo *>();
si->SetAccount(nc);
si->SetBy(source.GetNick());
si->SetReason(reason);
si->SetWhen(Anope::CurTime);
si->SetExpires(expiry_secs ? expiry_secs + Anope::CurTime : 0);
- for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>())
{
na2->SetLastQuit(reason);
@@ -186,7 +190,7 @@ class CommandNSSuspend : public Command
Log(LOG_ADMIN, source, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never");
source.Reply(_("\002{0}\002 is now suspended."), na->GetNick());
- this->onnicksuspend(&Event::NickSuspend::OnNickSuspend, na);
+ EventManager::Get()->Dispatch(&Event::NickSuspend::OnNickSuspend, na);
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
@@ -199,10 +203,8 @@ class CommandNSSuspend : public Command
class CommandNSUnSuspend : public Command
{
- EventHandlers<Event::NickUnsuspend> &onnickunsuspend;
-
public:
- CommandNSUnSuspend(Module *creator, EventHandlers<Event::NickUnsuspend> &event) : Command(creator, "nickserv/unsuspend", 1, 1), onnickunsuspend(event)
+ CommandNSUnSuspend(Module *creator) : Command(creator, "nickserv/unsuspend", 1, 1)
{
this->SetDesc(_("Unsuspend a given nick"));
this->SetSyntax(_("\037account\037"));
@@ -222,7 +224,7 @@ class CommandNSUnSuspend : public Command
return;
}
- NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo);
+ NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>();
if (!si)
{
source.Reply(_("\002{0}\002 is not suspended."), na->GetNick());
@@ -235,7 +237,7 @@ class CommandNSUnSuspend : public Command
source.Reply(_("\002{0}\002 is now released."), na->GetNick());
- this->onnickunsuspend(&Event::NickUnsuspend::OnNickUnsuspend, na);
+ EventManager::Get()->Dispatch(&Event::NickUnsuspend::OnNickUnsuspend, na);
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
@@ -252,8 +254,6 @@ class NSSuspend : public Module
{
CommandNSSuspend commandnssuspend;
CommandNSUnSuspend commandnsunsuspend;
- EventHandlers<Event::NickSuspend> onnicksuspend;
- EventHandlers<Event::NickUnsuspend> onnickunsuspend;
std::vector<Anope::string> show;
NSSuspendType nst;
@@ -272,10 +272,11 @@ class NSSuspend : public Module
public:
NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandnssuspend(this, onnicksuspend)
- , commandnsunsuspend(this, onnickunsuspend)
- , onnicksuspend(this)
- , onnickunsuspend(this)
+ , EventHook<Event::NickInfo>(this)
+ , EventHook<NickServ::Event::PreNickExpire>(this)
+ , EventHook<NickServ::Event::NickValidate>(this)
+ , commandnssuspend(this)
+ , commandnsunsuspend(this)
, nst(this)
{
}
@@ -289,7 +290,7 @@ class NSSuspend : public Module
void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override
{
- NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo);
+ NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>();
if (!s)
return;
@@ -307,7 +308,7 @@ class NSSuspend : public Module
void OnPreNickExpire(NickServ::Nick *na, bool &expire) override
{
- NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo);
+ NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>();
if (!s)
return;
@@ -327,7 +328,7 @@ class NSSuspend : public Module
EventReturn OnNickValidate(User *u, NickServ::Nick *na) override
{
- NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo);
+ NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>();
if (!s)
return EVENT_CONTINUE;
diff --git a/modules/nickserv/update.cpp b/modules/nickserv/update.cpp
index 6781585d3..d4815b4cb 100644
--- a/modules/nickserv/update.cpp
+++ b/modules/nickserv/update.cpp
@@ -14,10 +14,8 @@
class CommandNSUpdate : public Command
{
- EventHandlers<Event::NickUpdate> &onnickupdate;
-
public:
- CommandNSUpdate(Module *creator, EventHandlers<Event::NickUpdate> &event) : Command(creator, "nickserv/update", 0, 0), onnickupdate(event)
+ CommandNSUpdate(Module *creator) : Command(creator, "nickserv/update", 0, 0)
{
this->SetDesc(_("Updates your current status, i.e. it checks for new memos"));
this->RequireUser(true);
@@ -34,7 +32,7 @@ class CommandNSUpdate : public Command
na->SetLastSeen(Anope::CurTime);
}
- this->onnickupdate(&Event::NickUpdate::OnNickUpdate, u);
+ EventManager::Get()->Dispatch(&Event::NickUpdate::OnNickUpdate, u);
source.Reply(_("Status updated (memos, vhost, chmodes, flags)."));
}
@@ -53,12 +51,10 @@ class CommandNSUpdate : public Command
class NSUpdate : public Module
{
CommandNSUpdate commandnsupdate;
- EventHandlers<Event::NickUpdate> onnickupdate;
public:
NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandnsupdate(this, onnickupdate)
- , onnickupdate(this)
+ , commandnsupdate(this)
{
}
diff --git a/modules/operserv/akill.cpp b/modules/operserv/akill.cpp
index 7f366e0c9..1f62b2f55 100644
--- a/modules/operserv/akill.cpp
+++ b/modules/operserv/akill.cpp
@@ -1,21 +1,18 @@
/* OperServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
*/
#include "module.h"
-static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-
class CommandOSAKill : public Command
{
- private:
+ ServiceReference<XLineManager> akills;
+
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
Anope::string expiry, mask;
@@ -120,7 +117,12 @@ class CommandOSAKill : public Command
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(source.GetNick());
+ x->SetExpires(expires);
+ x->SetReason(reason);
+
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->SetID(XLineManager::GenerateUID());
@@ -139,7 +141,7 @@ class CommandOSAKill : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, akills);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, akills);
if (MOD_RESULT == EVENT_STOP)
{
delete x;
@@ -212,7 +214,7 @@ class CommandOSAKill : public Command
do
{
- Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills);
+ EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, akills);
Log(LOG_ADMIN, source, this) << "to remove " << x->GetMask() << " from the list";
source.Reply(_("\002{0}\002 deleted from the akill list."), x->GetMask());
@@ -256,7 +258,7 @@ class CommandOSAKill : public Command
unsigned int i = 0;
for (XLine *x : akills->GetXLines())
{
- if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true))
+ if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->GetID() || Anope::Match(x->GetMask(), mask, false, true))
{
ListFormatter::ListEntry entry;
entry["Number"] = stringify(++i);
@@ -319,7 +321,7 @@ class CommandOSAKill : public Command
{
for (XLine *x : akills->GetXLines())
{
- Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills);
+ EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, akills);
x->Delete();
}
@@ -331,6 +333,7 @@ class CommandOSAKill : public Command
}
public:
CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2)
+ , akills("xlinemanager/sgline")
{
this->SetDesc(_("Manipulate the AKILL list"));
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
diff --git a/modules/operserv/chankill.cpp b/modules/operserv/chankill.cpp
index 8d3773e9d..81f04583b 100644
--- a/modules/operserv/chankill.cpp
+++ b/modules/operserv/chankill.cpp
@@ -11,12 +11,13 @@
#include "module.h"
-static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-
class CommandOSChanKill : public Command
{
+ ServiceReference<XLineManager> akills;
+
public:
CommandOSChanKill(Module *creator) : Command(creator, "operserv/chankill", 2, 3)
+ , akills("xlinemanager/sgline")
{
this->SetDesc(_("AKILL all users on a specific channel"));
this->SetSyntax(_("[+\037expiry\037] \037channel\037 \037reason\037"));
@@ -83,7 +84,13 @@ class CommandOSChanKill : public Command
if (uc->user->server == Me || uc->user->HasMode("OPER"))
continue;
- XLine *x = new XLine("*@" + uc->user->host, source.GetNick(), expires, realreason, XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask("*@" + uc->user->host);
+ x->SetBy(source.GetNick());
+ x->SetExpires(expires);
+ x->SetReason(realreason);
+ x->SetID(XLineManager::GenerateUID());
+
akills->AddXLine(x);
akills->OnMatch(uc->user, x);
}
diff --git a/modules/operserv/defcon.cpp b/modules/operserv/defcon.cpp
index fc4a096c9..ba081eb06 100644
--- a/modules/operserv/defcon.cpp
+++ b/modules/operserv/defcon.cpp
@@ -107,11 +107,11 @@ static Timer *timeout;
class DefConTimeout : public Timer
{
- EventHandlers<Event::DefconLevel> &eventdefcon;
int level;
+ ServiceReference<Global::GlobalService> global;
public:
- DefConTimeout(EventHandlers<Event::DefconLevel> &ev, Module *mod, int newlevel) : Timer(mod, DConfig.timeout), eventdefcon(ev), level(newlevel)
+ DefConTimeout(Module *mod, int newlevel) : Timer(mod, DConfig.timeout), level(newlevel)
{
timeout = this;
}
@@ -126,18 +126,18 @@ class DefConTimeout : public Timer
if (DConfig.defaultlevel != level)
{
DConfig.defaultlevel = level;
- this->eventdefcon(&Event::DefconLevel::OnDefconLevel, level);
+ EventManager::Get()->Dispatch(&Event::DefconLevel::OnDefconLevel, level);
Log(Config->GetClient("OperServ"), "operserv/defcon") << "Defcon level timeout, returning to level " << level;
- if (DConfig.globalondefcon && Global::service)
+ if (DConfig.globalondefcon && global)
{
if (!DConfig.offmessage.empty())
- Global::service->SendGlobal(NULL, "", DConfig.offmessage);
+ global->SendGlobal(NULL, "", DConfig.offmessage);
else
- Global::service->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel));
+ global->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel));
if (!DConfig.message.empty())
- Global::service->SendGlobal(NULL, "", DConfig.message);
+ global->SendGlobal(NULL, "", DConfig.message);
}
runDefCon();
@@ -147,6 +147,8 @@ class DefConTimeout : public Timer
class CommandOSDefcon : public Command
{
+ ServiceReference<Global::GlobalService> global;
+
void SendLevels(CommandSource &source)
{
if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
@@ -171,10 +173,8 @@ class CommandOSDefcon : public Command
source.Reply(_("* No new memos sent"));
}
- EventHandlers<Event::DefconLevel> &ondefconlevel;
-
public:
- CommandOSDefcon(Module *creator, EventHandlers<Event::DefconLevel> &event) : Command(creator, "operserv/defcon", 1, 1), ondefconlevel(event)
+ CommandOSDefcon(Module *creator) : Command(creator, "operserv/defcon", 1, 1)
{
this->SetDesc(_("Manipulate the DefCon system"));
this->SetSyntax(_("[\0021\002|\0022\002|\0023\002|\0024\002|\0025\002]"));
@@ -206,12 +206,12 @@ class CommandOSDefcon : public Command
DConfig.defaultlevel = newLevel;
- this->ondefconlevel(&Event::DefconLevel::OnDefconLevel, newLevel);
+ EventManager::Get()->Dispatch(&Event::DefconLevel::OnDefconLevel, newLevel);
delete timeout;
if (DConfig.timeout)
- timeout = new DefConTimeout(this->ondefconlevel, this->module, 5);
+ timeout = new DefConTimeout(this->module, 5);
source.Reply(_("Services are now at defcon \002{0}\002."), DConfig.defaultlevel);
this->SendLevels(source);
@@ -219,15 +219,15 @@ class CommandOSDefcon : public Command
/* Global notice the user what is happening. Also any Message that
the Admin would like to add. Set in config file. */
- if (DConfig.globalondefcon && Global::service)
+ if (DConfig.globalondefcon && global)
{
if (DConfig.defaultlevel == 5 && !DConfig.offmessage.empty())
- Global::service->SendGlobal(NULL, "", DConfig.offmessage);
+ global->SendGlobal(NULL, "", DConfig.offmessage);
else if (DConfig.defaultlevel != 5)
{
- Global::service->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel));
+ global->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel));
if (!DConfig.message.empty())
- Global::service->SendGlobal(NULL, "", DConfig.message);
+ global->SendGlobal(NULL, "", DConfig.message);
}
}
@@ -254,7 +254,6 @@ class OSDefcon : public Module
ServiceReference<SessionService> session_service;
ServiceReference<XLineManager> akills;
CommandOSDefcon commandosdefcon;
- EventHandlers<Event::DefconLevel> ondefconlevel;
void ParseModeString()
{
@@ -337,10 +336,14 @@ class OSDefcon : public Module
public:
OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , session_service("SessionService", "session")
- , akills("XLineManager", "xlinemanager/sgline")
- , commandosdefcon(this, ondefconlevel)
- , ondefconlevel(this)
+ , EventHook<Event::ChannelModeSet>(this)
+ , EventHook<Event::ChannelModeUnset>(this)
+ , EventHook<Event::PreCommand>(this)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::ChannelModeAdd>(this)
+ , EventHook<Event::ChannelSync>(this)
+ , akills("xlinemanager/sgline")
+ , commandosdefcon(this)
{
}
@@ -463,7 +466,7 @@ class OSDefcon : public Module
{
return EVENT_STOP;
}
- else if (command->name == "nickserv/register" || command->name == "nickserv/group")
+ else if (command->GetName() == "nickserv/register" || command->GetName() == "nickserv/group")
{
if (DConfig.Check(DEFCON_NO_NEW_NICKS))
{
@@ -471,7 +474,7 @@ class OSDefcon : public Module
return EVENT_STOP;
}
}
- else if (command->name == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK"))
+ else if (command->GetName() == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK"))
{
if (DConfig.Check(DEFCON_NO_MLOCK_CHANGE))
{
@@ -479,7 +482,7 @@ class OSDefcon : public Module
return EVENT_STOP;
}
}
- else if (command->name == "chanserv/register")
+ else if (command->GetName() == "chanserv/register")
{
if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
{
@@ -487,7 +490,7 @@ class OSDefcon : public Module
return EVENT_STOP;
}
}
- else if (command->name == "memoserv/send")
+ else if (command->GetName() == "memoserv/send")
{
if (DConfig.Check(DEFCON_NO_NEW_MEMOS))
{
@@ -508,8 +511,11 @@ class OSDefcon : public Module
if (DConfig.Check(DEFCON_AKILL_NEW_CLIENTS) && akills)
{
Log(OperServ, "operserv/defcon") << "DEFCON: adding akill for *@" << u->host;
+#warning "xline allocated on stack"
+#if 0
XLine x("*@" + u->host, OperServ ? OperServ->nick : "defcon", Anope::CurTime + DConfig.akillexpire, DConfig.akillreason, XLineManager::GenerateUID());
akills->Send(NULL, &x);
+#endif
}
if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
@@ -539,9 +545,12 @@ class OSDefcon : public Module
++session->hits;
if (akills && DConfig.max_session_kill && session->hits >= DConfig.max_session_kill)
{
+#warning "xline allocated on stack"
+#if 0
XLine x("*@" + session->addr.mask(), OperServ ? OperServ->nick : "", Anope::CurTime + DConfig.session_autokill_expiry, "Defcon session limit exceeded", XLineManager::GenerateUID());
akills->Send(NULL, &x);
Log(OperServ, "akill/defcon") << "[DEFCON] Added a temporary AKILL for \002*@" << session->addr.mask() << "\002 due to excessive connections";
+#endif
}
else
{
diff --git a/modules/operserv/dns.cpp b/modules/operserv/dns.cpp
index 1d714700d..2cf79d631 100644
--- a/modules/operserv/dns.cpp
+++ b/modules/operserv/dns.cpp
@@ -13,6 +13,10 @@ static std::map<Anope::string, std::list<time_t> > server_quit_times;
class DNSZoneImpl : public DNSZone
{
+ friend class DNSZoneType;
+
+ Anope::string name;
+
public:
DNSZoneImpl(Serialize::TypeBase *type) : DNSZone(type) { }
DNSZoneImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZone(type, id) { }
@@ -22,7 +26,7 @@ class DNSZoneImpl : public DNSZone
static DNSZone *Find(const Anope::string &name)
{
- for (DNSZone *zone : Serialize::GetObjects<DNSZone *>(dnszone))
+ for (DNSZone *zone : Serialize::GetObjects<DNSZone *>())
if (zone->GetName().equals_ci(name))
return zone;
return nullptr;
@@ -34,8 +38,8 @@ class DNSZoneType : public Serialize::Type<DNSZoneImpl>
public:
Serialize::Field<DNSZoneImpl, Anope::string> name;
- DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator, "DNSZone")
- , name(this, "name")
+ DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator)
+ , name(this, "name", &DNSZoneImpl::name)
{
}
};
@@ -52,6 +56,15 @@ void DNSZoneImpl::SetName(const Anope::string &name)
class DNSServerImpl : public DNSServer
{
+ friend class DNSServerType;
+
+ ServiceReference<DNS::Manager> manager;
+
+ DNSZone *zone = nullptr;
+ Anope::string name;
+ unsigned int limit = 0;
+ bool pooled = false;
+
/* is actually in the pool */
bool active = false;
@@ -85,17 +98,17 @@ class DNSServerImpl : public DNSServer
this->SetPool(p);
active = p;
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
+ manager->UpdateSerial();
for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it)
- DNS::manager->Notify(*it);
+ manager->Notify(*it);
}
}
static DNSServerImpl *Find(const Anope::string &s)
{
- for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>(dnsserver))
+ for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>())
if (server->GetName().equals_ci(s))
return server;
return nullptr;
@@ -110,11 +123,11 @@ class DNSServerType : public Serialize::Type<DNSServerImpl>
Serialize::Field<DNSServerImpl, unsigned int> limit;
Serialize::Field<DNSServerImpl, bool> pooled;
- DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator, "DNSServer")
- , zone(this, "zone")
- , name(this, "name")
- , limit(this, "limit")
- , pooled(this, "pooled")
+ DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator)
+ , zone(this, "zone", &DNSServerImpl::zone)
+ , name(this, "name", &DNSServerImpl::name)
+ , limit(this, "limit", &DNSServerImpl::limit)
+ , pooled(this, "pooled", &DNSServerImpl::pooled)
{
}
};
@@ -161,6 +174,11 @@ void DNSServerImpl::SetPool(const bool &p)
class DNSZoneMembershipImpl : public DNSZoneMembership
{
+ friend class DNSZoneMembershipType;
+
+ DNSServer *server = nullptr;
+ DNSZone *zone = nullptr;
+
public:
DNSZoneMembershipImpl(Serialize::TypeBase *type) : DNSZoneMembership(type) { }
DNSZoneMembershipImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZoneMembership(type, id) { }
@@ -173,7 +191,7 @@ class DNSZoneMembershipImpl : public DNSZoneMembership
static DNSZoneMembership *Find(DNSServer *server, DNSZone *zone)
{
- for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>(dnszonemembership))
+ for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>())
if (mem->GetServer() == server && mem->GetZone() == zone)
return mem;
return nullptr;
@@ -186,9 +204,9 @@ class DNSZoneMembershipType : public Serialize::Type<DNSZoneMembershipImpl>
Serialize::ObjectField<DNSZoneMembershipImpl, DNSServer *> server;
Serialize::ObjectField<DNSZoneMembershipImpl, DNSZone *> zone;
- DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator, "DNSZoneMembership")
- , server(this, "server")
- , zone(this, "zone")
+ DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator)
+ , server(this, "server", &DNSZoneMembershipImpl::server)
+ , zone(this, "zone", &DNSZoneMembershipImpl::zone)
{
}
};
@@ -215,6 +233,11 @@ void DNSZoneMembershipImpl::SetZone(DNSZone *z)
class DNSIPImpl : public DNSIP
{
+ friend class DNSIPType;
+
+ DNSServer *server = nullptr;
+ Anope::string ip;
+
public:
DNSIPImpl(Serialize::TypeBase *type) : DNSIP(type) { }
DNSIPImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSIP(type, id) { }
@@ -229,12 +252,12 @@ class DNSIPImpl : public DNSIP
class DNSIPType : public Serialize::Type<DNSIPImpl>
{
public:
- Serialize::ObjectField<DNSServerImpl, DNSServer *> server;
- Serialize::Field<DNSServerImpl, Anope::string> ip;
+ Serialize::ObjectField<DNSIPImpl, DNSServer *> server;
+ Serialize::Field<DNSIPImpl, Anope::string> ip;
- DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator, "DNSIP")
- , server(this, "server")
- , ip(this, "ip")
+ DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator)
+ , server(this, "server", &DNSIPImpl::server)
+ , ip(this, "ip", &DNSIPImpl::ip)
{
}
};
@@ -261,9 +284,11 @@ void DNSIPImpl::SetIP(const Anope::string &ip)
class CommandOSDNS : public Command
{
+ ServiceReference<DNS::Manager> manager;
+
void DisplayPoolState(CommandSource &source)
{
- std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>(dnsserver);
+ std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>();
if (servers.empty())
{
@@ -282,7 +307,7 @@ class CommandOSDNS : public Command
entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None"));
Anope::string ip_str;
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
ip_str += ip->GetIP() + " ";
ip_str.trim();
if (ip_str.empty())
@@ -305,7 +330,7 @@ class CommandOSDNS : public Command
std::vector<Anope::string> replies;
lf.Process(replies);
- std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>(dnszone);
+ std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>();
if (!zones.empty())
{
ListFormatter lf2(source.GetAccount());
@@ -317,7 +342,7 @@ class CommandOSDNS : public Command
entry["Zone"] = z->GetName();
Anope::string server_str;
- for (DNSServer *s : z->GetRefs<DNSServer *>(dnsserver))
+ for (DNSServer *s : z->GetRefs<DNSServer *>())
server_str += s->GetName() + " ";
server_str.trim();
@@ -351,7 +376,7 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to add zone " << zone;
- DNSZone *z = dnszone.Create();
+ DNSZone *z = Serialize::New<DNSZone *>();
z->SetName(zone);
source.Reply(_("Added zone \002{0}\002."), zone);
}
@@ -372,13 +397,13 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to delete zone " << z->GetName();
- for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>(dnszonemembership))
+ for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>())
mem->Delete();
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(z->GetName());
+ manager->UpdateSerial();
+ manager->Notify(z->GetName());
}
source.Reply(_("Zone \002{0}\002 removed."), z->GetName());
@@ -415,14 +440,14 @@ class CommandOSDNS : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- mem = dnszonemembership.Create();
+ mem = Serialize::New<DNSZoneMembership *>();
mem->SetZone(z);
mem->SetServer(s);
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(zone);
+ manager->UpdateSerial();
+ manager->Notify(zone);
}
Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << z->GetName();
@@ -440,7 +465,7 @@ class CommandOSDNS : public Command
return;
}
- s = dnsserver.Create();
+ s = Serialize::New<DNSServer *>();
s->SetName(params[1]);
if (zone.empty())
{
@@ -465,14 +490,14 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << zone;
- DNSZoneMembership *mem = dnszonemembership.Create();
+ DNSZoneMembership *mem = Serialize::New<DNSZoneMembership *>();
mem->SetServer(s);
mem->SetZone(z);
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(z->GetName());
+ manager->UpdateSerial();
+ manager->Notify(z->GetName());
}
}
}
@@ -509,10 +534,10 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to remove server " << s->GetName() << " from zone " << z->GetName();
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(z->GetName());
+ manager->UpdateSerial();
+ manager->Notify(z->GetName());
}
mem->Delete();
@@ -526,14 +551,14 @@ class CommandOSDNS : public Command
return;
}
- for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>(dnszonemembership))
+ for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>())
mem->Delete();
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- if (DNS::manager)
- DNS::manager->UpdateSerial();
+ if (manager)
+ manager->UpdateSerial();
Log(LOG_ADMIN, source, this) << "to delete server " << s->GetName();
source.Reply(_("Removed server \002{0}\002."), s->GetName());
@@ -550,7 +575,7 @@ class CommandOSDNS : public Command
return;
}
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
if (params[2].equals_ci(ip->GetIP()))
{
source.Reply(_("IP \002{0}\002 already exists for \002{1}\002."), ip->GetIP(), s->GetName());
@@ -567,18 +592,18 @@ class CommandOSDNS : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- DNSIP *ip = dnsip.Create();
+ DNSIP *ip = Serialize::New<DNSIP *>();
ip->SetServer(s);
ip->SetIP(params[2]);
source.Reply(_("Added IP \002{0}\002 to \002{1}\002."), params[2], s->GetName());
Log(LOG_ADMIN, source, this) << "to add IP " << params[2] << " to " << s->GetName();
- if (s->Active() && DNS::manager)
+ if (s->Active() && manager)
{
- DNS::manager->UpdateSerial();
- for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone))
- DNS::manager->Notify(zone->GetName());
+ manager->UpdateSerial();
+ for (DNSZone *zone : s->GetRefs<DNSZone *>())
+ manager->Notify(zone->GetName());
}
}
@@ -595,7 +620,7 @@ class CommandOSDNS : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
if (params[2].equals_ci(ip->GetIP()))
{
ip->Delete();
@@ -603,17 +628,17 @@ class CommandOSDNS : public Command
source.Reply(_("Removed IP \002{0}\002 from \002{1}\002."), params[2], s->GetName());
Log(LOG_ADMIN, source, this) << "to remove IP " << params[2] << " from " << s->GetName();
- if (s->GetRefs<DNSIP *>(dnsip).empty())
+ if (s->GetRefs<DNSIP *>().empty())
{
s->repool = 0;
s->SetPool(false);
}
- if (s->Active() && DNS::manager)
+ if (s->Active() && manager)
{
- DNS::manager->UpdateSerial();
- for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone))
- DNS::manager->Notify(zone->GetName());
+ manager->UpdateSerial();
+ for (DNSZone *zone : s->GetRefs<DNSZone *>())
+ manager->Notify(zone->GetName());
}
return;
@@ -677,7 +702,7 @@ class CommandOSDNS : public Command
return;
}
- if (s->GetRefs<DNSIP *>(dnsip).empty())
+ if (s->GetRefs<DNSIP *>().empty())
{
source.Reply(_("Server \002{0}\002 has no configured IPs."), s->GetName());
return;
@@ -791,32 +816,34 @@ class ModuleDNS : public Module
DNSIPType iptype;
CommandOSDNS commandosdns;
- time_t ttl;
- int user_drop_mark;
- time_t user_drop_time;
- time_t user_drop_readd_time;
- bool remove_split_servers;
- bool readd_connected_servers;
+ time_t ttl = 0;
+ int user_drop_mark = 0;
+ time_t user_drop_time = 0;
+ time_t user_drop_readd_time = 0;
+ bool remove_split_servers = 0;
+ bool readd_connected_servers = 0;
- time_t last_warn;
+ time_t last_warn = 0;
public:
ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
+ , EventHook<Event::NewServer>(this)
+ , EventHook<Event::ServerQuit>(this)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::PreUserLogoff>(this)
+ , EventHook<Event::DnsRequest>(this)
, zonetype(this)
, servertype(this)
, zonemembtype(this)
, iptype(this)
, commandosdns(this)
- , last_warn(0)
{
-#if 0
- for (unsigned j = 0; j < dns_servers->size(); ++j)
- {
- DNSServer *s = dns_servers->at(j);
- if (s->Pooled() && Server::Find(s->GetName(), true))
+ /* enable active flag for linked servers */
+ std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>();
+
+ for (DNSServerImpl *s : servers)
+ if (s->GetPooled() && Server::Find(s->GetName(), true))
s->SetActive(true);
- }
-#endif
}
~ModuleDNS()
@@ -841,7 +868,7 @@ class ModuleDNS : public Module
if (!Me->IsSynced() || this->readd_connected_servers)
{
DNSServerImpl *dns = DNSServerImpl::Find(s->GetName());
- if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>(dnsip).empty())
+ if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>().empty())
{
dns->SetActive(true);
Log(this) << "Pooling server " << s->GetName();
@@ -934,12 +961,12 @@ class ModuleDNS : public Module
size_t answer_size = packet->answers.size();
if (zone)
{
- for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>(dnsserver))
+ for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>())
{
if (!s->Active())
continue;
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
{
DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
@@ -957,12 +984,12 @@ class ModuleDNS : public Module
if (packet->answers.size() == answer_size)
{
/* Default zone */
- for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>(dnsserver))
+ for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>())
{
if (!s->Active())
continue;
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
{
DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
@@ -986,8 +1013,8 @@ class ModuleDNS : public Module
}
/* Something messed up, just return them all and hope one is available */
- for (DNSServer *s : Serialize::GetObjects<DNSServer *>(dnsserver))
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSServer *s : Serialize::GetObjects<DNSServer *>())
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
{
DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp
index 2375eddcd..6fb0172cf 100644
--- a/modules/operserv/forbid.cpp
+++ b/modules/operserv/forbid.cpp
@@ -16,6 +16,12 @@
class ForbidDataImpl : public ForbidData
{
+ friend class ForbidDataType;
+
+ Anope::string mask, creator, reason;
+ time_t created = 0, expires = 0;
+ ForbidType type = static_cast<ForbidType>(0);
+
public:
ForbidDataImpl(Serialize::TypeBase *type) : ForbidData(type) { }
ForbidDataImpl(Serialize::TypeBase *type, Serialize::ID id) : ForbidData(type, id) { }
@@ -46,13 +52,13 @@ class ForbidDataType : public Serialize::Type<ForbidDataImpl>
Serialize::Field<ForbidDataImpl, time_t> created, expires;
Serialize::Field<ForbidDataImpl, ForbidType> type;
- ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me, "ForbidData")
- , mask(this, "mask")
- , creator(this, "creator")
- , reason(this, "reason")
- , created(this, "created")
- , expires(this, "expires")
- , type(this, "type")
+ ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me)
+ , mask(this, "mask", &ForbidDataImpl::mask)
+ , creator(this, "creator", &ForbidDataImpl::creator)
+ , reason(this, "reason", &ForbidDataImpl::reason)
+ , created(this, "created", &ForbidDataImpl::created)
+ , expires(this, "expires", &ForbidDataImpl::expires)
+ , type(this, "type", &ForbidDataImpl::type)
{
}
};
@@ -134,7 +140,7 @@ class MyForbidService : public ForbidService
std::vector<ForbidData *> GetForbids() override
{
- for (ForbidData *d : Serialize::GetObjects<ForbidData *>(forbiddata))
+ for (ForbidData *d : Serialize::GetObjects<ForbidData *>())
if (d->GetExpires() && !Anope::NoExpire && Anope::CurTime >= d->GetExpires())
{
Anope::string ftype = "none";
@@ -148,15 +154,16 @@ class MyForbidService : public ForbidService
Log(LOG_NORMAL, "expire/forbid", Config->GetClient("OperServ")) << "Expiring forbid for " << d->GetMask() << " type " << ftype;
d->Delete();
}
- return Serialize::GetObjects<ForbidData *>(forbiddata);
+ return Serialize::GetObjects<ForbidData *>();
}
};
class CommandOSForbid : public Command
{
ServiceReference<ForbidService> fs;
+
public:
- CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5), fs("ForbidService", "forbid")
+ CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5)
{
this->SetDesc(_("Forbid usage of nicknames, channels, and emails"));
this->SetSyntax(_("ADD {NICK|CHAN|EMAIL|REGISTER} [+\037expiry\037] \037entry\037 \037reason\037"));
@@ -242,7 +249,7 @@ class CommandOSForbid : public Command
bool created = false;
if (d == NULL)
{
- d = forbiddata.Create();
+ d = Serialize::New<ForbidData *>();
created = true;
}
@@ -303,8 +310,11 @@ class CommandOSForbid : public Command
if (IRCD->CanSQLineChannel && OperServ)
{
time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s");
+#warning "xline allocated on stack"
+#if 0
XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->GetReason());
IRCD->SendSQLine(NULL, &x);
+#endif
}
else if (ChanServ::service)
{
@@ -460,6 +470,10 @@ class OSForbid : public Module
public:
OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::UserNickChange>(this)
+ , EventHook<Event::CheckKick>(this)
+ , EventHook<Event::PreCommand>(this)
, forbid_service(this)
, type(this)
, commandosforbid(this)
@@ -491,8 +505,11 @@ class OSForbid : public Module
if (IRCD->CanSQLineChannel)
{
time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s");
+#warning "xline allocated on stack"
+#if 0
XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->GetReason());
IRCD->SendSQLine(NULL, &x);
+#endif
}
else if (ChanServ::service)
{
@@ -509,7 +526,7 @@ class OSForbid : public Module
EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
{
- if (command->name == "nickserv/info" && params.size() > 0)
+ if (command->GetName() == "nickserv/info" && params.size() > 0)
{
ForbidData *d = this->forbid_service.FindForbid(params[0], FT_NICK);
if (d != NULL)
@@ -521,7 +538,7 @@ class OSForbid : public Module
return EVENT_STOP;
}
}
- else if (command->name == "chanserv/info" && params.size() > 0)
+ else if (command->GetName() == "chanserv/info" && params.size() > 0)
{
ForbidData *d = this->forbid_service.FindForbid(params[0], FT_CHAN);
if (d != NULL)
@@ -535,7 +552,7 @@ class OSForbid : public Module
}
else if (source.IsOper())
return EVENT_CONTINUE;
- else if (command->name == "nickserv/register" && params.size() > 1)
+ else if (command->GetName() == "nickserv/register" && params.size() > 1)
{
ForbidData *d = this->forbid_service.FindForbid(source.GetNick(), FT_REGISTER);
if (d != NULL)
@@ -551,7 +568,7 @@ class OSForbid : public Module
return EVENT_STOP;
}
}
- else if (command->name == "nickserv/set/email" && params.size() > 0)
+ else if (command->GetName() == "nickserv/set/email" && params.size() > 0)
{
ForbidData *d = this->forbid_service.FindForbid(params[0], FT_EMAIL);
if (d != NULL)
@@ -560,7 +577,7 @@ class OSForbid : public Module
return EVENT_STOP;
}
}
- else if (command->name == "chanserv/register" && !params.empty())
+ else if (command->GetName() == "chanserv/register" && !params.empty())
{
ForbidData *d = this->forbid_service.FindForbid(params[0], FT_REGISTER);
if (d != NULL)
diff --git a/modules/operserv/ignore.cpp b/modules/operserv/ignore.cpp
index 0aeab0718..ffd85e5e9 100644
--- a/modules/operserv/ignore.cpp
+++ b/modules/operserv/ignore.cpp
@@ -14,6 +14,11 @@
class IgnoreImpl : public Ignore
{
+ friend class IgnoreType;
+
+ Anope::string mask, creator, reason;
+ time_t time = 0;
+
public:
IgnoreImpl(Serialize::TypeBase *type) : Ignore(type) { }
IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : Ignore(type, id) { }
@@ -37,11 +42,11 @@ class IgnoreType : public Serialize::Type<IgnoreImpl>
Serialize::Field<IgnoreImpl, Anope::string> mask, creator, reason;
Serialize::Field<IgnoreImpl, time_t> time;
- IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me, "IgnoreData")
- , mask(this, "mask")
- , creator(this, "creator")
- , reason(this, "reason")
- , time(this, "time")
+ IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me)
+ , mask(this, "mask", &IgnoreImpl::mask)
+ , creator(this, "creator", &IgnoreImpl::creator)
+ , reason(this, "reason", &IgnoreImpl::reason)
+ , time(this, "time", &IgnoreImpl::time)
{
}
};
@@ -96,7 +101,7 @@ class OSIgnoreService : public IgnoreService
Ignore *Find(const Anope::string &mask) override
{
User *u = User::Find(mask, true);
- std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(ignoretype);
+ std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>();
std::vector<Ignore *>::iterator ign = ignores.begin(), ign_end = ignores.end();
if (u)
@@ -155,6 +160,8 @@ class OSIgnoreService : public IgnoreService
class CommandOSIgnore : public Command
{
+ ServiceReference<IgnoreService> ignore_service;
+
private:
Anope::string RealMask(const Anope::string &mask)
{
@@ -216,7 +223,7 @@ class CommandOSIgnore : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- Ignore *ign = ignoretype.Create();
+ Ignore *ign = Serialize::New<Ignore *>();
ign->SetMask(mask);
ign->SetCreator(source.GetNick());
ign->SetReason(reason);
@@ -236,7 +243,7 @@ class CommandOSIgnore : public Command
void DoList(CommandSource &source)
{
- std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(ignoretype);
+ std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>();
for (Ignore *id : ignores)
{
@@ -247,7 +254,7 @@ class CommandOSIgnore : public Command
}
}
- ignores = Serialize::GetObjects<Ignore *>(ignoretype);
+ ignores = Serialize::GetObjects<Ignore *>();
if (ignores.empty())
{
source.Reply(_("Ignore list is empty."));
@@ -312,7 +319,7 @@ class CommandOSIgnore : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- for (Ignore *ign : Serialize::GetObjects<Ignore *>(ignoretype))
+ for (Ignore *ign : Serialize::GetObjects<Ignore *>())
ign->Delete();
Log(LOG_ADMIN, source, this) << "to CLEAR the list";
@@ -374,6 +381,7 @@ class OSIgnore : public Module
public:
OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::BotPrivmsg>(this)
, ignoretype(this)
, osignoreservice(this)
, commandosignore(this)
diff --git a/modules/operserv/info.cpp b/modules/operserv/info.cpp
index bb0eb8274..c1d625601 100644
--- a/modules/operserv/info.cpp
+++ b/modules/operserv/info.cpp
@@ -13,6 +13,12 @@
class OperInfoImpl : public OperInfo
{
+ friend class OperInfoType;
+
+ Serialize::Object *target = nullptr;
+ Anope::string info, creator;
+ time_t created = 0;
+
public:
OperInfoImpl(Serialize::TypeBase *type) : OperInfo(type) { }
OperInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : OperInfo(type, id) { }
@@ -37,11 +43,11 @@ class OperInfoType : public Serialize::Type<OperInfoImpl>
Serialize::Field<OperInfoImpl, Anope::string> info, creator;
Serialize::Field<OperInfoImpl, time_t> created;
- OperInfoType(Module *c) : Serialize::Type<OperInfoImpl>(c, "OperInfo")
- , target(this, "target", true)
- , info(this, "info")
- , creator(this, "adder")
- , created(this, "created")
+ OperInfoType(Module *c) : Serialize::Type<OperInfoImpl>(c)
+ , target(this, "target", &OperInfoImpl::target, true)
+ , info(this, "info", &OperInfoImpl::info)
+ , creator(this, "adder", &OperInfoImpl::creator)
+ , created(this, "created", &OperInfoImpl::created)
{
}
};
@@ -133,7 +139,7 @@ class CommandOSInfo : public Command
return;
}
- std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo);
+ std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>();
if (oinfos.size() >= Config->GetModule(this->module)->Get<unsigned int>("max", "10"))
{
source.Reply(_("The oper info list for \002{0}\002 is full."), target);
@@ -147,7 +153,7 @@ class CommandOSInfo : public Command
return;
}
- OperInfo *o = operinfo.Create();
+ OperInfo *o = Serialize::New<OperInfo *>();
o->SetTarget(e);
o->SetInfo(info);
o->SetCreator(source.GetNick());
@@ -167,7 +173,7 @@ class CommandOSInfo : public Command
return;
}
- std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo);
+ std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>();
if (oinfos.empty())
{
source.Reply(_("Oper info list for \002{0}\002 is empty."), target);
@@ -193,7 +199,7 @@ class CommandOSInfo : public Command
}
else if (cmd.equals_ci("CLEAR"))
{
- std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo);
+ std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>();
if (oinfos.empty())
{
@@ -235,12 +241,14 @@ class OSInfo : public Module
if (!source.IsOper())
return;
- for (OperInfo *o : e->GetRefs<OperInfo *>(operinfo))
+ for (OperInfo *o : e->GetRefs<OperInfo *>())
info[_("Oper Info")] = Anope::printf(_("(by %s on %s) %s"), o->GetCreator().c_str(), Anope::strftime(o->GetCreated(), source.GetAccount(), true).c_str(), o->GetInfo().c_str());
}
public:
OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::NickInfo>(this)
+ , EventHook<Event::ChanInfo>(this)
, commandosinfo(this)
, oinfotype(this)
{
diff --git a/modules/operserv/login.cpp b/modules/operserv/login.cpp
index 650c48e3d..fa4daf11d 100644
--- a/modules/operserv/login.cpp
+++ b/modules/operserv/login.cpp
@@ -100,7 +100,7 @@ class CommandOSLogout : public Command
}
Log(LOG_ADMIN, source, this);
- u->ShrinkOK<bool>("os_login");
+ u->Shrink<bool>("os_login");
source.Reply(_("You have been logged out."));
}
@@ -125,6 +125,7 @@ class OSLogin : public Module
public:
OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::IsServicesOperEvent>(this)
, commandoslogin(this)
, commandoslogout(this)
, os_login(this, "os_login")
diff --git a/modules/operserv/logsearch.cpp b/modules/operserv/logsearch.cpp
index 0fa425aba..543430c50 100644
--- a/modules/operserv/logsearch.cpp
+++ b/modules/operserv/logsearch.cpp
@@ -89,7 +89,7 @@ class CommandOSLogSearch : public Command
Log(LOG_ADMIN, source, this) << "for " << search_string;
- const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<Anope::string>("logname");
+ const Anope::string &logfile_name = Config->GetModule(this->GetOwner())->Get<Anope::string>("logname");
std::list<Anope::string> matches;
for (int d = days - 1; d >= 0; --d)
{
diff --git a/modules/operserv/main/operserv.cpp b/modules/operserv/main/operserv.cpp
index 0a4f1b692..40c392ea7 100644
--- a/modules/operserv/main/operserv.cpp
+++ b/modules/operserv/main/operserv.cpp
@@ -13,15 +13,6 @@
#include "modules/help.h"
#include "modules/nickserv.h"
-class SGlineType : public XLineType
-{
- public:
- SGlineType(Module *creator) : XLineType(creator, "SGLine")
- {
- SetParent(xline);
- }
-};
-
class SGLineManager : public XLineManager
{
public:
@@ -74,15 +65,6 @@ class SGLineManager : public XLineManager
}
};
-class SQlineType : public XLineType
-{
- public:
- SQlineType(Module *creator) : XLineType(creator, "SQLine")
- {
- SetParent(xline);
- }
-};
-
class SQLineManager : public XLineManager
{
public:
@@ -152,15 +134,6 @@ class SQLineManager : public XLineManager
}
};
-class SNlineType : public XLineType
-{
- public:
- SNlineType(Module *creator) : XLineType(creator, "SNLine")
- {
- SetParent(xline);
- }
-};
-
class SNLineManager : public XLineManager
{
public:
@@ -211,20 +184,23 @@ class OperServCore : public Module
, public EventHook<Event::Log>
{
Reference<ServiceBot> OperServ;
- SGlineType sgtype;
SGLineManager sglines;
- SQlineType sqtype;
SQLineManager sqlines;
- SNlineType sntype;
SNLineManager snlines;
public:
OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
- , sgtype(this)
+ , EventHook<Event::BotPrivmsg>(this)
+ , EventHook<Event::ServerQuit>(this)
+ , EventHook<Event::UserModeSet>(this)
+ , EventHook<Event::UserModeUnset>(this)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::UserNickChange>(this)
+ , EventHook<Event::CheckKick>(this)
+ , EventHook<Event::Help>(this)
+ , EventHook<Event::Log>(this)
, sglines(this)
- , sqtype(this)
, sqlines(this)
- , sntype(this)
, snlines(this)
{
@@ -250,11 +226,11 @@ class OperServCore : public Module
const Anope::string &osnick = conf->GetModule(this)->Get<Anope::string>("client");
if (osnick.empty())
- throw ConfigException(this->name + ": <client> must be defined");
+ throw ConfigException(Module::name + ": <client> must be defined");
ServiceBot *bi = ServiceBot::Find(osnick, true);
if (!bi)
- throw ConfigException(this->name + ": no bot named " + osnick);
+ throw ConfigException(Module::name + ": no bot named " + osnick);
OperServ = bi;
}
diff --git a/modules/operserv/modinfo.cpp b/modules/operserv/modinfo.cpp
index f3c6db00f..8fc76d3d7 100644
--- a/modules/operserv/modinfo.cpp
+++ b/modules/operserv/modinfo.cpp
@@ -31,16 +31,15 @@ class CommandOSModInfo : public Command
{
source.Reply(_("Module: \002{0}\002 Version: \002{1}\002 Author: \002{2}\002 Loaded: \002{3}\002"), m->name, !m->version.empty() ? m->version : "?", !m->author.empty() ? m->author : "Unknown", Anope::strftime(m->created, source.GetAccount()));
if (Anope::Debug)
- source.Reply(_(" Loaded at: {0}"), Anope::printf("%o", m->handle));
+ source.Reply(_(" Loaded at: {0}"), Anope::printf("0x%x", m->handle));
- std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command");
- for (unsigned i = 0; i < servicekeys.size(); ++i)
+ std::vector<Command *> commands = ServiceManager::Get()->FindServices<Command *>();
+ for (Command *c : commands)
{
- ServiceReference<Command> c("Command", servicekeys[i]);
- if (!c || c->owner != m)
+ if (c->GetOwner() != m)
continue;
- source.Reply(_(" Providing service: \002{0}\002"), c->name);
+ source.Reply(_(" Providing service: \002{0}\002"), c->GetName());
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
@@ -55,9 +54,9 @@ class CommandOSModInfo : public Command
{
const Anope::string &c_name = cit->first;
const CommandInfo &info = cit->second;
- if (info.name != c->name)
+ if (info.name != c->GetName())
continue;
- source.Reply(_(" Command \002{0}\002 on \002{1}\002 is linked to \002{2}\002"), c_name, bi->nick, c->name);
+ source.Reply(_(" Command \002{0}\002 on \002{1}\002 is linked to \002{2}\002"), c_name, bi->nick, c->GetName());
}
}
}
diff --git a/modules/operserv/module.cpp b/modules/operserv/module.cpp
index 14bc897e3..311757bc0 100644
--- a/modules/operserv/module.cpp
+++ b/modules/operserv/module.cpp
@@ -137,7 +137,7 @@ class CommandOSModUnLoad : public Command
return;
}
- Log(this->owner) << "Trying to unload module [" << mname << "]";
+ Log(this->GetOwner()) << "Trying to unload module [" << mname << "]";
ModuleReturn status = ModuleManager::UnloadModule(m, source.GetUser());
diff --git a/modules/operserv/news.cpp b/modules/operserv/news.cpp
index c14103f2e..8180c3b3d 100644
--- a/modules/operserv/news.cpp
+++ b/modules/operserv/news.cpp
@@ -1,12 +1,10 @@
/* OperServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at info@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.
*/
#include "module.h"
@@ -67,6 +65,12 @@ static struct NewsMessages
class NewsItemImpl : public NewsItem
{
+ friend class NewsItemType;
+
+ NewsType type;
+ Anope::string text, who;
+ time_t time = 0;
+
public:
NewsItemImpl(Serialize::TypeBase *type) : NewsItem(type) { }
NewsItemImpl(Serialize::TypeBase *type, Serialize::ID id) : NewsItem(type, id) { }
@@ -92,11 +96,11 @@ class NewsItemType : public Serialize::Type<NewsItemImpl>
Serialize::Field<NewsItemImpl, Anope::string> who;
Serialize::Field<NewsItemImpl, time_t> time;
- NewsItemType(Module *me) : Serialize::Type<NewsItemImpl>(me, "NewsItem")
- , type(this, "type")
- , text(this, "text")
- , who(this, "who")
- , time(this, "time")
+ NewsItemType(Module *me) : Serialize::Type<NewsItemImpl>(me)
+ , type(this, "type", &NewsItemImpl::type)
+ , text(this, "text", &NewsItemImpl::text)
+ , who(this, "who", &NewsItemImpl::who)
+ , time(this, "time", &NewsItemImpl::time)
{
}
};
@@ -154,7 +158,7 @@ class NewsBase : public Command
protected:
void DoList(CommandSource &source, NewsType ntype, const char **msgs)
{
- std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem);
+ std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>();
if (list.empty())
{
@@ -200,7 +204,7 @@ class NewsBase : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- NewsItem *ni = newsitem.Create();
+ NewsItem *ni = Serialize::New<NewsItem *>();
ni->SetNewsType(ntype);
ni->SetText(text);
ni->SetTime(Anope::CurTime);
@@ -213,7 +217,7 @@ class NewsBase : public Command
void DoDel(CommandSource &source, const std::vector<Anope::string> &params, NewsType ntype, const char **msgs)
{
const Anope::string &text = params.size() > 1 ? params[1] : "";
- std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem);
+ std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>();
if (text.empty())
{
@@ -304,7 +308,7 @@ class CommandOSLogonNews : public NewsBase
source.Reply(_("Edits or displays the list of logon news messages. When a user connects to the network, these messages will be sent to them."
" However, no more than \002{0}\002 messages will be sent in order to avoid flooding the user."
" If there are more news messages, only the most recent will be sent."),
- Config->GetModule(this->owner)->Get<unsigned>("newscount", "3"));
+ Config->GetModule(this->GetOwner())->Get<unsigned>("newscount", "3"));
return true;
}
};
@@ -328,7 +332,7 @@ class CommandOSOperNews : public NewsBase
" When a user opers up (with the /OPER command), these messages will be sent to them."
" However, no more than \002{0}\002 messages will be sent in order to avoid flooding the user."
" If there are more news messages, only the most recent will be sent."),
- Config->GetModule(this->owner)->Get<unsigned>("newscount", "3"));
+ Config->GetModule(this->GetOwner())->Get<unsigned>("newscount", "3"));
return true;
}
};
@@ -369,7 +373,7 @@ class OSNews : public Module
void DisplayNews(User *u, NewsType Type)
{
- std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem);
+ std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>();
if (list.empty())
return;
@@ -426,6 +430,8 @@ class OSNews : public Module
public:
OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserModeSet>(this)
+ , EventHook<Event::UserConnect>(this)
, newsitemtype(this)
, commandoslogonnews(this)
, commandosopernews(this)
diff --git a/modules/operserv/noop.cpp b/modules/operserv/noop.cpp
index a12bef6a2..d2711b7f4 100644
--- a/modules/operserv/noop.cpp
+++ b/modules/operserv/noop.cpp
@@ -52,7 +52,7 @@ class CommandOSNOOP : public Command
}
else if (cmd.equals_ci("REVOKE"))
{
- s->ShrinkOK<Anope::string>("noop");
+ s->Shrink<Anope::string>("noop");
IRCD->SendSVSNOOP(s, false);
Log(LOG_ADMIN, source, this) << "REVOKE on " << s->GetName();
source.Reply(_("All O:lines of \002{0}\002 have been reset."), s->GetName());
@@ -77,6 +77,7 @@ class OSNOOP : public Module
public:
OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserModeSet>(this)
, commandosnoop(this)
, noop(this, "noop")
{
diff --git a/modules/operserv/oper.cpp b/modules/operserv/oper.cpp
index 923137013..780c71903 100644
--- a/modules/operserv/oper.cpp
+++ b/modules/operserv/oper.cpp
@@ -79,7 +79,7 @@ class CommandOSOper : public Command
na->GetAccount()->o = nullptr;
}
- Oper *o = operblock.Create();
+ Oper *o = Serialize::New<Oper *>();
o->SetName(na->GetAccount()->GetDisplay());
o->SetType(ot);
o->SetRequireOper(true);
diff --git a/modules/operserv/reload.cpp b/modules/operserv/reload.cpp
index 217194e18..1d3d041d4 100644
--- a/modules/operserv/reload.cpp
+++ b/modules/operserv/reload.cpp
@@ -35,7 +35,7 @@ class CommandOSReload : public Command
}
catch (const ConfigException &ex)
{
- Log(this->owner) << "Error reloading configuration file: " << ex.GetReason();
+ Log(this->GetOwner()) << "Error reloading configuration file: " << ex.GetReason();
source.Reply(_("Error reloading configuration file: {0}"), ex.GetReason());
}
}
diff --git a/modules/operserv/session.cpp b/modules/operserv/session.cpp
index 0c20e6d7a..31944e9b6 100644
--- a/modules/operserv/session.cpp
+++ b/modules/operserv/session.cpp
@@ -33,12 +33,16 @@ namespace
/* Number of bits to use when comparing session IPs */
unsigned ipv4_cidr;
unsigned ipv6_cidr;
-
- EventHandlers<Event::Exception> *events;
}
class ExceptionImpl : public Exception
{
+ friend class ExceptionType;
+
+ Anope::string mask, who, reason;
+ unsigned int limit = 0;
+ time_t time = 0, expires = 0;
+
public:
ExceptionImpl(Serialize::TypeBase *type) : Exception(type) { }
ExceptionImpl(Serialize::TypeBase *type, Serialize::ID id) : Exception(type, id) { }
@@ -69,13 +73,13 @@ class ExceptionType : public Serialize::Type<ExceptionImpl>
Serialize::Field<ExceptionImpl, unsigned int> limit;
Serialize::Field<ExceptionImpl, time_t> time, expires;
- ExceptionType(Module *me) : Serialize::Type<ExceptionImpl>(me, "Exception")
- , mask(this, "mask")
- , who(this, "who")
- , reason(this, "reason")
- , limit(this, "limit")
- , time(this, "time")
- , expires(this, "expires")
+ ExceptionType(Module *me) : Serialize::Type<ExceptionImpl>(me)
+ , mask(this, "mask", &ExceptionImpl::mask)
+ , who(this, "who", &ExceptionImpl::who)
+ , reason(this, "reason", &ExceptionImpl::reason)
+ , limit(this, "limit", &ExceptionImpl::limit)
+ , time(this, "time", &ExceptionImpl::time)
+ , expires(this, "expires", &ExceptionImpl::expires)
{
}
};
@@ -149,7 +153,7 @@ class MySessionService : public SessionService
Exception *FindException(User *u) override
{
- for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ for (Exception *e : Serialize::GetObjects<Exception *>())
{
if (Anope::Match(u->host, e->GetMask()) || Anope::Match(u->ip.addr(), e->GetMask()))
return e;
@@ -162,7 +166,7 @@ class MySessionService : public SessionService
Exception *FindException(const Anope::string &host) override
{
- for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ for (Exception *e : Serialize::GetObjects<Exception *>())
{
if (Anope::Match(host, e->GetMask()))
return e;
@@ -211,6 +215,8 @@ class MySessionService : public SessionService
class CommandOSSession : public Command
{
+ ServiceReference<SessionService> session_service;
+
private:
void DoList(CommandSource &source, const std::vector<Anope::string> &params)
{
@@ -319,7 +325,7 @@ class CommandOSException : public Command
{
static void DoDel(CommandSource &source, Exception *e)
{
- (*events)(&Event::Exception::OnExceptionDel, source, e);
+ EventManager::Get()->Dispatch(&Event::Exception::OnExceptionDel, source, e);
e->Delete();
}
@@ -382,7 +388,7 @@ class CommandOSException : public Command
return;
}
- for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ for (Exception *e : Serialize::GetObjects<Exception *>())
if (e->GetMask().equals_ci(mask))
{
if (e->GetLimit() != limit)
@@ -395,7 +401,7 @@ class CommandOSException : public Command
return;
}
- Exception *e = exception.Create();
+ Exception *e = Serialize::New<Exception *>();
e->SetMask(mask);
e->SetLimit(limit);
e->SetReason(reason);
@@ -404,7 +410,7 @@ class CommandOSException : public Command
e->SetExpires(expires);
EventReturn MOD_RESULT;
- MOD_RESULT = (*events)(&Event::Exception::OnExceptionAdd, e);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::Exception::OnExceptionAdd, e);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -432,7 +438,7 @@ class CommandOSException : public Command
NumberList(mask, true,
[&](unsigned int number)
{
- std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(exception);
+ std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>();
if (!number || number > exceptions.size())
return;
@@ -456,7 +462,7 @@ class CommandOSException : public Command
else
{
bool found = false;
- for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ for (Exception *e : Serialize::GetObjects<Exception *>())
if (mask.equals_ci(e->GetMask()))
{
Log(LOG_ADMIN, source, this) << "to remove the session limit exception for " << mask;
@@ -476,7 +482,7 @@ class CommandOSException : public Command
void ProcessList(CommandSource &source, const std::vector<Anope::string> &params, ListFormatter &list)
{
const Anope::string &mask = params.size() > 1 ? params[1] : "";
- std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(exception);
+ std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>();
if (exceptions.empty())
{
@@ -621,24 +627,20 @@ class OSSession : public Module
CommandOSSession commandossession;
CommandOSException commandosexception;
ServiceReference<XLineManager> akills;
- EventHandlers<Event::Exception> exceptionevents;
ExceptionType etype;
public:
OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , EventHook<Event::UserConnect>(EventHook<Event::UserConnect>::Priority::FIRST)
- , EventHook<Event::UserQuit>(EventHook<Event::UserQuit>::Priority::FIRST)
- , EventHook<Event::ExpireTick>(EventHook<Event::ExpireTick>::Priority::FIRST)
+ , EventHook<Event::UserConnect>(this, EventHook<Event::UserConnect>::Priority::FIRST)
+ , EventHook<Event::UserQuit>(this, EventHook<Event::UserQuit>::Priority::FIRST)
+ , EventHook<Event::ExpireTick>(this, EventHook<Event::ExpireTick>::Priority::FIRST)
, ss(this)
, commandossession(this)
, commandosexception(this)
- , akills("XLineManager", "xlinemanager/sgline")
- , exceptionevents(this)
+ , akills("xlinemanager/sgline")
, etype(this)
{
this->SetPermanent(true);
-
- events = &exceptionevents;
}
void OnReload(Configuration::Conf *conf) override
@@ -658,7 +660,7 @@ class OSSession : public Module
ipv6_cidr = block->Get<unsigned>("session_ipv6_cidr", "128");
if (ipv4_cidr > 32 || ipv6_cidr > 128)
- throw ConfigException(this->name + ": session CIDR value out of range");
+ throw ConfigException(Module::name + ": session CIDR value out of range");
}
void OnUserConnect(User *u, bool &exempt) override
@@ -708,9 +710,16 @@ class OSSession : public Module
const Anope::string &akillmask = "*@" + session->addr.mask();
if (max_session_kill && session->hits >= max_session_kill && akills && !akills->HasEntry(akillmask))
{
- XLine *x = new XLine(akillmask, OperServ ? OperServ->nick : "", Anope::CurTime + session_autokill_expiry, "Session limit exceeded", XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(akillmask);
+ x->SetBy(OperServ ? OperServ->nick : "");
+ x->SetExpires(Anope::CurTime + session_autokill_expiry);
+ x->SetReason("Session limit exceeded");
+ x->SetID(XLineManager::GenerateUID());
+
akills->AddXLine(x);
akills->Send(NULL, x);
+
Log(OperServ, "akill/session") << "Added a temporary AKILL for \002" << akillmask << "\002 due to excessive connections";
}
else
@@ -753,7 +762,7 @@ class OSSession : public Module
if (Anope::NoExpire)
return;
- for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ for (Exception *e : Serialize::GetObjects<Exception *>())
{
if (!e->GetExpires() || e->GetExpires() > Anope::CurTime)
continue;
diff --git a/modules/operserv/set.cpp b/modules/operserv/set.cpp
index 45515fa4b..432480ffb 100644
--- a/modules/operserv/set.cpp
+++ b/modules/operserv/set.cpp
@@ -74,7 +74,7 @@ class CommandOSSet : public Command
*
* Rob
**/
- bool super_admin = Config->GetModule(this->owner)->Get<bool>("superadmin");
+ bool super_admin = Config->GetModule(this->GetOwner())->Get<bool>("superadmin");
if (!super_admin)
source.Reply(_("Super admin can not be set because it is not enabled in the configuration."));
else if (setting.equals_ci("ON"))
diff --git a/modules/operserv/stats.cpp b/modules/operserv/stats.cpp
index 025fe566c..0fc5e9ae1 100644
--- a/modules/operserv/stats.cpp
+++ b/modules/operserv/stats.cpp
@@ -11,32 +11,58 @@
#include "module.h"
#include "modules/operserv/session.h"
+#include "modules/operserv/stats.h"
-#if 0
-struct Stats : Serialize::Object
+class StatsImpl : public Stats
{
- static Stats *me;
+ friend class StatsType;
- Stats() : Serialize::Object("Stats")
- {
- me = this;
- }
+ unsigned int maxusercnt = 0;
+ time_t maxusertime = 0;
- void Serialize(Serialize::Data &data) const override
- {
- data["maxusercnt"] << MaxUserCount;
- data["maxusertime"] << MaxUserTime;
- }
+ public:
+
+ using Stats::Stats;
+
+ unsigned int GetMaxUserCount();
+ void SetMaxUserCount(unsigned int i);
+
+ time_t GetMaxUserTime();
+ void SetMaxUserTime(time_t t);
+};
+
+class StatsType : public Serialize::Type<StatsImpl>
+{
+ public:
+ Serialize::Field<StatsImpl, unsigned int> maxusercount;
+ Serialize::Field<StatsImpl, time_t> maxusertime;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ StatsType(Module *me) : Serialize::Type<StatsImpl>(me)
+ , maxusercount(this, "maxusercount", &StatsImpl::maxusercnt)
+ , maxusertime(this, "maxusertime", &StatsImpl::maxusertime)
{
- data["maxusercnt"] >> MaxUserCount;
- data["maxusertime"] >> MaxUserTime;
- return me;
}
};
-Stats *Stats::me;
+unsigned int StatsImpl::GetMaxUserCount()
+{
+ return Get(&StatsType::maxusercount);
+}
+
+void StatsImpl::SetMaxUserCount(unsigned int i)
+{
+ Set(&StatsType::maxusercount, i);
+}
+
+time_t StatsImpl::GetMaxUserTime()
+{
+ return Get(&StatsType::maxusertime);
+}
+
+void StatsImpl::SetMaxUserTime(time_t t)
+{
+ Set(&StatsType::maxusertime, t);
+}
/**
* Count servers connected to server s
@@ -60,6 +86,8 @@ static int stats_count_servers(Server *s)
class CommandOSStats : public Command
{
ServiceReference<XLineManager> akills, snlines, sqlines;
+ ServiceReference<SessionService> session_service;
+
private:
void DoStatsAkill(CommandSource &source)
{
@@ -128,16 +156,19 @@ class CommandOSStats : public Command
void DoStatsReset(CommandSource &source)
{
- MaxUserCount = UserListByNick.size();
+ Stats *stats = Serialize::GetObject<Stats *>();
+ stats->SetMaxUserCount(UserListByNick.size());
source.Reply(_("Statistics reset."));
return;
}
void DoStatsUptime(CommandSource &source)
{
+ Stats *stats = Serialize::GetObject<Stats *>();
time_t uptime = Anope::CurTime - Anope::StartTime;
+
source.Reply(_("Current users: \002{0}\002 (\002{1}\002 ops)"), UserListByNick.size(), OperCount);
- source.Reply(_("Maximum users: \002{0}\002 ({1})"), MaxUserCount, Anope::strftime(MaxUserTime, source.GetAccount()));
+ source.Reply(_("Maximum users: \002{0}\002 ({1})"), stats->GetMaxUserCount(), Anope::strftime(stats->GetMaxUserTime(), source.GetAccount()));
source.Reply(_("Services up \002{0}\002."), Anope::Duration(uptime, source.GetAccount()));
}
@@ -195,8 +226,10 @@ class CommandOSStats : public Command
}
public:
- CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1),
- akills("XLineManager", "xlinemanager/sgline"), snlines("XLineManager", "xlinemanager/snline"), sqlines("XLineManager", "xlinemanager/sqline")
+ CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1)
+ , akills("sgline")
+ , snlines("snline")
+ , sqlines("sqline")
{
this->SetDesc(_("Show status of Services and network"));
this->SetSyntax("[AKILL | HASH | UPLINK | UPTIME | ALL | RESET]");
@@ -245,27 +278,42 @@ class CommandOSStats : public Command
};
class OSStats : public Module
+ , public EventHook<Event::UserConnect>
{
CommandOSStats commandosstats;
- //Serialize::TypeBase stats_type;
- Stats stats_saver;
+ StatsType stats_type;
+
+ Stats *GetStats()
+ {
+ Stats *stats = Serialize::GetObject<Stats *>();
+ if (stats)
+ return stats;
+ else
+ return Serialize::New<Stats *>();
+ }
public:
OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserConnect>(this)
, commandosstats(this)
-// , stats_type("Stats", Stats::Unserialize)
+ , stats_type(this)
{
-
}
-#if 0
void OnUserConnect(User *u, bool &exempt) override
{
- if (UserListByNick.size() == MaxUserCount && Anope::CurTime == MaxUserTime)
- stats_saver.QueueUpdate();
+ Stats *stats = GetStats();
+
+ if (stats && UserListByNick.size() > stats->GetMaxUserCount())
+ {
+ stats->SetMaxUserCount(UserListByNick.size());
+ stats->SetMaxUserTime(Anope::CurTime);
+
+ Server *sserver = u->server;
+ if (sserver && sserver->IsSynced())
+ Log(this, "maxusers") << "connected - new maximum user count: " << UserListByNick.size();
+ }
}
-#endif
};
MODULE_INIT(OSStats)
-#endif
diff --git a/modules/operserv/sxline.cpp b/modules/operserv/sxline.cpp
index 61c95bc45..c1be6ad5b 100644
--- a/modules/operserv/sxline.cpp
+++ b/modules/operserv/sxline.cpp
@@ -71,7 +71,7 @@ class CommandOSSXLineBase : public Command
return;
}
- Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, this->xlm());
+ EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, this->xlm());
x->Delete();
source.Reply(_("\002{0}\002 deleted from the {1} list."), mask, source.command);
@@ -118,7 +118,7 @@ class CommandOSSXLineBase : public Command
unsigned int i = 0;
for (XLine *x : this->xlm()->GetXLines())
{
- if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true))
+ if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->GetID() || Anope::Match(x->GetMask(), mask, false, true))
{
ListFormatter::ListEntry entry;
entry["Number"] = stringify(i + 1);
@@ -163,7 +163,7 @@ class CommandOSSXLineBase : public Command
void OnClear(CommandSource &source)
{
- Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, nullptr, this->xlm());
+ EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, nullptr, this->xlm());
for (XLine *x : this->xlm()->GetXLines())
x->Delete();
@@ -307,7 +307,12 @@ class CommandOSSNLine : public CommandOSSXLineBase
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(source.GetNick());
+ x->SetExpires(expires);
+ x->SetReason(reason);
+
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->SetID(XLineManager::GenerateUID());
@@ -326,7 +331,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm());
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, this->xlm());
if (MOD_RESULT == EVENT_STOP)
{
delete x;
@@ -358,7 +363,8 @@ class CommandOSSNLine : public CommandOSSXLineBase
ServiceReference<XLineManager> snlines;
public:
- CommandOSSNLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/snline"), snlines("XLineManager", "xlinemanager/snline")
+ CommandOSSNLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/snline")
+ , snlines("xlinemanager/snline")
{
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037:\037reason\037"));
this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}"));
@@ -512,7 +518,12 @@ class CommandOSSQLine : public CommandOSSXLineBase
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(source.GetNick());
+ x->SetExpires(expires);
+ x->SetReason(reason);
+
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->SetID(XLineManager::GenerateUID());
@@ -531,7 +542,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm());
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, this->xlm());
if (MOD_RESULT == EVENT_STOP)
{
delete x;
@@ -589,7 +600,8 @@ class CommandOSSQLine : public CommandOSSXLineBase
ServiceReference<XLineManager> sqlines;
public:
- CommandOSSQLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/sqline"), sqlines("XLineManager", "xlinemanager/sqline")
+ CommandOSSQLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/sqline")
+ , sqlines("xlinemanager/sqline")
{
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}"));
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index c320f3a3e..c7e5c45f1 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -192,24 +192,24 @@ class BahamutIRCdProto : public IRCDProto
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
+ if (x->GetManager()->Check(it->second, x))
this->SendAkill(it->second, x);
return;
}
XLine *old = x;
- if (old->manager->HasEntry("*@" + u->host))
+ if (old->GetManager()->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- x = new XLine(xline);
+ x = Serialize::New<XLine *>();
x->SetMask("*@" + u->host);
x->SetBy(old->GetBy());
x->SetExpires(old->GetExpires());
x->SetReason(old->GetReason());
x->SetID(old->GetID());
- old->manager->AddXLine(x);
+ old->GetManager()->AddXLine(x);
Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask();
}
@@ -509,6 +509,7 @@ class ProtoBahamut : public Module
public:
ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
+ , EventHook<Event::UserNickChange>(this)
, ircd_proto(this)
, message_away(this)
, message_capab(this)
diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp
index fc59a7214..c37e8aab0 100644
--- a/modules/protocol/charybdis.cpp
+++ b/modules/protocol/charybdis.cpp
@@ -176,7 +176,7 @@ struct IRCDMessageEncap : IRCDMessage
if (params[1] == "CERTFP")
{
u->fingerprint = params[2];
- Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u);
+ EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u);
}
/*
* Received: :42X ENCAP * SASL 42XAAAAAH * S PLAIN
diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp
index b5c524530..65ea4a565 100644
--- a/modules/protocol/hybrid.cpp
+++ b/modules/protocol/hybrid.cpp
@@ -149,7 +149,7 @@ class HybridProto : public IRCDProto
* Find users that match and ban them.
*/
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
+ if (x->GetManager()->Check(it->second, x))
this->SendAkill(it->second, x);
return;
@@ -157,13 +157,18 @@ class HybridProto : public IRCDProto
XLine *old = x;
- if (old->manager->HasEntry("*@" + u->host))
+ if (old->GetManager()->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- XLine *xl = new XLine("*@" + u->host, old->GetBy(), old->GetExpires(), old->GetReason(), old->id);
-
- old->manager->AddXLine(xl);
+ XLine *xl = Serialize::New<XLine *>();
+ xl->SetMask("*@" + u->host);
+ xl->SetBy(old->GetBy());
+ xl->SetExpires(old->GetExpires());
+ xl->SetReason(old->GetReason());
+ xl->SetID(old->GetID());
+
+ old->GetManager()->AddXLine(xl);
x = xl;
Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#"
@@ -277,14 +282,19 @@ class HybridProto : public IRCDProto
void SendSVSHold(const Anope::string &nick, time_t t) override
{
+#if 0
XLine x(nick, Me->GetName(), Anope::CurTime + t, "Being held for registered user");
this->SendSQLine(NULL, &x);
+#endif
}
+#warning "xline on stack"
void SendSVSHoldDel(const Anope::string &nick) override
{
+#if 0
XLine x(nick);
this->SendSQLineDel(&x);
+#endif
}
void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override
@@ -579,7 +589,7 @@ struct IRCDMessageCertFP: IRCDMessage
User *u = source.GetUser();
u->fingerprint = params[0];
- Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u);
+ EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u);
}
};
@@ -627,6 +637,7 @@ class ProtoHybrid : public Module
public:
ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
+ , EventHook<Event::UserNickChange>(this)
, ircd_proto(this)
, message_away(this)
, message_capab(this)
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index f4c8bcf37..ae9cc700f 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -174,19 +174,23 @@ class InspIRCd20Proto : public IRCDProto
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
+ if (x->GetManager()->Check(it->second, x))
this->SendAkill(it->second, x);
return;
}
XLine *old = x;
- if (old->manager->HasEntry("*@" + u->host))
+ if (old->GetManager()->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- x = new XLine("*@" + u->host, old->GetBy(), old->GetExpires(), old->GetReason(), old->GetID());
- old->manager->AddXLine(x);
+ x = Serialize::New<XLine *>();
+ x->SetMask("*@" + u->host);
+ x->SetBy(old->GetBy());
+ x->SetExpires(old->GetExpires());
+ x->SetReason(old->GetReason());
+ old->GetManager()->AddXLine(x);
Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask();
}
@@ -645,14 +649,14 @@ struct IRCDMessageCapab : Message::Capab
ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]);
if (cm == nullptr)
{
- Log(owner) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar;
+ Log(this->GetOwner()) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar;
continue;
}
char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast<ChannelModeStatus *>(cm))->symbol : 0;
if (symbol != modesymbol)
{
- Log(owner) << "Warning: Channel mode " << modename << " has a misconfigured status character";
+ Log(this->GetOwner()) << "Warning: Channel mode " << modename << " has a misconfigured status character";
continue;
}
}
@@ -676,7 +680,7 @@ struct IRCDMessageCapab : Message::Capab
UserMode *um = ModeManager::FindUserModeByChar(modechar[0]);
if (um == nullptr)
{
- Log(owner) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar;
+ Log(this->GetOwner()) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar;
continue;
}
}
@@ -992,7 +996,7 @@ struct IRCDMessageMetadata : IRCDMessage
{
u->fingerprint = data.substr(pos1, pos2 - pos1);
}
- Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u);
+ EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u);
}
}
// We deliberately ignore non-bursting servers to avoid pseudoserver fights
@@ -1246,6 +1250,8 @@ struct IRCDMessageTime : IRCDMessage
struct IRCDMessageUID : IRCDMessage
{
+ ServiceReference<SASL::Service> sasl;
+
IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
/*
@@ -1270,7 +1276,7 @@ struct IRCDMessageUID : IRCDMessage
modes += " " + params[i];
NickServ::Nick *na = NULL;
- if (SASL::sasl)
+ if (sasl)
for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
{
SASLUser &u = *it;
@@ -1302,6 +1308,7 @@ class ProtoInspIRCd20 : public Module
{
InspIRCd20Proto ircd_proto;
ExtensibleItem<bool> ssl;
+ ServiceReference<ModeLocks> mlocks;
/* Core message handlers */
Message::Away message_away;
@@ -1349,6 +1356,13 @@ class ProtoInspIRCd20 : public Module
public:
ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
+ , EventHook<Event::UserNickChange>(this)
+ , EventHook<Event::ChannelSync>(this)
+ , EventHook<Event::ChanRegistered>(this)
+ , EventHook<Event::DelChan>(this)
+ , EventHook<Event::MLockEvents>(this)
+ , EventHook<Event::SetChannelOption>(this)
+
, ircd_proto(this)
, ssl(this, "ssl")
, message_away(this)
@@ -1489,7 +1503,7 @@ class ProtoInspIRCd20 : public Module
EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) override
{
- if (cmd->name == "chanserv/topic" && ci->c)
+ if (cmd->GetName() == "chanserv/topic" && ci->c)
{
if (setting == "topiclock on")
SendChannelMetadata(ci->c, "topiclock", "1");
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp
index b80f600e3..271466a42 100644
--- a/modules/protocol/ngircd.cpp
+++ b/modules/protocol/ngircd.cpp
@@ -357,7 +357,7 @@ struct IRCDMessageMetadata : IRCDMessage
else if (params[1].equals_cs("certfp"))
{
u->fingerprint = params[2];
- Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u);
+ EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u);
}
else if (params[1].equals_cs("cloakhost"))
{
@@ -634,6 +634,7 @@ class ProtongIRCd : public Module
public:
ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
+ , EventHook<Event::UserNickChange>(this)
, ircd_proto(this)
, message_capab(this)
, message_error(this)
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp
index 027fa2a14..efa521377 100644
--- a/modules/protocol/plexus.cpp
+++ b/modules/protocol/plexus.cpp
@@ -13,12 +13,13 @@
static Anope::string UplinkSID;
-static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid");
-
class PlexusProto : public IRCDProto
{
+ ServiceReference<IRCDProto> hybrid; // XXX use moddeps + inheritance here
+
public:
PlexusProto(Module *creator) : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1")
+ , hybrid("hybrid")
{
DefaultPseudoclientModes = "+oiU";
CanSVSNick = true;
@@ -204,7 +205,7 @@ struct IRCDMessageEncap : IRCDMessage
if (u)
{
u->fingerprint = params[3];
- Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u);
+ EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u);
}
}
return;
@@ -366,8 +367,8 @@ class ProtoPlexus : public Module
m_hybrid = ModuleManager::FindModule("hybrid");
if (!m_hybrid)
throw ModuleException("Unable to find hybrid");
- if (!hybrid)
- throw ModuleException("No protocol interface for hybrid");
+// if (!hybrid)
+// throw ModuleException("No protocol interface for hybrid");
}
~ProtoPlexus()
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index 9e1ea0710..54f085a3e 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -13,12 +13,12 @@
static Anope::string UplinkSID;
-static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid");
-
class RatboxProto : public IRCDProto
{
+ ServiceReference<IRCDProto> hybrid; // XXX
public:
RatboxProto(Module *creator) : IRCDProto(creator, "Ratbox 3.0+")
+ , hybrid("hybrid")
{
DefaultPseudoclientModes = "+oiS";
CanSNLine = true;
@@ -282,8 +282,8 @@ class ProtoRatbox : public Module
m_hybrid = ModuleManager::FindModule("hybrid");
if (!m_hybrid)
throw ModuleException("Unable to find hybrid");
- if (!hybrid)
- throw ModuleException("No protocol interface for hybrid");
+// if (!hybrid)
+// throw ModuleException("No protocol interface for hybrid");
}
~ProtoRatbox()
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
index 3bb8ab93a..327f1c32e 100644
--- a/modules/protocol/unreal.cpp
+++ b/modules/protocol/unreal.cpp
@@ -12,6 +12,7 @@
#include "module.h"
#include "modules/chanserv/mode.h"
#include "modules/sasl.h"
+#include "modules/operserv/stats.h"
class UnrealIRCdProto : public IRCDProto
{
@@ -89,19 +90,25 @@ class UnrealIRCdProto : public IRCDProto
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
+ if (x->GetManager()->Check(it->second, x))
this->SendAkill(it->second, x);
return;
}
XLine *old = x;
- if (old->manager->HasEntry("*@" + u->host))
+ if (old->GetManager()->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- XLine *xl = new XLine("*@" + u->host, old->GetBy(), old->GetExpires(), old->GetReason(), old->GetID());
- old->manager->AddXLine(xl);
+ XLine *xl = Serialize::New<XLine *>();
+ xl->SetMask("*@" + u->host);
+ xl->SetBy(old->GetBy());
+ xl->SetExpires(old->GetExpires());
+ xl->SetReason(old->GetReason());
+ xl->SetID(old->GetID());
+
+ old->GetManager()->AddXLine(xl);
x = xl;
Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask();
@@ -693,7 +700,8 @@ struct IRCDMessageNetInfo : IRCDMessage
void Run(MessageSource &source, const std::vector<Anope::string> &params) override
{
- UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7];
+ Stats *stats = Serialize::GetObject<Stats *>();
+ UplinkSocket::Message() << "NETINFO " << (stats ? stats->GetMaxUserCount() : 0) << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7];
}
};
@@ -792,12 +800,14 @@ struct IRCDMessagePong : IRCDMessage
struct IRCDMessageSASL : IRCDMessage
{
+ ServiceReference<SASL::Service> sasl;
+
IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
void Run(MessageSource &source, const std::vector<Anope::string> &params) override
{
size_t p = params[1].find('!');
- if (!SASL::sasl || p == Anope::string::npos)
+ if (!sasl || p == Anope::string::npos)
return;
SASL::Message m;
@@ -807,7 +817,7 @@ struct IRCDMessageSASL : IRCDMessage
m.data = params[3];
m.ext = params.size() > 4 ? params[4] : "";
- SASL::sasl->ProcessMessage(m);
+ sasl->ProcessMessage(m);
}
};
@@ -1006,6 +1016,7 @@ class ProtoUnreal : public Module
, public EventHook<Event::MLockEvents>
{
UnrealIRCdProto ircd_proto;
+ ServiceReference<ModeLocks> mlocks;
/* Core message handlers */
Message::Away message_away;
@@ -1049,11 +1060,11 @@ class ProtoUnreal : public Module
public:
ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
- , EventHook<Event::UserNickChange>(EventHook<Event::UserNickChange>::Priority::FIRST)
- , EventHook<Event::ChannelSync>(EventHook<Event::ChannelSync>::Priority::FIRST)
- , EventHook<Event::ChanRegistered>(EventHook<Event::ChanRegistered>::Priority::FIRST)
- , EventHook<Event::DelChan>(EventHook<Event::DelChan>::Priority::FIRST)
- , EventHook<Event::MLockEvents>(EventHook<Event::MLockEvents>::Priority::FIRST)
+ , EventHook<Event::UserNickChange>(this, EventHook<Event::UserNickChange>::Priority::FIRST)
+ , EventHook<Event::ChannelSync>(this, EventHook<Event::ChannelSync>::Priority::FIRST)
+ , EventHook<Event::ChanRegistered>(this, EventHook<Event::ChanRegistered>::Priority::FIRST)
+ , EventHook<Event::DelChan>(this, EventHook<Event::DelChan>::Priority::FIRST)
+ , EventHook<Event::MLockEvents>(this, EventHook<Event::MLockEvents>::Priority::FIRST)
, ircd_proto(this)
, message_away(this)
, message_capab(this, "PROTOCTL")
diff --git a/modules/proxyscan.cpp b/modules/proxyscan.cpp
deleted file mode 100644
index 398e021db..000000000
--- a/modules/proxyscan.cpp
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * (C) 2003-2014 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- */
-
-#include "module.h"
-
-struct ProxyCheck
-{
- std::set<Anope::string, ci::less> types;
- std::vector<unsigned short> ports;
- time_t duration;
- Anope::string reason;
-};
-
-static Anope::string ProxyCheckString;
-static Anope::string target_ip;
-static unsigned short target_port;
-static bool add_to_akill;
-
-class ProxyCallbackListener : public ListenSocket
-{
- class ProxyCallbackClient : public ClientSocket, public BufferedSocket
- {
- public:
- ProxyCallbackClient(ListenSocket *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), ClientSocket(l, a), BufferedSocket()
- {
- }
-
- void OnAccept() override
- {
- this->Write(ProxyCheckString);
- }
-
- bool ProcessWrite() override
- {
- return !BufferedSocket::ProcessWrite() || this->write_buffer.empty() ? false : true;
- }
- };
-
- public:
- ProxyCallbackListener(const Anope::string &b, int p) : Socket(-1, b.find(':') != Anope::string::npos), ListenSocket(b, p, false)
- {
- }
-
- ClientSocket *OnAccept(int fd, const sockaddrs &addr) override
- {
- return new ProxyCallbackClient(this, fd, addr);
- }
-};
-
-class ProxyConnect : public ConnectionSocket
-{
- static ServiceReference<XLineManager> akills;
-
- public:
- static std::set<ProxyConnect *> proxies;
-
- ProxyCheck proxy;
- unsigned short port;
- time_t created;
-
- ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ConnectionSocket(), proxy(p),
- port(po), created(Anope::CurTime)
- {
- proxies.insert(this);
- }
-
- ~ProxyConnect()
- {
- proxies.erase(this);
- }
-
- virtual void OnConnect() override = 0;
- virtual const Anope::string GetType() const = 0;
-
- protected:
- void Ban()
- {
- Anope::string reason = this->proxy.reason;
-
- reason = reason.replace_all_cs("%t", this->GetType());
- reason = reason.replace_all_cs("%i", this->conaddr.addr());
- reason = reason.replace_all_cs("%p", stringify(this->conaddr.port()));
-
- ServiceBot *OperServ = Config->GetClient("OperServ");
- Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.addr() << ":" << this->conaddr.port() << " (" << reason << ")";
-
- XLine *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID());
- if (add_to_akill && akills)
- {
- akills->AddXLine(x);
- akills->Send(NULL, x);
- }
- else
- {
- if (IRCD->CanSZLine)
- IRCD->SendSZLine(NULL, x);
- else
- IRCD->SendAkill(NULL, x);
- delete x;
- }
- }
-};
-ServiceReference<XLineManager> ProxyConnect::akills("XLineManager", "xlinemanager/sgline");
-std::set<ProxyConnect *> ProxyConnect::proxies;
-
-class HTTPProxyConnect : public ProxyConnect, public BufferedSocket
-{
- public:
- HTTPProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BufferedSocket()
- {
- }
-
- void OnConnect() override
- {
- this->Write("CONNECT %s:%d HTTP/1.0", target_ip.c_str(), target_port);
- this->Write("Content-length: 0");
- this->Write("Connection: close");
- this->Write("");
- }
-
- const Anope::string GetType() const override
- {
- return "HTTP";
- }
-
- bool ProcessRead() override
- {
- bool b = BufferedSocket::ProcessRead();
- if (this->GetLine() == ProxyCheckString)
- {
- this->Ban();
- return false;
- }
- return b;
- }
-};
-
-class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket
-{
- public:
- SOCKS5ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BinarySocket()
- {
- }
-
- void OnConnect() override
- {
- sockaddrs target_addr;
- char buf[4 + sizeof(target_addr.sa4.sin_addr.s_addr) + sizeof(target_addr.sa4.sin_port)];
- int ptr = 0;
- target_addr.pton(AF_INET, target_ip, target_port);
- if (!target_addr.valid())
- return;
-
- buf[ptr++] = 5; // Version
- buf[ptr++] = 1; // # of methods
- buf[ptr++] = 0; // No authentication
-
- this->Write(buf, ptr);
-
- ptr = 1;
- buf[ptr++] = 1; // Connect
- buf[ptr++] = 0; // Reserved
- buf[ptr++] = 1; // IPv4
- memcpy(buf + ptr, &target_addr.sa4.sin_addr.s_addr, sizeof(target_addr.sa4.sin_addr.s_addr));
- ptr += sizeof(target_addr.sa4.sin_addr.s_addr);
- memcpy(buf + ptr, &target_addr.sa4.sin_port, sizeof(target_addr.sa4.sin_port));
- ptr += sizeof(target_addr.sa4.sin_port);
-
- this->Write(buf, ptr);
- }
-
- const Anope::string GetType() const override
- {
- return "SOCKS5";
- }
-
- bool Read(const char *buffer, size_t l) override
- {
- if (l >= ProxyCheckString.length() && !strncmp(buffer, ProxyCheckString.c_str(), ProxyCheckString.length()))
- {
- this->Ban();
- return false;
- }
- return true;
- }
-};
-
-class ModuleProxyScan : public Module
- , public EventHook<Event::UserConnect>
-{
- Anope::string listen_ip;
- unsigned short listen_port;
- Anope::string con_notice, con_source;
- std::vector<ProxyCheck> proxyscans;
-
- ProxyCallbackListener *listener;
-
- class ConnectionTimeout : public Timer
- {
- public:
- ConnectionTimeout(Module *c, long timeout) : Timer(c, timeout, Anope::CurTime, true)
- {
- }
-
- void Tick(time_t) override
- {
- for (std::set<ProxyConnect *>::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;)
- {
- ProxyConnect *p = *it;
- ++it;
-
- if (p->created + this->GetSecs() < Anope::CurTime)
- delete p;
- }
- }
- } connectionTimeout;
-
- public:
- ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
- , connectionTimeout(this, 5)
- {
-
-
- this->listener = NULL;
- }
-
- ~ModuleProxyScan()
- {
- for (std::set<ProxyConnect *>::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;)
- {
- ProxyConnect *p = *it;
- ++it;
- delete p;
- }
-
- for (std::map<int, Socket *>::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;)
- {
- Socket *s = it->second;
- ++it;
-
- ClientSocket *cs = dynamic_cast<ClientSocket *>(s);
- if (cs != NULL && cs->ls == this->listener)
- delete s;
- }
-
- delete this->listener;
- }
-
- void OnReload(Configuration::Conf *conf) override
- {
- Configuration::Block *config = Config->GetModule(this);
-
- Anope::string s_target_ip = config->Get<Anope::string>("target_ip");
- if (s_target_ip.empty())
- throw ConfigException(this->name + " target_ip may not be empty");
-
- int s_target_port = config->Get<int>("target_port", "-1");
- if (s_target_port <= 0)
- throw ConfigException(this->name + " target_port may not be empty and must be a positive number");
-
- Anope::string s_listen_ip = config->Get<Anope::string>("listen_ip");
- if (s_listen_ip.empty())
- throw ConfigException(this->name + " listen_ip may not be empty");
-
- int s_listen_port = config->Get<int>("listen_port", "-1");
- if (s_listen_port <= 0)
- throw ConfigException(this->name + " listen_port may not be empty and must be a positive number");
-
- target_ip = s_target_ip;
- target_port = s_target_port;
- this->listen_ip = s_listen_ip;
- this->listen_port = s_listen_port;
- this->con_notice = config->Get<Anope::string>("connect_notice");
- this->con_source = config->Get<Anope::string>("connect_source");
- add_to_akill = config->Get<bool>("add_to_akill", "true");
- this->connectionTimeout.SetSecs(config->Get<time_t>("timeout", "5s"));
-
- ProxyCheckString = Config->GetBlock("networkinfo")->Get<Anope::string>("networkname") + " proxy check";
- delete this->listener;
- this->listener = NULL;
- try
- {
- this->listener = new ProxyCallbackListener(this->listen_ip, this->listen_port);
- }
- catch (const SocketException &ex)
- {
- throw ConfigException("m_proxyscan: " + ex.GetReason());
- }
-
- this->proxyscans.clear();
- for (int i = 0; i < config->CountBlock("proxyscan"); ++i)
- {
- Configuration::Block *block = config->GetBlock("proxyscan", i);
- ProxyCheck p;
- Anope::string token;
-
- commasepstream sep(block->Get<Anope::string>("type"));
- while (sep.GetToken(token))
- {
- if (!token.equals_ci("HTTP") && !token.equals_ci("SOCKS5"))
- continue;
- p.types.insert(token);
- }
- if (p.types.empty())
- continue;
-
- commasepstream sep2(block->Get<Anope::string>("port"));
- while (sep2.GetToken(token))
- {
- try
- {
- unsigned short port = convertTo<unsigned short>(token);
- p.ports.push_back(port);
- }
- catch (const ConvertException &) { }
- }
- if (p.ports.empty())
- continue;
-
- p.duration = block->Get<time_t>("time", "4h");
- p.reason = block->Get<Anope::string>("reason");
- if (p.reason.empty())
- continue;
-
- this->proxyscans.push_back(p);
- }
- }
-
- void OnUserConnect(User *user, bool &exempt) override
- {
- if (exempt || user->Quitting() || !Me->IsSynced() || !user->server->IsSynced())
- return;
-
- /* At this time we only support IPv4 */
- if (!user->ip.valid() || user->ip.sa.sa_family != AF_INET)
- /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */
- return;
-
- if (!this->con_notice.empty() && !this->con_source.empty())
- {
- ServiceBot *bi = ServiceBot::Find(this->con_source, true);
- if (bi)
- user->SendMessage(bi, this->con_notice);
- }
-
- for (unsigned i = this->proxyscans.size(); i > 0; --i)
- {
- ProxyCheck &p = this->proxyscans[i - 1];
-
- for (std::set<Anope::string, ci::less>::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it)
- {
- for (unsigned k = 0; k < p.ports.size(); ++k)
- {
- try
- {
- ProxyConnect *con = NULL;
- if (it->equals_ci("HTTP"))
- con = new HTTPProxyConnect(p, p.ports[k]);
- else if (it->equals_ci("SOCKS5"))
- con = new SOCKS5ProxyConnect(p, p.ports[k]);
- else
- continue;
- con->Connect(user->ip.addr(), p.ports[k]);
- }
- catch (const SocketException &ex)
- {
- Log(LOG_DEBUG) << "m_proxyscan: " << ex.GetReason();
- }
- }
- }
- }
- }
-};
-
-MODULE_INIT(ModuleProxyScan)
-
diff --git a/modules/redis.cpp b/modules/redis.cpp
index 81c958f7c..14da3cae5 100644
--- a/modules/redis.cpp
+++ b/modules/redis.cpp
@@ -265,7 +265,7 @@ RedisSocket::~RedisSocket()
void RedisSocket::OnConnect()
{
- Log() << "redis: Successfully connected to " << provider->name << (this == this->provider->sub ? " (sub)" : "");
+ Log() << "redis: Successfully connected to " << provider->GetName() << (this == this->provider->sub ? " (sub)" : "");
this->provider->SendCommand(NULL, "CLIENT SETNAME Anope");
this->provider->SendCommand(NULL, "SELECT " + stringify(provider->db));
@@ -273,7 +273,7 @@ void RedisSocket::OnConnect()
void RedisSocket::OnError(const Anope::string &error)
{
- Log() << "redis: Error on " << provider->name << (this == this->provider->sub ? " (sub)" : "") << ": " << error;
+ Log() << "redis: Error on " << provider->GetName() << (this == this->provider->sub ? " (sub)" : "") << ": " << error;
}
size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
@@ -504,6 +504,7 @@ class ModuleRedis : public Module
public:
ModuleRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
+ , EventHook<Event::ModuleUnload>(this)
{
}
@@ -546,7 +547,7 @@ class ModuleRedis : public Module
Provider *p = it->second;
++it;
- if (std::find(new_services.begin(), new_services.end(), p->name) == new_services.end())
+ if (std::find(new_services.begin(), new_services.end(), p->GetName()) == new_services.end())
delete it->second;
}
}
diff --git a/modules/sasl.cpp b/modules/sasl.cpp
index 174e86ab0..6fe68ce3e 100644
--- a/modules/sasl.cpp
+++ b/modules/sasl.cpp
@@ -15,13 +15,13 @@ using namespace SASL;
class Plain : public Mechanism
{
public:
- Plain(Module *o) : Mechanism(o, "PLAIN") { }
+ Plain(SASL::Service *s, Module *o) : Mechanism(s, o, "PLAIN") { }
void ProcessMessage(Session *sess, const SASL::Message &m) override
{
if (m.type == "S")
{
- sasl->SendMessage(sess, "C", "+");
+ GetService()->SendMessage(sess, "C", "+");
}
else if (m.type == "C")
{
@@ -31,7 +31,7 @@ class Plain : public Mechanism
size_t p = decoded.find('\0');
if (p == Anope::string::npos)
{
- sasl->Fail(sess);
+ GetService()->Fail(sess);
delete sess;
return;
}
@@ -40,7 +40,7 @@ class Plain : public Mechanism
p = decoded.find('\0');
if (p == Anope::string::npos)
{
- sasl->Fail(sess);
+ GetService()->Fail(sess);
delete sess;
return;
}
@@ -50,13 +50,13 @@ class Plain : public Mechanism
if (!NickServ::service || acc.empty() || pass.empty() || !IRCD->IsNickValid(acc) || pass.find_first_of("\r\n") != Anope::string::npos)
{
- sasl->Fail(sess);
+ GetService()->Fail(sess);
delete sess;
return;
}
- NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new IdentifyRequestListener(m.source), this->owner, acc, pass);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
+ NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new IdentifyRequestListener(GetService(), m.source), this->GetOwner(), acc, pass);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
req->Dispatch();
}
}
@@ -70,11 +70,12 @@ class External : public Mechanism
{
Anope::string cert;
- Session(Mechanism *m, const Anope::string &u) : SASL::Session(m, u) { }
+ Session(SASL::Service *s, Mechanism *m, const Anope::string &u) : SASL::Session(s, m, u) { }
};
public:
- External(Module *o) : Mechanism(o, "EXTERNAL"), certs("CertService", "certs")
+ External(SASL::Service *s, Module *o) : Mechanism(s, o, "EXTERNAL")
+ , certs("certs")
{
if (!IRCD || !IRCD->CanCertFP)
throw ModuleException("No CertFP");
@@ -82,7 +83,7 @@ class External : public Mechanism
Session* CreateSession(const Anope::string &uid) override
{
- return new Session(this, uid);
+ return new Session(this->GetService(), this, uid);
}
void ProcessMessage(SASL::Session *sess, const SASL::Message &m) override
@@ -93,13 +94,13 @@ class External : public Mechanism
{
mysess->cert = m.ext;
- sasl->SendMessage(sess, "C", "+");
+ GetService()->SendMessage(sess, "C", "+");
}
else if (m.type == "C")
{
if (!certs)
{
- sasl->Fail(sess);
+ GetService()->Fail(sess);
delete sess;
return;
}
@@ -107,13 +108,13 @@ class External : public Mechanism
NickServ::Account *nc = certs->FindAccountFromCert(mysess->cert);
if (!nc || nc->HasFieldS("NS_SUSPENDED"))
{
- sasl->Fail(sess);
+ GetService()->Fail(sess);
delete sess;
return;
}
Log(Config->GetClient("NickServ")) << "A user identified to account " << nc->GetDisplay() << " using SASL EXTERNAL";
- sasl->Succeed(sess, nc);
+ GetService()->Succeed(sess, nc);
delete sess;
}
}
@@ -149,13 +150,13 @@ class SASLService : public SASL::Service, public Timer
if (m.type == "S")
{
- ServiceReference<Mechanism> mech("SASL::Mechanism", m.data);
+ ServiceReference<Mechanism> mech(m.data);
if (!mech)
{
- Session tmp(NULL, m.source);
+ Session tmp(this, NULL, m.source);
- sasl->SendMechs(&tmp);
- sasl->Fail(&tmp);
+ this->SendMechs(&tmp);
+ this->Fail(&tmp);
return;
}
@@ -175,7 +176,7 @@ class SASLService : public SASL::Service, public Timer
Anope::string GetAgent() override
{
- Anope::string agent = Config->GetModule(Service::owner)->Get<Anope::string>("agent", "NickServ");
+ Anope::string agent = Config->GetModule(Service::GetOwner())->Get<Anope::string>("agent", "NickServ");
ServiceBot *bi = Config->GetClient(agent);
if (bi)
agent = bi->GetUID();
@@ -233,10 +234,11 @@ class SASLService : public SASL::Service, public Timer
void SendMechs(Session *session) override
{
- std::vector<Anope::string> mechs = Service::GetServiceKeys("SASL::Mechanism");
+ std::vector<Mechanism *> mechs = ServiceManager::Get()->FindServices<Mechanism *>();
+
Anope::string buf;
for (unsigned j = 0; j < mechs.size(); ++j)
- buf += "," + mechs[j];
+ buf += "," + mechs[j]->GetName();
this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1));
}
@@ -258,22 +260,55 @@ class SASLService : public SASL::Service, public Timer
}
};
+void IdentifyRequestListener::OnSuccess(NickServ::IdentifyRequest *req)
+{
+ NickServ::Nick *na = NickServ::FindNick(req->GetAccount());
+ if (!na || na->GetAccount()->HasFieldS("NS_SUSPENDED"))
+ return OnFail(req);
+
+ Session *s = service->GetSession(uid);
+ if (s)
+ {
+ Log(Config->GetClient("NickServ")) << "A user identified to account " << req->GetAccount() << " using SASL";
+ service->Succeed(s, na->GetAccount());
+ delete s;
+ }
+}
+
+void IdentifyRequestListener::OnFail(NickServ::IdentifyRequest *req)
+{
+ Session *s = service->GetSession(uid);
+ if (s)
+ {
+ service->Fail(s);
+ delete s;
+ }
+
+ Anope::string accountstatus;
+ NickServ::Nick *na = NickServ::FindNick(req->GetAccount());
+ if (!na)
+ accountstatus = "nonexistent ";
+ else if (na->GetAccount()->HasFieldS("NS_SUSPENDED"))
+ accountstatus = "suspended ";
+
+ Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << req->GetAccount() << " using SASL";
+}
+
class ModuleSASL : public Module
{
SASLService sasl;
Plain plain;
- External *external;
+ External *external = nullptr;
public:
ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
, sasl(this)
- , plain(this)
- , external(NULL)
+ , plain(&sasl, this)
{
try
{
- external = new External(this);
+ external = new External(&sasl, this);
}
catch (ModuleException &) { }
}
diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp
index e5d268dee..535df595f 100644
--- a/modules/webcpanel/pages/chanserv/access.cpp
+++ b/modules/webcpanel/pages/chanserv/access.cpp
@@ -105,11 +105,11 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
replacements["CREATORS"] = HTTPUtils::Escape(access->GetCreator());
}
- if (Service::FindService("Command", "chanserv/access"))
+ if (ServiceManager::Get()->FindService("Command", "chanserv/access"))
replacements["PROVIDERS"] = "chanserv/access";
- if (Service::FindService("Command", "chanserv/xop"))
+ if (ServiceManager::Get()->FindService("Command", "chanserv/xop"))
replacements["PROVIDERS"] = "chanserv/xop";
- if (Service::FindService("Command", "chanserv/flags"))
+ if (ServiceManager::Get()->FindService("Command", "chanserv/flags"))
replacements["PROVIDERS"] = "chanserv/flags";
Page.Serve(server, page_name, client, message, reply, replacements);
diff --git a/modules/webcpanel/pages/chanserv/drop.cpp b/modules/webcpanel/pages/chanserv/drop.cpp
index c546c0af5..b4eea6641 100644
--- a/modules/webcpanel/pages/chanserv/drop.cpp
+++ b/modules/webcpanel/pages/chanserv/drop.cpp
@@ -31,7 +31,7 @@ bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::str
replacements["MESSAGES"] = "Invalid Confirmation";
}
- for (::ChanServ::Channel *ci : na->GetAccount()->GetRefs<::ChanServ::Channel *>(::ChanServ::channel))
+ for (::ChanServ::Channel *ci : na->GetAccount()->GetRefs<::ChanServ::Channel *>())
if ((ci->HasFieldS("SECUREFOUNDER") ? ci->AccessFor(na->GetAccount()).founder : ci->AccessFor(na->GetAccount()).HasPriv("FOUNDER")) || (na->GetAccount()->IsServicesOper() && na->GetAccount()->o->GetType()->HasCommand("chanserv/drop")))
{
replacements["CHANNEL_NAMES"] = ci->GetName();
diff --git a/modules/webcpanel/pages/chanserv/utils.cpp b/modules/webcpanel/pages/chanserv/utils.cpp
index cf00de9d0..746097881 100644
--- a/modules/webcpanel/pages/chanserv/utils.cpp
+++ b/modules/webcpanel/pages/chanserv/utils.cpp
@@ -23,7 +23,7 @@ namespace ChanServ
void BuildChanList(::NickServ::Nick *na, TemplateFileServer::Replacements &replacements)
{
- std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>(::ChanServ::channel);
+ std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>();
std::sort(chans.begin(), chans.end(), ChannelSort);
for (::ChanServ::Channel *ci : chans)
diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp
index 522806a9f..5ff2d228f 100644
--- a/modules/webcpanel/pages/hostserv/request.cpp
+++ b/modules/webcpanel/pages/hostserv/request.cpp
@@ -28,7 +28,7 @@ bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope::
else
replacements["VHOST"] = na->GetVhostHost();
}
- if (ServiceReference<Command>("Command", "hostserv/request"))
+ if (ServiceReference<Command>("hostserv/request"))
replacements["CAN_REQUEST"] = "YES";
TemplateFileServer page("hostserv/request.html");
page.Serve(server, page_name, client, message, reply, replacements);
diff --git a/modules/webcpanel/pages/index.cpp b/modules/webcpanel/pages/index.cpp
index 551b73a0e..f40b029b4 100644
--- a/modules/webcpanel/pages/index.cpp
+++ b/modules/webcpanel/pages/index.cpp
@@ -94,7 +94,7 @@ bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page
// XXX Rate limit check.
::NickServ::IdentifyRequest *req = ::NickServ::service->CreateIdentifyRequest(new WebpanelRequest(reply, message, server, page_name, client, replacements), me, user, pass);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
req->Dispatch();
return false;
}
diff --git a/modules/webcpanel/pages/logout.cpp b/modules/webcpanel/pages/logout.cpp
index b5f97258e..648b277cc 100644
--- a/modules/webcpanel/pages/logout.cpp
+++ b/modules/webcpanel/pages/logout.cpp
@@ -13,8 +13,8 @@ WebCPanel::Logout::Logout(const Anope::string &u) : WebPanelProtectedPage("", u)
bool WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements)
{
- na->ShrinkOK<Anope::string>("webcpanel_id");
- na->ShrinkOK<Anope::string>("webcpanel_ip");
+ na->Shrink<Anope::string>("webcpanel_id");
+ na->Shrink<Anope::string>("webcpanel_ip");
reply.error = HTTP_FOUND;
reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/";
diff --git a/modules/webcpanel/pages/nickserv/access.cpp b/modules/webcpanel/pages/nickserv/access.cpp
index 51472058d..986dfb635 100644
--- a/modules/webcpanel/pages/nickserv/access.cpp
+++ b/modules/webcpanel/pages/nickserv/access.cpp
@@ -31,7 +31,7 @@ bool WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::s
WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "NickServ", "nickserv/access", params, replacements);
}
- for (NickAccess *a : na->GetAccount()->GetRefs<NickAccess *>(nsaccess))
+ for (NickAccess *a : na->GetAccount()->GetRefs<NickAccess *>())
replacements["ACCESS"] = a->GetMask();
TemplateFileServer page("nickserv/access.html");
diff --git a/modules/webcpanel/pages/nickserv/alist.cpp b/modules/webcpanel/pages/nickserv/alist.cpp
index 105f1c117..26e4b6ffb 100644
--- a/modules/webcpanel/pages/nickserv/alist.cpp
+++ b/modules/webcpanel/pages/nickserv/alist.cpp
@@ -18,7 +18,7 @@ WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string
bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements)
{
- std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>(::ChanServ::channel);
+ std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>();
std::sort(chans.begin(), chans.end(), ChannelSort);
int chan_count = 0;
diff --git a/modules/webcpanel/pages/nickserv/cert.cpp b/modules/webcpanel/pages/nickserv/cert.cpp
index 436725b04..cdf23a1b3 100644
--- a/modules/webcpanel/pages/nickserv/cert.cpp
+++ b/modules/webcpanel/pages/nickserv/cert.cpp
@@ -1,8 +1,9 @@
/*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
+ *
*/
#include "../../webcpanel.h"
@@ -31,7 +32,7 @@ bool WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::str
WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "NickServ", "nickserv/cert", params, replacements);
}
- std::vector<NSCertEntry *> cl = na->GetAccount()->GetRefs<NSCertEntry *>(certentry);
+ std::vector<NSCertEntry *> cl = na->GetAccount()->GetRefs<NSCertEntry *>();
for (NSCertEntry *e : cl)
replacements["CERTS"] = e->GetCert();
diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp
index b3c743ed3..efbf1a425 100644
--- a/modules/webcpanel/pages/nickserv/info.cpp
+++ b/modules/webcpanel/pages/nickserv/info.cpp
@@ -34,7 +34,7 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str
const Anope::string &post_greet = HTTPUtils::URLDecode(message.post_data["greet"].replace_all_cs("+", " "));
if (post_greet.empty())
- na->GetAccount()->ShrinkOK<Anope::string>("greet");
+ na->GetAccount()->Shrink<Anope::string>("greet");
else if (!greet || post_greet != *greet)
na->GetAccount()->Extend<Anope::string>("greet", post_greet);
diff --git a/modules/webcpanel/pages/operserv/akill.cpp b/modules/webcpanel/pages/operserv/akill.cpp
index 58b68b0b2..950ed2bd9 100644
--- a/modules/webcpanel/pages/operserv/akill.cpp
+++ b/modules/webcpanel/pages/operserv/akill.cpp
@@ -7,15 +7,12 @@
#include "../../webcpanel.h"
-WebCPanel::OperServ::Akill::Akill(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+WebCPanel::OperServ::Akill::Akill(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u), akills("xlinemanager/sgline")
{
}
bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements)
{
-
- static ServiceReference<XLineManager> akills("XLineManager","xlinemanager/sgline");
-
if (!na->GetAccount()->o || !na->GetAccount()->o->GetType()->HasCommand("operserv/akill"))
{
replacements["NOACCESS"];
diff --git a/modules/webcpanel/pages/operserv/akill.h b/modules/webcpanel/pages/operserv/akill.h
index 7367f593f..5ad75eaeb 100644
--- a/modules/webcpanel/pages/operserv/akill.h
+++ b/modules/webcpanel/pages/operserv/akill.h
@@ -13,6 +13,8 @@ namespace OperServ
class Akill : public WebPanelProtectedPage
{
+ ServiceReference<XLineManager> akills;
+
public:
Akill(const Anope::string &cat, const Anope::string &u);
diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp
index 5da56a6d4..14889c97d 100644
--- a/modules/webcpanel/webcpanel.cpp
+++ b/modules/webcpanel/webcpanel.cpp
@@ -78,7 +78,7 @@ class ModuleWebCPanel : public Module
template_base = Anope::DataDir + "/modules/webcpanel/templates/" + template_name;
page_title = block->Get<Anope::string>("title", "Anope IRC Services");
- provider = ServiceReference<HTTPProvider>("HTTPProvider", provider_name);
+ provider = ServiceReference<HTTPProvider>(provider_name);
if (!provider)
throw ModuleException("Unable to find HTTPD provider. Is m_httpd loaded?");
@@ -250,7 +250,7 @@ namespace WebPanel
{
void RunCommand(const Anope::string &user, NickServ::Account *nc, const Anope::string &service, const Anope::string &c, std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key)
{
- ServiceReference<Command> cmd("Command", c);
+ ServiceReference<Command> cmd(c);
if (!cmd)
{
r[key] = "Unable to find command " + c;
@@ -286,7 +286,7 @@ namespace WebPanel
void RunCommandWithName(NickServ::Account *nc, const Anope::string &service, const Anope::string &c, const Anope::string &cmdname, std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key)
{
- ServiceReference<Command> cmd("Command", c);
+ ServiceReference<Command> cmd(c);
if (!cmd)
{
r[key] = "Unable to find command " + c;
diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h
index 8e77b975a..23350ae32 100644
--- a/modules/webcpanel/webcpanel.h
+++ b/modules/webcpanel/webcpanel.h
@@ -31,7 +31,9 @@ struct Section
class Panel : public Section, public Service
{
public:
- Panel(Module *c, const Anope::string &n) : Service(c, "Panel", n) { }
+ static constexpr const char *NAME = "panel";
+
+ Panel(Module *c, const Anope::string &n) : Service(c, NAME, "") { }
std::vector<Section> sections;
@@ -74,6 +76,7 @@ class WebPanelPage : public HTTPPage
class WebPanelProtectedPage : public WebPanelPage
{
Anope::string category;
+ ServiceReference<Panel> panel;
public:
WebPanelProtectedPage(const Anope::string &cat, const Anope::string &u, const Anope::string &ct = "text/html") : WebPanelPage(u, ct), category(cat)
@@ -82,7 +85,6 @@ class WebPanelProtectedPage : public WebPanelPage
bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) override final
{
- ServiceReference<Panel> panel("Panel", "webcpanel");
NickServ::Nick *na;
if (!panel || !(na = panel->GetNickFromSession(client, message)))
diff --git a/modules/xmlrpc.cpp b/modules/xmlrpc.cpp
index 4dbfa0497..928929904 100644
--- a/modules/xmlrpc.cpp
+++ b/modules/xmlrpc.cpp
@@ -191,6 +191,7 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage
class ModuleXMLRPC : public Module
{
ServiceReference<HTTPProvider> httpref;
+
public:
MyXMLRPCServiceInterface xmlrpcinterface;
@@ -210,9 +211,12 @@ class ModuleXMLRPC : public Module
{
if (httpref)
httpref->UnregisterPage(&xmlrpcinterface);
- this->httpref = ServiceReference<HTTPProvider>("HTTPProvider", conf->GetModule(this)->Get<Anope::string>("server", "httpd/main"));
+
+ this->httpref = ServiceReference<HTTPProvider>(conf->GetModule(this)->Get<Anope::string>("server", "httpd/main"));
+
if (!httpref)
throw ConfigException("Unable to find http reference, is m_httpd loaded?");
+
httpref->RegisterPage(&xmlrpcinterface);
}
};
diff --git a/modules/xmlrpc_main.cpp b/modules/xmlrpc_main.cpp
index af0253028..a812b1fba 100644
--- a/modules/xmlrpc_main.cpp
+++ b/modules/xmlrpc_main.cpp
@@ -1,5 +1,6 @@
#include "module.h"
#include "modules/xmlrpc.h"
+#include "modules/operserv/stats.h"
static Module *me;
@@ -117,7 +118,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
else
{
NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new XMLRPCIdentifyRequest(request, client, iface), me, username, password);
- Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
+ EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
req->Dispatch();
return false;
}
@@ -127,6 +128,8 @@ class MyXMLRPCEvent : public XMLRPCEvent
void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
+ Stats *stats = Serialize::GetObject<Stats *>();
+
request.reply("uptime", stringify(Anope::CurTime - Anope::StartTime));
request.reply("uplinkname", Me->GetLinks().front()->GetName());
{
@@ -138,7 +141,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
request.reply("uplinkcapab", buf);
}
request.reply("usercount", stringify(UserListByNick.size()));
- request.reply("maxusercount", stringify(MaxUserCount));
+ request.reply("maxusercount", stringify(stats ? stats->GetMaxUserCount() : 0));
request.reply("channelcount", stringify(ChannelList.size()));
}
@@ -258,7 +261,7 @@ class ModuleXMLRPCMain : public Module
MyXMLRPCEvent stats;
public:
- ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpc("XMLRPCServiceInterface", "xmlrpc")
+ ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
{
me = this;
diff --git a/src/accessgroup.cpp b/src/accessgroup.cpp
new file mode 100644
index 000000000..0d2f7bbe0
--- /dev/null
+++ b/src/accessgroup.cpp
@@ -0,0 +1,106 @@
+#include "modules/chanserv.h"
+#include "accessgroup.h"
+
+using namespace ChanServ;
+
+bool AccessGroup::HasPriv(const Anope::string &priv)
+{
+ if (this->super_admin)
+ return true;
+ else if (!ci || ci->GetLevel(priv) == ACCESS_INVALID)
+ return false;
+
+ /* Privileges prefixed with auto are understood to be given
+ * automatically. Sometimes founders want to not automatically
+ * obtain privileges, so we will let them */
+ bool auto_mode = !priv.find("AUTO");
+
+ /* Only grant founder privilege if this isn't an auto mode or if they don't match any entries in this group */
+ if ((!auto_mode || this->empty()) && this->founder)
+ return true;
+
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&::Event::GroupCheckPriv::OnGroupCheckPriv, this, priv);
+ if (MOD_RESULT != EVENT_CONTINUE)
+ return MOD_RESULT == EVENT_ALLOW;
+
+ for (unsigned i = this->size(); i > 0; --i)
+ {
+ ChanAccess *access = this->at(i - 1);
+
+ if (access->HasPriv(priv))
+ return true;
+ }
+
+ return false;
+}
+
+ChanAccess *AccessGroup::Highest()
+{
+ ChanAccess *highest = NULL;
+ for (unsigned i = 0; i < this->size(); ++i)
+ if (highest == NULL || *this->at(i) > *highest)
+ highest = this->at(i);
+ return highest;
+}
+
+bool AccessGroup::operator>(AccessGroup &other)
+{
+ if (other.super_admin)
+ return false;
+ else if (this->super_admin)
+ return true;
+ else if (other.founder)
+ return false;
+ else if (this->founder)
+ return true;
+
+ const std::vector<Privilege> &privs = service->GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ {
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
+
+ if (!this_p && !other_p)
+ continue;
+
+ return this_p && !other_p;
+ }
+
+ return false;
+}
+
+bool AccessGroup::operator<(AccessGroup &other)
+{
+ if (this->super_admin)
+ return false;
+ else if (other.super_admin)
+ return true;
+ else if (this->founder)
+ return false;
+ else if (other.founder)
+ return true;
+
+ const std::vector<Privilege> &privs = service->GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ {
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
+
+ if (!this_p && !other_p)
+ continue;
+
+ return !this_p && other_p;
+ }
+
+ return false;
+}
+
+bool AccessGroup::operator>=(AccessGroup &other)
+{
+ return !(*this < other);
+}
+
+bool AccessGroup::operator<=(AccessGroup &other)
+{
+ return !(*this > other);
+} \ No newline at end of file
diff --git a/src/base.cpp b/src/base.cpp
index 0fcd868bc..61dcbdf60 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -10,9 +10,8 @@
#include "services.h"
#include "anope.h"
#include "service.h"
+#include "base.h"
-std::map<Anope::string, std::map<Anope::string, Service *> > *Service::Services = NULL;
-std::map<Anope::string, std::map<Anope::string, Anope::string> > *Service::Aliases = NULL;
std::set<ReferenceBase *> *ReferenceBase::references = NULL;
ReferenceBase::ReferenceBase()
diff --git a/src/bots.cpp b/src/bots.cpp
index f934676bb..6091756f7 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -26,7 +26,7 @@ ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, c
this->lastmsg = Anope::CurTime;
this->introduced = false;
- bi = botinfo.Create();
+ bi = Serialize::New<BotInfo *>();
bi->bot = this;
bi->SetNick(nnick);
@@ -35,7 +35,7 @@ ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, c
bi->SetRealName(nreal);
bi->SetCreated(Anope::CurTime);
- Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this);
+ EventManager::Get()->Dispatch(&Event::CreateBot::OnCreateBot, this);
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
@@ -57,13 +57,13 @@ ServiceBot::~ServiceBot()
bi->bot = nullptr;
bi->Delete();
- Event::OnDelBot(&Event::DelBot::OnDelBot, this);
+ EventManager::Get()->Dispatch(&Event::DelBot::OnDelBot, this);
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
{
IRCD->SendQuit(this, "");
- Event::OnUserQuit(&Event::UserQuit::OnUserQuit, this, "");
+ EventManager::Get()->Dispatch(&Event::UserQuit::OnUserQuit, this, "");
this->introduced = false;
// XXX ?
//XLine x(this->nick);
@@ -106,13 +106,13 @@ void ServiceBot::SetNewNick(const Anope::string &newnick)
std::vector<ChanServ::Channel *> ServiceBot::GetChannels() const
{
- return bi->GetRefs<ChanServ::Channel *>(ChanServ::channel);
+ return bi->GetRefs<ChanServ::Channel *>();
}
void ServiceBot::Assign(User *u, ChanServ::Channel *ci)
{
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreBotAssign::OnPreBotAssign, u, ci, this);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -121,13 +121,13 @@ void ServiceBot::Assign(User *u, ChanServ::Channel *ci)
ci->SetBot(this);
- Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this);
+ EventManager::Get()->Dispatch(&Event::BotAssign::OnBotAssign, u, ci, this);
}
void ServiceBot::UnAssign(User *u, ChanServ::Channel *ci)
{
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotUnAssign::OnBotUnAssign, u, ci);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -156,7 +156,7 @@ void ServiceBot::Join(Channel *c, ChannelStatus *status)
if (IRCD)
IRCD->SendJoin(this, c, status);
- Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, this, c);
+ EventManager::Get()->Dispatch(&Event::JoinChannel::OnJoinChannel, this, c);
}
void ServiceBot::Join(const Anope::string &chname, ChannelStatus *status)
@@ -170,13 +170,13 @@ void ServiceBot::Part(Channel *c, const Anope::string &reason)
if (c->FindUser(this) == NULL)
return;
- Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, this, c);
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, this, c);
IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : "");
c->DeleteUser(this);
- Event::OnPartChannel(&Event::PartChannel::OnPartChannel, this, c, c->name, reason);
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, this, c, c->name, reason);
}
void ServiceBot::OnMessage(User *u, const Anope::string &message)
@@ -259,9 +259,9 @@ bool BotInfo::GetOperOnly()
return Get(&BotInfoType::operonly);
}
-void BotInfo::SetNick(const Anope::string &nick)
+void BotInfo::SetNick(const Anope::string &n)
{
- Set(&BotInfoType::nick, nick);
+ Set(&BotInfoType::nick, n);
}
Anope::string BotInfo::GetNick()
@@ -269,9 +269,9 @@ Anope::string BotInfo::GetNick()
return Get(&BotInfoType::nick);
}
-void BotInfo::SetUser(const Anope::string &user)
+void BotInfo::SetUser(const Anope::string &u)
{
- Set(&BotInfoType::user, user);
+ Set(&BotInfoType::user, u);
}
Anope::string BotInfo::GetUser()
@@ -279,9 +279,9 @@ Anope::string BotInfo::GetUser()
return Get(&BotInfoType::user);
}
-void BotInfo::SetHost(const Anope::string &host)
+void BotInfo::SetHost(const Anope::string &h)
{
- Set(&BotInfoType::host, host);
+ Set(&BotInfoType::host, h);
}
Anope::string BotInfo::GetHost()
@@ -289,9 +289,9 @@ Anope::string BotInfo::GetHost()
return Get(&BotInfoType::host);
}
-void BotInfo::SetRealName(const Anope::string &realname)
+void BotInfo::SetRealName(const Anope::string &r)
{
- Set(&BotInfoType::realname, realname);
+ Set(&BotInfoType::realname, r);
}
Anope::string BotInfo::GetRealName()
diff --git a/src/channels.cpp b/src/channels.cpp
index e1529b270..7a380b547 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -43,12 +43,12 @@ Channel::Channel(const Anope::string &nname, time_t ts)
if (Me && Me->IsSynced())
Log(NULL, this, "create");
- Event::OnChannelCreate(&Event::ChannelCreate::OnChannelCreate, this);
+ EventManager::Get()->Dispatch(&Event::ChannelCreate::OnChannelCreate, this);
}
Channel::~Channel()
{
- Event::OnChannelDelete(&Event::ChannelDelete::OnChannelDelete, this);
+ EventManager::Get()->Dispatch(&Event::ChannelDelete::OnChannelDelete, this);
ModeManager::StackerDel(this);
@@ -94,7 +94,7 @@ void Channel::Reset()
void Channel::Sync()
{
syncing = false;
- Event::OnChannelSync(&Event::ChannelSync::OnChannelSync, this);
+ EventManager::Get()->Dispatch(&Event::ChannelSync::OnChannelSync, this);
CheckModes();
}
@@ -112,7 +112,7 @@ void Channel::CheckModes()
}
Reference<Channel> ref = this;
- Event::OnCheckModes(&Event::CheckModes::OnCheckModes, ref);
+ EventManager::Get()->Dispatch(&Event::CheckModes::OnCheckModes, ref);
}
bool Channel::CheckDelete()
@@ -128,7 +128,7 @@ bool Channel::CheckDelete()
return false;
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnCheckDelete(&Event::CheckDelete::OnCheckDelete, this);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::CheckDelete::OnCheckDelete, this);
return MOD_RESULT != EVENT_STOP && this->users.empty();
}
@@ -152,7 +152,7 @@ void Channel::DeleteUser(User *user)
if (user->server && user->server->IsSynced() && !user->Quitting())
Log(user, this, "leave");
- Event::OnLeaveChannel(&Event::LeaveChannel::OnLeaveChannel, user, this);
+ EventManager::Get()->Dispatch(&Event::LeaveChannel::OnLeaveChannel, user, this);
ChanUserContainer *cu = user->FindChannel(this);
if (!this->users.erase(user))
@@ -286,7 +286,7 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
if (cc)
cc->status.AddMode(cm->mchar);
- MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
/* Enforce secureops, etc */
if (enforce_mlock && MOD_RESULT != EVENT_STOP)
@@ -307,7 +307,7 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
return;
}
- MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
/* Check if we should enforce mlock */
if (!enforce_mlock || MOD_RESULT == EVENT_STOP)
@@ -350,7 +350,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm,
if (cc)
cc->status.DelMode(cm->mchar);
- MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
if (enforce_mlock && MOD_RESULT != EVENT_STOP)
this->SetCorrectModes(u, false);
@@ -370,7 +370,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm,
else
this->modes.erase(cm->name);
- MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
if (cm->name == "PERM")
{
@@ -740,13 +740,13 @@ bool Channel::KickInternal(const MessageSource &source, const Anope::string &nic
ChannelStatus status = cu->status;
- EventReturn MOD_RESULT = Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason);
if ((sender && sender->server == Me) || source.GetServer() == Me)
if (MOD_RESULT == EVENT_STOP)
return false;
this->DeleteUser(target);
- Event::OnUserKicked(&Event::UserKicked::OnUserKicked, source, target, this->name, status, reason);
+ EventManager::Get()->Dispatch(&Event::UserKicked::OnUserKicked, source, target, this->name, status, reason);
return true;
}
@@ -780,7 +780,7 @@ void Channel::ChangeTopicInternal(User *u, const Anope::string &user, const Anop
Log(LOG_DEBUG) << "Topic of " << this->name << " changed by " << this->topic_setter << " to " << newtopic;
- Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, u, this, user, this->topic);
+ EventManager::Get()->Dispatch(&Event::TopicUpdated::OnTopicUpdated, u, this, user, this->topic);
}
void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts)
@@ -794,7 +794,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop
/* Now that the topic is set update the time set. This is *after* we set it so the protocol modules are able to tell the old last set time */
this->topic_time = Anope::CurTime;
- Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, nullptr, this, user, this->topic);
+ EventManager::Get()->Dispatch(&Event::TopicUpdated::OnTopicUpdated, nullptr, this, user, this->topic);
}
void Channel::SetCorrectModes(User *user, bool give_modes)
@@ -812,7 +812,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes)
/* Initially only take modes if the channel is being created by a non netmerge */
bool take_modes = this->syncing && user->server->IsSynced();
- Event::OnSetCorrectModes(&Event::SetCorrectModes::OnSetCorrectModes, user, this, u_access, give_modes, take_modes);
+ EventManager::Get()->Dispatch(&Event::SetCorrectModes::OnSetCorrectModes, user, this, u_access, give_modes, take_modes);
/* Never take modes from ulines */
if (user->server->IsULined())
@@ -883,8 +883,7 @@ bool Channel::CheckKick(User *user)
Anope::string mask, reason;
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnCheckKick(&Event::CheckKick::OnCheckKick, user, this, mask, reason);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::CheckKick::OnCheckKick, user, this, mask, reason);
if (MOD_RESULT != EVENT_STOP)
return false;
diff --git a/src/command.cpp b/src/command.cpp
index f7de4ccec..825bc1bc8 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -105,7 +105,7 @@ void CommandSource::Reply(const Anope::string &message)
this->reply->SendMessage(*this->service, tok);
}
-Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(owner)
+Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(o)
{
allow_unregistered = require_user = false;
}
@@ -205,20 +205,20 @@ void Command::Run(CommandSource &source, const Anope::string &message)
if (it == source.service->commands.end())
{
if (has_help)
- source.Reply(_("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
+ source.Reply(_("Unknown command \002{0}\002. \"{1}{2} HELP\" for help."), message, Config->StrictPrivmsg, source.service->nick);
else
- source.Reply(_("Unknown command \002%s\002."), message.c_str());
+ source.Reply(_("Unknown command \002{0}\002."), message);
return;
}
const CommandInfo &info = it->second;
- ServiceReference<Command> c("Command", info.name);
+ ServiceReference<Command> c(info.name);
if (!c)
{
if (has_help)
- source.Reply(_("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
+ source.Reply(_("Unknown command \002{0}\002. \"{1}{2} HELP\" for help."), message, Config->StrictPrivmsg, source.service->nick);
else
- source.Reply(_("Unknown command \002%s\002."), message.c_str());
+ source.Reply(_("Unknown command \002{0}\002."), message);
Log(source.service) << "Command " << it->first << " exists on me, but its service " << info.name << " was not found!";
return;
}
@@ -252,8 +252,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com
source.command = cmdname;
source.permission = info.permission;
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, this, params);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, this, params);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -276,7 +275,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com
}
this->Execute(source, params);
- Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, this, params);
+ EventManager::Get()->Dispatch(&Event::PostCommand::OnPostCommand, source, this, params);
}
bool Command::FindCommandFromService(const Anope::string &command_service, ServiceBot* &bot, Anope::string &name)
diff --git a/src/config.cpp b/src/config.cpp
index 5042f1a47..ad73f8e59 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -315,7 +315,7 @@ Conf::Conf() : Block("")
if (ot == NULL)
throw ConfigException("Oper block for " + nname + " has invalid oper type " + type);
- Oper *o = operblock.Create();
+ Oper *o = Serialize::New<Oper *>();
o->conf = this;
o->SetName(nname);
o->SetType(ot);
@@ -326,7 +326,7 @@ Conf::Conf() : Block("")
o->SetVhost(vhost);
}
- for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo))
+ for (BotInfo *bi : Serialize::GetObjects<BotInfo *>())
bi->conf = nullptr;
for (int i = 0; i < this->CountBlock("service"); ++i)
{
@@ -502,7 +502,7 @@ Conf::Conf() : Block("")
if (status.length() > 1)
throw ConfigException("Channelmode status must be at most one character");
- if (list || !param_regex.empty() || param_unset || !status.empty())
+ if (list || !param_regex.empty() || !status.empty())
param = true;
Channelmode cm;
@@ -552,20 +552,19 @@ Conf::Conf() : Block("")
/* Clear existing conf opers */
if (Config)
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
if (o->conf == Config)
o->Delete();
/* Apply new opers */
- if (NickServ::service)
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
- {
- NickServ::Nick *na = NickServ::service->FindNick(o->GetName());
- if (!na)
- continue;
+ for (Oper *o : Serialize::GetObjects<Oper *>())
+ {
+ NickServ::Nick *na = NickServ::FindNick(o->GetName());
+ if (!na)
+ continue;
- na->GetAccount()->o = o;
- Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName();
- }
+ na->GetAccount()->o = o;
+ Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName();
+ }
/* Check the user keys */
if (!options->Get<unsigned>("seed"))
@@ -613,7 +612,7 @@ void Conf::Post(Conf *old)
ModeManager::Apply(old);
/* Apply opertype changes, as non-conf opers still point to the old oper types */
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
{
/* Oper's type is in the old config, so update it */
if (std::find(old->MyOperTypes.begin(), old->MyOperTypes.end(), o->GetType()) != old->MyOperTypes.end())
@@ -633,7 +632,7 @@ void Conf::Post(Conf *old)
}
}
- for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo))
+ for (BotInfo *bi : Serialize::GetObjects<BotInfo *>())
{
if (!bi->conf)
{
diff --git a/src/event.cpp b/src/event.cpp
index 3e313d5a0..89c60da13 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -1,6 +1,7 @@
-/* Modular support
+/*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2016 Adam <Adam@anope.org>
+ *
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -10,89 +11,15 @@
#include "services.h"
#include "event.h"
-using namespace Event;
+EventManager *EventManager::eventManager = nullptr;
+
+void EventManager::Init()
+{
+ eventManager = new EventManager();
+}
+
+EventManager *EventManager::Get()
+{
+ return eventManager;
+}
-EventHandlers<PreUserKicked> Event::OnPreUserKicked(nullptr);
-EventHandlers<UserKicked> Event::OnUserKicked(nullptr);
-EventHandlers<PreBotAssign> Event::OnPreBotAssign(nullptr);
-EventHandlers<BotAssign> Event::OnBotAssign(nullptr);
-EventHandlers<BotUnAssign> Event::OnBotUnAssign(nullptr);
-EventHandlers<UserConnect> Event::OnUserConnect(nullptr);
-EventHandlers<NewServer> Event::OnNewServer(nullptr);
-EventHandlers<UserNickChange> Event::OnUserNickChange(nullptr);
-EventHandlers<PreCommand> Event::OnPreCommand(nullptr);
-EventHandlers<PostCommand> Event::OnPostCommand(nullptr);
-EventHandlers<SaveDatabase> Event::OnSaveDatabase(nullptr);
-EventHandlers<LoadDatabase> Event::OnLoadDatabase(nullptr);
-EventHandlers<Encrypt> Event::OnEncrypt(nullptr);
-EventHandlers<Decrypt> Event::OnDecrypt(nullptr);
-EventHandlers<CreateBot> Event::OnCreateBot(nullptr);
-EventHandlers<DelBot> Event::OnDelBot(nullptr);
-EventHandlers<PrePartChannel> Event::OnPrePartChannel(nullptr);
-EventHandlers<PartChannel> Event::OnPartChannel(nullptr);
-EventHandlers<LeaveChannel> Event::OnLeaveChannel(nullptr);
-EventHandlers<JoinChannel> Event::OnJoinChannel(nullptr);
-EventHandlers<TopicUpdated> Event::OnTopicUpdated(nullptr);
-EventHandlers<PreServerConnect> Event::OnPreServerConnect(nullptr);
-EventHandlers<ServerConnect> Event::OnServerConnect(nullptr);
-EventHandlers<PreUplinkSync> Event::OnPreUplinkSync(nullptr);
-EventHandlers<ServerDisconnect> Event::OnServerDisconnect(nullptr);
-EventHandlers<Restart> Event::OnRestart(nullptr);
-EventHandlers<Shutdown> Event::OnShutdown(nullptr);
-EventHandlers<AddXLine> Event::OnAddXLine(nullptr);
-EventHandlers<DelXLine> Event::OnDelXLine(nullptr);
-EventHandlers<IsServicesOperEvent> Event::OnIsServicesOper(nullptr);
-EventHandlers<ServerQuit> Event::OnServerQuit(nullptr);
-EventHandlers<UserQuit> Event::OnUserQuit(nullptr);
-EventHandlers<PreUserLogoff> Event::OnPreUserLogoff(nullptr);
-EventHandlers<PostUserLogoff> Event::OnPostUserLogoff(nullptr);
-EventHandlers<AccessDel> Event::OnAccessDel(nullptr);
-EventHandlers<AccessAdd> Event::OnAccessAdd(nullptr);
-EventHandlers<AccessClear> Event::OnAccessClear(nullptr);
-EventHandlers<ChanRegistered> Event::OnChanRegistered(nullptr);
-EventHandlers<CreateChan> Event::OnCreateChan(nullptr);
-EventHandlers<DelChan> Event::OnDelChan(nullptr);
-EventHandlers<ChannelCreate> Event::OnChannelCreate(nullptr);
-EventHandlers<ChannelDelete> Event::OnChannelDelete(nullptr);
-EventHandlers<CheckKick> Event::OnCheckKick(nullptr);
-EventHandlers<CheckPriv> Event::OnCheckPriv(nullptr);
-EventHandlers<GroupCheckPriv> Event::OnGroupCheckPriv(nullptr);
-EventHandlers<NickIdentify> Event::OnNickIdentify(nullptr);
-EventHandlers<UserLogin> Event::OnUserLogin(nullptr);
-EventHandlers<NickLogout> Event::OnNickLogout(nullptr);
-EventHandlers<DelNick> Event::OnDelNick(nullptr);
-EventHandlers<NickCoreCreate> Event::OnNickCoreCreate(nullptr);
-EventHandlers<DelCore> Event::OnDelCore(nullptr);
-EventHandlers<ChangeCoreDisplay> Event::OnChangeCoreDisplay(nullptr);
-EventHandlers<NickClearAccess> Event::OnNickClearAccess(nullptr);
-EventHandlers<NickAddAccess> Event::OnNickAddAccess(nullptr);
-EventHandlers<NickEraseAccess> Event::OnNickEraseAccess(nullptr);
-EventHandlers<CheckAuthentication> Event::OnCheckAuthentication(nullptr);
-EventHandlers<Fingerprint> Event::OnFingerprint(nullptr);
-EventHandlers<UserAway> Event::OnUserAway(nullptr);
-EventHandlers<Invite> Event::OnInvite(nullptr);
-EventHandlers<SetVhost> Event::OnSetVhost(nullptr);
-EventHandlers<SetDisplayedHost> Event::OnSetDisplayedHost(nullptr);
-EventHandlers<ChannelModeSet> Event::OnChannelModeSet(nullptr);
-EventHandlers<ChannelModeUnset> Event::OnChannelModeUnset(nullptr);
-EventHandlers<UserModeSet> Event::OnUserModeSet(nullptr);
-EventHandlers<UserModeUnset> Event::OnUserModeUnset(nullptr);
-EventHandlers<ChannelModeAdd> Event::OnChannelModeAdd(nullptr);
-EventHandlers<UserModeAdd> Event::OnUserModeAdd(nullptr);
-EventHandlers<ModuleLoad> Event::OnModuleLoad(nullptr);
-EventHandlers<ModuleUnload> Event::OnModuleUnload(nullptr);
-EventHandlers<ServerSync> Event::OnServerSync(nullptr);
-EventHandlers<UplinkSync> Event::OnUplinkSync(nullptr);
-EventHandlers<BotPrivmsg> Event::OnBotPrivmsg(nullptr);
-EventHandlers<BotNotice> Event::OnBotNotice(nullptr);
-EventHandlers<Privmsg> Event::OnPrivmsg(nullptr);
-EventHandlers<Event::Log> Event::OnLog(nullptr);
-EventHandlers<LogMessage> Event::OnLogMessage(nullptr);
-EventHandlers<CheckModes> Event::OnCheckModes(nullptr);
-EventHandlers<ChannelSync> Event::OnChannelSync(nullptr);
-EventHandlers<SetCorrectModes> Event::OnSetCorrectModes(nullptr);
-EventHandlers<Message> Event::OnMessage(nullptr);
-EventHandlers<CanSet> Event::OnCanSet(nullptr);
-EventHandlers<CheckDelete> Event::OnCheckDelete(nullptr);
-EventHandlers<ExpireTick> Event::OnExpireTick(nullptr);
-EventHandlers<SerializeEvents> Event::OnSerialize(nullptr);
diff --git a/src/extensible.cpp b/src/extensible.cpp
index c3c56abf8..a014d6bd0 100644
--- a/src/extensible.cpp
+++ b/src/extensible.cpp
@@ -18,12 +18,10 @@ ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &t, const Anope::s
{
}
-ExtensibleBase::~ExtensibleBase()
-{
-}
-
Extensible::~Extensible()
{
+ while (!extension_items.empty())
+ (*extension_items.begin())->Unset(this);
}
bool Extensible::HasExtOK(const Anope::string &name)
diff --git a/src/init.cpp b/src/init.cpp
index e64bf0eff..f0f793839 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -481,8 +481,11 @@ void Anope::Init(int ac, char **av)
/* Initialize the socket engine. Note that some engines can not survive a fork(), so this must be here. */
SocketEngine::Init();
+ ServiceManager::Init();
+ EventManager::Init();
+
new BotInfoType();
- new XLineType(nullptr, "XLine");
+ new XLineType(nullptr);
new OperBlockType();
/* Read configuration file; exit if there are problems. */
@@ -567,14 +570,11 @@ void Anope::Init(int ac, char **av)
/* Load up databases */
Log() << "Loading databases...";
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnLoadDatabase(&Event::LoadDatabase::OnLoadDatabase);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::LoadDatabase::OnLoadDatabase);;
static_cast<void>(MOD_RESULT);
Log() << "Databases loaded";
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
it->second->Sync();
-
- //Serialize::CheckTypes();
}
diff --git a/src/logger.cpp b/src/logger.cpp
index 3a735d48d..7be130d0b 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -90,11 +90,11 @@ Log::Log(LogType t, CommandSource &src, Command *_c, ChanServ::Channel *_ci) : u
if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN)
throw CoreException("This constructor does not support this log type");
- size_t sl = c->name.find('/');
+ size_t sl = c->GetName().find('/');
this->bi = NULL;
if (sl != Anope::string::npos)
- this->bi = ServiceBot::Find(c->name.substr(0, sl), true);
- this->category = c->name;
+ this->bi = ServiceBot::Find(c->GetName().substr(0, sl), true);
+ this->category = c->GetName();
}
Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(NULL), c(NULL), source(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), type(LOG_CHANNEL), category(cat)
@@ -132,7 +132,15 @@ Log::~Log()
else if (this->type == LOG_TERMINAL)
std::cout << this->BuildPrefix() << this->buf.str() << std::endl;
- Event::OnLog(&Event::Log::OnLog, this);
+ /* Some of the higher debug messages are in the event/service system which manages event dispatch,
+ * so firing off the log event here can cause them to be in weird states
+ */
+ if (this->type <= LOG_NORMAL)
+ {
+ EventManager *em = EventManager::Get();
+ if (em != nullptr)
+ em->Dispatch(&Event::Log::OnLog, this);
+ }
if (Config)
for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
@@ -154,7 +162,7 @@ Anope::string Log::FormatSource() const
Anope::string Log::FormatCommand() const
{
- Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->name) + " ";
+ Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->GetName()) + " ";
if (this->ci)
buffer += "on " + this->ci->GetName() + " ";
@@ -348,7 +356,7 @@ void LogInfo::ProcessMessage(const Log *l)
const Anope::string &buffer = l->BuildPrefix() + l->buf.str();
- Event::OnLogMessage(&Event::LogMessage::OnLogMessage, this, l, buffer);
+ EventManager::Get()->Dispatch(&Event::LogMessage::OnLogMessage, this, l, buffer);
for (unsigned i = 0; i < this->targets.size(); ++i)
{
diff --git a/src/main.cpp b/src/main.cpp
index 65fb8d3f6..b6a41fd53 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -62,7 +62,7 @@ class ExpireTimer : public Timer
void Tick(time_t) override
{
- Event::OnExpireTick(&Event::ExpireTick::OnExpireTick);
+ EventManager::Get()->Dispatch(&Event::ExpireTick::OnExpireTick);
}
};
@@ -72,7 +72,7 @@ void Anope::SaveDatabases()
return;
Log(LOG_DEBUG) << "Saving databases";
- Event::OnSaveDatabase(&Event::SaveDatabase::OnSaveDatabase);
+ EventManager::Get()->Dispatch(&Event::SaveDatabase::OnSaveDatabase);
}
/** The following comes from InspIRCd to get the full path of the Anope executable
@@ -180,11 +180,11 @@ int main(int ac, char **av, char **envp)
if (Anope::Restarting)
{
- Event::OnRestart(&Event::Restart::OnRestart);
+ EventManager::Get()->Dispatch(&Event::Restart::OnRestart);
}
else
{
- Event::OnShutdown(&Event::Shutdown::OnShutdown);
+ EventManager::Get()->Dispatch(&Event::Shutdown::OnShutdown);
}
if (Anope::QuitReason.empty())
diff --git a/src/messages.cpp b/src/messages.cpp
index a6ccbe324..caef641a3 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -22,6 +22,7 @@
#include "channels.h"
#include "event.h"
#include "bots.h"
+#include "modules/operserv/stats.h"
using namespace Message;
@@ -29,7 +30,7 @@ void Away::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &msg = !params.empty() ? params[0] : "";
- Event::OnUserAway(&Event::UserAway::OnUserAway, source.GetUser(), msg);
+ EventManager::Get()->Dispatch(&Event::UserAway::OnUserAway, source.GetUser(), msg);
if (!msg.empty())
Log(source.GetUser(), "away") << "is now away: " << msg;
@@ -66,7 +67,7 @@ void Invite::Run(MessageSource &source, const std::vector<Anope::string> &params
if (!targ || targ->server != Me || !c || c->FindUser(targ))
return;
- Event::OnInvite(&Event::Invite::OnInvite, source.GetUser(), c, targ);
+ EventManager::Get()->Dispatch(&Event::Invite::OnInvite, source.GetUser(), c, targ);
}
void Join::Run(MessageSource &source, const std::vector<Anope::string> &params)
@@ -88,9 +89,9 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> &params)
Channel *c = cc->chan;
++it;
- Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, user, c);
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, user, c);
cc->chan->DeleteUser(user);
- Event::OnPartChannel(&Event::PartChannel::OnPartChannel, user, c, c->name, "");
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, user, c, c->name, "");
}
continue;
}
@@ -152,7 +153,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
*/
c->SetCorrectModes(u, true);
- Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, u, c);
+ EventManager::Get()->Dispatch(&Event::JoinChannel::OnJoinChannel, u, c);
}
/* Channel is done syncing */
@@ -273,7 +274,7 @@ void Notice::Run(MessageSource &source, const std::vector<Anope::string> &params
ServiceBot *bi = ServiceBot::Find(params[0]);
if (!bi)
return;
- Event::OnBotNotice(&Event::BotNotice::OnBotNotice, u, bi, message);
+ EventManager::Get()->Dispatch(&Event::BotNotice::OnBotNotice, u, bi, message);
}
}
@@ -294,9 +295,9 @@ void Part::Run(MessageSource &source, const std::vector<Anope::string> &params)
Log(u, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason");
- Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, u, c);
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, u, c);
c->DeleteUser(u);
- Event::OnPartChannel(&Event::PartChannel::OnPartChannel, u, c, c->name, !reason.empty() ? reason : "");
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, u, c, c->name, reason);
}
}
@@ -317,7 +318,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
Channel *c = Channel::Find(receiver);
if (c)
{
- Event::OnPrivmsg(&Event::Privmsg::OnPrivmsg, u, c, message);
+ EventManager::Get()->Dispatch(&Event::Privmsg::OnPrivmsg, u, c, message);
}
}
else
@@ -366,8 +367,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
return;
}
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnBotPrivmsg(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -409,7 +409,7 @@ void SQuit::Run(MessageSource &source, const std::vector<Anope::string> &params)
s->Delete(s->GetName() + " " + s->GetUplink()->GetName());
}
-void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
+void Message::Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
User *u = source.GetUser();
@@ -431,7 +431,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
else
{
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->GetName().c_str(), o->GetType()->GetName().replace_all_cs(" ", "_").c_str());
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
@@ -440,9 +440,11 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
break;
case 'u':
{
+ ::Stats *s = Serialize::GetObject<::Stats *>();
long uptime = static_cast<long>(Anope::CurTime - Anope::StartTime);
+
IRCD->SendNumeric(242, source.GetSource(), ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60);
- IRCD->SendNumeric(250, source.GetSource(), ":Current users: %d (%d ops); maximum %d", UserListByNick.size(), OperCount, MaxUserCount);
+ IRCD->SendNumeric(250, source.GetSource(), ":Current users: %d (%d ops); maximum %d", UserListByNick.size(), OperCount, s ? s->GetMaxUserCount() : 0);
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
break;
} /* case 'u' */
diff --git a/src/misc.cpp b/src/misc.cpp
index 436ac2261..323b66b13 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -140,14 +140,15 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer)
unsigned length = 0;
for (std::map<Anope::string, size_t>::iterator it = lenghts.begin(), it_end = lenghts.end(); it != it_end; ++it)
{
- /* Break lines at 80 chars */
- if (length > 80)
+ if (length > Config->LineWrap)
{
breaks.insert(it->first);
length = 0;
}
else
+ {
length += it->second;
+ }
}
/* Only put a list header if more than 1 column */
@@ -480,8 +481,7 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case
void Anope::Encrypt(const Anope::string &src, Anope::string &dest)
{
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnEncrypt(&Event::Encrypt::OnEncrypt, src, dest);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::Encrypt::OnEncrypt, src, dest);
static_cast<void>(MOD_RESULT);
}
@@ -495,8 +495,7 @@ bool Anope::Decrypt(const Anope::string &src, Anope::string &dest)
}
Anope::string hashm(src.begin(), src.begin() + pos);
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnDecrypt(&Event::Decrypt::OnDecrypt, hashm, src, dest);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::Decrypt::OnDecrypt, hashm, src, dest);
if (MOD_RESULT == EVENT_ALLOW)
return true;
diff --git a/src/modes.cpp b/src/modes.cpp
index cb70d7102..aae3d3f21 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -148,8 +148,7 @@ ChannelMode::ChannelMode(const Anope::string &cm, char mch) : Mode(cm, MC_CHANNE
bool ChannelMode::CanSet(User *u) const
{
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnCanSet(&Event::CanSet::OnCanSet, u, this);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::CanSet::OnCanSet, u, this);
return MOD_RESULT != EVENT_STOP;
}
@@ -391,7 +390,7 @@ bool ModeManager::AddUserMode(UserMode *um)
UserModes.push_back(um);
- Event::OnUserModeAdd(&Event::UserModeAdd::OnUserModeAdd, um);
+ EventManager::Get()->Dispatch(&Event::UserModeAdd::OnUserModeAdd, um);
return true;
}
@@ -426,7 +425,7 @@ bool ModeManager::AddChannelMode(ChannelMode *cm)
ChannelModes.push_back(cm);
- Event::OnChannelModeAdd(&Event::ChannelModeAdd::OnChannelModeAdd, cm);
+ EventManager::Get()->Dispatch(&Event::ChannelModeAdd::OnChannelModeAdd, cm);
for (unsigned int i = 0; i < ChannelModes.size(); ++i)
ChannelModes[i]->Check();
@@ -716,16 +715,20 @@ void ModeManager::StackerDel(Mode *m)
void ModeManager::Apply(Configuration::Conf *old)
{
- /* XXX remove old modes */
+#warning "remove old modes"
for (Configuration::Channelmode &cm : Config->Channelmodes)
{
ChannelMode *mode;
- if (cm.character)
- Log(LOG_DEBUG) << "Creating channelmode " << cm.name << " (" << cm.character << ")";
+ if (cm.list)
+ Log(LOG_DEBUG) << "Creating channelmode list " << cm.name << " (" << cm.character << ")";
+ else if (cm.status)
+ Log(LOG_DEBUG) << "Creating channelmode status " << cm.name << " (" << cm.character << ")";
+ else if (cm.param)
+ Log(LOG_DEBUG) << "Creating channelmode param " << cm.name << " (" << cm.character << ")";
else
- Log(LOG_DEBUG) << "Creating channelmode " << cm.name;
+ Log(LOG_DEBUG) << "Creating channelmode " << cm.name << " (" << cm.character << ")";
if (cm.list)
mode = new ChannelModeList(cm.name, cm.character);
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 76cec0b57..f931671b0 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -133,7 +133,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
#ifdef _WIN32
/* Generate the filename for the temporary copy of the module */
- Anope::string pbuf = Anope::DataDir + "/runtime/" + modname + ".so.XXXXXX";
+ Anope::string pbuf = Anope::DataDir + "/runtime/" + modname.replace_all_cs("/", "_") + ".so.XXXXXX";
/* Don't skip return value checking! -GD */
ModuleReturn ret = moduleCopyFile(modname, pbuf);
@@ -146,7 +146,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
return ret;
}
#else
- Anope::string pbuf = Anope::ModuleDir + "/modules/" + modname + ".so";
+ Anope::string pbuf = Anope::ModuleDir + "/modules/" + modname.replace_all_cs("/", "_") + ".so";
#endif
dlerror();
@@ -267,7 +267,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
Log(LOG_DEBUG) << "Module " << modname << " loaded.";
- Event::OnModuleLoad(&Event::ModuleLoad::OnModuleLoad, u, m);
+ EventManager::Get()->Dispatch(&Event::ModuleLoad::OnModuleLoad, u, m);
return MOD_ERR_OK;
}
@@ -277,7 +277,7 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u)
if (!m)
return MOD_ERR_PARAMS;
- Event::OnModuleUnload(&Event::ModuleUnload::OnModuleUnload, u, m);
+ EventManager::Get()->Dispatch(&Event::ModuleUnload::OnModuleUnload, u, m);
return DeleteModule(m);
}
diff --git a/src/opertype.cpp b/src/opertype.cpp
index d524c7ded..09bc23bb7 100644
--- a/src/opertype.cpp
+++ b/src/opertype.cpp
@@ -67,9 +67,9 @@ OperType *Oper::GetType()
return OperType::Find(Get(&OperBlockType::type));
}
-void Oper::SetType(OperType *type)
+void Oper::SetType(OperType *t)
{
- Set(&OperBlockType::type, type->GetName());
+ Set(&OperBlockType::type, t->GetName());
}
bool Oper::GetRequireOper()
@@ -84,7 +84,7 @@ void Oper::SetRequireOper(const bool &b)
Oper *Oper::Find(const Anope::string &name)
{
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
if (o->GetName() == name)
return o;
diff --git a/src/process.cpp b/src/process.cpp
index d14d8d589..e0beff9a7 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -51,12 +51,9 @@ void Anope::Process(const Anope::string &buffer)
MessageSource src(source);
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnMessage(&Event::Message::OnMessage, src, command, params);
- if (MOD_RESULT == EVENT_STOP)
- return;
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::Message::OnMessage, src, command, params);
- ServiceReference<IRCDMessage> m("IRCDMessage", proto_name + "/" + command.lower());
+ ServiceReference<IRCDMessage> m(proto_name + "/" + command.lower());
if (!m)
{
Log(LOG_DEBUG) << "unknown message from server (" << buffer << ")";
diff --git a/src/serialize.cpp b/src/serialize.cpp
index b11f8232c..4313047a9 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -1,13 +1,10 @@
/*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 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.
- *
*/
@@ -19,14 +16,15 @@
using namespace Serialize;
-std::map<Anope::string, TypeBase *> Serialize::Types;
-
std::unordered_map<ID, Object *> Serialize::objects;
std::vector<FieldBase *> Serialize::serializableFields;
+std::multimap<Anope::string, Anope::string> Serialize::child_types;
+
static ID curid;
+
Object *Serialize::GetID(ID id)
{
auto it = objects.find(id);
@@ -46,23 +44,19 @@ void Serialize::Clear()
void Serialize::Unregister(Module *m)
{
- for (FieldBase *field : serializableFields)
- if (field->creator == m)
- field->Unregister();
-
- for (const std::pair<Anope::string, TypeBase *> &p : Types)
- {
- TypeBase *s = p.second;
-
+ for (TypeBase *s : ServiceManager::Get()->FindServices<Serialize::TypeBase *>())
if (s->GetOwner() == m)
s->Unregister();
- }
+
+ for (FieldBase *field : serializableFields)
+ if (field->GetOwner() == m)
+ field->Unregister();
}
std::vector<Edge> Object::GetRefs(TypeBase *type)
{
std::vector<Edge> refs;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeGetRefs, this, type, refs);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeGetRefs, this, type, refs);
if (result == EVENT_ALLOW)
return refs;
@@ -86,7 +80,7 @@ std::vector<Edge> Object::GetRefs(TypeBase *type)
Object::Object(TypeBase *type)
{
ID i;
- EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializableGetId, i);
+ EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializableGetId, i);
if (result != EVENT_ALLOW)
{
while (GetID(++curid));
@@ -100,9 +94,9 @@ Object::Object(TypeBase *type)
type->objects.insert(this);
- Log(LOG_DEBUG) << "Creating object id #" << id << " type " << type->GetName();
+ Log(LOG_DEBUG_2) << "Creating object id #" << id << " address " << static_cast<void *>(this) << " type " << type->GetName();
- Event::OnSerialize(&Event::SerializeEvents::OnSerializableCreate, this);
+ EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializableCreate, this);
}
Object::Object(TypeBase *type, ID i)
@@ -114,12 +108,12 @@ Object::Object(TypeBase *type, ID i)
type->objects.insert(this);
- Log(LOG_DEBUG) << "Creating object from id #" << id << " type " << type->GetName();
+ Log(LOG_DEBUG_2) << "Creating object from id #" << id << " address " << static_cast<void *>(this) << " type " << type->GetName();
}
Object::~Object()
{
- Log(LOG_DEBUG) << "Destructing object id #" << id << " type " << s_type->GetName();
+ Log(LOG_DEBUG_2) << "Destructing object id #" << id << " address " << static_cast<void *>(this) << " type " << s_type->GetName();
/* Remove in memory edges */
cont:
@@ -128,12 +122,12 @@ Object::~Object()
{
if (!edge.direction)
{
- Log(LOG_DEBUG_2) << "Removing edge from object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->GetName();
+ Log(LOG_DEBUG_2) << "Removing edge from object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->serialize_name;
edge.other->RemoveEdge(this, edge.field);
}
else
{
- Log(LOG_DEBUG_2) << "Removing edge to object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->GetName();
+ Log(LOG_DEBUG_2) << "Removing edge to object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->serialize_name;
this->RemoveEdge(edge.other, edge.field);
}
goto cont;
@@ -145,7 +139,7 @@ Object::~Object()
void Object::Delete()
{
- Log(LOG_DEBUG) << "Deleting object id #" << id << " type " << s_type->GetName();
+ Log(LOG_DEBUG_2) << "Deleting object id #" << id << " type " << s_type->GetName();
/* Delete dependant objects */
for (const Edge &edge : GetRefs(nullptr))
@@ -158,17 +152,17 @@ void Object::Delete()
if (field->depends)
{
- Log(LOG_DEBUG_2) << "Deleting dependent object #" << other->id << " type " << other->GetSerializableType()->GetName() << " due to edge on " << field->GetName();
+ Log(LOG_DEBUG_2) << "Deleting dependent object #" << other->id << " type " << other->GetSerializableType()->GetName() << " due to edge on " << field->serialize_name;
other->Delete();
}
else
{
- Log(LOG_DEBUG_2) << "Unsetting field " << field->GetName() << " on object #" << other->id << " type " << other->GetSerializableType()->GetName();
+ Log(LOG_DEBUG_2) << "Unsetting field " << field->serialize_name << " on object #" << other->id << " type " << other->GetSerializableType()->GetName();
field->UnsetS(other);
}
}
- Event::OnSerialize(&Event::SerializeEvents::OnSerializableDelete, this);
+ EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializableDelete, this);
delete this;
}
@@ -198,112 +192,71 @@ void Object::RemoveEdge(Object *other, FieldBase *field)
Log(LOG_DEBUG_2) << "Unable to locate edge for removal on #" << this->id << " type " << s_type->GetName() << " <- #" << other->id << " type " << other->GetSerializableType()->GetName();
}
-TypeBase::TypeBase(Module *o, const Anope::string &n) : Service(o, "Serialize::Type", n), name(n), owner(o)
+TypeBase::TypeBase(Module *o, const Anope::string &n) : Service(o, TypeBase::NAME, n), name(n), owner(o)
{
- Types[this->name] = this;
}
TypeBase::~TypeBase()
{
- if (!Serialize::GetObjects<Object *>(this).empty())
+ if (!Serialize::GetObjects<Object *>(this->GetName()).empty())
throw CoreException("Type destructing with objects still alive");
-
- if (parent)
- {
- auto it = std::find(parent->children.begin(), parent->children.end(), this);
- if (it != parent->children.end())
- parent->children.erase(it);
- }
-
- for (TypeBase *child : children)
- child->parent = nullptr;
-
- Types.erase(this->name);
}
void TypeBase::Unregister()
{
Log(LOG_DEBUG_2) << "Unregistering type " << this->GetName();
- for (Object *obj : GetObjects<Object *>(this))
+ for (Object *obj : GetObjects<Object *>(this->GetName()))
obj->Delete();
- cont:
- for (FieldBase *field : fields)
+ for (FieldBase *field : serializableFields)
{
- field->Unregister();
- goto cont;
+ if (field->serialize_type == this->GetName())
+ {
+ field->Unregister();
+ }
}
}
-void TypeBase::SetParent(TypeBase *other)
-{
- parent = other;
- other->children.push_back(this);
-}
-
Serialize::FieldBase *TypeBase::GetField(const Anope::string &fname)
{
- for (FieldBase *f : fields)
- if (f->GetName() == fname)
- return f;
+ /* is this too slow? */
+ for (FieldBase *fb : ServiceManager::Get()->FindServices<FieldBase *>())
+ if (fb->serialize_type == this->GetName() && fb->serialize_name == fname)
+ return fb;
+
+ Log(LOG_DEBUG_2) << "GetField() for unknown field " << fname << " on " << this->GetName();
+
return nullptr;
}
-std::vector<TypeBase *> TypeBase::GetSubTypes()
+std::vector<Serialize::FieldBase *> TypeBase::GetFields()
{
- std::vector<TypeBase *> v;
+ std::vector<Serialize::FieldBase *> fields;
- v.push_back(this);
+ for (FieldBase *fb : ServiceManager::Get()->FindServices<FieldBase *>())
+ if (fb->serialize_type == this->GetName())
+ fields.push_back(fb);
- for (TypeBase *b : children)
- {
- std::vector<TypeBase *> c = b->GetSubTypes();
- v.insert(v.end(), c.begin(), c.end());
- }
-
- return v;
+ return fields;
}
TypeBase *TypeBase::Find(const Anope::string &name)
{
- std::map<Anope::string, TypeBase *>::iterator it = Types.find(name);
- if (it != Types.end())
- return it->second;
- return nullptr;
-}
-
-const std::map<Anope::string, Serialize::TypeBase *>& TypeBase::GetTypes()
-{
- return Types;
+ return ServiceManager::Get()->FindService<TypeBase *>(name);
}
-void Serialize::FieldBase::Listener::OnAcquire()
-{
- TypeBase *t = *this;
-
- if (base->unregister)
- return;
-
- Log(LOG_DEBUG_2) << "Acquired type reference to " << t->GetName() << " for field " << base->GetName();
-
- auto it = std::find(t->fields.begin(), t->fields.end(), base);
- if (it == t->fields.end())
- t->fields.push_back(base);
-}
-
-FieldBase::FieldBase(Module *c, const Anope::string &n, const ServiceReference<TypeBase> &t, bool d) : type(this, t), creator(c), name(n), depends(d)
+FieldBase::FieldBase(Module *c, const Anope::string &n, const Anope::string &t, bool d)
+ : Service(c, FieldBase::NAME)
+ , serialize_type(t)
+ , serialize_name(n)
+ , depends(d)
{
serializableFields.push_back(this);
-
- type.Check();
}
FieldBase::~FieldBase()
{
- if (std::find(type->fields.begin(), type->fields.end(), this) != type->fields.end())
- Log(LOG_DEBUG) << "Destructing field " << this->GetName() << " on " << type->GetName() << " while still registered!";
-
auto it = std::find(serializableFields.begin(), serializableFields.end(), this);
if (it != serializableFields.end())
serializableFields.erase(it);
@@ -311,25 +264,46 @@ FieldBase::~FieldBase()
void FieldBase::Unregister()
{
- unregister = true;
-
- Log(LOG_DEBUG_2) << "Unregistering field " << this->GetName() << " on " << type->GetName();
+ Log(LOG_DEBUG_2) << "Unregistering field " << serialize_name << " on " << serialize_type;
/* find edges on this field */
- for (Object *s : Serialize::GetObjects<Object *>(type))
+ for (Object *s : Serialize::GetObjects<Object *>(serialize_type))
{
for (const std::pair<TypeBase *, std::vector<Edge>> &p : s->edges)
for (const Edge &edge : p.second)
if (edge.direction && edge.field == this)
{
- Log(LOG_DEBUG_2) << "Removing edge on #" << s->id << " <-> #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName();
+ Log(LOG_DEBUG_2) << "Removing edge on #" << s->id << " type " << s->GetSerializableType()->GetName() << " -> #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName();
s->RemoveEdge(edge.other, edge.field);
+
goto cont;
}
cont:;
}
+}
+
+void Serialize::SetParent(const Anope::string &child, const Anope::string &parent)
+{
+ child_types.insert(std::make_pair(parent, child));
+}
+
+std::vector<Serialize::TypeBase *> Serialize::GetTypes(const Anope::string &name)
+{
+ std::vector<Serialize::TypeBase *> v;
+
+ Serialize::TypeBase *t = Serialize::TypeBase::Find(name);
+ if (t != nullptr)
+ v.push_back(t);
+ else
+ Log(LOG_DEBUG_2) << "GetTypes for unknown type " << name;
+
+ auto its = child_types.equal_range(name);
+ for (; its.first != its.second; ++its.first)
+ {
+ t = Serialize::TypeBase::Find(its.first->second);
+ if (t != nullptr)
+ v.push_back(t);
+ }
- auto it = std::find(type->fields.begin(), type->fields.end(), this);
- if (it != type->fields.end())
- type->fields.erase(it);
+ return v;
}
diff --git a/src/servers.cpp b/src/servers.cpp
index 9f94bc78e..1308147b7 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -51,7 +51,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
Burst();
}
- Event::OnNewServer(&Event::NewServer::OnNewServer, this);
+ EventManager::Get()->Dispatch(&Event::NewServer::OnNewServer, this);
}
Server::~Server()
@@ -86,7 +86,7 @@ void Server::Delete(const Anope::string &reason)
{
this->quit_reason = reason;
this->quitting = true;
- Event::OnServerQuit(&Event::ServerQuit::OnServerQuit, this);
+ EventManager::Get()->Dispatch(&Event::ServerQuit::OnServerQuit, this);
delete this;
}
@@ -228,7 +228,7 @@ void Server::Sync(bool sync_links)
Log(this, "sync") << "is done syncing";
- Event::OnServerSync(&Event::ServerSync::OnServerSync, this);
+ EventManager::Get()->Dispatch(&Event::ServerSync::OnServerSync, this);
if (sync_links && !this->links.empty())
{
@@ -240,7 +240,7 @@ void Server::Sync(bool sync_links)
if (me)
{
- Event::OnPreUplinkSync(&Event::PreUplinkSync::OnPreUplinkSync, this);
+ EventManager::Get()->Dispatch(&Event::PreUplinkSync::OnPreUplinkSync, this);
}
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end;)
@@ -257,7 +257,7 @@ void Server::Sync(bool sync_links)
IRCD->SendEOB();
Me->Sync(false);
- Event::OnUplinkSync(&Event::UplinkSync::OnUplinkSync, this);
+ EventManager::Get()->Dispatch(&Event::UplinkSync::OnUplinkSync, this);
if (!Anope::NoFork)
{
diff --git a/src/service.cpp b/src/service.cpp
index cfa9a17c7..c2270b734 100644
--- a/src/service.cpp
+++ b/src/service.cpp
@@ -1,6 +1,8 @@
/*
*
- * (C) 2014 Anope Team
+ * (C) 2014-2016 Anope Team
+ * (C) 2016 Adam <Adam@anope.org>
+ *
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -10,117 +12,59 @@
#include "services.h"
#include "service.h"
+#include "modules/nickserv.h"
+#include "modules/chanserv.h"
+#include "modules/memoserv.h"
-void Service::check()
-{
- if (Services || Aliases)
- return;
-
- Services = new std::map<Anope::string, std::map<Anope::string, Service *> >();
- Aliases = new std::map<Anope::string, std::map<Anope::string, Anope::string> >;
-}
+NickServ::NickServService *NickServ::service = nullptr;
+ChanServ::ChanServService *ChanServ::service = nullptr;
+MemoServ::MemoServService *MemoServ::service = nullptr;
-Service *Service::FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n)
+ServiceReferenceBase::ServiceReferenceBase(const Anope::string &_type, const Anope::string &_name) : type(_type), name(_name)
{
- std::map<Anope::string, Service *>::const_iterator it = services.find(n);
- if (it != services.end())
- return it->second;
-
- if (aliases != NULL)
- {
- std::map<Anope::string, Anope::string>::const_iterator it2 = aliases->find(n);
- if (it2 != aliases->end())
- return FindService(services, aliases, it2->second);
- }
-
- return NULL;
+ ServiceManager::Get()->RegisterReference(this);
}
-Service *Service::FindService(const Anope::string &t, const Anope::string &n)
+ServiceReferenceBase::ServiceReferenceBase(const Anope::string &_type) : ServiceReferenceBase(_type, "")
{
- check();
-
- std::map<Anope::string, std::map<Anope::string, Service *> >::const_iterator it = (*Services).find(t);
- if (it == (*Services).end())
- return NULL;
-
- std::map<Anope::string, std::map<Anope::string, Anope::string> >::const_iterator it2 = (*Aliases).find(t);
- if (it2 != (*Aliases).end())
- return FindService(it->second, &it2->second, n);
-
- return FindService(it->second, NULL, n);
}
-std::vector<Anope::string> Service::GetServiceKeys(const Anope::string &t)
+ServiceReferenceBase::~ServiceReferenceBase()
{
- check();
-
- std::vector<Anope::string> keys;
- std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = (*Services).find(t);
- if (it != (*Services).end())
- for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
- keys.push_back(it2->first);
- return keys;
+ ServiceManager::Get()->UnregisterReference(this);
}
-void Service::AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v)
+void ServiceReferenceBase::SetService(Service *service)
{
- check();
-
- std::map<Anope::string, Anope::string> &smap = (*Aliases)[t];
- smap[n] = v;
+ if (service == nullptr)
+ this->services.clear();
+ else
+ this->services = { service };
}
-void Service::DelAlias(const Anope::string &t, const Anope::string &n)
+void ServiceReferenceBase::SetServices(const std::vector<Service *> &s)
{
- check();
-
- std::map<Anope::string, Anope::string> &smap = (*Aliases)[t];
- smap.erase(n);
- if (smap.empty())
- (*Aliases).erase(t);
+ this->services = s;
}
Service::Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n)
{
- this->Register();
+ ServiceManager::Get()->Register(this);
}
Service::~Service()
{
- this->Unregister();
-}
-
-void Service::Register()
-{
- check();
-
- std::map<Anope::string, Service *> &smap = (*Services)[this->type];
- if (smap.find(this->name) != smap.end())
- throw ModuleException("Service " + this->type + " with name " + this->name + " already exists");
- smap[this->name] = this;
-
- ReferenceBase::ResetAll();
-}
-
-void Service::Unregister()
-{
- check();
-
- std::map<Anope::string, Service *> &smap = (*Services)[this->type];
- smap.erase(this->name);
- if (smap.empty())
- (*Services).erase(this->type);
+ ServiceManager::Get()->Unregister(this);
}
ServiceAlias::ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from)
{
- Service::AddAlias(type, from, to);
+ ServiceManager::Get()->AddAlias(type, from, to);
}
ServiceAlias::~ServiceAlias()
{
- Service::DelAlias(t, f);
+ ServiceManager::Get()->DelAlias(t, f);
}
diff --git a/src/service_manager.cpp b/src/service_manager.cpp
new file mode 100644
index 000000000..0d9255c7d
--- /dev/null
+++ b/src/service_manager.cpp
@@ -0,0 +1,144 @@
+/*
+ *
+ * (C) 2016 Anope Team
+ * (C) 2016 Adam <Adam@anope.org>
+ *
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ */
+
+#include "services.h"
+#include "service.h"
+#include "logger.h"
+
+ServiceManager *ServiceManager::manager = nullptr;
+
+void ServiceManager::Init()
+{
+ assert(manager == nullptr);
+ manager = new ServiceManager();
+}
+
+ServiceManager *ServiceManager::Get()
+{
+ return manager;
+}
+
+void ServiceManager::Destroy()
+{
+ delete manager;
+ manager = nullptr;
+}
+
+Service *ServiceManager::FindService(const Anope::string &name)
+{
+ for (Service *s : services)
+ if (s->GetName() == name)
+ return s;
+ return nullptr;
+}
+
+Service *ServiceManager::FindService(const Anope::string &type, const Anope::string &name)
+{
+ for (Service *s : services)
+ if (s->GetType() == type && s->GetName() == name)
+ return s;
+ return nullptr;
+}
+
+std::vector<Service *> ServiceManager::FindServices(const Anope::string &type)
+{
+ std::vector<Service *> v;
+
+ for (Service *s : services)
+ if (s->GetType() == type)
+ v.push_back(s);
+
+ return v;
+}
+
+void ServiceManager::AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v)
+{
+#warning "aliases dont work"
+// std::map<Anope::string, Anope::string> &smap = aliases[t];
+// smap[n] = v;
+}
+
+void ServiceManager::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);
+}
+
+void ServiceManager::Register(Service *service)
+{
+ // assert type
+ if (service->GetType().empty())
+ throw ModuleException("Service type must be non empty");
+
+ if (service->GetName().empty() == false)
+ {
+ Service *s = FindService(service->GetType(), service->GetName());
+
+ if (s != nullptr)
+ throw ModuleException("Service of type " + service->GetType() + " with name " + service->GetName() + " already exists");
+ }
+
+ Log(LOG_DEBUG_2) << "Service registered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(this) << " by " << service->GetOwner();
+
+ services.push_back(service);
+
+ LookupAll();
+}
+
+void ServiceManager::Unregister(Service *service)
+{
+ Log(LOG_DEBUG_2) << "Service unregistered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(service) << " by " << service->GetOwner();
+
+ auto it = std::find(services.begin(), services.end(), service);
+ if (it != services.end())
+ {
+ services.erase(it);
+
+ LookupAll();
+ }
+}
+
+void ServiceManager::Lookup(ServiceReferenceBase *reference)
+{
+ if (reference->GetName().empty())
+ {
+ std::vector<Service *> services = this->FindServices(reference->GetType());
+ Log(LOG_DEBUG_2) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << services.size() << " services";
+ reference->SetServices(services);
+ }
+ else
+ {
+ Service *service = this->FindService(reference->GetType(), reference->GetName());
+ Log(LOG_DEBUG_2) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << service;
+ reference->SetService(service);
+ }
+}
+
+void ServiceManager::LookupAll()
+{
+ for (ServiceReferenceBase *s : references)
+ Lookup(s);
+}
+
+void ServiceManager::RegisterReference(ServiceReferenceBase *reference)
+{
+ Lookup(reference);
+ this->references.push_back(reference);
+}
+
+void ServiceManager::UnregisterReference(ServiceReferenceBase *reference)
+{
+ auto it = std::find(this->references.begin(), this->references.end(), reference);
+ if (it != this->references.end())
+ this->references.erase(it);
+}
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 5b585ce09..91f9c6264 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -56,7 +56,7 @@ void Uplink::Connect()
new UplinkSocket();
if (!Config->GetBlock("serverinfo")->Get<Anope::string>("localhost").empty())
UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<Anope::string>("localhost"));
- Event::OnPreServerConnect(&Event::PreServerConnect::OnPreServerConnect);
+ EventManager::Get()->Dispatch(&Event::PreServerConnect::OnPreServerConnect);
Anope::string ip = Anope::Resolve(u.host, u.ipv6 ? AF_INET6 : AF_INET);
Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << "), port " << u.port;
UplinkSock->Connect(ip, u.port);
@@ -82,7 +82,7 @@ UplinkSocket::~UplinkSocket()
if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced())
{
- Event::OnServerDisconnect(&Event::ServerDisconnect::OnServerDisconnect);
+ EventManager::Get()->Dispatch(&Event::ServerDisconnect::OnServerDisconnect);
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
@@ -149,7 +149,7 @@ void UplinkSocket::OnConnect()
{
Log(LOG_TERMINAL) << "Successfully connected to uplink #" << (Anope::CurrentUplink + 1) << " " << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port;
IRCD->SendConnect();
- Event::OnServerConnect(&Event::ServerConnect::OnServerConnect);
+ EventManager::Get()->Dispatch(&Event::ServerConnect::OnServerConnect);
}
void UplinkSocket::OnError(const Anope::string &err)
diff --git a/src/users.cpp b/src/users.cpp
index 850cd8de8..87366676b 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -29,8 +29,6 @@
user_map UserListByNick, UserListByUID;
int OperCount = 0;
-unsigned MaxUserCount = 0;
-time_t MaxUserTime = 0;
std::list<User *> User::quitting_users;
@@ -74,18 +72,10 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!uip.empty() && uip != host ? "[" + uip + "] " : "") << "connected to the network (" << sserver->GetName() << ")";
}
- if (UserListByNick.size() > MaxUserCount)
- {
- MaxUserCount = UserListByNick.size();
- MaxUserTime = Anope::CurTime;
- if (sserver && sserver->IsSynced())
- Log(this, "maxusers") << "connected - new maximum user count: " << UserListByNick.size();
- }
-
bool exempt = false;
if (server && server->IsULined())
exempt = true;
- Event::OnUserConnect(&Event::UserConnect::OnUserConnect, this, exempt);
+ EventManager::Get()->Dispatch(&Event::UserConnect::OnUserConnect, this, exempt);
}
static void CollideKill(User *target, const Anope::string &reason)
@@ -154,12 +144,9 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts)
this->nick = newnick;
else
{
- if (NickServ::service)
- {
- NickServ::Nick *old_na = NickServ::service->FindNick(this->nick);
- if (old_na && (this->IsIdentified(true) || this->IsRecognized()))
- old_na->SetLastSeen(Anope::CurTime);
- }
+ NickServ::Nick *old_na = NickServ::FindNick(this->nick);
+ if (old_na && (this->IsIdentified(true) || this->IsRecognized()))
+ old_na->SetLastSeen(Anope::CurTime);
UserListByNick.erase(this->nick);
@@ -191,7 +178,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts)
}
}
- Event::OnUserNickChange(&Event::UserNickChange::OnUserNickChange, this, old);
+ EventManager::Get()->Dispatch(&Event::UserNickChange::OnUserNickChange, this, old);
}
void User::SetDisplayedHost(const Anope::string &shost)
@@ -203,7 +190,7 @@ void User::SetDisplayedHost(const Anope::string &shost)
Log(this, "host") << "changed vhost to " << shost;
- Event::OnSetDisplayedHost(&Event::SetDisplayedHost::OnSetDisplayedHost, this);
+ EventManager::Get()->Dispatch(&Event::SetDisplayedHost::OnSetDisplayedHost, this);
this->UpdateHost();
}
@@ -290,14 +277,12 @@ void User::SetRealname(const Anope::string &srealname)
throw CoreException("realname empty in SetRealname");
this->realname = srealname;
- if (NickServ::service)
- {
- //XXX event
- NickServ::Nick *na = NickServ::service->FindNick(this->nick);
- if (na && (this->IsIdentified(true) || this->IsRecognized()))
- na->SetLastRealname(srealname);
- }
+ //XXX event
+ NickServ::Nick *na = NickServ::FindNick(this->nick);
+
+ if (na && (this->IsIdentified(true) || this->IsRecognized()))
+ na->SetLastRealname(srealname);
Log(this, "realname") << "changed realname to " << srealname;
}
@@ -311,7 +296,7 @@ User::~User()
--this->server->users;
}
- Event::OnPreUserLogoff(&Event::PreUserLogoff::OnPreUserLogoff, this);
+ EventManager::Get()->Dispatch(&Event::PreUserLogoff::OnPreUserLogoff, this);
ModeManager::StackerDel(this);
this->Logout();
@@ -326,7 +311,7 @@ User::~User()
if (!this->uid.empty())
UserListByUID.erase(this->uid);
- Event::OnPostUserLogoff(&Event::PostUserLogoff::OnPostUserLogoff, this);
+ EventManager::Get()->Dispatch(&Event::PostUserLogoff::OnPostUserLogoff, this);
}
void User::SendMessage(const MessageSource &source, const Anope::string &msg)
@@ -348,8 +333,6 @@ void User::SendMessage(const MessageSource &source, const Anope::string &msg)
Anope::string buf;
for (Anope::string word; ssep.GetToken(word);)
{
- if (word.empty())
- word = " ";
Anope::string add = buf.empty() ? word : " " + word;
if (buf.length() + add.length() > Config->LineWrap)
{
@@ -387,7 +370,7 @@ void User::Identify(NickServ::Nick *na)
this->Login(na->GetAccount());
- Event::OnNickIdentify(&Event::NickIdentify::OnNickIdentify, this);
+ EventManager::Get()->Dispatch(&Event::NickIdentify::OnNickIdentify, this);
if (this->IsServicesOper())
{
@@ -424,7 +407,7 @@ void User::Login(NickServ::Account *core)
if (this->server->IsSynced())
Log(this, "account") << "is now identified as " << this->nc->GetDisplay();
- Event::OnUserLogin(&Event::UserLogin::OnUserLogin, this);
+ EventManager::Get()->Dispatch(&Event::UserLogin::OnUserLogin, this);
}
void User::Logout()
@@ -495,7 +478,7 @@ bool User::IsServicesOper()
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnIsServicesOper(&Event::IsServicesOperEvent::IsServicesOper, this);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::IsServicesOperEvent::IsServicesOper, this);
if (MOD_RESULT == EVENT_STOP)
return false;
@@ -522,7 +505,7 @@ void User::UpdateHost()
return;
//XXX event
- NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr;
+ NickServ::Nick *na = NickServ::FindNick(this->nick);
on_access = false;
if (na)
on_access = na->GetAccount()->IsOnAccess(this);
@@ -575,7 +558,7 @@ void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anop
if (um->name == "CLOAK" || um->name == "VHOST")
this->UpdateHost();
- Event::OnUserModeSet(&Event::UserModeSet::OnUserModeSet, source, this, um->name);
+ EventManager::Get()->Dispatch(&Event::UserModeSet::OnUserModeSet, source, this, um->name);
}
void User::RemoveModeInternal(const MessageSource &source, UserMode *um)
@@ -594,7 +577,7 @@ void User::RemoveModeInternal(const MessageSource &source, UserMode *um)
this->UpdateHost();
}
- Event::OnUserModeUnset(&Event::UserModeUnset::OnUserModeUnset, source, this, um->name);
+ EventManager::Get()->Dispatch(&Event::UserModeUnset::OnUserModeUnset, source, this, um->name);
}
void User::SetMode(ServiceBot *bi, UserMode *um, const Anope::string &param)
@@ -781,7 +764,7 @@ void User::Quit(const Anope::string &reason)
return;
}
- Event::OnUserQuit(&Event::UserQuit::OnUserQuit, this, reason);
+ EventManager::Get()->Dispatch(&Event::UserQuit::OnUserQuit, this, reason);
this->quit = true;
quitting_users.push_back(this);
diff --git a/src/xline.cpp b/src/xline.cpp
index 9d518a659..9601db54f 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -88,36 +88,30 @@ void XLine::Recache()
}
}
-XLine::XLine(const Anope::string &ma, const Anope::string &r, const Anope::string &uid) : Serialize::Object(xline)
+XLine::~XLine()
{
- SetMask(ma);
- SetReason(r);
- SetID(id);
+ delete regex;
+ delete c;
}
-XLine::XLine(const Anope::string &ma, const Anope::string &b, const time_t ex, const Anope::string &r, const Anope::string &uid) : Serialize::Object(xline)
+void XLine::SetType(const Anope::string &t)
{
- SetMask(ma);
- SetBy(b);
- SetReason(r);
- SetID(id);
+ Set(&XLineType::type, t);
}
-XLine::~XLine()
+Anope::string XLine::GetType()
{
- delete regex;
- delete c;
+ return Get(&XLineType::type);
}
void XLine::SetMask(const Anope::string &m)
{
Set(&XLineType::mask, m);
- Recache();
}
Anope::string XLine::GetMask()
{
- return Get(&XLineType::mask);
+ return Get<Anope::string>(&XLineType::mask);
}
void XLine::SetBy(const Anope::string &b)
@@ -209,6 +203,17 @@ bool XLine::IsRegex()
return mask.length() > 2 && mask[0] == '/' && mask[mask.length() - 1] == '/';
}
+XLineManager *XLine::GetManager()
+{
+ return ServiceManager::Get()->FindService<XLineManager *>(GetType());
+}
+
+void XLineType::Mask::SetField(XLine *s, const Anope::string &value)
+{
+ Serialize::Field<XLine, Anope::string>::SetField(s, value);
+ s->Recache();
+}
+
void XLineManager::RegisterXLineManager(XLineManager *xlm)
{
XLineManagers.push_back(xlm);
@@ -231,32 +236,20 @@ void XLineManager::CheckAll(User *u)
Anope::string XLineManager::GenerateUID()
{
Anope::string id;
- int count = 0;
- do
- {
- id.clear();
-
- if (++count > 10)
- {
- Log(LOG_DEBUG) << "Unable to generate XLine UID";
- break;
- }
- for (int i = 0; i < 10; ++i)
- {
- char c;
- do
- c = (rand() % 75) + 48;
- while (!isupper(c) && !isdigit(c));
- id += c;
- }
+ for (int i = 0; i < 10; ++i)
+ {
+ char c;
+ do
+ c = (rand() % 75) + 48;
+ while (!isupper(c) && !isdigit(c));
+ id += c;
}
- while (0);//XLinesByUID.count(id) > 0);
return id;
}
-XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service(creator, "XLineManager", xname), type(t)
+XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service(creator, NAME, xname), type(t)
{
}
@@ -274,8 +267,8 @@ std::vector<XLine *> XLineManager::GetXLines() const
{
std::vector<XLine *> xlines;
- for (XLine *x : Serialize::GetObjects<XLine *>(xline))
- if (x->manager == this)
+ for (XLine *x : Serialize::GetObjects<XLine *>())
+ if (x->GetType() == this->GetName())
xlines.push_back(x);
return xlines;
@@ -283,8 +276,7 @@ std::vector<XLine *> XLineManager::GetXLines() const
void XLineManager::AddXLine(XLine *x)
{
- // XXX this needs to always be set
- x->manager = this;
+ x->SetType(this->GetName());
}
XLine* XLineManager::GetEntry(unsigned index)
@@ -359,7 +351,7 @@ XLine* XLineManager::HasEntry(const Anope::string &mask)
XLine *XLineManager::CheckAllXLines(User *u)
{
- for (XLine *x : Serialize::GetObjects<XLine *>(xline))
+ for (XLine *x : Serialize::GetObjects<XLine *>())
{
if (x->GetExpires() && x->GetExpires() < Anope::CurTime)
{