Ejemplo n.º 1
1
 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
     throws BadLocationException {
   StringBuilder builder = new StringBuilder(string);
   for (int i = builder.length() - 1; i >= 0; i--) {
     int cp = builder.codePointAt(i);
     if (!Character.isDigit(cp) && cp != '-') {
       builder.deleteCharAt(i);
       if (Character.isSupplementaryCodePoint(cp)) {
         i--;
         builder.deleteCharAt(i);
       }
     }
   }
   super.insertString(fb, offset, builder.toString(), attr);
 }
Ejemplo n.º 2
0
 public static boolean isFormat(String str, String... format) {
   if (str.length() == 0) return format.length == 1 && format[0].equals("");
   char[] charset = str.toCharArray();
   int c = 0;
   for (int i = 0; i < format.length; i++) {
     String form = format[i];
     if (form.equals(NUMBERS)) {
       if (c >= charset.length) return false;
       if (!Character.isDigit(charset[c])) {
         if (charset[c] == '.') {
           if (c + 1 >= charset.length || !Character.isDigit(charset[c + 1])) return false;
         } else return false;
       }
       while (c < charset.length - 1
           && (Character.isDigit(charset[c + 1]) || charset[c + 1] == '.')) c++;
       c++;
     } else if (form.equals(LETTERS)) {
       if (c >= charset.length || !Character.isLetter(charset[c])) return false;
       while (c < charset.length - 1 && Character.isLetter(charset[c + 1])) c++;
       c++;
     } else {
       char[] formchars = form.toCharArray();
       if (formchars.length > charset.length - c) return false;
       for (int ch = 0; ch < formchars.length; ch++) {
         if (formchars[ch] != charset[c]) return false;
         c++;
       }
     }
   }
   return c == charset.length;
 }
Ejemplo n.º 3
0
 /**
  * Modtager værtens svar, der godt kan løbe over flere linjer. Sidste linje er en svarkode på tre
  * cifre, uden en bindestreg '-' på plads nummer 4
  */
 private String læsSvar() throws IOException {
   while (true) {
     String s = ind.readLine();
     System.out.println("modt: " + s);
     if (s.length() >= 3
         && s.charAt(3) != '-'
         && Character.isDigit(s.charAt(0))
         && Character.isDigit(s.charAt(1))
         && Character.isDigit(s.charAt(2)))
       return s; // afslut løkken og returner sidste linje med statuskode
   }
 }
Ejemplo n.º 4
0
 public static String getDigits(String s) {
   String str = "";
   for (int i = 0; i < s.length(); i++) {
     if (Character.isDigit(s.charAt(i))) str += s.charAt(i);
   }
   return str;
 }
 /**
  * Gets the next token from a tokenizer and converts it to a long.
  *
  * @return The next token in the stream, as a long.
  * @throws TextParseException The input was invalid or not a long.
  * @throws IOException An I/O error occurred.
  */
 public long getLong() throws IOException {
   String next = _getIdentifier("an integer");
   if (!Character.isDigit(next.charAt(0))) throw exception("expected an integer");
   try {
     return Long.parseLong(next);
   } catch (NumberFormatException e) {
     throw exception("expected an integer");
   }
 }
Ejemplo n.º 6
0
 private int getDataLength(String s) {
   int i;
   for (i = 0; i < s.length() && !Character.isDigit(s.charAt(i)); i++) ; // do it
   if (i == s.length()) return -1;
   String len_str = s.substring(i);
   try {
     return Integer.parseInt(len_str);
   } catch (NumberFormatException ex) {
     return -1;
   }
 }
Ejemplo n.º 7
0
  // get signs using an additional arg for a target rel
  private Collection<Sign> getSignsFromPredAndTargetRel(String pred, String targetRel) {

    Collection<Word> words = (Collection<Word>) _predToWords.get(pred);
    String specialTokenConst = null;

    // for robustness, when using supertagger, add words for pred sans sense index
    int dotIndex = -1;
    if (_supertagger != null
        && !Character.isDigit(pred.charAt(0))
        && // skip numbers
        (dotIndex = pred.lastIndexOf('.')) > 0
        && pred.length() > dotIndex + 1
        && pred.charAt(dotIndex + 1) != '_') // skip titles, eg Mr._Smith
    {
      String barePred = pred.substring(0, dotIndex);
      Collection<Word> barePredWords = (Collection<Word>) _predToWords.get(barePred);
      if (words == null) words = barePredWords;
      else if (barePredWords != null) {
        Set<Word> unionWords = new HashSet<Word>(words);
        unionWords.addAll(barePredWords);
        words = unionWords;
      }
    }

    if (words == null) {
      specialTokenConst = tokenizer.getSpecialTokenConstant(tokenizer.isSpecialToken(pred));
      if (specialTokenConst == null) return null;
      // lookup words with pred = special token const
      Collection<Word> specialTokenWords = (Collection<Word>) _predToWords.get(specialTokenConst);
      // replace special token const with pred
      if (specialTokenWords == null) return null;
      words = new ArrayList<Word>(specialTokenWords.size());
      for (Iterator<Word> it = specialTokenWords.iterator(); it.hasNext(); ) {
        Word stw = it.next();
        Word w = Word.createSurfaceWord(stw, pred);
        words.add(w);
      }
    }

    List<Sign> retval = new ArrayList<Sign>();
    for (Iterator<Word> it = words.iterator(); it.hasNext(); ) {
      Word w = it.next();
      try {
        SignHash signs = getSignsFromWord(w, specialTokenConst, pred, targetRel);
        retval.addAll(signs.asSignSet());
      }
      // shouldn't happen
      catch (LexException exc) {
        System.err.println("Unexpected lex exception for word " + w + ": " + exc);
      }
    }
    return retval;
  }
Ejemplo n.º 8
0
Archivo: Macro.java Proyecto: bramk/bnd
  String version(Version version, String mask) {
    if (version == null) {
      String v = domain.getProperty("@");
      if (v == null) {
        domain.error(
            "No version specified for ${version} or ${range} and no implicit version ${@} either, mask=%s",
            mask);
        v = "0";
      }
      version = new Version(v);
    }

    StringBuilder sb = new StringBuilder();
    String del = "";

    for (int i = 0; i < mask.length(); i++) {
      char c = mask.charAt(i);
      String result = null;
      if (c != '~') {
        if (i == 3) {
          result = version.getQualifier();
        } else if (Character.isDigit(c)) {
          // Handle masks like +00, =+0
          result = String.valueOf(c);
        } else {
          int x = version.get(i);
          switch (c) {
            case '+':
              x++;
              break;
            case '-':
              x--;
              break;
            case '=':
              break;
          }
          result = Integer.toString(x);
        }
        if (result != null) {
          sb.append(del);
          del = ".";
          sb.append(result);
        }
      }
    }
    return sb.toString();
  }
Ejemplo n.º 9
0
 public static boolean isDigits(String s) {
   for (int i = 0; i < s.length(); i++) {
     if (!Character.isDigit(s.charAt(i))) return false;
   }
   return true;
 }
Ejemplo n.º 10
0
  private DarkBotMCSpambot(
      DarkBot darkBot,
      String server,
      String username,
      String password,
      String sessionId,
      String loginProxy,
      String proxy,
      String owner) {
    synchronized (bots) {
      bots.add(this);
      // slotsTaken.incrementAndGet();
      synchronized (slotsTaken) {
        slotsTaken.notifyAll();
      }
    }
    MinecraftBotData.Builder builder = MinecraftBotData.builder();
    // botData.nickname = "";
    // for(int i = 0; i < 10; i++)
    // botData.nickname += alphas[random.nextInt(alphas.length)];
    if (proxy != null && !proxy.isEmpty()) {
      int port = 80;
      ProxyType type = ProxyType.SOCKS;
      if (proxy.contains(":")) {
        String[] parts = proxy.split(":");
        proxy = parts[0];
        port = Integer.parseInt(parts[1]);
        if (parts.length > 2) type = ProxyType.values()[Integer.parseInt(parts[2]) - 1];
      }
      builder.withSocksProxy(new ProxyData(proxy, port, type));
      this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxy, port));
    }
    if (loginProxy != null && !loginProxy.isEmpty()) {
      int port = 80;
      if (loginProxy.contains(":")) {
        String[] parts = loginProxy.split(":");
        loginProxy = parts[0];
        port = Integer.parseInt(parts[1]);
      }
      builder.withHttpProxy(new ProxyData(loginProxy, port, ProxyType.HTTP));
      this.loginProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loginProxy, port));
    }
    builder.withUsername(username);
    if (sessionId != null) builder.withSessionId(sessionId);
    else builder.withPassword(password);
    if (server != null && !server.isEmpty()) {
      int port = 25565;
      if (server.contains(":")) {
        String[] parts = server.split(":");
        server = parts[0];
        port = Integer.parseInt(parts[1]);
      }
      builder.withServer(server).withPort(port);
    } else throw new IllegalArgumentException("Unknown server!");

    this.owner = owner;
    MinecraftBotData botData = builder.build();
    System.setProperty("socksProxyHost", "");
    System.setProperty("socksProxyPort", "");
    System.out.println("[" + username + "] Connecting...");
    bot = new MinecraftBot(darkBot, botData);
    bot.setMovementDisabled(true);
    connectionHandler = bot.getConnectionHandler();
    Session session = bot.getSession();
    // System.gc();
    System.out.println("[" + username + "] Done! (" + amountJoined.incrementAndGet() + ")");
    bot.getEventManager().registerListener(this);
    bot.getGameHandler().registerListener(this);

    long lastShoutTime = System.currentTimeMillis();
    while (bot.isConnected()) {
      if (die) {
        connectionHandler.sendPacket(new Packet255KickDisconnect("Goodbye"));
        return;
      }
      try {
        Thread.sleep(3000 + random.nextInt(1000));
      } catch (InterruptedException exception) {
        exception.printStackTrace();
      }
      if (!bot.hasSpawned()) continue;
      connectionHandler.sendPacket(new Packet0KeepAlive(random.nextInt()));
      if (spamMessage == null || !canSpam) continue;
      String message = spamMessage;
      if (message.contains("%skill")) message = message.replace("%skill", skills[nextSkill++]);
      if (nextSkill >= skills.length) nextSkill = 0;
      if (message.contains("%bot")) {
        synchronized (bots) {
          message =
              message.replace(
                  "%bot",
                  bots.get(nextBot > bots.size() ? (nextBot = 0) * 0 : nextBot++)
                      .bot
                      .getSession()
                      .getUsername());
        }
      }
      if (message.contains("%spamlist"))
        message = message.replace("%spamlist", spamList[nextSpamList++]);
      if (nextSpamList >= spamList.length) nextSpamList = 0;
      if (message.contains("%rnd")) {
        int length = 1;
        int index = message.indexOf("%rnd") + "%rnd".length();
        int lastIndex;
        for (lastIndex = index; lastIndex < message.length(); lastIndex++)
          if (Character.isDigit(message.charAt(lastIndex))) lastIndex++;
          else break;
        if (lastIndex > message.length()) lastIndex--;
        try {
          System.out.println(index + "," + lastIndex + "," + message.length());
          length = Integer.parseInt(message.substring(index, lastIndex));
        } catch (Exception exception) {
        }

        String randomChars = "";
        for (int i = 0; i < length; i++) randomChars += alphas[random.nextInt(alphas.length)];
        message = message.replace("%rnd", randomChars);
      }
      if (message.contains("%msg"))
        message = "/msg " + msgChars[nextMsgChar++] + " " + message.replace("%msg", "");
      if (message.contains("%ernd")) {
        message = message.replace("%ernd", "");
        int extraMessageLength = 15 + random.nextInt(6);
        message = message.substring(0, Math.min(100 - extraMessageLength, message.length())) + " [";
        extraMessageLength -= 3;
        for (int i = 0; i < extraMessageLength; i++)
          message += alphas[random.nextInt(alphas.length)];
        message += "]";
      } else message = message.substring(0, Math.min(100, message.length()));
      connectionHandler.sendPacket(new Packet3Chat(message));
    }
    synchronized (bots) {
      bots.remove(this);
    }
    amountJoined.decrementAndGet();
    slotsTaken.decrementAndGet();
    synchronized (slotsTaken) {
      slotsTaken.notifyAll();
    }
  }
Ejemplo n.º 11
0
  public static File[] getHighestJarVersions(
      File[] files,
      String[] version_out,
      String[] id_out, // currently the version of last versioned jar found...
      boolean discard_non_versioned_when_versioned_found) {
    // WARNING!!!!
    // don't use Debug/lglogger here as we can be called before AZ has been initialised

    List res = new ArrayList();
    Map version_map = new HashMap();

    for (int i = 0; i < files.length; i++) {

      File f = files[i];

      String name = f.getName().toLowerCase();

      if (name.endsWith(".jar")) {

        int cvs_pos = name.lastIndexOf("_cvs");

        int sep_pos;

        if (cvs_pos <= 0) sep_pos = name.lastIndexOf("_");
        else sep_pos = name.lastIndexOf("_", cvs_pos - 1);

        if (sep_pos == -1
            || sep_pos == name.length() - 1
            || !Character.isDigit(name.charAt(sep_pos + 1))) {

          // not a versioned jar

          res.add(f);

        } else {

          String prefix = name.substring(0, sep_pos);

          String version =
              name.substring(sep_pos + 1, (cvs_pos <= 0) ? name.length() - 4 : cvs_pos);

          String prev_version = (String) version_map.get(prefix);

          if (prev_version == null) {

            version_map.put(prefix, version);

          } else {

            if (PluginUtils.comparePluginVersions(prev_version, version) < 0) {

              version_map.put(prefix, version);
            }
          }
        }
      }
    }

    // If any of the jars are versioned then the assumption is that all of them are
    // For migration purposes (i.e. on the first real introduction of the update versioning
    // system) we drop all non-versioned jars from the set

    if (version_map.size() > 0 && discard_non_versioned_when_versioned_found) {

      res.clear();
    }

    // fix a problem we had with the rating plugin. It went out as rating_x.jar when it should
    // have been azrating_x.jar. If there are any azrating entries then we remove any rating ones
    // to avoid load problems

    if (version_map.containsKey("azrating")) {

      version_map.remove("rating");
    }

    Iterator it = version_map.keySet().iterator();

    while (it.hasNext()) {

      String prefix = (String) it.next();
      String version = (String) version_map.get(prefix);

      String target = prefix + "_" + version;

      version_out[0] = version;
      id_out[0] = prefix;

      for (int i = 0; i < files.length; i++) {

        File f = files[i];

        String lc_name = f.getName().toLowerCase();

        if (lc_name.equals(target + ".jar") || lc_name.equals(target + "_cvs.jar")) {

          res.add(f);

          break;
        }
      }
    }

    File[] res_array = new File[res.size()];

    res.toArray(res_array);

    return (res_array);
  }