1

Flare - Minecraft Mod Launcher Creation Log

Scott's Avatar Scott12/21/15 4:01 pm
12/24/2015 5:35 am
Scott's Avatar Scott
Hey guys, Sodex here!
I am the lead developer of the "Flare" minecraft project. We are a group of dedicated people building - from the ground up - a Minecraft Mod Pack friendly launcher. Our aim is to make it fast, easy to use and friendly to modders / pack makers / users. We aim for reliability, working across all platforms. Here you will find my log of code, and achievements. To start it off, here is my (semi) finished log on screen:
Click to reveal
This log on is able to check against the Mojang servers XD Image was to big so just click URL https://i.gyazo.com/9829dcf3307578c322f ... 8a010e.png It looks allright (ish). And for you people who want to see the code here it is LoginScreen.javapackage org.flare.login;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRootPane;
import javax.swing.JTextField;

import org.flare.core.Main;
import org.flare.launcher.Launcher_Main;

public class LoginScreen implements ActionListener{

static JFrame logincore = new JFrame("Flare Launcher");

static JTextField username = new JTextField("");
static JPasswordField password = new JPasswordField("");

public static void loginScreen(){

logincore.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel container = new JPanel();

//Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

logincore.setUndecorated(true);
logincore.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

BackgroundPanel loginscreen = new BackgroundPanel(Main.getBackgroundImage());

//JLabel loginscreen = new JLabel(Main.getBackground());
logincore.add(loginscreen);
loginscreen.setLayout(new GridLayout(1,1));


JLabel text_username = new JLabel("Username: ");
JLabel text_password = new JLabel("Password: ");
JButton login = new JButton("Login to Minecraft!");
login.setActionCommand("LOGIN");
login.addActionListener(new LoginScreen());

text_password.setBackground(Color.WHITE);
text_username.setBackground(Color.WHITE);
login.setBackground(Color.WHITE);

JButton signup = new JButton("Quit");
signup.setActionCommand("QUIT");
signup.addActionListener(new LoginScreen());

signup.setBackground(Color.WHITE);

//ImageIcon icon = new ImageIcon(Main.getPath() + File.separator + "icon_button.png");

//signup.setIcon(icon);

GridBagLayout layout = new GridBagLayout();

container.setLayout(layout);
GridBagConstraints gbc = new GridBagConstraints();

username.setColumns(12);
password.setColumns(12);

gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 1;
gbc.gridy = 0;
container.add(username, gbc);

gbc.gridx = 0;
gbc.gridy = 0;
container.add(text_username, gbc);

gbc.gridx = 0;
gbc.gridy = 1;
container.add(text_password, gbc);

gbc.gridx = 1;
gbc.gridy = 1;
container.add(password, gbc);

gbc.gridx = 1;
gbc.gridy = 2;
container.add(login, gbc);

gbc.gridx = 0;
gbc.gridy = 2;
container.add(signup, gbc);

loginscreen.add(container);
//logincore.setLocation(dim.width/2-logincore.getSize().width/2, dim.height/2-logincore.getSize().height/2);
logincore.setSize(720, 480);
logincore.setResizable(false);
logincore.setVisible(true);
logincore.setLocationRelativeTo(null);

}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand() == "QUIT"){
logincore.setVisible(false);
logincore.dispose();
}else if(e.getActionCommand().equalsIgnoreCase("LOGIN")){

boolean success = false;

try {
URL url = new URL("https://authserver.mojang.com/authenticate");

@SuppressWarnings("deprecation")
String password_string = password.getText();
String username_string = username.getText();

success = Authenticate.httpRequest(url, Authenticate.getJSON(username_string, password_string));
} catch (Exception e1) {
e1.printStackTrace();
}

if(success == true){
System.out.println("Woo! Logged in.");
logincore.setVisible(false);
logincore.dispose();

Launcher_Main.launcherWindow();
}else{
System.out.println("Noo! Failed Loggin.");
JOptionPane.showMessageDialog(null, "Incorrect username/password.");
}

}
}

}
Authentication.javapackage org.flare.login;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONObject;

public class Authenticate {

public static String getJSON(String username, String password){
JSONObject json1 = new JSONObject();
json1.put("name", "Minecraft");
json1.put("version", 1);
JSONObject json = new JSONObject();
json.put("agent", json1);
json.put("username", username);
json.put("password", password);

return json.toString();

}

public static boolean httpRequest(URL url, String content) throws Exception {
byte[] contentBytes = content.getBytes("UTF-8");

URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Length", Integer.toString(contentBytes.length));

OutputStream requestStream = connection.getOutputStream();
requestStream.write(contentBytes, 0, contentBytes.length);
requestStream.close();

String response = "";
BufferedReader responseStream;
if (((HttpURLConnection) connection).getResponseCode() == 200) {
responseStream = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
} else {
responseStream = new BufferedReader(new InputStreamReader(((HttpURLConnection) connection).getErrorStream(), "UTF-8"));
}

response = responseStream.readLine();
responseStream.close();
System.out.println(response);

if (((HttpURLConnection) connection).getResponseCode() != 200) {
//Failed to login (Invalid Credentials or whatever)
return false;
}else{
return true;
}


}

}


#Update 2
Click to reveal
Me and Lorpie (he designed it) have made the home screen for the launcher. https://gyazo.com/5d1de348f0ce8759f0edb274bf6a50ca - its not done my side - I still need to add is some buttons and Labels.


Thanks for reading! I will update this as I code ofc XD
Want to Help?
post3720143.html#p3720143
Posted by Scott's Avatar
Scott
Level 40 : Master Droid
111

Create an account or sign in to comment.

10

1
12/24/2015 5:35 am
Level 40 : Master Droid
Scott
Scott's Avatar
- added update 2
1
12/22/2015 1:26 pm
Level 40 : Master Droid
Scott
Scott's Avatar
Yes please! To apply head over to post3720143.html#p3720143 Thanks
1
12/22/2015 3:02 pm
Level 14 : Journeyman Miner
anonpmc1665509
anonpmc1665509's Avatar
[deleted]
1
12/22/2015 1:20 pm
Level 14 : Journeyman Miner
anonpmc1665509
anonpmc1665509's Avatar
[deleted]
1
12/22/2015 1:10 pm
Level 27 : Expert Creeper Hugger
MCVenomNetwork
MCVenomNetwork's Avatar
I know nothing of java but I can't wait to use this Launcher.
1
12/22/2015 1:16 pm
Level 40 : Master Droid
Scott
Scott's Avatar
Thanks!
1
12/22/2015 7:26 am
Level 40 : Master Droid
Scott
Scott's Avatar
bump
1
12/22/2015 2:50 am
Level 40 : Master Droid
Scott
Scott's Avatar
Is it? Lol I didn't know - I don't use Hacked Clients
1
12/21/2015 5:38 pm
Level 23 : Expert Modder
SirBlobman
SirBlobman's Avatar
Is it strange that Flare is also the name of a Premium Hacked Client?
1
12/22/2015 4:22 am
Level 56 : Grandmaster Architect
TotallyNotMe
TotallyNotMe's Avatar
Never seen that! Oh well, we'll still be sticking to this name
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome