-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlteningAccount.kt
121 lines (100 loc) · 3.72 KB
/
AlteningAccount.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package net.ccbluex.liquidbounce.authlib.account
import com.google.gson.JsonObject
import com.mojang.authlib.Environment
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService
import com.thealtening.api.TheAltening
import com.thealtening.api.TheAlteningException
import net.ccbluex.liquidbounce.authlib.compat.GameProfile
import net.ccbluex.liquidbounce.authlib.compat.Session
import net.ccbluex.liquidbounce.authlib.utils.*
import net.ccbluex.liquidbounce.authlib.yggdrasil.YggdrasilUserAuthentication
import java.net.Proxy
import java.util.*
import kotlin.jvm.Throws
const val ALTENING_AUTH = "http://authserver.thealtening.com"
const val ALTENING_SESSION = "http://sessionserver.thealtening.com"
val alteningEnvironment = Environment(ALTENING_SESSION, "https://api.minecraftservices.com", "PROD")
/**
* Represents an Altening account from the TheAltening Account Generator
*
* @constructor Creates an AlteningAccount object with the specified type.
* @param type The type of the account.
*/
class AlteningAccount(var accountToken: String) : MinecraftAccount("TheAltening") {
/**
* Used for JSON deserialize.
*/
@Suppress("unused")
constructor() : this("")
/**
* Represents a token for authentication.
*/
var accessToken = ""
private set
/**
* Represents the level of a player on the Hypixel server.
*
* @property hypixelLevel The current level of the player on Hypixel.
*/
var hypixelLevel: Int = 0
private set
/**
* Represents the rank of a player on the Hypixel server.
* @property hypixelRank The rank of the player on Hypixel.
*/
var hypixelRank: String = ""
private set
private val sessionService = YggdrasilAuthenticationService(Proxy.NO_PROXY, alteningEnvironment)
private val userAuthentication = YggdrasilUserAuthentication(ALTENING_AUTH)
/**
* load the account data from json
* @param json contains the account data
*/
override fun fromRawJson(json: JsonObject) {
val name = json.string("name")!!
val uuid = if (json.has("uuid")) parseUuid(json.string("uuid")!!) else null
profile = GameProfile(name, uuid!!)
accessToken = json.string("token")!!
hypixelLevel = json.int("hypixelLevel")!!
hypixelRank = json.string("hypixelRank")!!
}
/**
* save the account data to json
* @param json needs to write data in
*/
override fun toRawJson(json: JsonObject) {
json["name"] = profile!!.username
if (profile!!.uuid != null) {
json["uuid"] = profile!!.uuid.toString()
}
json["token"] = accessToken
json["hypixelLevel"] = hypixelLevel
json["hypixelRank"] = hypixelRank
}
override fun refresh() {
val session = userAuthentication.authenticate(accountToken, "LiquidBounce")
accessToken = session.token
profile = GameProfile(session.username, session.uuid)
}
override fun login(): Pair<Session, YggdrasilAuthenticationService> {
if (profile?.uuid == null) {
refresh()
}
val session = profile!!.toSession(accessToken, "mojang")
return session to sessionService
}
companion object {
fun fromToken(accountToken: String): AlteningAccount {
val account = AlteningAccount(accountToken)
account.refresh()
return account
}
@Throws(TheAlteningException::class)
fun generateAccount(apiToken: String): AlteningAccount {
val alteningAccount = TheAltening.newBasicRetriever(apiToken).account
val account = AlteningAccount(alteningAccount.token)
account.refresh()
return account
}
}
}