From 14d102b7502e15ff091bd4d14a4d5d5ead9eddb3 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sat, 19 May 2012 12:21:02 +0200 Subject: m_spanningtree Fix various bugs related to protocol interface and ENCAP handling Most importantly: - Match the server name not the SID for determining if an incoming ENCAP should be processed by us - Handle the ? wildcard properly in the server name parameter of an ENCAP - Send single target ENCAPs to the destination only instead of broadcasting it - Make ProtocolInterface::SendMetaData accept TYPE_OTHER as target_type (on par with ProtoSendMetaData) instead of throwing an exception --- src/modules/m_spanningtree/protocolinterface.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/modules/m_spanningtree/protocolinterface.cpp') diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp index 6e68e2a52..9bd0263dc 100644 --- a/src/modules/m_spanningtree/protocolinterface.cpp +++ b/src/modules/m_spanningtree/protocolinterface.cpp @@ -48,7 +48,14 @@ void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl) void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap) { - Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap); + if (encap.size() < 2) + return; + + const std::string& target = encap[0]; + if (target.find_first_of("*?") == std::string::npos) + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "ENCAP", encap, target); + else + Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap); } void SpanningTreeProtocolInterface::SendMetaData(void* target, TargetTypeFlags type, const std::string &key, const std::string &data) @@ -63,12 +70,10 @@ void SpanningTreeProtocolInterface::SendMetaData(void* target, TargetTypeFlags t case TYPE_CHANNEL: params.push_back(((Channel*)target)->name); break; + case TYPE_OTHER: case TYPE_SERVER: params.push_back("*"); break; - default: - throw CoreException("I don't know how to handle TYPE_OTHER."); - break; } params.push_back(key); params.push_back(":" + data); @@ -179,7 +184,7 @@ void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::str TreeSocket* sock = serv->GetSocket(); if (sock) { - sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->nick + " :"+text); + sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->uuid + " :"+text); } } } @@ -192,7 +197,7 @@ void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::stri TreeSocket* sock = serv->GetSocket(); if (sock) { - sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->nick + " :"+text); + sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->uuid + " :"+text); } } } -- cgit v1.3.1-10-gc9f91 From 94fa5102cc44614024dffc9ce37de99d1b3cb596 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sat, 19 May 2012 12:30:38 +0200 Subject: m_spanningtree Remove low level stuff from SpanningTreeProtocolInterface::SendUserPrivmsg/Notice, use utility functions like the rest of the protocol interface --- src/modules/m_spanningtree/protocolinterface.cpp | 26 ++++++++---------------- 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/modules/m_spanningtree/protocolinterface.cpp') diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp index 9bd0263dc..0e8e09916 100644 --- a/src/modules/m_spanningtree/protocolinterface.cpp +++ b/src/modules/m_spanningtree/protocolinterface.cpp @@ -178,28 +178,18 @@ void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char stat void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text) { - TreeServer* serv = Utils->FindServer(target->server); - if (serv) - { - TreeSocket* sock = serv->GetSocket(); - if (sock) - { - sock->WriteLine(":" + ServerInstance->Config->GetSID() + " PRIVMSG " + target->uuid + " :"+text); - } - } + parameterlist p; + p.push_back(target->uuid); + p.push_back(":" + text); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PRIVMSG", p, target->server); } void SpanningTreeProtocolInterface::SendUserNotice(User* target, const std::string &text) { - TreeServer* serv = Utils->FindServer(target->server); - if (serv) - { - TreeSocket* sock = serv->GetSocket(); - if (sock) - { - sock->WriteLine(":" + ServerInstance->Config->GetSID() + " NOTICE " + target->uuid + " :"+text); - } - } + parameterlist p; + p.push_back(target->uuid); + p.push_back(":" + text); + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "NOTICE", p, target->server); } void SpanningTreeProtocolInterface::Introduce(User* user) -- cgit v1.3.1-10-gc9f91 From 9be03b56bab1a1acd92bf9b128f2bfeb7a5c2642 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sat, 19 May 2012 12:36:40 +0200 Subject: m_spanningtree Kill duplicated code in OnUserMessage/Notice, put code shared with the protocol interface into the utility class --- src/modules/m_spanningtree/main.cpp | 101 +++++------------------ src/modules/m_spanningtree/main.h | 1 + src/modules/m_spanningtree/protocolinterface.cpp | 23 +----- src/modules/m_spanningtree/protocolinterface.h | 1 - src/modules/m_spanningtree/utils.cpp | 17 ++++ src/modules/m_spanningtree/utils.h | 4 + 6 files changed, 45 insertions(+), 102 deletions(-) (limited to 'src/modules/m_spanningtree/protocolinterface.cpp') diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 226707103..d33bf6ee0 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -485,110 +485,47 @@ void ModuleSpanningTree::OnWallops(User* user, const std::string &text) } } -void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +void ModuleSpanningTree::LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const std::string& message_type) { - /* Server origin */ - if (user == NULL) - return; - if (target_type == TYPE_USER) { User* d = (User*)dest; - if ((d->GetFd() < 0) && (IS_LOCAL(user))) + if (IS_REMOTE(d)) { std::deque params; - params.clear(); params.push_back(d->uuid); params.push_back(":"+text); - Utils->DoOneToOne(user->uuid,"NOTICE",params,d->server); + Utils->DoOneToOne(user->uuid, message_type, params, d->server); } } else if (target_type == TYPE_CHANNEL) { - if (IS_LOCAL(user)) + Channel *c = (Channel*)dest; + if (c) { - Channel *c = (Channel*)dest; - if (c) - { - std::string cname = c->name; - if (status) - cname = status + cname; - TreeServerList list; - Utils->GetListOfServersForChannel(c,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = i->second->GetSocket(); - if (Sock) - Sock->WriteLine(":"+std::string(user->uuid)+" NOTICE "+cname+" :"+text); - } - } + Utils->SendChannelMessage(user->uuid, c, text, status, exempt_list, message_type); } } else if (target_type == TYPE_SERVER) { - if (IS_LOCAL(user)) - { - char* target = (char*)dest; - std::deque par; - par.push_back(target); - par.push_back(":"+text); - Utils->DoOneToMany(user->uuid,"NOTICE",par); - } + char* target = (char*)dest; + std::deque par; + par.push_back(target); + par.push_back(":"+text); + Utils->DoOneToMany(user->uuid, message_type, par); } } -void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { - /* Server origin */ - if (user == NULL) - return; + if ((user) && (IS_LOCAL(user))) + LocalMessage(user, dest, target_type, text, status, exempt_list, "NOTICE"); +} - if (target_type == TYPE_USER) - { - // route private messages which are targetted at clients only to the server - // which needs to receive them - User* d = (User*)dest; - if ((d->GetFd() < 0) && (IS_LOCAL(user))) - { - std::deque params; - params.clear(); - params.push_back(d->uuid); - params.push_back(":"+text); - Utils->DoOneToOne(user->uuid,"PRIVMSG",params,d->server); - } - } - else if (target_type == TYPE_CHANNEL) - { - if (IS_LOCAL(user)) - { - Channel *c = (Channel*)dest; - if (c) - { - std::string cname = c->name; - if (status) - cname = status + cname; - TreeServerList list; - Utils->GetListOfServersForChannel(c,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = i->second->GetSocket(); - if (Sock) - Sock->WriteLine(":"+std::string(user->uuid)+" PRIVMSG "+cname+" :"+text); - } - } - } - } - else if (target_type == TYPE_SERVER) - { - if (IS_LOCAL(user)) - { - char* target = (char*)dest; - std::deque par; - par.push_back(target); - par.push_back(":"+text); - Utils->DoOneToMany(user->uuid,"PRIVMSG",par); - } - } +void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +{ + if ((user) && (IS_LOCAL(user))) + LocalMessage(user, dest, target_type, text, status, exempt_list, "PRIVMSG"); } void ModuleSpanningTree::OnBackgroundTimer(time_t curtime) diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 9be1ee631..3d62146ac 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -58,6 +58,7 @@ class ModuleSpanningTree : public Module SpanningTreeUtilities* Utils; void RedoConfig(Module* mod, const std::string &name); + void LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const std::string& message_type); public: CacheRefreshTimer *RefreshTimer; diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp index 0e8e09916..243711453 100644 --- a/src/modules/m_spanningtree/protocolinterface.cpp +++ b/src/modules/m_spanningtree/protocolinterface.cpp @@ -149,31 +149,16 @@ void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", p, target->server); } -void SpanningTreeProtocolInterface::SendChannel(Channel* target, char status, const std::string &text) -{ - std::string cname = target->name; - if (status) - cname = status + cname; - TreeServerList list; - CUList exempt_list; - Utils->GetListOfServersForChannel(target,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = i->second->GetSocket(); - if (Sock) - Sock->WriteLine(text); - } -} - - void SpanningTreeProtocolInterface::SendChannelPrivmsg(Channel* target, char status, const std::string &text) { - SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" PRIVMSG "+target->name+" :"+text); + CUList exempt_list; + Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "PRIVMSG"); } void SpanningTreeProtocolInterface::SendChannelNotice(Channel* target, char status, const std::string &text) { - SendChannel(target, status, ":" + ServerInstance->Config->GetSID()+" NOTICE "+target->name+" :"+text); + CUList exempt_list; + Utils->SendChannelMessage(ServerInstance->Config->GetSID(), target, text, status, exempt_list, "NOTICE"); } void SpanningTreeProtocolInterface::SendUserPrivmsg(User* target, const std::string &text) diff --git a/src/modules/m_spanningtree/protocolinterface.h b/src/modules/m_spanningtree/protocolinterface.h index cfebf27d5..c3477db18 100644 --- a/src/modules/m_spanningtree/protocolinterface.h +++ b/src/modules/m_spanningtree/protocolinterface.h @@ -27,7 +27,6 @@ class SpanningTreeProtocolInterface : public ProtocolInterface { SpanningTreeUtilities* Utils; ModuleSpanningTree* Module; - void SendChannel(Channel* target, char status, const std::string &text); public: SpanningTreeProtocolInterface(ModuleSpanningTree* mod, SpanningTreeUtilities* util, InspIRCd* Instance) : ProtocolInterface(Instance), Utils(util), Module(mod) { } virtual ~SpanningTreeProtocolInterface() { } diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 781c5b1fc..d5c6b5157 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -684,3 +684,20 @@ Link* SpanningTreeUtilities::FindLink(const std::string& name) } return NULL; } + +void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const std::string& message_type) +{ + std::string raw = ":" + prefix + " " + message_type + " "; + if (status) + raw.append(1, status); + raw += target->name + " :" + text; + + TreeServerList list; + this->GetListOfServersForChannel(target, list, status, exempt_list); + for (TreeServerList::iterator i = list.begin(); i != list.end(); ++i) + { + TreeSocket* Sock = i->second->GetSocket(); + if (Sock) + Sock->WriteLine(raw); + } +} diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 10ab66a0e..ec81c6a93 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -222,6 +222,10 @@ class SpanningTreeUtilities : public classbase /** Refresh the IP cache used for allowing inbound connections */ void RefreshIPCache(); + + /** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix + */ + void SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const std::string& message_type); }; #endif -- cgit v1.3.1-10-gc9f91