Пример #1
0
  @Override
  protected Object doInBackground() throws Exception {
    loginFrame.getProgressBar().setVisible(true);
    loginFrame.getProgressBar().setString("Connecting to minecraft.net...");
    try {
      values = Utils.doLogin(user, pass, loginFrame.getProgressBar());
      Launcher.getGameUpdater().setMinecraftUser(values[2].trim());
      Launcher.getGameUpdater().setMinecraftSession(values[3].trim());
      Launcher.getGameUpdater().setDownloadTicket(values[1].trim());
      Launcher.getGameUpdater().setMinecraftPass(pass);

      UserPasswordInformation info = null;

      for (String username : loginFrame.usernames.keySet()) {
        if (username.equalsIgnoreCase(user)) {
          info = loginFrame.usernames.get(username);
          break;
        }
      }

      if (info != null) {
        if (user.contains("@")) {
          info.username = values[2].trim();
        } else {
          info.username = user;
        }
        info.password = pass;
      }

      loginFrame.onEvent(Event.SUCESSFUL_LOGIN);
      return true;
    } catch (AccountMigratedException e) {
      loginFrame.getProgressBar().setVisible(false);
      loginFrame.onEvent(Event.ACCOUNT_MIGRATED);
    } catch (BadLoginException e) {
      loginFrame.getProgressBar().setVisible(false);
      loginFrame.onEvent(Event.BAD_LOGIN);
    } catch (MinecraftUserNotPremiumException e) {
      loginFrame.onEvent(Event.USER_NOT_PREMIUM);
      loginFrame.getProgressBar().setVisible(false);
    } catch (PermissionDeniedException e) {
      loginFrame.onEvent(Event.PERMISSION_DENIED);
      this.cancel(true);
      loginFrame.getProgressBar().setVisible(false);
    } catch (MCNetworkException e) {
      UserPasswordInformation info = null;

      for (String username : loginFrame.usernames.keySet()) {
        if (username.equalsIgnoreCase(user)) {
          info = loginFrame.usernames.get(username);
          break;
        }
      }

      boolean authFailed = (info == null);

      if (!authFailed) {
        if (info.isHash) {
          try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(pass.getBytes());
            for (int i = 0; i < hash.length; i++) {
              if (hash[i] != info.passwordHash[i]) {
                authFailed = true;
                break;
              }
            }
          } catch (NoSuchAlgorithmException ex) {
            authFailed = true;
          }
        } else {
          authFailed = !(pass.equals(info.password));
        }
      }

      if (authFailed) {
        loginFrame.offline = false;
        loginFrame.onEvent(Event.MINECRAFT_NETWORK_DOWN);
      } else {
        loginFrame.offline = true;
        Launcher.getGameUpdater().setMinecraftUser(user);
        loginFrame.onEvent(Event.MINECRAFT_NETWORK_DOWN);
      }
      this.cancel(true);
      loginFrame.getProgressBar().setVisible(false);
    } catch (OutdatedMCLauncherException e) {
      JOptionPane.showMessageDialog(
          loginFrame.getParent(),
          "Incompatible login version. Contact Spout about updating the launcher!");
      loginFrame.getProgressBar().setVisible(false);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      this.cancel(true);
      loginFrame.getProgressBar().setVisible(false);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }