public async Task <IEnumerable <PlayerView> > GetPlayerViewAsync(IEnumerable <Player> list) { using (_log.Time("GetPlayerViewAsync")) { var players = list.ToList(); var guids = players.Select(x => x.Guid).ToList(); var playersInDb = await _playerRepository.GetPlayersAsync(guids); var result = players.Select(x => new PlayerView { Guid = x.Guid, IP = x.IP, Name = x.Name, Num = x.Num, Ping = x.Ping, State = x.State, Port = x.Port }).ToList(); result.ForEach(x => { var p = playersInDb.FirstOrDefault(y => y.GUID == x.Guid); if (p != null) { x.Id = p.Id; x.Comment = p.Comment; x.SteamId = p.SteamId; } }); var filterUsers = result.FirstOrDefault(x => !_nameRegex.IsMatch(x.Name)); if (filterUsers != null) { #pragma warning disable 4014 _banHelper.KickAsync(_serverId, filterUsers.Num, filterUsers.Guid, "bot: Fill Nickname"); #pragma warning restore 4014 } if (_badNicknames?.Any() == true) { var names = _badNicknames.Select(x => x.ToLower()).Distinct().ToDictionary(x => x); var bad = result.FirstOrDefault(x => !string.IsNullOrEmpty(x.Name) && names.ContainsKey(x.Name.ToLower())); if (bad != null) #pragma warning disable 4014 { _banHelper.KickAsync(_serverId, bad.Num, bad.Guid, "bot: Bad Nickname"); } #pragma warning restore 4014 } return(result); } }
private void KickClick(object sender, RoutedEventArgs e) { _playerHelper.KickAsync(_serverId, _playerNum, _playerGuid, tbReason.Text); Close(); }