Пример #1
0
  private static void doLogin(String name) {
    LoginRequest.isLoggingIn(true);

    try {
      ConcoctionDatabase.deferRefresh(true);
      LoginManager.initialize(name);
    } finally {
      ConcoctionDatabase.deferRefresh(false);
      LoginRequest.isLoggingIn(false);
    }

    // Abort further processing in Valhalla.
    if (CharPaneRequest.inValhalla()) {
      return;
    }

    // Abort further processing if we logged in to a fight or choice
    if (KoLmafia.isRefreshing()) {
      return;
    }

    if (Preferences.getBoolean(name, "getBreakfast")) {
      int today = HolidayDatabase.getPhaseStep();
      BreakfastManager.getBreakfast(Preferences.getInteger("lastBreakfast") != today);
      Preferences.setInteger("lastBreakfast", today);
    }

    if (Preferences.getBoolean("sharePriceData")) {
      KoLmafiaCLI.DEFAULT_SHELL.executeLine(
          "update prices http://kolmafia.us/scripts/updateprices.php?action=getmap");
    }

    // Also, do mushrooms, if a mushroom script has already
    // been setup by the user.

    if (Preferences.getBoolean(
        "autoPlant" + (KoLCharacter.canInteract() ? "Softcore" : "Hardcore"))) {
      String currentLayout = Preferences.getString("plantingScript");
      if (!currentLayout.equals("")
          && KoLCharacter.knollAvailable()
          && MushroomManager.ownsPlot()) {
        KoLmafiaCLI.DEFAULT_SHELL.executeLine(
            "call " + KoLConstants.PLOTS_DIRECTORY + currentLayout + ".ash");
      }
    }

    String scriptSetting = Preferences.getString("loginScript");
    if (!scriptSetting.equals("")) {
      KoLmafiaCLI.DEFAULT_SHELL.executeLine(scriptSetting);
    }

    if (EventManager.hasEvents()) {
      KoLmafiaCLI.DEFAULT_SHELL.executeLine("events");
    }
  }
Пример #2
0
 public static final void handleTemporaryCounters(final String type, final String encounter) {
   String temp = Preferences.getString("_tempRelayCounters");
   if (temp.equals("")) {
     return;
   }
   int snarfblat = KoLAdventure.lastAdventureId();
   if (snarfblat == 0
       || snarfblat == AdventurePool.THE_SHORE
       || snarfblat == AdventurePool.TRAINING_SNOWMAN
       || snarfblat == AdventurePool.DIRE_WARREN
       || (snarfblat >= AdventurePool.GINGERBREAD_CIVIC
           && snarfblat <= AdventurePool.GINGERBREAD_SEWERS)) {
     return;
   }
   if (type.equals("Combat")) {
     if (EncounterManager.isNoWanderMonster(encounter)) {
       return;
     }
   }
   String[] counters = temp.split("\\|");
   for (String counter : counters) {
     if (counter.equals("")) continue;
     String[] values = counter.split(":");
     TurnCounter.startCounting(StringUtilities.parseInt(values[0]), values[1], values[2]);
   }
   Preferences.setString("_tempRelayCounters", "");
 }
Пример #3
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;
  }
Пример #4
0
  public static final void loadCounters() {
    synchronized (TurnCounter.relayCounters) {
      TurnCounter.relayCounters.clear();

      String counters = Preferences.getString("relayCounters");
      if (counters.length() == 0) {
        return;
      }

      StringTokenizer tokens = new StringTokenizer(counters, ":");
      while (tokens.hasMoreTokens()) {
        int turns = StringUtilities.parseInt(tokens.nextToken()) - KoLCharacter.getCurrentRun();
        if (!tokens.hasMoreTokens()) break;
        String name = tokens.nextToken();
        if (!tokens.hasMoreTokens()) break;
        String image = tokens.nextToken();
        startCountingInternal(turns, name, image);
      }
    }
  }
Пример #5
0
  @Override
  public Value execute(final String functionName, final Object[] parameters) {
    String importString = Preferences.getString("commandLineNamespace");

    boolean shouldRefresh = !this.lastImportString.equals(importString);

    if (!shouldRefresh) {
      TreeMap imports = this.parser.getImports();
      Iterator it = imports.entrySet().iterator();

      while (it.hasNext() && !shouldRefresh) {
        Entry entry = (Entry) it.next();
        File file = (File) entry.getKey();
        Long date = (Long) entry.getValue();
        shouldRefresh = date.longValue() != file.lastModified();
      }
    }

    if (shouldRefresh && !refresh(importString)) {
      return DataTypes.VOID_VALUE;
    }

    return super.execute(functionName, parameters, shouldRefresh);
  }
Пример #6
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.");
    }
  }
Пример #7
0
 public static final void startCountingTemporary(int value, String label, String image) {
   String temp = Preferences.getString("_tempRelayCounters");
   temp = temp + value + ":" + label + ":" + image + "|";
   Preferences.setString("_tempRelayCounters", temp);
 }
Пример #8
0
  @Override
  public void run(final String cmd, final String parameters) {
    int splitIndex = parameters.indexOf("=");
    if (splitIndex == -1) {
      // Allow reading of system properties

      if (parameters.startsWith("System.")) {
        RequestLogger.printLine(System.getProperty(parameters.substring(7)));
      } else if (Preferences.isUserEditable(parameters)) {
        RequestLogger.printLine(Preferences.getString(parameters));
      }

      return;
    }

    String name = parameters.substring(0, splitIndex).trim();
    if (!Preferences.isUserEditable(name)) {
      return;
    }

    String value = parameters.substring(splitIndex + 1).trim();
    if (value.startsWith("\"")) {
      value = value.substring(1, value.endsWith("\"") ? value.length() - 1 : value.length());
    }

    while (value.endsWith(";")) {
      value = value.substring(0, value.length() - 1).trim();
    }

    if (name.equals("battleAction")) {
      if (value.contains(";") || value.startsWith("consult")) {
        CombatActionManager.setDefaultAction(value);
        value = "custom combat script";
      } else {
        value = CombatActionManager.getLongCombatOptionName(value);
      }

      // Special handling of the battle action property,
      // such that auto-recovery gets reset as needed.

      if (name.equals("battleAction") && value != null) {
        LockableListFactory.setSelectedItem(KoLCharacter.getBattleSkillNames(), value);
      }
    }

    if (name.equals("customCombatScript")) {
      ChangeCombatScriptCommand.update(value);
      return;
    }

    if (name.startsWith("combatHotkey")) {
      String desiredValue = CombatActionManager.getLongCombatOptionName(value);

      if (!desiredValue.startsWith("attack") || value.startsWith("attack")) {
        value = desiredValue;
      }
    }

    if (name.equals("_userMods")) {
      Modifiers.overrideModifier("Generated:_userMods", value);
      KoLCharacter.recalculateAdjustments();
      KoLCharacter.updateStatus();
    }

    if (Preferences.getString(name).equals(value)) {
      return;
    }

    // suppress CLI output iff it is a pref that starts with _ AND is defined in defaults.txt
    if (!name.startsWith("_") || Preferences.containsDefault(name))
      RequestLogger.printLine(name + " => " + value);
    Preferences.setString(name, value);

    if (name.startsWith("combatHotkey")) {
      StationaryButtonDecorator.reloadCombatHotkeyMap();
    }
  }
Пример #9
0
  @Override
  public void run(final String cmd, final String parameters) {
    String[] params = parameters.trim().split("\\s+");
    if (params.length < 2) return; // Do something better here

    String command = params[0];
    String input = params[1];
    String output;

    if (input.equals("")) {
      output = command;
    }
    if (command.equals("enhance")) {
      int enhanceLimit = 1;
      String chips = Preferences.getString("sourceTerminalChips");
      String files = Preferences.getString("sourceTerminalEnhanceKnown");
      if (chips.contains("CRAM")) enhanceLimit++;
      if (chips.contains("SCRAM")) enhanceLimit++;
      if (Preferences.getInteger("_sourceTerminalEnhanceUses") >= enhanceLimit) {
        KoLmafia.updateDisplay(
            KoLConstants.MafiaState.ERROR, "Source Terminal enhance limit reached");
        return;
      }

      if (input.startsWith("item")) {
        output = "enhance items.enh";
      } else if (input.startsWith("init")) {
        output = "enhance init.enh";
      } else if (input.startsWith("meat")) {
        output = "enhance meat.enh";
      } else if (input.startsWith("sub") && files.contains("substats.enh")) {
        output = "enhance substats.enh";
      } else if (input.startsWith("damage") && files.contains("damage.enh")) {
        output = "enhance damage.enh";
      } else if (input.startsWith("crit") && files.contains("critical.enh")) {
        output = "enhance critical.enh";
      } else {
        KoLmafia.updateDisplay(
            KoLConstants.MafiaState.ERROR, input + " is not a valid enhance target.");
        return;
      }
    } else if (command.equals("enquiry")) {
      String files = Preferences.getString("sourceTerminalEnquiryKnown");

      if (input.startsWith("fam")) {
        output = "enquiry familiar.enq";
      } else if (input.startsWith("mon")) {
        output = "enquiry monsters.enq";
      } else if (input.startsWith("protect") && files.contains("protect.enq")) {
        output = "enquiry protect.enq";
      } else if (input.startsWith("stat") && files.contains("stats.enq")) {
        output = "enquiry stats.enq";
      } else {
        KoLmafia.updateDisplay(
            KoLConstants.MafiaState.ERROR, input + " is not a valid enquiry target.");
        return;
      }
    } else if (command.equals("educate")) {
      String files = Preferences.getString("sourceTerminalEducateKnown");

      if (input.startsWith("compr") && files.contains("compress.edu")) {
        output = "educate compress.edu";
      } else if (input.startsWith("digit")) {
        output = "educate digitize.edu";
      } else if (input.startsWith("dup") && files.contains("duplicate.edu")) {
        output = "educate duplicate.edu";
      } else if (input.startsWith("extr")) {
        output = "educate extract.edu";
      } else if (input.startsWith("port") && files.contains("portscan.edu")) {
        output = "educate portscan.edu";
      } else if (input.startsWith("turbo") && files.contains("turbo.edu")) {
        output = "educate turbo.edu";
      } else {
        KoLmafia.updateDisplay(
            KoLConstants.MafiaState.ERROR, input + " is not a valid educate target.");
        return;
      }
    } else if (command.equals("extrude")) {
      if (Preferences.getInteger("_sourceTerminalExtrudes") >= 3) {
        KoLmafia.updateDisplay(
            KoLConstants.MafiaState.ERROR, "Source Terminal extrude limit reached");
        return;
      }

      String files = Preferences.getString("sourceTerminalExtrudeKnown");

      if (input.startsWith("booze") || input.contains("gibson")) {
        output = "extrude -f booze.ext";
      } else if (input.startsWith("food") || input.contains("cookie")) {
        output = "extrude -f food.ext";
      } else if (input.startsWith("fam") && files.contains("familiar.ext")) {
        output = "extrude -f familiar.ext";
      } else if (input.startsWith("goggles")) {
        output = "extrude -f goggles.ext";
      } else if (input.startsWith("cram") && files.contains("cram.ext")) {
        output = "extrude -f cram.ext";
      } else if (input.startsWith("dram") && files.contains("dram.ext")) {
        output = "extrude -f dram.ext";
      } else if (input.startsWith("gram") && files.contains("gram.ext")) {
        output = "extrude -f gram.ext";
      } else if (input.startsWith("pram") && files.contains("pram.ext")) {
        output = "extrude -f pram.ext";
      } else if (input.startsWith("spam") && files.contains("spam.ext")) {
        output = "extrude -f spam.ext";
      } else if (input.startsWith("tram") && files.contains("tram.ext")) {
        output = "extrude -f tram.ext";
      } else {
        KoLmafia.updateDisplay(
            KoLConstants.MafiaState.ERROR, input + " is not a valid extrude target.");
        return;
      }
    } else {
      KoLmafia.updateDisplay(
          KoLConstants.MafiaState.ERROR, command + " is not a valid terminal command.");
      return;
    }

    RequestThread.postRequest(new TerminalRequest(output));
  }