diff --git a/earlyLauncher/earlylauncher.py b/earlyLauncher/earlylauncher.py old mode 100755 new mode 100644 index db06ff6..ed483fc --- a/earlyLauncher/earlylauncher.py +++ b/earlyLauncher/earlylauncher.py @@ -1,11 +1,12 @@ #!/usr/bin/python2 -#TODO: make the code self-explanatory +#why does the bang not work? import urllib2, json, os, sys print "LinuxMint4Ever's EarlyLauncher version BETA 2.0_002" #globally used variables config = [] +offlineData = [] main = (__name__ == "__main__") #When run directly, make sure that we are in the correct directory. @@ -24,7 +25,7 @@ def readFile(fileName): def loadConfig(configFile = "config.txt"): global config - #read the config file + #read the config file and if run directly, do error handling as well if main: try: configRaw=readFile(configFile).split("\n") @@ -33,6 +34,7 @@ def loadConfig(configFile = "config.txt"): sys.exit(1) else: configRaw=readFile(configFile).split("\n") + #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 @@ -43,6 +45,33 @@ def loadConfig(configFile = "config.txt"): else: config = config + [configRaw[i].split("=")] +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): + for i in range(len(array): + if array[i][0]==key: + return array[i][1] + def getToken(username, password): data = { "agent": { @@ -55,9 +84,21 @@ def getToken(username, 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()) - except: - #TODO: Replace with proper error handling - return False, False, False + except urllib2.URLError: + if main: + print "Authentication server not reachable. Re-launching last user session." + loadOfflineData() + return getDataOff2DArray("access_token", offlineData), getDataOff2DArray("profile_id", offlineData), getDataOff2DArray("username", offlineData) + else: + #TODO: raise an exception + return False, False, False + except urllib2.HTTPError: + if main: + print "Invalid user information! (or something went wrong)" + sys.exit(1) + else: + #TODO: raise an exception + return False, False, False username = answer['selectedProfile']['name'] access_token = answer['accessToken'] @@ -69,13 +110,30 @@ def getToken(username, password): if main: loadConfig() - #TODO: get config values + ram = getDataOff2DArray("ram", config) + alignTo = getDataOff2DArray("alignTo", config) + assets = getDataOff2DArray("assets", config) + gameDir = getDataOff2DArray("gameDir", config) + libs = getDataOff2DArray("libs", config) #TODO: allow the use of sys.argv to override config - name=raw_input("eMail or username: ") + login=raw_input("eMail or username: ") pw=raw_input("Password: ") - #TODO: Use last accesToken in offline situations - accessToken, uuid, username = getToken(str(name), str(pw)) + 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." #TODO: use config (or sys.argv) values - os.system("java -Xmx"+str(ram)+alignTo+" -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path=runningDir/1.7.10-Forge10.13.4.1614-1.7.10-natives-6365946440842 -cp runningDir/libraries/net/minecraftforge/forge/1.7.10-10.13.4.1614-1.7.10/forge-1.7.10-10.13.4.1614-1.7.10.jar;runningDir/libraries/net/minecraft/launchwrapper/1.12/launchwrapper-1.12.jar;runningDir/libraries/org/ow2/asm/asm-all/5.0.3/asm-all-5.0.3.jar;runningDir/libraries/com/typesafe/akka/akka-actor_2.11/2.3.3/akka-actor_2.11-2.3.3.jar;runningDir/libraries/com/typesafe/config/1.2.1/config-1.2.1.jar;runningDir/libraries/org/scala-lang/scala-actors-migration_2.11/1.1.0/scala-actors-migration_2.11-1.1.0.jar;runningDir/libraries/org/scala-lang/scala-compiler/2.11.1/scala-compiler-2.11.1.jar;runningDir/libraries/org/scala-lang/plugins/scala-continuations-library_2.11/1.0.2/scala-continuations-library_2.11-1.0.2.jar;runningDir/libraries/org/scala-lang/plugins/scala-continuations-plugin_2.11.1/1.0.2/scala-continuations-plugin_2.11.1-1.0.2.jar;runningDir/libraries/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar;runningDir/libraries/org/scala-lang/scala-parser-combinators_2.11/1.0.1/scala-parser-combinators_2.11-1.0.1.jar;runningDir/libraries/org/scala-lang/scala-reflect/2.11.1/scala-reflect-2.11.1.jar;runningDir/libraries/org/scala-lang/scala-swing_2.11/1.0.1/scala-swing_2.11-1.0.1.jar;runningDir/libraries/org/scala-lang/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar;runningDir/libraries/lzma/lzma/0.0.1/lzma-0.0.1.jar;runningDir/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar;runningDir/libraries/com/google/guava/guava/17.0/guava-17.0.jar;runningDir/libraries/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar;runningDir/libraries/com/mojang/netty/1.6/netty-1.6.jar;runningDir/libraries/com/mojang/realms/1.3.5/realms-1.3.5.jar;runningDir/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar;runningDir/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar;runningDir/libraries/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar;runningDir/libraries/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar;runningDir/libraries/java3d/vecmath/1.3.1/vecmath-1.3.1.jar;runningDir/libraries/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar;runningDir/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar;runningDir/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar;runningDir/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar;runningDir/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar;runningDir/libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar;runningDir/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar;runningDir/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar;runningDir/libraries/io/netty/netty-all/4.0.10.Final/netty-all-4.0.10.Final.jar;runningDir/libraries/com/google/guava/guava/15.0/guava-15.0.jar;runningDir/libraries/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar;runningDir/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar;runningDir/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar;runningDir/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar;runningDir/libraries/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar;runningDir/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar;runningDir/libraries/com/mojang/authlib/1.5.21/authlib-1.5.21.jar;runningDir/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar;runningDir/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar;runningDir/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar;runningDir/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar;runningDir/libraries/tv/twitch/twitch/5.16/twitch-5.16.jar;runningDir/1.7.10.jar net.minecraft.launchwrapper.Launch --username "+username+" --version 1.7.10-Forge10.13.4.1614-1.7.10 --gameDir runningDir --assetsDir runningDir/assets --assetIndex 1.7.10 --uuid "+str(uuid)+" --accessToken "+str(accessToken)+" --userProperties {} --userType mojang --tweakClass cpw.mods.fml.common.launcher.FMLTweaker") - + #os.system("java -Xmx"+str(ram)+alignTo+" -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path=runningDir/1.7.10-Forge10.13.4.1614-1.7.10-natives-6365946440842 -cp runningDir/libraries/net/minecraftforge/forge/1.7.10-10.13.4.1614-1.7.10/forge-1.7.10-10.13.4.1614-1.7.10.jar;runningDir/libraries/net/minecraft/launchwrapper/1.12/launchwrapper-1.12.jar;runningDir/libraries/org/ow2/asm/asm-all/5.0.3/asm-all-5.0.3.jar;runningDir/libraries/com/typesafe/akka/akka-actor_2.11/2.3.3/akka-actor_2.11-2.3.3.jar;runningDir/libraries/com/typesafe/config/1.2.1/config-1.2.1.jar;runningDir/libraries/org/scala-lang/scala-actors-migration_2.11/1.1.0/scala-actors-migration_2.11-1.1.0.jar;runningDir/libraries/org/scala-lang/scala-compiler/2.11.1/scala-compiler-2.11.1.jar;runningDir/libraries/org/scala-lang/plugins/scala-continuations-library_2.11/1.0.2/scala-continuations-library_2.11-1.0.2.jar;runningDir/libraries/org/scala-lang/plugins/scala-continuations-plugin_2.11.1/1.0.2/scala-continuations-plugin_2.11.1-1.0.2.jar;runningDir/libraries/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar;runningDir/libraries/org/scala-lang/scala-parser-combinators_2.11/1.0.1/scala-parser-combinators_2.11-1.0.1.jar;runningDir/libraries/org/scala-lang/scala-reflect/2.11.1/scala-reflect-2.11.1.jar;runningDir/libraries/org/scala-lang/scala-swing_2.11/1.0.1/scala-swing_2.11-1.0.1.jar;runningDir/libraries/org/scala-lang/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar;runningDir/libraries/lzma/lzma/0.0.1/lzma-0.0.1.jar;runningDir/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar;runningDir/libraries/com/google/guava/guava/17.0/guava-17.0.jar;runningDir/libraries/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar;runningDir/libraries/com/mojang/netty/1.6/netty-1.6.jar;runningDir/libraries/com/mojang/realms/1.3.5/realms-1.3.5.jar;runningDir/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar;runningDir/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar;runningDir/libraries/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar;runningDir/libraries/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar;runningDir/libraries/java3d/vecmath/1.3.1/vecmath-1.3.1.jar;runningDir/libraries/net/sf/trove4j/trove4j/3.0.3/trove4j-3.0.3.jar;runningDir/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar;runningDir/libraries/net/sf/jopt-simple/jopt-simple/4.5/jopt-simple-4.5.jar;runningDir/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar;runningDir/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar;runningDir/libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar;runningDir/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar;runningDir/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar;runningDir/libraries/io/netty/netty-all/4.0.10.Final/netty-all-4.0.10.Final.jar;runningDir/libraries/com/google/guava/guava/15.0/guava-15.0.jar;runningDir/libraries/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar;runningDir/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar;runningDir/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar;runningDir/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar;runningDir/libraries/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar;runningDir/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar;runningDir/libraries/com/mojang/authlib/1.5.21/authlib-1.5.21.jar;runningDir/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar;runningDir/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar;runningDir/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar;runningDir/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar;runningDir/libraries/tv/twitch/twitch/5.16/twitch-5.16.jar;runningDir/1.7.10.jar net.minecraft.launchwrapper.Launch --username "+username+" --version 1.7.10-Forge10.13.4.1614-1.7.10 --gameDir runningDir --assetsDir runningDir/assets --assetIndex 1.7.10 --uuid "+str(uuid)+" --accessToken "+str(accessToken)+" --userProperties {} --userType mojang --tweakClass cpw.mods.fml.common.launcher.FMLTweaker") + #temporary code + print username + print uuid + print accessToken + print ram + print alignTo + print assets + print gameDir + print libs