public static void prepare() { // If there's no user to worry about, we're done now. String userName = KoLCharacter.getUserName(); if (userName == null || userName.equals("")) { return; } // If you need to allow for another login, create a login frame // to ensure that there is an active frame to display messages. if (StaticEntity.getClient() instanceof KoLmafiaGUI) { KoLmafiaGUI.constructFrame(LoginFrame.class); } // Shut down main frame if (KoLDesktop.instanceExists()) { KoLDesktop.getInstance().dispose(); } // Close down any other active frames. Since // there is at least one active, logout will // not be called again. Frame[] frames = Frame.getFrames(); for (int i = 0; i < frames.length; ++i) { if (frames[i].getClass() != LoginFrame.class) { frames[i].dispose(); } } }
/** * 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."); } }