2014-05-07 02:08:28 +05:30
|
|
|
package org.multimc;/*
|
2018-02-11 05:10:01 +05:30
|
|
|
* Copyright 2012-2018 MultiMC Contributors
|
2014-01-09 05:52:34 +05:30
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2013-01-11 06:55:40 +05:30
|
|
|
|
|
|
|
import net.minecraft.Launcher;
|
2014-01-09 05:52:34 +05:30
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
2013-01-11 06:55:40 +05:30
|
|
|
import java.applet.Applet;
|
2014-01-09 05:52:34 +05:30
|
|
|
import java.awt.*;
|
2013-01-11 06:55:40 +05:30
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import java.awt.event.WindowListener;
|
2014-01-09 05:52:34 +05:30
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.File;
|
2017-11-16 20:49:41 +05:30
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
2014-01-09 05:52:34 +05:30
|
|
|
import java.io.IOException;
|
2013-01-11 06:55:40 +05:30
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2017-11-16 20:49:41 +05:30
|
|
|
import java.util.Scanner;
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2014-01-09 05:52:34 +05:30
|
|
|
public class LegacyFrame extends Frame implements WindowListener
|
2013-01-11 06:55:40 +05:30
|
|
|
{
|
2013-11-04 07:23:05 +05:30
|
|
|
private Launcher appletWrap = null;
|
2014-01-09 05:52:34 +05:30
|
|
|
public LegacyFrame(String title)
|
2013-11-04 07:23:05 +05:30
|
|
|
{
|
|
|
|
super ( title );
|
2014-01-09 05:52:34 +05:30
|
|
|
BufferedImage image;
|
2013-11-04 07:23:05 +05:30
|
|
|
try {
|
|
|
|
image = ImageIO.read ( new File ( "icon.png" ) );
|
|
|
|
setIconImage ( image );
|
|
|
|
} catch ( IOException e ) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
this.addWindowListener ( this );
|
|
|
|
}
|
|
|
|
|
2017-10-29 16:54:49 +05:30
|
|
|
public void start ( Applet mcApplet, String user, String session, int winSizeW, int winSizeH, boolean maximize )
|
2013-11-04 07:23:05 +05:30
|
|
|
{
|
|
|
|
try {
|
2014-01-09 05:52:34 +05:30
|
|
|
appletWrap = new Launcher( mcApplet, new URL ( "http://www.minecraft.net/game" ) );
|
2013-11-04 07:23:05 +05:30
|
|
|
} catch ( MalformedURLException ignored ) {}
|
2017-11-16 20:49:41 +05:30
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
2013-11-04 07:23:05 +05:30
|
|
|
appletWrap.setParameter ( "username", user );
|
|
|
|
appletWrap.setParameter ( "sessionid", session );
|
|
|
|
appletWrap.setParameter ( "stand-alone", "true" ); // Show the quit button.
|
2017-09-21 03:27:20 +05:30
|
|
|
appletWrap.setParameter ( "haspaid", "true" ); // Some old versions need this for world saves to work.
|
2017-11-16 20:49:41 +05:30
|
|
|
appletWrap.setParameter ( "demo", "false" );
|
|
|
|
appletWrap.setParameter ( "fullscreen", "false" );
|
2014-01-09 05:52:34 +05:30
|
|
|
mcApplet.setStub(appletWrap);
|
2013-11-04 07:23:05 +05:30
|
|
|
this.add ( appletWrap );
|
2017-10-29 16:54:49 +05:30
|
|
|
appletWrap.setPreferredSize ( new Dimension (winSizeW, winSizeH) );
|
2013-11-04 07:23:05 +05:30
|
|
|
this.pack();
|
|
|
|
this.setLocationRelativeTo ( null );
|
|
|
|
this.setResizable ( true );
|
|
|
|
if ( maximize ) {
|
|
|
|
this.setExtendedState ( MAXIMIZED_BOTH );
|
|
|
|
}
|
|
|
|
validate();
|
|
|
|
appletWrap.init();
|
|
|
|
appletWrap.start();
|
|
|
|
setVisible ( true );
|
|
|
|
}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowActivated ( WindowEvent e ) {}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowClosed ( WindowEvent e ) {}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowClosing ( WindowEvent e )
|
|
|
|
{
|
|
|
|
new Thread() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
Thread.sleep ( 30000L );
|
|
|
|
} catch ( InterruptedException localInterruptedException ) {
|
|
|
|
localInterruptedException.printStackTrace();
|
|
|
|
}
|
|
|
|
System.out.println ( "FORCING EXIT!" );
|
|
|
|
System.exit ( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.start();
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
if ( appletWrap != null ) {
|
|
|
|
appletWrap.stop();
|
|
|
|
appletWrap.destroy();
|
|
|
|
}
|
|
|
|
// old minecraft versions can hang without this >_<
|
|
|
|
System.exit ( 0 );
|
|
|
|
}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowDeactivated ( WindowEvent e ) {}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowDeiconified ( WindowEvent e ) {}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowIconified ( WindowEvent e ) {}
|
2013-01-11 06:55:40 +05:30
|
|
|
|
2013-11-04 07:23:05 +05:30
|
|
|
@Override
|
|
|
|
public void windowOpened ( WindowEvent e ) {}
|
|
|
|
}
|