]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
3f5a910c9802627d971c6ccc8f6528745d4f3ccf
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "configreader.h"
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "commands/cmd_whois.h"
20 #include "commands/cmd_stats.h"
21 #include "socket.h"
22 #include "wildcard.h"
23 #include "xline.h"
24 #include "transport.h"
25 #include "socketengine.h"
26
27 #include "m_spanningtree/main.h"
28 #include "m_spanningtree/utils.h"
29 #include "m_spanningtree/treeserver.h"
30 #include "m_spanningtree/link.h"
31 #include "m_spanningtree/treesocket.h"
32 #include "m_spanningtree/resolvers.h"
33
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 */
35
36 /** Yay for fast searches!
37  * This is hundreds of times faster than recursion
38  * or even scanning a linked list, especially when
39  * there are more than a few servers to deal with.
40  * (read as: lots).
41  */
42 TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
43 {
44         server_hash::iterator iter = serverlist.find(ServerName.c_str());
45         if (iter != serverlist.end())
46         {
47                 return iter->second;
48         }
49         else
50         {
51                 return NULL;
52         }
53 }
54
55 TreeServer* SpanningTreeUtilities::FindRemoteBurstServer(TreeServer* Server)
56 {
57         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
58         if (iter != RemoteServersBursting.end())
59                 return iter->second;
60         else
61                 return NULL;
62 }
63
64 TreeSocket* SpanningTreeUtilities::FindBurstingServer(const std::string &ServerName)
65 {
66         std::map<irc::string,TreeSocket*>::iterator iter;
67         iter = burstingserverlist.find(ServerName.c_str());
68         if (iter != burstingserverlist.end())
69         {
70                 return iter->second;
71         }
72         else
73         {
74                 return NULL;
75         }
76 }
77
78 void SpanningTreeUtilities::SetRemoteBursting(TreeServer* Server, bool bursting)
79 {
80         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
81         if (bursting)
82         {
83                 if (iter == RemoteServersBursting.end())
84                         RemoteServersBursting.insert(make_pair(Server->GetName(), Server));
85                 else return;
86         }
87         else
88         {
89                 if (iter != RemoteServersBursting.end())
90                         RemoteServersBursting.erase(iter);
91                 else return;
92         }
93         ServerInstance->Log(DEBUG,"Server %s is %sbursting nicknames", Server->GetName().c_str(), bursting ? "" : "no longer ");
94 }
95
96 void SpanningTreeUtilities::AddBurstingServer(const std::string &ServerName, TreeSocket* s)
97 {
98         std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.find(ServerName.c_str());
99         if (iter == burstingserverlist.end())
100                 burstingserverlist[ServerName.c_str()] = s;
101 }
102
103 void SpanningTreeUtilities::DelBurstingServer(TreeSocket* s)
104 {
105          for (std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.begin(); iter != burstingserverlist.end(); iter++)
106          {
107                  if (iter->second == s)
108                  {
109                          burstingserverlist.erase(iter);
110                          return;
111                  }
112          }
113 }
114
115 /** Returns the locally connected server we must route a
116  * message through to reach server 'ServerName'. This
117  * only applies to one-to-one and not one-to-many routing.
118  * See the comments for the constructor of TreeServer
119  * for more details.
120  */
121 TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
122 {
123         if (ServerName.c_str() == TreeRoot->GetName())
124                 return NULL;
125         TreeServer* Found = FindServer(ServerName);
126         if (Found)
127         {
128                 return Found->GetRoute();
129         }
130         else
131         {
132                 return NULL;
133         }
134 }
135
136 /** Find the first server matching a given glob mask.
137  * Theres no find-using-glob method of hash_map [awwww :-(]
138  * so instead, we iterate over the list using an iterator
139  * and match each one until we get a hit. Yes its slow,
140  * deal with it.
141  */
142 TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
143 {
144         for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
145         {
146                 if (match(i->first.c_str(),ServerName.c_str()))
147                         return i->second;
148         }
149         return NULL;
150 }
151
152 TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
153 {
154         server_hash::iterator iter = sidlist.find(id);
155         if (iter != sidlist.end())
156                 return iter->second;
157         else
158                 return NULL;
159 }
160
161 /* A convenient wrapper that returns true if a server exists */
162 bool SpanningTreeUtilities::IsServer(const std::string &ServerName)
163 {
164         return (FindServer(ServerName) != NULL);
165 }
166
167 SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
168 {
169         Bindings.clear();
170
171         lines_to_apply = 0;
172
173         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
174
175         modulelist* ml = ServerInstance->FindInterface("InspSocketHook");
176
177         /* Did we find any modules? */
178         if (ml)
179         {
180                 /* Yes, enumerate them all to find out the hook name */
181                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
182                 {
183                         /* Make a request to it for its name, its implementing
184                          * InspSocketHook so we know its safe to do this
185                          */
186                         std::string name = InspSocketNameRequest((Module*)Creator, *m).Send();
187                         /* Build a map of them */
188                         hooks[name.c_str()] = *m;
189                         hooknames.push_back(name);
190                 }
191         }
192
193         this->ReadConfiguration(true);
194 }
195
196 SpanningTreeUtilities::~SpanningTreeUtilities()
197 {
198         for (unsigned int i = 0; i < Bindings.size(); i++)
199         {
200                 ServerInstance->SE->DelFd(Bindings[i]);
201                 Bindings[i]->Close();
202         }
203         while (TreeRoot->ChildCount())
204         {
205                 TreeServer* child_server = TreeRoot->GetChild(0);
206                 if (child_server)
207                 {
208                         TreeSocket* sock = child_server->GetSocket();
209                         ServerInstance->SE->DelFd(sock);
210                         sock->Close();
211                 }
212         }
213         delete TreeRoot;
214         ServerInstance->InspSocketCull();
215 }
216
217 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
218 {
219         if (list.find(server) == list.end())
220                 list[server] = server;
221 }
222
223 /* returns a list of DIRECT servernames for a specific channel */
224 void SpanningTreeUtilities::GetListOfServersForChannel(chanrec* c, TreeServerList &list, char status, const CUList &exempt_list)
225 {
226         CUList *ulist;
227         switch (status)
228         {
229                 case '@':
230                         ulist = c->GetOppedUsers();
231                 break;
232                 case '%':
233                         ulist = c->GetHalfoppedUsers();
234                 break;
235                 case '+':
236                         ulist = c->GetVoicedUsers();
237                 break;
238                 default:
239                         ulist = c->GetUsers();
240                 break;
241         }
242         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
243         {
244                 if ((i->first->GetFd() < 0) && (exempt_list.find(i->first) == exempt_list.end()))
245                 {
246                         TreeServer* best = this->BestRouteTo(i->first->server);
247                         if (best)
248                                 AddThisServer(best,list);
249                 }
250         }
251         return;
252 }
253
254 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params)
255 {
256         char pfx = 0;
257         TreeServer* omitroute = this->BestRouteTo(omit);
258         if ((command == "NOTICE") || (command == "PRIVMSG"))
259         {
260                 if (params.size() >= 2)
261                 {
262                         /* Prefixes */
263                         if ((*(params[0].c_str()) == '@') || (*(params[0].c_str()) == '%') || (*(params[0].c_str()) == '+'))
264                         {
265                                 pfx = params[0][0];
266                                 params[0] = params[0].substr(1, params[0].length()-1);
267                         }
268                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
269                         {
270                                 // special routing for private messages/notices
271                                 userrec* d = ServerInstance->FindNick(params[0]);
272                                 if (d)
273                                 {
274                                         std::deque<std::string> par;
275                                         par.push_back(params[0]);
276                                         par.push_back(":"+params[1]);
277                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
278                                         return true;
279                                 }
280                         }
281                         else if (*(params[0].c_str()) == '$')
282                         {
283                                 std::deque<std::string> par;
284                                 par.push_back(params[0]);
285                                 par.push_back(":"+params[1]);
286                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
287                                 return true;
288                         }
289                         else
290                         {
291                                 chanrec* c = ServerInstance->FindChan(params[0]);
292                                 userrec* u = ServerInstance->FindNick(prefix);
293                                 if (c && u)
294                                 {
295                                         CUList elist;
296                                         TreeServerList list;
297                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist));
298                                         GetListOfServersForChannel(c,list,pfx,elist);
299
300                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
301                                         {
302                                                 TreeSocket* Sock = i->second->GetSocket();
303                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
304                                                 {
305                                                         Sock->WriteLine(data);
306                                                 }
307                                         }
308                                         return true;
309                                 }
310                         }
311                 }
312         }
313         unsigned int items =this->TreeRoot->ChildCount();
314         for (unsigned int x = 0; x < items; x++)
315         {
316                 TreeServer* Route = this->TreeRoot->GetChild(x);
317                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
318                 {
319                         TreeSocket* Sock = Route->GetSocket();
320                         if (Sock)
321                                 Sock->WriteLine(data);
322                 }
323         }
324         return true;
325 }
326
327 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit)
328 {
329         TreeServer* omitroute = this->BestRouteTo(omit);
330         std::string FullLine = ":" + prefix + " " + command;
331         unsigned int words = params.size();
332         for (unsigned int x = 0; x < words; x++)
333         {
334                 FullLine = FullLine + " " + params[x];
335         }
336         unsigned int items = this->TreeRoot->ChildCount();
337         for (unsigned int x = 0; x < items; x++)
338         {
339                 TreeServer* Route = this->TreeRoot->GetChild(x);
340                 // Send the line IF:
341                 // The route has a socket (its a direct connection)
342                 // The route isnt the one to be omitted
343                 // The route isnt the path to the one to be omitted
344                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
345                 {
346                         TreeSocket* Sock = Route->GetSocket();
347                         if (Sock)
348                                 Sock->WriteLine(FullLine);
349                 }
350         }
351         return true;
352 }
353
354 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params)
355 {
356         std::string FullLine = ":" + prefix + " " + command;
357         unsigned int words = params.size();
358         for (unsigned int x = 0; x < words; x++)
359         {
360                 FullLine = FullLine + " " + params[x];
361         }
362         unsigned int items = this->TreeRoot->ChildCount();
363         for (unsigned int x = 0; x < items; x++)
364         {
365                 TreeServer* Route = this->TreeRoot->GetChild(x);
366                 if (Route && Route->GetSocket())
367                 {
368                         TreeSocket* Sock = Route->GetSocket();
369                         if (Sock)
370                                 Sock->WriteLine(FullLine);
371                 }
372         }
373         return true;
374 }
375
376 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params)
377 {
378         std::string spfx = prefix;
379         std::string scmd = command;
380         return this->DoOneToMany(spfx, scmd, params);
381 }
382
383 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit)
384 {
385         std::string spfx = prefix;
386         std::string scmd = command;
387         return this->DoOneToAllButSender(spfx, scmd, params, omit);
388 }
389
390 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target)
391 {
392         TreeServer* Route = this->BestRouteTo(target);
393         if (Route)
394         {
395                 std::string FullLine = ":" + prefix + " " + command;
396                 unsigned int words = params.size();
397                 for (unsigned int x = 0; x < words; x++)
398                 {
399                         FullLine = FullLine + " " + params[x];
400                 }
401                 if (Route && Route->GetSocket())
402                 {
403                         TreeSocket* Sock = Route->GetSocket();
404                         if (Sock)
405                                 Sock->WriteLine(FullLine);
406                 }
407                 return true;
408         }
409         else
410         {
411                 return false;
412         }
413 }
414
415 void SpanningTreeUtilities::RefreshIPCache()
416 {
417         ValidIPs.clear();
418         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
419         {
420                 if ((!L->IPAddr.empty()) && (!L->RecvPass.empty()) && (!L->SendPass.empty()) && (!L->Name.empty()) && (L->Port))
421                 {
422                         ValidIPs.push_back(L->IPAddr);
423
424                         if (L->AllowMask.length())
425                                 ValidIPs.push_back(L->AllowMask);
426
427                         /* Needs resolving */
428                         bool ipvalid = true;
429                         QueryType start_type = DNS_QUERY_A;
430 #ifdef IPV6
431                         start_type = DNS_QUERY_AAAA;
432                         if (strchr(L->IPAddr.c_str(),':'))
433                         {
434                                 in6_addr n;
435                                 if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
436                                         ipvalid = false;
437                         }
438                         else
439 #endif
440                         {
441                                 in_addr n;
442                                 if (inet_aton(L->IPAddr.c_str(),&n) < 1)
443                                         ipvalid = false;
444                         }
445                         if (!ipvalid)
446                         {
447                                 try
448                                 {
449                                         bool cached;
450                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type);
451                                         ServerInstance->AddResolver(sr, cached);
452                                 }
453                                 catch (...)
454                                 {
455                                 }
456                         }
457                 }
458         }
459 }
460
461 void SpanningTreeUtilities::ReadConfiguration(bool rebind)
462 {
463         ConfigReader* Conf = new ConfigReader(ServerInstance);
464         if (rebind)
465         {
466                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
467                 {
468                         std::string Type = Conf->ReadValue("bind","type",j);
469                         std::string IP = Conf->ReadValue("bind","address",j);
470                         std::string Port = Conf->ReadValue("bind","port",j);
471                         std::string transport = Conf->ReadValue("bind","transport",j);
472                         if (Type == "servers")
473                         {
474                                 irc::portparser portrange(Port, false);
475                                 int portno = -1;
476                                 while ((portno = portrange.GetToken()))
477                                 {
478                                         if (IP == "*")
479                                                 IP.clear();
480
481                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
482                                         {
483                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for port %s:%s - maybe you forgot to load it BEFORE m_spanningtree in your config file? - Skipping this port binding", transport.c_str(), IP.c_str(), Port.c_str());
484                                                 break;
485                                         }
486
487                                         TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
488                                         if (listener->GetState() == I_LISTENING)
489                                         {
490                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
491                                                 Bindings.push_back(listener);
492                                         }
493                                         else
494                                         {
495                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port: %s:%d: %s",IP.c_str(), portno, strerror(errno));
496                                                 listener->Close();
497                                         }
498                                 }
499                         }
500                 }
501         }
502         FlatLinks = Conf->ReadFlag("options","flatlinks",0);
503         HideULines = Conf->ReadFlag("options","hideulines",0);
504         AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
505         EnableTimeSync = Conf->ReadFlag("timesync","enable",0);
506         MasterTime = Conf->ReadFlag("timesync", "master", 0);
507         ChallengeResponse = !Conf->ReadFlag("options", "disablehmac", 0);
508         quiet_bursts = Conf->ReadFlag("options", "quietbursts", 0);
509         PingWarnTime = Conf->ReadInteger("options", "pingwarning", 0, true);
510         PingFreq = Conf->ReadInteger("options", "serverpingfreq", 0, true);
511
512         if (PingFreq == 0)
513                 PingFreq = 60;
514
515         if (PingWarnTime < 0 || PingWarnTime > PingFreq - 1)
516                 PingWarnTime = 0;
517
518         LinkBlocks.clear();
519         ValidIPs.clear();
520         for (int j = 0; j < Conf->Enumerate("link"); j++)
521         {
522                 Link L;
523                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
524                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
525                 L.AllowMask = Allow;
526                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
527                 L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
528                 L.Port = Conf->ReadInteger("link", "port", j, true);
529                 L.SendPass = Conf->ReadValue("link", "sendpass", j);
530                 L.RecvPass = Conf->ReadValue("link", "recvpass", j);
531                 L.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
532                 L.HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
533                 L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
534                 L.Hook = Conf->ReadValue("link", "transport", j);
535                 L.Bind = Conf->ReadValue("link", "bind", j);
536                 L.Hidden = Conf->ReadFlag("link", "hidden", j);
537
538                 if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) ==  hooks.end()))
539                 {
540                         ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for link '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.",
541                         L.Hook.c_str(), L.Name.c_str());
542                         continue;
543
544                 }
545
546                 L.NextConnectTime = time(NULL) + L.AutoConnect;
547                 /* Bugfix by brain, do not allow people to enter bad configurations */
548                 if (L.Name != ServerInstance->Config->ServerName)
549                 {
550                         if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
551                         {
552                                 ValidIPs.push_back(L.IPAddr);
553
554                                 if (Allow.length())
555                                         ValidIPs.push_back(Allow);
556
557                                 /* Needs resolving */
558                                 bool ipvalid = true;
559                                 QueryType start_type = DNS_QUERY_A;
560 #ifdef IPV6
561                                 start_type = DNS_QUERY_AAAA;
562                                 if (strchr(L.IPAddr.c_str(),':'))
563                                 {
564                                         in6_addr n;
565                                         if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
566                                                 ipvalid = false;
567                                 }
568                                 else
569                                 {
570                                         in_addr n;
571                                         if (inet_aton(L.IPAddr.c_str(),&n) < 1)
572                                                 ipvalid = false;
573                                 }
574 #else
575                                 in_addr n;
576                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
577                                         ipvalid = false;
578 #endif
579
580                                 if (!ipvalid)
581                                 {
582                                         try
583                                         {
584                                                 bool cached;
585                                                 SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
586                                                 ServerInstance->AddResolver(sr, cached);
587                                         }
588                                         catch (...)
589                                         {
590                                         }
591                                 }
592
593                                 LinkBlocks.push_back(L);
594                         }
595                         else
596                         {
597                                 if (L.IPAddr.empty())
598                                 {
599                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', IP address not defined!",L.Name.c_str());
600                                 }
601                                 else if (L.RecvPass.empty())
602                                 {
603                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', recvpass not defined!",L.Name.c_str());
604                                 }
605                                 else if (L.SendPass.empty())
606                                 {
607                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', sendpass not defined!",L.Name.c_str());
608                                 }
609                                 else if (L.Name.empty())
610                                 {
611                                         ServerInstance->Log(DEFAULT,"Invalid configuration, link tag without a name!");
612                                 }
613                                 else if (!L.Port)
614                                 {
615                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', no port specified!",L.Name.c_str());
616                                 }
617                         }
618                 }
619                 else
620                 {
621                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', link tag has the same server name as the local server!",L.Name.c_str());
622                 }
623         }
624         DELETE(Conf);
625 }
626
627 void SpanningTreeUtilities::DoFailOver(Link* x)
628 {
629         if (x->FailOver.length())
630         {
631                 if (x->FailOver == x->Name)
632                 {
633                         Creator->RemoteMessage(NULL,"FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Name.c_str());
634                         return;
635                 }
636                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
637                 if (TryThisOne)
638                 {
639                         Creator->RemoteMessage(NULL,"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
640                         Creator->ConnectServer(TryThisOne);
641                 }
642                 else
643                 {
644                         Creator->RemoteMessage(NULL,"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
645                 }
646         }
647 }
648
649 Link* SpanningTreeUtilities::FindLink(const std::string& name)
650 {
651         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
652         {
653                 if (ServerInstance->MatchText(x->Name.c_str(), name.c_str()))
654                 {
655                         return &(*x);
656                 }
657         }
658         return NULL;
659 }
660