diff options
author | cflip <cflip@cflip.net> | 2023-08-24 08:44:43 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2023-08-24 08:44:54 -0600 |
commit | 5a7d6a1d7efb249fe3360330704e8ae647ae3a8f (patch) | |
tree | a00e1965cc5a9788e4229c9ee87f736bc5b6bc71 /src/net/minecraft/LauncherFrame.java |
Import decompiled source from 2010 launcher jar
Diffstat (limited to 'src/net/minecraft/LauncherFrame.java')
-rw-r--r-- | src/net/minecraft/LauncherFrame.java | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/net/minecraft/LauncherFrame.java b/src/net/minecraft/LauncherFrame.java new file mode 100644 index 0000000..9d23071 --- /dev/null +++ b/src/net/minecraft/LauncherFrame.java @@ -0,0 +1,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.excutePost("http://www.minecraft.net/game/getversion.jsp", parameters); + 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); + } +} |