Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Fr0z3N on May 17, 2004, 09:42 PM

Title: [Java] Chat bot
Post by: Fr0z3N on May 17, 2004, 09:42 PM

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.
Title: Re:[Java] Chat bot
Post by: Lenny on May 17, 2004, 09:56 PM
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/
Title: Re:[Java] Chat bot
Post by: Fr0z3N on May 17, 2004, 09:58 PM
So I guess I am not connecting correctly to battle.net so its not receiving any data.
Title: Re:[Java] Chat bot
Post by: iago on May 17, 2004, 10:33 PM
Sounds like it's time for a packetlogger! :P
Title: Re:[Java] Chat bot
Post by: Fr0z3N on May 17, 2004, 11:14 PM
Nevah!

I rewrote my sexy code and got it working.