• Welcome to Valhalla Legends Archive.
 

[VB6] Parsing 0x65

Started by Joe[x86], August 15, 2005, 01:58 AM

Previous topic - Next topic

Joe[x86]

Heres my parser for it. It spits out ugly messages, and is horribly inefficent at doing so. There has got to be an easier way than this! Anyhow, heres what I've managed to do.

Quote[12:56:10 AM] [BNCS-DEBUG] Friends List:
[12:56:10 AM] [BNCS-DEBUG] krazed[x86] (Mutual Away) is in chat and using StarCraft Expansion in the channel op x86.
[12:56:10 AM] [BNCS-DEBUG] ersan is offline.
[12:56:10 AM] [BNCS-DEBUG] x86 is in chat and using WarCraft II: BNE.
[12:56:10 AM] [BNCS-DEBUG] WirE is offline.
[12:56:10 AM] [BNCS-DEBUG] vuther is offline.
[12:56:10 AM] [BNCS-DEBUG] InsaneJoey[x86] is offline.
[12:56:10 AM] [BNCS-DEBUG] Screenor is in chat and using WarCraft II: BNE.
[12:56:10 AM] [BNCS-DEBUG] HdxBmx27 is offline.

Quote'Status Constants
Private Const bMutual      As Byte = &H1
Private Const bDND         As Byte = &H2
Private Const bAway        As Byte = &H3

'Location Constants
Private Const bOffline     As Byte = &H0
Private Const bNotInChat   As Byte = &H1
Private Const bInChat      As Byte = &H2
Private Const bInPubGame   As Byte = &H3
Private Const bInPrivGame  As Byte = &H4

Public Sub ParseFriends(S As String)
    Call AddChat(frmMain.rtbChat, True, vbYellow, "[BNCS-DEBUG] Friends List:")
    Dim Debuff As clsDebuffer, i As Byte, Name As String, Status As Byte, Location As Byte, ProductID As String, Channel As String
    Set Debuff = New clsDebuffer
    With Debuff
        Let .Buffer = S
        Call .RemoveHeader(4) 'Remove Header
        For i = 1 To .RemoveByte
            Name = .RemoveNTString
            Status = .RemoveByte
            Location = .RemoveByte
            ProductID = .RemoveVoid(4)
            Channel = .RemoveNTString
            Call AddChat(frmMain.rtbChat, True, vbYellow, AssembleMessage(Name, ParseStatus(Status), ParseLocation(Location), modMain.GetProductName(ProductID), Channel))
        Next i
    End With
End Sub

Private Function ParseStatus(B As Byte) As String
    Dim Mutual As Boolean, DND As Boolean, Away As Boolean
    If B And bMutual Then Mutual = True
    If B And bDND Then DND = True
    If B And bAway Then Away = True
   
    Dim Ret As String
    Ret = Ret & IIf(Mutual, "Mutual ", vbNullString)
    Ret = Ret & IIf(DND, "DND ", vbNullString)
    Ret = Ret & IIf(Away, "Away", vbNullString)
   
    ParseStatus = Ret
End Function

Public Function ParseLocation(B As Byte)
    Select Case B
        Case bOffline
            ParseLocation = "offline"
        Case bNotInChat
            ParseLocation = "not in chat"
        Case bInChat
            ParseLocation = "in chat"
        Case bInPubGame
            ParseLocation = "in public game"
        Case bInPrivGame
            ParseLocation = "in private game"
    End Select
End Function

Public Function AssembleMessage(Name As String, Status As String, Location As String, ProductID As String, Channel As String)
        Dim Ret As String
        Let Ret = Ret & "[BNCS-DEBUG] "
        Let Ret = Ret & Name
        Let Ret = Ret & Space(1) & IIf(Len(Status) = 0, vbNullString, "(" & Status & ") ")
        Let Ret = Ret & "is " & Location
        If Location = "offline" Then AssembleMessage = Ret & ".": Exit Function
        Let Ret = Ret & " and using " & ProductID
        If Location = "not in chat" Then AssembleMessage = Ret & ".": Exit Function
        If Location = "in chat" And InStr(1, Status, "Mutual") Then AssembleMessage = Ret & " in the channel " & Channel & ".": Exit Function
        Let AssembleMessage = Ret & ".": Exit Function
        'Call AddChat(frmMain.rtbChat, True, vbYellow, "[BNCS-DEBUB] " & Name & "(" & ParseStatus(Status) & ") is " & ParseLocation(Location) & " using " & modMain.GetProductName(ProductID) & " in " & Channel & ".")
End Function


EDIT -
More code.

Private Sub CSB_UnhandledPacket(SocketName As String, Packet As String, RawData As String, HexData As String)
    Select Case Mid(Packet, 4)
        Case "65"
            Call ParseFriends(RawData)
        Case Else
             '...
    End Select
End Sub


QuotePrivate Sub tmrFriends_Timer()
    If CSB.Connected Then Call CSB.BuildPacket("BNET", "PACKET", &H65)
End Sub

Yes, I am using CSB. Leave me alone. /cry.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

I don't think it's that inefficient, unless your debuffer is horribly inefficient.  The only place you could really tune that is when you're formatting the string.  You might be able to speed it up with sprintf or something, but I don't really think that's necessary.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.