+void ModuleSpanningTree::ConnectServer(Autoconnect* a, bool on_timer)
+{
+ if (!a)
+ return;
+ for(unsigned int j=0; j < a->servers.size(); j++)
+ {
+ if (Utils->FindServer(a->servers[j]))
+ {
+ // found something in this block. Should the server fail,
+ // we want to start at the start of the list, not in the
+ // middle where we left off
+ a->position = -1;
+ return;
+ }
+ }
+ if (on_timer && a->position >= 0)
+ return;
+ if (!on_timer && a->position < 0)
+ return;
+
+ a->position++;
+ while (a->position < (int)a->servers.size())
+ {
+ Link* x = Utils->FindLink(a->servers[a->position]);
+ if (x)
+ {
+ ServerInstance->SNO->WriteToSnoMask('l', "AUTOCONNECT: Auto-connecting server \002%s\002", x->Name.c_str());
+ ConnectServer(x, a);
+ return;
+ }
+ a->position++;
+ }
+ // Autoconnect chain has been fully iterated; start at the beginning on the
+ // next AutoConnectServers run
+ a->position = -1;
+}
+