1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $ModDesc: Provides a spanning tree server link protocol */
17 #include "commands/cmd_whois.h"
18 #include "commands/cmd_stats.h"
21 #include "transport.h"
23 #include "m_spanningtree/cachetimer.h"
24 #include "m_spanningtree/resolvers.h"
25 #include "m_spanningtree/main.h"
26 #include "m_spanningtree/utils.h"
27 #include "m_spanningtree/treeserver.h"
28 #include "m_spanningtree/link.h"
29 #include "m_spanningtree/treesocket.h"
30 #include "m_spanningtree/rconnect.h"
31 #include "m_spanningtree/rsquit.h"
32 #include "m_spanningtree/protocolinterface.h"
34 /* $ModDep: m_spanningtree/cachetimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_spanningtree/rconnect.h m_spanningtree/rsquit.h m_spanningtree/protocolinterface.h */
36 ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
37 : Module(Me), max_local(0), max_global(0)
39 ServerInstance->Modules->UseInterface("BufferedSocketHook");
40 Utils = new SpanningTreeUtilities(ServerInstance, this);
41 command_rconnect = new CommandRConnect(ServerInstance, this, Utils);
42 ServerInstance->AddCommand(command_rconnect);
43 command_rsquit = new CommandRSQuit(ServerInstance, this, Utils);
44 ServerInstance->AddCommand(command_rsquit);
45 RefreshTimer = new CacheRefreshTimer(ServerInstance, Utils);
46 ServerInstance->Timers->AddTimer(RefreshTimer);
48 Implementation eventlist[] =
50 I_OnPreCommand, I_OnGetServerDescription, I_OnUserInvite, I_OnPostLocalTopicChange,
51 I_OnWallops, I_OnUserNotice, I_OnUserMessage, I_OnBackgroundTimer,
52 I_OnUserJoin, I_OnChangeLocalUserHost, I_OnChangeName, I_OnUserPart,
53 I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash,
54 I_OnOper, I_OnAddLine, I_OnDelLine, I_ProtoSendMode, I_OnMode,
55 I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnPostCommand
57 ServerInstance->Modules->Attach(eventlist, this, 27);
59 delete ServerInstance->PI;
60 ServerInstance->PI = new SpanningTreeProtocolInterface(this, Utils, ServerInstance);
62 for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
64 ServerInstance->PI->Introduce(*i);
68 void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
70 std::string Parent = Utils->TreeRoot->GetName();
71 if (Current->GetParent())
73 Parent = Current->GetParent()->GetName();
75 for (unsigned int q = 0; q < Current->ChildCount(); q++)
77 if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName().c_str()))))
81 ShowLinks(Current->GetChild(q),user,hops+1);
86 ShowLinks(Current->GetChild(q),user,hops+1);
89 /* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
90 if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName().c_str())) && (!IS_OPER(user)))
92 /* Or if the server is hidden and they're not an oper */
93 else if ((Current->Hidden) && (!IS_OPER(user)))
96 user->WriteNumeric(364, "%s %s %s :%d %s", user->nick.c_str(),Current->GetName().c_str(),
97 (Utils->FlatLinks && (!IS_OPER(user))) ? ServerInstance->Config->ServerName : Parent.c_str(),
98 (Utils->FlatLinks && (!IS_OPER(user))) ? 0 : hops,
99 Current->GetDesc().c_str());
102 int ModuleSpanningTree::CountLocalServs()
104 return Utils->TreeRoot->ChildCount();
107 int ModuleSpanningTree::CountServs()
109 return Utils->serverlist.size();
112 void ModuleSpanningTree::HandleLinks(const std::vector<std::string>& parameters, User* user)
114 ShowLinks(Utils->TreeRoot,user,0);
115 user->WriteNumeric(365, "%s * :End of /LINKS list.",user->nick.c_str());
119 void ModuleSpanningTree::HandleLusers(const std::vector<std::string>& parameters, User* user)
121 unsigned int n_users = ServerInstance->Users->UserCount();
123 /* Only update these when someone wants to see them, more efficient */
124 if ((unsigned int)ServerInstance->Users->LocalUserCount() > max_local)
125 max_local = ServerInstance->Users->LocalUserCount();
126 if (n_users > max_global)
127 max_global = n_users;
129 unsigned int ulined_count = 0;
130 unsigned int ulined_local_count = 0;
132 /* If ulined are hidden and we're not an oper, count the number of ulined servers hidden,
133 * locally and globally (locally means directly connected to us)
135 if ((Utils->HideULines) && (!IS_OPER(user)))
137 for (server_hash::iterator q = Utils->serverlist.begin(); q != Utils->serverlist.end(); q++)
139 if (ServerInstance->ULine(q->second->GetName().c_str()))
142 if (q->second->GetParent() == Utils->TreeRoot)
143 ulined_local_count++;
147 user->WriteNumeric(251, "%s :There are %d users and %d invisible on %d servers",user->nick.c_str(),
148 n_users-ServerInstance->Users->ModeCount('i'),
149 ServerInstance->Users->ModeCount('i'),
150 ulined_count ? this->CountServs() - ulined_count : this->CountServs());
152 if (ServerInstance->Users->OperCount())
153 user->WriteNumeric(252, "%s %d :operator(s) online",user->nick.c_str(),ServerInstance->Users->OperCount());
155 if (ServerInstance->Users->UnregisteredUserCount())
156 user->WriteNumeric(253, "%s %d :unknown connections",user->nick.c_str(),ServerInstance->Users->UnregisteredUserCount());
158 if (ServerInstance->ChannelCount())
159 user->WriteNumeric(254, "%s %ld :channels formed",user->nick.c_str(),ServerInstance->ChannelCount());
161 user->WriteNumeric(255, "%s :I have %d clients and %d servers",user->nick.c_str(),ServerInstance->Users->LocalUserCount(),ulined_local_count ? this->CountLocalServs() - ulined_local_count : this->CountLocalServs());
162 user->WriteNumeric(265, "%s :Current Local Users: %d Max: %d",user->nick.c_str(),ServerInstance->Users->LocalUserCount(),max_local);
163 user->WriteNumeric(266, "%s :Current Global Users: %d Max: %d",user->nick.c_str(),n_users,max_global);
167 std::string ModuleSpanningTree::TimeToStr(time_t secs)
169 time_t mins_up = secs / 60;
170 time_t hours_up = mins_up / 60;
171 time_t days_up = hours_up / 24;
173 mins_up = mins_up % 60;
174 hours_up = hours_up % 24;
175 return ((days_up ? (ConvToStr(days_up) + "d") : std::string(""))
176 + (hours_up ? (ConvToStr(hours_up) + "h") : std::string(""))
177 + (mins_up ? (ConvToStr(mins_up) + "m") : std::string(""))
178 + ConvToStr(secs) + "s");
181 void ModuleSpanningTree::DoPingChecks(time_t curtime)
184 * Cancel remote burst mode on any servers which still have it enabled due to latency/lack of data.
185 * This prevents lost REMOTECONNECT notices
188 gettimeofday(&t, NULL);
189 long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
191 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
193 TreeServer *s = i->second;
195 // Now do PING checks on all servers
196 TreeServer *mts = Utils->BestRouteTo(s->GetID());
200 // Only ping if this server needs one
201 if (curtime >= s->NextPingTime())
203 // And if they answered the last
204 if (s->AnsweredLastPing())
206 // They did, send a ping to them
207 s->SetNextPingTime(curtime + Utils->PingFreq);
208 TreeSocket *tsock = mts->GetSocket();
210 // ... if we can find a proper route to them
213 tsock->WriteLine(std::string(":") + ServerInstance->Config->GetSID() + " PING " +
214 ServerInstance->Config->GetSID() + " " + s->GetID());
215 s->LastPingMsec = ts;
220 // They didn't answer the last ping, if they are locally connected, get rid of them.
221 TreeSocket *sock = s->GetSocket();
224 sock->SendError("Ping timeout");
225 sock->Squit(s,"Ping timeout");
226 ServerInstance->SE->DelFd(sock);
233 // If warn on ping enabled and not warned and the difference is sufficient and they didn't answer the last ping...
234 if ((Utils->PingWarnTime) && (!s->Warned) && (curtime >= s->NextPingTime() - (Utils->PingFreq - Utils->PingWarnTime)) && (!s->AnsweredLastPing()))
236 /* The server hasnt responded, send a warning to opers */
237 ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not responded to PING for %d seconds, high latency.", s->GetName().c_str(), Utils->PingWarnTime);
244 void ModuleSpanningTree::ConnectServer(Link* x)
248 if (InspIRCd::Match(ServerInstance->Config->ServerName, assign(x->Name)))
250 this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Not connecting to myself.");
254 QueryType start_type = DNS_QUERY_A;
256 start_type = DNS_QUERY_AAAA;
257 if (strchr(x->IPAddr.c_str(),':'))
260 if (inet_pton(AF_INET6, x->IPAddr.c_str(), &n) < 1)
267 if (inet_aton(x->IPAddr.c_str(),&n) < 1)
271 /* Do we already have an IP? If so, no need to resolve it. */
274 /* Gave a hook, but it wasnt one we know */
275 if ((!x->Hook.empty()) && (Utils->hooks.find(x->Hook.c_str()) == Utils->hooks.end()))
277 TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port, x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]);
278 if (newsocket->GetFd() > -1)
280 /* Handled automatically on success */
284 this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
285 if (ServerInstance->SocketCull.find(newsocket) == ServerInstance->SocketCull.end())
286 ServerInstance->SocketCull[newsocket] = newsocket;
287 Utils->DoFailOver(x);
295 ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached, start_type);
296 ServerInstance->AddResolver(snr, cached);
298 catch (ModuleException& e)
300 this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
301 Utils->DoFailOver(x);
306 void ModuleSpanningTree::AutoConnectServers(time_t curtime)
308 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
310 if ((x->AutoConnect) && (curtime >= x->NextConnectTime))
312 x->NextConnectTime = curtime + x->AutoConnect;
313 TreeServer* CheckDupe = Utils->FindServer(x->Name.c_str());
314 if (x->FailOver.length())
316 TreeServer* CheckFailOver = Utils->FindServer(x->FailOver.c_str());
319 /* The failover for this server is currently a member of the network.
320 * The failover probably succeeded, where the main link did not.
321 * Don't try the main link until the failover is gone again.
328 // an autoconnected server is not connected. Check if its time to connect it
329 ServerInstance->SNO->WriteToSnoMask('l',"AUTOCONNECT: Auto-connecting server \002%s\002 (%lu seconds until next attempt)",x->Name.c_str(),x->AutoConnect);
330 this->ConnectServer(&(*x));
336 void ModuleSpanningTree::DoConnectTimeout(time_t curtime)
338 std::vector<Link*> failovers;
339 for (std::map<TreeSocket*, std::pair<std::string, int> >::iterator i = Utils->timeoutlist.begin(); i != Utils->timeoutlist.end(); i++)
341 TreeSocket* s = i->first;
342 std::pair<std::string, int> p = i->second;
343 if (curtime > s->age + p.second)
345 ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002 (timeout of %d seconds)",p.first.c_str(),p.second);
346 ServerInstance->SE->DelFd(s);
348 Link* MyLink = Utils->FindLink(p.first);
350 failovers.push_back(MyLink);
353 /* Trigger failover for each timed out socket */
354 for (std::vector<Link*>::const_iterator n = failovers.begin(); n != failovers.end(); ++n)
356 Utils->DoFailOver(*n);
360 int ModuleSpanningTree::HandleVersion(const std::vector<std::string>& parameters, User* user)
362 // we've already checked if pcnt > 0, so this is safe
363 TreeServer* found = Utils->FindServerMask(parameters[0]);
366 std::string Version = found->GetVersion();
367 user->WriteNumeric(351, "%s :%s",user->nick.c_str(),Version.c_str());
368 if (found == Utils->TreeRoot)
370 ServerInstance->Config->Send005(user);
375 user->WriteNumeric(402, "%s %s :No such server",user->nick.c_str(),parameters[0].c_str());
380 /* This method will attempt to get a message to a remote user.
382 void ModuleSpanningTree::RemoteMessage(User* user, const char* format, ...)
387 va_start(argsPtr, format);
388 vsnprintf(text, MAXBUF, format, argsPtr);
392 user->WriteServ("NOTICE %s :%s", user->nick.c_str(), text);
394 ServerInstance->PI->SendUserNotice(user, text);
397 int ModuleSpanningTree::HandleConnect(const std::vector<std::string>& parameters, User* user)
399 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
401 if (InspIRCd::Match(x->Name.c_str(),parameters[0]))
403 if (InspIRCd::Match(ServerInstance->Config->ServerName, assign(x->Name)))
405 RemoteMessage(user, "*** CONNECT: Server \002%s\002 is ME, not connecting.",x->Name.c_str());
409 TreeServer* CheckDupe = Utils->FindServer(x->Name.c_str());
412 RemoteMessage(user, "*** CONNECT: Connecting to server: \002%s\002 (%s:%d)",x->Name.c_str(),(x->HiddenFromStats ? "<hidden>" : x->IPAddr.c_str()),x->Port);
413 ConnectServer(&(*x));
418 RemoteMessage(user, "*** CONNECT: Server \002%s\002 already exists on the network and is connected via \002%s\002",x->Name.c_str(),CheckDupe->GetParent()->GetName().c_str());
423 RemoteMessage(user, "*** CONNECT: No server matching \002%s\002 could be found in the config file.",parameters[0].c_str());
427 void ModuleSpanningTree::OnGetServerDescription(const std::string &servername,std::string &description)
429 TreeServer* s = Utils->FindServer(servername);
432 description = s->GetDesc();
436 void ModuleSpanningTree::OnUserInvite(User* source,User* dest,Channel* channel, time_t expiry)
438 if (IS_LOCAL(source))
440 std::deque<std::string> params;
441 params.push_back(dest->uuid);
442 params.push_back(channel->name);
443 params.push_back(ConvToStr(expiry));
444 Utils->DoOneToMany(source->uuid,"INVITE",params);
448 void ModuleSpanningTree::OnPostLocalTopicChange(User* user, Channel* chan, const std::string &topic)
450 std::deque<std::string> params;
451 params.push_back(chan->name);
452 params.push_back(":"+topic);
453 Utils->DoOneToMany(user->uuid,"TOPIC",params);
456 void ModuleSpanningTree::OnWallops(User* user, const std::string &text)
460 std::deque<std::string> params;
461 params.push_back(":"+text);
462 Utils->DoOneToMany(user->uuid,"WALLOPS",params);
466 void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
472 if (target_type == TYPE_USER)
474 User* d = (User*)dest;
475 if ((d->GetFd() < 0) && (IS_LOCAL(user)))
477 std::deque<std::string> params;
479 params.push_back(d->uuid);
480 params.push_back(":"+text);
481 Utils->DoOneToOne(user->uuid,"NOTICE",params,d->server);
484 else if (target_type == TYPE_CHANNEL)
488 Channel *c = (Channel*)dest;
491 std::string cname = c->name;
493 cname = status + cname;
495 Utils->GetListOfServersForChannel(c,list,status,exempt_list);
496 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
498 TreeSocket* Sock = i->second->GetSocket();
500 Sock->WriteLine(":"+std::string(user->uuid)+" NOTICE "+cname+" :"+text);
505 else if (target_type == TYPE_SERVER)
509 char* target = (char*)dest;
510 std::deque<std::string> par;
511 par.push_back(target);
512 par.push_back(":"+text);
513 Utils->DoOneToMany(user->uuid,"NOTICE",par);
518 void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
524 if (target_type == TYPE_USER)
526 // route private messages which are targetted at clients only to the server
527 // which needs to receive them
528 User* d = (User*)dest;
529 if ((d->GetFd() < 0) && (IS_LOCAL(user)))
531 std::deque<std::string> params;
533 params.push_back(d->uuid);
534 params.push_back(":"+text);
535 Utils->DoOneToOne(user->uuid,"PRIVMSG",params,d->server);
538 else if (target_type == TYPE_CHANNEL)
542 Channel *c = (Channel*)dest;
545 std::string cname = c->name;
547 cname = status + cname;
549 Utils->GetListOfServersForChannel(c,list,status,exempt_list);
550 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
552 TreeSocket* Sock = i->second->GetSocket();
554 Sock->WriteLine(":"+std::string(user->uuid)+" PRIVMSG "+cname+" :"+text);
559 else if (target_type == TYPE_SERVER)
563 char* target = (char*)dest;
564 std::deque<std::string> par;
565 par.push_back(target);
566 par.push_back(":"+text);
567 Utils->DoOneToMany(user->uuid,"PRIVMSG",par);
572 void ModuleSpanningTree::OnBackgroundTimer(time_t curtime)
574 AutoConnectServers(curtime);
575 DoPingChecks(curtime);
576 DoConnectTimeout(curtime);
579 void ModuleSpanningTree::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
581 // Only do this for local users
584 std::deque<std::string> params;
585 // set up their permissions and the channel TS with FJOIN.
586 // All users are FJOINed now, because a module may specify
587 // new joining permissions for the user.
588 params.push_back(channel->name);
589 params.push_back(ConvToStr(channel->age));
590 params.push_back(std::string("+") + channel->ChanModes(true));
591 params.push_back(ServerInstance->Modes->ModeString(user, channel, false)+","+std::string(user->uuid));
592 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params);
596 int ModuleSpanningTree::OnChangeLocalUserHost(User* user, const std::string &newhost)
598 std::deque<std::string> params;
599 params.push_back(newhost);
600 Utils->DoOneToMany(user->uuid,"FHOST",params);
604 void ModuleSpanningTree::OnChangeName(User* user, const std::string &gecos)
606 // only occurs for local clients
607 if (user->registered != REG_ALL)
609 std::deque<std::string> params;
610 params.push_back(gecos);
611 Utils->DoOneToMany(user->uuid,"FNAME",params);
614 void ModuleSpanningTree::OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent)
618 std::deque<std::string> params;
619 params.push_back(channel->name);
620 if (!partmessage.empty())
621 params.push_back(":"+partmessage);
622 Utils->DoOneToMany(user->uuid,"PART",params);
626 void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
628 if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
630 std::deque<std::string> params;
632 if (oper_message != reason)
634 params.push_back(":"+oper_message);
635 Utils->DoOneToMany(user->uuid,"OPERQUIT",params);
638 params.push_back(":"+reason);
639 Utils->DoOneToMany(user->uuid,"QUIT",params);
642 // Regardless, We need to modify the user Counts..
643 TreeServer* SourceServer = Utils->FindServer(user->server);
646 SourceServer->SetUserCount(-1); // decrement by 1
650 void ModuleSpanningTree::OnUserPostNick(User* user, const std::string &oldnick)
654 std::deque<std::string> params;
655 params.push_back(user->nick);
657 /** IMPORTANT: We don't update the TS if the oldnick is just a case change of the newnick!
659 if (irc::string(user->nick.c_str()) != assign(oldnick))
660 user->age = ServerInstance->Time();
662 params.push_back(ConvToStr(user->age));
663 Utils->DoOneToMany(user->uuid,"NICK",params);
667 void ModuleSpanningTree::OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
669 if ((source) && (IS_LOCAL(source)))
671 std::deque<std::string> params;
672 params.push_back(chan->name);
673 params.push_back(user->uuid);
674 params.push_back(":"+reason);
675 Utils->DoOneToMany(source->uuid,"KICK",params);
679 std::deque<std::string> params;
680 params.push_back(chan->name);
681 params.push_back(user->uuid);
682 params.push_back(":"+reason);
683 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"KICK",params);
687 void ModuleSpanningTree::OnRemoteKill(User* source, User* dest, const std::string &reason, const std::string &operreason)
689 if (!IS_LOCAL(source)) return; // Only start routing if we're origin.
690 std::deque<std::string> params;
691 params.push_back(":"+reason);
692 Utils->DoOneToMany(dest->uuid,"OPERQUIT",params);
694 params.push_back(dest->uuid);
695 params.push_back(":"+reason);
696 dest->SetOperQuit(operreason);
697 Utils->DoOneToMany(source->uuid,"KILL",params);
700 void ModuleSpanningTree::OnRehash(User* user, const std::string ¶meter)
702 ServerInstance->Logs->Log("remoterehash", DEBUG, "called with param %s", parameter.c_str());
704 // Send out to other servers
705 if (!parameter.empty() && parameter[0] != '-')
707 ServerInstance->Logs->Log("remoterehash", DEBUG, "sending out lol");
708 std::deque<std::string> params;
709 params.push_back(parameter);
710 Utils->DoOneToAllButSender(user ? user->uuid : ServerInstance->Config->GetSID(), "REHASH", params, user ? user->server : ServerInstance->Config->ServerName);
713 // Re-read config stuff
714 Utils->ReadConfiguration(true);
717 // note: the protocol does not allow direct umode +o except
718 // via NICK with 8 params. sending OPERTYPE infers +o modechange
720 void ModuleSpanningTree::OnOper(User* user, const std::string &opertype)
724 std::deque<std::string> params;
725 params.push_back(opertype);
726 Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
730 void ModuleSpanningTree::OnAddLine(User* user, XLine *x)
732 if (!x->IsBurstable())
736 snprintf(data,MAXBUF,"%s %s %s %lu %lu :%s", x->type.c_str(), x->Displayable(),
737 ServerInstance->Config->ServerName, (unsigned long)x->set_time, (unsigned long)x->duration, x->reason);
738 std::deque<std::string> params;
739 params.push_back(data);
743 /* Server-set lines */
744 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ADDLINE", params);
746 else if (IS_LOCAL(user))
749 Utils->DoOneToMany(user->uuid, "ADDLINE", params);
753 void ModuleSpanningTree::OnDelLine(User* user, XLine *x)
759 snprintf(data,MAXBUF,"%s %s", x->type.c_str(), x->Displayable());
760 std::deque<std::string> params;
761 params.push_back(data);
765 /* Server-unset lines */
766 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "DELLINE", params);
768 else if (IS_LOCAL(user))
770 /* User-unset lines */
771 Utils->DoOneToMany(user->uuid, "DELLINE", params);
775 void ModuleSpanningTree::OnMode(User* user, void* dest, int target_type, const std::string &text)
777 if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
779 std::deque<std::string> params;
781 std::string output_text;
783 ServerInstance->Parser->TranslateUIDs(TR_SPACENICKLIST, text, output_text);
785 if (target_type == TYPE_USER)
787 User* u = (User*)dest;
788 params.push_back(u->uuid);
789 params.push_back(output_text);
794 Channel* c = (Channel*)dest;
795 params.push_back(c->name);
796 params.push_back(ConvToStr(c->age));
797 params.push_back(output_text);
801 Utils->DoOneToMany(user->uuid, command, params);
805 int ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg)
811 std::deque<std::string> params;
813 Utils->DoOneToMany(user->uuid,"AWAY",params);
817 std::deque<std::string> params;
818 params.push_back(":" + awaymsg);
819 Utils->DoOneToMany(user->uuid,"AWAY",params);
826 void ModuleSpanningTree::ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::string &modeline)
828 TreeSocket* s = (TreeSocket*)opaque;
829 std::string output_text;
831 ServerInstance->Parser->TranslateUIDs(TR_SPACENICKLIST, modeline, output_text);
835 if (target_type == TYPE_USER)
837 User* u = (User*)target;
838 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" FMODE "+u->uuid+" "+ConvToStr(u->age)+" "+output_text);
840 else if (target_type == TYPE_CHANNEL)
842 Channel* c = (Channel*)target;
843 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" FMODE "+c->name+" "+ConvToStr(c->age)+" "+output_text);
848 void ModuleSpanningTree::ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata)
850 TreeSocket* s = (TreeSocket*)opaque;
853 if (target_type == TYPE_USER)
855 User* u = (User*)target;
856 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
858 else if (target_type == TYPE_CHANNEL)
860 Channel* c = (Channel*)target;
861 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
864 if (target_type == TYPE_OTHER)
866 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
870 void ModuleSpanningTree::OnEvent(Event* event)
872 if ((event->GetEventID() == "send_encap") || (event->GetEventID() == "send_metadata") || (event->GetEventID() == "send_topic") || (event->GetEventID() == "send_mode") || (event->GetEventID() == "send_mode_explicit") || (event->GetEventID() == "send_opers")
873 || (event->GetEventID() == "send_modeset") || (event->GetEventID() == "send_snoset") || (event->GetEventID() == "send_push"))
875 ServerInstance->Logs->Log("m_spanningtree", DEBUG, "WARNING: Deprecated use of old 1.1 style m_spanningtree event ignored, type '"+event->GetEventID()+"'!");
879 ModuleSpanningTree::~ModuleSpanningTree()
881 delete ServerInstance->PI;
882 ServerInstance->PI = new ProtocolInterface(ServerInstance);
884 /* This will also free the listeners */
887 ServerInstance->Timers->DelTimer(RefreshTimer);
889 ServerInstance->Modules->DoneWithInterface("BufferedSocketHook");
892 Version ModuleSpanningTree::GetVersion()
894 return Version("$Id$", VF_VENDOR, API_VERSION);
897 /* It is IMPORTANT that m_spanningtree is the last module in the chain
898 * so that any activity it sees is FINAL, e.g. we arent going to send out
899 * a NICK message before m_cloaking has finished putting the +x on the user,
901 * Therefore, we return PRIORITY_LAST to make sure we end up at the END of
902 * the module call queue.
904 void ModuleSpanningTree::Prioritize()
906 ServerInstance->Modules->SetPriority(this, PRIO_LAST);
909 MODULE_INIT(ModuleSpanningTree)