Exemple #1
0
        private static void PingTimerCallback(object state)
        {
            try
            {
                List <Client> allClients = hubClients.Concat(RoomsController.GetRoomsList().SelectMany(x => x.roomClients)).Concat(RadioController.radioChannels.SelectMany(x => x.radioClients)).ToList();
                for (int i = 0; i < allClients.Count; i++)
                {
                    if (allClients.Count > i && allClients[i] != null)
                    {
                        if (allClients[i].playerConnection.Status == NetConnectionStatus.Disconnected)
                        {
                            ClientDisconnected(allClients[i]);
                        }
                    }
                }

                List <uint> emptyRooms = RoomsController.GetRoomsList().Where(x => x.roomClients.Count == 0 && !x.noHost).Select(y => y.roomId).ToList();
                if (emptyRooms.Count > 0 && !Settings.Instance.TournamentMode.Enabled)
                {
                    Logger.Instance.Log("Destroying empty rooms...");
                    foreach (uint roomId in emptyRooms)
                    {
                        RoomsController.DestroyRoom(roomId);
                        Logger.Instance.Log($"Destroyed room {roomId}!");
                    }
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Logger.Instance.Warning("PingTimerCallback Exception: " + e);
#endif
            }
        }