From 3624c137a6db85eaab0372550c9dca79d6d21e55 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Thu, 13 Jun 2013 18:15:34 +0200 Subject: Introduce ModeProcessFlags, can be passed to ModeParser::Process() to indicate local only mode changes and mode merges Change ProtocolInterface::SendMode() to take source and destination parameters, and call it from the mode parser whenever the mode change is global This deprecates the ambiguous InspIRCd::SendMode() and InspIRCd::SendGlobalMode() interface (the latter sent mode changes originating from local users twice, etc.) --- src/modules/m_spanningtree/fjoin.cpp | 4 +-- src/modules/m_spanningtree/fmode.cpp | 30 +++++++++--------- src/modules/m_spanningtree/main.cpp | 29 +----------------- src/modules/m_spanningtree/main.h | 1 - src/modules/m_spanningtree/protocolinterface.cpp | 39 ++++++++++-------------- src/modules/m_spanningtree/protocolinterface.h | 3 +- 6 files changed, 36 insertions(+), 70 deletions(-) (limited to 'src/modules/m_spanningtree') diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp index b25444cda..faf534542 100644 --- a/src/modules/m_spanningtree/fjoin.cpp +++ b/src/modules/m_spanningtree/fjoin.cpp @@ -130,7 +130,7 @@ CmdResult CommandFJoin::Handle(const std::vector& params, User *src /* Remember, params[params.size() - 1] is userlist, and we don't want to apply *that* */ modelist.insert(modelist.end(), params.begin()+2, params.end()-1); - ServerInstance->SendMode(modelist, srcuser); + ServerInstance->Modes->Process(modelist, srcuser, ModeParser::MODE_LOCALONLY | ModeParser::MODE_MERGE); } irc::modestacker modestack(true); @@ -222,7 +222,7 @@ void CommandFJoin::ApplyModeStack(User* srcuser, Channel* c, irc::modestacker& s while (stack.GetStackedLine(stackresult)) { - ServerInstance->SendMode(stackresult, srcuser); + ServerInstance->Modes->Process(stackresult, srcuser, ModeParser::MODE_LOCALONLY); stackresult.erase(stackresult.begin() + 1, stackresult.end()); } } diff --git a/src/modules/m_spanningtree/fmode.cpp b/src/modules/m_spanningtree/fmode.cpp index 7be904faf..9a72c5f05 100644 --- a/src/modules/m_spanningtree/fmode.cpp +++ b/src/modules/m_spanningtree/fmode.cpp @@ -55,23 +55,25 @@ CmdResult CommandFMode::Handle(const std::vector& params, User *who ourTS = user->age; } - /* TS is equal or less: Merge the mode changes into ours and pass on. + /* If the TS is greater than ours, we drop the mode and don't pass it anywhere. */ - if (TS <= ourTS) - { - std::vector modelist; - modelist.reserve(params.size()-1); - /* Insert everything into modelist except the TS (params[1]) */ - modelist.push_back(params[0]); - modelist.insert(modelist.end(), params.begin()+2, params.end()); + if (TS > ourTS) + return CMD_FAILURE; - bool merge = (TS == ourTS) && IS_SERVER(who); - ServerInstance->Modes->Process(modelist, who, merge); - return CMD_SUCCESS; - } - /* If the TS is greater than ours, we drop the mode and dont pass it anywhere. + /* TS is equal or less: Merge the mode changes into ours and pass on. */ - return CMD_FAILURE; + std::vector modelist; + modelist.reserve(params.size()-1); + /* Insert everything into modelist except the TS (params[1]) */ + modelist.push_back(params[0]); + modelist.insert(modelist.end(), params.begin()+2, params.end()); + + ModeParser::ModeProcessFlag flags = ModeParser::MODE_LOCALONLY; + if ((TS == ourTS) && IS_SERVER(who)) + flags |= ModeParser::MODE_MERGE; + + ServerInstance->Modes->Process(modelist, who, flags); + return CMD_SUCCESS; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 9af4bfd0c..8c5439fbb 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -77,7 +77,7 @@ void ModuleSpanningTree::init() I_OnUserMessage, I_OnBackgroundTimer, I_OnUserJoin, I_OnChangeHost, I_OnChangeName, I_OnChangeIdent, I_OnUserPart, I_OnUnloadModule, I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRehash, I_OnPreRehash, - I_OnOper, I_OnAddLine, I_OnDelLine, I_OnMode, I_OnLoadModule, I_OnStats, + I_OnOper, I_OnAddLine, I_OnDelLine, I_OnLoadModule, I_OnStats, I_OnSetAway, I_OnPostCommand, I_OnUserConnect, I_OnAcceptConnection }; ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); @@ -793,33 +793,6 @@ void ModuleSpanningTree::OnDelLine(User* user, XLine *x) } } -void ModuleSpanningTree::OnMode(User* user, void* dest, int target_type, const parameterlist &text, const std::vector &translate) -{ - if ((IS_LOCAL(user)) && (user->registered == REG_ALL)) - { - parameterlist params; - std::string output_text; - - ServerInstance->Parser->TranslateUIDs(translate, text, output_text); - - if (target_type == TYPE_USER) - { - User* u = (User*)dest; - params.push_back(u->uuid); - params.push_back(output_text); - Utils->DoOneToMany(user->uuid, "MODE", params); - } - else - { - Channel* c = (Channel*)dest; - params.push_back(c->name); - params.push_back(ConvToStr(c->age)); - params.push_back(output_text); - Utils->DoOneToMany(user->uuid, "FMODE", params); - } - } -} - ModResult ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg) { if (IS_LOCAL(user)) diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 22357aed4..28ebbc373 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -163,7 +163,6 @@ class ModuleSpanningTree : public Module void OnLine(User* source, const std::string &host, bool adding, char linetype, long duration, const std::string &reason); void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE; void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE; - void OnMode(User* user, void* dest, int target_type, const std::vector &text, const std::vector &translate) CXX11_OVERRIDE; ModResult OnStats(char statschar, User* user, string_list &results) CXX11_OVERRIDE; ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE; void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::vector &modeline, const std::vector &translate); diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp index 93a138758..ce824fef8 100644 --- a/src/modules/m_spanningtree/protocolinterface.cpp +++ b/src/modules/m_spanningtree/protocolinterface.cpp @@ -89,35 +89,28 @@ void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &top Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params); } -void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::vector &translate) +void SpanningTreeProtocolInterface::SendMode(User* source, User* u, Channel* c, const parameterlist& modedata, const std::vector& translate) { - if (modedata.empty()) - return; - - std::string outdata; - ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata); - - std::string uidtarget; - ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget); - - parameterlist outlist; - outlist.push_back(uidtarget); - outlist.push_back(outdata); + parameterlist params; - User* a = ServerInstance->FindNick(uidtarget); - if (a) + if (u) { - Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist); - return; + if (u->registered != REG_ALL) + return; + + params.push_back(u->uuid); + params.insert(params.end(), modedata.begin(), modedata.end()); + Utils->DoOneToMany(source->uuid, "MODE", params); } else { - Channel* c = ServerInstance->FindChan(target); - if (c) - { - outlist.insert(outlist.begin() + 1, ConvToStr(c->age)); - Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist); - } + std::string output_text; + ServerInstance->Parser->TranslateUIDs(translate, modedata, output_text); + + params.push_back(c->name); + params.push_back(ConvToStr(c->age)); + params.push_back(output_text); + Utils->DoOneToMany(source->uuid, "FMODE", params); } } diff --git a/src/modules/m_spanningtree/protocolinterface.h b/src/modules/m_spanningtree/protocolinterface.h index 80a21c49b..2b4c4371f 100644 --- a/src/modules/m_spanningtree/protocolinterface.h +++ b/src/modules/m_spanningtree/protocolinterface.h @@ -25,14 +25,13 @@ class ModuleSpanningTree; class SpanningTreeProtocolInterface : public ProtocolInterface { SpanningTreeUtilities* Utils; - void SendChannel(Channel* target, char status, const std::string &text); public: SpanningTreeProtocolInterface(SpanningTreeUtilities* util) : Utils(util) { } bool SendEncapsulatedData(const parameterlist &encap); void SendMetaData(Extensible* target, const std::string &key, const std::string &data); void SendTopic(Channel* channel, std::string &topic); - void SendMode(const std::string &target, const parameterlist &modedata, const std::vector &types); + void SendMode(User* source, User* usertarget, Channel* chantarget, const parameterlist& modedata, const std::vector& types); void SendSNONotice(const std::string &snomask, const std::string &text); void PushToClient(User* target, const std::string &rawline); void SendChannelPrivmsg(Channel* target, char status, const std::string &text); -- cgit v1.2.3