VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsClan"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'-----------------------------------------------------
' MirageBot User Object
' Written by Christopher Nevin (lancergli@gmail.com)
'-----------------------------------------------------

Option Explicit

Private Members() As New objMember

Public InviteTag As Long, Invitee As String, Inviter As String, InviteTagStr As String, InviteAfterCreate As New Collection
Public Cookie As Long, TickInvite As Long
Public Changee As String, ChangeeRank As Byte
Public TickInviteResp As Double, InviteRespType As Integer

Public InClan As Boolean
Public Rank As CLANRANKENUM
Public Tag As String

Public Sub Clear()
    ReDim Members(0)
End Sub

Public Sub Add(Username As String, Rank As Byte, Online As Long, Location As String)
On Error GoTo hErr
    If UBound(Members) > 0 Or Members(0).Username = Username Then Remove Username
    Dim U As New objMember
    U.Username = Username
    U.Online = Online
    U.Rank = Rank
    U.Location = Location
    If Online > 0 Then
        U.SeenTick = DblTickCount
    Else
        U.SeenTick = 0
    End If
    If LenB(Members(0).Username) Then ReDim Preserve Members(UBound(Members) + 1)
    Set Members(UBound(Members)) = U
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Members", "Add"
End Sub

Public Function Match(strMatch As String) As String()
    Dim I As Integer, S() As String, C As Integer
    ReDim S(0)
    C = UBound(Members)
    For I = 0 To C
        If Matches(Members(I).Username, strMatch) Then
            If LenB(S(0)) = 0 Then
                S(0) = Members(I).Username
            Else
                ReDim Preserve S(UBound(S) + 1)
                S(UBound(S)) = Members(I).Username
            End If
        End If
    Next I
    Match = S
End Function

Public Sub Remove(Username As String)
On Error GoTo hErr
    Dim I As Integer
    I = Find(Username)
    If I > -1 Then
        If UBound(Members) = 0 Then
            ReDim Members(0)
        Else
            Dim r As Integer, C As Integer
            C = UBound(Members) - 1
            For r = I To C
                Set Members(r) = Members(r + 1)
            Next
            ReDim Preserve Members(C)
        End If
    End If
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Members", "Remove"
End Sub

Public Sub Update(Username As String, Rank As Byte, Online As Long, Location As String)
On Error GoTo hErr
    Dim I As Integer
    I = Find(Username)
    If I > -1 Then
        Members(I).Rank = Rank
        Members(I).Online = Online
        Members(I).Location = Location
        If Online <> 0 And Members(I).SeenTick = 0 Then
            Members(I).SeenTick = DblTickCount
        Else
            Members(I).SeenTick = 0
        End If
    End If
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Members", "Update"
End Sub

Public Function Find(ByVal Username As String) As Integer
On Error GoTo hErr
    Dim I As Integer, C As Integer
    Username = LCase$(Username)
    C = UBound(Members)
    For I = 0 To C
        If (Username = LCase$(Members(I).Username)) Then
            Find = I
            Exit Function
        End If
    Next I
    Find = -1
    Exit Function
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Members", "Find"
End Function

Public Function Count() As Integer
    Count = UBound(Members)
End Function

Public Function CountShaman() As Integer
    Dim I As Integer, C As Integer
    For I = 0 To UBound(Members)
        If Members(I).Rank = crShaman Then
            C = C + 1
        End If
    Next I
    CountShaman = C
End Function

Public Function GetByName(Username As String) As objMember
On Error GoTo hErr
    Dim I As Integer
    I = Find(Username)
    If I > -1 Then Set GetByName = Members(I) Else Set GetByName = Nothing
    Exit Function
hErr:
    Set GetByName = Nothing
    ErrorHandler Err.Number, Err.Description, Erl, "Members", "GetByName"
End Function

Public Function GetByIndex(Index As Integer) As objMember
On Error GoTo hErr
    If Index < 0 Or Index > UBound(Members) Then Exit Function
    Set GetByIndex = Members(Index)
    Exit Function
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Members", "GetByIndex"
End Function

Public Function IsMember(Username As String) As Boolean
    IsMember = (Find(Username) > -1)
End Function

Public Sub Class_Initialize()
    ReDim Members(0) As New objMember
End Sub

Public Sub Class_Terminate()
    On Error Resume Next
    ReDim Members(0)
End Sub
