public static bool SendMessage(this List <Client> Clients, string Message, params object[] args) { if (args == null) { args = new object[0]; } if (args.Length > 0) { try { Message = String.Format(Message, args); } catch (Exception e) { Message = e.StackTrace + "\n" + Message; } } _ClientsListLock.EnterReadLock(); try { foreach (Client ThisClient in Clients) { ThisClient.SendMessage(Message); } } finally { _ClientsListLock.ExitReadLock(); } return(true); }
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)"); } } }