Valhalla Legends Forums Archive | Battle.net Bot Development | [Java] 0x25 Help

AuthorMessageTime
Spilled[DW]
This is my first attempt to create a bot in java and i am having some problems. How would i handle 0x25 in java and send the 4 bytes back? Heres what ive been trying:

[code]
private void PaRsEp(byte[] strData)
{
switch(strData[1])
{
case 0x25:
    String temp = new String(strData);
    InsertNonNTString(temp.substring(4,4));
    SendPacket(0x25);
                                                break;
[/code]

Am i handling it wrote by converting it to a string? Any ideas would be helpful! Thanks in advance!

October 8, 2005, 12:34 AM
l2k-Shadow
just a note, you don't need to parse 0x25.. the response to 0x25 will always be the same data that was sent to you so you can just send it back as it is to the server.
October 8, 2005, 1:33 AM
Spilled[DW]
yes, im sending back the substring of 4,4 which is the data hehe :) and also im just using this as an example of how to handle the data in java, IE i could just ignore 0x25 and work on 0x50 recv and 0x51 send :)
October 8, 2005, 3:51 AM
JoeTheOdd
BNCS:
[pre](BYTE)      Always 0xFF
(BYTE)      Message ID
(WORD)      Message length, including this header
(VOID)      Message Data[/pre]

0x25:
[pre](DWORD)     Ping Value[/pre]

0x25 Map:
[pre]Position:  00 | 01 | 02 | 03 | 04 | 05 | 06 | 07
Data:      FF | 25 | 00 | 08 | DE | AD | BE | EF[/pre]

Asuming that 0xDEADBEEF is your ping value, that is what your 0x25 packet will look like.

[pre]  private void parsep(byte[] strData) { // Random cap name, discusting =p
    switch(strData[1]) {
      case 0x25:
        String temp = strData; // I don't think that you do String(strData) here, just pass the byte[]
        InsertNonNTString(temp.substring(4,4)); // Uh, don't you have to reference the packetbuffer?
        SendPacket(0x25); // Uh, don't you have to reference the packetbuffer?
        break;
      default:
        // Error: Unhandled packet
    }
  }[/pre]

A better way to do this is do absolutely no parsing at all.

[pre]  private void parsep(byte[] strData) { // Random cap name, discusting =p
    switch(strData[1]) {
      case 0x25:
        InsertNonNTString(strData); // Uh, don't you have to reference the packetbuffer?
        SendRAW; // Uh, don't you have to reference the packetbuffer?
        break;
      default:
        // Error: Unhandled packet
    }
  }[/pre]

EDIT -
In JavaOp2, its handled the second way.
[pre]    public void processedPacket(BNetPacket buf, Object data) throws IOException
    {
        if(buf.getCode() == SID_PING)
        {
        // Returning a ping is very simple -- just echo back the exact packet
            out.setTCPNoDelay(true);
        out.sendPacket(buf);
        out.setTCPNoDelay(false);
        }
        // ...
    }[/pre]
http://www.javaop.com/javaop2/src/Ping/src/PluginMain.java
October 8, 2005, 4:09 AM
Spilled[DW]
hrmm, my sendpacket function create a byte[] variable and adds the 0xFF, the packetID, then the packet length(2bytes) then w/e is in the buffer, i still dont see why its not working since my sendpacket adds the packet header then the buffer to that byte variable. Since substring(4,4) is what i need to send back. i dont see the difference.

[code]
String temp = strData;
[/code]

will return you a incompatible error, i dont even have to test it cuz i know it will.
Any more ideas would be appreciate. Thx bro.

Also when i try inserting the whole strData, when i packet log i get the header(0xFF,0x25,WORDof length) and 8 bytes of 0xFF so problem when i do String temp = new String(strData)

Need help! any ideas would be helpful!
October 8, 2005, 4:23 AM
JoeTheOdd
[quote]will return you a incompatible error, i dont even have to test it cuz i know it will.[/quote]Test it anyways. I've used Java before too, and I'm pretty sure it works.

EDIT -
As for it adding the header onto an already header'd packet, what you need to do is write a sendRAW function which simply flushes the buffer out onto the line, without any formatting (adding header, basically) whatsoever.
October 8, 2005, 4:42 AM
Spilled[DW]
I just echod it back and it worked, i was just messing around and getting some practice in. appreciate it bro thanks!
October 8, 2005, 4:44 AM
l2k-Shadow
As far as your attempt goes, I believe the reason it did not work is because you were inserting back substring(4,4) instead of substring(5,4) since the actual data starts on the 5th byte and 4 bytes previous to that is the header.
October 8, 2005, 4:58 AM
Spilled[DW]
array starts at 0 so it would be 4,4 but in vb it would be 5,4 if im correct? Correct me if im wrong of course :)

but i did convert it to a string so ... yea your probably right.. im tired tho lol
October 8, 2005, 9:22 AM
l2k-Shadow
looks to me like you're converting it to a string lol ~.~

EDIT:
[quote author=Spilled[DW] link=topic=12981.msg130315#msg130315 date=1128763325]
but i did convert it to a string so ... yea your probably right.. im tired tho lol
[/quote]

didn't read second part of post <.<
October 9, 2005, 5:52 AM
JoeTheOdd
String positions, indexes rather, are zero-based in all the C-Style languages, including Java.
October 10, 2005, 5:38 AM

Search