예제 #1
0
        public async Task CreateRoom(CreateRoomChatView model, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                throw new Exception("User is not found");
            }

            Room room = new Room
            {
                Name = model.Name,
            };

            if (model.Photo != null)
            {
                room.Photo = _imageProvider.ResizeAndSave(model.Photo, Constants.FilePaths.RoomAvatarImages, $"{room.Id}.png", Constants.DefaultIconSizes.MaxWidthOriginalImage, Constants.DefaultIconSizes.MaxHeightOriginalImage);
            }

            user.CurrentRoomId = room.Id;

            UserInRoom userInRoom = new UserInRoom()
            {
                RoomId = room.Id,
                UserId = userId
            };

            await _roomRepository.Create(room);

            await _userInRoomRepository.Create(userInRoom);

            await _userManager.UpdateAsync(user);
        }
예제 #2
0
        void UsersSwitched(User user1, User user2)
        {
            if (!Dispatcher.UIThread.CheckAccess())
            {
                Dispatcher.UIThread.InvokeAsync(() => UsersSwitched(user1, user2));
                return;
            }

            UserInRoom entry1 = Users.FirstOrDefault(i => i.Text == user1.Name);
            UserInRoom entry2 = Users.FirstOrDefault(i => i.Text == user2.Name);

            if (entry1 != null && entry2 != null)
            {
                string temptext   = entry1.Text;
                bool   tempweight = entry1.Weight;

                entry1.Text        = entry2.Text;
                entry1.Ready.State = false;
                if (user1 == App.User)
                {
                    ReadyButton.State = false;
                }
                entry1.Weight = entry2.Weight;

                entry2.Text        = temptext;
                entry2.Ready.State = false;
                if (user2 == App.User)
                {
                    ReadyButton.State = false;
                }
                entry2.Weight = tempweight;

                UpdateRoomAdmin();
            }
        }
예제 #3
0
        void UserLeft(User user)
        {
            if (!Dispatcher.UIThread.CheckAccess())
            {
                Dispatcher.UIThread.InvokeAsync(() => UserLeft(user));
                return;
            }

            UserInRoom entry = Users.FirstOrDefault(i => i.Text == user.Name);

            if (entry != null)
            {
                for (int i = Users.IndexOf(entry); i < 3; i++)
                {
                    Users[i].Text        = Users[i + 1].Text;
                    Users[i].Ready.State = Users[i + 1].Ready.State;
                    Users[i].Weight      = Users[i + 1].Weight;
                }

                Users[3].Text        = "";
                Users[3].Ready.State = null;
                Users[3].Weight      = false;

                Separator.Opacity = Convert.ToDouble(--Count > 2);
                UpdateRoomAdmin();
            }
        }
예제 #4
0
        public async Task AddToGroup(string groupName)
        {
            var Claim    = Context.User.Identities.FirstOrDefault();
            var userName = Claim.Claims.Where(e => e.Type == "user_name").Select(e => e.Value).FirstOrDefault();
            int userId   = Convert.ToInt32(Claim.Claims.Where(e => e.Type == "user_id").Select(e => e.Value).FirstOrDefault());

            // Retrieve Room.
            var Room = _context.Rooms.Where(s => s.RoomName == groupName).FirstOrDefault();

            if (Room == null)
            {
                Room = new ConversationRoom
                {
                    RoomName = groupName
                };
                _context.Rooms.Add(Room);
                _context.SaveChanges();
            }
            var UserRoom = _context.RoomUsers.Where(s => s.room_id == Room.id && s.user_id == userId).FirstOrDefault();

            if (UserRoom == null)
            {
                UserRoom = new UserInRoom
                {
                    user_id          = userId,
                    room_id          = Room.id,
                    GroupConnections = new List <GroupConnection>()
                };
                _context.RoomUsers.Add(UserRoom);
                _context.SaveChanges();
            }
            else
            {
                UserRoom.GroupConnections = new List <GroupConnection>();
            }
            UserRoom.GroupConnections.Add(new GroupConnection
            {
                ConnectionID = Context.ConnectionId,
                UserAgent    = "User-Agent",
                Connected    = true
            });
            _context.SaveChanges();


            // Add to each assigned group.
            var user = _context.RoomUsers
                       .Include(u => u.GroupConnections)
                       .Where(u => u.room_id == Room.id).ToList();

            await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

            await Clients.Group(groupName).SendAsync("Send", $"{userName} has joined the group {groupName}.");
        }
예제 #5
0
        void UserJoined(User user)
        {
            if (!Dispatcher.UIThread.CheckAccess())
            {
                Dispatcher.UIThread.InvokeAsync(() => UserJoined(user));
                return;
            }

            UserInRoom entry = Users.FirstOrDefault(i => i.Text == " ");

            if (entry != null)
            {
                entry.Text        = user.Name;
                entry.Ready.State = user.Ready;

                Separator.Opacity = Convert.ToDouble(++Count > 2);
                UpdateRoomAdmin();
            }
        }
예제 #6
0
        void UserReady(User user)
        {
            if (!Dispatcher.UIThread.CheckAccess())
            {
                Dispatcher.UIThread.InvokeAsync(() => UserReady(user));
                return;
            }

            UserInRoom entry = Users.FirstOrDefault(i => i.Text == user.Name);

            if (entry != null)
            {
                entry.Ready.State = user.Ready;

                if (user == App.User)
                {
                    ReadyButton.State = user.Ready;
                }

                UpdateRoomAdmin();
            }
        }
예제 #7
0
        public bool JoinUserToRoom(IUser User)
        {
            UserInRoom.Add(User);

            return(true);
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room CurrentRoom, string[] Params)
        {
            RoomUser User = CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);

            if (User == null)
            {
                return;
            }



            if (Params.Length == 1 || Params[1].Length < 2)
            {
                Session.SendWhisper("Por favor escreva o valor da venda [Ex. 145000c OR 75000d]", 3);
                return;
            }

            string ActualInput = Params[1];

            if (CurrentRoom.RoomData.OwnerId != User.HabboId)
            {
                Session.SendWhisper("Você precisa ser o dono do quarto!", 3);
                return;
            }
            string roomCostType = ActualInput.Substring(ActualInput.Length - 1);
            int    roomCost;

            try
            {
                roomCost = int.Parse(ActualInput.Substring(0, ActualInput.Length - 1));
            }
            catch
            {
                User.GetClient().SendWhisper("Você precisa escrever um preço válido para o quarto", 3);
                return;
            }

            if (roomCost == 0)
            {
                CurrentRoom.RoomData.roomForSale  = false;
                CurrentRoom.RoomData.roomSaleCost = 0;
                CurrentRoom.RoomData.roomSaleType = "";
                Session.SendWhisper("Se o quarto for vendido, o quarto ficará indi´ponível", 3);
                User.RoomOfferPending = false;
                User.RoomOffer        = "";
                return;
            }

            if (roomCost < 1 || roomCost > 10000000)
            {
                User.GetClient().SendWhisper("Preço do quarto inválido, Ele é muito baixo ou muito alto", 3);
                return;
            }

            if (ActualInput.EndsWith("c") || ActualInput.EndsWith("d"))
            {
                CurrentRoom.RoomData.roomForSale  = true;
                CurrentRoom.RoomData.roomSaleCost = roomCost;
                CurrentRoom.RoomData.roomSaleType = roomCostType;
            }
            else
            {
                Session.SendWhisper("Preço inválido [Ex. 600c OR 400d]", 3);
                return;
            }

            foreach (RoomUser UserInRoom in CurrentRoom.GetRoomUserManager().GetRoomUsers().ToList())
            {
                if (UserInRoom != null)
                {
                    UserInRoom.GetClient().SendWhisper("Este quarto está a venda por " + roomCost + roomCostType + " diga :comprarquarto " + roomCost + roomCostType + " para aquiri-lo.", 5);
                }
            }
        }