Valhalla Legends Forums Archive | Battle.net Bot Development | [VB] IncommingPacket Class

AuthorMessageTime
JoeTheOdd
Yeah, I was having trouble splitting packets apart so I wrote this for JBBE. Basically, add to it when you recieve data. Then check for a packet, and if theres a whole one, parse it. Then check again, and again, until it returns false, when you exit the sub.

[code]Option Explicit

Private m_sBuffer As String

Public Sub Add(sData As String)
    'Debug.Print "added data: " & sData
    m_sBuffer = m_sBuffer & sData
End Sub

Public Function HasPacket() As Boolean
    'Debug.Print "HasPacket(). Current buffer: " & m_sBuffer
    If Len(m_sBuffer) < 4 Then HasPacket = False: Exit Function
    Dim Length As Integer: Length = GetWORD(Mid(m_sBuffer, 3, 2))
    If Len(m_sBuffer) >= Length Then
        HasPacket = True
    Else
        HasPacket = False
    End If
End Function

Public Function GetPacket() As String
    'Debug.Print "GetPacket(). HasPacket: " & HasPacket
    If HasPacket Then
        Dim Length As Integer: Length = GetWORD(Mid(m_sBuffer, 3, 2))
        GetPacket = Mid(m_sBuffer, 1, Length)
        m_sBuffer = Mid(m_sBuffer, Length + 1)
    End If
End Function[/code]

Usage:
[code]Public Sub PParse(sData As String)
    IncommingPacket.Add sData
Start:
    If IncommingPacket.HasPacket Then Call Parse(IncommingPacket.GetPacket) Else Exit Sub
    GoTo Start
End Sub[/code]

Enjoy!
November 20, 2005, 3:34 AM

Search