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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
package net.minecraft;
import javax.imageio.ImageIO;
import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.*;
import java.awt.image.VolatileImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
public class Launcher extends Applet implements Runnable, AppletStub {
public Map<String, String> customParameters = new HashMap<>();
private static final long serialVersionUID = 1L;
private GameUpdater gameUpdater;
private boolean gameUpdaterStarted = false;
private Applet applet;
private Image bgImage;
private boolean active = false;
private int context = 0;
private VolatileImage img;
private VersionManager versionManager;
private GameVersion latestVersion;
public boolean isActive() {
if (this.context == 0) {
this.context = -1;
try {
if (getAppletContext() != null) this.context = 1;
} catch (Exception exception) {
}
}
if (this.context == -1) return this.active;
return super.isActive();
}
public void init(String userName, String latestVersion, String downloadTicket, String sessionId) {
try {
this.bgImage = ImageIO.read(LoginForm.class.getResource("dirt.png")).getScaledInstance(32, 32, 16);
} catch (IOException e) {
e.printStackTrace();
}
this.customParameters.put("username", userName);
this.customParameters.put("sessionid", sessionId);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2010);
this.versionManager = new VersionManager();
this.latestVersion = versionManager.getVersionForInstant(calendar.toInstant());
this.gameUpdater = new GameUpdater(this.latestVersion);
}
public boolean canPlayOffline() {
return this.gameUpdater.canPlayOffline();
}
public void init() {
if (this.applet != null) {
this.applet.init();
return;
}
init(getParameter("userName"), getParameter("latestVersion"), getParameter("downloadTicket"), getParameter("sessionId"));
}
public void start() {
if (this.applet != null) {
this.applet.start();
return;
}
if (this.gameUpdaterStarted)
return;
Thread t = new Thread() {
public void run() {
Launcher.this.gameUpdater.run();
try {
if (!Launcher.this.gameUpdater.fatalError) {
System.setProperty("http.proxyHost", "betacraft.uk");
System.setProperty("http.proxyPort", String.valueOf(latestVersion.proxyPort));
Launcher.this.replace(Launcher.this.gameUpdater.createApplet());
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
};
t.setDaemon(true);
t.start();
t = new Thread() {
public void run() {
while (Launcher.this.applet == null) {
Launcher.this.repaint();
try {
Thread.sleep(10L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.setDaemon(true);
t.start();
this.gameUpdaterStarted = true;
}
public void stop() {
if (this.applet != null) {
this.active = false;
this.applet.stop();
}
}
public void destroy() {
if (this.applet != null) {
this.applet.destroy();
}
}
public void replace(Applet applet) {
this.applet = applet;
applet.setStub(this);
applet.setSize(getWidth(), getHeight());
setLayout(new BorderLayout());
add(applet, "Center");
applet.init();
this.active = true;
applet.start();
validate();
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g2) {
if (this.applet != null)
return;
int w = getWidth() / 2;
int h = getHeight() / 2;
if (this.img == null || this.img.getWidth() != w || this.img.getHeight() != h) {
this.img = createVolatileImage(w, h);
}
Graphics g = this.img.getGraphics();
for (int x = 0; x <= w / 32; x++) {
for (int y = 0; y <= h / 32; y++)
g.drawImage(this.bgImage, x * 32, y * 32, null);
}
g.setColor(Color.LIGHT_GRAY);
String msg = "Updating Minecraft";
if (this.gameUpdater.fatalError) {
msg = "Failed to launch";
}
g.setFont(new Font(null, 1, 20));
FontMetrics fm = g.getFontMetrics();
g.drawString(msg, w / 2 - fm.stringWidth(msg) / 2, h / 2 - fm.getHeight() * 2);
g.setFont(new Font(null, 0, 12));
fm = g.getFontMetrics();
msg = this.gameUpdater.getDescriptionForState();
if (this.gameUpdater.fatalError) {
msg = this.gameUpdater.fatalErrorDescription;
}
g.drawString(msg, w / 2 - fm.stringWidth(msg) / 2, h / 2 + fm.getHeight());
msg = this.gameUpdater.subtaskMessage;
g.drawString(msg, w / 2 - fm.stringWidth(msg) / 2, h / 2 + fm.getHeight() * 2);
if (!this.gameUpdater.fatalError) {
g.setColor(Color.black);
g.fillRect(64, h - 64, w - 128 + 1, 5);
g.setColor(new Color(32768));
g.fillRect(64, h - 64, this.gameUpdater.percentage * (w - 128) / 100, 4);
g.setColor(new Color(2138144));
g.fillRect(65, h - 64 + 1, this.gameUpdater.percentage * (w - 128) / 100 - 2, 1);
}
g.dispose();
g2.drawImage(this.img, 0, 0, w * 2, h * 2, null);
}
public void run() {
}
public String getParameter(String name) {
String custom = this.customParameters.get(name);
if (custom != null) return custom;
try {
return super.getParameter(name);
} catch (Exception e) {
this.customParameters.put(name, null);
return null;
}
}
public void appletResize(int width, int height) {
}
public URL getDocumentBase() {
try {
return new URL("http://www.minecraft.net/game/");
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
}
|