VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "BnetBot"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Const ID_EMOTE = &H17
Private Const ID_WHISPTO = &HA
Private Const ID_WHISPFROM = &H4
Private Const ID_TALK = &H5
Private Const ID_USER = &H1
Private Const ID_JOIN = &H2
Private Const ID_LEAVE = &H3
Private Const ID_FLAGS = &H9
Private Const ID_CHAN = &H7
Private Const ID_ERROR = &H13
Private Const ID_INFO = &H12
Private Const ID_BROADCAST = &H6
'Flag Settings for Special Icons
Private Const BNFLAGS_BLIZZ = &H1
Private Const BNFLAGS_SYSOP = &H8
Private Const BNFLAGS_OP = &H2
Private Const BNFLAGS_SPKR = &H4
Private Const BNFLAGS_GLASSES = &H40
Private Const BNFLAGS_SQUELCH = &H20
Private Const BNFLAGS_GFOFFICIAL = &H100000
Private Const BNFLAGS_GFPLAYER = &H200000
Private Const BNFLAGS_PLUG = &H10
Public Event OnUser(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnJoin(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnLeave(ByVal username As String, ByVal Flags As Long, ByVal Ping As Long)
Public Event OnWhisperFrom(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnTalk(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnChannel(ByVal ChannelName As String, ByVal Flags As Long)
Public Event OnFlags(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnWhisperTo(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnInfo(ByVal message As String)
Public Event OnError(ByVal message As String)
Public Event OnEmote(ByVal username As String, ByVal Flags As Long, ByVal message As String, ByVal Ping As Long)
Public Event OnUnknown(ByVal UnknownString As String)
Public Sub DispatchMessage(ByVal databuf As String)
Dim EID As Long, Ping As Long, username As String, message As String
    EID = MakeLong(Mid$(databuf, 5, 4))
    Flags = MakeLong(Mid$(databuf, 9, 4))
    Ping = MakeLong(Mid$(databuf, 13, 4))
    username = KillNull(Mid$(databuf, 29))
    message = KillNull(Mid$(databuf, Len(username) + 30))
    Dim i As Long
    i = InStr(1, username, "*")
    If i Then
        username = Mid$(username, i + 1)
    End If
Select Case EID
    Case ID_TALK
        RaiseEvent OnTalk(username, Flags, message, Ping)
        Exit Sub
    Case ID_EMOTE
        RaiseEvent OnEmote(username, Flags, message, Ping)
        Exit Sub
    Case ID_CHAN
        RaiseEvent OnChannel(message, Flags)
        Exit Sub
    Case ID_USER
        RaiseEvent OnUser(username, Flags, message, Ping)
        Exit Sub
    Case ID_JOIN
        RaiseEvent OnJoin(username, Flags, message, Ping)
        Exit Sub
    Case ID_LEAVE
        RaiseEvent OnLeave(username, Flags, Ping)
        Exit Sub
    Case ID_WHISPTO
        RaiseEvent OnWhisperTo(username, Flags, message, Ping)
        Exit Sub
    Case ID_WHISPFROM
        RaiseEvent OnWhisperFrom(username, Flags, message, Ping)
        Exit Sub
    Case ID_INFO
        RaiseEvent OnInfo(message)
        Exit Sub
    Case ID_FLAGS
        RaiseEvent OnFlags(username, Flags, message, Ping)
        Exit Sub
    Case ID_BROADCAST
        RaiseEvent OnInfo(message)
        Exit Sub
    Case ID_ERROR
        RaiseEvent OnError(message)
        Exit Sub
    Case ID_ERROR
        RaiseEvent OnError(message)
        Exit Sub
    Case Else
        RaiseEvent OnUnknown(message)
        Exit Sub
End Select
End Sub
Function MakeLong(X As String) As Long
    If Len(X) < 4 Then
        Exit Function
    End If
    CopyMemory MakeLong, ByVal X, 4
End Function
Public Function GetIconCode(ByVal statstring As String, ByVal Flags As Long) As Integer
Dim Product As String
Product = Mid(statstring, 1, 4)
    If (BNFLAGS_BLIZZ And Flags) = BNFLAGS_BLIZZ Then
        GetIconCode = 2
        Exit Function
    ElseIf (BNFLAGS_SYSOP And Flags) = BNFLAGS_SYSOP Then
        GetIconCode = 3
        Exit Function
    ElseIf (BNFLAGS_OP And Flags) = BNFLAGS_OP Then
        GetIconCode = 1
        Exit Function
    ElseIf (BNFLAGS_SPKR And Flags) = BNFLAGS_SPKR Then
        GetIconCode = 4
        Exit Function
    ElseIf (BNFLAGS_GLASSES And Flags) = BNFLAGS_GLASSES Then
        GetIconCode = 5
        Exit Function
    ElseIf (BNFLAGS_SQUELCH And Flags) = BNFLAGS_SQUELCH Then
        GetIconCode = 21
        Exit Function
    ElseIf (BNFLAGS_GFOFFICIAL And Flags) = BNFLAGS_GFOFFICIAL Then
        GetIconCode = 12
        Exit Function
    ElseIf (BNFLAGS_GFPLAYER And Flags) = BNFLAGS_GFPLAYER Then
        GetIconCode = 11
        Exit Function
    ElseIf Not Flags Then: GoTo Products
    End If
Products:
   Select Case Product
        Case "TAHC": GetIconCode = 6
        Case "LTRD": GetIconCode = 7
        Case "RHSD": GetIconCode = 8
        Case "VD2D": GetIconCode = 9
        Case "PX2D": GetIconCode = 10
        Case "RATS": GetIconCode = 13
        Case "RHSS": GetIconCode = 14
        Case "PXES": GetIconCode = 16
        Case "RTSJ": GetIconCode = 17
        Case "NB2W": GetIconCode = 18
        Case "3RAW": GetIconCode = 19
        Case Else: GetIconCode = 20
    End Select
End Function
Public Function GetPingIcon(ByVal Ping As Long, ByVal Flags As Long) As Integer
If (Flags And BNFLAGS_PLUG) = BNFLAGS_PLUG Then
            GetPingIcon = 28
            Exit Function
End If
    Select Case Ping
        Case Is = 0
            GetPingIcon = 28
        Case Is < 0
            GetPingIcon = 29
        Case 0 To 200
            GetPingIcon = 22
        Case 200 To 300
            GetPingIcon = 23
        Case 300 To 400
            GetPingIcon = 24
        Case 400 To 500
            GetPingIcon = 25
        Case 500 To 600
            GetPingIcon = 26
        Case Else
            GetPingIcon = 27
    End Select
End Function
