This repository has been archived on 2020-03-22. You can view files and clone it, but cannot push or open issues/pull-requests.
ThatMinecraftLauncher/earlyLauncher/earlylauncher.py

134 lines
5.2 KiB
Python
Raw Normal View History

2019-07-31 00:39:17 +02:00
#!/usr/bin/python2
2019-08-02 01:22:02 +02:00
#why does the bang not work?
2019-07-31 00:39:17 +02:00
import urllib2, json, os, sys
2019-08-05 01:45:21 +02:00
print "LinuxMint4Ever's EarlyLauncher version BETA 2.3"
#globally used variables
config = []
2019-08-02 01:22:02 +02:00
offlineData = []
main = (__name__ == "__main__")
#When run directly, make sure that we are in the correct directory.
if main:
if os.path.isfile(os.path.join(os.getcwd(), "earlylauncher.py")):
pass
else:
print "Error: Not running from the EarlyLauncher Directory"
sys.exit(1)
def readFile(fileName):
fileReader = open(fileName, "r")
fileContents = fileReader.read()
fileReader.close()
return fileContents
def loadConfig(configFile = "config.txt"):
global config
2019-08-02 01:22:02 +02:00
#read the config file and if run directly, do error handling as well
if main:
try:
configRaw=readFile(configFile).split("\n")
except:
print "Error: Could not read config file."
sys.exit(1)
else:
configRaw=readFile(configFile).split("\n")
2019-08-02 01:22:02 +02:00
#TODO: Raise an exception in case of an error
#put config options and values in a two dimensional list
for i in range(len(configRaw)):
#ignore empty lines and comments
if configRaw[i] == "":
pass
elif configRaw[i][0] == '#':
pass
else:
config = config + [configRaw[i].split("=")]
2019-08-02 01:22:02 +02:00
def loadOfflineData(offlineDataFile = "offline.txt"):
global offlineData
#read the config file and if run directly, do error handling as well
if main:
try:
dataRaw=readFile(offlineDataFile).split("\n")
except:
print "Error: Could not read offline data file."
sys.exit(1)
else:
#TODO: Raise an exception in case of an error
dataRaw=readFile(offlineDataFile).split("\n")
#put config options and values in a two dimensional list
for i in range(len(dataRaw)):
#ignore empty lines and comments
if dataRaw[i] == "":
pass
elif dataRaw[i][0] == '#':
pass
else:
offlineData = offlineData + [dataRaw[i].split("=")]
def getDataOff2DArray(key, array):
2019-08-02 01:36:36 +02:00
for i in range(len(array)):
2019-08-02 01:22:02 +02:00
if array[i][0]==key:
return array[i][1]
def getToken(username, password):
2019-07-31 00:39:17 +02:00
data = {
"agent": {
"name": "Minecraft",
"version": 1
},
"username": username,
"password": password
}
try:
request = urllib2.Request(url='https://authserver.mojang.com/authenticate', data=json.dumps(data).encode(), headers={"Content-Type": "application/json"})
answer = json.loads(urllib2.urlopen(request).read().decode())
2019-08-02 01:36:36 +02:00
except urllib2.HTTPError:
2019-08-02 01:22:02 +02:00
if main:
2019-08-02 01:36:36 +02:00
print "Invalid user information! (or something went wrong)"
sys.exit(1)
2019-08-02 01:22:02 +02:00
else:
#TODO: raise an exception
return False, False, False
2019-08-02 01:36:36 +02:00
except urllib2.URLError:
2019-08-02 01:22:02 +02:00
if main:
2019-08-02 01:36:36 +02:00
print "Authentication server not reachable. Re-launching last user session."
loadOfflineData()
return getDataOff2DArray("access_token", offlineData), getDataOff2DArray("profile_id", offlineData), getDataOff2DArray("username", offlineData)
2019-08-02 01:22:02 +02:00
else:
#TODO: raise an exception
return False, False, False
2019-07-31 00:39:17 +02:00
username = answer['selectedProfile']['name']
access_token = answer['accessToken']
profile_id = answer['selectedProfile']['id']
2019-07-31 00:39:17 +02:00
return access_token, profile_id, username
def run(java_executable, ram, alignTo, libs, username, gameDir, assets, uuid, accessToken):
return(os.system(java_executable+" -Xmx"+ram+alignTo+" -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path="+os.path.join(libs, "natives")+" -cp "+os.path.join(libs,"jar")+os.sep+(":"+os.path.join(libs,"jar")+os.sep).join(os.listdir(os.path.join(libs,"jar")))+" net.minecraft.launchwrapper.Launch --username "+username+" --version 1.7.10-Forge10.13.4.1614-1.7.10 --gameDir "+gameDir+" --assetsDir "+assets+" --assetIndex 1.7.10 --uuid "+str(uuid)+" --accessToken "+accessToken+" --userProperties {} --userType mojang --tweakClass cpw.mods.fml.common.launcher.FMLTweaker"))
2019-07-31 00:39:17 +02:00
if main:
loadConfig()
2019-08-02 01:22:02 +02:00
ram = getDataOff2DArray("ram", config)
alignTo = getDataOff2DArray("alignTo", config)
assets = getDataOff2DArray("assets", config)
gameDir = getDataOff2DArray("gameDir", config)
libs = getDataOff2DArray("libs", config)
2019-08-02 02:45:43 +02:00
java_executable = getDataOff2DArray("java_executable", config)
#TODO: allow the use of sys.argv to override config
2019-07-31 00:39:17 +02:00
2019-08-02 01:22:02 +02:00
login=raw_input("eMail or username: ")
pw=raw_input("Password: ")
2019-08-02 01:22:02 +02:00
accessToken, uuid, username = getToken(str(login), str(pw))
try:
offlineDataFile = open("offline.txt", "w")
offlineDataFile.write("username="+username+"\naccess_token="+accessToken+"\nprofile_id="+uuid)
offlineDataFile.close()
except:
print "Error creating offline login data. Proceeding with launch anyways."
sys.exit(run(java_executable, ram, alignTo, libs, username, gameDir, assets, uuid, accessToken))
2019-08-02 02:45:43 +02:00