예제 #1
0
        private NFriendInfo GetFriendInfo(TFriend tfriend)
        {

            Character friend;
            NFriendInfo nFriendInfo = new NFriendInfo();
            nFriendInfo.Id = tfriend.Id;
            if (!CharacterManager.Instance.GetCharacter(tfriend.FriendID, out friend))
            { //好友不在线
                nFriendInfo.friendInfo = new NMessageCharInfo()
                {
                    Id = tfriend.FriendID,
                    Name = tfriend.FriendName,
                    Level = tfriend.FriendLevel,
                    Class = tfriend.FriendClass,

                };
                nFriendInfo.Status = 0;
            }
            else
            {//好友在线
                nFriendInfo.friendInfo = new NMessageCharInfo()
                {
                    Id = friend.Id,
                    Name = friend.Data.Name,
                    Level = friend.Data.Level,
                    Class = friend.Data.Class,
                };
                nFriendInfo.Status = 1;
                friend.friendManager.UpdateFriendInfo(Owner.Info, 1);
            }
            return nFriendInfo;
        }
예제 #2
0
        internal static void AddFriend(int id1, int id2, NMessageCharInfo info1, NMessageCharInfo info2)
        {

            TFriend friend1 = DBService.Instance.Entities.Friends.Where(x => x.FriendID == id2 && x.TCharacterID == id1).FirstOrDefault();
            if (friend1 == null)
            {
                friend1 = GetTFriend(id1, info2);
                DBService.Instance.Entities.Friends.Add(friend1);
            }
            else
            {
                friend1.IsDelete = false;
            }
            TFriend friend2 = DBService.Instance.Entities.Friends.Where(x => x.FriendID == id1 && x.TCharacterID == id2).FirstOrDefault();
            if (friend2 == null)
            {
                friend2 = GetTFriend(id2, info1);
                DBService.Instance.Entities.Friends.Add(friend2);
            }
            else
            {
                friend2.IsDelete = false;
            }


        }
예제 #3
0
        public async Task <GenericResponse <BooleanResponse> > AddFriend(long userId, string friendUsername)
        {
            try
            {
                TUser dbFriend = _databaseContext.TUser.FirstOrDefault(u => u.Username == friendUsername);
                if (dbFriend == null)
                {
                    return(new GenericResponse <BooleanResponse>($"Username {friendUsername} not found", null));
                }

                TFriend friend = new TFriend
                {
                    UserId   = userId,
                    FriendId = dbFriend.Id
                };
                _databaseContext.TFriend.Add(friend);
                await _databaseContext.SaveChangesAsync();

                return(new GenericResponse <BooleanResponse>(new BooleanResponse {
                    Success = true
                }));
            }
            catch (DbUpdateException e)
            {
                return(new GenericResponse <BooleanResponse>($"Error while adding friend", e));
            }
        }
예제 #4
0
 public static TFriend GetTFriend(int ownerID, NMessageCharInfo friendInfo)
 {
     TFriend friend = new TFriend()
     {
         FriendID = friendInfo.Id,
         TCharacterID = ownerID,
         FriendClass = friendInfo.Class,
         FriendLevel = friendInfo.Level,
         FriendName = friendInfo.Name,
     };
     return friend;
 }
예제 #5
0
 internal static Result RemoveFriend(int id, int friendId)
 {
     try
     {
         TFriend friendship1 = DBService.Instance.Entities.Friends.Where(x => x.TCharacterID == id && x.FriendID == friendId).First();
         friendship1.IsDelete = true;               
         TFriend friendship2 = DBService.Instance.Entities.Friends.Where(x => x.TCharacterID == friendId && x.FriendID == id).First();
         friendship2.IsDelete = true;
         return Result.Success;
     }
     catch (Exception e)
     {
         Log.Error(e);
         return Result.Failed;
     }
 }
예제 #6
0
        public async Task <GenericResponse <BooleanResponse> > DeleteFriend(long userId, string friendUsername)
        {
            try
            {
                TFriend dbFriend = _databaseContext.TFriend.FirstOrDefault(f => f.UserId == userId && f.Friend.Username == friendUsername);

                // Error case if not found
                if (dbFriend == null)
                {
                    return(new GenericResponse <BooleanResponse>($"{friendUsername} is not a friend", null));
                }

                _databaseContext.TFriend.Remove(dbFriend);
                await _databaseContext.SaveChangesAsync();

                return(new GenericResponse <BooleanResponse>(new BooleanResponse {
                    Success = true
                }));
            }
            catch (DbUpdateException e)
            {
                return(new GenericResponse <BooleanResponse>("Error while deleting friend", e));
            }
        }