Valhalla Legends Forums Archive | Java Programming | Sending a packet in java..

AuthorMessageTime
Metallicist
Just started trying to make a b.net bot and am testing sending the SID_AUTH_INFO packet. I used ethereal to check what gets sent
and the data gets sent twice in same packet.. any one know why?
      (From ethereal)
XXXXXXXXXXXXXXXX ff 50 3a 00 00 00 00 00 36 38  .<.Y...P:.....68
58 49 50 58 45 53 d1 00 00 00 53 55 6e 65 c0 a8  XIPXES....SUne..
01 03 f0 00 00 00 09 04 00 00 09 04 00 00 55 53    ..............US
41 00 55 6e 69 74 65 64 20 53 74 61 74 65 73 00  A.United States.
ff 50 3a 00 00 00 00 00 36 38 58 49 50 58 45 53    .P:.....68XIPXES
d1 00 00 00 53 55 6e 65 c0 a8 01 03 f0 00 00 00    ....SUne........
09 04 00 00 09 04 00 00 55 53 41 00 55 6e 69 74  ........USA.Unit
65 64 20 53 74 61 74 65 73 00                            ed States.

Heres the relevant code ...
[code]
    (Sends the SID_AUTH_INFO packet {copied from ethereal})
...........................
ByteFromIntArray intToByte=new ByteFromIntArray(false);
int[] intAr = {0xFF,0x50,0x3a,0x00,0x00,0x00,0x00,0x00,0x36,0x38,
0x58,0x49,0x50,0x58,0x45,0x53,0xd1,0x00,0x00,0x00,0x53,0x55,0x6e,
0x65,0xc0,0xa8,0x01,0x03,0xf0,0x00,0x00,0x00,0x09,0x04,0x00,0x00,
0x09,0x04,0x00,0x00,0x55,0x53,0x41,0x00,0x55,0x6e,0x69,0x74,0x65,
0x64,0x20,0x53,0x74,0x61,0x74,0x65,0x73,0x00};
byte[] SID_AUTH_INFO = intToByte.getByteArray(intAr);
dosStream.write(SID_AUTH_INFO); (dosStream = DataOutputStream
....................
      (Taken from http://bnubot.googlecode.com/svn/trunk/BNUBot/src/org/jbls/util/ByteFromIntArray.java)
public byte[] getByteArray(int[] array) {
byte[] newArray = new byte[array.length];

int pos = 0;
for (int element : array) {
if (littleEndian) {
newArray[pos++] = (byte) ((element >> 0) & 0xFF);
newArray[pos++] = (byte) ((element >> 8) & 0xFF);
newArray[pos++] = (byte) ((element >> 16) & 0xFF);
newArray[pos++] = (byte) ((element >> 24) & 0xFF);
} else {
//newArray[pos++] = (byte) ((element >> 24) & 0xFF);
//newArray[pos++] = (byte) ((element >> 16) & 0xFF);
//newArray[pos++] = (byte) ((element >> 8) & 0xFF);
newArray[pos++] = (byte) ((element >> 0) & 0xFF);
}
}

return newArray;
}
[/code]
September 19, 2008, 8:42 PM
Metallicist
Can someone move this to java programming forum.. sorry  :-\
September 19, 2008, 9:22 PM
HdxBmx27
Well if you're going to be using someone elses code, go with the Buffer class. It'd keep things nice and clean.
It shouldn't be sending twice though, I see no logical reason for that. on the contrary, it should send once, but have a crapload of nulls in it [if you're doing littlendian] Perhaps a full unedited code would help.
September 19, 2008, 9:25 PM
Metallicist
not trying to do anything nice and clean yet.. was just trying to see if i could get bnet to respond. B.net responds just fine.. just confused about the double data in packet.. here's the full code

[code]
//--------------------------------------------------------------
import java.net.*;
import java.io.*;

public class Connection
{
Socket client;
DataInputStream disStream;
DataOutputStream dosStream;

public Connection(String address, int port)
{
try
{
client = new Socket(address, port);
client.setKeepAlive(true);
}
catch(Exception e)
{
System.out.println("Trying to open socket... " + e);
}

try
{
disStream = new DataInputStream(client.getInputStream());
}
catch(Exception e)
{
System.out.println("Trying to get input stream... " + e);
}

try
{
dosStream = new DataOutputStream(client.getOutputStream());
}
catch(Exception e)
{
System.out.println("Trying to get output stream... " + e);
}
}

public DataInputStream getInputStream()
{
return disStream;
}

public void sendPacket(int ID)
{
try
{
dosStream.flush();
}
catch(Exception e)
{
closeConnection();
System.out.println("flush... " + e);
}
switch(ID)
{
case 00:
try
{
dosStream.writeByte(0x01);
}
catch( Exception e)
{
closeConnection();
System.out.println("Trying to send 0x01... " + e);
}
case 50:
try
{
ByteFromIntArray intToByte=new ByteFromIntArray(false);
int[] intAr = {0xFF,0x50,0x3a,0x00,0x00,0x00,0x00,0x00,0x36,0x38,
0x58,0x49,0x50,0x58,0x45,0x53,0xd1,0x00,0x00,0x00,0x53,0x55,0x6e,
0x65,0xc0,0xa8,0x01,0x03,0xf0,0x00,0x00,0x00,0x09,0x04,0x00,0x00,
0x09,0x04,0x00,0x00,0x55,0x53,0x41,0x00,0x55,0x6e,0x69,0x74,0x65,
0x64,0x20,0x53,0x74,0x61,0x74,0x65,0x73,0x00};
byte[] SID_AUTH_INFO = intToByte.getByteArray(intAr);
dosStream.write(SID_AUTH_INFO);
}
catch (Exception e)
{
closeConnection();
System.out.println("Trying to send 0x50... " + e);
}

}


}


public void closeConnection()
{
try
{
dosStream.close();
disStream.close();
client.close();
}
catch(Exception e)
{
System.out.println("Trying to close connection..." + e);
}
}

}
//--------------------------------------------------------------
import java.io.*;

public class BNC
{
public static void main(String[] args)
{

Connection cn = new Connection("asia.battle.net",6112);
DataInputStream inStream;
cn.sendPacket(0);
cn.sendPacket(50);

inStream = cn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
int inChar=0;
try
{
inChar = br.read();
}
catch(Exception e)
{
cn.closeConnection();
System.out.println("Trying to read initial char from input stream... " + e);
}
System.out.print(inChar+" ");
while(inChar != -1)
{
try
{
inChar = br.read();
}
catch(Exception e)
{
cn.closeConnection();
System.out.println("Trying to read char from input stream... " + e);
}
System.out.print(inChar+ " ");
}
}
        cn.closeConnection();
}
[/code]
September 19, 2008, 10:48 PM
Metallicist
No problem now.. bot chillin' on b.net :)

Dunno what was happening there.. that code was tossed.
September 30, 2008, 3:59 PM

Search