• Welcome to Valhalla Legends Archive.
 

StealthBot News Retriever

Started by Joe[x86], March 26, 2005, 02:20 PM

Previous topic - Next topic

Joe[x86]

When StealthBot starts up, it displays some news about whats been going on latley on the SB world. I wrote a small Java program to retreive that information, and display it to the console. Stealth uses \n in his PHP file to make a new line, and I tried replacing that with \r\n to make a new line, but it doesn't seem to be working. Any suggestions? Heres my code.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

// Created on Mar 25, 2005
// @author JoeTheOdd
// Retreives the SB news and prints it to the console

public class Main {
   public static void main(String args[]) {
       Socket sckSBNews;
       String line;
       try {
           sckSBNews = new Socket("www.stealthbot.net", 80);
           BufferedReader in = new BufferedReader(new InputStreamReader(sckSBNews.getInputStream()));
           BufferedWriter out = new BufferedWriter(new OutputStreamWriter(sckSBNews.getOutputStream()));
           out.write("GET /getver.php HTTP/1.0" + "\r\n" + "Host: www.stealthbot.net" + "\r\n" + "\r\n");
           out.flush();
           while ((line = in.readLine()) != null)
               parseNews(in.readLine());
           sckSBNews.close();
       }
       catch (UnknownHostException e) { System.out.println("Unable to connect to stealthbot.net:80"); }
       catch (IOException e) { System.out.println("Caught IOException"); }
   }
   
   private static void parseNews(String s) {
       try
       {
           String data[];
           String data2;
           data = s.split(","); data2 = data[3]; // remove first two numbers
           data2 = data2.replaceAll("ÿcb", "");  // remove any bold flags
           data = data2.split("\n");             // split at new lines
           for(int i = 0; i < data.length; i++) { System.out.println(data[i]); }
       }
       catch (ArrayIndexOutOfBoundsException e) {}
   }
}
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

iago

If you need to split at \n or \r\n, use BufferedReader.readLine().  It looks after that for you.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Kp

Also, try not to throw away useful information.  You're only processing even numbered lines.  Finally, consider not doing concatenation of several adjacent string constants; just write them as one.  It works the same, but concatenating them like that looks a bit silly.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

iago

Quote from: Kp on March 26, 2005, 05:20 PM
Also, try not to throw away useful information.  You're only processing even numbered lines.
Good point

QuoteFinally, consider not doing concatenation of several adjacent string constants; just write them as one.  It works the same, but concatenating them like that looks a bit silly.
Haha, I saw that but opted to ignore it. 
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Joe[x86]

QuoteFinally, consider not doing concatenation of several adjacent string constants; just write them as one.  It works the same, but concatenating them like that looks a bit silly.

Woah, huh?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Joe[x86]

After some random changes I put to the test, I've managed to pump out this.

StealthBot News:
> Normal News:
>> Date: Mon, 28 Mar 2005 13:59:46 GMT
>> X-Powered-By: PHP/4.3.10
>> Content-Type: text/html
>> 584171,241,x,If you need help or have questions feel free to join our forums at http://www.stealthbot.net. They're back up!\n\nWant to trade Diablo II items? Check out the new http://www.d2central.com ! D2Central holds tournaments raffles and more - all realms are welcome!
> Beta News:
>> Date: Mon, 28 Mar 2005 13:59:46 GMT
>> X-Powered-By: PHP/4.3.10
>> Content-Type: text/html
>> 22194|260|ÿcbStealthBot v2.6 is now available!\nVisit http://www.stealthbot.net to download a copy today.\n\nÿcbForge Hosting is the new home of StealthBot.net\nForge Hosting's lightning-fast servers can handle all of your website needs.\nPlans start at just $4.99 monthly for 1GB space and 20GB transfer with 24 hour activation guaranteed. Check us out at http://www.forgehosting.com!|Beta version 2.620 is now available. Snag it in Betaland.


I'm going to keep working on it, and parsing the \n's still seems impossible. Also, BufferReader.readLine() doesn't seem to fix that.

Should I just input the 4th line of each thing the server sends back, or is there a more professional way to do it?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

dxoigmn

Here is something I put together real quick. It uses the built in classes so one doesn't actually have to parse through the http headers and such. I didn't do any parsing of the actual data (news) since I figured you should be able to do that. This is pretty easy to follow if you have the SDK in front of you.


import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class StealthBotNews {
public static void main(String args[]) {
try {
URL stealthbot = new URL("http", "www.stealthbot.net", 80, "/getver.php");
HttpURLConnection conn = (HttpURLConnection)stealthbot.openConnection();

conn.connect();

if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

System.out.println(in.readLine());
} else {
System.out.println("Bad response code: " + conn.getResponseCode());
}

conn.disconnect();

} catch (Exception e) {
e.printStackTrace();
}

}
}

Joe[x86]

Mind linking me to the SDK? Looks good at a quick glance. I'll test it later today after I've gone to bed. Erm, had a nap?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: Joey on March 30, 2005, 03:57 AM
Mind linking me to the SDK? Looks good at a quick glance. I'll test it later today after I've gone to bed. Erm, had a nap?

http://java.sun.com/j2se/1.4.2/docs/api/
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Joe[x86]

Thanks MyndFyre.

I'm going to work on this right now waiting for Blizzy to get their effing servers back up.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Joe[x86]

#11
Excellent. You men happen to be my heroes of the day!

Initiating SBNews...

StealthBot News:
> Version News:
>> 22194|260|ÿcbStealthBot v2.6 is now available!\nVisit http://www.stealthbot.net to download a copy today.\n\nÿcbForge Hosting is the new home of StealthBot.net\nForge Hosting's lightning-fast servers can handle all of your website needs.\nPlans start at just $4.99 monthly for 1GB space and 20GB transfer with 24 hour activation guaranteed. Check us out at http://www.forgehosting.com!|Beta version 2.620 is now available. Snag it in Betaland.
> Normal News:
>> 584171,241,x,If you need help or have questions feel free to join our forums at http://www.stealthbot.net. They're back up!\n\nWant to trade Diablo II items? Check out the new http://www.d2central.com ! D2Central holds tournaments raffles and more - all realms are welcome!
> Beta News:
>> 22194|260|ÿcbStealthBot v2.6 is now available!\nVisit http://www.stealthbot.net to download a copy today.\n\nÿcbForge Hosting is the new home of StealthBot.net\nForge Hosting's lightning-fast servers can handle all of your website needs.\nPlans start at just $4.99 monthly for 1GB space and 20GB transfer with 24 hour activation guaranteed. Check us out at http://www.forgehosting.com!|Beta version 2.620 is now available. Snag it in Betaland.


EDIT: My splitting method doesn't seem to be working exactly correct. It works for the normal news, but the beta and version news, from getver2.php, don't seem to come out right. Anybody wanna take a look? A VB version of what I'm trying to do is available at joe.astriks.com under the name prjSBNews-src.

// Created 3-25-05
// Re-Created 2-26-05
// Author: JoeTheOdd
// Thanks to dxoigmn for a better connection method

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) {
        System.out.println("Initiating SBNews...");
        System.out.println();
       
        String sVerNews; String sNormNews; String sBetaNews;
        sVerNews = getVerNews();
        sNormNews = getNormNews();
        sBetaNews = getBetaNews();
       
        System.out.println("StealthBot News:");
        System.out.println("> Version News:");
        System.out.println(">> " + sVerNews);
        System.out.println("> Normal News:");
        System.out.println(">> " + sNormNews);
        System.out.println("> Beta News:");
        System.out.println(">> " + sBetaNews);
    }

    // @return - SB Version News
    private static String getVerNews() {
        String s = null; String sSplt[];
        try {
            URL stealthbot = new URL("http", "www.stealthbot.net", 80, "/getver2.php");
            HttpURLConnection conn = (HttpURLConnection) stealthbot.openConnection();
            conn.connect();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                s = in.readLine();
            }else{
                System.out.println("Bad response code: " + conn.getResponseCode());
            }

            conn.disconnect();
        }catch(Exception e){
            e.printStackTrace();
        }
        sSplt = s.split("|");
        return sSplt[2].toString();
    }

    // @return - SB Normal News
    public static String getNormNews() {
        String s = null; String sSplt[];
        try {
            URL stealthbot = new URL("http", "www.stealthbot.net", 80, "/getver.php");
            HttpURLConnection conn = (HttpURLConnection) stealthbot.openConnection();
            conn.connect();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                s = in.readLine();
            }else{
                System.out.println("Bad response code: " + conn.getResponseCode());
            }

            conn.disconnect();
        }catch(Exception e){
            e.printStackTrace();
        }
        sSplt = s.split(",");
        return sSplt[3].toString();
    }
   
    // @return - SB Beta News
    private static String getBetaNews() {
        String s = null; String sSplt[];
        try {
            URL stealthbot = new URL("http", "www.stealthbot.net", 80, "/getver2.php");
            HttpURLConnection conn = (HttpURLConnection) stealthbot.openConnection();
            conn.connect();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                s = in.readLine();
            }else{
                System.out.println("Bad response code: " + conn.getResponseCode());
            }

            conn.disconnect();
        }catch(Exception e){
            e.printStackTrace();
        }
        sSplt = s.split("|");
        return sSplt[3].toString();
    }
}
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

dxoigmn

Quote from: Joey on March 31, 2005, 06:58 AM
EDIT: My splitting method doesn't seem to be working exactly correct. It works for the normal news, but the beta and version news, from getver2.php, don't seem to come out right. Anybody wanna take a look? A VB version of what I'm trying to do is available at joe.astriks.com under the name prjSBNews-src.

In java, for a string's split method, it takes a regular expression, NOT a character(s) to split on like in Visual Basic. So what you probably need to do is escape the character (in this case the pipe, |) since the pipe is a special character in regular expressions.

MyndFyre

Quote from: dxoigmn on March 31, 2005, 09:33 AM
In java, for a string's split method, it takes a regular expression, NOT a character(s) to split on like in Visual Basic. So what you probably need to do is escape the character (in this case the pipe, |) since the pipe is a special character in regular expressions.

Alternatively, you could use Java's StringTokenizer class, which can take one or more characters as delimiters.  You then run through it in the following manner:

while (myTokenizer.hasMoreTokens())
{
  System.out.println(new String("Next token: ").concat(myTokenizer.nextToken()));
}
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Joe[x86]

W
o
w

I'll try some more on this after school.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.