Beispiel #1
0
 public bool TryGetPeerState(string userId, out PeerState peerState)
 {
     return(this.peerDict.TryGetValue(userId, out peerState));
 }
        public void AddPeer(ILobbyPeer peer)
        {
            var peerState = new PeerState(peer);

            this.joiningPeers.AddLast(peerState);
            
            if (string.IsNullOrEmpty(peerState.UserId) == false)
            {
                this.userIdList.AddLast(peer.UserId);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Added peer: gameId={0}, userId={1}, joiningPeers={2}", this.Id, peer.UserId, this.joiningPeers.Count);
            }

            // check if max player is reached and inform the game list
            if (this.MaxPlayer > 0 && this.PlayerCount >= this.MaxPlayer)
            {
                this.Lobby.GameList.OnMaxPlayerReached(this);
            }

            // update player state in the online players cache
            if (this.Lobby.Application.PlayerOnlineCache != null && string.IsNullOrEmpty(peer.UserId) == false)
            {
                this.Lobby.Application.PlayerOnlineCache.OnJoinedGamed(peer.UserId, this);
            }
        }
Beispiel #3
0
        private void AddPeerState(PeerState peerState)
        {
            var oldValue = this.PlayerCount;
            this.joiningPeers.AddLast(peerState);
            this.Lobby.GameList.OnPlayerCountChanged(this, oldValue);

            this.IsJoinable = this.CheckIsGameJoinable();

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Added peer: gameId={0}, userId={1}, joiningPeers={2}", this.Id, peerState.UserId, this.joiningPeers.Count);
            }

            // update player state in the online players cache
            if (this.Lobby.Application.PlayerOnlineCache != null && string.IsNullOrEmpty(peerState.UserId) == false)
            {
                this.Lobby.Application.PlayerOnlineCache.OnJoinedGamed(peerState.UserId, this);
            }
        }
Beispiel #4
0
        public void AddPeer(ILobbyPeer peer)
        {
            if (this.ContainsUser(peer.UserId))
            {
                return;
            }
            var peerState = new PeerState(peer);

            this.AddPeerState(peerState);
        }
        /// <summary>
        ///   Invoked for peers which has joined the game on the game server instance.
        /// </summary>
        /// <param name = "userId">The user id of the peer joined.</param>
        private void OnPeerJoinedGameServer(string userId)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("User joined on game server: gameId={0}, userId={1}", this.Id, userId);
            }

            // remove the peer from the joining list
            bool removed = this.RemoveFromJoiningList(userId);
            if (removed == false && log.IsDebugEnabled)
            {
                log.DebugFormat("User not found in joining list: gameId={0}, userId={1}", this.Id, userId);
            }

            if (string.IsNullOrEmpty(userId))
            {
                return;
            }

            if (this.peerDict.ContainsKey(userId))
            {
                return;
            }

            var peerState = new PeerState(userId);
            this.peerDict.Add(peerState.UserId, peerState);

            if (log.IsWarnEnabled)
            {
                log.WarnFormat("Unknown user joined:  gameId={0}, userId={1}", this.Id, userId);
            }
        }
 public bool TryGetPeerState(string userId, out PeerState peerState)
 {
     return this.peerDict.TryGetValue(userId, out peerState);
 }
        public void AddPeer(ILobbyPeer peer)
        {
            var peerState = new PeerState(peer);

            this.joiningPeers.AddLast(peerState);

            if (string.IsNullOrEmpty(peerState.UserId) == false)
            {
                this.peerDict.Add(peer.UserId, peerState);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Added peer: gameId={0}, userId={1}, joiningPeers={2}", this.Id, peer.UserId, this.joiningPeers.Count);
            }
        }