public async Task <IActionResult> AcceptFriendInvite([FromBody] FriendResponse request)
        {
            try
            {
                Player player = (Player)HttpContext.Items["SessionPlayer"];

                FriendInvite friendRequest = new FriendInvite();
                friendRequest.playerId       = request.username;
                friendRequest.targetPlayerId = player.username;
                await _service.AcceptFriendInvite(friendRequest, request.response);

                return(Ok(new Success("Invite handled successfully.")));
            }
            catch (EntityNotFoundException e)
            {
                if (e is FriendRequestNotFound)
                {
                    return(BadRequest(new Error("FriendRequestNotFound", e.Message)));
                }
                return(NotFound(new Error("UserNotFound", "User Not Found.")));
            }
            catch (Exception exc)
            {
                this._logger.LogError(exc, exc.Message);
                return(StatusCode(500));
            }
        }
Exemple #2
0
        public async Task Delete(FriendInvite request)
        {
            var remove = await GetByUsernames(request.playerId, request.targetPlayerId);

            if (remove != null)
            {
                _context.FriendsRequests.Remove(remove);
            }
            await _context.SaveChangesAsync();
        }
Exemple #3
0
        public override void Process(IXFireClient context)
        {
            var recipient = context.Server.Database.QueryUser(Username);
            var invite    = new FriendInvite(context.User.Username, context.User.Nickname, Message);

            invite.Process(context);

            context.Server.Database.InsertFriendRequest(context.User, Username, Message);

            var recipientSession = context.Server.GetSession(recipient);

            recipientSession?.SendMessage(invite);
        }
    FriendInvite GetFreeFriend()
    {
        int index = currIndex;

        if (index >= friends.Count)
        {
            FriendInvite friend = Instantiate(FriendTemplate, Content.transform);
            friends.Add(friend);
        }

        currIndex++;
        return(friends[index]);
    }
        public void Create(DalInvite entity)
        {
            var invite = new FriendInvite()
            {
                Id       = entity.Id,
                Response = entity.Response
            };
            var profileFrom = Profiles.FirstOrDefault(p => p.Id == entity.IdFrom);
            var profileTo   = Profiles.FirstOrDefault(p => p.Id == entity.IdTo);

            invite.FromProfile = profileFrom;
            invite.ToProfile   = profileTo;
            Invites.Add(invite);
        }
Exemple #6
0
        public override async Task Process(IXFireClient context)
        {
            var recipient = await context.Server.Database.QueryUser(Username);

            var invite = new FriendInvite(context.User.Username, context.User.Nickname, Message);
            await invite.Process(context);

            await context.Server.Database.InsertFriendRequest(context.User, recipient, Message);

            var recipientSession = context.Server.GetSession(recipient);

            if (recipientSession != null)
            {
                await recipientSession.SendMessage(invite);
            }
        }
Exemple #7
0
        public void Process(Context context)
        {
            var recipient = context.Server.Database.QueryUser(Username);
            var invite    = new FriendInvite(context.User.Username, context.User.Nickname, Message);

            invite.Process(context);

            context.Server.Database.InsertFriendRequest(context.User, Username, Message);

            var recipientSession = context.Server.GetSession(recipient);

            if (recipientSession != null)
            {
                recipientSession.SendMessage(invite);
            }
        }
Exemple #8
0
        public async Task AcceptFriendInvite(FriendInvite sendRequest, bool accept)
        {
            Player player = await _playerRepository.GetByUsername(sendRequest.targetPlayerId);

            if (player == null)
            {
                throw new EntityNotFoundException();
            }
            FriendInvite request = await _requestsRepository.GetByUsernames(sendRequest.playerId, sendRequest.targetPlayerId);

            if (request == null)
            {
                throw new FriendRequestNotFound();
            }
            if (accept)
            {
                PlayerFriend friend = new PlayerFriend(sendRequest.playerId, sendRequest.targetPlayerId);
                await _friendListRepository.Create(friend);
            }
            await _requestsRepository.Delete(sendRequest);
        }
Exemple #9
0
        public async Task SendFriendInvite(string playerId, string targetPlayerId)
        {
            if (playerId == targetPlayerId)
            {
                throw new SendToYourselfException();
            }

            Player player = await _playerRepository.GetByUsername(targetPlayerId);

            if (player == null)
            {
                throw new EntityNotFoundException();
            }

            PlayerFriend foundFriend = new PlayerFriend(playerId, targetPlayerId);

            foundFriend = await _friendListRepository.GetByUsernames(foundFriend.playerId, foundFriend.friendId);

            if (foundFriend != null)
            {
                throw new AlreadyFriendsException();
            }
            FriendInvite foundSendRequest = await _requestsRepository.GetByUsernames(playerId, targetPlayerId);

            FriendInvite foundReceiveRequest = await _requestsRepository.GetByUsernames(targetPlayerId, playerId);

            if (foundSendRequest != null || foundReceiveRequest != null)
            {
                throw new AlreadyExistsFriendRequest();
            }

            FriendInvite createRequest = new FriendInvite();

            createRequest.playerId       = playerId;
            createRequest.targetPlayerId = targetPlayerId;
            await _requestsRepository.Create(createRequest);
        }
Exemple #10
0
 // Use this for initialization
 void Start()
 {
     g_instance = this;
 }
Exemple #11
0
 public async Task Create(FriendInvite request)
 {
     _context.FriendsRequests.Add(request);
     await _context.SaveChangesAsync();
 }