Exemplo n.º 1
0
        /// <summary>
        /// Registers a room to the server
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public virtual RegisteredRoom RegisterRoom(IPeer peer, RoomOptions options)
        {
            // Create the object
            var room = new RegisteredRoom(GenerateRoomId(), peer, options);

            var peerRooms = peer.GetProperty((int)PeerPropertyKeys.RegisteredRooms) as Dictionary <int, RegisteredRoom>;

            if (peerRooms == null)
            {
                // If this is the first time creating a room

                // Save the dictionary
                peerRooms = new Dictionary <int, RegisteredRoom>();
                peer.SetProperty((int)PeerPropertyKeys.RegisteredRooms, peerRooms);

                // Listen to disconnect event
                peer.Disconnected += OnRegisteredPeerDisconnect;
            }

            // Add a new room to peer
            peerRooms[room.RoomId] = room;

            // Add the room to a list of all rooms
            _rooms[room.RoomId] = room;

            // Invoke the event
            RoomRegistered?.Invoke(room);

            return(room);
        }
Exemplo n.º 2
0
        public virtual RegisteredSpawner CreateSpawner(IPeer peer, SpawnerOptions options)
        {
            var spawner = new RegisteredSpawner(GenerateSpawnerId(), peer, options);

            var peerSpawners =
                peer.GetProperty((int)MsfPropCodes.RegisteredSpawners) as Dictionary <string, RegisteredSpawner>;

            if (peerSpawners == null)
            {
                // If this is the first time registering a spawners

                // Save the dictionary
                peerSpawners = new Dictionary <string, RegisteredSpawner>();
                peer.SetProperty((int)MsfPropCodes.RegisteredSpawners, peerSpawners);

                peer.Disconnected += OnRegisteredPeerDisconnect;
            }

            // Add a new spawner
            peerSpawners[spawner.SpawnerId] = spawner;

            // Add the spawner to a list of all spawners
            Spawners[spawner.SpawnerId] = spawner;

            // Invoke the event
            if (SpawnerRegistered != null)
            {
                SpawnerRegistered.Invoke(spawner);
            }

            return(spawner);
        }
Exemplo n.º 3
0
        public virtual RegisteredSpawner CreateSpawner(IPeer peer, SpawnerOptions options)
        {
            var spawner = new RegisteredSpawner(GenerateSpawnerId(), peer, options);

            if (!(peer.GetProperty((int)PeerPropertyKeys.RegisteredSpawners) is Dictionary <int, RegisteredSpawner> peerSpawners))
            {
                // If this is the first time registering a spawners

                // Save the dictionary
                peerSpawners = new Dictionary <int, RegisteredSpawner>();
                peer.SetProperty((int)PeerPropertyKeys.RegisteredSpawners, peerSpawners);

                peer.Disconnected += OnRegisteredPeerDisconnect;
            }

            // Add a new spawner
            peerSpawners[spawner.SpawnerId] = spawner;

            // Add the spawner to a list of all spawners
            Spawners[spawner.SpawnerId] = spawner;

            // Invoke the event
            SpawnerRegistered?.Invoke(spawner);

            return(spawner);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Registers a room to the server
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public virtual RegisteredRoom RegisterRoom(IPeer peer, RoomOptions options)
        {
            var room = new RegisteredRoom(NextRoomId, peer, options);
            Dictionary <int, RegisteredRoom> peerRooms = peer.GetProperty((int)MstPeerPropertyCodes.RegisteredRooms) as Dictionary <int, RegisteredRoom>;

            if (peerRooms == null)
            {
                // If this is the first time creating a room

                // Save the dictionary
                peerRooms = new Dictionary <int, RegisteredRoom>();
                peer.SetProperty((int)MstPeerPropertyCodes.RegisteredRooms, peerRooms);

                // Listen to disconnect event
                peer.OnPeerDisconnectedEvent += OnRegisteredPeerDisconnect;
            }

            // Add a new room to peer
            peerRooms[room.RoomId] = room;

            // Add the room to a list of all rooms
            roomsList[room.RoomId] = room;

            // Invoke the event
            OnRoomRegisteredEvent?.Invoke(room);

            return(room);
        }
Exemplo n.º 5
0
        public virtual RegisteredSpawner CreateSpawner(IPeer peer, SpawnerOptions options)
        {
            var spawner = new RegisteredSpawner(GenerateSpawnerId(), peer, options);

            Dictionary <int, RegisteredSpawner> peerSpawners = peer.GetProperty((int)MstPeerPropertyCodes.RegisteredSpawners) as Dictionary <int, RegisteredSpawner>;

            // If this is the first time registering a spawners
            if (peerSpawners == null)
            {
                // Save the dictionary
                peerSpawners = new Dictionary <int, RegisteredSpawner>();
                peer.SetProperty((int)MstPeerPropertyCodes.RegisteredSpawners, peerSpawners);

                peer.OnPeerDisconnectedEvent += OnRegisteredPeerDisconnect;
            }

            // Add a new spawner
            peerSpawners[spawner.SpawnerId] = spawner;

            // Add the spawner to a list of all spawners
            spawnersList[spawner.SpawnerId] = spawner;

            // Invoke the event
            if (OnSpawnerRegisteredEvent != null)
            {
                OnSpawnerRegisteredEvent.Invoke(spawner);
            }

            return(spawner);
        }
Exemplo n.º 6
0
        private void OnRegisteredPeerDisconnect(IPeer peer)
        {
            if (!(peer.GetProperty((int)PeerPropertyKeys.RegisteredSpawners) is Dictionary <int, RegisteredSpawner> peerSpawners))
            {
                return;
            }

            // Create a copy so that we can iterate safely
            var registeredSpawners = peerSpawners.Values.ToList();

            foreach (var registeredSpawner in registeredSpawners)
            {
                DestroySpawner(registeredSpawner);
            }
        }
Exemplo n.º 7
0
        private void OnRegisteredPeerDisconnect(IPeer peer)
        {
            var peerRooms = peer.GetProperty((int)PeerPropertyKeys.RegisteredRooms) as Dictionary <int, RegisteredRoom>;

            if (peerRooms == null)
            {
                return;
            }

            // Create a copy so that we can iterate safely
            var registeredRooms = peerRooms.Values.ToList();

            foreach (var registeredRoom in registeredRooms)
            {
                DestroyRoom(registeredRoom);
            }
        }
Exemplo n.º 8
0
        private void OnRegisteredPeerDisconnect(IPeer peer)
        {
            var peerSpawners = peer.GetProperty((int)MsfPropCodes.RegisteredSpawners) as Dictionary <string, RegisteredSpawner>;

            if (peerSpawners == null)
            {
                return;
            }

            // Create a copy so that we can iterate safely
            var registeredSpawners = peerSpawners.Values.ToList();

            foreach (var registeredSpawner in registeredSpawners)
            {
                DestroySpawner(registeredSpawner);
            }
        }
        /// <summary>
        /// Fired when registered room peer disconnected from master
        /// </summary>
        /// <param name="peer"></param>
        private void OnRegisteredPeerDisconnect(IPeer peer)
        {
            Dictionary <int, RegisteredRoom> peerRooms = peer.GetProperty((int)MsfPropCodes.RegisteredRooms) as Dictionary <int, RegisteredRoom>;

            if (peerRooms == null)
            {
                return;
            }

            logger.Debug($"Client {peer.Id} was disconnected from server and it has registered rooms that also must be destroyed");

            // Create a copy so that we can iterate safely
            var registeredRooms = peerRooms.Values.ToList();

            foreach (var registeredRoom in registeredRooms)
            {
                DestroyRoom(registeredRoom);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Invokes when peer disconnected from server
        /// </summary>
        /// <param name="peer"></param>
        private void OnRegisteredPeerDisconnect(IPeer peer)
        {
            // Get registered spawners from peer property
            var peerSpawners = peer.GetProperty((int)MstPeerPropertyCodes.RegisteredSpawners) as Dictionary <int, RegisteredSpawner>;

            // Return if now spawner found
            if (peerSpawners == null)
            {
                return;
            }

            // Create a copy so that we can iterate safely
            var registeredSpawners = peerSpawners.Values.ToList();

            // Destroy all spawners
            foreach (var registeredSpawner in registeredSpawners)
            {
                DestroySpawner(registeredSpawner);
            }
        }