Example #1
0
 public void Ready(String session)
 {
     lock (_threadSync)
     {
         CGamePlayer player = _players.Single(p => p.PlayerInfo.Session == session);
         _logger.Info($"Game {Id} - Player with session {player.PlayerInfo.Session} Ready");
         player.Status = EPlayerStatus.InLobby;
     }
 }
Example #2
0
 private void NotifyWithout(Action <IGameChoiceServiceCallback> action, CGamePlayer player)
 {
     lock (_threadSync)
     {
         foreach (CGamePlayer notifyPlayer in _players.Where(p => p != player))
         {
             action(notifyPlayer.Callback);
         }
     }
 }
Example #3
0
        public Boolean LogIn(String login, Guid id, out CPlayer player)
        {
            IContextChannel chanel  = OperationContext.Current.Channel;
            String          session = OperationContext.Current.SessionId;

            chanel.Faulted += ChanelOnFaulted;

            player = new CPlayer(session, login, id);
            var gamePlayer = new CGamePlayer(player);

            var callback = OperationContext.Current.GetCallbackChannel <IGameChoiceServiceCallback>();

            gamePlayer.Callback = callback;

            _players.Add(gamePlayer);
            return(true);
        }
Example #4
0
        private void ChanelOnFaulted(Object sender, EventArgs e)
        {
            if (sender is IContextChannel chanel)
            {
                String      session = chanel.SessionId;
                CGamePlayer player  = _players.FirstOrDefault(p => p.PlayerInfo.Session == session);
                if (player != null)
                {
                    if (player.Game != null)
                    {
                        Guid gameId = player.Game.Id;
                        DisconnectInternal(gameId, session);
                    }

                    _players.Remove(player);
                }
            }
        }
Example #5
0
        public Boolean TryConnect(CGamePlayer player)
        {
            _logger.Info($"Player session {player.PlayerInfo.Session} try connect to game {Id}");
            Boolean exitResult = _playersSemaphore.WaitOne(TimeSpan.FromSeconds(10));

            if (!exitResult)
            {
                _logger.Info($"Player with session {player.PlayerInfo.Session} not connected to game {Id} by timeout");
                return(false);
            }
            lock (_threadSync)
            {
                _players.Add(player);
                player.Game = this;
            }

            NotifyWithout(cb => cb.PlayerHasConnected(player.PlayerInfo), player);
            _logger.Info($"Player session {player.PlayerInfo.Session} connected to game {Id}");

            return(true);
        }
Example #6
0
        public Boolean TryConnect(Guid gameId, out CGameInfo gameInfo)
        {
            gameInfo = null;

            CGame game = _games.FirstOrDefault(g => g.Id == gameId);

            if (game == null)
            {
                return(false);
            }

            String      session    = OperationContext.Current.SessionId;
            CGamePlayer gamePlayer = _players.Single(p => p.PlayerInfo.Session == session);

            Boolean connectionResult = game.TryConnect(gamePlayer);

            if (connectionResult)
            {
                gameInfo = game.GetInfo();
            }

            return(connectionResult);
        }