aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-01-10 20:24:09 +0100
committerLinnea Gräf <nea@nea.moe>2024-01-10 20:26:02 +0100
commite51112dadf5a8c01b621ade9eae40da16778691f (patch)
treea78b1389cdeecc1ff66af0eebe9b2ad1647350bd /src/main/kotlin
parentdf4f308005528111f8417c03efe95f1c2cee36bd (diff)
downloadNotEnoughUpdates-pvfailures.tar.gz
NotEnoughUpdates-pvfailures.tar.bz2
NotEnoughUpdates-pvfailures.zip
Add warning for missing auth tokenpvfailures
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt30
1 files changed, 29 insertions, 1 deletions
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)