Esempio n. 1
0
 @Override
 protected String doInBackground() {
   Benchmark.start("LoginWorker");
   try {
     if (Main.isAuthlibReadyToUse()) {
       try {
         LoginResponse resp =
             AuthlibHelper.authenticateWithAuthlib(
                 username, password, mojangData, selectedProfile);
         this.resp = resp;
         Benchmark.logBenchAs("LoginWorker", "Login Worker Run");
         if (resp != null && resp.getUsername() != null && !resp.getUsername().isEmpty()) {
           if (resp.getSessionID() != null) {
             return "good";
           } else {
             return "offline";
           }
         }
         if (resp == null) return "nullResponse";
         if (resp.getUsername() == null) return "NullUsername";
         return "bad";
       } catch (Exception e) {
         Logger.logError("Error using authlib", e);
       }
     } else {
       ErrorUtils.tossError("Authlib Unavaible. Please check your log for errors");
     }
   } catch (Exception e) {
     ErrorUtils.tossError(
         "Exception occurred, minecraft servers might be down. Check @ help.mojang.com");
   }
   return "";
 }
Esempio n. 2
0
 public void doLaunch() {
   if (users.getSelectedIndex() > 1 && ModPack.getSelectedPack() != null) {
     Settings.getSettings().setLastPack(ModPack.getSelectedPack().getDir());
     saveSettings();
     doLogin(
         UserManager.getUsername(users.getSelectedItem().toString()),
         UserManager.getPassword(users.getSelectedItem().toString()));
   } else if (users.getSelectedIndex() <= 1) {
     ErrorUtils.tossError("Please select a profile!");
   }
 }
Esempio n. 3
0
  public String getJavaPath() {
    String javaPath = getProperty("javaPath", null);
    if (javaPath == null || !new File(javaPath).isFile()) {
      remove("javaPath");
    }

    javaPath = getProperty("javaPath", getDefaultJavaPath());
    if (javaPath == null || !new File(javaPath).isFile()) {
      ErrorUtils.tossError(
          "Unable to find java; point to java executable file in Advanced Options or game will fail to launch.");
    }
    return javaPath;
  }
 @Override
 protected String doInBackground() {
   try {
     return AppUtils.downloadString(
         new URL(
             "https://login.minecraft.net/?user="******"UTF-8")
                 + "&password="******"UTF-8")
                 + "&version=13"));
   } catch (IOException e) {
     ErrorUtils.tossError("IOException, minecraft servers might be down. Check @ help.mojang.com");
     return "";
   }
 }
Esempio n. 5
0
    protected boolean downloadModPack(String modPackName, String dir) {
      boolean debugVerbose = Settings.getSettings().getDebugLauncher();
      String debugTag = "debug: downloadModPack: ";

      Logger.logInfo("Downloading Mod Pack");
      TrackerUtils.sendPageView(
          "net/ftb/tools/ModManager.java",
          "Downloaded: " + modPackName + " v." + curVersion.replace('_', '.'));
      String dynamicLoc = OSUtils.getDynamicStorageLocation();
      String installPath = Settings.getSettings().getInstallPath();
      ModPack pack = ModPack.getSelectedPack();
      String baseLink =
          (pack.isPrivatePack()
              ? "privatepacks/" + dir + "/" + curVersion + "/"
              : "modpacks/" + dir + "/" + curVersion + "/");
      File baseDynamic = new File(dynamicLoc, "ModPacks" + sep + dir + sep);
      if (debugVerbose) {
        Logger.logInfo(debugTag + "pack dir: " + dir);
        Logger.logInfo(debugTag + "dynamicLoc: " + dynamicLoc);
        Logger.logInfo(debugTag + "installPath: " + installPath);
        Logger.logInfo(debugTag + "baseLink: " + baseLink);
      }
      baseDynamic.mkdirs();
      String md5 = "";
      try {
        new File(baseDynamic, modPackName).createNewFile();
        md5 =
            downloadUrl(
                baseDynamic.getPath() + sep + modPackName,
                DownloadUtils.getCreeperhostLink(baseLink + modPackName));
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
      String animation = pack.getAnimation();
      if (!animation.equalsIgnoreCase("empty")) {
        try {
          downloadUrl(
              baseDynamic.getPath() + sep + animation,
              DownloadUtils.getCreeperhostLink(baseLink + animation));
        } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
        }
      }
      try {
        if ((md5 == null || md5.isEmpty())
            ? DownloadUtils.backupIsValid(
                new File(baseDynamic, modPackName), baseLink + modPackName)
            : DownloadUtils.isValid(new File(baseDynamic, modPackName), md5)) {
          if (debugVerbose) {
            Logger.logInfo(debugTag + "Extracting pack.");
          }
          FileUtils.extractZipTo(baseDynamic.getPath() + sep + modPackName, baseDynamic.getPath());
          if (debugVerbose) {
            Logger.logInfo(debugTag + "Purging mods, coremods, instMods");
          }
          clearModsFolder(pack);
          FileUtils.delete(new File(installPath, dir + "/minecraft/coremods"));
          FileUtils.delete(new File(installPath, dir + "/instMods/"));
          File version = new File(installPath, dir + sep + "version");
          BufferedWriter out = new BufferedWriter(new FileWriter(version));
          out.write(curVersion.replace("_", "."));
          out.flush();
          out.close();
          if (debugVerbose) {
            Logger.logInfo(debugTag + "Pack extracted, version tagged.");
          }
          return true;
        } else {
          ErrorUtils.tossError("Error downloading modpack!!!");
          return false;
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      return false;
    }
Esempio n. 6
0
  protected static LoginResponse authenticateWithAuthlib(
      String user, String pass, String mojangData, String selectedProfileName) {
    String displayName;
    boolean hasMojangData = false;
    boolean hasPassword = false;
    GameProfile selectedProfile = null;
    YggdrasilUserAuthentication authentication =
        (YggdrasilUserAuthentication)
            new YggdrasilAuthenticationService(Proxy.NO_PROXY, "1")
                .createUserAuthentication(Agent.MINECRAFT);
    if (user != null) {
      Logger.logDebug(
          user.contains("@")
              ? "Email address given"
              : "Username given" + " Not 100% sure, mojangdata might contain different username");
      Logger.logInfo("Beginning authlib authentication attempt");
      Logger.logInfo("successfully created YggdrasilAuthenticationService");
      authentication.setUsername(user);
      if (pass != null && !pass.isEmpty()) {
        authentication.setPassword(pass);
        hasPassword = true;
      }
      if (mojangData != null && !mojangData.isEmpty()) {
        Logger.logDebug("mojangData was passed to current method");
        Map<String, Object> m = decode(mojangData);
        if (m != null) {
          Logger.logDebug("Loading mojangData into authlib");
          authentication.loadFromStorage(m);
          hasMojangData = true;
        }
      } else {
        Logger.logDebug("mojangData is null or empty");
      }
      if (authentication.canLogIn()) {
        try {
          authentication.logIn();
        } catch (UserMigratedException e) {
          Logger.logError(e.toString());
          ErrorUtils.tossError(
              "Invalid credentials, please make sure to login with your Mojang account.");
          return null;
        } catch (InvalidCredentialsException e) {
          Logger.logError("Invalid credentials recieved for user: "******"Invalid username or password.");
            return null;
          }
        } catch (AuthenticationUnavailableException e) {
          Logger.logDebug("Error while authenticating, trying offline mode");
          if (hasMojangData) {
            // if the UUID is valid we can proceed to offline mode later
            uniqueID = authentication.getSelectedProfile().getId().toString();
            if (uniqueID != null && !uniqueID.isEmpty()) Logger.logDebug("Setting UUID");
            UserManager.setUUID(user, uniqueID);
          }
          if (uniqueID != null && !uniqueID.isEmpty()) {
            UserManager.setUUID(user, uniqueID);
            Logger.logDebug("Setting UUID and creating and returning new LoginResponse");
            return new LoginResponse(
                Integer.toString(authentication.getAgent().getVersion()),
                "token",
                user,
                null,
                uniqueID,
                authentication);
          }
          ErrorUtils.tossError(
              "Exception occurred, minecraft servers might be down. Check @ help.mojang.com");
          Logger.logDebug("failed", e);
          Logger.logDebug("AuthenticationUnavailableException caused by", e.getCause());
          return null;
        } catch (AuthenticationException e) {
          Logger.logError("Unknown error from authlib:", e);
        } catch (Exception e) {
          Logger.logError("Unknown authentication error occurred", e);
        }
      } else {
        Logger.logDebug("authentication.canLogIn() returned false");
      }

      if (isValid(authentication)) {
        Logger.logDebug("Authentication is valid ");
        displayName = authentication.getSelectedProfile().getName();
        if ((authentication.isLoggedIn()) && (authentication.canPlayOnline())) {
          Logger.logDebug("loggedIn() && CanPlayOnline()");
          if ((authentication instanceof YggdrasilUserAuthentication)) {
            UserManager.setStore(user, encode(authentication.saveForStorage()));
            UserManager.setUUID(
                user,
                authentication
                    .getSelectedProfile()
                    .getId()
                    .toString()); // enables use of offline mode later if needed on newer MC
            // Versions
            Logger.logDebug("Authentication done, returning LoginResponse");
            return new LoginResponse(
                Integer.toString(authentication.getAgent().getVersion()),
                "token",
                displayName,
                authentication.getAuthenticatedToken(),
                authentication.getSelectedProfile().getId().toString(),
                authentication);
          }
        }
        Logger.logDebug(
            "this should never happen: isLoggedIn: "
                + authentication.isLoggedIn()
                + " canPlayOnline(): "
                + authentication.canPlayOnline());
      } else if (authentication.getSelectedProfile() == null
          && (authentication.getAvailableProfiles() != null
              && authentication.getAvailableProfiles().length != 0)) {
        // user has more than one profile
        Logger.logDebug("User has more than one profile: " + toString(authentication));
        for (GameProfile profile : authentication.getAvailableProfiles()) {
          if (selectedProfileName.equals(profile.getName())) {
            Logger.logInfo("Selected profile: " + profile.getName());
            selectedProfile = profile;
          }
        }
        if (selectedProfile == null) {
          Logger.logInfo("Profile not found, defaulting to first");
          selectedProfile = authentication.getAvailableProfiles()[0];
        }
        Logger.logDebug("Authentication done, returning LoginResponse");
        return new LoginResponse(
            Integer.toString(authentication.getAgent().getVersion()),
            "token",
            selectedProfile.getName(),
            authentication.getAuthenticatedToken(),
            selectedProfile.getId().toString(),
            authentication);
      } else if (authentication.getSelectedProfile() == null
          && (authentication.getAvailableProfiles() != null
              && authentication.getAvailableProfiles().length == 0)) {
        Logger.logDebug("No profiles in mojang account: " + toString(authentication));
        ErrorUtils.showClickableMessage(
            "You need to own minecraft to play FTB Modpacks",
            "https://help.mojang.com/customer/portal/articles/1218766-can-only-play-minecraft-demo");
        return null;
      } else {
        Logger.logDebug("this should never happen: " + toString(authentication));
      }

    } else {
      Logger.logDebug("this should never happen");
    }

    if (hasMojangData) {
      Logger.logError(
          "Failed to authenticate with mojang data, attempting to use username & password");
      if (!hasPassword) {
        new PasswordDialog(LaunchFrame.getInstance(), true).setVisible(true);
        if (LaunchFrame.tempPass.isEmpty()) return null;
        pass = LaunchFrame.tempPass;
      }

      LoginResponse l = authenticateWithAuthlib(user, pass, null, selectedProfileName);
      if (l == null) {
        Logger.logError("Failed to login with username & password");
        return null;
      } else {
        Logger.logDebug("authentication ready, returning LoginResponse from authlib");
        return l;
      }
    }
    Logger.logError("Failed to authenticate");
    return null;
  }