Skip to content

Commit

Permalink
Resolve Issue #10: Blacklist messages feature
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Sep 26, 2015
1 parent e2ae40c commit 02e56b5
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 26 deletions.
Binary file modified .BNRBot.rbuistate
Binary file not shown.
28 changes: 28 additions & 0 deletions Modules/Globals.rbbas
Expand Up @@ -1859,6 +1859,34 @@ Protected Module Globals
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function MessageBlacklistMatch(Pattern As String) As Boolean

Dim regex As New RegEx()
Dim match As RegExMatch
Dim i As Integer = UBound(Settings.PrefMessageBlacklist)
While i >= 0
Select Case Settings.PrefMessageBlacklist(i).Left
Case 0 // Exact
If Settings.PrefMessageBlacklist(i).Right = Pattern Then Return True
Case 1 // Regex
Try
regex.SearchPattern = Settings.PrefMessageBlacklist(i).Right
match = regex.Search(Pattern)
If match <> Nil Then Return True
Catch err As RegExException
Continue // Regex problem, skip this pattern

This comment has been minimized.

Copy link
@carlbennett

carlbennett Nov 10, 2015

Author Owner

There's a bug here where it will enter an infinite loop since i is not decreased here. Reported in #19

End Try
Case Else // Unknown
End Select
i = i - 1
Wend

Return False // No Match

End Function
#tag EndMethod

#tag Method, Flags = &h0
Function NeedsCDKey(Product As UInt32) As Boolean

Expand Down
12 changes: 10 additions & 2 deletions Modules/Packets.rbbas
Expand Up @@ -1247,14 +1247,18 @@ Protected Module Packets
// If bTmp = True then they are talking at most 0.4 seconds after entering.

If dTmp <> Nil Then
If Sock.Config.SpamPrevention = True And Text = dTmp.Value("LastMessage") Then bTmp = True
If bTmp = False And Sock.Config.SpamPrevention = True And Text = dTmp.Value("LastMessage") Then bTmp = True
dTmp.Value("LastMessageTime") = Microseconds()
dTmp.Value("LastMessageType") = EventID
dTmp.Value("LastMessage") = Text
End If

// If bTmp = True now then they may also be repeating their message.

If bTmp = False And Globals.MessageBlacklistMatch(Text) = True Then bTmp = True

// If bTmp = True now then the message may even also be on the blacklist

If BitAnd(Flags, &H20) <= 0 And bTmp = False Then
If BitAnd(Flags, &H09) > 0 Then
colorA = Colors.Teal
Expand Down Expand Up @@ -1378,14 +1382,18 @@ Protected Module Packets
// If bTmp = True then they are talking at most 0.4 seconds after entering.

If dTmp <> Nil Then
If Sock.Config.SpamPrevention = True And Text = dTmp.Value("LastMessage") Then bTmp = True
If bTmp = False And Sock.Config.SpamPrevention = True And Text = dTmp.Value("LastMessage") Then bTmp = True
dTmp.Value("LastMessageTime") = Microseconds()
dTmp.Value("LastMessageType") = EventID
dTmp.Value("LastMessage") = Text
End If

// If bTmp = True now then they may also be repeating their message.

If bTmp = False And Globals.MessageBlacklistMatch(Text) = True Then bTmp = True

// If bTmp = True now then the message may even also be on the blacklist

If BitAnd(Flags, &H20) <= 0 And bTmp = False Then
If BitAnd(Flags, &H09) > 0 Then
colorA = Colors.Teal
Expand Down
110 changes: 100 additions & 10 deletions Modules/Settings.rbbas
Expand Up @@ -277,6 +277,7 @@ Protected Module Settings
Dim Options As UInt32
Dim Configs() As Configuration
Dim PingRanges() As PingRange
Dim MessageBlacklist() As Pair

// Second, retrieve the version of the file and then try to parse the file:
Dim Version As Byte = Buffer.ReadBYTE()
Expand Down Expand Up @@ -304,6 +305,9 @@ Protected Module Settings
PingRanges(UBound(PingRanges)).HighestPing = Buffer.ReadDWORD()
Wend

ReDim MessageBlacklist(-1) // Clear out any previous data (Fail safe check)
// Version 0 doesn't have a blacklist

Case Settings.SectionConfiguration
Configs.Append(New Configuration())
Configs(UBound(Configs)).Name = Buffer.ReadCString()
Expand Down Expand Up @@ -348,6 +352,78 @@ Protected Module Settings

End Select

Wend
Case 1
While Buffer.EOF() = False

Section = Buffer.ReadDWORD()
Select Case Section
Case Settings.SectionGlobal
Options = Buffer.ReadBYTE()
Settings.PrefCheckForUpdates = (BitAnd(Options, &H01) > 0)
Settings.PrefMinimizeToTray = (BitAnd(Options, &H02) > 0)
Settings.PrefPingRangesFlushRight = (BitAnd(Options, &H04) > 0)

// Ping Ranges
ReDim PingRanges(-1) // Clear out any previous data (Fail safe check)
Options = Buffer.ReadWORD() // Options is reused as a variable...
While UBound(PingRanges) + 1 < Options
PingRanges.Append(New PingRange())
PingRanges(UBound(PingRanges)).BarCount = Buffer.ReadDWORD()
PingRanges(UBound(PingRanges)).BarColor = Buffer.ReadDWORD()
PingRanges(UBound(PingRanges)).LowestPing = Buffer.ReadDWORD()
PingRanges(UBound(PingRanges)).HighestPing = Buffer.ReadDWORD()
Wend

// Message Blacklist
ReDim MessageBlacklist(-1) // Clear out any previous data (Fail safe check)
Options = Buffer.ReadWORD() // Options is reused as a variable...
While UBound(MessageBlacklist) + 1 < Options
MessageBlacklist.Append(New Pair(Buffer.ReadBYTE(), Buffer.ReadCString()))
Wend

Case Settings.SectionConfiguration
Configs.Append(New Configuration())
Configs(UBound(Configs)).Name = Buffer.ReadCString()
Configs(UBound(Configs)).Username = Buffer.ReadCString()
Configs(UBound(Configs)).Password = Buffer.ReadCString()
Configs(UBound(Configs)).BNETHost = Buffer.ReadCString()
Configs(UBound(Configs)).BNLSHost = Buffer.ReadCString()
Configs(UBound(Configs)).Product = Buffer.ReadDWORD()
Configs(UBound(Configs)).VersionByte = Buffer.ReadDWORD()
Configs(UBound(Configs)).CDKey = Buffer.ReadCString()
Configs(UBound(Configs)).CDKeyExpansion = Buffer.ReadCString()
Configs(UBound(Configs)).CDKeyOwner = Buffer.ReadCString()
Configs(UBound(Configs)).EmailAddress = Buffer.ReadCString()
Configs(UBound(Configs)).HomeChannel = Buffer.ReadCString()
Configs(UBound(Configs)).Timestamp = Buffer.ReadBYTE()
Configs(UBound(Configs)).PingSpoof = Buffer.ReadDWORD()

Options = Buffer.ReadDWORD()
Configs(UBound(Configs)).BNLSEnabled = (BitAnd(Options, &H01) > 0)
Configs(UBound(Configs)).CDKeySpawn = (BitAnd(Options, &H02) > 0)
Configs(UBound(Configs)).AutoRejoinWhenKicked = (BitAnd(Options, &H04) > 0)
Configs(UBound(Configs)).VerbosePackets = (BitAnd(Options, &H08) > 0)
Configs(UBound(Configs)).EnableUDP = (BitAnd(Options, &H10) > 0)
Configs(UBound(Configs)).BNLSVersionCheck = (BitAnd(Options, &H20) > 0)
Configs(UBound(Configs)).ShowJoinLeaveMessages = (BitAnd(Options, &H40) > 0)
Configs(UBound(Configs)).EnableUTF8 = (BitAnd(Options, &H80) > 0)
Configs(UBound(Configs)).SpamPrevention = (BitAnd(Options, &H100) > 0)
Configs(UBound(Configs)).IgnoreBanKickUnban = (BitAnd(Options, &H200) > 0)
Configs(UBound(Configs)).ConfirmRemovingClanMembers = (BitAnd(Options, &H400) > 0)
Configs(UBound(Configs)).CreateAccountsFirst = (BitAnd(Options, &H800) > 0)
Configs(UBound(Configs)).ShowUserUpdateMessages = (BitAnd(Options, &H1000) > 0)

Configs(UBound(Configs)).ProxyType = Buffer.ReadBYTE()
Configs(UBound(Configs)).ProxyHost = Buffer.ReadCString()

Case Else
// The section is unrecognized to us.
Settings.AppendLoadError("Could not parse the settings file because it contains at least one (1) bad section.")
Exit While

End Select

Wend
Case Else
// The file version is unrecognized to us.
Expand All @@ -357,6 +433,7 @@ Protected Module Settings

If UBound(Configs) >= 0 Then Settings.Configurations = Configs
If UBound(PingRanges) >= 0 Then Settings.PrefPingRanges = PingRanges
If UBound(MessageBlacklist) >= 0 Then Settings.PrefMessageBlacklist = MessageBlacklist

End Sub
#tag EndMethod
Expand Down Expand Up @@ -412,7 +489,7 @@ Protected Module Settings
Buffer.WriteCString("EDIT THIS FILE WITH BNRBOT, DO NOT MODIFY THIS FILE YOURSELF.")

// File version
Buffer.WriteBYTE(&H00)
Buffer.WriteBYTE(&H01)

// Section Global:
Buffer.WriteDWORD(Settings.SectionGlobal)
Expand All @@ -436,6 +513,17 @@ Protected Module Settings
Wend
End If

// Message Blacklist
Buffer.WriteWORD(UBound(Settings.PrefMessageBlacklist) + 1)
If UBound(Settings.PrefMessageBlacklist) >= 0 Then
Options = &H0000 // Reuse Options as our loop variable.
While Options <= UBound(Settings.PrefMessageBlacklist) And Options < &HFFFF
Buffer.WriteBYTE(Settings.PrefMessageBlacklist(Options).Left)
Buffer.WriteCString(Settings.PrefMessageBlacklist(Options).Right)
Options = Options + 1
Wend
End If

// Section Profile(s):
For Each Config As Configuration In Settings.Configurations
Buffer.WriteDWORD(Settings.SectionConfiguration)
Expand All @@ -462,17 +550,15 @@ Protected Module Settings
If Config.VerbosePackets = True Then Options = BitOr(Options, &H08)
If Config.EnableUDP = True Then Options = BitOr(Options, &H10)
If Config.BNLSVersionCheck = True Then Options = BitOr(Options, &H20)
// Unused Bit 0x40, used to be CBNET
If Config.ShowJoinLeaveMessages = True Then Options = BitOr(Options, &H80)
If Config.EnableUTF8 = True Then Options = BitOr(Options, &H100)
If Config.SpamPrevention = True Then Options = BitOr(Options, &H200)
If Config.IgnoreBanKickUnban = True Then Options = BitOr(Options, &H400)
If Config.ConfirmRemovingClanMembers = True Then Options = BitOr(Options, &H800)
If Config.CreateAccountsFirst = True Then Options = BitOr(Options, &H1000)
If Config.ShowUserUpdateMessages = True Then Options = BitOr(Options, &H2000)
If Config.ShowJoinLeaveMessages = True Then Options = BitOr(Options, &H40)
If Config.EnableUTF8 = True Then Options = BitOr(Options, &H80)
If Config.SpamPrevention = True Then Options = BitOr(Options, &H100)
If Config.IgnoreBanKickUnban = True Then Options = BitOr(Options, &H200)
If Config.ConfirmRemovingClanMembers = True Then Options = BitOr(Options, &H400)
If Config.CreateAccountsFirst = True Then Options = BitOr(Options, &H800)
If Config.ShowUserUpdateMessages = True Then Options = BitOr(Options, &H1000)
Buffer.WriteDWORD(Options)

Buffer.WriteCString("") // Unused String, used to be CBNET
Buffer.WriteBYTE(Config.ProxyType)
Buffer.WriteCString(Config.ProxyHost)

Expand Down Expand Up @@ -536,6 +622,10 @@ Protected Module Settings
Protected PrefCheckForUpdates As Boolean
#tag EndProperty

#tag Property, Flags = &h1
Protected PrefMessageBlacklist() As Pair
#tag EndProperty

#tag Property, Flags = &h1
Protected PrefMinimizeToTray As Boolean
#tag EndProperty
Expand Down
2 changes: 2 additions & 0 deletions Windows/wClanConfirmation.rbfrm
Expand Up @@ -46,6 +46,7 @@ Begin Window wClanConfirmation
Selectable = False
TabIndex = 0
TabPanelIndex = 0
TabStop = True
Text = "You requested to %ACTION% Clan %TAG%!"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -142,6 +143,7 @@ Begin Window wClanConfirmation
Selectable = False
TabIndex = 9
TabPanelIndex = 0
TabStop = True
Text = "If you really want to do this, hit OK below.\r\n\r\nOtherwise, hit Cancel to not take any action."
TextAlign = 0
TextColor = "#Colors.White"
Expand Down
5 changes: 5 additions & 0 deletions Windows/wClanCreationInvitation.rbfrm
Expand Up @@ -46,6 +46,7 @@ Begin Window wClanCreationInvitation
Selectable = False
TabIndex = 0
TabPanelIndex = 0
TabStop = True
Text = "You have been invited to create a clan!"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -80,6 +81,7 @@ Begin Window wClanCreationInvitation
Selectable = False
TabIndex = 1
TabPanelIndex = 0
TabStop = True
Text = "Clan Name: "
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -208,6 +210,7 @@ Begin Window wClanCreationInvitation
Selectable = False
TabIndex = 3
TabPanelIndex = 0
TabStop = True
Text = "Clan Tag:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -289,6 +292,7 @@ Begin Window wClanCreationInvitation
Selectable = False
TabIndex = 5
TabPanelIndex = 0
TabStop = True
Text = "Invited By:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -465,6 +469,7 @@ Begin Window wClanCreationInvitation
Selectable = False
TabIndex = 7
TabPanelIndex = 0
TabStop = True
Text = "Members:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down
4 changes: 4 additions & 0 deletions Windows/wClanInvitation.rbfrm
Expand Up @@ -46,6 +46,7 @@ Begin Window wClanInvitation
Selectable = False
TabIndex = 0
TabPanelIndex = 0
TabStop = True
Text = "You have been invited to a clan!"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -80,6 +81,7 @@ Begin Window wClanInvitation
Selectable = False
TabIndex = 1
TabPanelIndex = 0
TabStop = True
Text = "Clan Name: "
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -208,6 +210,7 @@ Begin Window wClanInvitation
Selectable = False
TabIndex = 3
TabPanelIndex = 0
TabStop = True
Text = "Clan Tag:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -289,6 +292,7 @@ Begin Window wClanInvitation
Selectable = False
TabIndex = 5
TabPanelIndex = 0
TabStop = True
Text = "Invited By:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down
3 changes: 3 additions & 0 deletions Windows/wClanRemoveMember.rbfrm
Expand Up @@ -46,6 +46,7 @@ Begin Window wClanRemoveMember
Selectable = False
TabIndex = 0
TabPanelIndex = 0
TabStop = True
Text = "Are you sure you wish to remove this member?"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -80,6 +81,7 @@ Begin Window wClanRemoveMember
Selectable = False
TabIndex = 1
TabPanelIndex = 0
TabStop = True
Text = "Username:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down Expand Up @@ -208,6 +210,7 @@ Begin Window wClanRemoveMember
Selectable = False
TabIndex = 3
TabPanelIndex = 0
TabStop = True
Text = "Clan Rank:"
TextAlign = 0
TextColor = "#Colors.White"
Expand Down

0 comments on commit 02e56b5

Please sign in to comment.