Advertisement
Guest User

Account Manager

a guest
Oct 16th, 2017
6,981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.10 KB | None | 0 0
  1. package net.minecraft.client.gui;
  2.  
  3. import java.awt.Color;
  4. import java.io.IOException;
  5. import java.net.Proxy;
  6.  
  7. import org.lwjgl.input.Keyboard;
  8.  
  9. import com.mojang.authlib.Agent;
  10. import com.mojang.authlib.exceptions.AuthenticationException;
  11. import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
  12. import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
  13. import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
  14.  
  15. import net.minecraft.client.Minecraft;
  16. import net.minecraft.util.Session;
  17.  
  18. public class GuiScreenAccount extends GuiScreen
  19. {
  20.    
  21.     private GuiScreen parentScreen;
  22.     private GuiTextField uTF;
  23.     private GuiTextField pTF;
  24.     private GuiTextField cTF;
  25.     private String error;
  26.    
  27.     public GuiScreenAccount(GuiScreen arg1)
  28.     {
  29.         parentScreen = arg1;
  30.     }
  31.    
  32.     @Override
  33.     public void updateScreen()
  34.     {
  35.         uTF.updateCursorCounter();
  36.         pTF.updateCursorCounter();
  37.         cTF.updateCursorCounter();
  38.     }
  39.    
  40.     protected void keyTyped(char c, int i)
  41.     {
  42.         uTF.textboxKeyTyped(c, i);
  43.         pTF.textboxKeyTyped(c, i);
  44.         cTF.textboxKeyTyped(c, i);
  45.        
  46.         if(c == '\t')
  47.         {
  48.             if(uTF.isFocused())
  49.             {
  50.                 uTF.setFocused(false);
  51.                 pTF.setFocused(true);
  52.             } else if (pTF.isFocused())
  53.             {
  54.                 pTF.setFocused(false);
  55.                 cTF.setFocused(true);
  56.             } else if (cTF.isFocused())
  57.             {
  58.                 cTF.setFocused(false);
  59.                 uTF.setFocused(true);
  60.             }
  61.         }
  62.        
  63.         if(c == '\r')
  64.         {
  65.             actionPerformed((GuiButton)this.buttonList.get(0));
  66.         }
  67.     }
  68.    
  69.     protected void mouseClicked(int x, int y, int mb)
  70.     {
  71.         try
  72.         {
  73.             super.mouseClicked(x, y, mb);
  74.         } catch (IOException e)
  75.         {
  76.             e.printStackTrace();
  77.         }
  78.         uTF.mouseClicked(x, y, mb);
  79.         pTF.mouseClicked(x, y, mb);
  80.         cTF.mouseClicked(x, y, mb);
  81.     }
  82.    
  83.     public void initGui()
  84.     {
  85.         Keyboard.enableRepeatEvents(true);
  86.        
  87.         int i = 24;
  88.         int j = this.height / 4 + 48;
  89.        
  90.         int locationFirst = j;
  91.         int locationAddition = 48;
  92.        
  93.         this.buttonList.add(new GuiButton(0, width / 2 - 126, j + 72 + 12 + 45, 120, 20, "Login"));
  94.         this.buttonList.add(new GuiButton(1, width / 2 + 7, j + 72 + 12 + 45, 120, 20, "Back"));
  95.        
  96.         uTF = new GuiTextField(0, fontRendererObj, width / 2 - 125, locationFirst, 250, 20);
  97.         pTF = new GuiTextField(1, fontRendererObj, width / 2 - 125, locationFirst + locationAddition * 1, 250, 20);
  98.         cTF = new GuiTextField(2, fontRendererObj, width / 2 - 125, locationFirst + locationAddition * 2, 250, 20);
  99.        
  100.         uTF.setMaxStringLength(100);
  101.         pTF.setMaxStringLength(100);
  102.         cTF.setMaxStringLength(200);
  103.     }
  104.    
  105.     public void drawScreen(int x, int y, float ticks)
  106.     {
  107.         drawDefaultBackground();
  108.        
  109.         int i = 24;
  110.         int j = this.height / 4 + 35;
  111.        
  112.         int locationFirst = j;
  113.         int locationAddition = 48;
  114.        
  115.         drawString(fontRendererObj, "Username", width/2-125, locationFirst, 0xFFFFFF);
  116.         drawString(fontRendererObj, "Password", width/2-125, locationFirst + locationAddition * 1, 0xFFFFFF);
  117.         drawString(fontRendererObj, "Combo (User:Pass)", width/2-125, locationFirst + locationAddition * 2, 0xFFFFFF);
  118.         uTF.drawTextBox();
  119.         pTF.drawTextBox();
  120.         cTF.drawTextBox();
  121.         if(error != null)
  122.         {          
  123.             drawString(fontRendererObj, error, width/2 - fontRendererObj.getStringWidth("\247cError: "+error)/2, j + 72 + 12 + 85, Color.YELLOW.getRGB());
  124.             if(error.contains("Logged in as")) {
  125.                 mc.displayGuiScreen(new GuiMultiplayer(this));
  126.             }
  127.         }
  128.         super.drawScreen(x, y, ticks);
  129.     }
  130.    
  131.     public void onGuiClosed()
  132.     {
  133.         Keyboard.enableRepeatEvents(false);
  134.     }
  135.    
  136.     protected void actionPerformed(GuiButton arg1)
  137.     {
  138.         if(!arg1.enabled)
  139.         {
  140.             return;
  141.         }
  142.         if(arg1.id == 1)
  143.         {
  144.             mc.displayGuiScreen(new GuiMultiplayer(this));
  145.         }
  146.         if(arg1.id == 0)
  147.         {
  148.             if((uTF.getText().length()>0) || ((cTF.getText().length()>2) && (cTF.getText().contains(":"))))
  149.             {
  150.                 error = null;
  151.                 String username = uTF.getText();
  152.                 String password = pTF.getText();
  153.                 if(password == "" && cTF.getText().equals("")) {
  154.                     changeCrackedName(username);
  155.                     return;
  156.                 }
  157.                
  158.                 if(!cTF.getText().equals(""))
  159.                 {
  160.                     String[] combo = cTF.getText().split(":", 2);
  161.                     try
  162.                     {
  163.                         username = combo[0];
  164.                         password = combo[1];
  165.                     } catch (ArrayIndexOutOfBoundsException e)
  166.                     {
  167.                         error = "Invalid Arguments!";
  168.                     }
  169.                 }
  170.                
  171.                 YggdrasilUserAuthentication auth =
  172.                           (YggdrasilUserAuthentication)new YggdrasilAuthenticationService(
  173.                           Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
  174.                        
  175.                         auth.setUsername(username);
  176.                         auth.setPassword(password);
  177.                         try
  178.                         {
  179.                           auth.logIn();
  180.                           mc.session =
  181.                             new Session(auth.getSelectedProfile().getName(),
  182.                             auth.getSelectedProfile().getId().toString(),
  183.                             auth.getAuthenticatedToken(), "mojang");
  184. //                        System.out.println(username);
  185. //                        System.out.println(password);
  186.                           error = "Logged in as: "+auth.getSelectedProfile().getName();
  187.                         }
  188.                         catch (AuthenticationUnavailableException e)
  189.                         {
  190.                           error = "Can not connect the mojang authentification Servers";
  191.                         }
  192.                         catch (AuthenticationException e)
  193.                         {
  194.                           e.printStackTrace();
  195.                           if ((e.getMessage().contains("Invalid username or password.")) ||
  196.                             (e.getMessage().toLowerCase().contains("account migrated"))) {
  197.                             error = "Invalid Password";
  198.                           }
  199.                           error = "Can not connect the mojang authentification Servers";
  200.                         }
  201.                         catch (NullPointerException e) {}
  202.                       }
  203.                
  204.             }else
  205.             {
  206.                 error = "Invalid Password!";
  207.             }
  208.             if(error != null)
  209.             {
  210.                 int i = 24;
  211.                 int j = this.height / 4 + 35;
  212.                 drawString(fontRendererObj, error, width/2 - fontRendererObj.getStringWidth("\247cError: "+error)/2, j + 72 + 12 + 85, Color.YELLOW.getRGB());
  213.                 if(error.contains("Logged in as")) {
  214.                     mc.displayGuiScreen(new GuiMultiplayer(this));
  215.                 }
  216.             }else
  217.             {
  218.                 mc.displayGuiScreen(new GuiMultiplayer(this));
  219.             }
  220.         }
  221.  
  222.      
  223.       private void changeCrackedName(String newName)
  224.       {
  225.         mc.session =
  226.           new Session(newName, "", "", "mojang");
  227.       }
  228.    
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement