private boolean validate(String name, String user) {
   if (!name.isEmpty() && !user.isEmpty()) {
     if (!UserManager.getNames().contains(name) && !UserManager.getUsernames().contains(user)) {
       return true;
     }
   }
   return false;
 }
예제 #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!");
   }
 }
예제 #3
0
 /** @param user - user added/edited */
 public static void writeUsers(String user) {
   try {
     userManager.write();
   } catch (IOException e) {
   }
   String[] usernames =
       concatenateArrays(dropdown_, UserManager.getNames().toArray(new String[] {}));
   users.removeAllItems();
   for (int i = 0; i < usernames.length; i++) {
     users.addItem(usernames[i]);
     if (usernames[i].equals(user)) {
       users.setSelectedIndex(i);
     }
   }
 }
예제 #4
0
  /** Create the frame. */
  public LaunchFrame(final int tab) {
    setFont(new Font("a_FuturaOrto", Font.PLAIN, 12));
    setResizable(false);
    setTitle("Feed the Beast Launcher v" + version);
    setIconImage(
        Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/image/logo_ftb.png")));

    panel = new JPanel();

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    if (OSUtils.getCurrentOS() == OS.WINDOWS) {
      setBounds(100, 100, 842, 480);
    } else {
      setBounds(100, 100, 850, 480);
    }
    panel.setBounds(0, 0, 850, 480);
    panel.setLayout(null);
    footer.setBounds(0, 380, 850, 100);
    footer.setLayout(null);
    footer.setBackground(LauncherStyle.getCurrentStyle().footerColor);
    tabbedPane.setBounds(0, 0, 850, 380);
    panel.add(tabbedPane);
    panel.add(footer);
    setContentPane(panel);

    // Footer
    // footerLogo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    // footerLogo.setBounds(20, 20, 42, 42);
    // footerLogo.addMouseListener(new MouseAdapter() {
    // @Override
    // public void mouseClicked(MouseEvent event) {
    // OSUtils.browse("http://www.feed-the-beast.com");
    // }
    // });

    footerCreeper.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    footerCreeper.setBounds(25, 20, 150, 42);
    footerCreeper.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent event) {
            OSUtils.browse("http://www.mckhaos.net");
          }
        });

    dropdown_[0] = I18N.getLocaleString("PROFILE_SELECT");
    dropdown_[1] = I18N.getLocaleString("PROFILE_CREATE");

    String[] dropdown =
        concatenateArrays(dropdown_, UserManager.getNames().toArray(new String[] {}));
    users = new JComboBox(dropdown);
    if (Settings.getSettings().getLastUser() != null) {
      for (int i = 0; i < dropdown.length; i++) {
        if (dropdown[i].equalsIgnoreCase(Settings.getSettings().getLastUser())) {
          users.setSelectedIndex(i);
        }
      }
    }

    donate = new JButton(I18N.getLocaleString("DONATE_BUTTON"));
    donate.setBounds(390, 20, 80, 30);
    donate.setEnabled(false);
    donate.setToolTipText("Coming Soon...");
    donate.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {}
        });

    users.setBounds(550, 20, 150, 30);
    users.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (users.getSelectedIndex() == 1) {
              ProfileAdderDialog p = new ProfileAdderDialog(getInstance(), true);
              users.setSelectedIndex(0);
              p.setVisible(true);
            }
            edit.setEnabled(users.getSelectedIndex() > 1);
          }
        });

    edit = new JButton(I18N.getLocaleString("EDIT_BUTTON"));
    edit.setBounds(480, 20, 60, 30);
    edit.setVisible(true);
    edit.setEnabled(users.getSelectedIndex() > 1);
    edit.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            if (users.getSelectedIndex() > 1) {
              ProfileEditorDialog p =
                  new ProfileEditorDialog(getInstance(), (String) users.getSelectedItem(), true);
              users.setSelectedIndex(0);
              p.setVisible(true);
            }
            edit.setEnabled(users.getSelectedIndex() > 1);
          }
        });

    launch.setText(I18N.getLocaleString("LAUNCH_BUTTON"));
    launch.setBounds(711, 20, 100, 30);
    launch.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            doLaunch();
          }
        });

    serverbutton.setBounds(480, 20, 330, 30);
    serverbutton.setText(I18N.getLocaleString("DOWNLOAD_SERVER_PACK"));
    serverbutton.setVisible(false);
    serverbutton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            if (!ModPack.getSelectedPack().getServerUrl().isEmpty()) {
              if (getSelectedModIndex() >= 0) {
                try {
                  String version =
                      (Settings.getSettings().getPackVer().equalsIgnoreCase("recommended version")
                              || Settings.getSettings()
                                  .getPackVer()
                                  .equalsIgnoreCase("newest version"))
                          ? ModPack.getSelectedPack().getVersion().replace(".", "_")
                          : Settings.getSettings().getPackVer().replace(".", "_");
                  if (ModPack.getSelectedPack().isPrivatePack()) {
                    OSUtils.browse(
                        DownloadUtils.getCreeperhostLink(
                            "privatepacks%5E"
                                + ModPack.getSelectedPack().getDir()
                                + "%5E"
                                + version
                                + "%5E"
                                + ModPack.getSelectedPack().getServerUrl()));
                  } else {
                    OSUtils.browse(
                        DownloadUtils.getCreeperhostLink(
                            "modpacks%5E"
                                + ModPack.getSelectedPack().getDir()
                                + "%5E"
                                + version
                                + "%5E"
                                + ModPack.getSelectedPack().getServerUrl()));
                  }
                  TrackerUtils.sendPageView(
                      ModPack.getSelectedPack().getName() + " Server Download",
                      ModPack.getSelectedPack().getName());
                } catch (NoSuchAlgorithmException e) {
                }
              }
            }
          }
        });

    mapInstall.setBounds(650, 20, 160, 30);
    mapInstall.setText(I18N.getLocaleString("INSTALL_MAP"));
    mapInstall.setVisible(false);
    mapInstall.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            if (getSelectedMapIndex() >= 0) {
              MapManager man = new MapManager(new JFrame(), true);
              man.setVisible(true);
              MapManager.cleanUp();
            }
          }
        });

    mapInstallLocation = new JComboBox();
    mapInstallLocation.setBounds(480, 20, 160, 30);
    mapInstallLocation.setToolTipText("Install to...");
    mapInstallLocation.setVisible(false);

    serverMap.setBounds(480, 20, 330, 30);
    serverMap.setText(I18N.getLocaleString("DOWNLOAD_MAP_SERVER"));
    serverMap.setVisible(false);
    serverMap.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            if (getSelectedMapIndex() >= 0) {
              try {
                OSUtils.browse(
                    DownloadUtils.getCreeperhostLink(
                        "maps%5E"
                            + Map.getMap(LaunchFrame.getSelectedMapIndex()).getMapName()
                            + "%5E"
                            + Map.getMap(LaunchFrame.getSelectedMapIndex()).getVersion()
                            + "%5E"
                            + Map.getMap(LaunchFrame.getSelectedMapIndex()).getUrl()));
              } catch (NoSuchAlgorithmException e) {
              }
            }
          }
        });

    tpInstall.setBounds(650, 20, 160, 30);
    tpInstall.setText(I18N.getLocaleString("INSTALL_TEXTUREPACK"));
    tpInstall.setVisible(false);
    tpInstall.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            if (getSelectedTexturePackIndex() >= 0) {
              TextureManager man = new TextureManager(new JFrame(), true);
              man.setVisible(true);
            }
          }
        });

    tpInstallLocation = new JComboBox();
    tpInstallLocation.setBounds(480, 20, 160, 30);
    tpInstallLocation.setToolTipText("Install to...");
    tpInstallLocation.setVisible(false);

    tpInstallLocLbl.setText("Install to...");
    tpInstallLocLbl.setBounds(480, 20, 80, 30);
    tpInstallLocLbl.setVisible(false);

    footer.add(edit);
    footer.add(users);
    footer.add(footerLogo);
    footer.add(footerCreeper);
    footer.add(launch);
    footer.add(donate);
    footer.add(serverbutton);
    footer.add(mapInstall);
    footer.add(mapInstallLocation);
    footer.add(serverMap);
    footer.add(tpInstall);
    footer.add(tpInstallLocation);

    newsPane = new NewsPane();
    modPacksPane = new ModpacksPane();
    mapsPane = new MapsPane();
    tpPane = new TexturepackPane();
    optionsPane = new OptionsPane(Settings.getSettings());

    getRootPane().setDefaultButton(launch);
    updateLocale();

    tabbedPane.add(newsPane, 0);
    tabbedPane.add(optionsPane, 1);
    tabbedPane.add(modPacksPane, 2);
    tabbedPane.add(mapsPane, 3);
    tabbedPane.add(tpPane, 4);
    setNewsIcon();
    tabbedPane.setIconAt(1, new ImageIcon(this.getClass().getResource("/image/tabs/options.png")));
    tabbedPane.setIconAt(2, new ImageIcon(this.getClass().getResource("/image/tabs/modpacks.png")));
    tabbedPane.setIconAt(3, new ImageIcon(this.getClass().getResource("/image/tabs/maps.png")));
    tabbedPane.setIconAt(
        4, new ImageIcon(this.getClass().getResource("/image/tabs/texturepacks.png")));
    tabbedPane.setSelectedIndex(tab);

    tabbedPane.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent event) {
            if (tabbedPane.getSelectedComponent() instanceof ILauncherPane) {
              ((ILauncherPane) tabbedPane.getSelectedComponent()).onVisible();
              currentPane = Panes.values()[tabbedPane.getSelectedIndex()];
              updateFooter();
            }
          }
        });
  }
예제 #5
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;
  }