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