Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. package fr.nathanael2611.projectz.launcher;
  2.  
  3. import fr.nathanael2611.nlib.NLib;
  4. import fr.theshark34.openauth.AuthenticationException;
  5. import fr.theshark34.openlauncherlib.LaunchException;
  6. import fr.theshark34.openlauncherlib.util.Saver;
  7. import fr.theshark34.openlauncherlib.util.ramselector.RamSelector;
  8. import fr.theshark34.swinger.Swinger;
  9. import fr.theshark34.swinger.colored.SColoredBar;
  10. import fr.theshark34.swinger.colored.SColoredButton;
  11. import fr.theshark34.swinger.event.SwingerEvent;
  12. import fr.theshark34.swinger.event.SwingerEventListener;
  13. import fr.theshark34.swinger.textured.STexturedButton;
  14. import fr.theshark34.swinger.textured.STexturedProgressBar;
  15. import sun.awt.image.PixelConverter;
  16.  
  17. import javax.swing.*;
  18. import java.applet.Applet;
  19. import java.applet.AudioClip;
  20. import java.awt.*;
  21. import java.awt.image.BufferedImage;
  22. import java.io.*;
  23. import java.net.URL;
  24. import java.nio.Buffer;
  25.  
  26. public class LauncherPanel extends JPanel implements SwingerEventListener {
  27.  
  28.  
  29.  
  30.  
  31.  
  32. private Image background = Swinger.getResource("background.png");
  33.  
  34.  
  35.  
  36.  
  37.  
  38. private Saver saver = new Saver(new File(Launcher.PZ_DIR, "launcher.properties"));
  39.  
  40.  
  41.  
  42. private JTextField usernameField = new JTextField();
  43.  
  44. private JPasswordField passwordField = new JPasswordField(saver.get("mdp"));
  45.  
  46.  
  47. private JTextField userField = new JTextField();
  48.  
  49.  
  50.  
  51. private SColoredButton playButton = new SColoredButton(Swinger.TRANSPARENT);
  52. private SColoredButton ramButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
  53. private SColoredButton closeButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
  54. private SColoredButton reducButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
  55. /*private SColoredButton discordButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
  56. private SColoredButton webButton = new SColoredButton(Swinger.TRANSPARENT, Swinger.TRANSPARENT);
  57. */
  58.  
  59. private SColoredBar pb = new SColoredBar(new Color(100, 100, 100, 10), new Color(171, 34, 33));
  60.  
  61. private Image crackon = Swinger.getResource("crackon.png");
  62. private Image crackoff = Swinger.getResource("crackoff.png");
  63. private STexturedButton crackbutton = new STexturedButton((BufferedImage) crackoff, (BufferedImage)crackoff);
  64.  
  65.  
  66.  
  67. private RamSelector ramSelector = new RamSelector(new File(Launcher.PZ_DIR, "ram.txt"));
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. public LauncherPanel() {
  75.  
  76.  
  77. File iscrackfile = new File(Launcher.PZ_DIR, "iscrack.txt");
  78. String iscrackvalue = "";
  79.  
  80. try
  81. {
  82.  
  83. BufferedInputStream in = new BufferedInputStream(new FileInputStream(iscrackfile));
  84. StringWriter out = new StringWriter();
  85. int b;
  86. while ((b=in.read()) != -1)
  87. out.write(b);
  88. out.flush();
  89. out.close();
  90. in.close();
  91. iscrackvalue = out.toString();
  92.  
  93.  
  94. }
  95. catch (FileNotFoundException exception)
  96. {
  97. System.out.println ("Le fichier n'a pas été trouvé");
  98. } catch (IOException e) {
  99. e.printStackTrace();
  100. }
  101.  
  102. crackbutton.setBounds(0, 5, 150, 29);
  103. crackbutton.addEventListener(this);
  104. this.add(crackbutton);
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. this.setBackground(Swinger.TRANSPARENT);
  113.  
  114. this.setLayout(null);
  115.  
  116.  
  117. usernameField.setForeground(Color.WHITE);
  118. usernameField.setFont(usernameField.getFont().deriveFont(20F));
  119. usernameField.setCaretColor(Color.WHITE);
  120. usernameField.setOpaque(false);
  121. usernameField.setBorder(null);
  122. usernameField.setBounds(417, 247, 346, 52);
  123. this.add(usernameField);
  124.  
  125.  
  126.  
  127. passwordField.setForeground(Color.WHITE);
  128. passwordField.setFont(usernameField.getFont().deriveFont(20F));
  129. passwordField.setCaretColor(Color.WHITE);
  130. passwordField.setOpaque(false);
  131. passwordField.setBorder(null);
  132. passwordField.setBounds(417, 309, 346, 52);
  133. this.add(passwordField);
  134. if(Launcher.IS_CRACK == true){
  135. passwordField.setEnabled(false);
  136. }
  137.  
  138.  
  139.  
  140.  
  141. playButton.setBounds(479, 378, 228, 92);
  142. playButton.addEventListener(this);
  143. this.add(playButton);
  144.  
  145.  
  146.  
  147. File usernamefile = new File(Launcher.PZ_DIR, "username.txt");
  148.  
  149.  
  150. try
  151. {
  152.  
  153. BufferedInputStream in = new BufferedInputStream(new FileInputStream(usernamefile));
  154. StringWriter out = new StringWriter();
  155. int b;
  156. while ((b=in.read()) != -1)
  157. out.write(b);
  158. out.flush();
  159. out.close();
  160. in.close();
  161. usernameField.setText(out.toString());
  162.  
  163. }
  164. catch (FileNotFoundException exception)
  165. {
  166. System.out.println ("Le fichier n'a pas été trouvé");
  167. } catch (IOException e) {
  168. e.printStackTrace();
  169. }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. ramButton.setBounds(628, 6, 44, 44);
  177. ramButton.addEventListener(this);
  178. this.add(ramButton);
  179. closeButton.setBounds(759, 13, 27, 29);
  180. closeButton.addEventListener(this);
  181. this.add(closeButton);
  182. reducButton.setBounds(703, 13, 27, 29);
  183. reducButton.addEventListener(this);
  184.  
  185.  
  186. this.add(reducButton);
  187.  
  188.  
  189. /*discordButton.setBounds(135, 240, 91, 60);
  190. discordButton.addEventListener(this);
  191. this.add(discordButton);
  192. webButton.setBounds(135, 140, 91, 80);
  193. webButton.addEventListener(this);
  194. this.add(webButton);*/
  195.  
  196.  
  197.  
  198. pb.setStringPainted(true);
  199. pb.setBounds(133, 448, 345, 37);
  200. this.add(pb);
  201.  
  202.  
  203.  
  204.  
  205.  
  206. if(iscrackvalue.equals("true")){
  207.  
  208.  
  209. Launcher.IS_CRACK = true;
  210.  
  211. crackbutton.setTexture(crackon);
  212.  
  213. crackbutton.setTextureHover(crackon);
  214.  
  215. passwordField.setText("");
  216. passwordField.setEnabled(false);
  217.  
  218. }
  219.  
  220.  
  221.  
  222.  
  223.  
  224. }
  225.  
  226.  
  227. public void onEvent(SwingerEvent e) {
  228.  
  229. if(e.getSource() == playButton){
  230.  
  231. File usernamefile = new File(Launcher.PZ_DIR, "username.txt");
  232.  
  233. try (PrintWriter output = new PrintWriter(usernamefile)){
  234.  
  235.  
  236. output.print(usernameField.getText());
  237. } catch (FileNotFoundException e1) {
  238. e1.printStackTrace();
  239. }
  240.  
  241.  
  242. File iscrackfile = new File(Launcher.PZ_DIR, "iscrack.txt");
  243.  
  244. try (PrintWriter output = new PrintWriter(iscrackfile)){
  245.  
  246.  
  247. output.print(Launcher.IS_CRACK);
  248. } catch (FileNotFoundException e1) {
  249. e1.printStackTrace();
  250. }
  251.  
  252.  
  253. LauncherPanel.this.ramSelector.save();
  254. NLib.playAudioClip(Launcher.class, "resources/balle.wav");
  255.  
  256.  
  257. setFieldsEnabled(false);
  258.  
  259.  
  260. if(Launcher.IS_CRACK == false) {
  261. if (usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) {
  262. JOptionPane.showMessageDialog(this, "Veuillez rentrer un e-mail et un mot de passe valide.", "Erreur !", JOptionPane.ERROR_MESSAGE);
  263. setFieldsEnabled(true);
  264.  
  265. return;
  266.  
  267. }
  268. }else{
  269.  
  270. if (usernameField.getText().replaceAll(" ", "").length() == 0) {
  271. JOptionPane.showMessageDialog(this, "Veuillez rentrer un pseudonyme valide !.", "Erreur !", JOptionPane.ERROR_MESSAGE);
  272. usernameField.setEnabled(true);
  273. passwordField.setEnabled(false);
  274.  
  275. return;
  276.  
  277. }
  278.  
  279. }
  280.  
  281.  
  282.  
  283. Thread t = new Thread() {
  284. @Override
  285. public void run() {
  286.  
  287. LauncherPanel.this.ramSelector.save();
  288.  
  289. try {
  290. Launcher.auth(usernameField.getText(), passwordField.getText());
  291. System.out.println("f");
  292.  
  293. } catch (AuthenticationException e) {
  294.  
  295. JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de se connecter !" + e.getErrorModel().getErrorMessage(), "Erreur !", JOptionPane.ERROR_MESSAGE);
  296. setFieldsEnabled(true);
  297.  
  298.  
  299. System.out.println("f");
  300.  
  301. return;
  302.  
  303.  
  304. }
  305.  
  306.  
  307.  
  308. try {
  309. Launcher.update();
  310. } catch (Exception e) {
  311.  
  312. Launcher.InterruptThread();
  313. JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de Mettre le jeu à jour ! !" + e, "Erreur !", JOptionPane.ERROR_MESSAGE);
  314. setFieldsEnabled(true);
  315.  
  316.  
  317.  
  318. return;
  319.  
  320.  
  321. }
  322.  
  323. try {
  324. Launcher.launch();
  325. } catch (LaunchException e) {
  326.  
  327. JOptionPane.showMessageDialog(LauncherPanel.this, "Impossible de lancer le jeu." + e, "Erreur !", JOptionPane.ERROR_MESSAGE);
  328. setFieldsEnabled(true);
  329.  
  330.  
  331.  
  332. return;
  333.  
  334.  
  335. }
  336.  
  337.  
  338.  
  339. System.out.println("t");
  340. }
  341. };
  342. t.start();
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354. }
  355. else if (e.getSource() == this.ramButton) {
  356.  
  357. ramSelector.display();
  358. System.out.println("hey");
  359.  
  360. }else if(e.getSource() == this.closeButton){
  361. System.exit(0);
  362. }else if(e.getSource() == this.reducButton){
  363.  
  364. LauncherFrame.getInstance().setState(Frame.ICONIFIED);
  365.  
  366. }/*else if(e.getSource() == this.webButton){
  367. BrowserControl.displayURL("http://kyrgon.revhost.fr");
  368. }else if(e.getSource() == this.discordButton){
  369. BrowserControl.displayURL("paste discord link here");
  370. }*/
  371. else if (e.getSource() == this.crackbutton){
  372.  
  373. if(Launcher.IS_CRACK == false){
  374.  
  375. Launcher.IS_CRACK = true;
  376.  
  377. crackbutton.setTexture(crackon);
  378. crackbutton.setTextureHover(crackon);
  379.  
  380. passwordField.setText("");
  381. passwordField.setEnabled(false);
  382.  
  383.  
  384.  
  385. }else{
  386. Launcher.IS_CRACK = false;
  387. crackbutton.setTexture(crackoff);
  388. crackbutton.setTextureHover(crackoff);
  389. passwordField.setEnabled(true);
  390. }
  391.  
  392.  
  393.  
  394. }
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409. }
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417. @Override
  418. public void paintComponent(Graphics g) {
  419.  
  420.  
  421. super.paintComponent(g);
  422.  
  423.  
  424. g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this);
  425.  
  426. }
  427.  
  428. private void setFieldsEnabled(boolean enabled) {
  429.  
  430. usernameField.setEnabled(enabled);
  431. passwordField.setEnabled(enabled);
  432. playButton.setEnabled(enabled);
  433.  
  434.  
  435.  
  436. }
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443. public SColoredBar getProgressBar() {
  444. return pb;
  445. }
  446.  
  447. public RamSelector getRamSelector(){
  448. return ramSelector;
  449. }
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement