• Welcome to Valhalla Legends Archive.
 

Help with 0x0F EID 0x01

Started by Loud, July 19, 2005, 07:11 PM

Previous topic - Next topic

Hdx

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

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

Kp

Alternately, if you were using a language that actually supported indexing operations well, you'd just step the iterator forward by 20 bytes. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Loud

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.

Eric

#18
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

Kp

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? :P
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!