예제 #1
0
        /// <summary>
        /// Create a new room if one with the provided name does not already exist.
        /// </summary>
        /// <param name="sender">Session of the user trying to create a room.</param>
        /// <param name="name">Name of the room to create.</param>
        /// <returns></returns>
        public static UserOwnedRoom CreateRoom(Session sender, string name)
        {
            var record = new Room()
            {
                Name        = name,
                Description = "",
                OwnerUserID = sender.User.ID
            };
            var room = RoomList.ContainsKey(name.ToLower()) ? null : new UserOwnedRoom(record);

            if (room != null)
            {
                var id = Room.manager.Create(room.Data);
                room.Data = Room.manager.Get(id);
                RoomList.Add(room.Name.ToLower(), room);
            }
            return(room);
        }
예제 #2
0
        /// <summary>
        /// Move a user from their current room to a room with the provided name.
        /// </summary>
        /// <param name="session">Session to be moved</param>
        /// <param name="name">Name of the room to move to</param>
        public static void MoveTo(Session session, string name)
        {
            name = name.ToLower();
            if (!RoomList.ContainsKey(name))
            {
                throw new ArgumentException("Room with that name does not exist.");
            }
            var newRoom = RoomList[name];
            var oldRoom = Instance.GetRoomContainingSession(session);

            oldRoom?.Leave(session);
            newRoom.Join(session);
            if (SessionLocations.ContainsKey(session.ID))
            {
                SessionLocations[session.ID] = newRoom.Name.ToLower();
            }
            else
            {
                SessionLocations.Add(session.ID, newRoom.Name.ToLower());
            }
        }