private void TimebanTimer_Elapsed(object sender, ElapsedEventArgs e) { try { bool hasPlayerBeenUnbanned = false; foreach (var bannedPlayer in _banDal.GetCurrentlyBannedPlayers(true)) { if (bannedPlayer.BannedUntil == null) { _logger.Error("Error: Expected banned until duration but is null: " + bannedPlayer.PlayerName); continue; } if (bannedPlayer.BannedUntil.Value < DateTime.Now) { _logger.Info("Unbanning player: " + bannedPlayer.PlayerName); _adminBanSl.UnbanPlayer(bannedPlayer.PlayerName, "Timer Unban", ConfigHandler.GhostDatabaseList); hasPlayerBeenUnbanned = true; } } if (hasPlayerBeenUnbanned) { RefreshBanList(); } } catch (Exception ex) { _logger.Error(ex, "[FRS] Timeban Handler Error"); } }
public BanListViewModel GetBannedPlayers() { var playerBanDataList = _banDal.GetCurrentlyBannedPlayers(false).ToList(); BanListViewModel banListViewModel = new BanListViewModel { PermanentBans = playerBanDataList.Where(x => x.IsPermanentBan), TimeBans = playerBanDataList.Where(x => !x.IsPermanentBan).ToList() }; banListViewModel.TimeBans.ToList().ForEach(x => { if (x.BannedUntil != null) { x.RemainingDuration = (int)x.BannedUntil.Value.Subtract(DateTime.Now).TotalMinutes; } }); return(banListViewModel); }