Exemple #1
0
  /**
   * Publish
   *
   * <p>Send a message to a channel.
   *
   * @param String channel name.
   * @param JSONObject message.
   * @return boolean false on fail.
   */
  public JSONArray publish(String channel, JSONObject message) {
    // Generate String to Sign
    String signature = "0";
    if (this.SECRET_KEY.length() > 0) {
      StringBuilder string_to_sign = new StringBuilder();
      string_to_sign
          .append(this.PUBLISH_KEY)
          .append('/')
          .append(this.SUBSCRIBE_KEY)
          .append('/')
          .append(this.SECRET_KEY)
          .append('/')
          .append(channel)
          .append('/')
          .append(message.toString());

      // Sign Message
      signature = md5(string_to_sign.toString());
    }

    // Build URL
    List<String> url = new ArrayList<String>();
    url.add("publish");
    url.add(this.PUBLISH_KEY);
    url.add(this.SUBSCRIBE_KEY);
    url.add(signature);
    url.add(channel);
    url.add("0");
    url.add(message.toString());

    // Return JSONArray
    return _request(url);
  }
 public String getSlot(String slotString, boolean largeResponse) {
   try {
     return getSlot(new BigInteger(slotString));
   } catch (Exception e) {
     // going to load all slots made by user.
   }
   JSONArray json = getJSON();
   if (!largeResponse) {
     int entries = 0;
     for (int i = 0; i < json.length(); i++) {
       JSONObject o = json.getJSONObject(i);
       if (o == null) continue;
       if (o.getString("name").toLowerCase().equals(slotString.toLowerCase())) entries++;
     }
     if (entries > 0) return slotString + " owns " + entries + " savestates!!! :D/";
     return slotString + " doesnt own any savestates );";
   }
   StringBuilder slots = new StringBuilder();
   int entries = 0;
   for (int i = 0; i < json.length(); i++) {
     JSONObject o = json.getJSONObject(i);
     if (o == null) continue;
     if (o.getString("name").toLowerCase().equals(slotString.toLowerCase())) {
       entries++;
       slots.append(o.getString("slot")).append(", ");
     }
   }
   if (entries > 0) {
     slots.deleteCharAt(slots.length() - 1);
     slots.deleteCharAt(slots.length() - 1);
     return "owha! " + slotString + " owns slot(s) " + slots.toString() + "!!!! :D :D :D/";
   }
   return slotString + " doesn't own any savestates!! (u should fix that !! O:)";
 }
  public String markOf(String username, int sentenceSize) {
    username = username.trim();
    JSONArray json = getJSON();
    ArrayList<String> words = new ArrayList<>();

    if (sentenceSize <= 0) sentenceSize = ((int) (Math.random() * 6)) + 5;
    if (sentenceSize > 50) sentenceSize = 50;

    for (int i = 0; i < json.length(); i++) {
      JSONObject savestate = json.getJSONObject(i);
      if (savestate.getString("name").toLowerCase().equals(username.toLowerCase())) {
        String[] splitMessage = savestate.getString("message").split("\\s+");
        words.addAll(Arrays.asList(splitMessage));
      }
    }

    if (words.isEmpty()) {
      return "helo there that person SUCKS for not having any SAVESTATES O:<";
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < sentenceSize; i++) /**/
      sb.append(words.get(rand.nextInt(words.size()))).append(' ');
    return sb.toString().trim();
  }
Exemple #4
0
  @JavascriptInterface
  public String approveNewVolunteersInit() {
    HttpURLConnection connection = null;
    OutputStreamWriter wr = null;
    BufferedReader rd = null;
    StringBuilder sb = null;
    String line = null;
    String ret;

    URL serverAddress = null;

    try {
      serverAddress =
          new URL(
              "http://env-3010859.jelastic.servint.net/Controller/approveNewVolunteersInit.jsp");

      // Set up the initial connection
      connection = (HttpURLConnection) serverAddress.openConnection();
      connection.setRequestMethod("GET");
      // connection.setDoOutput(true);
      connection.setReadTimeout(10000);
      // connection = (HttpURLConnection) serverAddress.openConnection();

      // get the output stream writer and write the output to the server
      // not needed in this example
      /*
       wr = new OutputStreamWriter(connection.getOutputStream());
       wr.write("");
       wr.flush();
      */

      // read the result from the server
      rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      sb = new StringBuilder();

      while ((line = rd.readLine()) != null) {
        sb.append(line);
      }
      ret = sb.toString();

    } catch (MalformedURLException e) {
      e.printStackTrace();
      ret = "false1";
    } catch (ProtocolException e) {
      e.printStackTrace();
      ret = "false2";
    } catch (IOException e) {
      e.printStackTrace();
      ret = "false3";
    } finally {
      // close the connection, set all objects to null
      connection.disconnect();
      rd = null;
      sb = null;
      wr = null;
      connection = null;
    }
    return (ret);
  }
Exemple #5
0
 private String _encodeURIcomponent(String s) {
   StringBuilder o = new StringBuilder();
   for (char ch : s.toCharArray()) {
     if (isUnsafe(ch)) {
       o.append('%');
       o.append(toHex(ch / 16));
       o.append(toHex(ch % 16));
     } else o.append(ch);
   }
   return o.toString();
 }
  private static String readAll(Reader rd) throws IOException {
    StringBuilder sb = new StringBuilder(); /*
												 * readall builds the contents
												 * of the strings in the buffer
												 */
    int cp;
    while ((cp = rd.read()) != -1) {
      sb.append((char) cp);
    }
    return sb.toString();
  }
 /** @return Returns a JSON Array of the JSON database */
 private JSONArray getJSON() {
   try {
     File file = new File(filename);
     InputStream is = new FileInputStream(file);
     BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
     StringBuilder sb = new StringBuilder();
     String line;
     while ((line = in.readLine()) != null) sb.append(line).append("\n");
     JSONTokener tokenizer = new JSONTokener(sb.toString());
     return new JSONArray(tokenizer);
   } catch (IOException | JSONException e) {
     return null;
   }
 }
 public String search(String term, boolean largeResponse) {
   int MIN_SEARCH_SIZE = 3;
   if (!(term.length() >= MIN_SEARCH_SIZE)) {
     return "\""
         + term
         + "\" is 2 small !! gotta add "
         + (MIN_SEARCH_SIZE - term.length())
         + " more chars d;";
   }
   JSONArray json = getJSON();
   StringBuilder sb = new StringBuilder();
   int size = 0;
   for (int i = 0; i < json.length(); i++) {
     JSONObject savestate = json.getJSONObject(i);
     if (savestate.getString("message").toLowerCase().contains(term.trim().toLowerCase())) {
       sb.append(savestate.getString("slot")).append(", ");
       size++;
     }
   }
   if (sb.length() == 0) return "no search resluts! )^:";
   if (largeResponse) return term + ": " + sb.toString().substring(0, sb.toString().length() - 2);
   else return term + ": " + size + " resluts found !!! (go 2 #savespam 2 view em !)";
 }
 public String chain(String username, boolean verbose, int sentenceSize) {
   username = username.trim();
   JSONArray json = getJSON();
   ArrayList<String> words = new ArrayList<>();
   for (int i = 0; i < json.length(); i++) {
     JSONObject savestate = json.getJSONObject(i);
     if (savestate.getString("name").toLowerCase().equals(username.toLowerCase())) {
       String[] splitMessage = savestate.getString("message").split("\\s+");
       words.addAll(Arrays.asList(splitMessage));
     }
   }
   if (words.isEmpty()) {
     return "helo there that person SUCKS for not having any SAVESTATES O:<";
   }
   StringBuilder sb = new StringBuilder();
   // all words are in "words"
   // pick a word out at random!
   int wordIndex = (int) (Math.random() * words.size());
   if (sentenceSize <= 0) sentenceSize = ((int) (Math.random() * 6)) + 5;
   if (sentenceSize > 50) sentenceSize = 50;
   for (int i = 0; i < sentenceSize; i++) {
     // get current word
     sb.append(words.get(wordIndex)).append(' ');
     // 40% chance we'll stay on the same sentence.
     if (Math.random() > 0.40) {
       // different sentence
       // make an array of all the .toLowerCase() matches of the current word
       ArrayList<Integer> wordIndexes = new ArrayList<>();
       for (int j = 0; j < words.size(); j++) {
         if (words.get(j).equalsIgnoreCase(words.get(wordIndex))) wordIndexes.add(j);
       }
       // we have all the word indexes in wordIndexes
       // ... if there are none, we'll just follow the current word (since it'll match)
       int sameWordIndex = (int) (Math.random() * wordIndexes.size());
       wordIndex = wordIndexes.get(sameWordIndex) + 1;
     } else {
       wordIndex++;
     }
     if (wordIndex >= words.size()) {
       // in case we go over!!!
       // new random number
       wordIndex = (int) (Math.random() * words.size());
     }
   }
   return sb.toString();
 }
  public String log() {
    StringBuilder sb = new StringBuilder();
    sb.append("<!DOCTYPE html>\n");
    sb.append("<html>\n");
    sb.append("    <head>\n");
    sb.append("    <title>dongs!!!!</title>\n");
    sb.append("    </head>\n");
    sb.append("    <body>\n");
    sb.append("        <h4>SaveyBot's Savestates!!! :D :D :D/</h4>\n");
    sb.append("        <br />\n");
    sb.append("        <table style='table-layout: fixed; width: 100%'><tbody class=\"list\">\n");

    JSONArray json = getJSON();

    for (int i = 0; i < json.length(); i++) {
      JSONObject savestate = json.getJSONObject(i);
      sb.append("            <tr>\n");
      sb.append("                <td class=\"slot\" style='word-wrap: break-word;'>")
          .append(savestate.getString("slot"))
          .append("</td>\n");
      sb.append("                <td class=\"name\" style='word-wrap: break-word;'>")
          .append(savestate.getString("name"))
          .append("</td>\n");
      sb.append("                <td class=\"message\" style='word-wrap: break-word;'>")
          .append(savestate.getString("message"))
          .append("</td>\n");
      sb.append("            </tr>\n");
    }

    sb.append("        </tbody></table>\n");
    sb.append("    </body>\n");
    sb.append("</html>\n");
    sb.append("\n\n\n\n");

    DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Date date = new Date();
    sb.append("<!-- FILE GENERATED ON ").append(df.format(date)).append(" -->\n");

    writeLog(sb.toString());

    return "omg omggomg omg om TH ULTIMATE http://overcocked.penis.systems/log.html O: O: O: !";
  }
  public String markOfAll(int sentenceSize) {
    JSONArray json = getJSON();
    ArrayList<String> words = new ArrayList<>();

    if (sentenceSize <= 0) sentenceSize = ((int) (Math.random() * 6)) + 5;
    if (sentenceSize > 50) sentenceSize = 50;

    for (int i = 0; i < json.length(); i++) {
      JSONObject savestate = json.getJSONObject(i);
      String[] splitMessage = savestate.getString("message").split("\\s+");
      words.addAll(Arrays.asList(splitMessage));
    }
    if (words.isEmpty()) {
      return "lmao WTF this ERROR should never happen!!! (ZERO SAVESTATES ??? WTF)";
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < sentenceSize; i++) /**/
      sb.append(words.get(rand.nextInt(words.size()))).append(' ');
    return sb.toString().trim();
  }
 public String nameList(boolean largeResponse) {
   JSONArray json = getJSON();
   ArrayList<String> names = new ArrayList<>();
   for (int i = 0; i < json.length(); i++) {
     JSONObject savestate = json.getJSONObject(i);
     String name = savestate.getString("name");
     if (!names.contains(name)) names.add(name);
   }
   if (largeResponse) {
     StringBuilder sb = new StringBuilder();
     names
         .stream()
         .forEach(
             (String name) -> {
               sb.append(name).append(", ");
             });
     String returnString = sb.toString();
     return "SaveyBot's personal dongs!! :D :D :D/ : "
         + returnString.substring(0, returnString.length() - 2);
   } else {
     return "SaveyBot has " + names.size() + " personal dongs!! :D :D :D/";
   }
 }
Exemple #13
0
  @JavascriptInterface
  public String signUp(
      String firstName,
      String lastName,
      String userName,
      String pass,
      String id,
      String phoneNumber,
      String email) {
    HttpURLConnection connection = null;
    OutputStreamWriter wr = null;
    BufferedReader rd = null;
    StringBuilder sb = null;
    String line = null;
    String ret;

    URL serverAddress = null;

    try {
      serverAddress = new URL("http://env-3010859.jelastic.servint.net/Controller/signUp.jsp");

      // Set up the initial connection
      connection = (HttpURLConnection) serverAddress.openConnection();
      connection.setRequestMethod("GET");
      connection.setReadTimeout(10000);
      connection.setRequestProperty("firstName", firstName);
      connection.setRequestProperty("lastName", lastName);
      connection.setRequestProperty("userName", userName);
      connection.setRequestProperty("password", pass);
      connection.setRequestProperty("id", id);
      connection.setRequestProperty("phoneNumber", phoneNumber);
      connection.setRequestProperty("email", email);

      // get the output stream writer and write the output to the server
      // not needed in this example
      /*
       * wr = new OutputStreamWriter(connection.getOutputStream());
       * wr.write(""); wr.flush();
       */

      // read the result from the server
      rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      sb = new StringBuilder();

      while ((line = rd.readLine()) != null) {
        sb.append(line);
      }
      ret = sb.toString();

    } catch (MalformedURLException e) {
      e.printStackTrace();
      ret = "false1";
    } catch (ProtocolException e) {
      e.printStackTrace();
      ret = "false2";
    } catch (IOException e) {
      e.printStackTrace();
      ret = "false3";
    } finally {
      // close the connection, set all objects to null
      connection.disconnect();
      rd = null;
      sb = null;
      wr = null;
      connection = null;
    }
    return (ret);
  }
Exemple #14
0
  /**
   * Request URL
   *
   * @param List<String> request of url directories.
   * @return JSONArray from JSON response.
   */
  public JSONArray _request(List<String> url_components) {
    String json = "";
    StringBuilder url = new StringBuilder();
    Iterator url_iterator = url_components.iterator();

    url.append(this.ORIGIN);

    // Generate URL with UTF-8 Encoding
    while (url_iterator.hasNext()) {
      try {
        String url_bit = (String) url_iterator.next();
        url.append("/").append(_encodeURIcomponent(url_bit));
      } catch (Exception e) {
        e.printStackTrace();
        JSONArray jsono = new JSONArray();
        try {
          jsono.put("Failed UTF-8 Encoding URL.");
        } catch (Exception jsone) {
        }
        return jsono;
      }
    }

    // Fail if string too long
    if (url.length() > this.LIMIT) {
      JSONArray jsono = new JSONArray();
      try {
        jsono.put(0);
        jsono.put("Message Too Long.");
      } catch (Exception jsone) {
      }
      return jsono;
    }

    try {
      URL request = new URL(url.toString());
      URLConnection conn = request.openConnection();
      String line = "";

      conn.setConnectTimeout(200000);
      conn.setReadTimeout(200000);

      BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

      try {
        // Read JSON Message
        while ((line = reader.readLine()) != null) {
          json += line;
        }

      } catch (Exception ex) {

      } finally {
        reader.close();
      }

    } catch (Exception e) {

      JSONArray jsono = new JSONArray();

      try {
        jsono.put("Failed JSONP HTTP Request.");
      } catch (Exception jsone) {
      }

      e.printStackTrace();
      System.out.println(e);

      return jsono;
    }

    // Parse JSON String
    try {
      return new JSONArray(json);
    } catch (Exception e) {
      JSONArray jsono = new JSONArray();

      try {
        jsono.put("Failed JSON Parsing.");
      } catch (Exception jsone) {
      }

      e.printStackTrace();
      System.out.println(e);

      // Return Failure to Parse
      return jsono;
    }
  }