コード例 #1
0
        protected virtual bool HasPermissionToEditProfiles(IPeer messagePeer)
        {
            var securityExtension = messagePeer.GetExtension <SecurityInfoPeerExtension>();

            return(securityExtension != null &&
                   securityExtension.PermissionLevel >= editProfilePermissionLevel);
        }
コード例 #2
0
ファイル: ChatChannel.cs プロジェクト: Miapata/GPE104
        /// <summary>
        /// Invoked, when user, who is connected to this channel, leaves
        /// </summary>
        /// <param name="peer"></param>
        protected virtual void OnUserDisconnect(IPeer peer)
        {
            var extension = peer.GetExtension <ChatUserExtension>();

            if (extension == null)
            {
                return;
            }

            RemoveUser(extension);
        }
コード例 #3
0
ファイル: ChatModule.cs プロジェクト: jraicr/MST
        /// <summary>
        /// Fired if existing client disconnected
        /// </summary>
        /// <param name="peer"></param>
        protected virtual void OnClientDisconnected(IPeer peer)
        {
            peer.OnPeerDisconnectedEvent -= OnClientDisconnected;

            var chatUser = peer.GetExtension <ChatUserPeerExtension>();

            if (chatUser != null)
            {
                RemoveChatUser(chatUser);
            }
        }
コード例 #4
0
ファイル: BaseLobby.cs プロジェクト: jraicr/MST
        /// <summary>
        /// Extracts username of the peer.
        /// By default, uses user extension <see cref="IUserPeerExtension"/>
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        protected virtual string TryGetUsername(IPeer peer)
        {
            var userExt = peer.GetExtension <IUserPeerExtension>();

            if (userExt == null)
            {
                return(null);
            }

            return(userExt.Username);
        }
コード例 #5
0
ファイル: ChatModule.cs プロジェクト: Miapata/GPE104
        protected virtual void OnClientDisconnected(IPeer peer)
        {
            peer.Disconnected -= OnClientDisconnected;

            var chatExt = peer.GetExtension <ChatUserExtension>();

            if (chatExt != null)
            {
                RemoveChatUser(chatExt);
            }
        }
コード例 #6
0
        protected virtual LobbyUserPeerExtension GetOrCreateLobbiesExtension(IPeer peer)
        {
            var extension = peer.GetExtension <LobbyUserPeerExtension>();

            if (extension == null)
            {
                extension = new LobbyUserPeerExtension(peer);
                peer.AddExtension(extension);
            }

            return(extension);
        }
コード例 #7
0
        /// <summary>
        /// Invoked, when user logs out (disconnects from master)
        /// </summary>
        /// <param name="session"></param>
        private void OnPeerPlayerDisconnectedEventHandler(IPeer peer)
        {
            peer.OnPeerDisconnectedEvent -= OnPeerPlayerDisconnectedEventHandler;

            var profileExtension = peer.GetExtension <ProfilePeerExtension>();

            if (profileExtension == null)
            {
                return;
            }

            // Unload profile
            StartCoroutine(UnloadProfile(profileExtension.Username, unloadProfileAfter));
        }
コード例 #8
0
        /// <summary>
        /// Invoked, when user logs out (disconnects from master)
        /// </summary>
        /// <param name="session"></param>
        private void OnPeerPlayerDisconnected(IPeer peer)
        {
            peer.Disconnected -= OnPeerPlayerDisconnected;

            var profileExtension = peer.GetExtension <ProfileExtension>();

            if (profileExtension == null)
            {
                return;
            }

            // Unload profile
            Task.Factory.StartNew(() => UnloadProfile(profileExtension.Username, UnloadProfileAfter));
        }
コード例 #9
0
        private void OnUserDisconnect(IPeer peer)
        {
            var extension = peer.GetExtension <UserExtension>();

            if (extension == null)
            {
                return;
            }

            _loggedInUsers.Remove(extension.Username.ToLower());

            peer.Disconnected -= OnUserDisconnect;

            LoggedOut?.Invoke(extension);
        }
コード例 #10
0
        /// <summary>
        /// Fires when room player is disconnected
        /// </summary>
        /// <param name="peer"></param>
        private void Server_OnPeerDisconnectedEvent(IPeer peer)
        {
            var roomUserExtension = peer.GetExtension <RoomUserPeerExtension>();

            if (roomUserExtension != null)
            {
                roomPlayersByMsfPeerId.Remove(roomUserExtension.MasterPeerId);
                roomPlayersByRoomPeerId.Remove(peer.Id);
                roomPlayersByUsername.Remove(roomUserExtension.Username);

                var roomServer = Server as RoomServerBehaviour;
                roomServer.CurrentRoomController.NotifyPlayerLeft(roomUserExtension.MasterPeerId);

                OnPlayerLeftEvent?.Invoke(roomUserExtension);
            }
        }
コード例 #11
0
ファイル: ChatModule.cs プロジェクト: jraicr/MST
        /// <summary>
        /// Removes existing chat user from all the channels, and creates a new
        /// <see cref="ChatUserPeerExtension"/> with new username. If <see cref="joinSameChannels"/> is true,
        /// user will be added to same channels
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="newUsername"></param>
        /// <param name="joinSameChannels"></param>
        public void ChangeUsername(IPeer peer, string newUsername, bool joinSameChannels = true)
        {
            var chatUser = peer.GetExtension <ChatUserPeerExtension>();

            if (chatUser == null)
            {
                return;
            }

            // Get previous chat user channels that one is connected to
            var prevChannels = chatUser.CurrentChannels.ToList();

            // Get his default chat channel
            var defaultChannel = chatUser.DefaultChannel;

            // Remove the user from chat
            RemoveChatUser(chatUser);

            // Create a new chat user
            var newExtension = CreateChatUser(peer, newUsername);

            // Replace with new user
            peer.AddExtension(newExtension);

            if (joinSameChannels)
            {
                foreach (var prevChannel in prevChannels)
                {
                    var channel = GetOrCreateChannel(prevChannel.Name);
                    if (channel != null)
                    {
                        channel.AddUser(newExtension);
                    }
                }

                if (defaultChannel != null && defaultChannel.Users.Contains(newExtension))
                {
                    // If we were added to the chat, which is now set as our default chat
                    // It's safe to set the default channel
                    newExtension.DefaultChannel = defaultChannel;
                }
            }
        }
コード例 #12
0
        private void OnPeerDisconnectedEventHandler(IPeer peer)
        {
            logger.Debug($"Client {peer.Id} disconnected from server. Total clients are: {connectedPeers.Count - 1}");

            // Remove listener to messages
            peer.OnMessageReceivedEvent -= OnMessageReceived;

            // Remove the peer
            connectedPeers.Remove(peer.Id);

            var extension = peer.GetExtension <SecurityInfoPeerExtension>();

            if (extension != null)
            {
                // Remove from guid lookup
                peersByGuidLookup.Remove(extension.UniqueGuid);
            }

            // Invoke the event
            OnPeerDisconnectedEvent?.Invoke(peer);
            OnPeerDisconnected(peer);
        }
コード例 #13
0
        private void Disconnected(IPeer peer)
        {
            // Remove listener to messages
            peer.MessageReceived -= OnMessageReceived;

            // Remove the peer
            ConnectedPeers.Remove(peer.Id);

            var extension = peer.GetExtension <PeerSecurityExtension>();

            if (extension != null)
            {
                PeersByGuidLookup.Remove(extension.UniqueGuid);
            }

            // Invoke the event
            if (PeerDisconnected != null)
            {
                PeerDisconnected(peer);
            }

            OnPeerDisconnected(peer);
        }
コード例 #14
0
ファイル: ChatModule.cs プロジェクト: Avatarchik/ProjectVerse
        /// <summary>
        ///     Removes existing chat user from all the channels, and creates a new
        ///     <see cref="ChatUserExtension" /> with new username. If <see cref="joinSameChannels" /> is true,
        ///     user will be added to same channels
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="newUsername"></param>
        /// <param name="joinSameChannels"></param>
        public void ChangeUsername(IPeer peer, string newUsername, bool joinSameChannels = true)
        {
            var chatExt = peer.GetExtension <ChatUserExtension>();

            if (chatExt == null)
            {
                return;
            }

            var prevChannels   = chatExt.CurrentChannels.ToList();
            var defaultChannel = chatExt.DefaultChannel;

            // Remove the user from chat
            RemoveChatUser(chatExt);

            // Create a new chat user
            var newExtension = CreateChatUser(peer, newUsername);

            peer.AddExtension(newExtension);

            if (joinSameChannels)
            {
                foreach (var prevChannel in prevChannels)
                {
                    var channel = GetOrCreateChannel(prevChannel.Name);
                    if (channel != null)
                    {
                        channel.AddUser(newExtension);
                    }
                }

                if (defaultChannel != null && defaultChannel.Users.Contains(newExtension))
                {
                    newExtension.DefaultChannel = defaultChannel;
                }
            }
        }
コード例 #15
0
        private bool HasCreationPermissions(IPeer peer)
        {
            var extension = peer.GetExtension <PeerSecurityExtension>();

            return(extension.PermissionLevel >= _config.CreateSpawnerPermissionLevel);
        }
コード例 #16
0
ファイル: BaseLobby.cs プロジェクト: jraicr/MST
 /// <summary>
 /// Invoked when one of the members disconnects
 /// </summary>
 /// <param name="session"></param>
 protected virtual void OnPeerDisconnected(IPeer peer)
 {
     RemovePlayer(peer.GetExtension <LobbyUserPeerExtension>());
 }
コード例 #17
0
        /// <summary>
        /// Sends a request to room, to retrieve an access to it for a specified peer,
        /// with some extra properties
        /// </summary>
        public void GetAccess(IPeer peer, Dictionary <string, string> properties, GetAccessCallback callback)
        {
            // If request is already pending
            if (_requestsInProgress.Contains(peer.Id))
            {
                callback.Invoke(null, "You've already requested an access to this room");
                return;
            }

            // If player is already in the game
            if (_players.ContainsKey(peer.Id))
            {
                callback.Invoke(null, "You are already in this room");
                return;
            }

            // If player has already received an access and didn't claim it
            // but is requesting again - send him the old one
            var currentAccess = _unconfirmedAccesses.Values.FirstOrDefault(v => v.Peer == peer);

            if (currentAccess != null)
            {
                // Restore the timeout
                currentAccess.Timeout = DateTime.Now.AddSeconds(Options.AccessTimeoutPeriod);

                callback.Invoke(currentAccess.Access, null);
                return;
            }

            // If there's a player limit
            if (Options.MaxPlayers != 0)
            {
                var playerSlotsTaken = _requestsInProgress.Count
                                       + _accessesInUse.Count
                                       + _unconfirmedAccesses.Count;

                if (playerSlotsTaken >= Options.MaxPlayers)
                {
                    callback.Invoke(null, "Room is already full");
                    return;
                }
            }

            var packet = new RoomAccessProvideCheckPacket()
            {
                PeerId = peer.Id,
                RoomId = RoomId
            };

            // Add the username if available
            var userExt = peer.GetExtension <IUserExtension>();

            if (userExt != null && !string.IsNullOrEmpty(userExt.Username))
            {
                packet.Username = userExt.Username;
            }

            // Add to pending list
            _requestsInProgress.Add(peer.Id);

            Peer.SendMessage((short)OpCodes.ProvideRoomAccessCheck, packet, (status, response) =>
            {
                // Remove from pending list
                _requestsInProgress.Remove(peer.Id);

                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var accessData = response.Deserialize(new RoomAccessPacket());

                var access = new RoomAccessData()
                {
                    Access  = accessData,
                    Peer    = peer,
                    Timeout = DateTime.Now.AddSeconds(Options.AccessTimeoutPeriod)
                };

                // Save the access
                _unconfirmedAccesses[access.Access.Token] = access;

                callback.Invoke(access.Access, null);
            });
        }
コード例 #18
0
        protected virtual bool CheckIfHasPermissionToCreate(IPeer peer)
        {
            var extension = peer.GetExtension <SecurityInfoPeerExtension>();

            return(extension.PermissionLevel >= createLobbiesPermissionLevel);
        }
コード例 #19
0
ファイル: RoomsPlugin.cs プロジェクト: proepkes/SpeedDate
        /// <summary>
        /// Returns true, if peer has permissions to register a game server
        /// </summary>
        /// <param name="peer"></param>
        /// <returns></returns>
        protected virtual bool HasRoomRegistrationPermissions(IPeer peer)
        {
            var extension = peer.GetExtension <PeerSecurityExtension>();

            return(extension.PermissionLevel >= RegisterRoomPermissionLevel);
        }
コード例 #20
0
        /// <summary>
        /// Returns true, if peer has permissions to register a spawner
        /// </summary>
        /// <param name="peer"></param>
        /// <returns></returns>
        protected virtual bool HasCreationPermissions(IPeer peer)
        {
            var extension = peer.GetExtension <PeerSecurityExtension>();

            return(extension.PermissionLevel >= CreateSpawnerPermissionLevel);
        }
コード例 #21
0
ファイル: RegisteredRoom.cs プロジェクト: xyberviri/MST
        /// <summary>
        /// Sends a request to room, to retrieve an access to it for a specified peer, 
        /// with some extra options
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="customOptions"></param>
        /// <param name="callback"></param>
        public void GetAccess(IPeer peer, MstProperties customOptions, GetAccessCallback callback)
        {
            // If request is already pending
            if (requestsInProgress.Contains(peer.Id))
            {
                callback.Invoke(null, "You've already requested an access to this room");
                return;
            }

            // If player is already in the game
            if (connectedPlayers.ContainsKey(peer.Id))
            {
                callback.Invoke(null, "You are already in this room");
                return;
            }

            // If player has already received an access and didn't claim it
            // but is requesting again - send him the old one
            var currentAccess = unconfirmedAccesses.Values.FirstOrDefault(v => v.Peer == peer);
            if (currentAccess != null)
            {
                // Restore the timeout
                currentAccess.Timeout = DateTime.Now.AddSeconds(Options.AccessTimeoutPeriod);

                callback.Invoke(currentAccess.Access, null);
                return;
            }

            // If there's a player limit
            if (Options.MaxConnections != 0)
            {
                var playerSlotsTaken = requestsInProgress.Count + accessesInUse.Count + unconfirmedAccesses.Count;

                if (playerSlotsTaken >= Options.MaxConnections)
                {
                    callback.Invoke(null, "Room is already full");
                    return;
                }
            }

            // Create packet to request checking of access
            var provideRoomAccessCheckPacket = new ProvideRoomAccessCheckPacket()
            {
                PeerId = peer.Id,
                RoomId = RoomId,
                CustomOptions = customOptions
            };

            // Try to find out if requester is logged in add the username if available
            // Simetimes we want to check if user is banned
            var userPeerExtension = peer.GetExtension<IUserPeerExtension>();
            if (userPeerExtension != null && !string.IsNullOrEmpty(userPeerExtension.Username))
            {
                provideRoomAccessCheckPacket.Username = userPeerExtension.Username;
            }

            // Add requester peer id to pending list to prevent new access request to this room
            requestsInProgress.Add(peer.Id);

            // Send request to owner of the room to get access token
            Peer.SendMessage((short)MstMessageCodes.ProvideRoomAccessCheck, provideRoomAccessCheckPacket, (status, response) =>
            {
                // Remove requester peer id from pending list
                requestsInProgress.Remove(peer.Id);

                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                // Parse access data from message
                var accessData = response.Deserialize(new RoomAccessPacket());

                // Create new access info
                var access = new RoomAccessData()
                {
                    Access = accessData,
                    Peer = peer,
                    Timeout = DateTime.Now.AddSeconds(Options.AccessTimeoutPeriod)
                };

                // Save the access info to list and wait for confirmation
                unconfirmedAccesses[access.Access.Token] = access;

                callback.Invoke(access.Access, null);
            });
        }
コード例 #22
0
        public bool HasGetPeerInfoPermissions(IPeer peer)
        {
            var extension = peer.GetExtension <PeerSecurityExtension>();

            return(extension.PermissionLevel >= GetPeerDataPermissionsLevel);
        }