Beispiel #1
0
        public async Task GetPlayer()
        {
            var request = CommonRequest.GetPlayerMessageRequest();

            var serverRequest = GetRequestBuilder().GetRequestEnvelope(new[] { request });

            var serverResponse = await PostProto <Request>(serverRequest).ConfigureAwait(false);

            ParseServerResponse(serverResponse);

            if (serverResponse.StatusCode == ResponseEnvelope.Types.StatusCode.Redirect)
            {
                await GetPlayer().ConfigureAwait(false);

                return;
            }

            var responses = serverResponse.Returns;

            if (responses != null)
            {
                var getPlayerResponse = new GetPlayerResponse();
                if (responses.Count > 0)
                {
                    getPlayerResponse.MergeFrom(responses[0]);
                    CommonRequest.ProcessGetPlayerResponse(Client, getPlayerResponse);
                }
            }
        }
Beispiel #2
0
        public async Task GetPlayer()
        {
            var _getPlayerRequest = CommonRequest.GetPlayerMessageRequest(LocaleInfo.Country, LocaleInfo.Language, LocaleInfo.TimeZone);

            var serverRequest = GetRequestBuilder().GetRequestEnvelope(new[] { _getPlayerRequest });

            var serverResponse = await PostProto <Request>(serverRequest).ConfigureAwait(false);

            ParseServerResponse(serverResponse);

            if (serverResponse.StatusCode == ResponseEnvelope.Types.StatusCode.Redirect)
            {
                await GetPlayer().ConfigureAwait(false);

                return;
            }

            var responses = serverResponse.Returns;

            if (responses != null)
            {
                var getPlayerResponse = new GetPlayerResponse();
                if (responses.Count > 0)
                {
                    getPlayerResponse.MergeFrom(responses[0]);
                    Client.Player.PlayerResponse = getPlayerResponse;
                    if (getPlayerResponse.Warn)
                    {
                        Logger.Warning("This account is flagged.");
                    }
                    if (getPlayerResponse.Banned)
                    {
                        Logger.Warning("This account is banned.");
                    }
                }
            }
        }
Beispiel #3
0
        public async Task FireRequestBlock(Request request)
        {
            var requests = CommonRequest.AddChallengeRequest(request, Client);

            var serverRequest  = GetRequestBuilder().GetRequestEnvelope(requests, true);
            var serverResponse = await PostProto <Request>(serverRequest).ConfigureAwait(false);

            var platfResponses = serverResponse.PlatformReturns;

            if (platfResponses != null)
            {
                var mapPlatform = platfResponses.FirstOrDefault(x => x.Type == PlatformRequestType.UnknownPtr8);
                if (mapPlatform != null)
                {
                    var unknownPtr8Response = UnknownPtr8Response.Parser.ParseFrom(mapPlatform.Response);
                    Resources.Api.UnknownPtr8Message = unknownPtr8Response.Message;
                }
            }

            switch (serverResponse.StatusCode)
            {
            case ResponseEnvelope.Types.StatusCode.SessionInvalidated:
            case ResponseEnvelope.Types.StatusCode.InvalidAuthToken:
                Logger.Debug("Invalid token.");
                Client.AuthToken = null;
                throw new AccessTokenExpiredException();

            case ResponseEnvelope.Types.StatusCode.InvalidPlatformRequest:
                Logger.Debug("Invalid Platform.");
                Client.AuthToken = null;
                throw new InvalidPlatformException();

            case ResponseEnvelope.Types.StatusCode.Redirect:
                // 53 means that the api_endpoint was not correctly set, should be at this point, though, so redo the request
                if (!string.IsNullOrEmpty(serverResponse.ApiUrl))
                {
                    Client.ApiUrl = "https://" + serverResponse.ApiUrl + "/rpc";
                    Logger.Debug("New Client.ApiUrl: " + Client.ApiUrl);
                }
                Logger.Debug("Redirecting");
                await FireRequestBlock(request).ConfigureAwait(false);

                return;

            case ResponseEnvelope.Types.StatusCode.BadRequest:
                // Your account may be banned! please try from the official client.
                throw new LoginFailedException("Your account may be banned! please try from the official client.");

            case ResponseEnvelope.Types.StatusCode.Unknown:
                break;

            case ResponseEnvelope.Types.StatusCode.Ok:
                break;

            case ResponseEnvelope.Types.StatusCode.OkRpcUrlInResponse:
                if (!string.IsNullOrEmpty(serverResponse.ApiUrl))
                {
                    Client.ApiUrl = "https://" + serverResponse.ApiUrl + "/rpc";
                    Logger.Debug("New Client.ApiUrl: " + Client.ApiUrl);
                }
                break;

            case ResponseEnvelope.Types.StatusCode.InvalidRequest:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (serverResponse.AuthTicket != null)
            {
                Client.AuthTicket = serverResponse.AuthTicket;
                Logger.Debug("Received AuthTicket: " + Client.AuthTicket);
            }

            var responses = serverResponse.Returns;

            if (responses != null)
            {
                var getPlayerResponse = new GetPlayerResponse();
                if (1 <= responses.Count)
                {
                    getPlayerResponse.MergeFrom(responses[0]);
                    CommonRequest.ProcessGetPlayerResponse(Client, getPlayerResponse);
                }
                var checkChallengeResponse = new CheckChallengeResponse();
                if (2 <= responses.Count)
                {
                    checkChallengeResponse.MergeFrom(responses[1]);
                    CommonRequest.ProcessCheckChallengeResponse(Client, checkChallengeResponse);
                }
            }
        }