Esempio n. 1
0
        private void OnPlayerLeft(IPlayer player, LeaveReasons reason)
        {
            Log.Default.WriteLine(LogLevels.Info, "Player left:{0} {1}", player.Name, reason);

            bool wasServerMaster = false;

            // Remove from player manager
            lock (_playerManager.LockObject)
            {
                if (player == _playerManager.ServerMaster)
                {
                    wasServerMaster = true;
                }
                // Remove player from player list
                _playerManager.Remove(player);
            }

            // Clean host tables
            foreach (IHost host in _hosts)
            {
                host.RemovePlayer(player);
            }

            // If game was running and player was playing, check if only one player left (see GameLostHandler)
            if ((State == ServerStates.GameStarted || State == ServerStates.GamePaused) && player.State == PlayerStates.Playing)
            {
                int playingCount = _playerManager.Players.Count(p => p.State == PlayerStates.Playing);
                if (playingCount == 0 || playingCount == 1)
                {
                    Log.Default.WriteLine(LogLevels.Info, "Game finished by forfeit no winner");
                    State = ServerStates.GameFinished;
                    GameStatistics statistics = PrepareGameStatistics();
                    // Send game finished (no winner)
                    foreach (IEntity entity in Entities.Where(x => x != player))
                    {
                        entity.OnGameFinished(statistics);
                    }
                    State = ServerStates.WaitingStartGame;
                }
            }

            // Inform players and spectators except disconnected player
            foreach (IEntity entity in Entities.Where(x => x != player))
            {
                entity.OnPlayerLeft(player.Id, player.Name, reason);
            }

            // Send new server master id
            if (wasServerMaster)
            {
                IPlayer serverMaster = _playerManager.ServerMaster;
                if (serverMaster != null)
                {
                    foreach (IEntity entity in Entities.Where(x => x != player))
                    {
                        entity.OnServerMasterChanged(serverMaster.Id);
                    }
                }
            }
        }
Esempio n. 2
0
 private void OnPlayerLeft(int playerId, string playerName, LeaveReasons reason)
 {
     lock (_lock)
     {
         Console.ResetColor();
         Console.SetCursorPosition(_client.Board.Width + 2 + BoardStartX, 2);
         Console.Write("{0} [{1}] left {2}", playerName, playerId, reason);
     }
 }
Esempio n. 3
0
 private void OnPlayerLeft(int playerId, string playerName, LeaveReasons reason)
 {
     if (Client.IsSpectator)
         return;
     OpponentViewModel opponent = GetOpponentViewModel(playerId);
     if (opponent != null)
     {
         opponent.PlayerId = -1;
         opponent.PlayerName = "Not playing";
         opponent.Team = "";
     }
 }
Esempio n. 4
0
        private void OnPlayerLeft(int playerId, string playerName, LeaveReasons reason)
        {
            if (!Client.IsSpectator)
            {
                return;
            }

            OpponentViewModel opponent = OpponentsViewModel[playerId];

            if (opponent != null)
            {
                opponent.PlayerId   = -1;
                opponent.PlayerName = "Not playing";
                opponent.Team       = "";
            }
        }
Esempio n. 5
0
        private void OnSpectatorLeft(ISpectator spectator, LeaveReasons reason)
        {
            Log.Default.WriteLine(LogLevels.Info, "Spectator left:{0} {1}", spectator.Name, reason);

            // Remove from spectator
            lock (_spectatorManager.LockObject)
            {
                // Remove spectator from spectator list
                _spectatorManager.Remove(spectator);
            }

            // Clean host tables
            foreach (IHost host in _hosts)
            {
                host.RemoveSpectator(spectator);
            }

            // Inform players and spectators except disconnected spectator
            foreach (IEntity entity in Entities.Where(x => x != spectator))
            {
                entity.OnSpectatorLeft(spectator.Id, spectator.Name, reason);
            }
        }
Esempio n. 6
0
        private void OnPlayerLeft(int playerid, string playerName, LeaveReasons reason)
        {
            string msg;

            switch (reason)
            {
            case LeaveReasons.Spam:
                msg = String.Format("*** {0} has been BANNED [SPAM]", playerName);
                break;

            case LeaveReasons.Disconnected:
                msg = String.Format("*** {0} has disconnected", playerName);
                break;

            case LeaveReasons.ConnectionLost:
                msg = String.Format("*** {0} has left [connection lost]", playerName);
                break;

            case LeaveReasons.Timeout:
                msg = String.Format("*** {0} has left [timeout]", playerName);
                break;

            case LeaveReasons.Ban:
                msg = String.Format("*** {0} has been BANNED", playerName);
                break;

            case LeaveReasons.Kick:
                msg = String.Format("*** {0} has been kicked", playerName);
                break;

            default:
                msg = String.Format("*** {0} has left {1}", playerName, reason);
                break;
            }
            AddServerMessage(ChatColor.Green, msg);
        }
Esempio n. 7
0
 public void OnClientDisconnected(Guid clientId, LeaveReasons reason)
 {
     UpdateCallInfo(System.Reflection.MethodBase.GetCurrentMethod().Name, clientId, reason);
 }
Esempio n. 8
0
        public void OnAdminDisconnected(Guid adminId, LeaveReasons reason)
        {
            _admins.RemoveAll(x => x.Id == adminId);

            AdminDisconnected.Do(x => x(adminId, reason));
        }
Esempio n. 9
0
 public void OnAdminDisconnected(Guid adminId, LeaveReasons reason)
 {
     UpdateCallInfo(System.Reflection.MethodBase.GetCurrentMethod().Name, adminId, reason);
 }
Esempio n. 10
0
        private static void OnAdminDisconnected(Guid adminId, LeaveReasons reason)
        {
            Console.WriteLine("OnAdminDisconnected: {0} {1}", adminId, reason);

            DisplayAdminList();
        }
Esempio n. 11
0
        public void OnClientDisconnected(Guid clientId, LeaveReasons reason)
        {
            _clients.RemoveAll(x => x.Id == clientId);

            ClientDisconnected.Do(x => x(clientId, reason));
        }
Esempio n. 12
0
 public void OnPlayerLeft(int playerId, string name, LeaveReasons reason)
 {
     UpdateCallCount(System.Reflection.MethodBase.GetCurrentMethod().Name);
 }
Esempio n. 13
0
        public void OnClientDisconnected(Guid clientId, LeaveReasons reason)
        {
            Log.Default.WriteLine(LogLevels.Info, "Client disconnected {0} {1}", clientId, reason);

            ResetTimeout();

            ClientData clientInGame = _gameClients.FirstOrDefault(x => x.Id == clientId);

            // If client was in game, remove it
            if (clientInGame != null)
            {
                Log.Default.WriteLine(LogLevels.Info, "Client disconnected {0} and removed from game", clientId);

                _gameClients.RemoveAll(x => x.Id == clientId);
                ClientGameLeft.Do(x => x(clientInGame));
            }

            // Remove client
            ClientData client = _clients.FirstOrDefault(x => x.Id == clientId);
            if (client != null)
                _clients.RemoveAll(x => x.Id == clientId);

            ClientDisconnected.Do(x => x(client, reason));
        }
 public void OnSpectatorLeft(int spectatorId, string name, LeaveReasons reason)
 {
     throw new NotImplementedException();
 }
Esempio n. 15
0
        private static void OnClientDisconnected(Guid clientId, LeaveReasons reason)
        {
            Console.WriteLine("OnClientDisconnected: {0} {1}", clientId, reason);

            DisplayClientList();
        }
Esempio n. 16
0
 public void OnPlayerLeft(int playerId, string name, LeaveReasons reason)
 {
     ExceptionFreeAction(() => Callback.OnPlayerLeft(playerId, name, reason));
 }
Esempio n. 17
0
 public void OnPlayerLeft(int playerId, string name, LeaveReasons reason)
 {
     Log.Default.WriteLine(LogLevels.Info, "OnPlayedLeft[{0}]:{1}[{2}] {3}", PlayerName, name, playerId, reason);
     ResetTimeout();
 }
 public void OnAdminDisconnected(Guid adminId, LeaveReasons reason)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 private void OnSpectatorLeft(int spectatorId, string spectatorName, LeaveReasons reason)
 {
     DeleteSpectatorEntry(spectatorId, spectatorName);
 }
Esempio n. 20
0
 private void OnPlayerLeft(int playerId, string playerName, LeaveReasons reason)
 {
     DeletePlayerEntry(playerId, playerName);
 }
Esempio n. 21
0
 public void OnClientDisconnected(Guid clientId, LeaveReasons reason)
 {
     ExceptionFreeAction(() => Callback.OnClientDisconnected(clientId, reason));
 }
Esempio n. 22
0
        private void OnClientDisconnected(ClientData client, LeaveReasons reason)
        {
            Console.WriteLine("OnClientDisconnected: {0} {1}", client == null ? Guid.Empty : client.Id, reason);

            DisplayClientList();
        }
Esempio n. 23
0
 public void OnSpectatorLeft(int spectatorId, string name, LeaveReasons reason)
 {
     ExceptionFreeAction(() => Callback.OnSpectatorLeft(spectatorId, name, reason));
 }
Esempio n. 24
0
 private void OnSpectatorLeft(int spectatorId, string spectatorName, LeaveReasons reason)
 {
     OnPlayerLeft(spectatorId, spectatorName, reason);
 }
Esempio n. 25
0
 public void OnSpectatorLeft(int spectatorId, string name, LeaveReasons reason)
 {
     Log.Default.WriteLine(LogLevels.Info, "OnSpectatorLeft[{0}]:{1}[{2}] {3}", PlayerName, name, spectatorId, reason);
 }
 public void OnClientDisconnected(Guid clientId, LeaveReasons reason)
 {
     throw new NotImplementedException();
 }
 public void OnPlayerLeft(int playerId, string name, LeaveReasons reason)
 {
     throw new NotImplementedException();
 }
Esempio n. 28
0
 public void OnAdminDisconnected(Guid adminId, LeaveReasons reason)
 {
     ExceptionFreeAction(() => Callback.OnAdminDisconnected(adminId, reason));
 }