Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. @Override
  2. public String getAlias() {
  3. return "login";
  4. }
  5.  
  6. @Override
  7. public String getDescription() {
  8. return "Log into an account";
  9. }
  10.  
  11. @Override
  12. public String getSyntax() {
  13. return ".login <email> <pass>";
  14. }
  15.  
  16. public void onCommand(String command, String[] args) throws Exception {
  17. response(Auth.setSessionData(args[0], args.length == 2 ? args[1] : ""), args[0]);
  18. }
  19.  
  20. private void response(int code, String user) {
  21. String message = "";
  22. switch (code) {
  23. case 0:
  24. message = "Authentication failed";
  25. break;
  26. case 1:
  27. message = "Authentication successful";
  28. break;
  29. case 2:
  30. message = "Username changed ( no legacy )";
  31. }
  32. Client.INSTANCE.addChatMessage(message);
  33. }
  34.  
  35. public static class Auth {
  36. public void login(Account account) {
  37. setSessionData(account.email, account.password);
  38. }
  39.  
  40. public static int setSessionData(String user, String pass) {
  41. if (pass.length() != 0) {
  42. YggdrasilAuthenticationService authentication = new YggdrasilAuthenticationService(Proxy.NO_PROXY, "");
  43. YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) authentication
  44. .createUserAuthentication(Agent.MINECRAFT);
  45. auth.setUsername(user);
  46. auth.setPassword(pass);
  47. try {
  48. auth.logIn();
  49. Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(),
  50. auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "legacy");
  51. return 1;
  52. } catch (Exception var4_4) {
  53. return 0;
  54. }
  55. }
  56. Minecraft.getMinecraft().session = new Session(user, "0", "0", "legacy");
  57. return 2;
  58. }
  59. }
  60.  
  61. public class Account {
  62. public List<Account> accounts = new CopyOnWriteArrayList();
  63. public String email;
  64. public String password;
  65. public String username;
  66. public ResourceLocation head;
  67. public boolean authenticating;
  68.  
  69. public Account(String email, String password) {
  70. this.email = email;
  71. this.password = password;
  72. if (!email.contains("@")) {
  73. loadHead(email);
  74. }
  75. }
  76.  
  77. public void loadHead(String username) {
  78. this.username = username;
  79. if (this.head == null) {
  80. this.head = new ResourceLocation("heads/" + username);
  81. ThreadDownloadImageData textureHead = new ThreadDownloadImageData(null,
  82. String.format("https://minotar.net/helm/%s/64.png", new Object[] { username }), null, null);
  83. Minecraft.getMinecraft().getTextureManager().loadTexture(this.head, textureHead);
  84. }
  85. }
  86.  
  87. public boolean login(String username, String password) {
  88. YggdrasilUserAuthentication auth = new YggdrasilUserAuthentication(
  89. new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()), Agent.MINECRAFT);
  90. auth.setUsername(username);
  91. auth.setPassword(password);
  92. try {
  93. auth.logIn();
  94. Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(),
  95. auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "legacy");
  96. return true;
  97. } catch (AuthenticationException e) {
  98. if (((e instanceof UserMigratedException)) || ((e instanceof InvalidCredentialsException))) {
  99. Minecraft.getMinecraft().session = new Session(username, UUID.randomUUID().toString(), "-",
  100. "legacy");
  101. return false;
  102. }
  103. Minecraft.getMinecraft().session = new Session(username, UUID.randomUUID().toString(), "-", "legacy");
  104. }
  105. return true;
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement