-
Notifications
You must be signed in to change notification settings - Fork 0
/
amml.py
83 lines (56 loc) · 2.09 KB
/
amml.py
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
"""
The main script of the loader.
"""
import os
import subprocess
import http.server
import socketserver
# import re
from typing import Union, Optional, TypedDict
import minecraft_launcher_lib
from minecraft_launcher_lib import microsoft_account
mc_directory = os.path.join(os.getcwd(), 'mcdir')
client_id = "9d4eb936-02b6-445e-a7fd-51ccce4ab536"
redirect_url = "http://127.0.0.1:8000/"
version = "1.16.5"
minecraft_launcher_lib.install.install_minecraft_version(version, mc_directory)
login_url = microsoft_account.get_login_url(
client_id, redirect_url)
print(login_url)
class CodeContainer(TypedDict):
code: Optional[str]
def wait_for_code(port: int):
container = CodeContainer(code=None)
class RedirectHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
# global wait_for_code.code
# code_match = re.search(r"(?<=code=)[\w.-]+", self.path)
# print(self.path)
# print(code_match)
# print(code_match.group())
container["code"] = microsoft_account.get_auth_code_from_url(
self.path)
self.send_response(200)
self.send_header("Content-Length", "text/html")
self.end_headers()
# self.wfile.write(b'<script>window.close()</script>')
with socketserver.TCPServer(("", port), RedirectHandler) as httpd:
print("Waiting for socket event.")
httpd.handle_request()
return container["code"]
code = wait_for_code(8000)
print(f"code: {code}")
# login
login_data = microsoft_account.complete_login(client_id, None, redirect_url, code, None)
options: minecraft_launcher_lib.types.MinecraftOptions = {
"username": login_data["name"],
"uuid": login_data["id"],
"token": login_data["access_token"]
}
# launch
def launch_mc(version: str, dir: Union[str, os.PathLike],
options: minecraft_launcher_lib.utils.MinecraftOptions):
launch_command = minecraft_launcher_lib.command.get_minecraft_command(
version, dir, options)
subprocess.Popen(launch_command)
launch_mc(version, mc_directory, options)