Add Clean Server/Client launcher. Update Start.java to new Main class and login system.
This commit is contained in:
parent
da8fb7f8a0
commit
028c77c3a0
4 changed files with 92 additions and 52 deletions
|
@ -5,75 +5,110 @@ import java.lang.reflect.Field;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
|
||||
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.main.Main;
|
||||
|
||||
public class Start
|
||||
{
|
||||
public static void main(String[] args)
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
int userIndex = -1;
|
||||
int passIndex = -1;
|
||||
int sessIndex = -1;
|
||||
int versIndex = -1;
|
||||
|
||||
for( int x = 0; x < args.length; x++)
|
||||
{
|
||||
if (args[x].equals("--username")) userIndex = x + 1;
|
||||
else if (args[x].equals("--password")) passIndex = x + 1;
|
||||
else if (args[x].equals("--session")) sessIndex = x + 1;
|
||||
else if (args[x].equals("--version")) versIndex = x + 1;
|
||||
}
|
||||
|
||||
if (userIndex != 0-1 && passIndex != -1 && sessIndex == -1)
|
||||
{
|
||||
String[] session = getSession(args[userIndex], args[passIndex]);
|
||||
if (session != null)
|
||||
{
|
||||
args[userIndex] = session[0];
|
||||
args = concat(args, new String[]{"--session", session[1]});
|
||||
}
|
||||
}
|
||||
|
||||
//Kill the password if its there so it isn't printed to the console.
|
||||
if (passIndex != -1)
|
||||
{
|
||||
args[passIndex-1] = "no_password_for_joo";
|
||||
args[passIndex] = "no_password_for_joo";
|
||||
}
|
||||
|
||||
if (versIndex == -1)
|
||||
{
|
||||
args = concat(args, new String[]{ "--version", "fml_mcp" });
|
||||
}
|
||||
|
||||
Main.main(args);
|
||||
}
|
||||
|
||||
private static String[] getSession(String username, String password) throws UnsupportedEncodingException
|
||||
{
|
||||
String parameters = "http://login.minecraft.net/?user=" + URLEncoder.encode(username, "UTF-8") +
|
||||
"&password=" + URLEncoder.encode(password, "UTF-8") +
|
||||
"&version=" + 13;
|
||||
String result = openUrl(parameters);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
System.out.println("Can't connect to minecraft.net");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!result.contains(":"))
|
||||
{
|
||||
System.out.println("Login Failed: " + result);
|
||||
return null;
|
||||
}
|
||||
String[] values = result.split(":");
|
||||
return new String[]{ values[2].trim(), values[3].trim() };
|
||||
}
|
||||
|
||||
private static String openUrl(String addr)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = Minecraft.class.getDeclaredField("field_71463_am");
|
||||
Field.setAccessible(new Field[] { f }, true);
|
||||
f.set(null, new File("."));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (args.length != 2)
|
||||
{
|
||||
Minecraft.main(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
String parameters = "http://login.minecraft.net/?user=" + URLEncoder.encode(args[0], "UTF-8") +
|
||||
"&password=" + URLEncoder.encode(args[1], "UTF-8") +
|
||||
"&version=" + 13;
|
||||
String result = openUrl(parameters);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
System.out.println("Can't connect to minecraft.net");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.contains(":"))
|
||||
{
|
||||
System.out.println("Login Failed: " + result);
|
||||
return;
|
||||
}
|
||||
//latestVersion, downloadTicket, userName, sessionId
|
||||
String[] values = result.split(":");
|
||||
Minecraft.main(new String[]{values[2].trim(), values[3].trim()});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String openUrl(String addr)
|
||||
{
|
||||
try {
|
||||
URL url = new URL(addr);
|
||||
java.io.InputStream is;
|
||||
is = url.openConnection().getInputStream();
|
||||
|
||||
java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(is));
|
||||
String buf = "";
|
||||
String line = null;
|
||||
while((line = reader.readLine() ) != null)
|
||||
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
buf += "\n" + line;
|
||||
buf += "\n" + line;
|
||||
}
|
||||
|
||||
reader.close();
|
||||
return buf;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <T> T[] concat(T[] first, T[] second)
|
||||
{
|
||||
T[] result = Arrays.copyOf(first, first.length + second.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
return result;
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -20,17 +20,17 @@
|
|||
<classpathentry kind="lib" path="jars/libraries/com/google/code/gson/gson/2.2.2/gson-2.2.2.jar" />
|
||||
<classpathentry kind="lib" path="jars/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="FML/libraries/natives"/>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Minecraft/natives"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="jars/libraries/org/lwjgl/lwjgl/lwjgl/2.9.0/lwjgl-2.9.0.jar">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="FML/libraries/natives"/>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Minecraft/natives"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="jars/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.0/lwjgl_util-2.9.0.jar">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="FML/libraries/natives"/>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Minecraft/natives"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
</classpath>
|
||||
|
|
|
@ -30,6 +30,11 @@
|
|||
<type>2</type>
|
||||
<locationURI>MCP_LOC/lib</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>natives</name>
|
||||
<type>2</type>
|
||||
<locationURI>MCP_LOC/jars/libraries/natives</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
|
|
Loading…
Reference in a new issue