public void Shutdown(DisconnectType type)
{
Logger.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info, Client);
// Send a CloseCircuit packet to simulators if we are initiating the disconnect
bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout);
lock (Simulators)
{
// Disconnect all simulators except the current one
for (int i = 0; i < Simulators.Count; i++)
{
if (Simulators[i] != null && Simulators[i] != CurrentSim)
{
Simulators[i].Disconnect(sendCloseCircuit);
// Fire the SimDisconnected event if a handler is registered
if (OnSimDisconnected != null)
{
try { OnSimDisconnected(Simulators[i], type); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
}
Simulators.Clear();
}
if (CurrentSim != null)
{
// Kill the connection to the curent simulator
CurrentSim.Disconnect(sendCloseCircuit);
// Fire the SimDisconnected event if a handler is registered
if (OnSimDisconnected != null)
{
try { OnSimDisconnected(CurrentSim, type); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}
// Clear out all of the packets that never had time to process
PacketInbox.Close();
PacketOutbox.Close();
connected = false;
// Fire the disconnected callback
if (OnDisconnected != null)
{
try { OnDisconnected(DisconnectType.ClientInitiated, String.Empty); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
}