Ejemplo n.º 1
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            Log.Information("OnDisconnected: Removing player connid '{0}'", Context.ConnectionId);

            try
            {
                _playerPool.GetPlayerByConnectionId(Context.ConnectionId)?.ExcludeMySelfFromAnyGame(_gamePool);

                _playerPool.RemovePlayerFromPoolByConnID(Context.ConnectionId);

                Log.Information("Player '{connid}' disconnected event", Context.ConnectionId);
            }
            catch { }


            await base.OnDisconnectedAsync(exception);

            //if (exception == null)
            //{
            //    Guid pGuid = _playerPool.GetPlayerByConnectionId(Context.ConnectionId);

            //    if (pGuid != Guid.Empty)
            //    {
            //        Guid gGuid = _gamePool.FindTheGamePlayerBelongsTo(pGuid);

            //        if (gGuid != Guid.Empty)
            //        {
            //            Game g = _gamePool.Games[gGuid];
            //            Player p = _playerPool.Players[pGuid];

            //            if (!(p.Role == PlayerRole.Ghost || p.Role == PlayerRole.Kicked))
            //            {
            //                g.RemovePlayer(pGuid);
            //            }
            //            else
            //            {
            //                Log.Information("Player '{name}' disconnected, but he is '{role}' so leaving him in game and on server until game" +
            //                    "{name} ends", p.Name, p.Role.ToString(), g.Name);
            //            }

            //            //_gamePool.Games[gGuid].RemovePlayer(pGuid);

            //            //_playerPool.RemovePlayerFromPoolByConnID(Context.ConnectionId);

            //            //Log.Information("Player {p} successifuly removed from game {g} on disconnection event", pGuid, gGuid);
            //        }
            //    }
            //}
            //else
            //{
            //    Log.Error("Client '{0}' diconnected with exception '{1}'", Context.ConnectionId, exception.Message);
            //}
        }