Ejemplo n.º 1
0
        /// <summary>
        /// Ignores a friend request between the specified
        /// id (the source) and the logged in user (the destination)
        /// </summary>
        /// <param name="id">The id of the source of the friend request</param>
        /// <returns>True if successful, false otherwise</returns>
        public Boolean IgnoreFriendRequest(int id)
        {
            // Find the pending request
            friend_pending pending = (from f in _dbContext.friend_pending
                                      where f.source_id == id && f.destination_id == WebSecurity.CurrentUserId
                                      select f).FirstOrDefault();

            if (pending == null)
            {
                return(false);
            }

            // Ignore pending request
            pending.ignored = true;

            LoggerModel logFriendRequest = new LoggerModel()
            {
                Action    = Logger.PlayerFriendLogType.IgnoreRequest.ToString(),
                UserID    = WebSecurity.CurrentUserId,
                IPAddress = HttpContext.Current.Request.UserHostAddress,
                TimeStamp = DateTime.Now,
                ID1       = id,
                IDType1   = Logger.LogIDType.User.ToString()
            };

            Logger.LogSingleEntry(logFriendRequest, _dbContext);

            _dbContext.SaveChanges();
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Accepts a friend request between the specified
        /// id (the source) and the logged in user (the destination)
        /// </summary>
        /// <param name="id">The id of the source of the friend request</param>
        /// <returns>True if successful, false otherwise</returns>
        public Boolean AcceptFriendRequest(int id)
        {
            // Ssame user?
            if (id == WebSecurity.CurrentUserId)
            {
                return(false);
            }

            // Find the pending request
            friend_pending pending = (from f in _dbContext.friend_pending
                                      where f.source_id == id && f.destination_id == WebSecurity.CurrentUserId
                                      select f).FirstOrDefault();

            if (pending == null)
            {
                return(false);
            }

            // Remove pending, then add friendships in both directions
            _dbContext.friend_pending.Remove(pending);

            friend f1 = new friend()
            {
                source_id      = id,
                destination_id = WebSecurity.CurrentUserId,
                request_date   = pending.request_date,
                friended_date  = DateTime.Now
            };

            friend f2 = new friend()
            {
                source_id      = WebSecurity.CurrentUserId,
                destination_id = id,
                request_date   = pending.request_date,
                friended_date  = f1.friended_date
            };

            _dbContext.friend.Add(f1);
            _dbContext.friend.Add(f2);

            _unitOfWork.AchievementRepository.CheckFriendSystemAchievements(WebSecurity.CurrentUserId);
            _unitOfWork.AchievementRepository.CheckFriendSystemAchievements(f1.source_id);
            LoggerModel logFriendRequest = new LoggerModel()
            {
                Action    = Logger.PlayerFriendLogType.AcceptRequest.ToString(),
                UserID    = WebSecurity.CurrentUserId,
                IPAddress = HttpContext.Current.Request.UserHostAddress,
                TimeStamp = DateTime.Now,
                ID1       = id,
                IDType1   = Logger.LogIDType.User.ToString()
            };

            Logger.LogSingleEntry(logFriendRequest, _dbContext);
            _dbContext.SaveChanges();
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to add a friend (sends a request)
        /// </summary>
        /// <param name="id">The id of the user to add as a friend</param>
        /// <returns>True if successful, false otherwise</returns>
        public Boolean AddFriend(int id)
        {
            // Can't be us!
            if (id == WebSecurity.CurrentUserId)
            {
                return(false);
            }

            // Get the user and make sure they're playing
            user u = GetUser(id);

            if (u == null || !u.is_player || u.status != (int)JPPConstants.UserStatus.Active)
            {
                return(false);
            }

            // Are we already friends?
            bool alreadyFriends = (from f in _dbContext.friend
                                   where ((f.source_id == id && f.destination_id == WebSecurity.CurrentUserId) ||
                                          (f.source_id == WebSecurity.CurrentUserId && f.destination_id == id))
                                   select f).Any();

            if (alreadyFriends)
            {
                return(false);
            }

            // Pending friend invite?
            bool alreadyPending = (from f in _dbContext.friend_pending
                                   where ((f.source_id == id && f.destination_id == WebSecurity.CurrentUserId) ||
                                          (f.source_id == WebSecurity.CurrentUserId && f.destination_id == id))
                                   select f).Any();

            if (alreadyPending)
            {
                return(false);
            }

            // Create the new pending request
            friend_pending friend = new friend_pending()
            {
                source_id      = WebSecurity.CurrentUserId,
                destination_id = u.id,
                ignored        = false,
                request_date   = DateTime.Now
            };

            _dbContext.friend_pending.Add(friend);
            LoggerModel logFriendRequest = new LoggerModel()
            {
                Action    = Logger.PlayerFriendLogType.AddFriend.ToString(),
                UserID    = WebSecurity.CurrentUserId,
                IPAddress = HttpContext.Current.Request.UserHostAddress,
                TimeStamp = DateTime.Now,
                ID1       = id,
                IDType1   = Logger.LogIDType.User.ToString()
            };

            Logger.LogSingleEntry(logFriendRequest, _dbContext);

            Save();
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to add a friend (sends a request)
        /// </summary>
        /// <param name="id">The id of the user to add as a friend</param>
        /// <returns>True if successful, false otherwise</returns>
        public Boolean AddFriend(int id)
        {
            // Can't be us!
            if (id == WebSecurity.CurrentUserId)
                return false;

            // Get the user and make sure they're playing
            user u = GetUser(id);
            if (u == null || !u.is_player || u.status != (int)JPPConstants.UserStatus.Active)
                return false;

            // Are we already friends?
            bool alreadyFriends = (from f in _dbContext.friend
                                   where ((f.source_id == id && f.destination_id == WebSecurity.CurrentUserId) ||
                                           (f.source_id == WebSecurity.CurrentUserId && f.destination_id == id))
                                   select f).Any();
            if (alreadyFriends)
                return false;

            // Pending friend invite?
            bool alreadyPending = (from f in _dbContext.friend_pending
                                   where ((f.source_id == id && f.destination_id == WebSecurity.CurrentUserId) ||
                                           (f.source_id == WebSecurity.CurrentUserId && f.destination_id == id))
                                   select f).Any();
            if (alreadyPending)
                return false;

            // Create the new pending request
            friend_pending friend = new friend_pending()
            {
                source_id = WebSecurity.CurrentUserId,
                destination_id = u.id,
                ignored = false,
                request_date = DateTime.Now
            };
            _dbContext.friend_pending.Add(friend);
            LoggerModel logFriendRequest = new LoggerModel()
            {
                Action = Logger.PlayerFriendLogType.AddFriend.ToString(),
                UserID = WebSecurity.CurrentUserId,
                IPAddress = HttpContext.Current.Request.UserHostAddress,
                TimeStamp = DateTime.Now,
                ID1 = id,
                IDType1 = Logger.LogIDType.User.ToString()
            };
            Logger.LogSingleEntry(logFriendRequest, _dbContext);

            Save();
            return true;
        }