From b76828d28b778b8e2c8d16f7a7c8018bea3fb442 Mon Sep 17 00:00:00 2001 From: brain Date: Sat, 3 Dec 2005 14:11:48 +0000 Subject: Fixed routing of channel privmsgs/notices to only go to servers that need them git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2124 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree.cpp | 71 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index a4f719398..073e6c7cd 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -1161,14 +1161,47 @@ class TreeSocket : public InspSocket } }; +void AddThisServer(TreeServer* server, std::deque &list) +{ + for (unsigned int c = 0; c < list.size(); c++) + { + if (list[c] == server) + { + return; + } + } + list.push_back(server); +} + +// returns a list of DIRECT servernames for a specific channel +std::deque GetListOfServersForChannel(chanrec* c) +{ + std::deque list; + std::vector *ulist = c->GetUsers(); + for (unsigned int i = 0; i < ulist->size(); i++) + { + char* o = (*ulist)[i]; + userrec* otheruser = (userrec*)o; + if (std::string(otheruser->server) != Srv->GetServerName()) + { + TreeServer* best = BestRouteTo(otheruser->server); + if (best) + AddThisServer(best,list); + } + } + return list; +} + bool DoOneToAllButSenderRaw(std::string data,std::string omit,std::string prefix,std::string command,std::deque params) { + TreeServer* omitroute = BestRouteTo(omit); if ((command == "NOTICE") || (command == "PRIVMSG")) { if (params.size() >= 2) { if (*(params[0].c_str()) != '#') { + // special routing for private messages/notices userrec* d = Srv->FindNick(params[0]); if (d) { @@ -1180,9 +1213,23 @@ bool DoOneToAllButSenderRaw(std::string data,std::string omit,std::string prefix return true; } } + else + { + chanrec* c = Srv->FindChannel(params[0]); + if (c) + { + std::deque list = GetListOfServersForChannel(c); + for (unsigned int i = 0; i < list.size(); i++) + { + TreeSocket* Sock = list[i]->GetSocket(); + if (Sock) + Sock->WriteLine(data); + } + return true; + } + } } } - TreeServer* omitroute = BestRouteTo(omit); for (unsigned int x = 0; x < TreeRoot->ChildCount(); x++) { TreeServer* Route = TreeRoot->GetChild(x); @@ -1551,10 +1598,13 @@ class ModuleSpanningTree : public Module if (std::string(user->server) == Srv->GetServerName()) { chanrec *c = (chanrec*)dest; - std::deque params; - params.push_back(c->name); - params.push_back(":"+text); - DoOneToMany(user->nick,"NOTICE",params); + std::deque list = GetListOfServersForChannel(c); + for (unsigned int i = 0; i < list.size(); i++) + { + TreeSocket* Sock = list[i]->GetSocket(); + if (Sock) + Sock->WriteLine(":"+std::string(user->nick)+" NOTICE "+std::string(c->name)+" :"+text); + } } } } @@ -1580,10 +1630,13 @@ class ModuleSpanningTree : public Module if (std::string(user->server) == Srv->GetServerName()) { chanrec *c = (chanrec*)dest; - std::deque params; - params.push_back(c->name); - params.push_back(":"+text); - DoOneToMany(user->nick,"PRIVMSG",params); + std::deque list = GetListOfServersForChannel(c); + for (unsigned int i = 0; i < list.size(); i++) + { + TreeSocket* Sock = list[i]->GetSocket(); + if (Sock) + Sock->WriteLine(":"+std::string(user->nick)+" PRIVMSG "+std::string(c->name)+" :"+text); + } } } } -- cgit v1.2.3