• Welcome to Valhalla Legends Archive.
 

[BNCS] Parse packet data.

Started by mime, November 17, 2009, 05:29 PM

Previous topic - Next topic

mime

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.

mime


Imperceptus

What was the solution? I have no clue about java but would be interested to know.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

mime

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);

rabbit

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.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.