• Welcome to Valhalla Legends Archive.
 

[Java] Chat bot

Started by Fr0z3N, May 17, 2004, 09:42 PM

Previous topic - Next topic

Fr0z3N


import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;


import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


/**
*
* @author  Jared
*/
public class Main {
   
   /** Creates a new instance of Main */
   public Main() {
   }
   
   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) throws IOException {
       
      Socket BNet = null;
      InputStream in;
      OutputStream out;
   
       
       try {
           System.out.println("Connecting...");
           InetAddress address = InetAddress.getByName((String) "useast.battle.net");
           BNet = new Socket(address, 6112);
           in = BNet.getInputStream();
           out = BNet.getOutputStream();
           
       } catch (UnknownHostException e) {
           System.out.println("Unknown Host Exception: " + e.toString());
           
       } catch (IOException e) {
           System.out.println("I/O Exception: " + e.toString());
       }

       in = BNet.getInputStream();
       out = BNet.getOutputStream();
       
       System.out.println("Connected");
       
       String login = (char) 0x03 + (char) 0x04 + "Suffer[BH]" + "\n" + "PASSWORD!" + "\n";
       out.write(login.getBytes());
       
       try {
           while(true) {
               System.out.println((int) in.read());
               //System.out.println(Integer.toHexString(in.read()));
           }
       }
       catch(IOException e)
       {
         System.out.println("Lost connection - " + e.toString());
       }
       
       
       }
   
   }



The receive loop is printing '-1' and I don't know why.

Help is appreciated.

Lenny

#1
Quote
Method Detail

read
public abstract int read()
                 throws IOException

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255.

If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

A subclass must provide an implementation of this method.


Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.

http://java.sun.com/j2se/1.4.2/docs/api/
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

Fr0z3N

So I guess I am not connecting correctly to battle.net so its not receiving any data.

iago

Sounds like it's time for a packetlogger! :P
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Fr0z3N

Nevah!

I rewrote my sexy code and got it working.