@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher
|
||||
*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
|
||||
* Copyright (C) 2022 flow <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||
@ -55,13 +54,6 @@
|
||||
|
||||
package org.prismlauncher.launcher.impl.legacy;
|
||||
|
||||
import net.minecraft.Launcher;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
@ -75,6 +67,13 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.prismlauncher.utils.logging.Log;
|
||||
|
||||
import net.minecraft.Launcher;
|
||||
|
||||
public final class LegacyFrame extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -84,85 +83,85 @@ public final class LegacyFrame extends JFrame {
|
||||
public LegacyFrame(String title, Applet applet) {
|
||||
super(title);
|
||||
|
||||
this.launcher = new Launcher(applet);
|
||||
launcher = new Launcher(applet);
|
||||
|
||||
applet.setStub(this.launcher);
|
||||
applet.setStub(launcher);
|
||||
|
||||
try {
|
||||
this.setIconImage(ImageIO.read(new File("icon.png")));
|
||||
setIconImage(ImageIO.read(new File("icon.png")));
|
||||
} catch (IOException e) {
|
||||
Log.error("Unable to read Minecraft icon", e);
|
||||
Log.error("Failed to read window icon", e);
|
||||
}
|
||||
|
||||
this.addWindowListener(new ForceExitHandler());
|
||||
addWindowListener(new ForceExitHandler());
|
||||
}
|
||||
|
||||
public void start(String user, String session, int width, int height, boolean maximize, String serverAddress,
|
||||
String serverPort, boolean isDemo) {
|
||||
String serverPort, boolean demo) {
|
||||
// Implements support for launching in to multiplayer on classic servers using a
|
||||
// mpticket
|
||||
// file generated by an external program and stored in the instance's root
|
||||
// folder.
|
||||
// mpticket file generated by an external program and stored in the instance's
|
||||
// root folder.
|
||||
Path instanceFolder = Paths.get("..");
|
||||
Path mpticket = instanceFolder.resolve("mpticket");
|
||||
Path mpticketCorrupt = instanceFolder.resolve("mpticket.corrupt");
|
||||
|
||||
Path mpticketFile = Paths.get(System.getProperty("user.dir"), "..", "mpticket");
|
||||
|
||||
Path mpticketFileCorrupt = Paths.get(System.getProperty("user.dir"), "..", "mpticket.corrupt");
|
||||
|
||||
if (Files.exists(mpticketFile)) {
|
||||
if (Files.exists(mpticket)) {
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(mpticketFile, StandardCharsets.UTF_8);
|
||||
List<String> lines = Files.readAllLines(mpticket, StandardCharsets.UTF_8);
|
||||
|
||||
if (lines.size() < 3) {
|
||||
Files.move(mpticketFile, mpticketFileCorrupt, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.move(mpticket, mpticketCorrupt, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
Log.warning("Mpticket file is corrupted!");
|
||||
Log.warning("mpticket file is corrupted");
|
||||
} else {
|
||||
// Assumes parameters are valid and in the correct order
|
||||
this.launcher.setParameter("server", lines.get(0));
|
||||
this.launcher.setParameter("port", lines.get(1));
|
||||
this.launcher.setParameter("mppass", lines.get(2));
|
||||
launcher.setParameter("server", lines.get(0));
|
||||
launcher.setParameter("port", lines.get(1));
|
||||
launcher.setParameter("mppass", lines.get(2));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error("Unable to read mpticket file", e);
|
||||
Log.error("Failed to read mpticket file", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (serverAddress != null) {
|
||||
this.launcher.setParameter("server", serverAddress);
|
||||
this.launcher.setParameter("port", serverPort);
|
||||
launcher.setParameter("server", serverAddress);
|
||||
launcher.setParameter("port", serverPort);
|
||||
}
|
||||
|
||||
this.launcher.setParameter("username", user);
|
||||
this.launcher.setParameter("sessionid", session);
|
||||
this.launcher.setParameter("stand-alone", "true"); // Show the quit button. TODO: why won't this work?
|
||||
this.launcher.setParameter("haspaid", "true"); // Some old versions need this for world saves to work.
|
||||
this.launcher.setParameter("demo", isDemo ? "true" : "false");
|
||||
this.launcher.setParameter("fullscreen", "false");
|
||||
launcher.setParameter("username", user);
|
||||
launcher.setParameter("sessionid", session);
|
||||
launcher.setParameter("stand-alone", true); // Show the quit button. TODO: why won't this work?
|
||||
launcher.setParameter("haspaid", true); // Some old versions need this for world saves to work.
|
||||
launcher.setParameter("demo", demo);
|
||||
launcher.setParameter("fullscreen", false);
|
||||
|
||||
this.add(this.launcher);
|
||||
add(launcher);
|
||||
|
||||
this.launcher.setPreferredSize(new Dimension(width, height));
|
||||
launcher.setPreferredSize(new Dimension(width, height));
|
||||
|
||||
this.pack();
|
||||
pack();
|
||||
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setResizable(true);
|
||||
setLocationRelativeTo(null);
|
||||
setResizable(true);
|
||||
|
||||
if (maximize)
|
||||
setExtendedState(MAXIMIZED_BOTH);
|
||||
|
||||
this.validate();
|
||||
validate();
|
||||
|
||||
this.launcher.init();
|
||||
this.launcher.start();
|
||||
launcher.init();
|
||||
launcher.start();
|
||||
|
||||
this.setVisible(true);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private final class ForceExitHandler extends WindowAdapter {
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent event) {
|
||||
// FIXME better solution
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -177,9 +176,9 @@ public final class LegacyFrame extends JFrame {
|
||||
}
|
||||
}).start();
|
||||
|
||||
if (LegacyFrame.this.launcher != null) {
|
||||
LegacyFrame.this.launcher.stop();
|
||||
LegacyFrame.this.launcher.destroy();
|
||||
if (launcher != null) {
|
||||
launcher.stop();
|
||||
launcher.destroy();
|
||||
}
|
||||
|
||||
// old minecraft versions can hang without this >_<
|
||||
|
Reference in New Issue
Block a user