Exemplo n.º 1
0
        public RegisterResult RegisterServer(ServerInfoDto serverInfo)
        {
            var request = new RestRequest("serverlist/register", Method.POST);

            request.AddParameter("application/json", JsonConvert.SerializeObject(serverInfo), ParameterType.RequestBody);
            return(Execute <RegisterResultDto>(request).Result);
        }
Exemplo n.º 2
0
        public void GetServerInfo_Should_Return_Server_Info()
        {
            var resultObj = new ServerInfoDto {
                Id = Guid.NewGuid().ToString()
            };
            var client = CreateClient(resultObj);

            client.SetDeviceInfo("embystat", "mediabrowser", "0.0.0.0", "cb290477-d048-4b01-b201-8181922c6399", "fa89fb6c-f3b7-4cc5-bc17-9522e3b94246");
            client.BaseUrl = "localhost:9000";
            client.ApiKey  = "apikey";

            var result = client.GetServerInfo();

            result.Should().NotBeNull();
            result.Id.Should().Be(resultObj.Id);

            _usedRequest.Should().NotBeNull();

            _usedRequest?.Parameters.Count.Should().Be(2);
            // ReSharper disable once PossibleNullReferenceException
            var parameters = _usedRequest.Parameters.OrderBy(x => x.Name).ToArray();

            parameters[0].Name.Should().Be("X-Emby-Authorization");
            parameters[0].Type.Should().Be(ParameterType.HttpHeader);
            parameters[0].Value.Should().Be("mediabrowser RestClient=\"other\", DeviceId=\"cb290477-d048-4b01-b201-8181922c6399\", Device=\"embystat\", Version=\"0.0.0.0\"");
            parameters[1].Name.Should().Be("X-Emby-Token");
            parameters[1].Type.Should().Be(ParameterType.HttpHeader);
            parameters[1].Value.Should().Be("apikey");

            _usedRequest?.Method.Should().Be(Method.GET);
            _usedRequest?.Resource.Should().Be("System/Info");
        }
Exemplo n.º 3
0
        private void AddServiceGatewayForServer(ServiceGateway service, AuthTokenDto authToken)
        {
            try
            {
                _serverInfo = service.Server.GetServerInfo(authToken.ServerDto, authToken.Token);
            }
            catch (Exception exc)
            {
                // default the configuration to vsphere
                _serverInfo = new ServerInfoDto
                {
                    Release     = "Vsphere",
                    ProductName = "idm"
                };
            }

            if (authToken.ServerDto.ServerName == "10.161.26.243")
            {
                _serverInfo.Release = "Lightwave";
            }
            var serviceConfigManager = new ServiceConfigManager(_serverInfo.Release);
            var serviceGateway       = new ServiceGateway(serviceConfigManager);

            SnapInContext.Instance.ServiceGatewayManager.Add(authToken.ServerDto.ServerName, serviceGateway);
        }
Exemplo n.º 4
0
        public ServerMonitorSteamQueryViewModel(ServerInfoDto serverInfo, IIpService ipService)
        {
            _ipService = ipService;
            Host       = serverInfo.Host;
            Port       = serverInfo.SteamPort;

            RaisePropertyChanged(nameof(Host));
            RaisePropertyChanged(nameof(Port));

            ExcecuteCommand = new ActionCommand(() => Task.Run(() =>
            {
                try
                {
                    IsBisy = true;
                    GetStat();
                }
                finally
                {
                    IsBisy = false;
                }
            }),
                                                () =>
            {
                var iphost = Host;

                if (string.IsNullOrEmpty(iphost))
                {
                    return(false);
                }
                return(true);
            });
        }
Exemplo n.º 5
0
        public ServerInfoModel()
        {
            var model = new ServerInfoDto();

            model.Id = Guid.Empty;
            _info    = model;
        }
Exemplo n.º 6
0
            public ServerItem(ServerInfoDto info, IBEServer beServer, IEventAggregator eventAggregator)
            {
                _eventAggregator = eventAggregator;
                Info             = info;
                BEServer         = beServer;

                BEServer.PlayerHandler  += BEServer_PlayerHandler;
                BEServer.AdminHandler   += BEServer_AdminHandler;
                BEServer.BanHandler     += BEServer_BanHandler;
                BEServer.MissionHandler += BEServer_MissionHandler;

                BEServer.BanLog       += BEServer_BanLog;
                BEServer.RConAdminLog += BEServer_RConAdminLog;
                BEServer.PlayerLog    += BEServer_PlayerLog;

                BEServer.ChatMessageHandler += BEServer_ChatMessageHandler;

                BEServer.ConnectHandler    += BEServer_ConnectHandler;
                BEServer.ConnectingHandler += BEServer_ConnectingHandler;
                BEServer.DisconnectHandler += BEServer_DisconnectHandler;

                BEServer.MessageHandler += BEServer_MessageHandler;

                _eventAggregator.GetEvent <BEMessageEvent <BECommand> >().Subscribe(Command);
                _eventAggregator.GetEvent <BEMessageEvent <BECustomCommand> >().Subscribe(CustomCommand);
            }
Exemplo n.º 7
0
 public async Task <RegisterResult> Register(ServerInfoDto serverInfo)
 {
     UpdateLastActivity();
     return(AuthServer.Instance.ServerManager.Add(serverInfo)
             ? RegisterResult.OK
             : RegisterResult.AlreadyExists);
 }
Exemplo n.º 8
0
        public ServerMonitorPlayerViewModel(ServerInfoDto serverInfo,
                                            IBanHelper banHelper, IEventAggregator eventAggregator, IPlayerRepository playerRepository, ReasonRepository reasonRepository)
            : base(
                new ActionCommand(() => SendCommand(eventAggregator, serverInfo.Id, CommandType.Players)),
                new PlayerViewComparer())
        {
            _serverInfo      = serverInfo;
            _eventAggregator = eventAggregator;
            _playerHelper    = new PlayerHelper(serverInfo.Id, banHelper, playerRepository, reasonRepository);

            KickUserCommand   = new DelegateCommand(ShowKickDialog, CanShowDialog);
            BanUserCommand    = new DelegateCommand(ShowBanDialog, CanShowDialog);
            PlayerInfoCommand = new DelegateCommand(PlayerInfoDialog, CanShowDialog);


            PropertyChanged += ServerMonitorPlayerViewModel_PropertyChanged;

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Player> > >().Subscribe(e =>
            {
                if (e.ServerId == serverInfo.Id)
                {
                    SetDataAsync(e.Items);
                    WaitingForEvent = false;
                }
            });

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Admin> > >().Subscribe(e =>
            {
                if (e.ServerId == serverInfo.Id)
                {
                    _admins = e.Items ?? new Admin[0];
                }
            });
        }
Exemplo n.º 9
0
        private void BeServerConnectHandler(ServerInfoDto info)
        {
            OnServerImmediateUpdateHandler(new BECommand(info.Id, CommandType.Players));

            OnServerUpdateHandler(new BECommand(info.Id, CommandType.Bans));
            OnServerUpdateHandler(new BECommand(info.Id, CommandType.Missions));
            OnServerUpdateHandler(new BECommand(info.Id, CommandType.Admins));
        }
Exemplo n.º 10
0
 private void BeServerDisconnectHandler(ServerInfoDto info)
 {
     if (info.Id != CurrentServer.Id)
     {
         return;
     }
     Connected = false;
 }
Exemplo n.º 11
0
        private void CheckServer(ServerInfoDto info)
        {
            var item = _serverPool.GetOrAdd(info.Id, id => Create(info));

            if (!item.BEServer.Connected)
            {
                item.BEServer.Connect();
            }
        }
Exemplo n.º 12
0
        private void CloseServer(ServerInfoDto info)
        {
            ServerItem item;

            if (_serverPool.TryRemove(info.Id, out item))
            {
                item.Dispose();
            }
        }
Exemplo n.º 13
0
        public async Task <IHttpActionResult> PutServer(string endpoint, ServerInfoDto serverInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _mediator.Send(new PutServerInfoCommand(endpoint, serverInfo));

            return(Ok());
        }
Exemplo n.º 14
0
        public async Task Should_add_new_server()
        {
            var serverInfo = new ServerInfoDto {
                Name = string.Empty, GameModes = new List <string>()
            };

            await _handler.Handle(new PutServerInfoCommand(string.Empty, serverInfo));

            Assert.AreEqual(1, _context.Servers.Count());
        }
Exemplo n.º 15
0
        public ServerMonitorModel(ServerInfoDto currentServer,
                                  IEventAggregator eventAggregator, IServerInfoRepository infoRepository)
        {
            CurrentServer    = currentServer;
            _eventAggregator = eventAggregator;
            _infoRepository  = infoRepository;

            _eventAggregator.GetEvent <ConnectServerEvent>().Subscribe(BeServerConnectHandler, ThreadOption.UIThread);
            _eventAggregator.GetEvent <DisConnectServerEvent>().Subscribe(BeServerDisconnectHandler, ThreadOption.UIThread);
            _eventAggregator.GetEvent <RunServerEvent>().Publish(CurrentServer);
        }
Exemplo n.º 16
0
        public bool UpdateServer(ServerInfoDto serverInfo)
        {
            var request = new RestRequest("serverlist/", Method.POST);

            request.AddParameter("application/json", JsonConvert.SerializeObject(serverInfo), ParameterType.RequestBody);

            HttpStatusCode statusCode;

            Execute(request, out statusCode);

            return(statusCode == HttpStatusCode.OK);
        }
Exemplo n.º 17
0
        public async Task <RegisterResult> Register(ServerInfoDto serverInfo)
        {
            UpdateLastActivity();
            var result = (RegisterResult)Network.AuthServer.Instance.ServerManager.Add(serverInfo);

            if (result == RegisterResult.OK)
            {
                var state = CurrentContext.Channel.GetAttribute(ChannelAttributes.State).Get();
                state.ServerId = serverInfo.Id;
            }

            return(result);
        }
Exemplo n.º 18
0
        public ServerInfoModel(ServerInfoDto info)
        {
            _info = info;

            if (_info != null)
            {
                Host      = _info.Host;
                Port      = _info.Port;
                SteamPort = _info.SteamPort;
                Password  = _info.Password;
                Name      = _info.Name;
            }
        }
Exemplo n.º 19
0
        private void CheckServer(ServerInfoDto serverInfo)
        {
            var iphost = _ipService.GetIpAddress(serverInfo.Host);
            var server = new Arma3BEClient.Steam.Server(new IPEndPoint(IPAddress.Parse(iphost), serverInfo.SteamPort));

            var settings = new GetServerInfoSettings();
            var rules    = server.GetServerInfoSync(settings);

            if (string.Compare(rules.Environment, "w", StringComparison.Ordinal) != 0)
            {
                ShowWarning = true;
            }
        }
        public ServerMonitorAdminsViewModel(ServerInfoDto serverInfo, IEventAggregator eventAggregator)
            : base(new ActionCommand(() => SendCommand(eventAggregator, serverInfo.Id, CommandType.Admins)), new AdminComparer())
        {
            _helper = new AdminHelper(serverInfo.Id);

            eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Admin> > >().Subscribe(async e =>
            {
                if (e.ServerId == serverInfo.Id)
                {
                    await SetDataAsync(e.Items);
                    WaitingForEvent = false;
                }
            });
        }
Exemplo n.º 21
0
        public virtual int Add(ServerInfoDto vm)
        {
            int count = 0;

            if (vm != null)
            {
                using (var db = this.CreateDbContext())
                {
                    db.Configuration.AutoDetectChangesEnabled = true;
                    using (db.BeginTransaction(System.Data.IsolationLevel.Serializable))
                    {
                        var m = db.ServerInfo.Where(q => q.Address == vm.Address).FirstOrDefault();
                        if (m == null || m.IsDelete == true)
                        {
                            if (m == null)
                            {
                                m = new ServerInfo();
                            }
                            m.Address    = vm.Address;
                            m.Port       = vm.Port;
                            m.Account    = vm.Account;
                            m.Password   = vm.Password;
                            m.IsDelete   = false;
                            m.UpdateTime = DateTime.Now;
                            if (m.Id == 0)
                            {
                                db.ServerInfo.Add(m);
                            }
                            count += db.SaveChanges();
                            vm.Id  = m.Id;
                            if (vm.SyncList != null)
                            {
                                ServerSyncTypeRepository.Instance.AddOrUpdate(m.Id, vm.SyncList, db);
                            }
                            db.AddCommitCallback(() =>
                            {
                                var serverInfoCache = this.GetCache <IServerInfoCache>();
                                serverInfoCache.Remove();
                            });
                            db.Commit();
                            vm.UpdateTime = m.UpdateTime;
                        }
                    }
                }
            }

            return(count);
        }
Exemplo n.º 22
0
        public async Task GetServer_should_return_server_info_when_server_exists()
        {
            var serverInfoDto = new ServerInfoDto {
                Name = string.Empty, GameModes = new List <string> {
                    string.Empty
                }
            };

            A.CallTo(() => _fakeMediator.Send(A <GetServerInfoQuery> ._, A <CancellationToken> ._)).Returns(serverInfoDto);

            var result = await _serversController.GetServer(string.Empty) as OkNegotiatedContentResult <ServerInfoDto>;

            Assert.NotNull(result);
            Assert.AreEqual(string.Empty, result.Content.Name);
            Assert.AreEqual(1, result.Content.GameModes.Count);
        }
Exemplo n.º 23
0
        private IBEServer CreateServer(ServerInfoDto info)
        {
            var host = _ipService.GetIpAddress(info.Host);

            if (string.IsNullOrEmpty(host))
            {
                var message = $"Host {info.Host} is incorrect for server {info.Name}";
                _log.Error(message);
            }

            var server = _container.Resolve <BEServer>(new ParameterOverride("host", host),
                                                       new ParameterOverride("port", info.Port),
                                                       new ParameterOverride("password", info.Password));

            return(server);
        }
Exemplo n.º 24
0
        public async Task Should_add_new_gamemodes_when_they_does_not_exists()
        {
            _context.GameModes.Add(new GameMode {
                Name = "DM"
            });
            _context.SaveChanges();
            var serverInfo = new ServerInfoDto {
                Name = string.Empty, GameModes = new List <string> {
                    "dM", "TDM"
                }
            };

            await _handler.Handle(new PutServerInfoCommand(string.Empty, serverInfo));

            Assert.AreEqual(2, _context.GameModes.Count());
        }
Exemplo n.º 25
0
        public ServerMonitorBansViewModel(ServerInfoDto serverInfo, IEventAggregator eventAggregator, IServerInfoRepository infoRepository,
                                          IBanHelper banHelper, ISettingsStoreSource settingsStoreSource)
            : base(
                new ActionCommand(() => SendCommand(eventAggregator, serverInfo.Id, CommandType.Bans)),
                new BanViewComparer())
        {
            _serverInfoId    = serverInfo.Id;
            _eventAggregator = eventAggregator;
            _helper          = banHelper;
            AvailibleBans    = new BanView[0];

            SyncBans = new ActionCommand(() =>
            {
                var bans = SelectedAvailibleBans;

                if (bans != null)
                {
                    Task.Factory.StartNew(async() => { await _helper.BanGUIDOfflineAsync(_serverInfoId, bans.ToArray(), true); },
                                          TaskCreationOptions.LongRunning);
                }
            });

            CustomBan = new ActionCommand(() =>
            {
                var w = new BanPlayerWindow(_serverInfoId, _helper, null, false, null, null, infoRepository, settingsStoreSource);
                w.ShowDialog();
            });

            RefreshAvailiableCommand = new ActionCommand(async() =>
            {
                AvailibleBans = await GetAvailibleBans();
                RaisePropertyChanged(nameof(AvailibleBans));
                RaisePropertyChanged(nameof(AvailibleBansCount));
            });

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Ban> > >()
            .Subscribe(async e =>
            {
                if (_serverInfoId == e.ServerId)
                {
                    await SetDataAsync(e.Items);
                    WaitingForEvent = false;
                }
            });
        }
Exemplo n.º 26
0
        public ServerMonitorManageServerViewModel(ServerInfoDto serverInfo, IEventAggregator eventAggregator,
                                                  IIpService ipService)
        {
            _serverId        = serverInfo.Id;
            _eventAggregator = eventAggregator;
            _ipService       = ipService;

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Mission> > >().Subscribe(e =>
            {
                if (e.ServerId == _serverId)
                {
                    Missions = e.Items;
                }
            });

            SetMissionCommand = new ActionCommand(() =>
            {
                var m = SelectedMission;
                if (m != null && ConfirmNotSupported(CommandType.Mission))
                {
                    var mn = m.Name;
                    SendCommand(CommandType.Mission, mn);
                }
            },
                                                  () => SelectedMission != null);

            RefreshCommand = new ActionCommand(() => SendCommand(CommandType.Missions));

            InitCommand     = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.Init); });
            ShutdownCommand = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.Shutdown); });
            ReassignCommand = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.Reassign); });
            RestartCommand  = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.Restart); });

            RestartServerCommand = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.RestartServer); });

            LockCommand   = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.Lock); });
            UnlockCommand = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.Unlock); });

            LoadBansCommand    = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.LoadBans); });
            LoadScriptsCommand = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.LoadScripts); });
            LoadEventsCommand  = new ActionCommand(() => { SendCommandWithConfirmation(CommandType.LoadEvents); });

            ShowWarning = false;
            Task.Run(() => CheckServer(serverInfo));
        }
        public ServerMonitorChatViewModel(ServerInfoDto serverInfo, IEventAggregator eventAggregator, ISettingsStoreSource settingsStoreSource, IServerInfoRepository infoRepository)
        {
            _serverId            = serverInfo.Id;
            _eventAggregator     = eventAggregator;
            _settingsStoreSource = settingsStoreSource;

            AutoScroll = true;
            EnableChat = true;

            _chatHelper = new ChatHelper(_serverId);

            _eventAggregator.GetEvent <BEMessageEvent <BEChatMessage> >()
            .Subscribe(async e => await BeServerChatMessageHandlerAsync(e), ThreadOption.UIThread);

            _eventAggregator.GetEvent <BEMessageEvent <BEAdminLogMessage> >()
            .Subscribe(_beServer_PlayerLog, ThreadOption.UIThread);
            _eventAggregator.GetEvent <BEMessageEvent <BEPlayerLogMessage> >()
            .Subscribe(_beServer_PlayerLog, ThreadOption.UIThread);
            _eventAggregator.GetEvent <BEMessageEvent <BEBanLogMessage> >()
            .Subscribe(_beServer_PlayerLog, ThreadOption.UIThread);

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Player> > >()
            .Subscribe(_beServer_PlayerHandler, ThreadOption.UIThread);

            var global = new Player(-1, null, 0, 0, null, "GLOBAL", Player.PlayerState.Ingame);

            Players = new List <Player> {
                global
            };
            SelectedPlayer = global;

            ShowHistoryCommand = new ActionCommand(() =>
            {
                var model       = new ChatHistoryViewModel(_serverId, infoRepository);
                model.StartDate = DateTime.UtcNow.UtcToLocalFromSettings().AddHours(-5);
                var wnd         = new ChatHistory(model);
                wnd.Show();
                wnd.Activate();
            });

            SendCommandMessage = new DelegateCommand(() => SendCommand(), () => string.IsNullOrEmpty(CommandMessage) == false);
        }
Exemplo n.º 28
0
        private async Task OpenServerInfoAsync(ServerInfoDto serverInfo)
        {
            var region = _regionManager.Regions[RegionNames.ServerTabRegion];

            if (region.Views.OfType <ServerInfoControl>()
                .Select(x => x.DataContext as ServerMonitorModel)
                .Any(x => x?.CurrentServer.Id == serverInfo.Id))
            {
                return;
            }

            var control =
                _container.Resolve <ServerInfoControl>(
                    new ParameterOverride("currentServer", serverInfo).OnType <ServerMonitorModel>(),
                    new ParameterOverride("console", false).OnType <ServerMonitorModel>());

            await _model.ReloadAsync();

            region.Add(control, null, true);
            region.Activate(control);
        }
Exemplo n.º 29
0
        public static ServerInfo ConvertToInfo(this ServerInfoDto info)
        {
            if (info != null)
            {
                return(new ServerInfo
                {
                    CachePath = info.CachePath,
                    CanLaunchWebBrowser = info.CanLaunchWebBrowser,
                    CanSelfRestart = info.CanSelfRestart,
                    CanSelfUpdate = info.CanSelfUpdate,
                    HardwareAccelerationRequiresPremiere = info.HardwareAccelerationRequiresPremiere,
                    HasPendingRestart = info.HasPendingRestart,
                    HasUpdateAvailable = info.HasUpdateAvailable,
                    HttpServerPortNumber = info.HttpServerPortNumber,
                    HttpsPortNumber = info.HttpsPortNumber,
                    Id = info.Id,
                    InternalMetadataPath = info.InternalMetadataPath,
                    IsShuttingDown = info.IsShuttingDown,
                    ItemsByNamePath = info.ItemsByNamePath,
                    LocalAddress = info.LocalAddress,
                    LogPath = info.LogPath,
                    OperatingSystem = info.OperatingSystem,
                    OperatingSystemDisplayName = info.OperatingSystemDisplayName,
                    ProgramDataPath = info.ProgramDataPath,
                    ServerName = info.ServerName,
                    SupportsAutoRunAtStartup = info.SupportsAutoRunAtStartup,
                    SupportsHttps = info.SupportsHttps,
                    SupportsLibraryMonitor = info.SupportsLibraryMonitor,
                    SystemUpdateLevel = info.SystemUpdateLevel == "Release" ? UpdateLevel.Release :
                                        info.SystemUpdateLevel == "beta" ? UpdateLevel.Beta : UpdateLevel.Dev,
                    TranscodingTempPath = info.TranscodingTempPath,
                    Version = info.Version,
                    WanAddress = info.WanAddress,
                    WebSocketPortNumber = info.WebSocketPortNumber
                });
            }

            return(null);
        }
Exemplo n.º 30
0
        public async Task Should_update_existing_server()
        {
            var server =
                new Data.Server
            {
                Endpoint  = "localhost",
                Name      = string.Empty,
                GameModes = new List <GameMode>()
            };

            _context.Servers.Add(server);
            _context.SaveChanges();
            var serverInfo = new ServerInfoDto {
                Name = "new name", GameModes = new List <string> {
                    "DM"
                }
            };

            await _handler.Handle(new PutServerInfoCommand("LOCALhost", serverInfo));

            Assert.AreEqual(1, _context.Servers.Count());
            Assert.AreEqual("new name", _context.Servers.First().Name);
            Assert.AreEqual(1, _context.Servers.First().GameModes.Count);
        }