Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: mime on November 17, 2009, 05:29 PM

Title: [BNCS] Parse packet data.
Post by: mime on November 17, 2009, 05:29 PM
Hello, I create a simple chat client for bnet.

I'am use
http://code.google.com/p/javaop/source/browse/trunk/javaop2/javaop2/src/util/BNetPacket.java
for creating packet.

I refer as follows:
 
       // [0x50] SID_AUTH_INFO
      //...
        DataOutputStream out = new DataOutputStream(...);
        // ...
// create packet
BNetPacket packet = new BNetPacket((byte) 0x50);
packet.addDWord(0);
packet.addDWord(PlatformsID.PLATFORM_IX86);
packet.addDWord(ProductsID.D2XP);
packet.addDWord(0x0C);
packet.addDWord(0);
packet.addDWord(0);
packet.addDWord(0);
packet.addDWord(0);
packet.addDWord(0);
packet.addNTString(locale.getISO3Country());
packet.addNTString(locale.getDisplayCountry());
// send game protocol byte
out.writeByte(0x01);
out.flush();
// send packet
out.write(packet.getBytes());
out.flush();

I have a question, how receive and parse packet?

I wrote:
DataInputStream in = new DataInputStream(...);
System.out.println(in.read()); //PING
System.out.println(in.read()); //Logon Type
System.out.println(in.read()); //Server Token
System.out.println(in.read()); // UDPValue**
System.out.println(in.read()); // MPQ filetime
System.out.println(in.read()); // IX86ver filename
System.out.println(in.read()); //  ValueString


and the output i see:

255
37
8
0
159
160
97

How to get the code and data packets from the packet in the normal view?

Thanks.
Title: Re: [BNCS] Parse packet data.
Post by: mime on November 18, 2009, 10:24 AM
I found the solution in BNCSPacketReader.java (http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bncs/BNCSPacketReader.java)

Thanks. :)
Title: Re: [BNCS] Parse packet data.
Post by: Imperceptus on November 18, 2009, 11:54 AM
What was the solution? I have no clue about java but would be interested to know.
Title: Re: [BNCS] Parse packet data.
Post by: mime on November 18, 2009, 12:24 PM
Quote from: Imperceptus on November 18, 2009, 11:54 AM
What was the solution? I have no clue about java but would be interested to know.
    //...
        BNetInputStream stream ...
byte magic;
do {
magic = stream.readByte();
} while(magic != (byte)0xFF);

int packetId= stream.readByte() & 0x000000FF;
System.out.println(Integer.toHexString("Receive packet: 0x" + packetId));
int packetLength = stream.readWord() & 0x0000FFFF;

byte [] data = new byte[packetLength-4];
for(int i = 0; i < packetLength-4; i++) {
data[i] = stream.readByte();
}

BNetInputStream auth = new BNetInputStream(new ByteArrayInputStream(data));
       
Integer nlsRevision = auth.readDWord();
System.out.println("nlsRevision: " + nlsRevision);
int serverToken = auth.readDWord();
System.out.println("Server Token:" + serverToken);
auth.skip(4);
long mpqFileTime = auth.readQWord();
System.out.println("MPQ Filetime: " + mpqFileTime);
String mpqFileName = auth.readNTString();
System.out.println("MPQ Filename: " + mpqFileName);
byte[] valueStr = auth.readNTBytes();
System.out.println(valueStr);
Title: Re: [BNCS] Parse packet data.
Post by: rabbit on November 19, 2009, 09:32 AM
Quote from: Imperceptus on November 18, 2009, 11:54 AM
What was the solution? I have no clue about java but would be interested to know.
The solution was copypasta with no learning.