Support for classic multiplayer via mpticket
This commit is contained in:
parent
b000b33661
commit
3470158943
@ -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,6 +51,50 @@ 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.
|
||||
|
Loading…
Reference in New Issue
Block a user