Esempio n. 1
0
        /// <summary>
        ///     The main entry point for the application.
        /// </summary>
        private static void Main()
        {
            if (!Environment.UserInteractive)
            {
                throw new NotImplementedException();
#pragma warning disable 162
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { };
                ServiceBase.Run(ServicesToRun);
                return;

#pragma warning restore 162
            }

            var config     = new ServerSettings();
            var logger     = new ConsoleLogger("console", (m, l) => l >= LogLevel.Information, true);
            var supervisor = new EmptySupervisor();
            var serv       = new EvadersServer(new DefaultProviderFactory <IServerSupervisor>(item => supervisor), new DefaultProviderFactory <GameSettings>(item => GameSettings.Default), new DefaultProviderFactory <IMatchmaking>(item => new Matchmaking("Default", config.MaxTimeInQueueSec, logger)), logger, config);
            serv.Start();

            var wait = new SpinWait();
            while (true)
            {
                serv.Update();
                wait.SpinOnce();
            }
        }
        /// <inheritdoc />
        public void Start()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(DefaultGameServer));
            }
            if (_running)
            {
                throw new InvalidOperationException("The server is already running.");
            }
            _running = true;

            _logger.LogInformation("Starting game server ...");

            _cancellation = new CancellationTokenSource();

            _server = new EvadersServer(_serverSupervisorFactory.Create(_settings.SupervisorProviderId), _matchmakingFactory.Create(_settings.MatchmakingProviderId), _loggerFactory.CreateLogger <EvadersServer>(), _serverConfigurationFactory.Create(_settings.ServerConfigurationProviderId));

            _gameServerLoop = new Task(GameLoop, _cancellation.Token, _cancellation.Token, TaskCreationOptions.LongRunning);
            _gameServerLoop.Start();
        }