• Welcome to Valhalla Legends Archive.
 

[Java] 0x25 Help

Started by Spilled, October 07, 2005, 07:34 PM

Previous topic - Next topic

Spilled

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:


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


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


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.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Spilled

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

Joe[x86]

#3
BNCS:
(BYTE)      Always 0xFF
(BYTE)      Message ID
(WORD)      Message length, including this header
(VOID)      Message Data


0x25:
(DWORD)       Ping Value


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


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

  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
    }
  }


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

  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
    }
  }


EDIT -
In JavaOp2, its handled the second way.
    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);
        }
        // ...
    }

http://www.javaop.com/javaop2/src/Ping/src/PluginMain.java
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Spilled

#4
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.


String temp = strData;


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!

Joe[x86]

Quotewill return you a incompatible error, i dont even have to test it cuz i know it will.
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.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Spilled

I just echod it back and it worked, i was just messing around and getting some practice in. appreciate it bro thanks!

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.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Spilled

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

l2k-Shadow

#9
looks to me like you're converting it to a string lol ~.~

EDIT:
Quote from: Spilled[DW] on October 08, 2005, 04:22 AM
but i did convert it to a string so ... yea your probably right.. im tired tho lol

didn't read second part of post <.<
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Joe[x86]

String positions, indexes rather, are zero-based in all the C-Style languages, including Java.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.