1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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"
22 #include "transport.h"
24 #include "m_spanningtree/timesynctimer.h"
25 #include "m_spanningtree/resolvers.h"
26 #include "m_spanningtree/main.h"
27 #include "m_spanningtree/utils.h"
28 #include "m_spanningtree/treeserver.h"
29 #include "m_spanningtree/link.h"
30 #include "m_spanningtree/treesocket.h"
31 #include "m_spanningtree/rconnect.h"
32 #include "m_spanningtree/rsquit.h"
34 /* $ModDep: m_spanningtree/timesynctimer.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 */
36 ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
37 : Module(Me), max_local(0), max_global(0)
39 ServerInstance->Modules->UseInterface("InspSocketHook");
40 Utils = new SpanningTreeUtilities(Me, this);
41 command_rconnect = new cmd_rconnect(ServerInstance, this, Utils);
42 ServerInstance->AddCommand(command_rconnect);
43 command_rsquit = new cmd_rsquit(ServerInstance, this, Utils);
44 ServerInstance->AddCommand(command_rsquit);
45 if (Utils->EnableTimeSync)
47 SyncTimer = new TimeSyncTimer(ServerInstance, this);
48 ServerInstance->Timers->AddTimer(SyncTimer);
53 RefreshTimer = new CacheRefreshTimer(ServerInstance, Utils);
54 ServerInstance->Timers->AddTimer(RefreshTimer);
57 void ModuleSpanningTree::ShowLinks(TreeServer* Current, userrec* user, int hops)
59 std::string Parent = Utils->TreeRoot->GetName();
60 if (Current->GetParent())
62 Parent = Current->GetParent()->GetName();
64 for (unsigned int q = 0; q < Current->ChildCount(); q++)
66 if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName().c_str()))))
70 ShowLinks(Current->GetChild(q),user,hops+1);
75 ShowLinks(Current->GetChild(q),user,hops+1);
78 /* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
79 if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName().c_str())) && (!IS_OPER(user)))
81 /* Or if the server is hidden and they're not an oper */
82 else if ((Current->Hidden) && (!IS_OPER(user)))
85 user->WriteServ("364 %s %s %s :%d %s", user->nick,Current->GetName().c_str(),
86 (Utils->FlatLinks && (!IS_OPER(user))) ? ServerInstance->Config->ServerName : Parent.c_str(),
87 (Utils->FlatLinks && (!IS_OPER(user))) ? 0 : hops,
88 Current->GetDesc().c_str());
91 int ModuleSpanningTree::CountLocalServs()
93 return Utils->TreeRoot->ChildCount();
96 int ModuleSpanningTree::CountServs()
98 return Utils->serverlist.size();
101 void ModuleSpanningTree::HandleLinks(const char** parameters, int pcnt, userrec* user)
103 ShowLinks(Utils->TreeRoot,user,0);
104 user->WriteServ("365 %s * :End of /LINKS list.",user->nick);
108 void ModuleSpanningTree::HandleLusers(const char** parameters, int pcnt, userrec* user)
110 unsigned int n_users = ServerInstance->UserCount();
112 /* Only update these when someone wants to see them, more efficient */
113 if ((unsigned int)ServerInstance->LocalUserCount() > max_local)
114 max_local = ServerInstance->LocalUserCount();
115 if (n_users > max_global)
116 max_global = n_users;
118 unsigned int ulined_count = 0;
119 unsigned int ulined_local_count = 0;
121 /* If ulined are hidden and we're not an oper, count the number of ulined servers hidden,
122 * locally and globally (locally means directly connected to us)
124 if ((Utils->HideULines) && (!*user->oper))
126 for (server_hash::iterator q = Utils->serverlist.begin(); q != Utils->serverlist.end(); q++)
128 if (ServerInstance->ULine(q->second->GetName().c_str()))
131 if (q->second->GetParent() == Utils->TreeRoot)
132 ulined_local_count++;
136 user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,
137 n_users-ServerInstance->InvisibleUserCount(),
138 ServerInstance->InvisibleUserCount(),
139 ulined_count ? this->CountServs() - ulined_count : this->CountServs());
141 if (ServerInstance->OperCount())
142 user->WriteServ("252 %s %d :operator(s) online",user->nick,ServerInstance->OperCount());
144 if (ServerInstance->UnregisteredUserCount())
145 user->WriteServ("253 %s %d :unknown connections",user->nick,ServerInstance->UnregisteredUserCount());
147 if (ServerInstance->ChannelCount())
148 user->WriteServ("254 %s %d :channels formed",user->nick,ServerInstance->ChannelCount());
150 user->WriteServ("255 %s :I have %d clients and %d servers",user->nick,ServerInstance->LocalUserCount(),ulined_local_count ? this->CountLocalServs() - ulined_local_count : this->CountLocalServs());
151 user->WriteServ("265 %s :Current Local Users: %d Max: %d",user->nick,ServerInstance->LocalUserCount(),max_local);
152 user->WriteServ("266 %s :Current Global Users: %d Max: %d",user->nick,n_users,max_global);
156 std::string ModuleSpanningTree::TimeToStr(time_t secs)
158 time_t mins_up = secs / 60;
159 time_t hours_up = mins_up / 60;
160 time_t days_up = hours_up / 24;
162 mins_up = mins_up % 60;
163 hours_up = hours_up % 24;
164 return ((days_up ? (ConvToStr(days_up) + "d") : std::string(""))
165 + (hours_up ? (ConvToStr(hours_up) + "h") : std::string(""))
166 + (mins_up ? (ConvToStr(mins_up) + "m") : std::string(""))
167 + ConvToStr(secs) + "s");
170 const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current)
172 time_t secs_up = ServerInstance->Time() - Current->age;
173 return (" [Up: " + TimeToStr(secs_up) + " Lag: "+ConvToStr(Current->rtt)+"ms]");
176 // WARNING: NOT THREAD SAFE - DONT GET ANY SMART IDEAS.
177 void ModuleSpanningTree::ShowMap(TreeServer* Current, userrec* user, int depth, char matrix[128][128], float &totusers, float &totservers)
181 for (int t = 0; t < depth; t++)
183 matrix[line][t] = ' ';
185 // For Aligning, we need to work out exactly how deep this thing is, and produce
186 // a 'Spacer' String to compensate.
188 memset(spacer,' ',40);
189 if ((40 - Current->GetName().length() - depth) > 1) {
190 spacer[40 - Current->GetName().length() - depth] = '\0';
198 /* Neat and tidy default values, as we're dealing with a matrix not a simple string */
199 memset(text, 0, 128);
201 if (ServerInstance->clientlist->size() == 0) {
202 // If there are no users, WHO THE HELL DID THE /MAP?!?!?!
207 percent = ((float)Current->GetUserCount() / (float)ServerInstance->clientlist->size()) * 100;
209 const std::string operdata = IS_OPER(user) ? MapOperInfo(Current) : "";
210 snprintf(text, 126, "%s %s%5d [%5.2f%%]%s", Current->GetName().c_str(), spacer, Current->GetUserCount(), percent, operdata.c_str());
211 totusers += Current->GetUserCount();
213 strlcpy(&matrix[line][depth],text,126);
215 for (unsigned int q = 0; q < Current->ChildCount(); q++)
217 if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName().c_str()))))
221 ShowMap(Current->GetChild(q),user,(Utils->FlatLinks && (!*user->oper)) ? depth : depth+2,matrix,totusers,totservers);
226 ShowMap(Current->GetChild(q),user,(Utils->FlatLinks && (!*user->oper)) ? depth : depth+2,matrix,totusers,totservers);
232 int ModuleSpanningTree::HandleMotd(const char** parameters, int pcnt, userrec* user)
236 if (match(ServerInstance->Config->ServerName, parameters[0]))
239 /* Remote MOTD, the server is within the 1st parameter */
240 std::deque<std::string> params;
241 params.push_back(parameters[0]);
242 /* Send it out remotely, generate no reply yet */
243 TreeServer* s = Utils->FindServerMask(parameters[0]);
246 params[0] = s->GetName();
247 Utils->DoOneToOne(user->uuid, "MOTD", params, s->GetName());
250 user->WriteServ( "402 %s %s :No such server", user->nick, parameters[0]);
256 int ModuleSpanningTree::HandleAdmin(const char** parameters, int pcnt, userrec* user)
260 if (match(ServerInstance->Config->ServerName, parameters[0]))
263 /* Remote ADMIN, the server is within the 1st parameter */
264 std::deque<std::string> params;
265 params.push_back(parameters[0]);
266 /* Send it out remotely, generate no reply yet */
267 TreeServer* s = Utils->FindServerMask(parameters[0]);
270 params[0] = s->GetName();
271 Utils->DoOneToOne(user->uuid, "ADMIN", params, s->GetName());
274 user->WriteServ( "402 %s %s :No such server", user->nick, parameters[0]);
280 int ModuleSpanningTree::HandleModules(const char** parameters, int pcnt, userrec* user)
284 if (match(ServerInstance->Config->ServerName, parameters[0]))
287 std::deque<std::string> params;
288 params.push_back(parameters[0]);
289 TreeServer* s = Utils->FindServerMask(parameters[0]);
292 params[0] = s->GetName();
293 Utils->DoOneToOne(user->uuid, "MODULES", params, s->GetName());
296 user->WriteServ( "402 %s %s :No such server", user->nick, parameters[0]);
302 int ModuleSpanningTree::HandleStats(const char** parameters, int pcnt, userrec* user)
306 if (match(ServerInstance->Config->ServerName, parameters[1]))
309 /* Remote STATS, the server is within the 2nd parameter */
310 std::deque<std::string> params;
311 params.push_back(parameters[0]);
312 params.push_back(parameters[1]);
313 /* Send it out remotely, generate no reply yet */
315 TreeServer* s = Utils->FindServerMask(parameters[1]);
318 params[1] = s->GetName();
319 Utils->DoOneToOne(user->uuid, "STATS", params, s->GetName());
323 user->WriteServ( "402 %s %s :No such server", user->nick, parameters[1]);
330 // Ok, prepare to be confused.
331 // After much mulling over how to approach this, it struck me that
332 // the 'usual' way of doing a /MAP isnt the best way. Instead of
333 // keeping track of a ton of ascii characters, and line by line
334 // under recursion working out where to place them using multiplications
335 // and divisons, we instead render the map onto a backplane of characters
336 // (a character matrix), then draw the branches as a series of "L" shapes
337 // from the nodes. This is not only friendlier on CPU it uses less stack.
338 void ModuleSpanningTree::HandleMap(const char** parameters, int pcnt, userrec* user)
340 // This array represents a virtual screen which we will
341 // "scratch" draw to, as the console device of an irc
342 // client does not provide for a proper terminal.
344 float totservers = 0;
345 char matrix[128][128];
346 for (unsigned int t = 0; t < 128; t++)
351 // The only recursive bit is called here.
352 ShowMap(Utils->TreeRoot,user,0,matrix,totusers,totservers);
353 // Process each line one by one. The algorithm has a limit of
354 // 128 servers (which is far more than a spanning tree should have
355 // anyway, so we're ok). This limit can be raised simply by making
356 // the character matrix deeper, 128 rows taking 10k of memory.
357 for (int l = 1; l < line; l++)
359 // scan across the line looking for the start of the
360 // servername (the recursive part of the algorithm has placed
361 // the servers at indented positions depending on what they
363 int first_nonspace = 0;
364 while (matrix[l][first_nonspace] == ' ')
369 // Draw the `- (corner) section: this may be overwritten by
370 // another L shape passing along the same vertical pane, becoming
371 // a |- (branch) section instead.
372 matrix[l][first_nonspace] = '-';
373 matrix[l][first_nonspace-1] = '`';
375 // Draw upwards until we hit the parent server, causing possibly
376 // other corners (`-) to become branches (|-)
377 while ((matrix[l2][first_nonspace-1] == ' ') || (matrix[l2][first_nonspace-1] == '`'))
379 matrix[l2][first_nonspace-1] = '|';
383 // dump the whole lot to the user. This is the easy bit, honest.
384 for (int t = 0; t < line; t++)
386 user->WriteServ("006 %s :%s",user->nick,&matrix[t][0]);
388 float avg_users = totusers / totservers;
389 user->WriteServ("270 %s :%.0f server%s and %.0f user%s, average %.2f users per server",user->nick,totservers,(totservers > 1 ? "s" : ""),totusers,(totusers > 1 ? "s" : ""),avg_users);
390 user->WriteServ("007 %s :End of /MAP",user->nick);
394 int ModuleSpanningTree::HandleSquit(const char** parameters, int pcnt, userrec* user)
396 TreeServer* s = Utils->FindServerMask(parameters[0]);
399 if (s == Utils->TreeRoot)
401 user->WriteServ("NOTICE %s :*** SQUIT: Foolish mortal, you cannot make a server SQUIT itself! (%s matches local server name)",user->nick,parameters[0]);
404 TreeSocket* sock = s->GetSocket();
407 ServerInstance->SNO->WriteToSnoMask('l',"SQUIT: Server \002%s\002 removed from network by %s",parameters[0],user->nick);
408 sock->Squit(s,std::string("Server quit by ") + user->GetFullRealHost());
409 ServerInstance->SE->DelFd(sock);
415 user->WriteServ("NOTICE %s :*** WARNING: Using SQUIT to split remote servers is deprecated. Please use RSQUIT instead.",user->nick);
420 user->WriteServ("NOTICE %s :*** SQUIT: The server \002%s\002 does not exist on the network.",user->nick,parameters[0]);
425 int ModuleSpanningTree::HandleTime(const char** parameters, int pcnt, userrec* user)
427 if ((IS_LOCAL(user)) && (pcnt))
429 TreeServer* found = Utils->FindServerMask(parameters[0]);
432 // we dont' override for local server
433 if (found == Utils->TreeRoot)
436 std::deque<std::string> params;
437 params.push_back(found->GetName());
438 params.push_back(user->uuid);
439 Utils->DoOneToOne(ServerInstance->Config->GetSID(),"TIME",params,found->GetName());
443 user->WriteServ("402 %s %s :No such server",user->nick,parameters[0]);
449 int ModuleSpanningTree::HandleRemoteWhois(const char** parameters, int pcnt, userrec* user)
451 if ((IS_LOCAL(user)) && (pcnt > 1))
453 userrec* remote = ServerInstance->FindNick(parameters[1]);
454 if ((remote) && (remote->GetFd() < 0))
456 std::deque<std::string> params;
457 params.push_back(parameters[1]);
458 Utils->DoOneToOne(user->uuid,"IDLE",params,remote->server);
463 user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[1]);
464 user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, parameters[1]);
471 void ModuleSpanningTree::DoPingChecks(time_t curtime)
473 for (unsigned int j = 0; j < Utils->TreeRoot->ChildCount(); j++)
475 TreeServer* serv = Utils->TreeRoot->GetChild(j);
476 TreeSocket* sock = serv->GetSocket();
479 if (curtime >= serv->NextPingTime())
481 if (serv->AnsweredLastPing())
483 sock->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" PING "+serv->GetID());
484 serv->SetNextPingTime(curtime + Utils->PingFreq);
485 serv->LastPing = curtime;
487 gettimeofday(&t, NULL);
488 long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
489 serv->LastPingMsec = ts;
490 serv->Warned = false;
494 /* they didnt answer, boot them */
495 sock->SendError("Ping timeout");
496 sock->Squit(serv,"Ping timeout");
497 ServerInstance->SE->DelFd(sock);
502 else if ((Utils->PingWarnTime) && (!serv->Warned) && (curtime >= serv->NextPingTime() - (Utils->PingFreq - Utils->PingWarnTime)) && (!serv->AnsweredLastPing()))
504 /* The server hasnt responded, send a warning to opers */
505 ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not responded to PING for %d seconds, high latency.", serv->GetName().c_str(), Utils->PingWarnTime);
511 /* Cancel remote burst mode on any servers which still have it enabled due to latency/lack of data.
512 * This prevents lost REMOTECONNECT notices
514 for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
515 Utils->SetRemoteBursting(i->second, false);
518 void ModuleSpanningTree::ConnectServer(Link* x)
521 QueryType start_type = DNS_QUERY_A;
523 start_type = DNS_QUERY_AAAA;
524 if (strchr(x->IPAddr.c_str(),':'))
527 if (inet_pton(AF_INET6, x->IPAddr.c_str(), &n) < 1)
534 if (inet_aton(x->IPAddr.c_str(),&n) < 1)
538 /* Do we already have an IP? If so, no need to resolve it. */
541 /* Gave a hook, but it wasnt one we know */
542 if ((!x->Hook.empty()) && (Utils->hooks.find(x->Hook.c_str()) == Utils->hooks.end()))
544 TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]);
545 if (newsocket->GetFd() > -1)
547 /* Handled automatically on success */
551 RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
552 if (ServerInstance->SocketCull.find(newsocket) == ServerInstance->SocketCull.end())
553 ServerInstance->SocketCull[newsocket] = newsocket;
554 Utils->DoFailOver(x);
562 ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached, start_type);
563 ServerInstance->AddResolver(snr, cached);
565 catch (ModuleException& e)
567 RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
568 Utils->DoFailOver(x);
573 void ModuleSpanningTree::AutoConnectServers(time_t curtime)
575 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
577 if ((x->AutoConnect) && (curtime >= x->NextConnectTime))
579 x->NextConnectTime = curtime + x->AutoConnect;
580 TreeServer* CheckDupe = Utils->FindServer(x->Name.c_str());
581 if (x->FailOver.length())
583 TreeServer* CheckFailOver = Utils->FindServer(x->FailOver.c_str());
586 /* The failover for this server is currently a member of the network.
587 * The failover probably succeeded, where the main link did not.
588 * Don't try the main link until the failover is gone again.
595 // an autoconnected server is not connected. Check if its time to connect it
596 ServerInstance->SNO->WriteToSnoMask('l',"AUTOCONNECT: Auto-connecting server \002%s\002 (%lu seconds until next attempt)",x->Name.c_str(),x->AutoConnect);
597 this->ConnectServer(&(*x));
603 int ModuleSpanningTree::HandleVersion(const char** parameters, int pcnt, userrec* user)
605 // we've already checked if pcnt > 0, so this is safe
606 TreeServer* found = Utils->FindServerMask(parameters[0]);
609 std::string Version = found->GetVersion();
610 user->WriteServ("351 %s :%s",user->nick,Version.c_str());
611 if (found == Utils->TreeRoot)
613 ServerInstance->Config->Send005(user);
618 user->WriteServ("402 %s %s :No such server",user->nick,parameters[0]);
623 /* This method will attempt to get a link message out to as many people as is required.
624 * If a user is provided, and that user is local, then the user is sent the message using
625 * WriteServ (they are the local initiator of that message). If the user is remote, they are
626 * sent that message remotely via PUSH.
627 * If the user is NULL, then the notice is sent locally via WriteToSnoMask with snomask 'l',
628 * and remotely via SNONOTICE with mask 'l'.
630 void ModuleSpanningTree::RemoteMessage(userrec* user, const char* format, ...)
632 /* This could cause an infinite loop, because DoOneToMany() will, on error,
633 * call TreeSocket::OnError(), which in turn will call this function to
634 * notify everyone of the error. So, drop any messages that are generated
635 * during the sending of another message. -Special */
636 static bool SendingRemoteMessage = false;
637 if (SendingRemoteMessage)
639 SendingRemoteMessage = true;
641 std::deque<std::string> params;
645 va_start(argsPtr, format);
646 vsnprintf(text, MAXBUF, format, argsPtr);
651 /* No user, target it generically at everyone */
652 ServerInstance->SNO->WriteToSnoMask('l', "%s", text);
653 params.push_back("l");
654 params.push_back(std::string(":") + text);
655 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "SNONOTICE", params);
660 user->WriteServ("NOTICE %s :%s", user->nick, text);
663 params.push_back(user->uuid);
664 params.push_back(std::string("::") + ServerInstance->Config->ServerName + " NOTICE " + user->nick + " :*** From " +
665 ServerInstance->Config->ServerName+ ": " + text);
666 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "PUSH", params);
670 SendingRemoteMessage = false;
673 int ModuleSpanningTree::HandleConnect(const char** parameters, int pcnt, userrec* user)
675 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
677 if (ServerInstance->MatchText(x->Name.c_str(),parameters[0]))
679 TreeServer* CheckDupe = Utils->FindServer(x->Name.c_str());
682 RemoteMessage(user, "*** CONNECT: Connecting to server: \002%s\002 (%s:%d)",x->Name.c_str(),(x->HiddenFromStats ? "<hidden>" : x->IPAddr.c_str()),x->Port);
683 ConnectServer(&(*x));
688 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());
693 RemoteMessage(user, "*** CONNECT: No server matching \002%s\002 could be found in the config file.",parameters[0]);
697 void ModuleSpanningTree::BroadcastTimeSync()
699 if (Utils->MasterTime)
701 std::deque<std::string> params;
702 params.push_back(ConvToStr(ServerInstance->Time(false)));
703 params.push_back("FORCE");
704 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "TIMESET", params);
708 int ModuleSpanningTree::OnStats(char statschar, userrec* user, string_list &results)
710 if ((statschar == 'c') || (statschar == 'n'))
712 for (unsigned int i = 0; i < Utils->LinkBlocks.size(); i++)
714 results.push_back(std::string(ServerInstance->Config->ServerName)+" 213 "+user->nick+" "+statschar+" *@"+(Utils->LinkBlocks[i].HiddenFromStats ? "<hidden>" : Utils->LinkBlocks[i].IPAddr)+" * "+Utils->LinkBlocks[i].Name.c_str()+" "+ConvToStr(Utils->LinkBlocks[i].Port)+" "+(Utils->LinkBlocks[i].Hook.empty() ? "plaintext" : Utils->LinkBlocks[i].Hook)+" "+(Utils->LinkBlocks[i].AutoConnect ? 'a' : '-')+'s');
715 if (statschar == 'c')
716 results.push_back(std::string(ServerInstance->Config->ServerName)+" 244 "+user->nick+" H * * "+Utils->LinkBlocks[i].Name.c_str());
718 results.push_back(std::string(ServerInstance->Config->ServerName)+" 219 "+user->nick+" "+statschar+" :End of /STATS report");
719 ServerInstance->SNO->WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)",(!strcmp(user->server,ServerInstance->Config->ServerName) ? "Stats" : "Remote stats"),statschar,user->nick,user->ident,user->host);
723 if (statschar == 'p')
725 /* show all server ports, after showing client ports. -- w00t */
727 for (unsigned int i = 0; i < Utils->Bindings.size(); i++)
729 std::string ip = Utils->Bindings[i]->IP;
733 std::string transport("plaintext");
734 if (Utils->Bindings[i]->GetHook())
735 transport = InspSocketNameRequest(this, Utils->Bindings[i]->GetHook()).Send();
737 results.push_back(ConvToStr(ServerInstance->Config->ServerName) + " 249 "+user->nick+" :" + ip + ":" + ConvToStr(Utils->Bindings[i]->port)+
738 " (server, " + transport + ")");
744 int ModuleSpanningTree::OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
746 /* If the command doesnt appear to be valid, we dont want to mess with it. */
750 if (command == "CONNECT")
752 return this->HandleConnect(parameters,pcnt,user);
754 else if (command == "STATS")
756 return this->HandleStats(parameters,pcnt,user);
758 else if (command == "MOTD")
760 return this->HandleMotd(parameters,pcnt,user);
762 else if (command == "ADMIN")
764 return this->HandleAdmin(parameters,pcnt,user);
766 else if (command == "SQUIT")
768 return this->HandleSquit(parameters,pcnt,user);
770 else if (command == "MAP")
772 this->HandleMap(parameters,pcnt,user);
775 else if ((command == "TIME") && (pcnt > 0))
777 return this->HandleTime(parameters,pcnt,user);
779 else if (command == "LUSERS")
781 this->HandleLusers(parameters,pcnt,user);
784 else if (command == "LINKS")
786 this->HandleLinks(parameters,pcnt,user);
789 else if (command == "WHOIS")
794 return this->HandleRemoteWhois(parameters,pcnt,user);
797 else if ((command == "VERSION") && (pcnt > 0))
799 this->HandleVersion(parameters,pcnt,user);
802 else if ((command == "MODULES") && (pcnt > 0))
804 return this->HandleModules(parameters,pcnt,user);
809 void ModuleSpanningTree::OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
811 if ((result == CMD_SUCCESS) && (ServerInstance->IsValidModuleCommand(command, pcnt, user)))
813 /* Safe, we know its non-null because IsValidModuleCommand returned true */
814 command_t* thiscmd = ServerInstance->Parser->GetHandler(command);
815 // this bit of code cleverly routes all module commands
816 // to all remote severs *automatically* so that modules
817 // can just handle commands locally, without having
818 // to have any special provision in place for remote
819 // commands and linking protocols.
820 std::deque<std::string> params;
822 int n_translate = thiscmd->translation.size();
823 TranslateType translate_to;
825 /* To make sure that parameters with spaces, or empty
826 * parameters, etc, are always sent properly, *always*
827 * prefix the last parameter with a :. This also removes
828 * an extra strchr() */
829 for (int j = 0; j < pcnt; j++)
833 /* Map all items to UUIDs where neccessary */
836 /* We have a translation mapping for this index */
837 translate_to = thiscmd->translation[j] != TR_END ? thiscmd->translation[j] : TR_TEXT;
840 translate_to = TR_TEXT;
842 ServerInstance->Log(DEBUG,"TRANSLATION: %s - type is %d", parameters[j], translate_to);
843 ServerInstance->Parser->TranslateUIDs(translate_to, parameters[j], target);
846 params.push_back(":" + target);
848 params.push_back(target);
850 Utils->DoOneToMany(user->uuid, command, params);
854 void ModuleSpanningTree::OnGetServerDescription(const std::string &servername,std::string &description)
856 TreeServer* s = Utils->FindServer(servername);
859 description = s->GetDesc();
863 void ModuleSpanningTree::OnUserInvite(userrec* source,userrec* dest,chanrec* channel)
865 if (IS_LOCAL(source))
867 std::deque<std::string> params;
868 params.push_back(dest->uuid);
869 params.push_back(channel->name);
870 Utils->DoOneToMany(source->uuid,"INVITE",params);
874 void ModuleSpanningTree::OnPostLocalTopicChange(userrec* user, chanrec* chan, const std::string &topic)
876 std::deque<std::string> params;
877 params.push_back(chan->name);
878 params.push_back(":"+topic);
879 Utils->DoOneToMany(user->uuid,"TOPIC",params);
882 void ModuleSpanningTree::OnWallops(userrec* user, const std::string &text)
886 std::deque<std::string> params;
887 params.push_back(":"+text);
888 Utils->DoOneToMany(user->uuid,"WALLOPS",params);
892 void ModuleSpanningTree::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
894 if (target_type == TYPE_USER)
896 userrec* d = (userrec*)dest;
897 if ((d->GetFd() < 0) && (IS_LOCAL(user)))
899 std::deque<std::string> params;
901 params.push_back(d->uuid);
902 params.push_back(":"+text);
903 Utils->DoOneToOne(user->uuid,"NOTICE",params,d->server);
906 else if (target_type == TYPE_CHANNEL)
910 chanrec *c = (chanrec*)dest;
913 std::string cname = c->name;
915 cname = status + cname;
917 Utils->GetListOfServersForChannel(c,list,status,exempt_list);
918 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
920 TreeSocket* Sock = i->second->GetSocket();
922 Sock->WriteLine(":"+std::string(user->uuid)+" NOTICE "+cname+" :"+text);
927 else if (target_type == TYPE_SERVER)
931 char* target = (char*)dest;
932 std::deque<std::string> par;
933 par.push_back(target);
934 par.push_back(":"+text);
935 Utils->DoOneToMany(user->uuid,"NOTICE",par);
940 void ModuleSpanningTree::OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
942 if (target_type == TYPE_USER)
944 // route private messages which are targetted at clients only to the server
945 // which needs to receive them
946 userrec* d = (userrec*)dest;
947 if ((d->GetFd() < 0) && (IS_LOCAL(user)))
949 std::deque<std::string> params;
951 params.push_back(d->uuid);
952 params.push_back(":"+text);
953 Utils->DoOneToOne(user->uuid,"PRIVMSG",params,d->server);
956 else if (target_type == TYPE_CHANNEL)
960 chanrec *c = (chanrec*)dest;
963 std::string cname = c->name;
965 cname = status + cname;
967 Utils->GetListOfServersForChannel(c,list,status,exempt_list);
968 for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
970 TreeSocket* Sock = i->second->GetSocket();
972 Sock->WriteLine(":"+std::string(user->uuid)+" PRIVMSG "+cname+" :"+text);
977 else if (target_type == TYPE_SERVER)
981 char* target = (char*)dest;
982 std::deque<std::string> par;
983 par.push_back(target);
984 par.push_back(":"+text);
985 Utils->DoOneToMany(user->uuid,"PRIVMSG",par);
990 void ModuleSpanningTree::OnBackgroundTimer(time_t curtime)
992 AutoConnectServers(curtime);
993 DoPingChecks(curtime);
996 void ModuleSpanningTree::OnUserJoin(userrec* user, chanrec* channel, bool &silent)
998 // Only do this for local users
1001 if (channel->GetUserCounter() == 1)
1003 std::deque<std::string> params;
1004 // set up their permissions and the channel TS with FJOIN.
1005 // All users are FJOINed now, because a module may specify
1006 // new joining permissions for the user.
1007 params.push_back(channel->name);
1008 params.push_back(ConvToStr(channel->age));
1009 params.push_back(std::string(channel->GetAllPrefixChars(user))+","+std::string(user->uuid));
1010 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params);
1011 /* First user in, sync the modes for the channel */
1013 params.push_back(channel->ChanModes(true));
1014 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",params);
1018 std::deque<std::string> params;
1019 params.push_back(channel->name);
1020 params.push_back(ConvToStr(channel->age));
1021 Utils->DoOneToMany(user->uuid,"JOIN",params);
1026 void ModuleSpanningTree::OnChangeHost(userrec* user, const std::string &newhost)
1028 // only occurs for local clients
1029 if (user->registered != REG_ALL)
1031 std::deque<std::string> params;
1032 params.push_back(newhost);
1033 Utils->DoOneToMany(user->uuid,"FHOST",params);
1036 void ModuleSpanningTree::OnChangeName(userrec* user, const std::string &gecos)
1038 // only occurs for local clients
1039 if (user->registered != REG_ALL)
1041 std::deque<std::string> params;
1042 params.push_back(gecos);
1043 Utils->DoOneToMany(user->uuid,"FNAME",params);
1046 void ModuleSpanningTree::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
1050 std::deque<std::string> params;
1051 params.push_back(channel->name);
1052 if (!partmessage.empty())
1053 params.push_back(":"+partmessage);
1054 Utils->DoOneToMany(user->uuid,"PART",params);
1058 void ModuleSpanningTree::OnUserConnect(userrec* user)
1062 std::deque<std::string> params;
1063 params.push_back(user->uuid);
1064 params.push_back(ConvToStr(user->age));
1065 params.push_back(user->nick);
1066 params.push_back(user->host);
1067 params.push_back(user->dhost);
1068 params.push_back(user->ident);
1069 params.push_back("+"+std::string(user->FormatModes()));
1070 params.push_back(user->GetIPString());
1071 params.push_back(ConvToStr(user->signon));
1072 params.push_back(":"+std::string(user->fullname));
1073 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
1074 // User is Local, change needs to be reflected!
1075 TreeServer* SourceServer = Utils->FindServer(user->server);
1078 SourceServer->AddUserCount();
1083 void ModuleSpanningTree::OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
1085 if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
1087 std::deque<std::string> params;
1089 if (oper_message != reason)
1091 params.push_back(":"+oper_message);
1092 Utils->DoOneToMany(user->uuid,"OPERQUIT",params);
1095 params.push_back(":"+reason);
1096 Utils->DoOneToMany(user->uuid,"QUIT",params);
1098 // Regardless, We need to modify the user Counts..
1099 TreeServer* SourceServer = Utils->FindServer(user->server);
1102 SourceServer->DelUserCount();
1106 void ModuleSpanningTree::OnUserPostNick(userrec* user, const std::string &oldnick)
1110 std::deque<std::string> params;
1111 params.push_back(user->nick);
1113 /** IMPORTANT: We don't update the TS if the oldnick is just a case change of the newnick!
1115 if (irc::string(user->nick) != assign(oldnick))
1116 user->age = ServerInstance->Time(true);
1118 params.push_back(ConvToStr(user->age));
1119 Utils->DoOneToMany(user->uuid,"NICK",params);
1123 void ModuleSpanningTree::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason, bool &silent)
1125 if ((source) && (IS_LOCAL(source)))
1127 std::deque<std::string> params;
1128 params.push_back(chan->name);
1129 params.push_back(user->uuid);
1130 params.push_back(":"+reason);
1131 Utils->DoOneToMany(source->uuid,"KICK",params);
1135 std::deque<std::string> params;
1136 params.push_back(chan->name);
1137 params.push_back(user->uuid);
1138 params.push_back(":"+reason);
1139 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"KICK",params);
1143 void ModuleSpanningTree::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason, const std::string &operreason)
1145 std::deque<std::string> params;
1146 params.push_back(":"+reason);
1147 Utils->DoOneToMany(dest->uuid,"OPERQUIT",params);
1149 params.push_back(dest->uuid);
1150 params.push_back(":"+reason);
1151 dest->SetOperQuit(operreason);
1152 Utils->DoOneToMany(source->uuid,"KILL",params);
1155 void ModuleSpanningTree::OnRehash(userrec* user, const std::string ¶meter)
1157 if (!parameter.empty())
1159 std::deque<std::string> params;
1160 params.push_back(parameter);
1161 Utils->DoOneToMany(user ? user->nick : ServerInstance->Config->GetSID(), "REHASH", params);
1163 if (ServerInstance->MatchText(ServerInstance->Config->ServerName,parameter))
1165 ServerInstance->WriteOpers("*** Remote rehash initiated locally by \002%s\002", user ? user->nick : ServerInstance->Config->ServerName);
1166 ServerInstance->RehashServer();
1169 Utils->ReadConfiguration(false);
1170 InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance);
1173 // note: the protocol does not allow direct umode +o except
1174 // via NICK with 8 params. sending OPERTYPE infers +o modechange
1176 void ModuleSpanningTree::OnOper(userrec* user, const std::string &opertype)
1180 std::deque<std::string> params;
1181 params.push_back(opertype);
1182 Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
1186 void ModuleSpanningTree::OnLine(userrec* source, const std::string &host, bool adding, char linetype, long duration, const std::string &reason)
1190 /* Server-set lines */
1192 snprintf(data,MAXBUF,"%c %s %s %lu %lu :%s", linetype, host.c_str(), ServerInstance->Config->ServerName, (unsigned long)ServerInstance->Time(false),
1193 (unsigned long)duration, reason.c_str());
1194 std::deque<std::string> params;
1195 params.push_back(data);
1196 Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ADDLINE", params);
1200 if (IS_LOCAL(source))
1203 snprintf(type,8,"%cLINE",linetype);
1204 std::string stype = type;
1207 char sduration[MAXBUF];
1208 snprintf(sduration,MAXBUF,"%ld",duration);
1209 std::deque<std::string> params;
1210 params.push_back(host);
1211 params.push_back(sduration);
1212 params.push_back(":"+reason);
1213 Utils->DoOneToMany(source->uuid,stype,params);
1217 std::deque<std::string> params;
1218 params.push_back(host);
1219 Utils->DoOneToMany(source->uuid,stype,params);
1225 void ModuleSpanningTree::OnAddGLine(long duration, userrec* source, const std::string &reason, const std::string &hostmask)
1227 OnLine(source,hostmask,true,'G',duration,reason);
1230 void ModuleSpanningTree::OnAddZLine(long duration, userrec* source, const std::string &reason, const std::string &ipmask)
1232 OnLine(source,ipmask,true,'Z',duration,reason);
1235 void ModuleSpanningTree::OnAddQLine(long duration, userrec* source, const std::string &reason, const std::string &nickmask)
1237 OnLine(source,nickmask,true,'Q',duration,reason);
1240 void ModuleSpanningTree::OnAddELine(long duration, userrec* source, const std::string &reason, const std::string &hostmask)
1242 OnLine(source,hostmask,true,'E',duration,reason);
1245 void ModuleSpanningTree::OnDelGLine(userrec* source, const std::string &hostmask)
1247 OnLine(source,hostmask,false,'G',0,"");
1250 void ModuleSpanningTree::OnDelZLine(userrec* source, const std::string &ipmask)
1252 OnLine(source,ipmask,false,'Z',0,"");
1255 void ModuleSpanningTree::OnDelQLine(userrec* source, const std::string &nickmask)
1257 OnLine(source,nickmask,false,'Q',0,"");
1260 void ModuleSpanningTree::OnDelELine(userrec* source, const std::string &hostmask)
1262 OnLine(source,hostmask,false,'E',0,"");
1265 void ModuleSpanningTree::OnMode(userrec* user, void* dest, int target_type, const std::string &text)
1267 if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
1269 std::deque<std::string> params;
1270 std::string command;
1271 std::string output_text;
1273 ServerInstance->Parser->TranslateUIDs(TR_SPACENICKLIST, text, output_text);
1275 if (target_type == TYPE_USER)
1277 userrec* u = (userrec*)dest;
1278 params.push_back(u->uuid);
1279 params.push_back(output_text);
1284 chanrec* c = (chanrec*)dest;
1285 params.push_back(c->name);
1286 params.push_back(ConvToStr(c->age));
1287 params.push_back(output_text);
1291 Utils->DoOneToMany(user->uuid, command, params);
1295 void ModuleSpanningTree::OnSetAway(userrec* user)
1299 std::deque<std::string> params;
1300 params.push_back(":"+std::string(user->awaymsg));
1301 Utils->DoOneToMany(user->uuid,"AWAY",params);
1305 void ModuleSpanningTree::OnCancelAway(userrec* user)
1309 std::deque<std::string> params;
1311 Utils->DoOneToMany(user->uuid,"AWAY",params);
1315 void ModuleSpanningTree::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline)
1317 TreeSocket* s = (TreeSocket*)opaque;
1318 std::string output_text;
1320 ServerInstance->Parser->TranslateUIDs(TR_SPACENICKLIST, modeline, output_text);
1324 if (target_type == TYPE_USER)
1326 userrec* u = (userrec*)target;
1327 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" FMODE "+u->uuid+" "+ConvToStr(u->age)+" "+output_text);
1331 chanrec* c = (chanrec*)target;
1332 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" FMODE "+c->name+" "+ConvToStr(c->age)+" "+output_text);
1337 void ModuleSpanningTree::ProtoSendMetaData(void* opaque, int target_type, void* target, const std::string &extname, const std::string &extdata)
1339 TreeSocket* s = (TreeSocket*)opaque;
1342 if (target_type == TYPE_USER)
1344 userrec* u = (userrec*)target;
1345 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
1347 else if (target_type == TYPE_CHANNEL)
1349 chanrec* c = (chanrec*)target;
1350 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
1353 if (target_type == TYPE_OTHER)
1355 s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
1359 void ModuleSpanningTree::OnEvent(Event* event)
1361 std::deque<std::string>* params = (std::deque<std::string>*)event->GetData();
1362 if (event->GetEventID() == "send_metadata")
1364 if (params->size() < 3)
1366 (*params)[2] = ":" + (*params)[2];
1367 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",*params);
1369 else if (event->GetEventID() == "send_topic")
1371 if (params->size() < 2)
1373 (*params)[1] = ":" + (*params)[1];
1374 params->insert(params->begin() + 1,ServerInstance->Config->ServerName);
1375 params->insert(params->begin() + 1,ConvToStr(ServerInstance->Time(true)));
1376 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC",*params);
1378 else if (event->GetEventID() == "send_mode")
1380 if (params->size() < 2)
1382 // Insert the TS value of the object, either userrec or chanrec
1384 std::string output_text;
1386 /* Warning: in-place translation is only safe for type TR_NICK */
1387 for (size_t n = 0; n < params->size(); n++)
1388 ServerInstance->Parser->TranslateUIDs(TR_NICK, (*params)[n], (*params)[n]);
1390 userrec* a = ServerInstance->FindNick((*params)[0]);
1394 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",*params);
1399 chanrec* a = ServerInstance->FindChan((*params)[0]);
1403 params->insert(params->begin() + 1,ConvToStr(ourTS));
1404 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",*params);
1408 else if (event->GetEventID() == "send_mode_explicit")
1410 if (params->size() < 2)
1412 std::string output_text;
1414 /* Warning: in-place translation is only safe for type TR_NICK */
1415 for (size_t n = 0; n < params->size(); n++)
1416 ServerInstance->Parser->TranslateUIDs(TR_NICK, (*params)[n], (*params)[n]);
1418 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",*params);
1420 else if (event->GetEventID() == "send_opers")
1422 if (params->size() < 1)
1424 (*params)[0] = ":" + (*params)[0];
1425 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"OPERNOTICE",*params);
1427 else if (event->GetEventID() == "send_modeset")
1429 if (params->size() < 2)
1431 (*params)[1] = ":" + (*params)[1];
1432 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODENOTICE",*params);
1434 else if (event->GetEventID() == "send_snoset")
1436 if (params->size() < 2)
1438 (*params)[1] = ":" + (*params)[1];
1439 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"SNONOTICE",*params);
1441 else if (event->GetEventID() == "send_push")
1443 if (params->size() < 2)
1446 userrec *a = ServerInstance->FindNick((*params)[0]);
1451 (*params)[0] = a->uuid;
1452 (*params)[1] = ":" + (*params)[1];
1453 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", *params, a->server);
1457 ModuleSpanningTree::~ModuleSpanningTree()
1459 /* This will also free the listeners */
1462 ServerInstance->Timers->DelTimer(SyncTimer);
1464 ServerInstance->Timers->DelTimer(RefreshTimer);
1466 ServerInstance->Modules->DoneWithInterface("InspSocketHook");
1469 Version ModuleSpanningTree::GetVersion()
1471 return Version(1,1,0,2,VF_VENDOR,API_VERSION);
1474 void ModuleSpanningTree::Implements(char* List)
1476 List[I_OnPreCommand] = List[I_OnGetServerDescription] = List[I_OnUserInvite] = List[I_OnPostLocalTopicChange] = 1;
1477 List[I_OnWallops] = List[I_OnUserNotice] = List[I_OnUserMessage] = List[I_OnBackgroundTimer] = 1;
1478 List[I_OnUserJoin] = List[I_OnChangeHost] = List[I_OnChangeName] = List[I_OnUserPart] = List[I_OnUserConnect] = 1;
1479 List[I_OnUserQuit] = List[I_OnUserPostNick] = List[I_OnUserKick] = List[I_OnRemoteKill] = List[I_OnRehash] = 1;
1480 List[I_OnOper] = List[I_OnAddGLine] = List[I_OnAddZLine] = List[I_OnAddQLine] = List[I_OnAddELine] = 1;
1481 List[I_OnDelGLine] = List[I_OnDelZLine] = List[I_OnDelQLine] = List[I_OnDelELine] = List[I_ProtoSendMode] = List[I_OnMode] = 1;
1482 List[I_OnStats] = List[I_ProtoSendMetaData] = List[I_OnEvent] = List[I_OnSetAway] = List[I_OnCancelAway] = List[I_OnPostCommand] = 1;
1485 /* It is IMPORTANT that m_spanningtree is the last module in the chain
1486 * so that any activity it sees is FINAL, e.g. we arent going to send out
1487 * a NICK message before m_cloaking has finished putting the +x on the user,
1489 * Therefore, we return PRIORITY_LAST to make sure we end up at the END of
1490 * the module call queue.
1492 Priority ModuleSpanningTree::Prioritize()
1494 return PRIORITY_LAST;
1497 MODULE_INIT(ModuleSpanningTree)