Esempio n. 1
0
        public PokerUser Join(PokerUser user)
        {
            _logger.Info("{0} joined PlanningLab", user.Email);

            var userRef = _users.Where(x => x.Value.Email == user.Email).Select(x => new {
                ConnectionId = x.Key,
                User = x.Value
            }).FirstOrDefault();

            if (userRef != null && userRef.ConnectionId != Context.ConnectionId)
                _users.Remove(userRef.ConnectionId);

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

            if (!_users.ContainsKey(Context.ConnectionId))
                _users.Add(Context.ConnectionId, user);

            return user;
        }
Esempio n. 2
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);
        }