Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharll-large authored Jan 14, 2023
1 parent 46cc4b8 commit 2f0c958
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 36 deletions.
13 changes: 4 additions & 9 deletions FMCLCore/Auth/MicrosoftAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def post(url, data, headers):
tmp = urllib.request.Request(url=url, data=urllib.parse.urlencode(data).encode(), headers=headers)
return urllib.request.urlopen(tmp).read().decode()

def Auth(refresh_token: str=None):
def Auth(usecallback: bool, Code: str=None):
defaultheaders = {"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
Expand All @@ -17,15 +17,13 @@ def Auth(refresh_token: str=None):
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}
informations = {}
if refresh_token is None:
webbrowser.open("https://login.live.com/oauth20_authorize.srf?client_id=00000000402b5328&response_type=code&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf")
authcode = input("请输入回调链接:")
authcode = authcode[authcode.find("?code=")+6:authcode.find("&lc=2052")]
if usecallback:
authcode = Code[Code.find("?code=")+6:Code.find("&lc=2052")]
MSdata = urllib.parse.urlencode({"client_id": "00000000402b5328", "code": authcode, "grant_type": "authorization_code",
"redirect_uri": "https://login.live.com/oauth20_desktop.srf", "scope": "service::user.auth.xboxlive.com::MBI_SSL"
}).encode()
else:
authcode = refresh_token
authcode = Code
MSdata = urllib.parse.urlencode({"client_id": "00000000402b5328", "refresh_token": authcode, "grant_type": "refresh_token",
"redirect_uri": "https://login.live.com/oauth20_desktop.srf", "scope": "service::user.auth.xboxlive.com::MBI_SSL"
}).encode()
Expand Down Expand Up @@ -76,6 +74,3 @@ def Auth(refresh_token: str=None):
informations["uuid"] = mcinfo["id"]

return informations

print(Auth())
input()
15 changes: 9 additions & 6 deletions FMCLCore/Launch/CoreLaunchTaskSub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import platform
import re
import subprocess
import threading
import urllib.request
import uuid
Expand All @@ -22,7 +23,7 @@ def download_native(arg: dict):
(("size" not in arg) or (os.path.getsize(arg["path"]) == arg["size"])) and \
(("sha1" not in arg) or (hashlib.sha1(open(arg["path"], "rb").read()).hexdigest() == arg["sha1"])):
if "unzip" in arg:
FMCLCore.System.Logging.showinfo("unzip" + arg)
FMCLCore.System.Logging.showinfo("unzip" + str(arg))
FMCLCore.System.UnzipTask.unzip(arg["path"], arg["unzip"])
back_msg += f"Download successfully in {i} try(s) and {e} exception(s): {emsg}"
break
Expand Down Expand Up @@ -185,7 +186,7 @@ def launch(game_directory: str = ".minecraft", version_name: str = None, java: s
"${assets_index_name}": ver_json["assetIndex"]["id"],
"${auth_uuid}": UUID,
"${auth_access_token}": TOKEN,
"${user_type}": "Legacy",
"${user_type}": "Mojang",
"${version_type}": "FMCL",
"${user_properties}": "{}",
"${auth_session}": "{}",
Expand All @@ -204,9 +205,11 @@ def launch(game_directory: str = ".minecraft", version_name: str = None, java: s
return cmdlist

# a = (launch(input(".minecraft路径:"),
# input("要启动的游戏版本:"),
# input("java路径(可只填写\"java\"):"),
# input("玩家名称:")))
# input("要启动的游戏版本:"),
# input("java路径(可只填写\"java\"):"),
# input("玩家名称:"),
# UUID='c8189b09aebf49838b65bad10e905ba6',
# TOKEN='eyJhbGciOiJIUzI1NiJ9.eyJ4dWlkIjoiMjUzNTQwNzExMjg1Njg4OCIsImFnZyI6IkFkdWx0Iiwic3ViIjoiNDg1ZjI2ODUtOGJkZi00ZmNlLTkwZmUtMTcyMjZlNzYwZDc5IiwibmJmIjoxNjczNjA3MzU1LCJhdXRoIjoiWEJPWCIsInJvbGVzIjpbXSwiaXNzIjoiYXV0aGVudGljYXRpb24iLCJleHAiOjE2NzM2OTM3NTUsImlhdCI6MTY3MzYwNzM1NSwicGxhdGZvcm0iOiJVTktOT1dOIiwieXVpZCI6IjAxYTYxYWMyYTNiZTI5YjVmMjc2MTM2ZjIwNGZmMmM0In0.OdD4LGd9BE3aw9QjH0-iWhfuIT9PGg1EmJ5ZMP76oBs'))
# print(a)
# subprocess.run(a)
# #input()
# input()
48 changes: 28 additions & 20 deletions FMCLCore/System/CoreConfigIO.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,58 @@
import json
import os
from multiprocessing import cpu_count
import FMCLCore.System.Logging
import FMCLCore.System.CoreMakeFolderTask

config = os.path.abspath("config.json")
import FMCLCore.System.CoreMakeFolderTask
import FMCLCore.System.Logging

config = os.path.abspath(".first.mcl.json")
really = {}

def read():
return json.load(open(config, "r+"))

return json.load(open(config, "r+", encoding="utf-8"))

def write(playername: str = "player", dotmc: str = ".minecraft", java: str = "java", ram: str = "1024M",
threads: int = cpu_count() * 8):
con = {"playername": playername, ".mc": dotmc, "java": java, "ram": ram, "threads": threads}
writejson(con)
def writejson(conf: dict):
open(config, "w+", encoding="utf-8").write(json.dumps(conf))

def add_account(account: dict):
tmp = read()
tmp["Accounts"].append(account)
writejson(tmp)

def writejson(all: dict):
open(config, "w+").write(json.dumps(all))
def delete_account(number: int):
tmp = read()
del tmp["Accounts"][number]
writejson(tmp)

def get_account():
accountlist = []
for i in read()["Accounts"]:
accountlist.append("[" + i["type"] + "] " + i["name"])
return accountlist

def fixdepend():
if not os.path.exists("config.json"):
write()
print(FMCLCore.System.Logging.showinfo("Config-Checker:\tConfig.json not found. Create config.json."))
std = {"About": "This file is very important! DO NOT EDIT OR SHARE!", ".mc": ".minecraft", "java": "java", "ram": "1024M", "threads": 64, "Language": "English", "Accounts": []}
if not os.path.exists(config):
writejson(std)
print(FMCLCore.System.Logging.showinfo("Config-Checker:\t" + config + " not found. Create " + config + "."))
else:
try:
read()

except json.decoder.JSONDecodeError:
print(FMCLCore.System.Logging.showwarning("config.json is broken, fixing."))
write()
print(FMCLCore.System.Logging.showsuccess("Successfully fixed config.json."))
print(FMCLCore.System.Logging.showwarning(config + " is broken, fixing."))
writejson(std)
print(FMCLCore.System.Logging.showsuccess("Successfully fixed " + config + "."))

finally:
fixed = False
config_json = FMCLCore.System.CoreConfigIO.read()
std = {"playername": "player", ".mc": ".minecraft", "java": "java", "ram": "1024M", "threads": 128}
for i in std:
if i not in config_json:
print(FMCLCore.System.Logging.showwarning("Config-Checker:\tMissing object: " + i))
config_json[i] = std[i]
FMCLCore.System.CoreConfigIO.writejson(config_json)
fixed = True
if fixed:
print(FMCLCore.System.Logging.showsuccess("Config-Checker:\tSuccessfully fixed config.json!"))
print(FMCLCore.System.Logging.showsuccess("Config-Checker:\tSuccessfully fixed " + config + "!"))

FMCLCore.System.CoreMakeFolderTask.make_mc_dir(FMCLCore.System.CoreConfigIO.read()[".mc"])
2 changes: 1 addition & 1 deletion FMCLCore/System/CoreVersionGet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_version_list(version_type: list):
def local_version(mcpath):
versions = []
for i in os.listdir(os.path.join(mcpath, "versions")):
if os.path.exists(os.path.join(mcpath, "versions", i, f"{i}.jar")) and os.path.exists(os.path.join(mcpath, "versions", i, f"{i}.json")):
if os.path.exists(os.path.join(mcpath, "versions", i, f"{i}.json")):
versions.append(i)
return versions

Expand Down

0 comments on commit 2f0c958

Please sign in to comment.