From 70be9c79d284982d03744443b84268bef44a3080 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Wed, 22 Nov 2017 12:37:20 +0000 Subject: [PATCH] Move OnSync{Channel,Network,User} to ServerEventListener. --- include/modules.h | 37 +++---------------------- include/modules/server.h | 20 +++++++++++++ src/modules.cpp | 3 -- src/modules/m_filter.cpp | 8 ++++-- src/modules/m_spanningtree/netburst.cpp | 9 +++--- 5 files changed, 34 insertions(+), 43 deletions(-) diff --git a/include/modules.h b/include/modules.h index ce2402964..5dee6bfb6 100644 --- a/include/modules.h +++ b/include/modules.h @@ -230,8 +230,8 @@ enum Implementation I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick, - I_OnUserMessage, I_OnMode, I_OnSyncUser, - I_OnSyncChannel, I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit, + I_OnUserMessage, I_OnMode, + I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit, I_OnChangeHost, I_OnChangeName, I_OnAddLine, I_OnDelLine, I_OnExpireLine, I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnLoadModule, I_OnUnloadModule, I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite, @@ -239,7 +239,7 @@ enum Implementation I_OnStats, I_OnChangeLocalUserHost, I_OnPreTopicChange, I_OnPostTopicChange, I_OnPostConnect, I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete, - I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnPostCommand, I_OnPostJoin, + I_OnPostOper, I_OnSetAway, I_OnPostCommand, I_OnPostJoin, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass, I_OnText, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric, I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent, I_OnSetUserIP, @@ -581,40 +581,11 @@ class CoreExport Module : public classbase, public usecountbase */ virtual void OnMode(User* user, User* usertarget, Channel* chantarget, const Modes::ChangeList& changelist, ModeParser::ModeProcessFlag processflags, const std::string& output_mode); - /** Allows modules to synchronize data which relates to users during a netburst. - * When this function is called, it will be called from the module which implements - * the linking protocol. This currently is m_spanningtree.so. - * This function will be called for every user visible on your side - * of the burst, allowing you to for example set modes, etc. - * @param user The user being syncronized - * @param server The target of the burst - */ - virtual void OnSyncUser(User* user, ProtocolServer& server); - - /** Allows modules to synchronize data which relates to channels during a netburst. - * When this function is called, it will be called from the module which implements - * the linking protocol. This currently is m_spanningtree.so. - * This function will be called for every channel visible on your side of the burst, - * allowing you to for example set modes, etc. - * - * @param chan The channel being syncronized - * @param server The target of the burst - */ - virtual void OnSyncChannel(Channel* chan, ProtocolServer& server); - - /** Allows modules to syncronize metadata not related to users or channels, over the network during a netburst. - * When the linking module has finished sending all data it wanted to send during a netburst, then - * this method is called. You should use the SendMetaData() function after you've - * correctly decided how the data should be represented, to send the data. - * @param server The target of the burst - */ - virtual void OnSyncNetwork(ProtocolServer& server); - /** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module. * Please see src/modules/m_swhois.cpp for a working example of how to use this method call. * @param target The Channel* or User* that data should be added to * @param extname The extension name which is being sent - * @param extdata The extension data, encoded at the other end by an identical module through OnSyncChannelMetaData or OnSyncUserMetaData + * @param extdata The extension data, encoded at the other end by an identical module */ virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata); diff --git a/include/modules/server.h b/include/modules/server.h index 8e64a3b35..99bd2ee1d 100644 --- a/include/modules/server.h +++ b/include/modules/server.h @@ -38,4 +38,24 @@ class ServerEventListener : public Events::ModuleEventListener * @param server Server that split */ virtual void OnServerSplit(const Server* server) { } + + /** Allows modules to synchronize user metadata during a netburst. This will + * be called for every user visible on your side of the burst. + * @param user The user being synchronized. + * @param server The target of the burst. + */ + virtual void OnSyncUser(User* user, ProtocolServer& server) { } + + /** Allows modules to synchronize channel metadata during a netburst. This will + * be called for every channel visible on your side of the burst. + * @param chan The channel being synchronized. + * @param server The target of the burst. + */ + virtual void OnSyncChannel(Channel* chan, ProtocolServer& server) { } + + /** Allows modules to synchronize network metadata during a netburst. + * @param server The target of the burst. + */ + virtual void OnSyncNetwork(ProtocolServer& server) { } + }; diff --git a/src/modules.cpp b/src/modules.cpp index 65e0a53ca..f204f3fc1 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -116,9 +116,6 @@ void Module::OnPostConnect(User*) { DetachEvent(I_OnPostConnect); } void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { DetachEvent(I_OnUserMessage); } void Module::OnUserInvite(User*, User*, Channel*, time_t, unsigned int, CUList&) { DetachEvent(I_OnUserInvite); } void Module::OnPostTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPostTopicChange); } -void Module::OnSyncUser(User*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncUser); } -void Module::OnSyncChannel(Channel*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncChannel); } -void Module::OnSyncNetwork(ProtocolInterface::Server&) { DetachEvent(I_OnSyncNetwork); } void Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { DetachEvent(I_OnDecodeMetaData); } void Module::OnChangeHost(User*, const std::string&) { DetachEvent(I_OnChangeHost); } void Module::OnChangeName(User*, const std::string&) { DetachEvent(I_OnChangeName); } diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 8e43d2767..27c511c16 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -23,6 +23,7 @@ #include "inspircd.h" #include "xline.h" #include "modules/regex.h" +#include "modules/server.h" enum FilterFlags { @@ -154,7 +155,7 @@ class CommandFilter : public Command } }; -class ModuleFilter : public Module +class ModuleFilter : public Module, public ServerEventListener { typedef insp::flat_set ExemptTargetSet; @@ -292,7 +293,10 @@ bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags) } ModuleFilter::ModuleFilter() - : initing(true), filtcommand(this), RegexEngine(this, "regex") + : ServerEventListener(this) + , initing(true) + , filtcommand(this) + , RegexEngine(this, "regex") { } diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index cdafa9ded..5115c7aa8 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -27,6 +27,7 @@ #include "treeserver.h" #include "main.h" #include "commands.h" +#include "modules/server.h" /** * Creates FMODE messages, used only when syncing channels @@ -122,7 +123,7 @@ void TreeSocket::DoBurst(TreeServer* s) // Send all xlines this->SendXLines(); - FOREACH_MOD(OnSyncNetwork, (bs.server)); + FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), ServerEventListener, OnSyncNetwork, (bs.server)); this->WriteLine(CmdBuilder("ENDBURST")); ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+ s->GetName()+"\2."); @@ -261,7 +262,7 @@ void TreeSocket::SyncChannel(Channel* chan, BurstState& bs) this->WriteLine(CommandMetadata::Builder(chan, item->name, value)); } - FOREACH_MOD(OnSyncChannel, (chan, bs.server)); + FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), ServerEventListener, OnSyncChannel, (chan, bs.server)); } void TreeSocket::SyncChannel(Channel* chan) @@ -273,8 +274,6 @@ void TreeSocket::SyncChannel(Channel* chan) /** Send all users and their state, including oper and away status and global metadata */ void TreeSocket::SendUsers(BurstState& bs) { - ProtocolInterface::Server& piserver = bs.server; - const user_hash& users = ServerInstance->Users->GetUsers(); for (user_hash::const_iterator u = users.begin(); u != users.end(); ++u) { @@ -299,6 +298,6 @@ void TreeSocket::SendUsers(BurstState& bs) this->WriteLine(CommandMetadata::Builder(user, item->name, value)); } - FOREACH_MOD(OnSyncUser, (user, piserver)); + FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), ServerEventListener, OnSyncUser, (user, bs.server)); } } -- 2.39.5