Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.procyx.mc.launcher.iyc;
- import com.google.gson.JsonObject;
- import fr.procyx.cyxapi.DebugSystem;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.net.URLConnection;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import javafx.application.Application;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Node;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import javafx.scene.image.ImageView;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.input.PickResult;
- import javafx.scene.layout.Pane;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- import javax.swing.JFrame;
- import javax.swing.JTextArea;
- public final class IycLauncher extends Application
- {
- private static final String FX_TRANSPARENT = "-fx-background-color: transparent;";
- public static void main(String[] args)
- {
- launch(args);
- }
- public void start(Stage s) throws Exception
- {
- initDebuger();
- Pane pane = new Pane();
- ImageView imgv = JavaFxUtils.getInstance().getImageView("bg.png");
- Button exit = new Button();
- exit.setPrefWidth(30.0D);
- exit.setPrefHeight(30.0D);
- exit.setStyle("-fx-background-color: transparent;");
- exit.relocate(370.0D, 0.0D);
- Button back = new Button();
- back.setPrefWidth(30.0D);
- back.setPrefHeight(30.0D);
- back.setStyle("-fx-background-color: transparent;");
- back.relocate(340.0D, 0.0D);
- Button co = new Button();
- co.setPrefWidth(200.0D);
- co.setPrefHeight(50.0D);
- co.setStyle("-fx-background-color: transparent;");
- co.relocate(100.0D, 370.0D);
- TextField user = new TextField();
- user.relocate(100.0D, 195.0D);
- user.setPrefWidth(200.0D);
- user.setStyle("-fx-background-color: transparent; -fx-text-fill: white; -fx-text-alignment: center;");
- user.setPrefHeight(20.0D);
- user.setFont(JavaFxUtils.getInstance().getFont("seguiemj.ttf", 15.0D));
- PasswordField pass = new PasswordField();
- pass.relocate(100.0D, 268.0D);
- pass.setPrefWidth(200.0D);
- pass.setStyle("-fx-background-color: transparent; -fx-text-fill: white; -fx-text-alignment: center;");
- pass.setPrefHeight(20.0D);
- CheckBox c = new CheckBox();
- c.relocate(85.0D, 320.0D);
- s.initStyle(StageStyle.UNDECORATED);
- EventHandler myHandler = new EventHandler(exit, back, s, co, user, pass)
- {
- public void handle(ActionEvent event) {
- if (event.getSource() == this.val$exit)
- System.exit(0);
- if (event.getSource() == this.val$back)
- this.val$s.toBack();
- if (event.getSource() == this.val$co)
- IycLauncher.this.auth(this.val$user.getText(), this.val$pass.getText());
- }
- };
- EventHandler hover = new EventHandler()
- {
- public void handle(MouseEvent e)
- {
- }
- };
- EventHandler exitM = new EventHandler()
- {
- public void handle(MouseEvent e)
- {
- e.getPickResult().getIntersectedNode().setStyle("-fx-background-color: transparent;");
- }
- };
- exit.setOnAction(myHandler);
- exit.addEventHandler(MouseEvent.MOUSE_EXITED, exitM);
- back.setOnAction(myHandler);
- back.addEventHandler(MouseEvent.MOUSE_EXITED, exitM);
- co.setOnAction(myHandler);
- co.addEventHandler(MouseEvent.MOUSE_ENTERED, hover);
- co.addEventHandler(MouseEvent.MOUSE_EXITED, exitM);
- pane.getChildren().addAll(new Node[] { imgv, exit, back, co, user, pass, c });
- s.setScene(new Scene(pane));
- s.sizeToScene();
- s.show();
- }
- private void auth(String username, String password)
- {
- if ((username == null) || (username.length() == 0) || (username.contains(" "))) { System.out.println("Username = malformed"); return; }
- if ((password == null) || (password.length() == 0) || (password.contains(" "))) { System.out.println("Password = malformed"); return; }
- System.out.println("Auth -> " + username);
- System.out.println("Creating request...");
- JsonObject d = new JsonObject();
- d.addProperty("user", username);
- System.out.println("Hash Pass -> " + stringToSha512(password));
- d.addProperty("pass", stringToSha512(password));
- d.addProperty("ip", "localhost");
- System.out.println("Json Request: ");
- System.out.println(d.toString());
- System.out.println("Sending request...");
- String response = null;
- try {
- response = sendHttpRequest(new URL(readToString("http://download1513.mediafire.com/d426xcc1vhmg/2k0o9szkwyxbugv/requete.txt")), d.toString());
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println("Response = " + response);
- contactDownloader();
- }
- private String sendHttpRequest(URL url, String content) throws IOException
- {
- System.out.println("Request URL -> " + url);
- 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();
- BufferedReader responseStream;
- if (((HttpURLConnection)connection).getResponseCode() == 200)
- responseStream = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
- else
- return null;
- BufferedReader responseStream;
- String response = responseStream.readLine();
- responseStream.close();
- return response;
- }
- private String readToString(String targetURL) throws IOException
- {
- URL url = new URL(targetURL);
- BufferedReader bufferedReader = new BufferedReader(
- new InputStreamReader(url.openStream()));
- StringBuilder stringBuilder = new StringBuilder();
- String inputLine;
- while ((inputLine = bufferedReader.readLine()) != null)
- {
- String inputLine;
- stringBuilder.append(inputLine);
- stringBuilder.append(System.lineSeparator());
- }
- bufferedReader.close();
- return stringBuilder.toString().trim();
- }
- private String stringToSha512(String passwordToHash)
- {
- String generatedPassword = null;
- try
- {
- MessageDigest md = MessageDigest.getInstance("SHA-512");
- md.update(passwordToHash.getBytes());
- byte[] bytes = md.digest();
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < bytes.length; i++) {
- sb.append(Integer.toString((bytes[i] & 0xFF) + 256, 16).substring(1));
- }
- generatedPassword = sb.toString();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }return generatedPassword;
- }
- private void initDebuger()
- {
- JFrame debug = new JFrame();
- debug.setSize(500, 500);
- JTextArea a = new JTextArea();
- System.setOut(new PrintStream(new DebugSystem(a)));
- debug.add(a);
- debug.setVisible(true);
- System.out.println("IYC Debuger - Inititalized");
- }
- private void contactDownloader()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement