Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.client.gui;
- import java.awt.Color;
- import java.io.IOException;
- import java.net.Proxy;
- import org.lwjgl.input.Keyboard;
- import com.mojang.authlib.Agent;
- import com.mojang.authlib.exceptions.AuthenticationException;
- import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
- import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
- import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
- import net.minecraft.client.Minecraft;
- import net.minecraft.util.Session;
- public class GuiScreenAccount extends GuiScreen
- {
- private GuiScreen parentScreen;
- private GuiTextField uTF;
- private GuiTextField pTF;
- private GuiTextField cTF;
- private String error;
- public GuiScreenAccount(GuiScreen arg1)
- {
- parentScreen = arg1;
- }
- @Override
- public void updateScreen()
- {
- uTF.updateCursorCounter();
- pTF.updateCursorCounter();
- cTF.updateCursorCounter();
- }
- protected void keyTyped(char c, int i)
- {
- uTF.textboxKeyTyped(c, i);
- pTF.textboxKeyTyped(c, i);
- cTF.textboxKeyTyped(c, i);
- if(c == '\t')
- {
- if(uTF.isFocused())
- {
- uTF.setFocused(false);
- pTF.setFocused(true);
- } else if (pTF.isFocused())
- {
- pTF.setFocused(false);
- cTF.setFocused(true);
- } else if (cTF.isFocused())
- {
- cTF.setFocused(false);
- uTF.setFocused(true);
- }
- }
- if(c == '\r')
- {
- actionPerformed((GuiButton)this.buttonList.get(0));
- }
- }
- protected void mouseClicked(int x, int y, int mb)
- {
- try
- {
- super.mouseClicked(x, y, mb);
- } catch (IOException e)
- {
- e.printStackTrace();
- }
- uTF.mouseClicked(x, y, mb);
- pTF.mouseClicked(x, y, mb);
- cTF.mouseClicked(x, y, mb);
- }
- public void initGui()
- {
- Keyboard.enableRepeatEvents(true);
- int i = 24;
- int j = this.height / 4 + 48;
- int locationFirst = j;
- int locationAddition = 48;
- this.buttonList.add(new GuiButton(0, width / 2 - 126, j + 72 + 12 + 45, 120, 20, "Login"));
- this.buttonList.add(new GuiButton(1, width / 2 + 7, j + 72 + 12 + 45, 120, 20, "Back"));
- uTF = new GuiTextField(0, fontRendererObj, width / 2 - 125, locationFirst, 250, 20);
- pTF = new GuiTextField(1, fontRendererObj, width / 2 - 125, locationFirst + locationAddition * 1, 250, 20);
- cTF = new GuiTextField(2, fontRendererObj, width / 2 - 125, locationFirst + locationAddition * 2, 250, 20);
- uTF.setMaxStringLength(100);
- pTF.setMaxStringLength(100);
- cTF.setMaxStringLength(200);
- }
- public void drawScreen(int x, int y, float ticks)
- {
- drawDefaultBackground();
- int i = 24;
- int j = this.height / 4 + 35;
- int locationFirst = j;
- int locationAddition = 48;
- drawString(fontRendererObj, "Username", width/2-125, locationFirst, 0xFFFFFF);
- drawString(fontRendererObj, "Password", width/2-125, locationFirst + locationAddition * 1, 0xFFFFFF);
- drawString(fontRendererObj, "Combo (User:Pass)", width/2-125, locationFirst + locationAddition * 2, 0xFFFFFF);
- uTF.drawTextBox();
- pTF.drawTextBox();
- cTF.drawTextBox();
- if(error != null)
- {
- drawString(fontRendererObj, error, width/2 - fontRendererObj.getStringWidth("\247cError: "+error)/2, j + 72 + 12 + 85, Color.YELLOW.getRGB());
- if(error.contains("Logged in as")) {
- mc.displayGuiScreen(new GuiMultiplayer(this));
- }
- }
- super.drawScreen(x, y, ticks);
- }
- public void onGuiClosed()
- {
- Keyboard.enableRepeatEvents(false);
- }
- protected void actionPerformed(GuiButton arg1)
- {
- if(!arg1.enabled)
- {
- return;
- }
- if(arg1.id == 1)
- {
- mc.displayGuiScreen(new GuiMultiplayer(this));
- }
- if(arg1.id == 0)
- {
- if((uTF.getText().length()>0) || ((cTF.getText().length()>2) && (cTF.getText().contains(":"))))
- {
- error = null;
- String username = uTF.getText();
- String password = pTF.getText();
- if(password == "" && cTF.getText().equals("")) {
- changeCrackedName(username);
- return;
- }
- if(!cTF.getText().equals(""))
- {
- String[] combo = cTF.getText().split(":", 2);
- try
- {
- username = combo[0];
- password = combo[1];
- } catch (ArrayIndexOutOfBoundsException e)
- {
- error = "Invalid Arguments!";
- }
- }
- YggdrasilUserAuthentication auth =
- (YggdrasilUserAuthentication)new YggdrasilAuthenticationService(
- Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
- auth.setUsername(username);
- auth.setPassword(password);
- try
- {
- auth.logIn();
- mc.session =
- new Session(auth.getSelectedProfile().getName(),
- auth.getSelectedProfile().getId().toString(),
- auth.getAuthenticatedToken(), "mojang");
- // System.out.println(username);
- // System.out.println(password);
- error = "Logged in as: "+auth.getSelectedProfile().getName();
- }
- catch (AuthenticationUnavailableException e)
- {
- error = "Can not connect the mojang authentification Servers";
- }
- catch (AuthenticationException e)
- {
- e.printStackTrace();
- if ((e.getMessage().contains("Invalid username or password.")) ||
- (e.getMessage().toLowerCase().contains("account migrated"))) {
- error = "Invalid Password";
- }
- error = "Can not connect the mojang authentification Servers";
- }
- catch (NullPointerException e) {}
- }
- }else
- {
- error = "Invalid Password!";
- }
- if(error != null)
- {
- int i = 24;
- int j = this.height / 4 + 35;
- drawString(fontRendererObj, error, width/2 - fontRendererObj.getStringWidth("\247cError: "+error)/2, j + 72 + 12 + 85, Color.YELLOW.getRGB());
- if(error.contains("Logged in as")) {
- mc.displayGuiScreen(new GuiMultiplayer(this));
- }
- }else
- {
- mc.displayGuiScreen(new GuiMultiplayer(this));
- }
- }
- private void changeCrackedName(String newName)
- {
- mc.session =
- new Session(newName, "", "", "mojang");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement