Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Loud on July 19, 2005, 07:11 PM

Title: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 07:11 PM
I've checked BNETDocs, and Developement resources already... I just have a basic lame question, because nobody I know can tell me ANYTHING about packets (all my programmer friends are on vacation).

Should 0x01 contain more than one user per packet? I got the impression from BNETDocs that it shouldn't but it does... Uhhh, thanks in advance.
Title: Re: Help with 0x0F EID 0x01
Post by: Warrior on July 19, 2005, 07:20 PM
It doesn't send them all together but it will send that packet continuously per user.
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 07:28 PM
Hmm, that's odd...
..<.........^...............CLaN-SoF10]SoF.3RAW 1R3W 0 dRoW...4.........................o4]SoF[.3RAW 1R3W 0 FoS...4.........^...............o1]SoF[.3RAW 1R3W 0 FoS...U.........^[email protected] 7190 116 12931 0 0 7304 1448 426 NB2W...F.........}[email protected] 0 0 0 0 0 0 0 0 [email protected] 0 0 0 0 0 0 0 0 [email protected] 0 0 3 0 0 0 0 0 PXES...F.........................DNX]SoF[@USWest.NB2W 0 0 0 0 0 0 0 0 NB2W...:.........m...............imaloser]sof[.3RAW 1R3W 0 FoS...=.........N...............RuM_N_CoKe]SoF[.3RAW 1R3W 1 dRoW...5.........?...............RuM_BoT]SoF[.3RAW 1R3W 0...4.........?...............o6]SoF[.3RAW 1R3W 0 FoS...I.........................I-DNX]SoF[@USWest.NB2W 0 0 40 0 0 0 0 0 NB2W...G.........................Loud]SoF[@USWest.RATS 0 0 0 0 0 0 0 0 RATS...4.........^...............o2]SoF[.3RAW 1R3W 0 FoS...4.........^...............o3]SoF[.3RAW 1R3W 0 FoS...;.........^...............ClaNSoF)1]SoF[.3RAW 1R3W 0 [email protected] 0 0 0 0 0 0 0 0 NB2W.

That is the text from the right (I am pretty newb at programming at the moment), and my logger claims it is all one packet. On EID 0x01 my bot SHOULD add the user enclosed in 0x01... But with shit like this, it just doesn't do it.

Any idea what's wrong? I am using BNCSUtility if that is of any use...
Title: Re: Help with 0x0F EID 0x01
Post by: Hdx on July 19, 2005, 07:30 PM
Give us a format output of it, including the hex value of it. What i think is happening is that you are simply get all those packets at once, and you need to seperate them out.
~-~(HDX)~-~

Edit, It seems that you are reciving these 18 packets:
..<.........^...............CLaN-SoF10]SoF.3RAW 1R3W 0 dRoW.
..4.........................o4]SoF[.3RAW 1R3W 0 FoS.
..4.........^...............o1]SoF[.3RAW 1R3W 0 FoS.
..U.........^[email protected] 7190 116 12931 0 0 7304 1448 426 NB2W.
..F.........}[email protected] 0 0 0 0 0 0 0 0 NB2W.
[email protected] 0 0 0 0 0 0 0 0 NB2W.
[email protected] 0 0 3 0 0 0 0 0 PXES.
..F.........................DNX]SoF[@USWest.NB2W 0 0 0 0 0 0 0 0 NB2W.
..:.........m...............imaloser]sof[.3RAW 1R3W 0 FoS.
..=.........N...............RuM_N_CoKe]SoF[.3RAW 1R3W 1 dRoW.
..5.........?...............RuM_BoT]SoF[.3RAW 1R3W 0.
..4.........?...............o6]SoF[.3RAW 1R3W 0 FoS.
..I.........................I-DNX]SoF[@USWest.NB2W 0 0 40 0 0 0 0 0 NB2W.
..G.........................Loud]SoF[@USWest.RATS 0 0 0 0 0 0 0 0 RATS.
..4.........^...............o2]SoF[.3RAW 1R3W 0 FoS.
..4.........^...............o3]SoF[.3RAW 1R3W 0 FoS.
..;.........^...............ClaNSoF)1]SoF[.3RAW 1R3W 0 FoS.
[email protected] 0 0 0 0 0 0 0 0 NB2W.

So Like I said, you need to split them up.
~-~(HDX)~-~
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 07:38 PM
I am not very apt at Visual Basic 6 right now, can you point me in the direction as to which I need to go to separate the recieved packets? I am not 100% sure what means you can do it by.

Sorry to be so needy, but I want my bot not to crash when a users leaves because they aren't found on the user list.
Title: Re: Help with 0x0F EID 0x01
Post by: Hdx on July 19, 2005, 08:01 PM
http://bnetdocs.valhallalegends.com/content.php?Section=d&id=6
Check out the BNCS headers. Notice that it has a 'Length' section? Thats how you tell how to split it up. Just throw everything you recive into a incoming buffer (a string vareable) after you get it out of the winsock. Then while Len(Buffer) >=4 then 'get the lengeth and parse it. If the Lengeth in the header is longer then the current buffer, then wait for more to come.

It's not hard. As for crashing cusz it's not found in the userlist... thats jsut bad coding :/
~-~(HDX)~-~
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 08:20 PM
Lol, your solution sounds like it will work. Thanks for the commentary about my code to, that helps a lot... =/
Title: Re: Help with 0x0F EID 0x01
Post by: Eric on July 19, 2005, 08:33 PM
TCP/IP is a streaming protocol--data is sent and received in chunks.  This presents a problem: If data is being sent and received in chunks, how will you know when one message ends and another begins?  The answer to that question is an application-defined packet header which generally contains the length of the packet, and in some cases, additional information as well.  Battle.net's packet header is 4 bytes long and consists of the header ID (0xFF), the packet ID and the length of the packet.  You'll need to seperate each individual packet based on it's length before processing it.  Due to the fact that data is received in chunks, you may not always receive all of a packet at once, so you'll need to buffer the incoming data and wait for the rest of the packet to be received.  You may also encounter times where you receive multiple packets at once, as you have here.
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 09:06 PM
I can't figure out how to throw all my data recieved into a string... (Yes, I suck at coding.)

Also, HDX, for your statement, where did you pull 4 from? Is that so that it checks the BNCS header...?
Title: Re: Help with 0x0F EID 0x01
Post by: R.a.B.B.i.T on July 19, 2005, 09:11 PM
socket.GetData BufferString, vbString
I suggest you learn to program (that's VB6, btw).
Title: Re: Help with 0x0F EID 0x01
Post by: Tontow on July 19, 2005, 09:14 PM
(BYTE)      Always 0xFF - 1 byte
(BYTE)      Message ID - 1 byte
(WORD)      Message length, including this header - 2 bytes
= 4 bytes
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 10:05 PM
Yes, I'm back for more abuse (Thanks Rabbit I <3 you)...

Anyways, let me lay out this concept as I am percieving it, because I don't know if I am interpreting this correctly!

You are bascially saying, find out the length of the individual packet (That has been mashed wish several of the same type), extract that individual part, parse it, then continue on to the next part in the packet, until you have run out. Errr, is this correct?

If so, how do I dispose of the part(s) that I have dealt with?

I am newb, but I am thinking I should use something like this...

'Let's say, PacketToParse is what I am parsing...
PacketToParse = Mid(AllPacketText, PStart, PLength)


That is probably the completely incorrect way to do this, but it is all I can think up (Tired)... This method kind of screws me, because I don't know how to dispose of PacketToParse that has been parsed, because it will just continually parse the same part...

Uhhh, any suggestions, other than rabbit's "Learn to program"...
Title: Re: Help with 0x0F EID 0x01
Post by: Arta on July 19, 2005, 10:11 PM
When you have parsed the the packet -- which, by the way, should correctly be named a message -- you move the rest of the buffer back according to the length of the message you parsed.

For example, if you parse a message 20 bytes long, you would move all of the data in the buffer backwards by 20 bytes. I'm not a VB programmer, so this will not be written correctly, but the concept is what's important:


' extract a message for parsing
PacketToParse = Mid(AllPacketText, PStart, PLength)

' reset the buffer
AllPacketText = Mid(AllPacketText, PLength, Length(AllPacketText) - PLength)
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 19, 2005, 10:47 PM

' reset the buffer
AllPacketText = Mid(AllPacketText, PLength, Length(AllPacketText) - PLength)

Subtracting PLength from Len(AllPacketText), I am unsure about that... Wouldn't it remove from the (for lack of a better term) bottom of the packet...? I know you aren't a VB programmer, but maybe somebody that is can clarify that.
Title: Re: Help with 0x0F EID 0x01
Post by: Tontow on July 19, 2005, 11:18 PM
Maby these could be of some help:
http://forum.valhallalegends.com/phpbbs/index.php?topic=12149.0
http://forum.valhallalegends.com/phpbbs/index.php?topic=12218.0

Title: Re: Help with 0x0F EID 0x01
Post by: Hdx on July 20, 2005, 02:39 AM
Quote from: Arta[vL] on July 19, 2005, 10:11 PM

' extract a message for parsing
PacketToParse = Left(AllPacketText, PStart, PLength)

' reset the buffer
AllPacketText = Mid(AllPacketText, PLength, Length(AllPacketText) - PLength)


Should be this:

' extract a message for parsing
PacketToParse = Mid(AllPacketText, PStart, PLength)

' reset the buffer
AllPacketText = Mid(AllPacketText, PLength + 1)


Simpe as that. Considering We are coming at it from the bigining of the string, PStart is always 1, Or you could sjut use Left() Insted of Mid() for the 1st part.
PLength Would be simple.
PLengeth = Val("&H" & Hex(ASC(Mid(AllPacketText, 4, 1)) & Hex(ASC(Mid(AllPacketText, 4, 1)))
It'd be much better if you use a spacific function to convert a word from it's ASCII state to it's integer equivalent.. But w/e that works.

So let me Pull this all together for you:
Sub Winsock.DataArival()
   Static AllPacketText as string
   Dim PLengeth as Integer, tmpInfo as string, PacketToParse as String
   Winsock.GetData tmpInfo, vbString
   AllPacketText = AllPacketText & tmpInfo
   
   Do While Len(AllPacketText) >= 4
      PLengeth = Val("&H" & Hex(ASC(Mid(AllPacketText, 4, 1)) & Hex(ASC(Mid(AllPacketText, 4, 1)))
      If Len(AllPacketText) < PLengeth  then Exit Sub 'We don't have all the info, wait for more
      PacketToParse = Left(AllPacketText, PLength)
      AllPacketText = Mid(AllPacketText, PLength + 1)
      'Whoot this si where you parse the packets!!!!!
   Loop
End Sub


Note, Just wrote that, it's untested
~-~(HDX)~-~
Title: Re: Help with 0x0F EID 0x01
Post by: Kp on July 21, 2005, 09:17 PM
Alternately, if you were using a language that actually supported indexing operations well, you'd just step the iterator forward by 20 bytes. :)
Title: Re: Help with 0x0F EID 0x01
Post by: Loud on July 21, 2005, 09:54 PM
Kp pwns me and my Visual Basic... I see the error in my ways, and promise to only program in C from this day on... As soon as I can cough up X amount of money for Visual C++...? Uhh, maybe later.
Title: Re: Help with 0x0F EID 0x01
Post by: Eric on July 21, 2005, 10:01 PM
Note that it would also be a good idea to have a sanity check to ensure that the packet is not of some obsurd length, one which could possibly overflow your buffer.

Public Type BNCSPKT
    bytPktHdr  As Byte
    bytPktID   As Byte
    intPktLen  As Integer
    strPktData As String
End Type


' Removes individual packets from the incoming TCP/IP stream and passes them to parsing function
Public Sub PreParse(ByRef strData As String, ByVal lngLen As Long)
    Dim pkt As modBNCS.BNCSPKT
   
    lngLstBeat = GetTickCount()
    bMsdBeats = 0

    ' Store incoming data stream in buffer
    With PktInBuf
        .InsertRAW strData
       
        ' Check for buffer errors
        If (.LastErr() > 0) Then
            .ClearBuf
           
            Exit Sub
        End If
   
        ' Remove packet(s) from buffer
        While (.BufSize() >= 4)
       
            If (.PeekBYTE() <> &HFF) Then
                ' Packet has an invalid header

                .ClearBuf

                Exit Sub
            End If

            pkt.intPktLen = .PeekWORD(3)
           
            If (pkt.intPktLen > .BufSize()) Then
                ' Incomplete packet
                Exit Sub
            End If
           
            Call CopyMemory(pkt, ByVal .GetRAW(4), 4)
            pkt.strPktData = .GetRAW((pkt.intPktLen - 4))
           
            Call ParsePkt(pkt)
        Wend
    End With
End Sub
Title: Re: Help with 0x0F EID 0x01
Post by: Kp on July 21, 2005, 11:58 PM
Quote from: Loud on July 21, 2005, 09:54 PMKp pwns me and my Visual Basic... I see the error in my ways, and promise to only program in C from this day on... As soon as I can cough up X amount of money for Visual C++...? Uhh, maybe later.

Or you could get a free C++ compiler (http://www.mingw.org/)? :P