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
        /// <summary>
        /// Unregisters a room from a server
        /// </summary>
        /// <param name="room"></param>
        public virtual void DestroyRoom(RegisteredRoom room)
        {
            var peer = room.Peer;

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

                // Remove the room from peer
                peerRooms?.Remove(room.RoomId);
            }

            // Remove the room from all rooms
            _rooms.Remove(room.RoomId);

            room.Destroy();

            // Invoke the event
            RoomDestroyed?.Invoke(room);
        }
Exemplo n.º 3
0
 public virtual Dictionary <string, string> GetPublicRoomProperties(IPeer player, RegisteredRoom room,
                                                                    Dictionary <string, string> playerFilters)
 {
     return(room.Options.Properties);
 }
Exemplo n.º 4
0
 public virtual void ChangeRoomOptions(RegisteredRoom room, RoomOptions options)
 {
     room.ChangeOptions(options);
 }