Exemplo n.º 1
0
        public PokerRoom JoinRoom(PokerRoom room)
        {
            var user = _users.Where(x => x.Key == Context.ConnectionId).Select(x => x.Value).FirstOrDefault();

            if (user == null)
                throw new Exception("No user with this connection Id has joined yet.");

            _logger.Info("{0} joined {1} room", user.Email, room.Name);

            room = _rooms.FirstOrDefault(x => x.Name == room.Name) ?? room;

            if (!_rooms.Contains(room))
            {
                room.owner = user.Name;
                _rooms.Add(room);
            }
            else
            {
                room.owner = "";
            }

            if (room.Users.All(x => x.Email != user.Email))
            {
                room.Users.Add(user);
            }

            // tell the people in this room that you've joined
            Clients.Group(room.Name).userChanged(user);

            Groups.Add(Context.ConnectionId, room.Name);

            return room;
        }
Exemplo n.º 2
0
        public PokerRoom JoinRoom(PokerRoom room)
        {
            var user = _users.Where(x => x.Key == Context.ConnectionId).Select(x => x.Value).FirstOrDefault();

            if (user == null)
            {
                throw new Exception("No user with this connection Id has joined yet.");
            }

            _logger.Info("{0} joined {1} room", user.Email, room.Name);

            room = _rooms.FirstOrDefault(x => x.Name == room.Name) ?? room;

            if (!_rooms.Contains(room))
            {
                _rooms.Add(room);
            }

            if (room.Users.All(x => x.Email != user.Email))
            {
                room.Users.Add(user);
            }

            // tell the people in this room that you've joined
            Clients.Group(room.Name).userChanged(user);

            Groups.Add(Context.ConnectionId, room.Name);

            return(room);
        }
Exemplo n.º 3
0
        public void ShowAllCards(PokerRoom room, bool show)
        {
            AssertContextUserJoinedRoom(room.Name);

            // tell the people in this room that the topic has changed
            Clients.Group(room.Name).showAllCards(show);
        }
Exemplo n.º 4
0
        public void ChangedCard(PokerRoom room, string cardValue)
        {
            AssertContextUserJoinedRoom(room.Name);

            var user = _users.Where(x => x.Key == Context.ConnectionId).Select(x => x.Value).FirstOrDefault();

            room = _rooms.FirstOrDefault(x => x.Name == room.Name);

            var card = room.Cards.FirstOrDefault(x => x.User.Email == user.Email);

            if (card == null)
            {
                card = new PokerCard
                {
                    User  = user,
                    Value = cardValue
                };
                room.Cards.Add(card);
            }

            card.Value = cardValue;

            // tell the people in this room that your card has changed
            Clients.Group(room.Name).cardChanged(card);
        }
Exemplo n.º 5
0
        public void ChangeRoomTopic(PokerRoom room, string topic)
        {
            AssertContextUserJoinedRoom(room.Name);

            room       = _rooms.FirstOrDefault(x => x.Name == room.Name);
            room.Topic = topic;

            // tell the people in this room that the topic has changed
            Clients.Group(room.Name).roomTopicChanged(topic);
        }
Exemplo n.º 6
0
        public void ChangeRoomTopic(PokerRoom room, string topic)
        {
            AssertContextUserJoinedRoom(room.Name);

            room = _rooms.FirstOrDefault(x => x.Name == room.Name);
            room.Topic = topic;

            // tell the people in this room that the topic has changed
            Clients.Group(room.Name).roomTopicChanged(topic);
        }
Exemplo n.º 7
0
        public void ResetRoom(PokerRoom room)
        {
            AssertContextUserJoinedRoom(room.Name);

            room       = _rooms.FirstOrDefault(x => x.Name == room.Name);
            room.Topic = "";
            room.Cards = new List <PokerCard>();

            // tell the people in this room that the topic has changed
            Clients.Group(room.Name).resetRoom(room);
        }
Exemplo n.º 8
0
        public void LeaveRoom(PokerRoom room, PokerUser user)
        {
            AssertContextUserJoinedRoom(room.Name);
            room = _rooms.FirstOrDefault(x => x.Name == room.Name);

            if (room.Users.All(x => x.Email != user.Email))
            {
                throw new Exception("User being removed hasn't joined this room yet.");
            }

            room.Users = room.Users.Where(x => x.Email != user.Email).ToList();
            room.Cards = room.Cards.Where(x => x.User.Email != user.Email).ToList();

            // tell the people in this room that user has been removed
            Clients.Group(room.Name).userRemoved(user);
        }
Exemplo n.º 9
0
        //================================================================================================================
        //================================================================================================================
        #endregion  // API Demos

        #region Poker Room
        //================================================================================================================
        //================================================================================================================

        public ActionResult PokerRoom()
        //================================================================================================================
        // This action is invoked when the poker room page is requested.
        //
        // Returns
        //      The home page view
        //================================================================================================================
        {
            // Safety check for the server
            if ((bool)Session[SiteHelpers.ServerRunning] == false)
            {
                return(View("ServerNotRunning", new PokerPlayground()));
            }

            PokerRoom model = new PokerRoom();

            return(View("PokerRoom", model));
        }
Exemplo n.º 10
0
        public IActionResult RoomCreate(CreateModel Created)
        {
            // Creation of ScrumPoker room
            if (ModelState.IsValid)
            {
                int _nullablepassword;
                using (var _context = new PokerPlanningContext())
                {
                    _nullablepassword = PasswordEncrypt.GetPassword(Created.Password);

                    var NewRoom = new PokerRoom()
                    {
                        Title       = Created.RoomTitle,
                        Description = "",
                        Password    = _nullablepassword,
                        CreateDate  = DateTime.Now,
                        CloseDate   = null,
                        TypeCards   = Created.CardsType
                    };

                    _context.PokerRooms.Add(NewRoom);
                    _context.SaveChanges();

                    var NewPlayer = new Player()
                    {
                        Name        = Created.Name,
                        Role        = 2,
                        PokerRoomId = NewRoom.Id,
                        IsOnline    = false
                    };

                    _context.Players.Add(NewPlayer);
                    _context.SaveChanges();
                    return(RedirectToAction("RoomEntrance", "ScrumRoom", new { PokerRoomId = NewRoom.Id, PlayerId = NewPlayer.Id, password = _nullablepassword })); //переход в комнату
                }
            }
            else
            {
                return(View(Created));
            }
        }
Exemplo n.º 11
0
        public void ChangedCard(PokerRoom room, string cardValue)
        {
            AssertContextUserJoinedRoom(room.Name);

            var user = _users.Where(x => x.Key == Context.ConnectionId).Select(x => x.Value).FirstOrDefault();
            room = _rooms.FirstOrDefault(x => x.Name == room.Name);

            var card = room.Cards.FirstOrDefault(x => x.User.Email == user.Email);

            if (card == null)
            {
                card = new PokerCard
                {
                    User = user,
                    Value = cardValue
                };
                room.Cards.Add(card);
            }

            card.Value = cardValue;

            // tell the people in this room that your card has changed
            Clients.Group(room.Name).cardChanged(card);
        }
Exemplo n.º 12
0
        public void ShowAllCards(PokerRoom room, bool show)
        {
            AssertContextUserJoinedRoom(room.Name);

            // tell the people in this room that the topic has changed
            Clients.Group(room.Name).showAllCards(show);
        }
Exemplo n.º 13
0
        //public void PingUsers(PokerRoom room)
        //{
        //    if (room == null)
        //        return;
        //    AssertContextUserJoinedRoom(room.Name);
        //    room = _rooms.FirstOrDefault(x => x.Name == room.Name);
        //    if (room.Users.All(x => x.Email != user.Email))
        //        throw new Exception("User being removed hasn't joined this room yet.");
        //    room.Users = room.Users.Where(x => x.Email != user.Email).ToList();
        //    room.Cards = room.Cards.Where(x => x.User.Email != user.Email).ToList();
        //    // tell the people in this room that user has been removed
        //    Clients.Group(room.Name).userRemoved(user);
        //}
        public void ResetRoom(PokerRoom room)
        {
            AssertContextUserJoinedRoom(room.Name);

            room = _rooms.FirstOrDefault(x => x.Name == room.Name);
            room.Topic = "";
            room.Cards = new List<PokerCard>();

            // tell the people in this room that the topic has changed
            Clients.Group(room.Name).resetRoom(room);
        }
Exemplo n.º 14
0
        public void LeaveRoom(PokerRoom room, PokerUser user)
        {
            if (room == null)
                return;

            AssertContextUserJoinedRoom(room.Name);
            room = _rooms.FirstOrDefault(x => x.Name == room.Name);

            if (room.Users.All(x => x.Email != user.Email))
                throw new Exception("User being removed hasn't joined this room yet.");

            room.Users = room.Users.Where(x => x.Email != user.Email).ToList();
            room.Cards = room.Cards.Where(x => x.User.Email != user.Email).ToList();

            // tell the people in this room that user has been removed
            Clients.Group(room.Name).userRemoved(user);
        }