diff options
author | Linnea Gräf <nea@nea.moe> | 2024-01-10 20:24:09 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-01-10 20:26:02 +0100 |
commit | e51112dadf5a8c01b621ade9eae40da16778691f (patch) | |
tree | a78b1389cdeecc1ff66af0eebe9b2ad1647350bd | |
parent | df4f308005528111f8417c03efe95f1c2cee36bd (diff) | |
download | NotEnoughUpdates-pvfailures.tar.gz NotEnoughUpdates-pvfailures.tar.bz2 NotEnoughUpdates-pvfailures.zip |
Add warning for missing auth tokenpvfailures
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java | 32 | ||||
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt | 30 |
2 files changed, 58 insertions, 4 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index faff8c5f..a145dfb5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -32,7 +32,9 @@ import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.SkillsWe import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; import io.github.moulberry.notenoughupdates.util.AsyncDependencyLoader; import io.github.moulberry.notenoughupdates.util.PronounDB; +import io.github.moulberry.notenoughupdates.util.UrsaClient; import io.github.moulberry.notenoughupdates.util.Utils; +import lombok.val; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityOtherPlayerMP; import net.minecraft.client.gui.GuiScreen; @@ -453,7 +455,29 @@ public class GuiProfileViewer extends GuiScreen { //like telling them to go find a psychotherapist long timeDiff = System.currentTimeMillis() - startTime; - if (timeDiff > 20000) { + val authState = NotEnoughUpdates.INSTANCE.manager.ursaClient.getAuthenticationState(); + if (authState == UrsaClient.AuthenticationState.FAILED_TO_JOINSERVER) { + Utils.drawStringCentered( + EnumChatFormatting.RED + + "Looks like we cannot authenticate with Mojang.", + guiLeft + sizeX / 2f, guiTop + 111, true, 0 + ); + Utils.drawStringCentered( + EnumChatFormatting.RED + "Is your game open for more than 24 hours?", + guiLeft + sizeX / 2f, guiTop + 121, true, 0 + ); + } else if (authState == UrsaClient.AuthenticationState.REJECTED) { + Utils.drawStringCentered( + EnumChatFormatting.RED + + "Looks like we cannot authenticate with Ursa.", + guiLeft + sizeX / 2f, guiTop + 111, true, 0 + ); + Utils.drawStringCentered( + EnumChatFormatting.RED + "Is your game open for more than 24 hours?", + guiLeft + sizeX / 2f, guiTop + 121, true, 0 + ); + + } else if (timeDiff > 20000) { Utils.drawStringCentered( EnumChatFormatting.YELLOW + "Its taking a while...", guiLeft + sizeX / 2f, guiTop + 111, true, 0 @@ -494,7 +518,8 @@ public class GuiProfileViewer extends GuiScreen { ); if (timeDiff > 1200000) { Utils.drawStringCentered( - EnumChatFormatting.RED + String.valueOf(EnumChatFormatting.BOLD) + "You're a menace to society", + EnumChatFormatting.RED + String.valueOf(EnumChatFormatting.BOLD) + + "You're a menace to society", guiLeft + sizeX / 2f, guiTop + 181, true, 0 ); if (timeDiff > 1800000) { @@ -505,7 +530,8 @@ public class GuiProfileViewer extends GuiScreen { ); if (timeDiff > 3000000) { Utils.drawStringCentered( - EnumChatFormatting.RED + String.valueOf(EnumChatFormatting.BOLD) + "You really want this?", + EnumChatFormatting.RED + String.valueOf(EnumChatFormatting.BOLD) + + "You really want this?", guiLeft + sizeX / 2f, guiTop + 91, true, 0 ); if (timeDiff > 3300000) { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt index 312c5d9b..67df5bf9 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt @@ -20,6 +20,7 @@ package io.github.moulberry.notenoughupdates.util import com.google.gson.JsonObject +import com.mojang.authlib.exceptions.AuthenticationException import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag @@ -92,6 +93,7 @@ class UrsaClient(val apiUtil: ApiUtil) { } else { this.token = Token(validUntil, token, usedUrsaRoot) isPollingForToken = false + authenticationState = AuthenticationState.SUCCEEDED logger.log("Token saving successful") } } @@ -115,6 +117,13 @@ class UrsaClient(val apiUtil: ApiUtil) { logger.log("Request failed") continueOn(MinecraftExecutor.OnThread) isPollingForToken = false + if (e is AuthenticationException) { + authenticationState = AuthenticationState.FAILED_TO_JOINSERVER + } + if (e is HttpStatusCodeException && e.statusCode == 401) { + authenticationState = AuthenticationState.REJECTED + this.token = null + } request.consumer.completeExceptionally(e) } } @@ -179,6 +188,24 @@ class UrsaClient(val apiUtil: ApiUtil) { } } + + private var authenticationState = AuthenticationState.NOT_ATTEMPTED + + fun getAuthenticationState(): AuthenticationState { + if (authenticationState == AuthenticationState.SUCCEEDED && token?.isValid != true) { + return AuthenticationState.OUTDATED + } + return authenticationState + } + + enum class AuthenticationState { + NOT_ATTEMPTED, + FAILED_TO_JOINSERVER, + REJECTED, + SUCCEEDED, + OUTDATED, + } + companion object { @JvmStatic fun profiles(uuid: UUID) = KnownRequest("v1/hypixel/v2/profiles/${uuid}", JsonObject::class.java) @@ -193,7 +220,8 @@ class UrsaClient(val apiUtil: ApiUtil) { fun bingo(uuid: UUID) = KnownRequest("v1/hypixel/v2/bingo/${uuid}", JsonObject::class.java) @JvmStatic - fun museumForProfile(profileUuid: String) = KnownRequest("v1/hypixel/v2/museum/${profileUuid}", JsonObject::class.java) + fun museumForProfile(profileUuid: String) = + KnownRequest("v1/hypixel/v2/museum/${profileUuid}", JsonObject::class.java) @JvmStatic fun status(uuid: UUID) = KnownRequest("v1/hypixel/v2/status/${uuid}", JsonObject::class.java) |