Throw PtcOfflineException on maintenance
Throw PtcOfflineException on maintenance
Thx @ https://github.com/NecronomiconCoding/Pokemon-Go-Bot/commit/8b4f3c1b1c22654ae4b54148fad90643d0a3663f
diff --git a/PokemonGo.RocketAPI/Login/PtcLogin.cs b/PokemonGo.RocketAPI/Login/PtcLogin.cs
index aa6e94c..19f5078 100644
--- a/PokemonGo.RocketAPI/Login/PtcLogin.cs
+++ b/PokemonGo.RocketAPI/Login/PtcLogin.cs
@@ -16,7 +16,7 @@ namespace PokemonGo.RocketAPI.Login
{
public static async Task<string> GetAccessToken(string username, string password)
{
- var handler = new HttpClientHandler()
+ var handler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip,
AllowAutoRedirect = false
@@ -27,6 +27,11 @@ namespace PokemonGo.RocketAPI.Login
//Get session cookie
var sessionResp = await tempHttpClient.GetAsync(Resources.PtcLoginUrl);
var data = await sessionResp.Content.ReadAsStringAsync();
+ if (data == null) throw new PtcOfflineException();
+
+ if (sessionResp.StatusCode == HttpStatusCode.InternalServerError || data.Contains("<title>Maintenance"))
+ throw new PtcOfflineException();
+
var lt = JsonHelper.GetValue(data, "lt");
var executionId = JsonHelper.GetValue(data, "execution");
@@ -39,7 +44,7 @@ namespace PokemonGo.RocketAPI.Login
new KeyValuePair<string, string>("execution", executionId),
new KeyValuePair<string, string>("_eventId", "submit"),
new KeyValuePair<string, string>("username", username),
- new KeyValuePair<string, string>("password", password),
+ new KeyValuePair<string, string>("password", password)
}));
if (loginResp.Headers.Location == null)
@@ -60,7 +65,7 @@ namespace PokemonGo.RocketAPI.Login
new KeyValuePair<string, string>("client_secret",
"w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR"),
new KeyValuePair<string, string>("grant_type", "refresh_token"),
- new KeyValuePair<string, string>("code", ticketId),
+ new KeyValuePair<string, string>("code", ticketId)
}));
var tokenData = await tokenResp.Content.ReadAsStringAsync();
@@ -68,4 +73,4 @@ namespace PokemonGo.RocketAPI.Login
}
}
}
-}
+}
\ No newline at end of file
You may download the files in Public Git.