Search in sources :

Example 21 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class PokemonGo method verifyChallenge.

/**
	 * Verifies the current challenge with the given token.
	 *
	 * @param token the challenge response token
	 * @return if the token was valid or not
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public boolean verifyChallenge(String token) throws RequestFailedException {
    hasChallenge = false;
    VerifyChallengeMessage message = VerifyChallengeMessage.newBuilder().setToken(token).build();
    ServerRequest request = new ServerRequest(RequestType.VERIFY_CHALLENGE, message);
    ByteString responseData = getRequestHandler().sendServerRequests(request, true);
    try {
        VerifyChallengeResponse response = VerifyChallengeResponse.parseFrom(responseData);
        hasChallenge = !response.getSuccess();
        if (!hasChallenge) {
            challengeURL = null;
            synchronized (challengeLock) {
                challengeLock.notifyAll();
            }
        }
        return response.getSuccess();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) VerifyChallengeResponse(POGOProtos.Networking.Responses.VerifyChallengeResponseOuterClass.VerifyChallengeResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) VerifyChallengeMessage(POGOProtos.Networking.Requests.Messages.VerifyChallengeMessageOuterClass.VerifyChallengeMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 22 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Battle method beginDefenderBattle.

/**
	 * Starts this battle with an individual defender
	 *
	 * @param handler to handle this battle
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
private void beginDefenderBattle(final BattleHandler handler) throws RequestFailedException {
    lastRetrievedAction = null;
    queuedActions.clear();
    battleState = BattleState.STATE_UNSET;
    lastServerTime = api.currentTimeMillis();
    lastSendTime = lastServerTime;
    sentActions = false;
    List<Pokemon> attackers = new ArrayList<>();
    for (Pokemon pokemon : team) {
        if (!faintedPokemon.contains(pokemon.getId())) {
            attackers.add(pokemon);
        }
    }
    if (attackers.size() > 0 && defenderIndex < defenderCount) {
        StartGymBattleMessage.Builder builder = StartGymBattleMessage.newBuilder().setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).setGymId(gym.getId()).setDefendingPokemonId(gym.getDefendingPokemon().get(defenderIndex).getId());
        for (Pokemon pokemon : attackers) {
            builder.addAttackingPokemonIds(pokemon.getId());
            if (pokemon.getStamina() < pokemon.getMaxStamina()) {
                throw new IllegalArgumentException("Pokemon must have full stamina to battle in a gym!");
            } else {
                String deployedFortId = pokemon.getDeployedFortId();
                if (pokemon.getFromFort() && deployedFortId != null && deployedFortId.length() > 0) {
                    throw new IllegalArgumentException("Cannot deploy Pokemon that is already in a gym!");
                }
            }
        }
        try {
            StartGymBattleMessage message = builder.build();
            ServerRequest request = new ServerRequest(RequestType.START_GYM_BATTLE, message);
            api.getRequestHandler().sendServerRequests(request);
            StartGymBattleResponse response = StartGymBattleResponse.parseFrom(request.getData());
            if (response.getResult() == StartGymBattleResponse.Result.SUCCESS) {
                battleId = response.getBattleId();
                attacker = response.getAttacker();
                defender = response.getDefender();
                activeDefender = new BattlePokemon(defender.getActivePokemon());
                activeAttacker = new BattlePokemon(attacker.getActivePokemon());
                updateLog(handler, response.getBattleLog());
            }
            sendActions(handler);
            handler.onStart(api, this, response.getResult());
        } catch (InvalidProtocolBufferException e) {
            battleId = "";
            throw new RequestFailedException(e);
        }
    } else {
        active = false;
    }
}
Also used : StartGymBattleResponse(POGOProtos.Networking.Responses.StartGymBattleResponseOuterClass.StartGymBattleResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) StartGymBattleMessage(POGOProtos.Networking.Requests.Messages.StartGymBattleMessageOuterClass.StartGymBattleMessage) Pokemon(com.pokegoapi.api.pokemon.Pokemon) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 23 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Map method requestIncensePokemon.

/**
	 * Requests and returns incense pokemon from the server.
	 *
	 * @return the returned incense pokemon response
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
protected GetIncensePokemonResponse requestIncensePokemon() throws RequestFailedException {
    GetIncensePokemonMessage message = GetIncensePokemonMessage.newBuilder().setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest request = new ServerRequest(RequestType.GET_INCENSE_POKEMON, message);
    api.getRequestHandler().sendServerRequests(request);
    try {
        return GetIncensePokemonResponse.parseFrom(request.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : GetIncensePokemonMessage(POGOProtos.Networking.Requests.Messages.GetIncensePokemonMessageOuterClass.GetIncensePokemonMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 24 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class DiskEncounter method encounter.

@Override
public EncounterResult encounter() throws RequestFailedException {
    DiskEncounterMessage message = DiskEncounterMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setFortId(pokemon.getSpawnPointId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest request = new ServerRequest(RequestType.DISK_ENCOUNTER, message);
    ByteString responseData = api.getRequestHandler().sendServerRequests(request, true);
    try {
        DiskEncounterResponse response = DiskEncounterResponse.parseFrom(responseData);
        encounterResult = EncounterResult.from(response.getResult());
        activeItem = response.getActiveItem();
        captureProbabilities = response.getCaptureProbability();
        encounteredPokemon = response.getPokemonData();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return encounterResult;
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DiskEncounterMessage(POGOProtos.Networking.Requests.Messages.DiskEncounterMessageOuterClass.DiskEncounterMessage) DiskEncounterResponse(POGOProtos.Networking.Responses.DiskEncounterResponseOuterClass.DiskEncounterResponse) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 25 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Encounter method throwPokeball.

/**
	 * Throws a pokeball in this encounter
	 *
	 * @param pokeball the pokeball to throw
	 * @param throwProperties the throw properties for this throw
	 * @return the result from the pokeball throw
	 * @throws RequestFailedException if the throw request fails
	 * @throws NoSuchItemException if the requested pokeball does not exist
	 */
public CatchPokemonResponse.CatchStatus throwPokeball(ItemId pokeball, ThrowProperties throwProperties) throws RequestFailedException, NoSuchItemException {
    if (isActive()) {
        ItemBag bag = api.getInventories().getItemBag();
        Item item = bag.getItem(pokeball);
        if (item.getCount() > 0) {
            CatchPokemonMessage message = CatchPokemonMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setSpawnPointId(pokemon.getSpawnPointId()).setPokeball(pokeball).setNormalizedHitPosition(throwProperties.getNormalizedHitPosition()).setNormalizedReticleSize(throwProperties.getNormalizedReticleSize()).setSpinModifier(throwProperties.getSpinModifier()).setHitPokemon(throwProperties.shouldHitPokemon()).build();
            ServerRequest request = new ServerRequest(RequestType.CATCH_POKEMON, message);
            ByteString responseData = api.getRequestHandler().sendServerRequests(request, true);
            try {
                CatchPokemonResponse response = CatchPokemonResponse.parseFrom(responseData);
                status = response.getStatus();
                if (hasCaptured()) {
                    captureAward = response.getCaptureAward();
                    capturedPokemon = response.getCapturedPokemonId();
                    captureReason = response.getCaptureReason();
                }
                if (status == CatchStatus.CATCH_SUCCESS || status == CatchStatus.CATCH_FLEE) {
                    pokemon.setDespawned(true);
                }
                if (status == CatchStatus.CATCH_SUCCESS) {
                    api.getPlayerProfile().updateProfile();
                }
                if (status != CatchStatus.CATCH_ERROR) {
                    item.setCount(item.getCount() - 1);
                }
            } catch (InvalidProtocolBufferException e) {
                throw new RequestFailedException(e);
            }
        } else {
            throw new NoSuchItemException();
        }
    }
    return status;
}
Also used : Item(com.pokegoapi.api.inventory.Item) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) CatchPokemonResponse(POGOProtos.Networking.Responses.CatchPokemonResponseOuterClass.CatchPokemonResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) CatchPokemonMessage(POGOProtos.Networking.Requests.Messages.CatchPokemonMessageOuterClass.CatchPokemonMessage) NoSuchItemException(com.pokegoapi.exceptions.NoSuchItemException) ItemBag(com.pokegoapi.api.inventory.ItemBag)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)104 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)37 ByteString (com.google.protobuf.ByteString)21 IOException (java.io.IOException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CodedInputStream (com.google.protobuf.CodedInputStream)4 List (java.util.List)4 TypicalData (protos.TypicalData)4 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3 Text (org.apache.hadoop.io.Text)3 YamcsClient (org.yamcs.studio.core.client.YamcsClient)3 ArchiveCatalogue (org.yamcs.studio.core.model.ArchiveCatalogue)3 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2