示例#1
0
        public void TestClearNoPlayers()
        {
            IPlayerManager playerManager = CreatePlayerManager(5);

            playerManager.Clear();

            Assert.AreEqual(playerManager.PlayerCount, 0);
        }
示例#2
0
        public void TestClearSomePlayers()
        {
            IPlayerManager playerManager = CreatePlayerManager(5);

            playerManager.Add(new Player(0, "player1", new CountCallTetriNETCallback()));
            playerManager.Add(new Player(1, "player2", new CountCallTetriNETCallback()));
            playerManager.Add(new Player(2, "player3", new CountCallTetriNETCallback()));

            playerManager.Clear();

            Assert.AreEqual(playerManager.PlayerCount, 0);
        }
示例#3
0
        public void TestServerMasterNullOnClear()
        {
            IPlayer        player1       = new Player(0, "player1", new CountCallTetriNETCallback());
            IPlayer        player2       = new Player(1, "player2", new CountCallTetriNETCallback());
            IPlayer        player3       = new Player(2, "player3", new CountCallTetriNETCallback());
            IPlayerManager playerManager = CreatePlayerManager(5);

            playerManager.Add(player1);
            playerManager.Add(player2);
            playerManager.Add(player3);

            playerManager.Clear();

            Assert.IsNull(playerManager.ServerMaster);
        }
示例#4
0
        public void StopServer()
        {
            Log.Default.WriteLine(LogLevels.Info, "Stopping server");

            if (State != ServerStates.StoppingServer && State != ServerStates.WaitingStartServer)
            {
                State = ServerStates.StoppingServer;

                try
                {
                    // Stop worker threads
                    _cancellationTokenSource.Cancel();

                    _timeoutTask.Wait(2000);
                    _gameActionQueue.Wait(2000);
                }
                catch (AggregateException ex)
                {
                    Log.Default.WriteLine(LogLevels.Warning, "Aggregate exception while stopping. Exception: {0}", ex.Flatten());
                }

                // Inform players and spectators
                foreach (IEntity entity in Entities)
                {
                    entity.OnServerStopped();
                }

                // Stop hosts
                foreach (IHost host in _hosts)
                {
                    host.Stop();
                }
                // Clear player manager
                _playerManager.Clear();

                State = ServerStates.WaitingStartServer;

                Log.Default.WriteLine(LogLevels.Info, "Server stopped");
            }
            else
            {
                Log.Default.WriteLine(LogLevels.Info, "Server already stopped or stopping");
            }
        }