+void TreeServer::SQuitChild(TreeServer* server, const std::string& reason)
+{
+ stdalgo::erase(Children, server);
+
+ if (IsRoot())
+ {
+ // Server split from us, generate a SQUIT message and broadcast it
+ ServerInstance->SNO->WriteGlobalSno('l', "Server \002" + server->GetName() + "\002 split: " + reason);
+ CmdBuilder("SQUIT").push(server->GetID()).push_last(reason).Broadcast();
+ }
+ else
+ {
+ ServerInstance->SNO->WriteToSnoMask('L', "Server \002" + server->GetName() + "\002 split from server \002" + GetName() + "\002 with reason: " + reason);
+ }
+
+ unsigned int num_lost_servers = 0;
+ server->SQuitInternal(num_lost_servers);
+
+ const std::string quitreason = GetName() + " " + server->GetName();
+ unsigned int num_lost_users = QuitUsers(quitreason);
+
+ ServerInstance->SNO->WriteToSnoMask(IsRoot() ? 'l' : 'L', "Netsplit complete, lost \002%u\002 user%s on \002%u\002 server%s.",
+ num_lost_users, num_lost_users != 1 ? "s" : "", num_lost_servers, num_lost_servers != 1 ? "s" : "");
+
+ // No-op if the socket is already closed (i.e. it called us)
+ if (server->IsLocal())
+ server->GetSocket()->Close();
+
+ // Add the server to the cull list, the servers behind it are handled by cull() and the destructor
+ ServerInstance->GlobalCulls.AddItem(server);
+}
+
+void TreeServer::SQuitInternal(unsigned int& num_lost_servers)
+{
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Server %s lost in split", GetName().c_str());
+
+ for (ChildServers::const_iterator i = Children.begin(); i != Children.end(); ++i)
+ {
+ TreeServer* server = *i;
+ server->SQuitInternal(num_lost_servers);
+ }
+
+ // Mark server as dead
+ isdead = true;
+ num_lost_servers++;
+ RemoveHash();
+
+ if (!Utils->Creator->dying)
+ FOREACH_MOD_CUSTOM(Utils->Creator->GetEventProvider(), ServerEventListener, OnServerSplit, (this));
+}
+
+unsigned int TreeServer::QuitUsers(const std::string& reason)