Start.java
3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.mumfrey.liteloader.debug;
import java.io.File;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import net.minecraft.hopper.Util;
import net.minecraft.launcher.authentication.yggdrasil.AuthenticationResponse;
import net.minecraft.launchwrapper.Launch;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import com.mumfrey.liteloader.launch.LiteLoaderTweaker;
/**
* Wrapper class for LaunchWrapper Main class, which logs into minecraft.net first so that online shizzle can be tested
*
* @author Adam Mummery-Smith
* @version 0.5
*/
public abstract class Start
{
/**
* Username specified on the command line
*/
private static String userName = "";
/**
* Session ID retrieved during login ("-" means no session, eg. offline)
*/
private static String sessionId = "-";
/**
* Entry point. Validates the parameters and performs the login
*
* @param args
*/
public static void main(String[] args)
{
// Check we have enough arguments
if (args.length < 2)
{
Start.showError("Invalid parameters specified for start, use: <username> <password> to log in to minecraft.net");
userName = args.length < 1 ? System.getProperty("user.name") : args[0];
}
else
{
// Assign username as the first argument
userName = args[0];
// Perform the login if the second parameter is not "-" (indicating offline)
if (!args[1].equals("-") && Start.login(args[0], args[1], 13, true))
{
Start.showMessage(String.format("Successfully logged in as %s with session ID %s", userName, sessionId));
args[0] = userName;
args[1] = sessionId;
}
}
Start.showMessage(String.format("Launching game as %s", userName));
File gameDir = new File(System.getProperty("user.dir"));
File assetsDir = new File(gameDir, "assets");
args = new String[] {
"--tweakClass", LiteLoaderTweaker.class.getName(),
"--username", userName,
"--session", sessionId,
"--version", "mcp",
"--gameDir", gameDir.getAbsolutePath(),
"--assetsDir", assetsDir.getAbsolutePath()
};
Launch.main(args);
}
private static boolean login(String user, String password, int masqueradeLauncherVersion, boolean validateCertificate)
{
try
{
AuthenticationResponse response = Start.authRequest(user, password);
if (response != null)
{
userName = response.getSelectedProfile().getName();
sessionId = String.format("token:%s:%s", response.getAccessToken(), response.getSelectedProfile().getId());
return true;
}
}
catch (Exception ex) {}
return false;
}
protected static AuthenticationResponse authRequest(String user, String password) throws IOException
{
Gson gson = new Gson();
AuthenticationRequest request = new AuthenticationRequest(user, password);
URL authUrl = new URL("https://authserver.mojang.com/authenticate");
String json = Util.performPost(authUrl, gson.toJson(request), Proxy.NO_PROXY, "application/json", true);
AuthenticationResponse result = gson.fromJson(json, AuthenticationResponse.class);
if (result != null)
{
if (StringUtils.isBlank(result.getError()))
return result;
Start.showError(result.getErrorMessage());
}
return null;
}
/**
* Show a message on stdout
*
* @param message
*/
private static void showMessage(String message)
{
System.out.println("[START] [INFO] " + message);
}
/**
* Show a message on stderr
*
* @param message
*/
private static void showError(String message)
{
System.err.println("[START] [ERROR] " + message);
}
}