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.
I found the solution in BNCSPacketReader.java (http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bncs/BNCSPacketReader.java)
Thanks. :)
What was the solution? I have no clue about java but would be interested to know.
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);
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.