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