예제 #1
0
        public void Handle(Player player, Request request)
        {
            int friendsAccepted = request.ReadInt();
            var messenger       = player.Messenger;

            for (int i = 0; i < friendsAccepted; i++)
            {
                int userId = request.ReadInt();

                if (!messenger.HasRequest(userId))
                {
                    continue;
                }

                if (messenger.Friends.Count >= messenger.MaxFriendsAllowed)
                {
                    continue;
                }

                var playerData = PlayerManager.Instance.GetDataById(userId);

                if (playerData == null)
                {
                    continue;
                }

                var targetMessenger = Messenger.GetMessengerData(userId);
                var targetFriend    = new MessengerUser(playerData);

                targetMessenger.Friends.Add(messenger.MessengerUser);
                messenger.Friends.Add(targetFriend);

                targetMessenger.RemoveRequest(player.Details.Id);
                messenger.RemoveRequest(userId);

                var targetPlayer = PlayerManager.Instance.GetPlayerById(userId);

                if (targetPlayer != null)
                {
                    targetPlayer.Messenger.QueueUpdate(MessengerUpdateType.AddFriend, messenger.MessengerUser);
                    targetPlayer.Messenger.ForceUpdate();
                }

                MessengerDao.DeleteRequests(player.Details.Id, userId);
                MessengerDao.SaveFriend(new MessengerFriendData
                {
                    FriendId = userId,
                    UserId   = player.Details.Id
                });
                MessengerDao.SaveFriend(new MessengerFriendData
                {
                    UserId   = userId,
                    FriendId = player.Details.Id
                });

                messenger.QueueUpdate(MessengerUpdateType.AddFriend, targetFriend);
            }

            messenger.ForceUpdate();
        }
        public void Handle(Player player, Request request)
        {
            bool mode   = request.ReadBoolean();
            int  amount = request.ReadInt();

            if (!mode)
            {
                for (int i = 0; i < amount; i++)
                {
                    int userId = request.ReadInt();

                    if (!player.Messenger.HasRequest(userId))
                    {
                        continue;
                    }

                    MessengerDao.DeleteRequests(player.Details.Id, userId);
                    player.Messenger.RemoveRequest(userId);
                }
            }
            else
            {
                player.Messenger.Requests.Clear();
                MessengerDao.DeleteAllRequests(player.Details.Id);
            }
        }
예제 #3
0
        public void Handle(Player player, Request request)
        {
            int friendsToDelete = request.ReadInt();
            var messenger       = player.Messenger;

            for (int i = 0; i < friendsToDelete; i++)
            {
                int userId = request.ReadInt();

                if (!messenger.HasFriend(userId))
                {
                    continue;
                }

                if (messenger.Friends.Count >= messenger.MaxFriendsAllowed)
                {
                    continue;
                }

                var playerData = PlayerManager.Instance.GetDataById(userId);

                if (playerData == null)
                {
                    continue;
                }

                var targetMessenger = Messenger.GetMessengerData(userId);

                targetMessenger.RemoveFriend(player.Details.Id);
                messenger.RemoveFriend(userId);

                var targetPlayer = PlayerManager.Instance.GetPlayerById(userId);

                if (targetPlayer != null)
                {
                    targetPlayer.Messenger.QueueUpdate(MessengerUpdateType.RemoveFriend, messenger.MessengerUser);
                    targetPlayer.Messenger.ForceUpdate();
                }

                MessengerDao.DeleteRequests(player.Details.Id, userId);
                MessengerDao.DeleteFriends(player.Details.Id, userId);

                messenger.QueueUpdate(MessengerUpdateType.RemoveFriend, Messenger.Wrap(playerData));
            }

            messenger.ForceUpdate();
        }