Beispiel #1
0
        private IArmaProcess InitializeArmaProcess(IArmaProcess armaProcess)
        {
            if (armaProcess.IsStartingOrStarted)
            {
                armaProcess.OnProcessShutdown += OnServerProcessShutdown;
            }

            return(armaProcess);
        }
 private DedicatedServer PrepareDedicatedServer(IArmaProcess armaProcess, IEnumerable <IArmaProcess>?headlessClients = null)
 => new DedicatedServer(
     ServerPort,
     _modset,
     _modsetConfigMock.Object,
     _serverStatusFactoryMock.Object,
     _keysProviderMock.Object,
     _armaProcessManagerMock.Object,
     armaProcess,
     headlessClients ?? new List <IArmaProcess>(),
     new Logger <DedicatedServer>(new NullLoggerFactory()));
        public async Task <Result <IArmaProcess> > CheckServerIsRestarting(IArmaProcess armaProcess)
        {
            var armaProcesses = await _armaProcessDiscoverer.DiscoverArmaProcesses();

            var newArmaProcess = armaProcesses
                                 .SingleOrDefault(x => x.Value.Exists(process => Equals(process.Parameters, armaProcess.Parameters)))
                                 .Value?
                                 .SingleOrDefault(process => process.ProcessType == ArmaProcessType.Server);

            return(newArmaProcess is null
                ? Result.Failure <IArmaProcess>("Server process did not restart.")
                : Result.Success(newArmaProcess));
        }
        private IDedicatedServer CreateServer(
            int port,
            IModset modset,
            IArmaProcess armaProcess,
            IEnumerable <IArmaProcess>?headlessClients = null)
        {
            var server = _dedicatedServerFactory.CreateDedicatedServer(
                port,
                modset,
                armaProcess,
                headlessClients);

            return(server);
        }
        public IDedicatedServer CreateDedicatedServer(
            int port,
            IModset modset,
            IArmaProcess armaProcess,
            IEnumerable <IArmaProcess>?headlessProcesses = null)
        {
            var builder = _serverBuilderFactory.CreateServerBuilder();

            return(builder
                   .OnPort(port)
                   .WithModset(modset)
                   .WithServerProcess(armaProcess)
                   .WithHeadlessClients(headlessProcesses)
                   .Build());
        }
Beispiel #6
0
        private async Task OnServerProcessShutdown(IArmaProcess armaProcess)
        {
            _logger.LogDebug("Detected server process shutdown on port {Port}", Port);

            await(await _armaProcessManager.CheckServerIsRestarting(armaProcess))
            .Match(
                onSuccess: async newArmaProcess =>
            {
                _logger.LogDebug("Server restart detected");
                _armaProcess = newArmaProcess;
                _armaProcess.OnProcessShutdown += OnServerProcessShutdown;
                await InvokeOnServerRestarted();
            },
                onFailure: async _ =>
            {
                _logger.LogDebug("Server process shutdown itself");
                ShutdownHeadlessClients();
                await InvokeOnServerShutdown();
            });
        }
Beispiel #7
0
        public DedicatedServer(
            int port,
            IModset modset,
            IModsetConfig modsetConfig,
            IServerStatusFactory serverStatusFactory,
            IKeysPreparer keysPreparer,
            IArmaProcessManager armaProcessManager,
            IArmaProcess armaProcess,
            IEnumerable <IArmaProcess> headlessClients,
            ILogger <DedicatedServer> logger)
        {
            Port                 = port;
            SteamQueryPort       = port + 1;
            _keysPreparer        = keysPreparer;
            _armaProcessManager  = armaProcessManager;
            Modset               = modset;
            _modsetConfig        = modsetConfig;
            _serverStatusFactory = serverStatusFactory;
            _armaProcess         = InitializeArmaProcess(armaProcess);

            _headlessProcesses = headlessClients.ToList();
            _logger            = logger;
        }
 public IServerBuilder WithServerProcess(IArmaProcess armaProcess)
 {
     _armaProcess = armaProcess;
     return(this);
 }