Skip to content
Permalink
Browse files

Store username-based filters in memory

This avoids several disk reads on every user event
  • Loading branch information...
Davnit committed Mar 27, 2017
1 parent f1203e1 commit 3c4f06a63f0cdad32f9a3d963f0f5e3df48467b1
Showing with 58 additions and 59 deletions.
  1. +47 −41 trunk/frmChat.frm
  2. +1 −0 trunk/frmFilters.frm
  3. +3 −0 trunk/modCommandsChat.bas
  4. +1 −0 trunk/modConstants.bas
  5. +1 −0 trunk/modGlobals.bas
  6. +5 −18 trunk/modOtherCode.bas
@@ -1836,6 +1836,7 @@ Private Sub Form_Load()
ReDim gOutFilters(0)
ReDim gFilters(0)
ReDim ServerRequests(0)
ReDim g_Blocklist(0)

Call BuildProductInfo

@@ -7258,6 +7259,7 @@ Sub ReloadConfig(Optional Mode As Byte = 0)
'LoadSafelist
LoadArray LOAD_PHRASES, Phrases()
LoadArray LOAD_FILTERS, gFilters()
LoadArray LOAD_BLOCKLIST, g_Blocklist()

ProtectMsg = Config.ChannelProtectionMessage

@@ -7532,55 +7534,59 @@ ERROR_HANDLER:
End Sub

Sub LoadArray(ByVal Mode As Byte, ByRef tArray() As String)
Dim f As Integer
Dim Path As String
Dim temp As String
Dim i As Integer
Dim c As Integer

f = FreeFile

Const FI As String = "TextFilters"

Dim iFileHandle As Integer ' Source file number
Dim sFilePath As String ' Full path to the source file
Dim sTemp As String ' Temporary string
Dim iFilterCount As Integer ' Total number of filters saved
Dim sFilterSection As String ' The section of filters to read (message vs users)
Dim i As Integer ' Counter

' Determine where to read from.
Select Case Mode
Case LOAD_FILTERS
Path = GetFilePath(FILE_FILTERS)
Case LOAD_FILTERS, LOAD_BLOCKLIST
sFilePath = GetFilePath(FILE_FILTERS)
sFilterSection = IIf(Mode = LOAD_FILTERS, "TextFilters", "BlockList")
Case LOAD_PHRASES
Path = GetFilePath(FILE_PHRASE_BANS)
Case LOAD_DB
Path = GetFilePath(FILE_USERDB)
Exit Sub
sFilePath = GetFilePath(FILE_PHRASE_BANS)
End Select

If Dir(Path) <> vbNullString Then
Open Path For Input As #f
If LOF(f) > 2 Then
ReDim tArray(0)
If Mode <> LOAD_FILTERS Then
Do
Line Input #f, temp
If Len(temp) > 0 Then
' removed for 2.5 - why am I PCing it ?
'If Mode = LOAD_SAFELIST Then temp = PrepareCheck(temp)
tArray(UBound(tArray)) = LCase(temp)
ReDim Preserve tArray(UBound(tArray) + 1)
End If
Loop While Not EOF(f)
Else
temp = ReadINI(FI, "Total", FILE_FILTERS)
If temp <> vbNullString And CInt(temp) > -1 Then
c = Int(temp)
For i = 1 To c
temp = ReadINI(FI, "Filter" & i, FILE_FILTERS)
If temp <> vbNullString Then
tArray(UBound(tArray)) = LCase(temp)
If i <> c Then ReDim Preserve tArray(UBound(tArray) + 1)
If Dir(sFilePath) <> vbNullString Then
' Empty the turn array.
ReDim tArray(0)

Select Case Mode
Case LOAD_FILTERS, LOAD_BLOCKLIST
' Get the total number of filters
sTemp = ReadINI(sFilterSection, "Total", FILE_FILTERS)
If ((LenB(sTemp) > 0) And (CInt(sTemp) > 0)) Then
iFilterCount = Int(sTemp)

' Read each filter into a row of the array.
For i = 1 To iFilterCount
sTemp = ReadINI(sFilterSection, "Filter" & i, FILE_FILTERS)
If LenB(sTemp) > 0 Then
tArray(UBound(tArray)) = sTemp
ReDim Preserve tArray(UBound(tArray) + 1)
End If
Next i
End If
End If
Case Else
' Read each line of the file into a row in the array.
Open sFilePath For Input As #iFileHandle
Do
Line Input #iFileHandle, sTemp
If LenB(sTemp) > 0 Then
tArray(UBound(tArray)) = sTemp
ReDim Preserve tArray(UBound(tArray) + 1)
End If
Loop While Not EOF(iFileHandle)
Close #iFileHandle
End Select

' Remove the last unused row.
If UBound(tArray) > 0 Then
ReDim Preserve tArray(UBound(tArray) - 1)
End If
Close #f
End If
End Sub

@@ -706,6 +706,7 @@ Private Sub Form_Unload(Cancel As Integer)

Call frmChat.LoadOutFilters
Call frmChat.LoadArray(LOAD_FILTERS, gFilters())
Call frmChat.LoadArray(LOAD_BLOCKLIST, g_Blocklist())
End Sub

Private Sub optBlock_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
@@ -62,6 +62,8 @@ Public Sub OnBlock(Command As clsCommandObj)
WriteINI "BlockList", "Filter" & (Total + 1), Command.Argument("Username"), FiltersPath
WriteINI "BlockList", "Total", Total + 1, FiltersPath
Command.Respond StringFormat("Added {0}{1}{0} to the username block list.", Chr$(34), Command.Argument("Username"))

Call frmChat.LoadArray(LOAD_BLOCKLIST, g_Blocklist())
Else
Command.Respond "Your filters file has been edited manually and is no longer valid. Please delete it."
End If
@@ -232,6 +234,7 @@ Public Sub OnUnBlock(Command As clsCommandObj)
Next i
WriteINI "BlockList", "Total", (Total - 1), FiltersPath
Command.Respond StringFormat("Removed {0}{1}{0} from the blocked users list.", Chr$(34), Command.Argument("Username"))
Call frmChat.LoadArray(LOAD_BLOCKLIST, g_Blocklist())
End If
Else
Command.Respond "Your filters file has been edited manually and is no longer valid. Please delete it."
@@ -239,6 +239,7 @@ Public Const LOAD_SAFELIST = 1
Public Const LOAD_FILTERS = 2
Public Const LOAD_PHRASES = 3
Public Const LOAD_DB = 4
Public Const LOAD_BLOCKLIST = 5

Public Const DB_TYPE_USER = "USER"
Public Const DB_TYPE_GROUP = "GROUP"
@@ -97,6 +97,7 @@ Public Catch() As String
Public gBans() As udtBanList
Public gOutFilters() As udtOutFilters
Public gFilters() As String
Public g_Blocklist() As String

Public AutoModSafelistValue As Integer

@@ -765,27 +765,14 @@ Public Function CheckBlock(ByVal Username As String) As Boolean
Dim s As String
Dim i As Integer

If (LenB(Dir$(GetFilePath(FILE_FILTERS))) > 0) Then
s = ReadINI("BlockList", "Total", GetFilePath(FILE_FILTERS))

If (StrictIsNumeric(s)) Then
i = s
Else
Exit Function
End If

Username = PrepareCheck(Username)

For i = 0 To i
s = ReadINI("BlockList", "Filter" & i, GetFilePath(FILE_FILTERS))

If (Username Like PrepareCheck(s)) Then
For i = 0 To UBound(g_Blocklist)
If Len(g_Blocklist(i)) > 0 Then
If (PrepareCheck(Username) Like PrepareCheck(g_Blocklist(i))) Then
CheckBlock = True

Exit Function
End If
Next i
End If
End If
Next i
End Function

Public Function CheckMsg(ByVal Msg As String, Optional ByVal Username As String, Optional ByVal Ping As _

0 comments on commit 3c4f06a

Please sign in to comment.
You can’t perform that action at this time.