732 lines
39 KiB
Python
732 lines
39 KiB
Python
import os,requests,json,time,sys,argparse,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
#Environment Setup Area.
|
|
|
|
#Set Global Var.
|
|
Log='[Logs Output]'
|
|
number=0
|
|
source=json.loads('["https://bmclapi2.bangbang93.com","https://download.mcbbs.net","https://gemcapi.ghink.net/?path=","https://download.minebbs.com/?path="]')
|
|
#Read Config File.
|
|
config_open=open("config.json", mode='r')
|
|
config_json=config_open.read()
|
|
config_open.close()
|
|
try:
|
|
config=json.loads(config_json)
|
|
config_status=True
|
|
except:
|
|
config_status=False
|
|
Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Starting to read config file.'
|
|
if(config_status==True):
|
|
Log=Log + '\n' + "[" + config['name'] + "]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Read config successfully.'
|
|
else:
|
|
Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[ERROR]Read config failed.'
|
|
Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]There is a deadly error,the program will stop soon.'
|
|
Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Starting to save log.'
|
|
if os.path.exists('logs'):
|
|
Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The dir logs has already existed.Nothing to do.'
|
|
else:
|
|
Log=Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The dir logs does not exist.The program will create one.'
|
|
os.makedirs('logs')
|
|
logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
|
logs_output.write(Log + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + "[Program]" + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]Please check if the json is right.')
|
|
logs_output.close()
|
|
sys.exit(0)
|
|
#Get Parameter.
|
|
parser=argparse.ArgumentParser()
|
|
parser.add_argument("--launcher_name", help="The name of the launcher.")
|
|
parser.add_argument("--launcher_version", help="The version of the launcher.")
|
|
parser.add_argument("--type", help="The type of task,{\"launcher_game\",\"search_file\",\"get_game_version_list\",\"get_java_path\",\"get_system_memory\",\"get_online_source_list\",\"install_online_source\",\"get_uuid\",\"download_file\",\"clean_logs\",\"clean_temp\",\"clean\",\"clean_logs_without_output\",\"clean_without_output\"}")
|
|
parser.add_argument("--copyright", help="The copyright of the game,true of false.The default is false.")
|
|
#Launcher Game Parameter Area.
|
|
#Search File Area.
|
|
parser.add_argument("--file_name", help="The name of file which you want to search.")
|
|
parser.add_argument("--file_dir", help="The dir of file which you want to search.")
|
|
#True Copyright.
|
|
parser.add_argument("--email", help="The email of game account.(If your game is genuine,you have to input this parameter.)")
|
|
parser.add_argument("--password", help="The password of game account.(If your game is genuine,you have to input this parameter.")
|
|
#False Copyright.
|
|
parser.add_argument("--id", help="The id of game.(If your game is not genuine,you have to input this parameter.)")
|
|
#Get Game Version List Area.
|
|
parser.add_argument("--game_dir", help="The dir of your game.If you not input this parameter,the GMCL Core will use the Mojang's Launcher's game dir.")
|
|
#Get System Memory Area.
|
|
parser.add_argument("--memory_data_type", help="The data type of memory that will return.{\"free\",\"used\",\"total\",\"auto\"}")
|
|
parser.add_argument("--memory_data_unit", help="The data unit of memory that will return,the default unit is B.{\"MB\",\"KB\",\"GB\",\"B\",\"TB\"}")
|
|
#Get Online Resources List Area.
|
|
parser.add_argument("--online_resources_list_type", help="The online resources type of list,you have to input a json there.{\"tree_number\":int,")
|
|
parser.add_argument("--online_resources_list_return_type", help="The return data type of return data of online resources,the default is json.{\"json\"}")
|
|
#Install online Source Area.
|
|
parser.add_argument("--install_online_resources_type", help="The online resources type of which resources you want to install,you have to input a json there.")
|
|
parser.add_argument("--install_online_resources_id", help="The online resources id of which resources you want to install.")
|
|
parser.add_argument("--install_online_resources_dir", help="The game dir which you want to install to.")
|
|
#Download Resources Area.
|
|
parser.add_argument("--download_url", help="The file url of resources which you want download.If you want to download multi files,you have to input json like:{\"number\":10,\"url\":[\"example1.com\",\"example2.com\"]} and {\"number\":10,\"path\":[\"\\usr\\root\\home\\Desktop\\1\",\"\\usr\\root\\home\\Desktop\\2\"]}")
|
|
parser.add_argument("--download_path", help="The save path of resources which you want download.")
|
|
#Get System Java Path Area.
|
|
parser.add_argument("--number_of_java", help="How many java path(s) you want to return.Do not set the number too big,it will cost a lot of time and system performance.")
|
|
#Global Parameter Area.
|
|
parser.add_argument("--source", help="The source of online resources.If you want to use mix mode,you have to input a json like:{\"mode\":\"mix\",\"source\":{\"number\":number,\"source\":[\"source_1\",\"source_2\"]}}or not input anything.{\"bmclapi\",\"gemcapi\",\"minebbs\",\"mojang\",\"mix\"}")
|
|
parser.add_argument("--memory", help="The memory that could be used by game.You should input with unit,if you send a null parameter,the core will get java path automatically.")
|
|
parser.add_argument("--java", help="The java path of the system,if you send a null parameter,the core will get java path automatically.")
|
|
parser.add_argument("--parameter", help="The excess parameter that launcher game need.")
|
|
parser.add_argument("--dir", help="The game dir,if you send a null parameter,the core will use Mojang's Launcher's game dir.")
|
|
parser.add_argument("--version", help="The game version.")
|
|
parser.add_argument("--uuid", help="Your UUID,you can input your UUID by your self,this parameter isn't must,the core will generate one automatically.There's two mode you can use to generate UUID.The default mode is gmclc.If you want to use other mode,for example:hmcl mode,just input \"hmcl\" there.{\"hmcl\",\"gmclc\"}")
|
|
parser=parser.parse_args()
|
|
#Set Parameter into Var.
|
|
if(parser.launcher_name==None):
|
|
launcher_name=config['default_launcher_name']
|
|
else:
|
|
launcher_name=parser.launcher_name
|
|
if(parser.launcher_version==None):
|
|
launcher_version=config['version']
|
|
else:
|
|
launcher_version=parser.launcher_version
|
|
if(parser.number_of_java==None):
|
|
number_of_java=1
|
|
else:
|
|
try:
|
|
number_of_java=int(parser.number_of_java)
|
|
except:
|
|
number_of_java=""
|
|
if(parser.game_dir==None):
|
|
game_dir='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft'
|
|
else:
|
|
game_dir=parser.game_dir
|
|
|
|
#Set Config Into Var.
|
|
UA={'User-Agent':launcher_name + '/' + launcher_version + config['useragent']}
|
|
name=config['name']
|
|
logs_head="[" + config['name'] + "]"
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
#Sub_Program Area.
|
|
def log(log_type,logvar):
|
|
global Log
|
|
global name
|
|
global logs_head
|
|
if(log_type=="info"):
|
|
log_type="INFO"
|
|
elif(log_type=="warn"):
|
|
log_type="WARN"
|
|
elif(log_type=="error"):
|
|
log_type="ERROR"
|
|
Log=Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar
|
|
def return_data(return_d):
|
|
if(config['return_mode']=='directly'):
|
|
print(return_d)
|
|
elif(config['return_mode']=='json'):
|
|
if(check_json(return_d)):
|
|
print('{"return":' + return_d + ',"logs":"' + Log.replace('\n','\\n') + '"}')
|
|
else:
|
|
print('{"return":"' + return_d + '","logs":"' + Log.replace('\n','\\n') + '"}')
|
|
def launcher_true(email,password,memory,java,parameter,dir,version):
|
|
pass
|
|
def launcher_false(id,memory,java,parameter,dir,version):
|
|
pass
|
|
def download_resources(type,assembly,version):
|
|
pass
|
|
def check_json(input_str):
|
|
try:
|
|
json.loads(input_str)
|
|
return True
|
|
except:
|
|
return False
|
|
def download(url, dirpath):
|
|
global Log
|
|
global UA
|
|
global name
|
|
log("info",'The ' + name + ' is downloading the file ' + dirpath + '.')
|
|
try:
|
|
download=requests.get(url, headers=UA)
|
|
with open(dirpath,"wb") as code:
|
|
code.write(download.content)
|
|
except:
|
|
log("error",'There has a error in task while downloading the file ' + dirpath + ' from ' + url + '.')
|
|
else:
|
|
log("info",'The file ' + dirpath + ' has been downloaded successfully.')
|
|
def make_dir_exist(dirpath):
|
|
global Log
|
|
global name
|
|
if os.path.exists(dirpath):
|
|
log("info",'The dir ' + dirpath + ' has already existed.Nothing to do.')
|
|
else:
|
|
log("info",'The dir ' + dirpath + ' does not exist.The ' + name + ' will create one.')
|
|
os.makedirs(dirpath)
|
|
def memory(return_type):
|
|
if(return_type=="free"):
|
|
return psutil.virtual_memory().free
|
|
elif(return_type=="used"):
|
|
return psutil.virtual_memory().used
|
|
elif(return_type=="total"):
|
|
return psutil.virtual_memory().total
|
|
elif(return_type=="auto"):
|
|
return 0.8 * psutil.virtual_memory().free
|
|
def error_output_log(logpath):
|
|
global Log
|
|
global logs_head
|
|
logs_output=open(logpath + '/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
|
logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[WARN]Please check if the parameter is right.')
|
|
logs_output.close()
|
|
def deadly_error():
|
|
log("warn","There is a deadly error,the program will stop soon.")
|
|
make_dir_exist('logs')
|
|
error_output_log('logs')
|
|
sys.exit(0)
|
|
def search_java_windows_temp(path,tagfile):
|
|
global number
|
|
for ipath in os.listdir(path):
|
|
fulldir = os.path.join(path,ipath)
|
|
if(os.path.isfile(fulldir)):
|
|
if(tagfile in os.path.split(fulldir)[1]):
|
|
print(fulldir)
|
|
number=number+1
|
|
if(os.path.isdir(fulldir)):
|
|
try:
|
|
search_java_windows_temp(fulldir,tagfile)
|
|
except:
|
|
pass
|
|
if(parser.number_of_java=="all"):
|
|
pass
|
|
elif(number==number_of_java):
|
|
break
|
|
def search_files(path,tagfile):
|
|
global number
|
|
for ipath in os.listdir(path):
|
|
fulldir = os.path.join(path,ipath)
|
|
if(os.path.isfile(fulldir)):
|
|
if(tagfile in os.path.split(fulldir)[1]):
|
|
print(fulldir)
|
|
number=number+1
|
|
if(os.path.isdir(fulldir)):
|
|
try:
|
|
search_files(fulldir,tagfile)
|
|
except:
|
|
pass
|
|
def get_uuid(id,g_type):
|
|
if(g_type=='hmcl'):
|
|
return_i='OfflinePlayer:' + id
|
|
md5=hashlib.md5()
|
|
md5.update(return_i.encode(encoding='utf-8'))
|
|
return md5.hexdigest()
|
|
elif(g_type=='gmclc'):
|
|
result=id
|
|
for i in range(0,len(id)):
|
|
md5=hashlib.md5()
|
|
md5.update(result.encode(encoding='utf-8'))
|
|
result=md5.hexdigest()
|
|
return result
|
|
def make_file_exist(file,url):
|
|
if(parser.source==None):
|
|
num=random.randint(0,3)
|
|
domain=source[num]
|
|
if(num==0):
|
|
source_type=0
|
|
elif(num==1):
|
|
source_type=0
|
|
elif(num==2):
|
|
source_type=1
|
|
elif(num==3):
|
|
source_type=1
|
|
elif(parser.source=='mix'):
|
|
num=random.randint(0,3)
|
|
domain=source[num]
|
|
if(num==0):
|
|
source_type=0
|
|
elif(num==1):
|
|
source_type=0
|
|
elif(num==2):
|
|
source_type=1
|
|
elif(num==3):
|
|
source_type=1
|
|
elif(parser.source=='bmclapi'):
|
|
domain=source[0]
|
|
source_type=0
|
|
elif(parser.source=='mcbbs'):
|
|
domain=source[1]
|
|
source_type=0
|
|
elif(parser.source=='gemcapi'):
|
|
domain=source[2]
|
|
source_type=1
|
|
elif(parser.source=='minebbs'):
|
|
domain=source[3]
|
|
source_type=1
|
|
elif(parser.source=='mojang'):
|
|
source_type=2
|
|
try:
|
|
f=open(file)
|
|
f.close()
|
|
except:
|
|
if(source_type==2):
|
|
os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file)
|
|
return_data('Downloading ' + url + ' to ' + file + '.')
|
|
elif(source_type==0):
|
|
url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries')
|
|
os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file)
|
|
return_data('Downloading ' + url + ' to ' + file + '.')
|
|
elif(source_type==1):
|
|
url=url.replace('https://libraries.minecraft.net','https://gemcapi.ghink.net/?path=minecraft/libraries')
|
|
os.system("python gmclc.py --type download_file --download_url " + url + " --download_path " + file)
|
|
return_data('Downloading ' + url + ' to ' + file + '.')
|
|
def unzip(src,dir):
|
|
uz=zipfile.ZipFile(src,'r')
|
|
for file in uz.namelist():
|
|
try:
|
|
uz.extract(file,dir)
|
|
except:
|
|
pass
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
#Make Dir Area.
|
|
make_dir_exist("temp")
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
#Use Statistics Area.
|
|
open_s=requests.get('https://open.gmclc.statistics.ghink.net', headers=UA)
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
log("info","Start to deal the tasks that need to do.")
|
|
if(parser.type=="download_file"):
|
|
log("info","Download file(s) mode.")
|
|
try:
|
|
try:
|
|
urljson=json.loads(parser.download_url)
|
|
pathjson=json.loads(parser.download_path)
|
|
if(urljson['number']==pathjson['number']):
|
|
count=0
|
|
for i in range(0,urljson['number']):
|
|
try:
|
|
filepath=pathjson['path'][count]
|
|
dirpath=filepath.replace(os.path.basename(filepath),"")
|
|
make_dir_exist(dirpath)
|
|
download(urljson['url'][count],filepath)
|
|
except:
|
|
log("error","Some errors happened while downloading files,please check and try again.")
|
|
count=count+1
|
|
else:
|
|
log("error","The file(s) number is not same!We can't download the file(s).")
|
|
deadly_error()
|
|
except:
|
|
try:
|
|
dirpath=parser.download_path.replace(os.path.basename(parser.download_path),"")
|
|
make_dir_exist(dirpath)
|
|
download(parser.download_url,parser.download_path)
|
|
except:
|
|
log("error","Some errors happened while downloading files,please check and try again.")
|
|
deadly_error()
|
|
except:
|
|
log("error","Some errors happened.We can't download the file(s),please check if the parameter you input is correct.")
|
|
deadly_error()
|
|
elif(parser.type=="get_system_memory"):
|
|
log("info","Get system memory mode.")
|
|
try:
|
|
if(parser.memory_data_type=="free"):
|
|
memory_data=memory("free")
|
|
elif(parser.memory_data_type=="used"):
|
|
memory_data=memory("used")
|
|
elif(parser.memory_data_type=="total"):
|
|
memory_data=memory("total")
|
|
elif(parser.memory_data_type=="auto"):
|
|
memory_data=memory("auto")
|
|
else:
|
|
log("error","We can't get the memory data,please check if the parameter you input is coreect.")
|
|
deadly_error()
|
|
if(parser.memory_data_unit==None):
|
|
log("info","Return:" + str(memory_data) + '.')
|
|
return_data(str(memory_data))
|
|
elif(parser.memory_data_unit=="B"):
|
|
log("info","Return:" + str(memory_data) + '.')
|
|
return_data(str(memory_data))
|
|
elif(parser.memory_data_unit=="KB"):
|
|
log("info","Return:" + str(memory_data / 1024) + '.')
|
|
return_data(str(memory_data / 1024))
|
|
elif(parser.memory_data_unit=="MB"):
|
|
log("info","Return:" + str(memory_data / 1024 / 1024) + '.')
|
|
return_data(str(memory_data / 1024 / 1024))
|
|
elif(parser.memory_data_unit=="GB"):
|
|
log("info","Return:" + str(memory_data / 1024 / 1024 / 1024) + '.')
|
|
return_data(str(memory_data / 1024 / 1024 / 1024))
|
|
elif(parser.memory_data_unit=="TB"):
|
|
log("info","Return:" + str(memory_data / 1024 / 1024 / 1024 / 1024) + '.')
|
|
return_data(str(memory_data / 1024 / 1024 / 1024 / 1024))
|
|
except:
|
|
log("error","Some errors happened.We can't get the memory data,please check if the parameter you input is correct.")
|
|
deadly_error()
|
|
elif(parser.type=="search_file"):
|
|
log("info","Search file mode.")
|
|
if(parser.file_name==None):
|
|
log("error","There has a error while search file,you can't let the parameter \"file_name\" be \"None\",please check is the parameter input correct.")
|
|
else:
|
|
search_files(parser.file_dir,parser.file_name)
|
|
elif(parser.type=="get_uuid"):
|
|
log("info","Get UUID mode.")
|
|
if(parser.id==None):
|
|
return_data('There has a error in parameters you input,please check if the parameter "id" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "id" is correct.')
|
|
deadly_error()
|
|
else:
|
|
if(parser.uuid==None):
|
|
uuid=get_uuid(parser.id,'gmclc')
|
|
elif(parser.uuid=='gmclc'):
|
|
uuid=get_uuid(parser.id,'gmclc')
|
|
elif(parser.uuid=='hmcl'):
|
|
uuid=get_uuid(parser.id,'hmcl')
|
|
else:
|
|
return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
|
deadly_error()
|
|
print(uuid)
|
|
elif(parser.type=="get_java_path"):
|
|
log("info","Get system java environment path mode.")
|
|
if(platform.system()=='Windows'):
|
|
return_info=os.popen('python gmclc.py --type temp_1 --number_of_java ' + str(number_of_java))
|
|
return_i=return_info.read()
|
|
return_info.close()
|
|
with open('temp/temp-3.gmclc', 'w') as file_object:
|
|
file_object.write(return_i)
|
|
number=0
|
|
count = len(open('temp/temp-3.gmclc', 'r').readlines())
|
|
for line in open("temp/temp-3.gmclc"):
|
|
number=number+1
|
|
with open('temp/temp-4.gmclc', 'a') as file_object:
|
|
if(number==count):
|
|
if(count==1):
|
|
file_object.write(line.replace("\n",""))
|
|
else:
|
|
file_object.write(line.replace("\n","") + '"]')
|
|
elif(number==1):
|
|
file_object.write('["' + line.replace("\n","") + '","')
|
|
else:
|
|
file_object.write(line.replace("\n","") + '","')
|
|
return_data(open("temp/temp-4.gmclc",'r').read())
|
|
os.remove('temp/temp-3.gmclc')
|
|
os.remove('temp/temp-4.gmclc')
|
|
else:
|
|
return_data('java')
|
|
elif(parser.type=="get_game_version_list"):
|
|
log("info","Get game versions list mode.")
|
|
if(platform.system()=='Windows'):
|
|
return_info=os.popen('python gmclc.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"')
|
|
return_i=return_info.read()
|
|
return_info.close()
|
|
with open('temp/temp-1.gmclc', 'w') as file_object:
|
|
file_object.write(return_i)
|
|
number=0
|
|
count = len(open('temp/temp-1.gmclc', 'r').readlines())
|
|
for line in open("temp/temp-1.gmclc"):
|
|
number=number+1
|
|
with open('temp/temp-2.gmclc', 'a') as file_object:
|
|
if(number==count):
|
|
if(count==1):
|
|
file_object.write('"' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"')
|
|
else:
|
|
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]')
|
|
elif(number==1):
|
|
file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
|
else:
|
|
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
|
return_data(open("temp/temp-2.gmclc",'r').read())
|
|
os.remove('temp/temp-1.gmclc')
|
|
os.remove('temp/temp-2.gmclc')
|
|
else:
|
|
if(parser.game_dir==None):
|
|
log('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.')
|
|
else:
|
|
return_info=os.popen('python gmclc.py --type search_file --file_name ".json" --file_dir "' + game_dir + '\\versions"')
|
|
return_i=return_info.read()
|
|
return_info.close()
|
|
with open('temp/temp-1.gmclc', 'w') as file_object:
|
|
file_object.write(return_i)
|
|
number=0
|
|
count = len(open('temp/temp-1.gmclc', 'r').readlines())
|
|
for line in open("temp/temp-1.gmclc"):
|
|
number=number+1
|
|
with open('temp/temp-2.gmclc', 'a+') as file_object:
|
|
if(number==count):
|
|
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '"]')
|
|
elif(number==1):
|
|
file_object.write('["' + line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
|
else:
|
|
file_object.write(line.replace(line[::-1].split('\\', 1)[-1][::-1],'').replace('\\','').replace('.json','').replace('\n','') + '","')
|
|
return_data(open("temp/temp-2.gmclc",'r').read())
|
|
os.remove('temp/temp-1.gmclc')
|
|
os.remove('temp/temp-2.gmclc')
|
|
elif(parser.type=="clean_logs"):
|
|
log("info","Clean logs mode.")
|
|
log("info","Cleaning logs......")
|
|
try:
|
|
shutil.rmtree("logs")
|
|
except:
|
|
log("error","Cleaning logs error.")
|
|
elif(parser.type=="clean_temp"):
|
|
log("info","Clean temp mode.")
|
|
log("info","Cleaning temp......")
|
|
try:
|
|
shutil.rmtree("temp")
|
|
except:
|
|
log("error","Cleaning temp error.")
|
|
elif(parser.type=="clean"):
|
|
log("info","Clean file mode.")
|
|
log("info","Cleaning file......")
|
|
try:
|
|
shutil.rmtree("logs")
|
|
except:
|
|
log("error","Cleaning logs error.")
|
|
try:
|
|
shutil.rmtree("temp")
|
|
except:
|
|
log("error","Cleaning temp error.")
|
|
elif(parser.type=="clean_without_output"):
|
|
log("info","Clean file mode.")
|
|
log("info","Cleaning file......")
|
|
try:
|
|
shutil.rmtree("logs")
|
|
except:
|
|
pass
|
|
try:
|
|
shutil.rmtree("temp")
|
|
except:
|
|
pass
|
|
sys.exit(0)
|
|
elif(parser.type=="clean_logs_without_output"):
|
|
log("info","Clean logs mode.")
|
|
log("info","Cleaning logs......")
|
|
try:
|
|
shutil.rmtree("logs")
|
|
except:
|
|
pass
|
|
sys.exit(0)
|
|
elif(parser.type=="launcher_game"):
|
|
log("info","Launcher game mode.")
|
|
return_data('Checking game dir.')
|
|
log('info','Checking game dir.')
|
|
if(parser.dir==None):
|
|
if(platform.system()=='Windows'):
|
|
dir_i='C:\\Users\\' + str(getpass.getuser()) + '\\AppData\\Roaming\\.minecraft'
|
|
else:
|
|
return_data('Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.')
|
|
log('error','Your system is UNIX or Linux,we can\'t use the Mojang\'s Launcher\'s game dir,please enter your game path and try again.')
|
|
deadly_error()
|
|
else:
|
|
dir_i=parser.dir
|
|
return_data('Checking game copyright.')
|
|
log('info','Checking game copyright.')
|
|
if(parser.copyright==None):
|
|
if(parser.id==None):
|
|
return_data('There has a error in parameters you input,please check if the parameter "id" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "id" is correct.')
|
|
deadly_error()
|
|
else:
|
|
return_data('Checking player uuid.')
|
|
log('info','Checking player uuid.')
|
|
if(parser.uuid==None):
|
|
uuid=get_uuid(parser.id,'gmclc')
|
|
elif(parser.uuid=='gmclc'):
|
|
uuid=get_uuid(parser.id,'gmclc')
|
|
elif(parser.uuid=='hmcl'):
|
|
uuid=get_uuid(parser.id,'hmcl')
|
|
elif(len(parser.uuid)==32):
|
|
uuid=parser.uuid
|
|
else:
|
|
return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
|
deadly_error()
|
|
access_token=uuid
|
|
id_i=parser.id
|
|
elif(parser.copyright=='false'):
|
|
if(parser.id==None):
|
|
return_data('There has a error in parameters you input,please check if the parameter "id" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "id" is correct.')
|
|
deadly_error()
|
|
else:
|
|
return_data('Checking player uuid.')
|
|
log('info','Checking player uuid.')
|
|
if(parser.uuid==None):
|
|
uuid=get_uuid(parser.id,'gmclc')
|
|
elif(parser.uuid=='gmclc'):
|
|
uuid=get_uuid(parser.id,'gmclc')
|
|
elif(parser.uuid=='hmcl'):
|
|
uuid=get_uuid(parser.id,'hmcl')
|
|
elif(len(parser.uuid)==32):
|
|
uuid=parser.uuid
|
|
else:
|
|
return_data('There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "uuid" is correct.')
|
|
deadly_error()
|
|
access_token=uuid
|
|
id_i=parser.id
|
|
elif(parser.copyright=='true'):
|
|
if(parser.email==None):
|
|
return_data('There has a error in parameters you input,please check if the parameter "email" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "email" is correct.')
|
|
deadly_error()
|
|
elif(parser.email.count('@')==1):
|
|
email=parser.email
|
|
else:
|
|
return_data('There has a error in parameters you input,please check if the parameter "email" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "email" is correct.')
|
|
deadly_error()
|
|
if(parser.password==None):
|
|
return_data('There has a error in parameters you input,please check if the parameter "password" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "password" is correct.')
|
|
deadly_error()
|
|
else:
|
|
password=parser.password
|
|
if(json.loads(requests.get('https://authserver.mojang.com/', headers=UA).text)['Status']=='OK'):
|
|
rq_r=json.loads(requests.post('https://authserver.mojang.com/authenticate', '{"agent": {"name": "Minecraft","version": 1},"username": "' + parser.email + '","password": "' + parser.password + '"}', headers=UA).text)
|
|
access_token=rq_r['accessToken']
|
|
id_i=rq_r['selectedProfile']['name']
|
|
uuid=rq_r['selectedProfile']['id']
|
|
else:
|
|
return_data('There has a error while login to mojang account,the auth server has failed.')
|
|
log('error','There has a error while login to mojang account,the auth server has failed.')
|
|
deadly_error()
|
|
return_data('Checking game version(s).')
|
|
log('info','Checking game version(s).')
|
|
if(parser.version==None):
|
|
return_data('There has a error in parameters you input,please check if the parameter "version" is correct.')
|
|
log('error','There has a error in parameters you input,please check if the parameter "version" is correct.')
|
|
deadly_error()
|
|
else:
|
|
return_info=os.popen('python gmclc.py --type get_game_version_list --game_dir "' + dir_i)
|
|
return_i=return_info.read()
|
|
if(return_i.count('"' + parser.version + '"')!=0):
|
|
game_config_open=open(dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.json',encoding='UTF-8')
|
|
game_config_json=game_config_open.read()
|
|
game_config_open.close()
|
|
game_config=json.loads(game_config_json)
|
|
return_data('Checking game files.')
|
|
log('info','Checking game files.')
|
|
number=0
|
|
for i in range(0,game_config_json.count('"path"')):
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['artifact']['url'])
|
|
if(platform.system()=='Windows'):
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['url'])
|
|
except:
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['url'])
|
|
except:
|
|
pass
|
|
elif(platform.system()=='Linux'):
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['url'])
|
|
except:
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['url'])
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['url'])
|
|
except:
|
|
try:
|
|
make_file_exist(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['url'])
|
|
except:
|
|
pass
|
|
except:
|
|
pass
|
|
number=number+1
|
|
if(os.path.isdir(dir_i + '\\versions\\' + parser.version + '\\natives')):
|
|
pass
|
|
else:
|
|
make_dir_exist(dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
number=0
|
|
for i in range(0,game_config_json.count('"path"')):
|
|
if(platform.system()=='Windows'):
|
|
try:
|
|
unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
except:
|
|
try:
|
|
unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-windows']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
except:
|
|
pass
|
|
elif(platform.system()=='Linux'):
|
|
try:
|
|
unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
except:
|
|
try:
|
|
unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-linux']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
unzip(dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
except:
|
|
try:
|
|
unzip(dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['classifiers']['natives-macos']['path'].replace('/','\\'),dir_i + '\\versions\\' + parser.version + '\\natives')
|
|
except:
|
|
pass
|
|
number=number+1
|
|
cp=""
|
|
number=0
|
|
for i in range(0,game_config_json.count('"path"')):
|
|
try:
|
|
cp=cp + dir_i + '\\libraries\\' + game_config['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';'
|
|
except:
|
|
try:
|
|
cp=cp + dir_i + '\\libraries\\' + game_config['patches'][0]['libraries'][number]['downloads']['artifact']['path'].replace('/','\\') + ';'
|
|
except:
|
|
pass
|
|
number=number+1
|
|
cp=cp + dir_i + '\\versions\\' + parser.version + '\\' + parser.version + '.jar'
|
|
return_data('Checking java environment.')
|
|
log('info','Checking java environment.')
|
|
if(parser.java==None):
|
|
return_info=os.popen('python gmclc.py --type get_java_path')
|
|
java=return_info.read()
|
|
return_info.close()
|
|
elif(os.path.exists(parser.java)):
|
|
java=parser.java
|
|
else:
|
|
return_data('The java program you input is not exist!Please check if the parameter you input is correct!')
|
|
log('error','The java program you input is not exist!Please check if the parameter you input is correct!')
|
|
deadly_error()
|
|
return_data('Checking memory parameter.')
|
|
log('info','Checking memory parameter.')
|
|
if(parser.memory==None):
|
|
return_info=os.popen('python gmclc.py --type get_system_memory --memory_data_type auto --memory_data_unit MB')
|
|
memory=str(math.ceil(float(return_info.read().replace("\n","")))) + "m"
|
|
return_info.close()
|
|
else:
|
|
memory=parser.memory
|
|
try:
|
|
asset_index=game_config['assetIndex']['id']
|
|
except:
|
|
asset_index=game_config['patches'][0]['assetIndex']['id']
|
|
command='\"' + java.replace('\n','') + '\" -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow -Xmn128m -Xmx' + memory + ' -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Djava.library.path=' + dir_i + '\\versions\\' + parser.version + '\\natives -Dminecraft.launcher.brand=' + config['default_launcher_name'] + ' -Dminecraft.launcher.version=' + config['version'] + ' -cp ' + cp + ' net.minecraft.client.main.Main --username ' + id_i + ' --version "' + config['default_launcher_name'] + ' ' + config['version'] + '" --gameDir ' + dir_i + ' --assetsDir ' + dir_i + '\\assets --assetIndex ' + asset_index + ' --uuid ' + uuid + ' --accessToken ' + access_token + ' --userProperties {} --userType mojang --versionType "' + config['default_launcher_name'] + ' ' + config['version'] + '" --tweakClass cpw.mods.fml.common.launcher.FMLTweaker'
|
|
subprocess.Popen(command, shell=True)
|
|
open_s=requests.get('https://launch.gmclc.statistics.ghink.net', headers=UA)
|
|
#print(command)
|
|
else:
|
|
return_data('The version you input is not exist!Please check if the parameter you input is correct!')
|
|
log('error','The vversion you input is not exist!Please check if the parameter you input is correct!')
|
|
deadly_error()
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
#Temp Mode Area.
|
|
elif(parser.type=="temp_1"):#Get java mode temp
|
|
search_java_windows_temp('C:\\Program Files\\Java\\','javaw.exe')
|
|
|
|
#-------------------------------------------------------#
|
|
|
|
#Starting To Save Logs.
|
|
log("info",'Starting to save logs.')
|
|
try:
|
|
make_dir_exist("logs")
|
|
except:
|
|
pass
|
|
logs_output=open('logs/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
|
logs_output.write(Log + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]Save logs successfully.' + '\n' + logs_head + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]The task has done successfully.')
|
|
logs_output.close()
|