-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmojangauth.proxy.kts
75 lines (60 loc) · 2.07 KB
/
mojangauth.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
@file:Repository("https://jitpack.io")
@file:DependsOn("com.github.Litarvan:OpenAuth:v1.1.4")
@file:Import("gui.kt")
import me.marvin.proxy.utils.*
import java.net.*
import java.util.*
import java.util.concurrent.atomic.*
import java.awt.*
import java.io.*
import javax.swing.*
import javax.swing.text.*
import fr.litarvan.openauth.microsoft.*
object Constants {
val GUI_REFERENCE = AtomicReference<Gui>(null)
}
@Entrypoint
fun entry() {
logger.info("[Mojang Auth] Started!")
logger.info("[Mojang Auth] To show the GUI, please use the command 'mojang'")
commands.register({ _ ->
logger.info("[Mojang Auth] Opening GUI...")
Constants.GUI_REFERENCE.get()?.close()
Constants.GUI_REFERENCE.set(openGui())
return@register true
}, "mojang")
}
@Destructor
fun destruct() {
commands.unregister("mojang")
logger.info("[Mojang Auth] Stopped!")
}
fun openGui(): Gui = Gui().apply {
open("mojang auth", { name, password ->
logger.info("[Mojang Auth] Logging in with email '$name'...")
try {
val authenticator = MicrosoftAuthenticator()
val result = authenticator.loginWithCredentials(name, password)
proxy.name(result.profile.name)
proxy.uuid(result.profile.id)
proxy.accessToken(result.accessToken)
JOptionPane.showMessageDialog(
null,
"successfully logged in\n(${proxy.name()})",
"success",
JOptionPane.INFORMATION_MESSAGE
)
logger.info("[Mojang Auth] Successfully logged in! ($name -> ${proxy.name()})")
proxy.sessionService(SessionService.DEFAULT)
logger.info("[Mojang Auth] Set session service to: " + proxy.sessionService())
} catch (e: Exception) {
JOptionPane.showMessageDialog(
null,
e.message!!.lowercase(),
"error during login",
JOptionPane.ERROR_MESSAGE
)
logger.info("[Mojang Auth] Failed to log in! ($name)")
}
})
}