]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
Fix to use DuplicateID. This stops things segfaulting on duplicate SID introduction...
[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         std::string OurSID;
172
173         OurSID += (char)((Instance->Config->sid / 100) + 48);
174         OurSID += (char)((Instance->Config->sid / 10) % 10 + 48);
175         OurSID += (char)(Instance->Config->sid % 10 + 48);
176
177         lines_to_apply = 0;
178
179         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, OurSID);
180
181         modulelist* ml = ServerInstance->FindInterface("InspSocketHook");
182
183         /* Did we find any modules? */
184         if (ml)
185         {
186                 /* Yes, enumerate them all to find out the hook name */
187                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
188                 {
189                         /* Make a request to it for its name, its implementing
190                          * InspSocketHook so we know its safe to do this
191                          */
192                         std::string name = InspSocketNameRequest((Module*)Creator, *m).Send();
193                         /* Build a map of them */
194                         hooks[name.c_str()] = *m;
195                         hooknames.push_back(name);
196                 }
197         }
198
199         this->ReadConfiguration(true);
200 }
201
202 SpanningTreeUtilities::~SpanningTreeUtilities()
203 {
204         for (unsigned int i = 0; i < Bindings.size(); i++)
205         {
206                 ServerInstance->SE->DelFd(Bindings[i]);
207                 Bindings[i]->Close();
208         }
209         while (TreeRoot->ChildCount())
210         {
211                 TreeServer* child_server = TreeRoot->GetChild(0);
212                 if (child_server)
213                 {
214                         TreeSocket* sock = child_server->GetSocket();
215                         ServerInstance->SE->DelFd(sock);
216                         sock->Close();
217                 }
218         }
219         delete TreeRoot;
220         ServerInstance->InspSocketCull();
221 }
222
223 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
224 {
225         if (list.find(server) == list.end())
226                 list[server] = server;
227 }
228
229 /* returns a list of DIRECT servernames for a specific channel */
230 void SpanningTreeUtilities::GetListOfServersForChannel(chanrec* c, TreeServerList &list, char status, const CUList &exempt_list)
231 {
232         CUList *ulist;
233         switch (status)
234         {
235                 case '@':
236                         ulist = c->GetOppedUsers();
237                 break;
238                 case '%':
239                         ulist = c->GetHalfoppedUsers();
240                 break;
241                 case '+':
242                         ulist = c->GetVoicedUsers();
243                 break;
244                 default:
245                         ulist = c->GetUsers();
246                 break;
247         }
248         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
249         {
250                 if ((i->first->GetFd() < 0) && (exempt_list.find(i->first) == exempt_list.end()))
251                 {
252                         TreeServer* best = this->BestRouteTo(i->first->server);
253                         if (best)
254                                 AddThisServer(best,list);
255                 }
256         }
257         return;
258 }
259
260 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params)
261 {
262         char pfx = 0;
263         TreeServer* omitroute = this->BestRouteTo(omit);
264         if ((command == "NOTICE") || (command == "PRIVMSG"))
265         {
266                 if (params.size() >= 2)
267                 {
268                         /* Prefixes */
269                         if ((*(params[0].c_str()) == '@') || (*(params[0].c_str()) == '%') || (*(params[0].c_str()) == '+'))
270                         {
271                                 pfx = params[0][0];
272                                 params[0] = params[0].substr(1, params[0].length()-1);
273                         }
274                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
275                         {
276                                 // special routing for private messages/notices
277                                 userrec* d = ServerInstance->FindNick(params[0]);
278                                 if (d)
279                                 {
280                                         std::deque<std::string> par;
281                                         par.push_back(params[0]);
282                                         par.push_back(":"+params[1]);
283                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
284                                         return true;
285                                 }
286                         }
287                         else if (*(params[0].c_str()) == '$')
288                         {
289                                 std::deque<std::string> par;
290                                 par.push_back(params[0]);
291                                 par.push_back(":"+params[1]);
292                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
293                                 return true;
294                         }
295                         else
296                         {
297                                 chanrec* c = ServerInstance->FindChan(params[0]);
298                                 userrec* u = ServerInstance->FindNick(prefix);
299                                 if (c && u)
300                                 {
301                                         CUList elist;
302                                         TreeServerList list;
303                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist));
304                                         GetListOfServersForChannel(c,list,pfx,elist);
305
306                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
307                                         {
308                                                 TreeSocket* Sock = i->second->GetSocket();
309                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
310                                                 {
311                                                         Sock->WriteLine(data);
312                                                 }
313                                         }
314                                         return true;
315                                 }
316                         }
317                 }
318         }
319         unsigned int items =this->TreeRoot->ChildCount();
320         for (unsigned int x = 0; x < items; x++)
321         {
322                 TreeServer* Route = this->TreeRoot->GetChild(x);
323                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
324                 {
325                         TreeSocket* Sock = Route->GetSocket();
326                         if (Sock)
327                                 Sock->WriteLine(data);
328                 }
329         }
330         return true;
331 }
332
333 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit)
334 {
335         TreeServer* omitroute = this->BestRouteTo(omit);
336         std::string FullLine = ":" + prefix + " " + command;
337         unsigned int words = params.size();
338         for (unsigned int x = 0; x < words; x++)
339         {
340                 FullLine = FullLine + " " + params[x];
341         }
342         unsigned int items = this->TreeRoot->ChildCount();
343         for (unsigned int x = 0; x < items; x++)
344         {
345                 TreeServer* Route = this->TreeRoot->GetChild(x);
346                 // Send the line IF:
347                 // The route has a socket (its a direct connection)
348                 // The route isnt the one to be omitted
349                 // The route isnt the path to the one to be omitted
350                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
351                 {
352                         TreeSocket* Sock = Route->GetSocket();
353                         if (Sock)
354                                 Sock->WriteLine(FullLine);
355                 }
356         }
357         return true;
358 }
359
360 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params)
361 {
362         std::string FullLine = ":" + prefix + " " + command;
363         unsigned int words = params.size();
364         for (unsigned int x = 0; x < words; x++)
365         {
366                 FullLine = FullLine + " " + params[x];
367         }
368         unsigned int items = this->TreeRoot->ChildCount();
369         for (unsigned int x = 0; x < items; x++)
370         {
371                 TreeServer* Route = this->TreeRoot->GetChild(x);
372                 if (Route && Route->GetSocket())
373                 {
374                         TreeSocket* Sock = Route->GetSocket();
375                         if (Sock)
376                                 Sock->WriteLine(FullLine);
377                 }
378         }
379         return true;
380 }
381
382 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params)
383 {
384         std::string spfx = prefix;
385         std::string scmd = command;
386         return this->DoOneToMany(spfx, scmd, params);
387 }
388
389 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit)
390 {
391         std::string spfx = prefix;
392         std::string scmd = command;
393         return this->DoOneToAllButSender(spfx, scmd, params, omit);
394 }
395
396 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target)
397 {
398         TreeServer* Route = this->BestRouteTo(target);
399         if (Route)
400         {
401                 std::string FullLine = ":" + prefix + " " + command;
402                 unsigned int words = params.size();
403                 for (unsigned int x = 0; x < words; x++)
404                 {
405                         FullLine = FullLine + " " + params[x];
406                 }
407                 if (Route && Route->GetSocket())
408                 {
409                         TreeSocket* Sock = Route->GetSocket();
410                         if (Sock)
411                                 Sock->WriteLine(FullLine);
412                 }
413                 return true;
414         }
415         else
416         {
417                 return false;
418         }
419 }
420
421 void SpanningTreeUtilities::RefreshIPCache()
422 {
423         ValidIPs.clear();
424         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
425         {
426                 if ((!L->IPAddr.empty()) && (!L->RecvPass.empty()) && (!L->SendPass.empty()) && (!L->Name.empty()) && (L->Port))
427                 {
428                         ValidIPs.push_back(L->IPAddr);
429
430                         if (L->AllowMask.length())
431                                 ValidIPs.push_back(L->AllowMask);
432
433                         /* Needs resolving */
434                         bool ipvalid = true;
435                         QueryType start_type = DNS_QUERY_A;
436 #ifdef IPV6
437                         start_type = DNS_QUERY_AAAA;
438                         if (strchr(L->IPAddr.c_str(),':'))
439                         {
440                                 in6_addr n;
441                                 if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
442                                         ipvalid = false;
443                         }
444                         else
445 #endif
446                         {
447                                 in_addr n;
448                                 if (inet_aton(L->IPAddr.c_str(),&n) < 1)
449                                         ipvalid = false;
450                         }
451                         if (!ipvalid)
452                         {
453                                 try
454                                 {
455                                         bool cached;
456                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type);
457                                         ServerInstance->AddResolver(sr, cached);
458                                 }
459                                 catch (...)
460                                 {
461                                 }
462                         }
463                 }
464         }
465 }
466
467 void SpanningTreeUtilities::ReadConfiguration(bool rebind)
468 {
469         ConfigReader* Conf = new ConfigReader(ServerInstance);
470         if (rebind)
471         {
472                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
473                 {
474                         std::string Type = Conf->ReadValue("bind","type",j);
475                         std::string IP = Conf->ReadValue("bind","address",j);
476                         std::string Port = Conf->ReadValue("bind","port",j);
477                         std::string transport = Conf->ReadValue("bind","transport",j);
478                         if (Type == "servers")
479                         {
480                                 irc::portparser portrange(Port, false);
481                                 int portno = -1;
482                                 while ((portno = portrange.GetToken()))
483                                 {
484                                         if (IP == "*")
485                                                 IP.clear();
486
487                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
488                                         {
489                                                 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());
490                                                 break;
491                                         }
492
493                                         TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
494                                         if (listener->GetState() == I_LISTENING)
495                                         {
496                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
497                                                 Bindings.push_back(listener);
498                                         }
499                                         else
500                                         {
501                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port: %s:%d: %s",IP.c_str(), portno, strerror(errno));
502                                                 listener->Close();
503                                         }
504                                 }
505                         }
506                 }
507         }
508         FlatLinks = Conf->ReadFlag("options","flatlinks",0);
509         HideULines = Conf->ReadFlag("options","hideulines",0);
510         AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
511         EnableTimeSync = Conf->ReadFlag("timesync","enable",0);
512         MasterTime = Conf->ReadFlag("timesync", "master", 0);
513         ChallengeResponse = !Conf->ReadFlag("options", "disablehmac", 0);
514         quiet_bursts = Conf->ReadFlag("options", "quietbursts", 0);
515         PingWarnTime = Conf->ReadInteger("options", "pingwarning", 0, true);
516         PingFreq = Conf->ReadInteger("options", "serverpingfreq", 0, true);
517
518         if (PingFreq == 0)
519                 PingFreq = 60;
520
521         if (PingWarnTime < 0 || PingWarnTime > PingFreq - 1)
522                 PingWarnTime = 0;
523
524         LinkBlocks.clear();
525         ValidIPs.clear();
526         for (int j = 0; j < Conf->Enumerate("link"); j++)
527         {
528                 Link L;
529                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
530                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
531                 L.AllowMask = Allow;
532                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
533                 L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
534                 L.Port = Conf->ReadInteger("link", "port", j, true);
535                 L.SendPass = Conf->ReadValue("link", "sendpass", j);
536                 L.RecvPass = Conf->ReadValue("link", "recvpass", j);
537                 L.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
538                 L.HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
539                 L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
540                 L.Hook = Conf->ReadValue("link", "transport", j);
541                 L.Bind = Conf->ReadValue("link", "bind", j);
542                 L.Hidden = Conf->ReadFlag("link", "hidden", j);
543
544                 if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) ==  hooks.end()))
545                 {
546                         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.",
547                         L.Hook.c_str(), L.Name.c_str());
548                         continue;
549
550                 }
551
552                 L.NextConnectTime = time(NULL) + L.AutoConnect;
553                 /* Bugfix by brain, do not allow people to enter bad configurations */
554                 if (L.Name != ServerInstance->Config->ServerName)
555                 {
556                         if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
557                         {
558                                 ValidIPs.push_back(L.IPAddr);
559
560                                 if (Allow.length())
561                                         ValidIPs.push_back(Allow);
562
563                                 /* Needs resolving */
564                                 bool ipvalid = true;
565                                 QueryType start_type = DNS_QUERY_A;
566 #ifdef IPV6
567                                 start_type = DNS_QUERY_AAAA;
568                                 if (strchr(L.IPAddr.c_str(),':'))
569                                 {
570                                         in6_addr n;
571                                         if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
572                                                 ipvalid = false;
573                                 }
574                                 else
575                                 {
576                                         in_addr n;
577                                         if (inet_aton(L.IPAddr.c_str(),&n) < 1)
578                                                 ipvalid = false;
579                                 }
580 #else
581                                 in_addr n;
582                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
583                                         ipvalid = false;
584 #endif
585
586                                 if (!ipvalid)
587                                 {
588                                         try
589                                         {
590                                                 bool cached;
591                                                 SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
592                                                 ServerInstance->AddResolver(sr, cached);
593                                         }
594                                         catch (...)
595                                         {
596                                         }
597                                 }
598
599                                 LinkBlocks.push_back(L);
600                         }
601                         else
602                         {
603                                 if (L.IPAddr.empty())
604                                 {
605                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', IP address not defined!",L.Name.c_str());
606                                 }
607                                 else if (L.RecvPass.empty())
608                                 {
609                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', recvpass not defined!",L.Name.c_str());
610                                 }
611                                 else if (L.SendPass.empty())
612                                 {
613                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', sendpass not defined!",L.Name.c_str());
614                                 }
615                                 else if (L.Name.empty())
616                                 {
617                                         ServerInstance->Log(DEFAULT,"Invalid configuration, link tag without a name!");
618                                 }
619                                 else if (!L.Port)
620                                 {
621                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', no port specified!",L.Name.c_str());
622                                 }
623                         }
624                 }
625                 else
626                 {
627                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', link tag has the same server name as the local server!",L.Name.c_str());
628                 }
629         }
630         DELETE(Conf);
631 }
632
633 void SpanningTreeUtilities::DoFailOver(Link* x)
634 {
635         if (x->FailOver.length())
636         {
637                 if (x->FailOver == x->Name)
638                 {
639                         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());
640                         return;
641                 }
642                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
643                 if (TryThisOne)
644                 {
645                         Creator->RemoteMessage(NULL,"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
646                         Creator->ConnectServer(TryThisOne);
647                 }
648                 else
649                 {
650                         Creator->RemoteMessage(NULL,"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
651                 }
652         }
653 }
654
655 Link* SpanningTreeUtilities::FindLink(const std::string& name)
656 {
657         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
658         {
659                 if (ServerInstance->MatchText(x->Name.c_str(), name.c_str()))
660                 {
661                         return &(*x);
662                 }
663         }
664         return NULL;
665 }
666