Support for classic multiplayer via mpticket

This commit is contained in:
MinecraftZuriki 2017-11-17 02:19:41 +11:00 committed by MinecraftZuriki
parent b000b33661
commit 3470158943

View File

@ -23,9 +23,12 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
public class LegacyFrame extends Frame implements WindowListener
{
@ -48,12 +51,56 @@ public class LegacyFrame extends Frame implements WindowListener
try {
appletWrap = new Launcher( mcApplet, new URL ( "http://www.minecraft.net/game" ) );
} catch ( MalformedURLException ignored ) {}
// 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.
File mpticketFile = null;
Scanner fileReader = null;
try {
mpticketFile = new File(System.getProperty("user.dir") + "/../mpticket").getCanonicalFile();
fileReader = new Scanner(new FileInputStream(mpticketFile), "ascii");
String[] mpticketParams = new String[3];
for(int i=0;i<3;i++) {
if(fileReader.hasNextLine()) {
mpticketParams[i] = fileReader.nextLine();
} else {
throw new IllegalArgumentException();
}
}
// Assumes parameters are valid and in the correct order
appletWrap.setParameter("server", mpticketParams[0]);
appletWrap.setParameter("port", mpticketParams[1]);
appletWrap.setParameter("mppass", mpticketParams[2]);
fileReader.close();
mpticketFile.delete();
}
catch (FileNotFoundException e) {}
catch (IllegalArgumentException e) {
fileReader.close();
File mpticketFileCorrupt = new File(System.getProperty("user.dir") + "/../mpticket.corrupt");
if(mpticketFileCorrupt.exists()) {
mpticketFileCorrupt.delete();
}
mpticketFile.renameTo(mpticketFileCorrupt);
System.err.println("Malformed mpticket file, missing argument.");
e.printStackTrace(System.err);
System.exit(-1);
}
catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
appletWrap.setParameter ( "username", user );
appletWrap.setParameter ( "sessionid", session );
appletWrap.setParameter ( "stand-alone", "true" ); // Show the quit button.
appletWrap.setParameter ( "haspaid", "true" ); // Some old versions need this for world saves to work.
appletWrap.setParameter ( "demo", "false" );
appletWrap.setParameter("fullscreen", "false");
appletWrap.setParameter ( "demo", "false" );
appletWrap.setParameter ( "fullscreen", "false" );
mcApplet.setStub(appletWrap);
this.add ( appletWrap );
appletWrap.setPreferredSize ( new Dimension (winSizeW, winSizeH) );