-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvanityauth.proxy.kts
125 lines (101 loc) · 3.99 KB
/
vanityauth.proxy.kts
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
121
122
123
124
125
@file:Import("gui.kt")
import me.marvin.proxy.utils.*
import com.google.gson.*
import java.net.*
import java.net.http.*
import java.util.*
import java.util.concurrent.atomic.*
import java.awt.*
import java.io.*
import javax.swing.*
import javax.swing.text.*
import java.nio.charset.StandardCharsets
object Constants {
val JOIN_URL = URI.create("https://kliens.vanityempire.hu/join.php")
val LOGIN_URL = URI.create("https://kliens.vanityempire.hu/login.php")
val CLIENT = HttpClient.newBuilder().build()
val NAME_FIELD = "DqMvBP"
val PASSWORD_FIELD = "zPvBMBgd"
val GUI_REFERENCE = AtomicReference<Gui>(null)
}
class VanitySessionService() : SessionService {
override fun joinServer(profile: GameProfile, token: String, serverId: String) {
val json = JsonObject();
json.addProperty("accessToken", token)
json.addProperty("selectedProfile", profile.uuid().toString())
json.addProperty("serverId", serverId)
val response = Constants.CLIENT.send(HttpRequest.newBuilder()
.uri(Constants.JOIN_URL)
.POST(HttpRequest.BodyPublishers.ofString(json.toString()))
.header("Content-Type", "application/json")
.build(), HttpResponse.BodyHandlers.ofString())
logger.info("[Vanity Auth] Got response: ${response.body()}")
}
}
@Entrypoint
fun entry() {
logger.info("[Vanity Auth] Started!")
logger.info("[Vanity Auth] To show the GUI, please use the command 'vanity'")
commands.register({ _ ->
logger.info("[Vanity Auth] Opening GUI...")
Constants.GUI_REFERENCE.get()?.close()
Constants.GUI_REFERENCE.set(openGui())
return@register true
}, "vanity")
}
@Destructor
fun destruct() {
commands.unregister("vanity")
Constants.GUI_REFERENCE.get()?.close()
logger.info("[Vanity Auth] Stopped!")
}
fun JsonElement.isNotEmpty(): Boolean {
return when (this) {
is JsonPrimitive -> this.getAsString().isNotEmpty()
else -> false
}
}
fun openGui(): Gui = Gui().apply {
open("vanity auth", { name, password ->
logger.info("[Vanity Auth] Logging in with name '$name'...")
try {
val json = JsonObject()
json.addProperty(Constants.NAME_FIELD, name)
json.addProperty(Constants.PASSWORD_FIELD, password)
json.addProperty("twofact", "")
val result = JsonParser.parseString(Constants.CLIENT.send(HttpRequest.newBuilder()
.uri(Constants.LOGIN_URL)
.POST(HttpRequest.BodyPublishers.ofString(json.toString()))
.build(), HttpResponse.BodyHandlers.ofString()).body())
.getAsJsonObject()
logger.info("[Vanity Auth] Got got response: $result")
if (result["error"].isNotEmpty() || result["errormessage"].isNotEmpty()) {
if (result["error"].isNotEmpty()) {
throw Exception(result["error"].getAsString())
} else {
throw Exception(result["errormessage"].getAsString())
}
}
proxy.name(result["username"].getAsString())
proxy.uuid(result["uuid"].getAsString())
proxy.accessToken(result["sessionId"].getAsString())
JOptionPane.showMessageDialog(
null,
"successfully logged in\n(${proxy.name()})",
"success",
JOptionPane.INFORMATION_MESSAGE
)
logger.info("[Vanity Auth] Successfully logged in! ($name -> ${proxy.name()})")
proxy.sessionService(VanitySessionService())
logger.info("[Vanity Auth] Set session service to: " + proxy.sessionService())
} catch (e: Exception) {
JOptionPane.showMessageDialog(
null,
e.message!!.lowercase(),
"error during login",
JOptionPane.ERROR_MESSAGE
)
logger.info("[Vanity Auth] Failed to log in! ($name)")
}
})
}