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