public static final boolean registerRequest(final String urlString) {
    if (!urlString.startsWith("crimbo10.php")) {
      return false;
    }

    String action = GenericRequest.getAction(urlString);
    String message = null;

    // We want to log certain simple visits
    if (action == null) {
      message = Crimbo10Request.visitLocation(urlString);
    }

    // Buy stuff in the CRIMBCO Gift Shop
    else if (action.equals("buygift")) {
      // Let CRIMBCOGiftShopRequest claim this
      return CRIMBCOGiftShopRequest.registerRequest(urlString);
    }

    // Unknown action
    else {
      return false;
    }

    if (message == null) {
      return true;
    }

    RequestLogger.printLine();
    RequestLogger.updateSessionLog();
    RequestLogger.printLine(message);
    RequestLogger.updateSessionLog(message);

    return true;
  }
示例#2
0
  @Override
  public void run(final String cmd, final String parameters) {
    String[][] banishData = BanishManager.getBanishData();

    StringBuilder output = new StringBuilder();

    if (banishData != null) {
      output.append("<table border=2 cols=4>");
      output.append("<tr>");
      output.append("<th>Monsters Banished</th>");
      output.append("<th>Banished By</th>");
      output.append("<th>On Turn</th>");
      output.append("<th>Turns Left</th>");
      output.append("</tr>");

      for (String[] banish : banishData) {
        output.append("<tr>");

        for (int i = 0; i < 4; i++) {
          output.append("<td>");
          output.append(banish[i]);
          output.append("</td>");
        }
        output.append("</tr>");
      }

      output.append("</table>");
    } else {
      output.append("No current banishes");
    }

    RequestLogger.printLine(output.toString());
    RequestLogger.printLine();
  }
  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;
  }
  @Override
  public void run(final String command, final String parameters) {
    boolean isSpeculateOnly = KoLmafiaCLI.isExecutingCheckOnlyCommand;

    if (!MaximizerFrame.maximize(parameters, 0, 0, isSpeculateOnly) && !isSpeculateOnly) {
      KoLmafia.updateDisplay(
          MafiaState.ERROR, "Unable to meet all requirements via equipment changes.");
      RequestLogger.printLine("See the Modifier Maximizer for further suggestions.");
    }
  }
示例#5
0
  @Override
  public void run(final String cmd, String parameters) {
    int spaceIndex = parameters.indexOf(" ");
    String color = "#000000";

    if (spaceIndex != -1) {
      color = parameters.substring(0, spaceIndex).replaceAll("[\">]", "");
    }

    parameters = parameters.substring(spaceIndex + 1);
    StringUtilities.globalStringReplace(parameters, "<", "&lt;");
    RequestLogger.printLine("<font color=\"" + color + "\">" + parameters + "</font>");
  }
  public static void use(final String command, String parameters) {
    if (parameters.equals("")) {
      return;
    }

    boolean either = parameters.startsWith("either ");
    if (either) {
      parameters = parameters.substring(7).trim();
    }

    if (command.equals("eat") || command.equals("eatsilent")) {
      if (KoLCharacter.inBadMoon() && KitchenCommand.visit(parameters)) {
        return;
      }
      if (KoLCharacter.canadiaAvailable() && RestaurantCommand.makeChezSnooteeRequest(parameters)) {
        return;
      }
    }

    if (command.equals("drink") || command.equals("overdrink")) {
      if (KoLCharacter.inBadMoon() && KitchenCommand.visit(parameters)) {
        return;
      }
      if (KoLCharacter.gnomadsAvailable()
          && RestaurantCommand.makeMicroBreweryRequest(parameters)) {
        return;
      }
    }

    // Now, handle the instance where the first item is actually
    // the quantity desired, and the next is the amount to use

    if (command.equals("eat") || command.equals("eatsilent") || command.equals("ghost")) {
      ItemFinder.setMatchType(ItemFinder.FOOD_MATCH);
    } else if (command.equals("drink") || command.equals("overdrink") || command.equals("hobo")) {
      ItemFinder.setMatchType(ItemFinder.BOOZE_MATCH);
    } else if (command.equals("slimeling")) {
      ItemFinder.setMatchType(ItemFinder.EQUIP_MATCH);
    } else {
      ItemFinder.setMatchType(ItemFinder.USE_MATCH);
    }

    Object[] itemList = ItemFinder.getMatchingItemList(KoLConstants.inventory, parameters);

    ItemFinder.setMatchType(ItemFinder.ANY_MATCH);

    for (int level = either ? 0 : 2;
        level <= 2;
        ++level) { // level=0: use only items in inventory, exit on first success
      // level=1: buy/make as needed, exit on first success
      // level=2: use all items in list, buy/make as needed
      for (int i = 0; i < itemList.length; ++i) {
        AdventureResult currentMatch = (AdventureResult) itemList[i];
        int consumpt = ItemDatabase.getConsumptionType(currentMatch.getItemId());

        if (command.equals("eat") && consumpt == KoLConstants.CONSUME_FOOD_HELPER) { // allowed
        } else if (command.equals("eat") || command.equals("ghost")) {
          if (consumpt != KoLConstants.CONSUME_EAT) {
            KoLmafia.updateDisplay(
                MafiaState.ERROR, currentMatch.getName() + " cannot be consumed.");
            return;
          }
        }

        if (command.equals("drink") && consumpt == KoLConstants.CONSUME_DRINK_HELPER) { // allowed
        } else if (command.equals("drink") || command.equals("hobo")) {
          if (consumpt != KoLConstants.CONSUME_DRINK) {
            KoLmafia.updateDisplay(
                MafiaState.ERROR, currentMatch.getName() + " is not an alcoholic beverage.");
            return;
          }
        }

        if (command.equals("use")) {
          switch (consumpt) {
            case KoLConstants.CONSUME_EAT:
            case KoLConstants.CONSUME_FOOD_HELPER:
              KoLmafia.updateDisplay(MafiaState.ERROR, currentMatch.getName() + " must be eaten.");
              return;
            case KoLConstants.CONSUME_DRINK:
            case KoLConstants.CONSUME_DRINK_HELPER:
              KoLmafia.updateDisplay(
                  MafiaState.ERROR, currentMatch.getName() + " is an alcoholic beverage.");
              return;
          }
        }

        int have = currentMatch.getCount(KoLConstants.inventory);
        if (level > 0 || have > 0) {
          if (level == 0 && have < currentMatch.getCount()) {
            currentMatch = currentMatch.getInstance(have);
          }
          if (KoLmafiaCLI.isExecutingCheckOnlyCommand) {
            RequestLogger.printLine(currentMatch.toString());
          } else {
            UseItemRequest request =
                command.equals("hobo")
                    ? UseItemRequest.getInstance(KoLConstants.CONSUME_HOBO, currentMatch)
                    : command.equals("ghost")
                        ? UseItemRequest.getInstance(KoLConstants.CONSUME_GHOST, currentMatch)
                        : command.equals("slimeling")
                            ? UseItemRequest.getInstance(KoLConstants.CONSUME_SLIME, currentMatch)
                            : UseItemRequest.getInstance(currentMatch);
            RequestThread.postRequest(request);
          }

          if (level < 2) {
            return;
          }
        }
      }
    }
  }
示例#7
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.");
    }
  }
  private void snapshot(final String parameters) {
    RequestLogger.updateSessionLog();
    RequestLogger.updateSessionLog("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

    RequestLogger.getDebugStream().println();
    RequestLogger.getDebugStream().println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

    StringBuffer title = new StringBuffer("Player Snapshot");

    int leftIndent = (46 - title.length()) / 2;
    for (int i = 0; i < leftIndent; ++i) {
      title.insert(0, ' ');
    }

    RequestLogger.updateSessionLog(title.toString());
    RequestLogger.updateSessionLog("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

    RequestLogger.getDebugStream().println(title.toString());
    RequestLogger.getDebugStream().println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

    String[] options = parameters.split("\\s*,\\s*");

    for (int i = 0; i < options.length; ++i) {
      RequestLogger.updateSessionLog();
      RequestLogger.updateSessionLog(" > " + options[i]);

      ShowDataCommand.show(options[i], true);
    }

    RequestLogger.updateSessionLog();
    RequestLogger.updateSessionLog("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

    RequestLogger.getDebugStream().println();
    RequestLogger.getDebugStream().println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");

    RequestLogger.updateSessionLog();
    RequestLogger.updateSessionLog();

    RequestLogger.getDebugStream().println();
    RequestLogger.getDebugStream().println();
  }
  public static boolean makeChezSnooteeRequest(final String parameters) {
    if (!KoLCharacter.canadiaAvailable()) {
      KoLmafia.updateDisplay(
          "Since you have no access to Little Canadia, you may not visit the restaurant.");
      return false;
    }

    if (KoLConstants.restaurantItems.isEmpty()) {
      ChezSnooteeRequest.getMenu();
    }

    if (parameters.equals("")) {
      RequestLogger.printLine("Today's Special: " + ChezSnooteeRequest.getDailySpecial());
      return false;
    }

    String[] splitParameters = AbstractCommand.splitCountAndName(parameters);
    String countString = splitParameters[0];
    String nameString = splitParameters[1];

    if (nameString.equalsIgnoreCase("daily special")) {
      nameString = ChezSnooteeRequest.getDailySpecial().getName();
    } else if (nameString.startsWith("\u00B6")) {
      String name = ItemDatabase.getItemName(StringUtilities.parseInt(nameString.substring(1)));
      if (name != null) {
        nameString = name;
      }
    }

    nameString = nameString.toLowerCase();

    for (int i = 0; i < KoLConstants.restaurantItems.size(); ++i) {
      String name = (String) KoLConstants.restaurantItems.get(i);

      if (!StringUtilities.substringMatches(name.toLowerCase(), nameString, false)) {
        continue;
      }

      if (KoLmafiaCLI.isExecutingCheckOnlyCommand) {
        RequestLogger.printLine(name);
        return true;
      }

      int count =
          countString == null || countString.length() == 0
              ? 1
              : StringUtilities.parseInt(countString);

      if (count == 0) {
        int fullness = ItemDatabase.getFullness(name);
        if (fullness > 0) {
          count = (KoLCharacter.getFullnessLimit() - KoLCharacter.getFullness()) / fullness;
        }
      }

      for (int j = 0; j < count; ++j) {
        RequestThread.postRequest(new ChezSnooteeRequest(name));
      }

      return true;
    }

    return false;
  }
  @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();
    }
  }