Ejemplo n.º 1
0
        public async UniTask <bool> SendMail(Mail mail)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            SendMailResp resp = await DbServiceClient.SendMailAsync(new SendMailReq()
            {
                Mail = DatabaseServiceUtils.ToByteString(mail),
            });

            if (resp.Error == 0)
            {
                return(true);
            }
#endif
            return(false);
        }
        public async UniTaskVoid HandleRequestSendMail(RequestHandlerData requestHandler, RequestSendMailMessage request, RequestProceedResultDelegate <ResponseSendMailMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            IPlayerCharacterData playerCharacter;
            if (GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter))
            {
                // Validate gold
                if (request.gold < 0)
                {
                    request.gold = 0;
                }
                if (playerCharacter.Gold >= request.gold)
                {
                    playerCharacter.Gold -= request.gold;
                }
                else
                {
                    result.Invoke(AckResponseCode.Error, new ResponseSendMailMessage()
                    {
                        message = UITextKeys.UI_ERROR_NOT_ENOUGH_GOLD,
                    });
                    return;
                }
                // Find receiver
                GetUserIdByCharacterNameResp userIdResp = await DbServiceClient.GetUserIdByCharacterNameAsync(new GetUserIdByCharacterNameReq()
                {
                    CharacterName = request.receiverName,
                });

                string receiverId = userIdResp.UserId;
                if (string.IsNullOrEmpty(receiverId))
                {
                    result.Invoke(AckResponseCode.Error, new ResponseSendMailMessage()
                    {
                        message = UITextKeys.UI_ERROR_MAIL_SEND_NO_RECEIVER,
                    });
                    return;
                }
                Mail mail = new Mail()
                {
                    SenderId   = playerCharacter.UserId,
                    SenderName = playerCharacter.CharacterName,
                    ReceiverId = receiverId,
                    Title      = request.title,
                    Content    = request.content,
                    Gold       = request.gold,
                };
                SendMailResp resp = await DbServiceClient.SendMailAsync(new SendMailReq()
                {
                    Mail = mail,
                });

                UITextKeys message = resp.Error;
                result.Invoke(
                    message == UITextKeys.NONE ? AckResponseCode.Success : AckResponseCode.Error,
                    new ResponseSendMailMessage()
                {
                    message = message,
                });
            }
            else
            {
                result.Invoke(AckResponseCode.Error, new ResponseSendMailMessage()
                {
                    message = UITextKeys.UI_ERROR_SERVICE_NOT_AVAILABLE,
                });
            }
#endif
        }