Skip to content

Commit 1e43ac3

Browse files
committed
Add xbox error codes to SISU authentication
1 parent d00bd20 commit 1e43ac3

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

core/src/main/java/com/rtm516/mcxboxbroadcast/core/Utils.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,33 @@ public static String getStackTrace(Throwable ex) {
1818
// Return the stack trace as a string
1919
return sw.toString();
2020
}
21+
22+
/**
23+
* Get the error message for the Xbox error code
24+
* <p>
25+
* Ported from <a href="https://github.com/HashimTheArab/gophertunnel/commit/b16d5d5f387a9ccee184e87bde0b514cb484d60d">HashimTheArab/gophertunnel</a>
26+
*
27+
* @param code The Xbox error code
28+
* @return The error message for the Xbox error code
29+
*/
30+
public static String getXboxErrorCode(String code) {
31+
return switch (code) {
32+
case "2148916227" ->
33+
"Your account was banned by Xbox for violating one or more Community Standards for Xbox and is unable to be used.";
34+
case "2148916229" ->
35+
"Your account is currently restricted and your guardian has not given you permission to play online. Login to https://account.microsoft.com/family/ and have your guardian change your permissions.";
36+
case "2148916233" ->
37+
"Your account currently does not have an Xbox profile. Please create one at https://www.xbox.com/live";
38+
case "2148916234" -> "Your account has not accepted Xbox's Terms of Service. Please login and accept them.";
39+
case "2148916235" ->
40+
"Your account resides in a region that Xbox has not authorized use from. Xbox has blocked your attempt at logging in.";
41+
case "2148916236" ->
42+
"Your account requires proof of age. Please login to https://login.live.com/login.srf and provide proof of age.";
43+
case "2148916237" ->
44+
"Your account has reached its limit for playtime. Your account has been blocked from logging in.";
45+
case "2148916238" ->
46+
"The account date of birth is under 18 years and cannot proceed unless the account is added to a family by an adult.";
47+
default -> "";
48+
};
49+
}
2150
}

core/src/main/java/com/rtm516/mcxboxbroadcast/core/XboxTokenManager.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Collections;
3434
import java.util.HashMap;
3535
import java.util.Map;
36+
import java.util.Optional;
3637
import java.util.UUID;
3738

3839
/**
@@ -225,11 +226,23 @@ public SISUAuthenticationResponse getSISUToken(String msa, String deviceToken) {
225226
.POST(HttpRequest.BodyPublishers.ofString(requestContentString))
226227
.build();
227228

228-
// Get and parse the response
229-
SISUAuthenticationResponse tokenResponse = Constants.OBJECT_MAPPER.readValue(httpClient.send(authRequest, HttpResponse.BodyHandlers.ofString()).body(), SISUAuthenticationResponse.class);
229+
// Get
230+
HttpResponse<String> httpResponse = httpClient.send(authRequest, HttpResponse.BodyHandlers.ofString());
231+
232+
if (httpResponse.statusCode() != 200) {
233+
Optional<String> errorCode = httpResponse.headers().firstValue("x-err");
234+
if (errorCode.isPresent()) {
235+
throw new RuntimeException(errorCode.get() + ": " + Utils.getXboxErrorCode(errorCode.get()));
236+
} else {
237+
throw new RuntimeException("Got HTTP status code: " + httpResponse.statusCode());
238+
}
239+
}
240+
241+
// Parse the response
242+
SISUAuthenticationResponse tokenResponse = Constants.OBJECT_MAPPER.readValue(httpResponse.body(), SISUAuthenticationResponse.class);
230243

231244
return tokenResponse;
232-
} catch (IOException | InterruptedException e) {
245+
} catch (IOException | InterruptedException | RuntimeException e) {
233246
logger.error("Failed to get SISU authentication token", e);
234247
return null;
235248
}

0 commit comments

Comments
 (0)