Skip to content

Commit e757afc

Browse files
committed
Fixed stupid gson
1 parent 29b0709 commit e757afc

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

common/src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
package com.lambda
1919

20-
import com.github.kittinunf.fuel.Fuel
21-
import com.github.kittinunf.fuel.core.await
22-
import com.github.kittinunf.fuel.core.awaitResponse
23-
import com.github.kittinunf.fuel.core.awaitUnit
2420
import com.google.gson.Gson
2521
import com.google.gson.GsonBuilder
2622
import com.lambda.config.serializer.*

common/src/main/kotlin/com/lambda/module/modules/client/Network.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.module.modules.client
1919

2020
import com.lambda.Lambda.LOG
21+
import com.lambda.Lambda.gson
2122
import com.lambda.Lambda.mc
2223
import com.lambda.context.SafeContext
2324
import com.lambda.event.events.ClientEvent
@@ -31,6 +32,7 @@ import com.lambda.network.api.v1.endpoints.login
3132
import com.lambda.network.api.v1.models.Authentication
3233
import com.lambda.module.Module
3334
import com.lambda.module.tag.ModuleTag
35+
import com.lambda.network.api.v1.models.Authentication.Data
3436
import com.lambda.util.extension.isOffline
3537
import net.minecraft.client.network.AllowedAddressResolver
3638
import net.minecraft.client.network.ClientLoginNetworkHandler
@@ -41,6 +43,7 @@ import net.minecraft.network.encryption.NetworkEncryptionUtils
4143
import net.minecraft.network.packet.c2s.login.LoginHelloC2SPacket
4244
import net.minecraft.text.Text
4345
import java.math.BigInteger
46+
import java.util.*
4447

4548
object Network : Module(
4649
name = "Network",
@@ -49,15 +52,16 @@ object Network : Module(
4952
enabledByDefault = true,
5053
) {
5154
val authServer by setting("Auth Server", "auth.lambda-client.org")
52-
val apiUrl: String by setting("API Server", "https://api.lambda-client.org")
55+
val apiUrl by setting("API Server", "https://api.lambda-client.org")
5356
val apiVersion by setting("API Version", ApiVersion.V1)
5457

5558
var apiAuth: Authentication? = null; private set // TODO: Cache
59+
var deserialized: Data? = null; private set // gson is too stupid
5660
val accessToken: String
5761
get() = apiAuth?.accessToken ?: ""
5862

5963
val SafeContext.isDiscordLinked: Boolean
60-
get() = apiAuth?.decoded?.data?.discordId != null
64+
get() = deserialized?.data?.discordId != null
6165

6266
private lateinit var serverId: String
6367
private lateinit var hash: String
@@ -79,11 +83,12 @@ object Network : Module(
7983
// and posted to the sessionserver api
8084
val (authResponse, error) = login(mc.session.username, hash)
8185
if (error != null) {
82-
LOG.debug("Unable to authenticate with the API: {}", error.errorData)
86+
LOG.debug("Unable to authenticate with the API: ${error.message}")
8387
return@listenOnceUnsafe false
8488
}
8589

8690
apiAuth = authResponse
91+
deserialized = gson.fromJson(String(Base64.getUrlDecoder().decode(accessToken.split(".")[1])), Data::class.java)
8792

8893
// Destroy the listener
8994
true

common/src/main/kotlin/com/lambda/network/api/v1/models/Authentication.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
package com.lambda.network.api.v1.models
1919

2020
import com.google.gson.annotations.SerializedName
21-
import com.lambda.Lambda
22-
import java.time.Instant
23-
import kotlin.io.encoding.Base64
24-
import kotlin.io.encoding.ExperimentalEncodingApi
2521

2622
data class Authentication(
2723
// The access token to use for the API
@@ -39,18 +35,15 @@ data class Authentication(
3935
@SerializedName("token_type")
4036
val tokenType: String,
4137
) {
42-
@OptIn(ExperimentalEncodingApi::class)
43-
val decoded = Lambda.gson.fromJson(Base64.decode(accessToken).toString(), Payload::class.java)
44-
45-
data class Payload(
38+
data class Data(
4639
@SerializedName("nbf")
47-
val notBefore: Instant,
40+
val notBefore: Long,
4841

4942
@SerializedName("iat")
50-
val issuedAt: Instant,
43+
val issuedAt: Long,
5144

5245
@SerializedName("exp")
53-
val expirationDate: Instant,
46+
val expirationDate: Long,
5447

5548
@SerializedName("data")
5649
val data: Player,

0 commit comments

Comments
 (0)