]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
4e0193727a66617feee4102386aca49ab63073a4
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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         if (this->ServerInstance->IsSID(ServerName))
41                 return this->FindServerID(ServerName);
42
43         server_hash::iterator iter = serverlist.find(ServerName.c_str());
44         if (iter != serverlist.end())
45         {
46                 return iter->second;
47         }
48         else
49         {
50                 return NULL;
51         }
52 }
53
54 TreeServer* SpanningTreeUtilities::FindRemoteBurstServer(TreeServer* Server)
55 {
56         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
57         if (iter != RemoteServersBursting.end())
58                 return iter->second;
59         else
60                 return NULL;
61 }
62
63 TreeSocket* SpanningTreeUtilities::FindBurstingServer(const std::string &ServerName)
64 {
65         std::map<irc::string,TreeSocket*>::iterator iter;
66         iter = burstingserverlist.find(ServerName.c_str());
67         if (iter != burstingserverlist.end())
68         {
69                 return iter->second;
70         }
71         else
72         {
73                 return NULL;
74         }
75 }
76
77 void SpanningTreeUtilities::SetRemoteBursting(TreeServer* Server, bool bursting)
78 {
79         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
80         if (bursting)
81         {
82                 if (iter == RemoteServersBursting.end())
83                         RemoteServersBursting.insert(make_pair(Server->GetName(), Server));
84                 else return;
85         }
86         else
87         {
88                 if (iter != RemoteServersBursting.end())
89                         RemoteServersBursting.erase(iter);
90                 else return;
91         }
92         ServerInstance->Log(DEBUG,"Server %s is %sbursting nicknames", Server->GetName().c_str(), bursting ? "" : "no longer ");
93 }
94
95 void SpanningTreeUtilities::AddBurstingServer(const std::string &ServerName, TreeSocket* s)
96 {
97         std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.find(ServerName.c_str());
98         if (iter == burstingserverlist.end())
99                 burstingserverlist[ServerName.c_str()] = s;
100 }
101
102 void SpanningTreeUtilities::DelBurstingServer(TreeSocket* s)
103 {
104          for (std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.begin(); iter != burstingserverlist.end(); iter++)
105          {
106                  if (iter->second == s)
107                  {
108                          burstingserverlist.erase(iter);
109                          return;
110                  }
111          }
112 }
113
114 /** Returns the locally connected server we must route a
115  * message through to reach server 'ServerName'. This
116  * only applies to one-to-one and not one-to-many routing.
117  * See the comments for the constructor of TreeServer
118  * for more details.
119  */
120 TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
121 {
122         if (ServerName.c_str() == TreeRoot->GetName() || ServerName == ServerInstance->Config->GetSID())
123                 return NULL;
124         TreeServer* Found = FindServer(ServerName);
125         if (Found)
126         {
127                 return Found->GetRoute();
128         }
129         else
130         {
131                 return NULL;
132         }
133 }
134
135 /** Find the first server matching a given glob mask.
136  * Theres no find-using-glob method of hash_map [awwww :-(]
137  * so instead, we iterate over the list using an iterator
138  * and match each one until we get a hit. Yes its slow,
139  * deal with it.
140  */
141 TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
142 {
143         for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
144         {
145                 if (match(i->first.c_str(),ServerName.c_str()))
146                         return i->second;
147         }
148         return NULL;
149 }
150
151 TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
152 {
153         server_hash::iterator iter = sidlist.find(id);
154         if (iter != sidlist.end())
155                 return iter->second;
156         else
157                 return NULL;
158 }
159
160 /* A convenient wrapper that returns true if a server exists */
161 bool SpanningTreeUtilities::IsServer(const std::string &ServerName)
162 {
163         return (FindServer(ServerName) != NULL);
164 }
165
166 SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
167 {
168         Bindings.clear();
169
170         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
171
172         modulelist* ml = ServerInstance->Modules->FindInterface("BufferedSocketHook");
173
174         /* Did we find any modules? */
175         if (ml)
176         {
177                 /* Yes, enumerate them all to find out the hook name */
178                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
179                 {
180                         /* Make a request to it for its name, its implementing
181                          * BufferedSocketHook so we know its safe to do this
182                          */
183                         std::string name = BufferedSocketNameRequest((Module*)Creator, *m).Send();
184                         /* Build a map of them */
185                         hooks[name.c_str()] = *m;
186                         hooknames.push_back(name);
187                 }
188         }
189
190         this->ReadConfiguration(true);
191 }
192
193 SpanningTreeUtilities::~SpanningTreeUtilities()
194 {
195         for (unsigned int i = 0; i < Bindings.size(); i++)
196         {
197                 ServerInstance->SE->DelFd(Bindings[i]);
198                 Bindings[i]->Close();
199         }
200         while (TreeRoot->ChildCount())
201         {
202                 TreeServer* child_server = TreeRoot->GetChild(0);
203                 if (child_server)
204                 {
205                         TreeSocket* sock = child_server->GetSocket();
206                         ServerInstance->SE->DelFd(sock);
207                         sock->Close();
208                 }
209         }
210         delete TreeRoot;
211         ServerInstance->BufferedSocketCull();
212 }
213
214 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
215 {
216         if (list.find(server) == list.end())
217                 list[server] = server;
218 }
219
220 /* returns a list of DIRECT servernames for a specific channel */
221 void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list)
222 {
223         CUList *ulist;
224         switch (status)
225         {
226                 case '@':
227                         ulist = c->GetOppedUsers();
228                 break;
229                 case '%':
230                         ulist = c->GetHalfoppedUsers();
231                 break;
232                 case '+':
233                         ulist = c->GetVoicedUsers();
234                 break;
235                 default:
236                         ulist = c->GetUsers();
237                 break;
238         }
239         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
240         {
241                 if ((i->first->GetFd() < 0) && (exempt_list.find(i->first) == exempt_list.end()))
242                 {
243                         TreeServer* best = this->BestRouteTo(i->first->server);
244                         if (best)
245                                 AddThisServer(best,list);
246                 }
247         }
248         return;
249 }
250
251 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params)
252 {
253         char pfx = 0;
254         TreeServer* omitroute = this->BestRouteTo(omit);
255         if ((command == "NOTICE") || (command == "PRIVMSG"))
256         {
257                 if (params.size() >= 2)
258                 {
259                         /* Prefixes */
260                         if ((*(params[0].c_str()) == '@') || (*(params[0].c_str()) == '%') || (*(params[0].c_str()) == '+'))
261                         {
262                                 pfx = params[0][0];
263                                 params[0] = params[0].substr(1, params[0].length()-1);
264                         }
265                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
266                         {
267                                 // special routing for private messages/notices
268                                 User* d = ServerInstance->FindNick(params[0]);
269                                 if (d)
270                                 {
271                                         std::deque<std::string> par;
272                                         par.push_back(params[0]);
273                                         par.push_back(":"+params[1]);
274                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
275                                         return true;
276                                 }
277                         }
278                         else if (*(params[0].c_str()) == '$')
279                         {
280                                 std::deque<std::string> par;
281                                 par.push_back(params[0]);
282                                 par.push_back(":"+params[1]);
283                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
284                                 return true;
285                         }
286                         else
287                         {
288                                 Channel* c = ServerInstance->FindChan(params[0]);
289                                 User* u = ServerInstance->FindNick(prefix);
290                                 if (c && u)
291                                 {
292                                         CUList elist;
293                                         TreeServerList list;
294                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist, params[1]));
295                                         GetListOfServersForChannel(c,list,pfx,elist);
296
297                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
298                                         {
299                                                 TreeSocket* Sock = i->second->GetSocket();
300                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
301                                                 {
302                                                         Sock->WriteLine(data);
303                                                 }
304                                         }
305                                         return true;
306                                 }
307                         }
308                 }
309         }
310         unsigned int items =this->TreeRoot->ChildCount();
311         for (unsigned int x = 0; x < items; x++)
312         {
313                 TreeServer* Route = this->TreeRoot->GetChild(x);
314                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
315                 {
316                         TreeSocket* Sock = Route->GetSocket();
317                         if (Sock)
318                                 Sock->WriteLine(data);
319                 }
320         }
321         return true;
322 }
323
324 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit)
325 {
326         TreeServer* omitroute = this->BestRouteTo(omit);
327         std::string FullLine = ":" + prefix + " " + command;
328         unsigned int words = params.size();
329         for (unsigned int x = 0; x < words; x++)
330         {
331                 FullLine = FullLine + " " + params[x];
332         }
333         unsigned int items = this->TreeRoot->ChildCount();
334         for (unsigned int x = 0; x < items; x++)
335         {
336                 TreeServer* Route = this->TreeRoot->GetChild(x);
337                 // Send the line IF:
338                 // The route has a socket (its a direct connection)
339                 // The route isnt the one to be omitted
340                 // The route isnt the path to the one to be omitted
341                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
342                 {
343                         TreeSocket* Sock = Route->GetSocket();
344                         if (Sock)
345                                 Sock->WriteLine(FullLine);
346                 }
347         }
348         return true;
349 }
350
351 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params)
352 {
353         std::string FullLine = ":" + prefix + " " + command;
354         unsigned int words = params.size();
355         for (unsigned int x = 0; x < words; x++)
356         {
357                 FullLine = FullLine + " " + params[x];
358         }
359         unsigned int items = this->TreeRoot->ChildCount();
360         for (unsigned int x = 0; x < items; x++)
361         {
362                 TreeServer* Route = this->TreeRoot->GetChild(x);
363                 if (Route && Route->GetSocket())
364                 {
365                         TreeSocket* Sock = Route->GetSocket();
366                         if (Sock)
367                                 Sock->WriteLine(FullLine);
368                 }
369         }
370         return true;
371 }
372
373 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params)
374 {
375         std::string spfx = prefix;
376         std::string scmd = command;
377         return this->DoOneToMany(spfx, scmd, params);
378 }
379
380 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit)
381 {
382         std::string spfx = prefix;
383         std::string scmd = command;
384         return this->DoOneToAllButSender(spfx, scmd, params, omit);
385 }
386
387 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target)
388 {
389         TreeServer* Route = this->BestRouteTo(target);
390         if (Route)
391         {
392                 std::string FullLine = ":" + prefix + " " + command;
393                 unsigned int words = params.size();
394                 for (unsigned int x = 0; x < words; x++)
395                 {
396                         FullLine = FullLine + " " + params[x];
397                 }
398                 if (Route && Route->GetSocket())
399                 {
400                         TreeSocket* Sock = Route->GetSocket();
401                         if (Sock)
402                                 Sock->WriteLine(FullLine);
403                 }
404                 return true;
405         }
406         else
407         {
408                 return false;
409         }
410 }
411
412 void SpanningTreeUtilities::RefreshIPCache()
413 {
414         ValidIPs.clear();
415         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
416         {
417                 if ((!L->IPAddr.empty()) && (!L->RecvPass.empty()) && (!L->SendPass.empty()) && (!L->Name.empty()) && (L->Port))
418                 {
419                         ValidIPs.push_back(L->IPAddr);
420
421                         if (L->AllowMask.length())
422                                 ValidIPs.push_back(L->AllowMask);
423
424                         /* Needs resolving */
425                         bool ipvalid = true;
426                         QueryType start_type = DNS_QUERY_A;
427 #ifdef IPV6
428                         start_type = DNS_QUERY_AAAA;
429                         if (strchr(L->IPAddr.c_str(),':'))
430                         {
431                                 in6_addr n;
432                                 if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
433                                         ipvalid = false;
434                         }
435                         else
436 #endif
437                         {
438                                 in_addr n;
439                                 if (inet_aton(L->IPAddr.c_str(),&n) < 1)
440                                         ipvalid = false;
441                         }
442                         if (!ipvalid)
443                         {
444                                 try
445                                 {
446                                         bool cached;
447                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type);
448                                         ServerInstance->AddResolver(sr, cached);
449                                 }
450                                 catch (...)
451                                 {
452                                 }
453                         }
454                 }
455         }
456 }
457
458 void SpanningTreeUtilities::ReadConfiguration(bool rebind)
459 {
460         ConfigReader* Conf = new ConfigReader(ServerInstance);
461         if (rebind)
462         {
463                 for (unsigned int i = 0; i < Bindings.size(); i++)
464                 {
465                         ServerInstance->SE->DelFd(Bindings[i]);
466                         Bindings[i]->Close();
467                 }
468                 ServerInstance->BufferedSocketCull();
469                 Bindings.clear();
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                                                 throw CoreException("Can't find transport type '"+transport+"' for port "+IP+":"+Port+" - maybe you forgot to load it BEFORE m_spanningtree in your config file?");
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                         throw CoreException("Can't find transport type '"+L.Hook+"' for link '"+assign(L.Name)+"' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.");
546                         continue;
547
548                 }
549
550                 L.NextConnectTime = time(NULL) + L.AutoConnect;
551                 /* Bugfix by brain, do not allow people to enter bad configurations */
552                 if (L.Name != ServerInstance->Config->ServerName)
553                 {
554                         if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
555                         {
556                                 if (L.Name.find('.') == std::string::npos)
557                                         throw CoreException("The link name '"+assign(L.Name)+"' is invalid and must contain at least one '.' character");
558
559                                 if (L.Name.length() > 64)
560                                         throw CoreException("The link name '"+assign(L.Name)+"' is longer than 64 characters!");
561
562                                 ValidIPs.push_back(L.IPAddr);
563
564                                 if (Allow.length())
565                                         ValidIPs.push_back(Allow);
566
567                                 /* Needs resolving */
568                                 bool ipvalid = true;
569                                 QueryType start_type = DNS_QUERY_A;
570 #ifdef IPV6
571                                 start_type = DNS_QUERY_AAAA;
572                                 if (strchr(L.IPAddr.c_str(),':'))
573                                 {
574                                         in6_addr n;
575                                         if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
576                                                 ipvalid = false;
577                                 }
578                                 else
579                                 {
580                                         in_addr n;
581                                         if (inet_aton(L.IPAddr.c_str(),&n) < 1)
582                                                 ipvalid = false;
583                                 }
584 #else
585                                 in_addr n;
586                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
587                                         ipvalid = false;
588 #endif
589
590                                 if (!ipvalid)
591                                 {
592                                         try
593                                         {
594                                                 bool cached;
595                                                 SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
596                                                 ServerInstance->AddResolver(sr, cached);
597                                         }
598                                         catch (...)
599                                         {
600                                         }
601                                 }
602
603                                 LinkBlocks.push_back(L);
604                         }
605                         else
606                         {
607                                 if (L.IPAddr.empty())
608                                 {
609                                         throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', IP address not defined!");
610                                 }
611                                 else if (L.RecvPass.empty())
612                                 {
613                                         throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', recvpass not defined!");
614                                 }
615                                 else if (L.SendPass.empty())
616                                 {
617                                         throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', sendpass not defined!");
618                                 }
619                                 else if (L.Name.empty())
620                                 {
621                                         throw CoreException("Invalid configuration, link tag without a name! IP address: "+L.IPAddr);
622                                 }
623                                 else if (!L.Port)
624                                 {
625                                         throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', no port specified!");
626                                 }
627                         }
628                 }
629                 else
630                 {
631                         throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', link tag has the same server name as the local server!");
632                 }
633         }
634         delete Conf;
635 }
636
637 void SpanningTreeUtilities::DoFailOver(Link* x)
638 {
639         if (x->FailOver.length())
640         {
641                 if (x->FailOver == x->Name)
642                 {
643                         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());
644                         return;
645                 }
646                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
647                 if (TryThisOne)
648                 {
649                         TreeServer* CheckDupe = this->FindServer(x->FailOver.c_str());
650                         if (CheckDupe)
651                         {
652                                 ServerInstance->Log(DEBUG,"Skipping existing failover: %s", x->FailOver.c_str());
653                         }
654                         else
655                         {
656                                 Creator->RemoteMessage(NULL,"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
657                                 Creator->ConnectServer(TryThisOne);
658                         }
659                 }
660                 else
661                 {
662                         Creator->RemoteMessage(NULL,"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
663                 }
664         }
665 }
666
667 Link* SpanningTreeUtilities::FindLink(const std::string& name)
668 {
669         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
670         {
671                 if (ServerInstance->MatchText(x->Name.c_str(), name.c_str()))
672                 {
673                         return &(*x);
674                 }
675         }
676         return NULL;
677 }