Beispiel #1
0
        public void Save()
        {
            try
            {
                var settings = _settingsStoreSource.GetSettingsStore();
                settings.TimeZoneInfo         = Settings.TimeZoneInfo;
                settings.AdminName            = Settings.AdminName.Replace(" ", string.Empty);
                settings.BansUpdateSeconds    = Settings.BansUpdateSeconds;
                settings.PlayersUpdateSeconds = Settings.PlayersUpdateSeconds;
                settings.Save();

                using (var servierInfoRepository = new ServerInfoRepository())
                {
                    var all = servierInfoRepository.GetServerInfo();

                    var todelete = all.Where(x => Servers.All(s => s.GetDbModel().Id != x.Id));

                    foreach (var serverInfo in todelete)
                    {
                        servierInfoRepository.Remove(serverInfo.Id);
                    }

                    foreach (var s in Servers)
                    {
                        var m = s.GetDbModel();
                        if (m.Id == Guid.Empty)
                        {
                            m.Id = Guid.NewGuid();
                        }
                        servierInfoRepository.AddOrUpdate(m);
                    }
                }

                using (var dc = new ReasonRepository())
                {
                    dc.UpdateBanReasons(BanReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                    dc.UpdateBanTimes(BanTimes.Where(x => string.IsNullOrEmpty(x.Text) == false).Select(x => new BanTime()
                    {
                        TimeInMinutes = x.Minutes, Title = x.Text
                    }).ToArray());
                    dc.UpdateKickReasons(KickReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                }

                _eventAggregator.GetEvent <BEServersChangedEvent>().Publish(null);
                _eventAggregator.GetEvent <SettingsChangedEvent>().Publish(_settingsStoreSource.GetSettingsStore());
            }
            catch (Exception e)
            {
                _log.Error(e);
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #2
0
        public BEServiceLogic(IEventAggregator aggregator, IBEService beService, ISettingsStoreSource settingsStoreSource, IBELogic beLogic)
        {
            _aggregator          = aggregator;
            _beService           = beService;
            _settingsStoreSource = settingsStoreSource;
            _beLogic             = beLogic;

            _playersUpdater = new TimedAction(_settingsStoreSource.GetSettingsStore().PlayersUpdateSeconds, UpdatePlayers);
            _bansUpdater    = new TimedAction(_settingsStoreSource.GetSettingsStore().BansUpdateSeconds, UpdateBans);

            _aggregator.GetEvent <SettingsChangedEvent>()
            .Subscribe(SettingsChanged);


            _beLogic.ServerUpdateHandler += _beLogic_ServerUpdateHandler;
        }
Beispiel #3
0
        public void Kick(Guid serverId, int playerNum, string playerGuid, string reason, bool isAuto = false)
        {
            var totalreason =
                $"[{_settingsStoreSource.GetSettingsStore().AdminName}][{DateTime.UtcNow.ToString("dd.MM.yy HH:mm:ss")}] {reason}";

            SendCommand(serverId, CommandType.Kick,
                        $"{playerNum} {totalreason}");

            if (!isAuto)
            {
                var user = _playerRepository.GetPlayer(playerGuid);
                if (user != null)
                {
                    _playerRepository.AddNotes(user.Id, $"Kicked with reason: {totalreason}");
                    user.Comment = $"{user.Comment} | {reason}";
                    _playerRepository.UpdatePlayerComment(user.GUID, user.Comment);
                }
            }
        }
Beispiel #4
0
        public async Task KickAsync(Guid serverId, int playerNum, string playerGuid, string reason, bool isAuto = false)
        {
            var totalreason = _messageHelper.GetKickMessage(_settingsStoreSource.GetSettingsStore(), reason);

            SendCommand(serverId, CommandType.Kick,
                        $"{playerNum} {totalreason}");

            if (!isAuto)
            {
                var user = await _playerRepository.GetPlayerAsync(playerGuid);

                if (user != null)
                {
                    await _playerRepository.AddNotesAsync(user.Id, $"Kicked with reason: {totalreason}");

                    user.Comment = $"{user.Comment} | {reason}";
                    await _playerRepository.UpdatePlayerCommentAsync(user.GUID, user.Comment);
                }
            }
        }
Beispiel #5
0
        public SteamServiceViewModel(ISettingsStoreSource settingsStoreSource)
        {
            _settingsStoreSource = settingsStoreSource;
            SelectFolderCommand  = new DelegateCommand(SelectFolder, () => !InProgress);
            GenerateDataCommand  = new DelegateCommand(GenerateData, () => !string.IsNullOrEmpty(Folder) && !InProgress);

            CancelCommand = new DelegateCommand(Cancel, () => InProgress);

            var settings = _settingsStoreSource.GetSettingsStore();

            Folder = settings.SteamFolder;
        }
Beispiel #6
0
        public SteamService(ISettingsStoreSource settingsStoreSource)
        {
            var folder = settingsStoreSource.GetSettingsStore().SteamFolder;

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }

            var idsFIleName   = Path.Combine(folder, "ids.bin");
            var indexFIleName = Path.Combine(folder, "index.bin");

            _isReady = File.Exists(idsFIleName) && File.Exists(indexFIleName);

            if (_isReady)
            {
                var md5 = new StandardHashProvider();
                _idByHashSearcher = new IdByHashSearcher(idsFIleName, indexFIleName, md5, _log);
            }
        }
        public void SendMessage(string rawmessage)
        {
            if (!string.IsNullOrEmpty(rawmessage))
            {
                var adminName = _settingsStoreSource.GetSettingsStore().AdminName;

                var selectedPlayer = SelectedPlayer;
                var destinationNum = -1;
                if (selectedPlayer != null)
                {
                    destinationNum = selectedPlayer.Num;
                }

                var message = $" {destinationNum} {adminName}: {rawmessage}";

                _eventAggregator.GetEvent <BEMessageEvent <BECommand> >()
                .Publish(new BECommand(_serverId, CommandType.Say, message));
            }

            InputMessage = string.Empty;
        }
Beispiel #8
0
        public MainViewModel(IEventAggregator eventAggregator, IServerInfoRepository infoRepository, ISettingsStoreSource settingsStoreSource)
        {
            _infoRepository = infoRepository;
            ReloadAsync();

            OptionsCommand = new DelegateCommand(() =>
            {
                eventAggregator.GetEvent <ShowOptionsEvent>().Publish(new ShowOptionsEvent());
            });

            eventAggregator.GetEvent <BEServersChangedEvent>().Subscribe(async(state) =>
            {
                await ReloadAsync();
            });

            var tm = settingsStoreSource.GetSettingsStore().TopMost;

            foreach (Window wnd in Application.Current.Windows)
            {
                wnd.Topmost = tm;
            }
        }
Beispiel #9
0
 private void SettingsChanged(ISettingsStore settings)
 {
     _playersUpdater.SetTimer(_settingsStoreSource.GetSettingsStore().PlayersUpdateSeconds);
     _bansUpdater.SetTimer(_settingsStoreSource.GetSettingsStore().BansUpdateSeconds);
 }
Beispiel #10
0
        public async Task Save()
        {
            try
            {
                var customStore = _settingsStoreSource.GetCustomSettingsStore();

                foreach (var serverSetting in ServerSettings)
                {
                    customStore.Save(serverSetting.ServerId.ToString(), new ServerSettings()
                    {
                        ServerId        = serverSetting.ServerId,
                        IdleTimeInMins  = serverSetting.IdleTimeInMins,
                        IdleKickReason  = serverSetting.IdleKickReason,
                        KickIdlePlayers = serverSetting.KickIdlePlayers
                    });
                }

                var settings = _settingsStoreSource.GetSettingsStore();
                settings.TimeZoneInfo = Settings.TimeZoneInfo;

                settings.AdminName = Settings.AdminName.Replace(" ", string.Empty);

                settings.BanMessageTemplate  = Settings.BanMessageTemplate;
                settings.KickMessageTemplate = Settings.KickMessageTemplate;


                settings.BansUpdateSeconds    = Settings.BansUpdateSeconds;
                settings.PlayersUpdateSeconds = Settings.PlayersUpdateSeconds;

                settings.TopMost = Settings.TopMost;

                settings.Save();


                var all = await _infoRepository.GetServerInfoAsync();

                var todelete = all.Where(x => Servers.All(s => s.GetDbModel().Id != x.Id));

                foreach (var serverInfo in todelete)
                {
                    await _infoRepository.RemoveAsync(serverInfo.Id);
                }

                foreach (var s in Servers)
                {
                    var m = s.GetDbModel();
                    if (m.Id == Guid.Empty)
                    {
                        m.Id = Guid.NewGuid();
                    }
                    await _infoRepository.AddOrUpdateAsync(m);
                }


                using (var dc = new ReasonRepository())
                {
                    await dc.UpdateBanReasons(BanReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());

                    await dc.UpdateBanTimes(BanTimes.Where(x => string.IsNullOrEmpty(x.Text) == false).Select(x => new BanTime {
                        TimeInMinutes = x.Minutes, Title = x.Text
                    }).ToArray());

                    await dc.UpdateKickReasons(KickReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());


                    await dc.UpdateBadNicknames(BadNicknames.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());

                    await dc.UpdateImportantWords(ImportantWords.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                }

                _eventAggregator.GetEvent <BEServersChangedEvent>().Publish(null);
                _eventAggregator.GetEvent <SettingsChangedEvent>().Publish(_settingsStoreSource.GetSettingsStore());


                foreach (Window wnd in Application.Current.Windows)
                {
                    wnd.Topmost = settings.TopMost;
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #11
0
 public WindowBase(ISettingsStoreSource settingsStoreSource)
 {
     this.Topmost = settingsStoreSource.GetSettingsStore().TopMost;
 }