예제 #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;
  }
  public void runGame(String user, String session, String downloadTicket) {
    Dimension size = WindowMode.getModeById(Settings.getWindowModeId()).getDimension(this);
    Point centeredLoc =
        WindowMode.getModeById(Settings.getWindowModeId())
            .getCenteredLocation(Launcher.getLoginFrame());

    this.setLocation(centeredLoc);
    this.setSize(size);

    Launcher.getGameUpdater().setWaiting(true);
    while (!Launcher.getGameUpdater().isFinished()) {
      try {
        Thread.sleep(100);
      } catch (InterruptedException ignore) {
      }
    }

    Applet applet = null;
    try {
      applet =
          MinecraftLauncher.getMinecraftApplet(Launcher.getGameUpdater().getBuild().getLibraries());
    } catch (CorruptedMinecraftJarException corruption) {
      corruption.printStackTrace();
    } catch (MinecraftVerifyException verify) {
      Launcher.clearCache();
      JOptionPane.showMessageDialog(
          getParent(),
          "Your Minecraft installation is corrupt, but has been cleaned. \nTry to login again.\n\n If that fails, close and restart the appplication.");
      this.setVisible(false);
      this.dispose();
      Launcher.getLoginFrame().enableForm();
      return;
    }
    if (applet == null) {
      String message = "Failed to launch Spoutcraft!";
      this.setVisible(false);
      JOptionPane.showMessageDialog(getParent(), message);
      this.dispose();
      Launcher.getLoginFrame().enableForm();
      return;
    }

    StartupParameters params = Utils.getStartupParameters();

    minecraft = new MinecraftAppletEnglober(applet);
    minecraft.addParameter("username", user);
    minecraft.addParameter("sessionid", session);
    minecraft.addParameter("downloadticket", downloadTicket);
    minecraft.addParameter("spoutcraftlauncher", "true");
    minecraft.addParameter("portable", params.isPortable() + "");
    if (params.getServer() != null) {
      minecraft.addParameter("server", params.getServer());
      if (params.getPort() != null) {
        minecraft.addParameter("port", params.getPort());
      } else {
        minecraft.addParameter("port", "25565");
      }
    } else if (Settings.getDirectJoin() != null && Settings.getDirectJoin().length() > 0) {
      String address = Settings.getDirectJoin();
      String port = "25565";
      if (address.contains(":")) {
        String[] s = address.split(":");
        address = s[0];
        port = s[1];
      }
      minecraft.addParameter("server", address);
      minecraft.addParameter("port", port);
    }
    if (params.getProxyHost() != null) {
      minecraft.addParameter("proxy_host", params.getProxyHost());
    }
    if (params.getProxyPort() != null) {
      minecraft.addParameter("proxy_port", params.getProxyPort());
    }
    if (params.getProxyUser() != null) {
      minecraft.addParameter("proxy_user", params.getProxyUser());
    }
    if (params.getProxyPassword() != null) {
      minecraft.addParameter("proxy_pass", params.getProxyPassword());
    }
    // minecraft.addParameter("fullscreen", WindowMode.getModeById(Settings.getWindowModeId()) ==
    // WindowMode.FULL_SCREEN ? "true" : "false");

    applet.setStub(minecraft);
    this.add(minecraft);

    validate();
    this.setVisible(true);
    minecraft.init();
    minecraft.setSize(getWidth(), getHeight());
    minecraft.start();
    Launcher.getLoginFrame().onEvent(Event.GAME_LAUNCH);
    return;
  }