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
134
135
136
137
138
139
140
|
package net.minecraft;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URLEncoder;
public class LauncherFrame extends Frame {
public static final int VERSION = 12;
private static final long serialVersionUID = 1L;
public LauncherFrame() {
super("Minecraft Launcher");
setBackground(Color.BLACK);
this.loginForm = new LoginForm(this);
setLayout(new BorderLayout());
add(this.loginForm, "Center");
this.loginForm.setPreferredSize(new Dimension(854, 480));
pack();
setLocationRelativeTo(null);
try {
setIconImage(ImageIO.read(LauncherFrame.class.getResource("favicon.png")));
} catch (IOException e1) {
e1.printStackTrace();
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
(new Thread() {
public void run() {
try {
Thread.sleep(30000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("FORCING EXIT!");
System.exit(0);
}
}).start();
if (LauncherFrame.this.launcher != null) {
LauncherFrame.this.launcher.stop();
LauncherFrame.this.launcher.destroy();
}
System.exit(0);
}
});
}
private Launcher launcher;
private LoginForm loginForm;
public void playCached(String userName) {
try {
if (userName == null || userName.length() <= 0) {
userName = "Player";
}
this.launcher = new Launcher();
this.launcher.customParameters.put("userName", userName);
this.launcher.init();
removeAll();
add(this.launcher, "Center");
validate();
this.launcher.start();
this.loginForm = null;
setTitle("Minecraft");
} catch (Exception e) {
e.printStackTrace();
showError(e.toString());
}
}
public void login(String userName, String password) {
try {
String parameters = "user=" + URLEncoder.encode(userName, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=" + '\f';
String result = Util.makeDummyAuthString(userName);
if (result == null) {
showError("Can't connect to minecraft.net");
this.loginForm.setNoNetwork();
return;
}
if (!result.contains(":")) {
if (result.trim().equals("Bad login")) {
showError("Login failed");
} else if (result.trim().equals("Old version")) {
this.loginForm.setOutdated();
showError("Outdated launcher");
} else {
showError(result);
}
this.loginForm.setNoNetwork();
return;
}
String[] values = result.split(":");
System.out.println("Username is '" + values[2] + "'");
this.launcher = new Launcher();
this.launcher.customParameters.put("userName", values[2].trim());
this.launcher.customParameters.put("latestVersion", values[0].trim());
this.launcher.customParameters.put("downloadTicket", values[1].trim());
this.launcher.customParameters.put("sessionId", values[3].trim());
this.launcher.init();
removeAll();
add(this.launcher, "Center");
validate();
this.launcher.start();
this.loginForm.loginOk();
this.loginForm = null;
setTitle("Minecraft");
} catch (Exception e) {
e.printStackTrace();
showError(e.toString());
this.loginForm.setNoNetwork();
}
}
private void showError(String error) {
removeAll();
add(this.loginForm);
this.loginForm.setError(error);
validate();
}
public boolean canPlayOffline(String userName) {
Launcher launcher = new Launcher();
launcher.init(userName, null, null, null);
return launcher.canPlayOffline();
}
public static void main(String[] args) {
LauncherFrame launcherFrame = new LauncherFrame();
launcherFrame.setVisible(true);
}
}
|