Guest User

Untitled

a guest
Sep 6th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.89 KB | None | 0 0
  1. package net.minecraft;
  2.  
  3. import java.awt.*;
  4. import java.io.*;
  5. import java.util.Random;
  6. import javax.crypto.*;
  7. import javax.crypto.spec.PBEKeySpec;
  8. import javax.crypto.spec.PBEParameterSpec;
  9. import javax.swing.*;
  10. import javax.swing.border.MatteBorder;
  11.  
  12. // Referenced classes of package net.minecraft:
  13. // TransparentPanel, TransparentCheckbox, TransparentButton, TransparentLabel,
  14. // Util, TexturedPanel, LogoPanel, LauncherFrame
  15.  
  16. public class LoginForm extends TransparentPanel
  17. {
  18.  
  19. public LoginForm(LauncherFrame launcherFrame)
  20. {
  21. userName = new jtextfield(20);
  22. password = new jpasswordfield(20);
  23. rememberBox = new TransparentCheckbox("Remember password");
  24. launchButton = new TransparentButton("Login");
  25. optionsButton = new TransparentButton("Options");
  26. retryButton = new TransparentButton("Try again");
  27. offlineButton = new TransparentButton("Play offline");
  28. errorLabel = new TransparentLabel("", 0);
  29. outdated = false;
  30. this.launcherFrame = launcherFrame;
  31. borderlayout gbl = new borderlayout();
  32. setLayout(gbl);
  33. add(buildMainLoginPanel(), "Center");
  34. readUsername();
  35. java.awt.event.actionlistener al = new object() /* anonymous class not found */
  36. class _anm1 {}
  37.  
  38. ;
  39. userName.addActionListener(al);
  40. password.addActionListener(al);
  41. retryButton.addActionListener(new object() /* anonymous class not found */
  42. class _anm2 {}
  43.  
  44. );
  45. offlineButton.addActionListener(new object(launcherFrame) /* anonymous class not found */
  46. class _anm3 {}
  47.  
  48. );
  49. launchButton.addActionListener(al);
  50. optionsButton.addActionListener(new object(launcherFrame) /* anonymous class not found */
  51. class _anm4 {}
  52.  
  53. );
  54. }
  55.  
  56. public void doLogin()
  57. {
  58. setLoggingIn();
  59. (new object() /* anonymous class not found */
  60. class _anm5 {}
  61.  
  62. ).start();
  63. }
  64.  
  65. private void readUsername()
  66. {
  67. try
  68. {
  69. file lastLogin = new file(util.getWorkingDirectory(), "lastlogin");
  70. Cipher cipher = getCipher(2, "passwordfile");
  71. datainputstream dis;
  72. if(cipher != null)
  73. dis = new datainputstream(new CipherInputStream(new fileinputstream(lastLogin), cipher));
  74. else
  75. dis = new datainputstream(new fileinputstream(lastLogin));
  76. userName.setText(dis.readUTF());
  77. password.setText(dis.readUTF());
  78. rememberBox.setSelected(password.getPassword().length > 0);
  79. dis.close();
  80. }
  81. catch(exception e)
  82. {
  83. e.printStackTrace();
  84. }
  85. }
  86.  
  87. private void writeUsername()
  88. {
  89. try
  90. {
  91. file lastLogin = new file(util.getWorkingDirectory(), "lastlogin");
  92. Cipher cipher = getCipher(1, "passwordfile");
  93. dataoutputstream dos;
  94. if(cipher != null)
  95. dos = new dataoutputstream(new CipherOutputStream(new fileoutputstream(lastLogin), cipher));
  96. else
  97. dos = new dataoutputstream(new fileoutputstream(lastLogin));
  98. dos.writeUTF(userName.getText());
  99. dos.writeUTF(rememberBox.isSelected() ? new string(password.getPassword()) : "");
  100. dos.close();
  101. }
  102. catch(exception e)
  103. {
  104. e.printStackTrace();
  105. }
  106. }
  107.  
  108. private Cipher getCipher(int mode, string password)
  109. throws exception
  110. {
  111. random random = new random(0x29482c2L);
  112. byte salt[] = new byte[8];
  113. random.nextBytes(salt);
  114. PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
  115. javax.crypto.SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(password.toCharArray()));
  116. Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
  117. cipher.init(mode, pbeKey, pbeParamSpec);
  118. return cipher;
  119. }
  120.  
  121. private jscrollpane getUpdateNews()
  122. {
  123. if(scrollPane != null)
  124. return scrollPane;
  125. try
  126. {
  127. jtextpane editorPane = new object() /* anonymous class not found */
  128. class _anm6 {}
  129.  
  130. ;
  131. editorPane.setText("<html><body><font color=\"#808080\"><br><br><br><br><br><br><br><center>Loading update news..</center></font></body></html>");
  132. editorPane.addHyperlinkListener(new object() /* anonymous class not found */
  133. class _anm7 {}
  134.  
  135. );
  136. (new object(editorPane) /* anonymous class not found */
  137. class _anm8 {}
  138.  
  139. ).start();
  140. editorPane.setBackground(color.DARK_GRAY);
  141. editorPane.setEditable(false);
  142. scrollPane = new jscrollpane(editorPane);
  143. scrollPane.setBorder(null);
  144. editorPane.setMargin(null);
  145. scrollPane.setBorder(new matteborder(0, 0, 2, 0, color.BLACK));
  146. }
  147. catch(exception e2)
  148. {
  149. e2.printStackTrace();
  150. }
  151. return scrollPane;
  152. }
  153.  
  154. private jpanel buildMainLoginPanel()
  155. {
  156. jpanel p = new TransparentPanel(new borderlayout());
  157. p.add(getUpdateNews(), "Center");
  158. jpanel southPanel = new TexturedPanel();
  159. southPanel.setLayout(new borderlayout());
  160. southPanel.add(new LogoPanel(), "West");
  161. southPanel.add(new TransparentPanel(), "Center");
  162. southPanel.add(center(buildLoginPanel()), "East");
  163. southPanel.setPreferredSize(new dimension(100, 100));
  164. p.add(southPanel, "South");
  165. return p;
  166. }
  167.  
  168. private jpanel buildLoginPanel()
  169. {
  170. TransparentPanel panel = new TransparentPanel();
  171. panel.setInsets(4, 0, 4, 0);
  172. borderlayout layout = new borderlayout();
  173. layout.setHgap(0);
  174. layout.setVgap(8);
  175. panel.setLayout(layout);
  176. gridlayout gl1 = new gridlayout(0, 1);
  177. gl1.setVgap(2);
  178. gridlayout gl2 = new gridlayout(0, 1);
  179. gl2.setVgap(2);
  180. gridlayout gl3 = new gridlayout(0, 1);
  181. gl3.setVgap(2);
  182. TransparentPanel titles = new TransparentPanel(gl1);
  183. TransparentPanel values = new TransparentPanel(gl2);
  184. titles.add(new TransparentLabel("Username:", 4));
  185. titles.add(new TransparentLabel("Password:", 4));
  186. titles.add(new TransparentLabel("", 4));
  187. values.add(userName);
  188. values.add(password);
  189. values.add(rememberBox);
  190. panel.add(titles, "West");
  191. panel.add(values, "Center");
  192. TransparentPanel loginPanel = new TransparentPanel(new borderlayout());
  193. TransparentPanel third = new TransparentPanel(gl3);
  194. titles.setInsets(0, 0, 0, 4);
  195. third.setInsets(0, 10, 0, 10);
  196. third.add(optionsButton);
  197. third.add(launchButton);
  198. try
  199. {
  200. if(outdated)
  201. {
  202. TransparentLabel accountLink = getUpdateLink();
  203. third.add(accountLink);
  204. } else
  205. {
  206. TransparentLabel accountLink = new object("Need account?") /* anonymous class not found */
  207. class _anm9 {}
  208.  
  209. ;
  210. accountLink.setCursor(cursor.getPredefinedCursor(12));
  211. accountLink.addMouseListener(new object() /* anonymous class not found */
  212. class _anm10 {}
  213.  
  214. );
  215. accountLink.setForeground(LINK_COLOR);
  216. third.add(accountLink);
  217. }
  218. }
  219. catch(error error) { }
  220. loginPanel.add(third, "Center");
  221. panel.add(loginPanel, "East");
  222. errorLabel.setFont(new font(null, 2, 16));
  223. errorLabel.setForeground(new color(0xff4040));
  224. errorLabel.setText("");
  225. panel.add(errorLabel, "North");
  226. return panel;
  227. }
  228.  
  229. private TransparentLabel getUpdateLink()
  230. {
  231. TransparentLabel accountLink = new object("You need to update the launcher!") /* anonymous class not found */
  232. class _anm11 {}
  233.  
  234. ;
  235. accountLink.setCursor(cursor.getPredefinedCursor(12));
  236. accountLink.addMouseListener(new object() /* anonymous class not found */
  237. class _anm12 {}
  238.  
  239. );
  240. accountLink.setForeground(LINK_COLOR);
  241. return accountLink;
  242. }
  243.  
  244. private jpanel buildMainOfflinePanel()
  245. {
  246. jpanel p = new TransparentPanel(new borderlayout());
  247. p.add(getUpdateNews(), "Center");
  248. jpanel southPanel = new TexturedPanel();
  249. southPanel.setLayout(new borderlayout());
  250. southPanel.add(new LogoPanel(), "West");
  251. southPanel.add(new TransparentPanel(), "Center");
  252. southPanel.add(center(buildOfflinePanel()), "East");
  253. southPanel.setPreferredSize(new dimension(100, 100));
  254. p.add(southPanel, "South");
  255. return p;
  256. }
  257.  
  258. private component center(component c)
  259. {
  260. TransparentPanel tp = new TransparentPanel(new gridbaglayout());
  261. tp.add(c);
  262. return tp;
  263. }
  264.  
  265. private TransparentPanel buildOfflinePanel()
  266. {
  267. TransparentPanel panel = new TransparentPanel();
  268. panel.setInsets(0, 0, 0, 20);
  269. borderlayout layout = new borderlayout();
  270. panel.setLayout(layout);
  271. TransparentPanel loginPanel = new TransparentPanel(new borderlayout());
  272. gridlayout gl = new gridlayout(0, 1);
  273. gl.setVgap(2);
  274. TransparentPanel pp = new TransparentPanel(gl);
  275. pp.setInsets(0, 8, 0, 0);
  276. pp.add(retryButton);
  277. pp.add(offlineButton);
  278. loginPanel.add(pp, "East");
  279. boolean canPlayOffline = launcherFrame.canPlayOffline(userName.getText());
  280. offlineButton.setEnabled(canPlayOffline);
  281. if(!canPlayOffline)
  282. loginPanel.add(new TransparentLabel("(Not downloaded)", 4), "South");
  283. panel.add(loginPanel, "Center");
  284. TransparentPanel p2 = new TransparentPanel(new gridlayout(0, 1));
  285. errorLabel.setFont(new font(null, 2, 16));
  286. errorLabel.setForeground(new color(0xff4040));
  287. p2.add(errorLabel);
  288. if(outdated)
  289. {
  290. TransparentLabel accountLink = getUpdateLink();
  291. p2.add(accountLink);
  292. }
  293. loginPanel.add(p2, "Center");
  294. return panel;
  295. }
  296.  
  297. public void setError(string errorMessage)
  298. {
  299. removeAll();
  300. add(buildMainLoginPanel(), "Center");
  301. errorLabel.setText(errorMessage);
  302. validate();
  303. }
  304.  
  305. public void loginOk()
  306. {
  307. writeUsername();
  308. }
  309.  
  310. public void setLoggingIn()
  311. {
  312. removeAll();
  313. jpanel panel = new jpanel(new borderlayout());
  314. panel.add(getUpdateNews(), "Center");
  315. jpanel southPanel = new TexturedPanel();
  316. southPanel.setLayout(new borderlayout());
  317. southPanel.add(new LogoPanel(), "West");
  318. southPanel.add(new TransparentPanel(), "Center");
  319. jlabel label = new TransparentLabel("Logging in... ", 0);
  320. label.setFont(new font(null, 1, 16));
  321. southPanel.add(center(label), "East");
  322. southPanel.setPreferredSize(new dimension(100, 100));
  323. panel.add(southPanel, "South");
  324. add(panel, "Center");
  325. validate();
  326. }
  327.  
  328. public void setNoNetwork()
  329. {
  330. removeAll();
  331. add(buildMainOfflinePanel(), "Center");
  332. validate();
  333. }
  334.  
  335. public void checkAutologin()
  336. {
  337. if(password.getPassword().length > 0)
  338. launcherFrame.login(userName.getText(), new string(password.getPassword()));
  339. }
  340.  
  341. public void setOutdated()
  342. {
  343. outdated = true;
  344. }
  345.  
  346. private static final int PANEL_SIZE = 100;
  347. private static final long serialVersionUID = 1L;
  348. private static final color LINK_COLOR = new color(0x8080ff);
  349. public jtextfield userName;
  350. public jpasswordfield password;
  351. private TransparentCheckbox rememberBox;
  352. private TransparentButton launchButton;
  353. private TransparentButton optionsButton;
  354. private TransparentButton retryButton;
  355. private TransparentButton offlineButton;
  356. private TransparentLabel errorLabel;
  357. private LauncherFrame launcherFrame;
  358. private boolean outdated;
  359. private jscrollpane scrollPane;
  360.  
  361.  
  362.  
  363.  
  364. }
Add Comment
Please, Sign In to add comment