Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
More safely handle offline authentication servers. (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
wordandahalf authored Jan 28, 2024
1 parent 6b3f670 commit 002dcc2
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ public static void loginEncryptionResponseListener(@NotNull ClientEncryptionResp
final HttpClient client = HttpClient.newHttpClient();
final HttpRequest request = HttpRequest.newBuilder(URI.create(url)).GET().build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).whenComplete((response, throwable) -> {
if (throwable != null) {
MinecraftServer.getExceptionManager().handleException(throwable);
final boolean ok = throwable == null && response.statusCode() == 200 && response.body() != null && !response.body().isEmpty();

if (!ok) {
if (throwable != null) {
MinecraftServer.getExceptionManager().handleException(throwable);
}

if (socketConnection.getPlayer() != null) {
socketConnection.getPlayer().kick(Component.text("Failed to contact Mojang's Session Servers (Are they down?)"));
} else {
Expand All @@ -134,15 +139,6 @@ public static void loginEncryptionResponseListener(@NotNull ClientEncryptionResp
}
try {
final JsonObject gameProfile = GSON.fromJson(response.body(), JsonObject.class);
if (gameProfile == null) {
// Invalid response
if (socketConnection.getPlayer() != null) {
socketConnection.getPlayer().kick(Component.text("Failed to get data from Mojang's Session Servers (Are they down?)"));
} else {
socketConnection.disconnect();
}
return;
}
socketConnection.setEncryptionKey(getSecretKey(packet.sharedSecret()));
UUID profileUUID = java.util.UUID.fromString(gameProfile.get("id").getAsString()
.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
Expand Down

0 comments on commit 002dcc2

Please sign in to comment.