Ejemplo n.º 1
0
  public static void logout() {
    if (LogoutManager.isRunning) {
      return;
    }

    LogoutManager.isRunning = true;

    // If there's no user to worry about, we're done now.

    String userName = KoLCharacter.getUserName();

    if (userName == null || userName.equals("")) {
      return;
    }

    if (!KoLmafia.isSessionEnding()) {
      LogoutManager.prepare();
    }

    KoLmafia.updateDisplay("Preparing for logout...");

    // Shut down chat-related activity

    BuffBotHome.setBuffBotActive(false);
    ChatManager.dispose();

    // Run on-logout scripts

    String scriptSetting = Preferences.getString("logoutScript");
    if (!scriptSetting.equals("")) {
      KoLmafia.updateDisplay("Executing logout script...");
      KoLmafiaCLI.DEFAULT_SHELL.executeLine(scriptSetting);
    }

    if (Preferences.getBoolean("sharePriceData")) {
      KoLmafia.updateDisplay("Sharing mall price data with other users...");
      KoLmafiaCLI.DEFAULT_SHELL.executeLine(
          "spade prices http://kolmafia.us/scripts/updateprices.php");
    }

    // Clear out user data

    RequestLogger.closeSessionLog();
    RequestLogger.closeMirror();

    GenericRequest.reset();
    KoLCharacter.reset("");

    // Execute the logout request

    RequestThread.postRequest(new LogoutRequest());
    KoLmafia.updateDisplay("Logout completed.");

    RequestLogger.closeDebugLog();

    LogoutManager.isRunning = false;
  }
Ejemplo n.º 2
0
  /**
   * Initializes the <code>KoLmafia</code> session. Called after the login has been confirmed to
   * notify that the login was successful, the user-specific settings should be loaded, and the user
   * can begin adventuring.
   */
  public static void initialize(final String username) {
    // Load the JSON string first, so we can use it, if necessary.
    ActionBarManager.loadJSONString();

    // Initialize the variables to their initial states to avoid
    // null pointers getting thrown all over the place

    // Do this first to reset per-player item aliases
    ItemDatabase.reset();

    KoLCharacter.reset(username);

    // Get rid of cached password hashes in KoLAdventures
    AdventureDatabase.refreshAdventureList();

    // Reset all per-player information

    ChatManager.reset();
    MailManager.clearMailboxes();
    StoreManager.clearCache();
    DisplayCaseManager.clearCache();
    ClanManager.clearCache();

    CampgroundRequest.reset();
    MushroomManager.reset();
    HermitRequest.initialize();
    SpecialOutfit.forgetCheckpoints();

    KoLmafia.updateDisplay("Initializing session for " + username + "...");
    Preferences.setString("lastUsername", username);

    // Perform requests to read current character's data

    StaticEntity.getClient().refreshSession();

    // Reset the session tally and encounter list

    StaticEntity.getClient().resetSession();

    // Open the session log and indicate that we've logged in.

    RequestLogger.openSessionLog();

    if (Preferences.getBoolean("logStatusOnLogin")) {
      KoLmafiaCLI.DEFAULT_SHELL.executeCommand("log", "snapshot");
    }

    // If the password hash is non-null, then that means you
    // might be mid-transition.

    if (GenericRequest.passwordHash.equals("")) {
      PasswordHashRequest request = new PasswordHashRequest("lchat.php");
      RequestThread.postRequest(request);
    }

    ContactManager.registerPlayerId(username, String.valueOf(KoLCharacter.getUserId()));

    if (Preferences.getString("spadingData").length() > 10) {
      KoLmafia.updateDisplay(
          "Some data has been collected that may be of interest "
              + "to others.  Please type `spade' to examine and submit or delete this data.");
    }

    // Rebuild Scripts menu if needed
    GenericFrame.compileScripts();

    if (StaticEntity.getClient() instanceof KoLmafiaGUI) {
      KoLmafiaGUI.intializeMainInterfaces();
    } else if (Preferences.getString("initialFrames").indexOf("LocalRelayServer") != -1) {
      KoLmafiaGUI.constructFrame("LocalRelayServer");
    }

    String updateText;

    String holiday = HolidayDatabase.getHoliday(true);
    String moonEffect = HolidayDatabase.getMoonEffect();

    if (holiday.equals("")) {
      updateText = moonEffect;
    } else {
      updateText = holiday + ", " + moonEffect;
    }

    KoLmafia.updateDisplay(updateText);

    if (MailManager.hasNewMessages()) {
      KoLmafia.updateDisplay("You have new mail.");
    }
  }