Skip to content

Commit 588db36

Browse files
authored
0.79.3 (#938)
* Update RPC request headers * Update to 0.77.1 * Bump to 0.79.3 * Fix proto submodule
1 parent 5bb2c4f commit 588db36

File tree

16 files changed

+119
-63
lines changed

16 files changed

+119
-63
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "library/src/resources/protobuf"]
22
path = library/src/resources/protobuf
3-
url = https://github.com/AeonLucid/POGOProtos.git
3+
url = https://github.com/pogosandbox/POGOProtos.git

library/src/main/java/com/pokegoapi/api/inventory/Inventories.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import POGOProtos.Inventory.InventoryItemOuterClass.InventoryItem;
2828
import POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData;
2929
import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId;
30-
import POGOProtos.Networking.Requests.Messages.GetInventoryMessageOuterClass.GetInventoryMessage;
30+
import POGOProtos.Networking.Requests.Messages.GetHoloInventoryMessageOuterClass.GetHoloInventoryMessage;
3131
import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType;
32-
import POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse;
32+
import POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse;
3333
import com.google.protobuf.InvalidProtocolBufferException;
3434
import com.pokegoapi.api.PokemonGo;
3535
import com.pokegoapi.api.pokemon.EggPokemon;
@@ -90,7 +90,7 @@ public Inventories(PokemonGo api) {
9090
* @return the response to the update message
9191
* @throws RequestFailedException if an exception occurred while sending requests
9292
*/
93-
public GetInventoryResponse updateInventories() throws RequestFailedException {
93+
public GetHoloInventoryResponse updateInventories() throws RequestFailedException {
9494
return updateInventories(false);
9595
}
9696

@@ -103,7 +103,7 @@ public GetInventoryResponse updateInventories() throws RequestFailedException {
103103
* @deprecated Inventory is updated as a common request
104104
*/
105105
@Deprecated
106-
public GetInventoryResponse updateInventories(boolean forceUpdate)
106+
public GetHoloInventoryResponse updateInventories(boolean forceUpdate)
107107
throws RequestFailedException {
108108
if (forceUpdate) {
109109
lastInventoryUpdate = 0;
@@ -116,15 +116,15 @@ public GetInventoryResponse updateInventories(boolean forceUpdate)
116116
}
117117
hatchery.reset();
118118
}
119-
GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder()
119+
GetHoloInventoryMessage invReqMsg = GetHoloInventoryMessage.newBuilder()
120120
.setLastTimestampMs(lastInventoryUpdate)
121121
.build();
122-
ServerRequest inventoryRequest = new ServerRequest(RequestType.GET_INVENTORY, invReqMsg);
122+
ServerRequest inventoryRequest = new ServerRequest(RequestType.GET_HOLO_INVENTORY, invReqMsg);
123123
api.getRequestHandler().sendServerRequests(inventoryRequest, false);
124124

125-
GetInventoryResponse response;
125+
GetHoloInventoryResponse response;
126126
try {
127-
response = GetInventoryResponse.parseFrom(inventoryRequest.getData());
127+
response = GetHoloInventoryResponse.parseFrom(inventoryRequest.getData());
128128
} catch (InvalidProtocolBufferException e) {
129129
throw new RequestFailedException(e);
130130
}
@@ -138,7 +138,7 @@ public GetInventoryResponse updateInventories(boolean forceUpdate)
138138
* @param response the get inventory response
139139
* @throws RequestFailedException if a request fails while sending a request
140140
*/
141-
public void updateInventories(GetInventoryResponse response) throws RequestFailedException {
141+
public void updateInventories(GetHoloInventoryResponse response) throws RequestFailedException {
142142
lastInventoryUpdate = api.currentTimeMillis();
143143

144144
for (InventoryItem inventoryItem : response.getInventoryDelta().getInventoryItemsList()) {

library/src/main/java/com/pokegoapi/api/inventory/PokeBank.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import POGOProtos.Inventory.InventoryItemOuterClass.InventoryItem;
2323
import POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage;
2424
import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType;
25-
import POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse;
25+
import POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse;
2626
import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse;
2727
import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result;
2828
import com.annimon.stream.Collectors;
@@ -39,6 +39,7 @@
3939
import lombok.Getter;
4040

4141
import java.util.ArrayList;
42+
import java.util.Arrays;
4243
import java.util.Collections;
4344
import java.util.HashMap;
4445
import java.util.List;
@@ -166,15 +167,13 @@ public Map<PokemonFamilyId, Integer> releasePokemon(Pokemon... releasePokemon) t
166167
Map<PokemonFamilyId, Integer> lastCandies = new HashMap<>(api.getInventories().getCandyjar().getCandies());
167168
ServerResponse response = api.getRequestHandler().sendServerRequests(envelope);
168169
try {
169-
ByteString inventoryData = response.get(RequestType.GET_INVENTORY);
170-
GetInventoryResponse inventoryResponse = GetInventoryResponse.parseFrom(inventoryData);
170+
ByteString inventoryData = response.get(RequestType.GET_HOLO_INVENTORY);
171+
GetHoloInventoryResponse inventoryResponse = GetHoloInventoryResponse.parseFrom(inventoryData);
171172
ReleasePokemonResponse releaseResponse = ReleasePokemonResponse.parseFrom(releaseRequest.getData());
172173
Map<PokemonFamilyId, Integer> candyCount = new HashMap<>();
173174
if (releaseResponse.getResult() == Result.SUCCESS && inventoryResponse.getSuccess()) {
174175
synchronized (this.lock) {
175-
for (Pokemon pokemon : releasePokemon) {
176-
this.pokemons.remove(pokemon);
177-
}
176+
this.pokemons.removeAll(Arrays.asList(releasePokemon));
178177
}
179178
for (Pokemon pokemon : releasePokemon) {
180179
api.getInventories().getPokebank().removePokemon(pokemon);

library/src/main/java/com/pokegoapi/auth/CredentialProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ public abstract class CredentialProvider {
2828

2929
public abstract AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, InvalidCredentialsException;
3030

31+
/**
32+
* @deprecated Use {@link CredentialProvider#isTokenIdInvalid()}
33+
*/
34+
@Deprecated
3135
public abstract boolean isTokenIdExpired();
3236

37+
public abstract boolean isTokenIdInvalid();
38+
3339
public abstract void reset();
3440
}

library/src/main/java/com/pokegoapi/auth/GoogleAutoCredentialProvider.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private TokenInfo refreshToken(String username, String refreshToken) throws Logi
102102
*/
103103
@Override
104104
public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCredentialsException {
105-
if (refresh || isTokenIdExpired()) {
105+
if (refresh || isTokenIdInvalid()) {
106106
this.tokenInfo = refreshToken(username, tokenInfo.refreshToken);
107107
}
108108
return tokenInfo.authToken.getToken();
@@ -124,7 +124,12 @@ public AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, Invali
124124

125125
@Override
126126
public boolean isTokenIdExpired() {
127-
return tokenInfo.authToken.getExpiry() < time.currentTimeMillis() / 1000;
127+
return isTokenIdInvalid();
128+
}
129+
130+
@Override
131+
public boolean isTokenIdInvalid() {
132+
return tokenInfo == null || tokenInfo.authToken.getExpiry() < time.currentTimeMillis() / 1000;
128133
}
129134

130135
@Override

library/src/main/java/com/pokegoapi/auth/GoogleCredentialProvider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private GoogleAuthTokenJson poll(GoogleAuthJson json) throws URISyntaxException,
241241

242242
@Override
243243
public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCredentialsException {
244-
if (refresh || isTokenIdExpired()) {
244+
if (refresh || isTokenIdInvalid()) {
245245
refreshToken(refreshToken);
246246
}
247247
return tokenId;
@@ -257,7 +257,7 @@ public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCr
257257
*/
258258
@Override
259259
public AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, InvalidCredentialsException {
260-
if (refresh || isTokenIdExpired()) {
260+
if (refresh || isTokenIdInvalid()) {
261261
refreshToken(refreshToken);
262262
}
263263
authbuilder.setProvider("google");
@@ -267,7 +267,12 @@ public AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, Invali
267267

268268
@Override
269269
public boolean isTokenIdExpired() {
270-
return System.currentTimeMillis() > expiresTimestamp;
270+
return isTokenIdInvalid();
271+
}
272+
273+
@Override
274+
public boolean isTokenIdInvalid() {
275+
return tokenId == null || System.currentTimeMillis() > expiresTimestamp;
271276
}
272277

273278
@Override

library/src/main/java/com/pokegoapi/auth/GoogleUserCredentialProvider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void login(String authCode) throws LoginFailedException, InvalidCredentia
227227

228228
@Override
229229
public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCredentialsException {
230-
if (refresh || isTokenIdExpired()) {
230+
if (refresh || isTokenIdInvalid()) {
231231
refreshToken(refreshToken);
232232
}
233233
return tokenId;
@@ -244,7 +244,7 @@ public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCr
244244
@Override
245245
public AuthInfo getAuthInfo(boolean refresh)
246246
throws LoginFailedException, InvalidCredentialsException {
247-
if (refresh || isTokenIdExpired()) {
247+
if (refresh || isTokenIdInvalid()) {
248248
refreshToken(refreshToken);
249249
}
250250
authbuilder.setProvider("google");
@@ -254,7 +254,12 @@ public AuthInfo getAuthInfo(boolean refresh)
254254

255255
@Override
256256
public boolean isTokenIdExpired() {
257-
return time.currentTimeMillis() > expiresTimestamp;
257+
return isTokenIdInvalid();
258+
}
259+
260+
@Override
261+
public boolean isTokenIdInvalid() {
262+
return tokenId == null || time.currentTimeMillis() > expiresTimestamp;
258263
}
259264

260265
@Override
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This program is free software: you can redistribute it and/or modify
3+
* it under the terms of the GNU General Public License as published by
4+
* the Free Software Foundation, either version 3 of the License, or
5+
* (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
package com.pokegoapi.auth;
16+
17+
import lombok.Getter;
18+
19+
public class PtcAuthError {
20+
@Getter
21+
private String lt;
22+
@Getter
23+
private String execution;
24+
@Getter
25+
private String[] errors;
26+
}

library/src/main/java/com/pokegoapi/auth/PtcCredentialProvider.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,17 @@
3333
import okhttp3.Response;
3434

3535
import java.io.IOException;
36-
import java.net.URLEncoder;
3736
import java.security.SecureRandom;
3837
import java.util.ArrayList;
3938
import java.util.HashMap;
4039
import java.util.List;
41-
import java.util.Locale;
4240

4341
public class PtcCredentialProvider extends CredentialProvider {
4442
public static final String CLIENT_SECRET = "w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR";
4543
public static final String REDIRECT_URI = "https://www.nianticlabs.com/pokemongo/error";
4644
public static final String CLIENT_ID = "mobile-app_pokemon-go";
4745
public static final String SERVICE_URL = "https://sso.pokemon.com/sso/oauth2.0/callbackAuthorize";
48-
public static final String LOGIN_URL = "https://sso.pokemon.com/sso/login?locale=en&service="
49-
+ URLEncoder.encode(SERVICE_URL) + "";
46+
public static final String LOGIN_URL = "https://sso.pokemon.com/sso/login";
5047
public static final String LOGIN_OAUTH = "https://sso.pokemon.com/sso/oauth2.0/accessToken";
5148
public static final String USER_AGENT = "pokemongo/1 CFNetwork/811.4.18 Darwin/16.5.0";
5249
//We try and refresh token 5 minutes before it actually expires
@@ -183,9 +180,13 @@ private void login(String username, String password, int attempt)
183180
.add("_eventId", "submit")
184181
.add("username", username)
185182
.add("password", password)
183+
.add("locale", "en_US")
184+
.build();
185+
HttpUrl loginPostUrl = HttpUrl.parse(LOGIN_URL).newBuilder()
186+
.addQueryParameter("service", SERVICE_URL)
186187
.build();
187188
Request postRequest = new Request.Builder()
188-
.url(LOGIN_URL)
189+
.url(loginPostUrl)
189190
.post(postForm)
190191
.build();
191192

@@ -207,19 +208,23 @@ private void login(String username, String password, int attempt)
207208
throw new LoginFailedException("Response body fetching failed", e);
208209
}
209210

210-
if (postBody.length() > 0) {
211-
if (postBody.toLowerCase(Locale.ROOT).contains("password is incorrect")) {
212-
throw new InvalidCredentialsException("Username or password is incorrect");
213-
} else if (postBody.toLowerCase(Locale.ROOT).contains("failed to log in correctly")) {
214-
throw new InvalidCredentialsException("Account temporarily disabled");
215-
}
216-
}
217-
218211
List<Cookie> cookies = client.cookieJar().loadForRequest(HttpUrl.parse(LOGIN_URL));
219212
for (Cookie cookie : cookies) {
220213
if (cookie.name().startsWith("CASTGC")) {
221214
this.tokenId = cookie.value();
222215
expiresTimestamp = time.currentTimeMillis() + 7140000L;
216+
return;
217+
}
218+
}
219+
220+
if (postBody.length() > 0) {
221+
try {
222+
String[] errors = moshi.adapter(PtcAuthError.class).fromJson(postBody).getErrors();
223+
if (errors != null && errors.length > 0) {
224+
throw new InvalidCredentialsException(errors[0]);
225+
}
226+
} catch (IOException e) {
227+
throw new LoginFailedException("Failed to parse ptc error json");
223228
}
224229
}
225230
} catch (LoginFailedException e) {
@@ -233,7 +238,7 @@ private void login(String username, String password, int attempt)
233238

234239
@Override
235240
public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCredentialsException {
236-
if (refresh || isTokenIdExpired()) {
241+
if (refresh || isTokenIdInvalid()) {
237242
login(username, password, 0);
238243
}
239244
return tokenId;
@@ -249,7 +254,7 @@ public String getTokenId(boolean refresh) throws LoginFailedException, InvalidCr
249254
*/
250255
@Override
251256
public AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, InvalidCredentialsException {
252-
if (refresh || isTokenIdExpired()) {
257+
if (refresh || isTokenIdInvalid()) {
253258
login(username, password, 0);
254259
}
255260

@@ -261,7 +266,12 @@ public AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, Invali
261266

262267
@Override
263268
public boolean isTokenIdExpired() {
264-
return time.currentTimeMillis() > expiresTimestamp;
269+
return isTokenIdInvalid();
270+
}
271+
272+
@Override
273+
public boolean isTokenIdInvalid() {
274+
return tokenId == null || time.currentTimeMillis() > expiresTimestamp;
265275
}
266276

267277
@Override

library/src/main/java/com/pokegoapi/main/CommonRequests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
import POGOProtos.Networking.Requests.Messages.GetAssetDigestMessageOuterClass.GetAssetDigestMessage;
2525
import POGOProtos.Networking.Requests.Messages.GetBuddyWalkedMessageOuterClass.GetBuddyWalkedMessage;
2626
import POGOProtos.Networking.Requests.Messages.GetHatchedEggsMessageOuterClass.GetHatchedEggsMessage;
27+
import POGOProtos.Networking.Requests.Messages.GetHoloInventoryMessageOuterClass.GetHoloInventoryMessage;
2728
import POGOProtos.Networking.Requests.Messages.GetIncensePokemonMessageOuterClass.GetIncensePokemonMessage;
28-
import POGOProtos.Networking.Requests.Messages.GetInventoryMessageOuterClass.GetInventoryMessage;
2929
import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType;
3030
import POGOProtos.Networking.Responses.CheckAwardedBadgesResponseOuterClass.CheckAwardedBadgesResponse;
3131
import POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse;
3232
import POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse;
3333
import POGOProtos.Networking.Responses.GetBuddyWalkedResponseOuterClass.GetBuddyWalkedResponse;
3434
import POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse;
35+
import POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse;
3536
import POGOProtos.Networking.Responses.GetIncensePokemonResponseOuterClass.GetIncensePokemonResponse;
36-
import POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse;
3737
import com.google.protobuf.ByteString;
3838
import com.google.protobuf.InvalidProtocolBufferException;
3939
import com.pokegoapi.api.PokemonGo;
@@ -129,9 +129,9 @@ public static void handleCommons(PokemonGo api, ServerResponse response)
129129
CheckChallengeResponse checkChallenge = CheckChallengeResponse.parseFrom(data);
130130
api.updateChallenge(checkChallenge.getChallengeUrl(), checkChallenge.getShowChallenge());
131131
}
132-
if (response.has(RequestType.GET_INVENTORY)) {
133-
ByteString data = response.get(RequestType.GET_INVENTORY);
134-
GetInventoryResponse inventory = GetInventoryResponse.parseFrom(data);
132+
if (response.has(RequestType.GET_HOLO_INVENTORY)) {
133+
ByteString data = response.get(RequestType.GET_HOLO_INVENTORY);
134+
GetHoloInventoryResponse inventory = GetHoloInventoryResponse.parseFrom(data);
135135
api.getInventories().updateInventories(inventory);
136136
}
137137
if (response.has(RequestType.CHECK_AWARDED_BADGES)) {
@@ -188,8 +188,8 @@ public static ServerRequest getHatchedEggs() {
188188
*/
189189
public static ServerRequest getInventory(PokemonGo api) {
190190
long lastUpdate = api.getInventories().getLastInventoryUpdate();
191-
GetInventoryMessage message = GetInventoryMessage.newBuilder().setLastTimestampMs(lastUpdate).build();
192-
return new ServerRequest(RequestType.GET_INVENTORY, message);
191+
GetHoloInventoryMessage message = GetHoloInventoryMessage.newBuilder().setLastTimestampMs(lastUpdate).build();
192+
return new ServerRequest(RequestType.GET_HOLO_INVENTORY, message);
193193
}
194194

195195
/**

0 commit comments

Comments
 (0)