Search in sources :

Example 1 with RequestHandler

use of com.pokegoapi.main.RequestHandler in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method initialize.

private void initialize() throws RequestFailedException {
    if (requestHandler != null) {
        requestHandler.exit();
    }
    requestHandler = new RequestHandler(this, client);
    requestHandler.sendServerRequests(ServerRequestEnvelope.create());
    playerProfile.updateProfile();
    ServerRequest downloadConfigRequest = new ServerRequest(RequestType.DOWNLOAD_REMOTE_CONFIG_VERSION, CommonRequests.getDownloadRemoteConfigVersionMessageRequest(this));
    requestHandler.sendServerRequests(downloadConfigRequest, true);
    getAssetDigest();
    try {
        ByteString configVersionData = downloadConfigRequest.getData();
        if (itemTemplates.requiresUpdate(DownloadRemoteConfigVersionResponse.parseFrom(configVersionData))) {
            itemTemplates.update(this);
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    playerProfile.getProfile();
    try {
        LevelUpRewardsMessage rewardsMessage = LevelUpRewardsMessage.newBuilder().setLevel(playerProfile.getStats().getLevel()).build();
        ServerRequest request = new ServerRequest(RequestType.LEVEL_UP_REWARDS, rewardsMessage);
        ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons(request, this);
        requestHandler.sendServerRequests(envelope);
        LevelUpRewardsResponse levelUpRewardsResponse = LevelUpRewardsResponse.parseFrom(request.getData());
        if (levelUpRewardsResponse.getResult() == Result.SUCCESS) {
            inventories.itemBag.addAwardedItems(levelUpRewardsResponse);
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    ByteString getStoreItems = GetStoreItemsRequest.newBuilder().build().toByteString();
    ServerRequestEnvelope envelope = ServerRequestEnvelope.create();
    envelope.addPlatform(new ServerPlatformRequest(PlatformRequestType.GET_STORE_ITEMS, getStoreItems));
    requestHandler.sendServerRequests(envelope);
    try {
        FetchAllNewsMessageOuterClass.FetchAllNewsMessage msg = FetchAllNewsMessageOuterClass.FetchAllNewsMessage.newBuilder().build();
        ServerRequest request = new ServerRequest(RequestType.FETCH_ALL_NEWS, msg);
        envelope = ServerRequestEnvelope.create(request);
        requestHandler.sendServerRequests(envelope);
        FetchAllNewsResponseOuterClass.FetchAllNewsResponse response = FetchAllNewsResponseOuterClass.FetchAllNewsResponse.parseFrom(request.getData());
        if (response.getResult() == FetchAllNewsResponseOuterClass.FetchAllNewsResponse.Result.SUCCESS) {
            Log.i(TAG, "FetchAllNewsMessage Success: total News=" + response.getCurrentNews().getNewsArticlesCount());
            this.news.setCurrentNews(response.getCurrentNews());
            // mark all un-read new to read
            this.news.markUnreadNews();
        } else {
            Log.d(TAG, "FetchAllNewsMessage Failed. Result=" + response.getResult());
        }
    } catch (Exception e) {
        Log.d(TAG, "Exceptions FetchAllNew");
    }
    List<LoginListener> loginListeners = getListeners(LoginListener.class);
    for (LoginListener listener : loginListeners) {
        listener.onLogin(this);
    }
    loggingIn = false;
    active = true;
    ArrayList<TutorialState> tutorialStates = playerProfile.getTutorialState().getTutorialStates();
    if (tutorialStates.isEmpty()) {
        playerProfile.activateAccount();
    }
    if (!tutorialStates.contains(TutorialState.AVATAR_SELECTION)) {
        playerProfile.setupAvatar();
    }
    heartbeat.start();
    if (!tutorialStates.contains(TutorialState.POKEMON_CAPTURE)) {
        playerProfile.encounterTutorialComplete();
    }
    int remainingCodenameClaims = playerProfile.getPlayerData().getRemainingCodenameClaims();
    if (!tutorialStates.contains(TutorialState.NAME_SELECTION) && remainingCodenameClaims > 0) {
        playerProfile.claimCodeName();
    }
    if (!tutorialStates.contains(TutorialState.FIRST_TIME_EXPERIENCE_COMPLETE)) {
        playerProfile.firstTimeExperienceComplete();
    }
}
Also used : LevelUpRewardsMessage(POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage) ByteString(com.google.protobuf.ByteString) FetchAllNewsMessageOuterClass(POGOProtos.Networking.Requests.Messages.FetchAllNewsMessageOuterClass) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) IOException(java.io.IOException) Point(com.pokegoapi.api.map.Point) FetchAllNewsResponseOuterClass(POGOProtos.Networking.Responses.FetchAllNewsResponseOuterClass) ServerRequestEnvelope(com.pokegoapi.main.ServerRequestEnvelope) LoginListener(com.pokegoapi.api.listener.LoginListener) RequestHandler(com.pokegoapi.main.RequestHandler) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ServerRequest(com.pokegoapi.main.ServerRequest) LevelUpRewardsResponse(POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse) ServerPlatformRequest(com.pokegoapi.main.ServerPlatformRequest) TutorialState(POGOProtos.Enums.TutorialStateOuterClass.TutorialState)

Aggregations

TutorialState (POGOProtos.Enums.TutorialStateOuterClass.TutorialState)1 FetchAllNewsMessageOuterClass (POGOProtos.Networking.Requests.Messages.FetchAllNewsMessageOuterClass)1 LevelUpRewardsMessage (POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage)1 FetchAllNewsResponseOuterClass (POGOProtos.Networking.Responses.FetchAllNewsResponseOuterClass)1 LevelUpRewardsResponse (POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 LoginListener (com.pokegoapi.api.listener.LoginListener)1 Point (com.pokegoapi.api.map.Point)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 RequestHandler (com.pokegoapi.main.RequestHandler)1 ServerPlatformRequest (com.pokegoapi.main.ServerPlatformRequest)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 ServerRequestEnvelope (com.pokegoapi.main.ServerRequestEnvelope)1 IOException (java.io.IOException)1