public static bool Stop() { foreach (Client ThisClient in Clients.YSFClients) { ThisClient.Disconnect("Server shutting down."); } DateTime Delay = DateTime.Now; while (Clients.YSFClients.Count > 0 & (DateTime.Now - Delay).TotalSeconds < 5) { Thread.Sleep(10); } foreach (Client ThisClient in Clients.YSFClients) { Debug.WriteLine("Stray Client" + ThisClient.Username); } Vehicles.List.Clear(); ListenerSocket.Close(); ListenerSocket.Dispose(); //ServerClosed.WaitOne(); ServerListenerThread.Abort(); return(false); }
public static void DoHeartbeatMonitor() { Client[] Temp = Clients.YSFClients.ToArray(); foreach (Client ThisClient in Temp) { if (ThisClient.IsFakeClient()) { continue; } if ((DateTime.Now - ThisClient.LastHeartBeat).TotalSeconds >= 60 & (DateTime.Now - ThisClient.LastHeartBeatWarning).TotalSeconds >= 60) { ThisClient.LastHeartBeatWarning = DateTime.Now + new TimeSpan(0, 0, 1); Log.Warning("DoHeartBeat Monitor Warning for " + ThisClient.Username); ThisClient.SendMessage("No Activity for 60 Seconds. Please do something or you will be disconnected soon!"); continue; } if ((DateTime.Now - ThisClient.LastHeartBeat).TotalSeconds >= 120 & (DateTime.Now - ThisClient.LastHeartBeatWarning).TotalSeconds <= 120) { ThisClient.SendMessage("You have been disconnected due to inactivity!"); ThisClient.Disconnect("Disconnected due to inactivity (DoHeartbeatMonitor)"); } } }