Skip to content
Permalink
Browse files

[Event_ServerInfo] Stricter parsing on ban and kick reasons; they can…

… no longer be used for unintended side-effects.

- "You are " must be the start of the message for /whoami response.
- "You are still marked " must be the start of the message for still-away alert.
- " your friends list." must be the end of the message for /f a, /f r, /f p, /f d responses.
- " was banned by " must follow the first word (username) for ban alert.
- " was unbanned by " must follow the first word (username) for unban alert.
- " kicked you out of the channel!" must be the end of the message for kicked alert.
- " has been unsquelched." must be the end of the message for /unsquelch response.
- " is your designated heir." must be the end of the message for /designate response.
- "Your friends are:" must be the entire message for /f l response.

- The above strings are moved to constants in this function.

Other server locales than "enUS" are still not supported.
  • Loading branch information...
nmbook committed Oct 29, 2017
1 parent bdc5f5e commit 20fddbe62a1d9ec9dc9829804a43e68ee87b5447
Showing with 166 additions and 152 deletions.
  1. +166 −152 trunk/modEvents.bas
@@ -720,15 +720,35 @@ Public Sub Event_ServerInfo(ByVal Username As String, ByVal Message As String)
On Error GoTo ERROR_HANDLER
#End If

Const MSG_BANNED As String = " was banned by "
Const MSG_UNBANNED As String = " was unbanned by "
Const MSG_SQUELCHED As String = " has been squelched."
Const MSG_UNSQUELCHED As String = " has been unsquelched."
Const MSG_KICKEDOUT As String = " kicked you out of the channel!"
Const MSG_FRIENDS As String = "Your friends are:"
Const MSG_WHOIS_1 As String = "You are "
Const MSG_WHOIS_2 As String = ", using "
Const MSG_WHOIS_IN_CHANNEL As String = " in channel "
Const MSG_WHOIS_IN_GAME As String = " in game "
Const MSG_WHOIS_IN_PRIVATE As String = " a private "

Const MSG_MARKED_AWAY As String = "You are still marked"

Const MSG_FRIENDSCH_END As String = " your friends list."
Const MSG_FRIENDSCH_ADDED As String = "Added "
Const MSG_FRIENDSCH_REMOVED As String = "Removed "
Const MSG_FRIENDSCH_PROMOTED As String = "Promoted "
Const MSG_FRIENDSCH_DEMOTED As String = "Demoted "

Const MSG_BAN As String = " was banned by "
Const MSG_UNBAN As String = " was unbanned by "

Const MSG_RECVKICK As String = " kicked you out of the channel!"

Const MSG_UNSQUELCH As String = " has been unsquelched."

Const MSG_DESIGNATED As String = " is your new designated heir."

Const MSG_FRIENDS As String = "Your friends are:"
Const MSG_FRIEND_OFFLINE As String = ", offline"
Const MSG_FRIENDS_SB_HIDING As String = " ÿci(StealthBot is hiding your offline friends)"

Dim i As Integer
Dim temp As String
Dim User As String
Dim bHide As Boolean
Dim ToANSI As String

@@ -761,183 +781,177 @@ Public Sub Event_ServerInfo(ByVal Username As String, ByVal Message As String)
' .Enabled = True
'End With
End If

' what is our current gateway name?
If (BotVars.Gateway = vbNullString) Then
If (InStr(1, Message, "You are ", vbTextCompare) > 0) And (InStr(1, Message, ", using ", _
vbTextCompare) > 0) Then

If ((InStr(1, Message, " in channel ", vbTextCompare) = 0) And _
(InStr(1, Message, " in game ", vbTextCompare) = 0) And _
(InStr(1, Message, " a private ", vbTextCompare) = 0)) Then

i = InStrRev(Message, Space$(1))

BotVars.Gateway = Mid$(Message, i + 1)

SetTitle GetCurrentUsername & ", online on " & BotVars.Gateway

Call DoChannelJoinHome

Call InsertDummyQueueEntry

RunInAll "Event_LoggedOn", CurrentUsername, BotVars.Product

Exit Sub
If (InStr(1, Message, Space$(1), vbBinaryCompare) <> 0) Then
' what is our current gateway name?
If (LenB(BotVars.Gateway) = 0) Then
If (StrComp(Left$(Message, Len(MSG_WHOIS_1)), MSG_WHOIS_1, vbTextCompare) = 0) And (InStr(1, Message, MSG_WHOIS_2, _
vbTextCompare) > 0) Then

If ((InStr(1, Message, MSG_WHOIS_IN_CHANNEL, vbTextCompare) = 0) And _
(InStr(1, Message, MSG_WHOIS_IN_GAME, vbTextCompare) = 0) And _
(InStr(1, Message, MSG_WHOIS_IN_PRIVATE, vbTextCompare) = 0)) Then

i = InStrRev(Message, Space$(1))

BotVars.Gateway = Mid$(Message, i + 1)

SetTitle GetCurrentUsername & ", online on " & BotVars.Gateway

Call DoChannelJoinHome

Call InsertDummyQueueEntry

RunInAll "Event_LoggedOn", CurrentUsername, BotVars.Product

Exit Sub
End If
End If
End If
End If

If (InStr(1, Message, Space$(1), vbBinaryCompare) <> 0) Then
If (InStr(1, Message, "are still marked", vbTextCompare) <> 0) Then
' You are still marked as away: filter TODO: option
If (StrComp(Left$(Message, Len(MSG_MARKED_AWAY)), MSG_MARKED_AWAY, vbTextCompare) = 0) Then
Exit Sub
End If

If ((InStr(1, Message, " from your friends list.", vbBinaryCompare) > 0) Or _
(InStr(1, Message, " to your friends list.", vbBinaryCompare) > 0) Or _
(InStr(1, Message, " in your friends list.", vbBinaryCompare) > 0) Or _
(InStr(1, Message, " of your friends list.", vbBinaryCompare) > 0)) Then

' friends list changes: request updates for unsupported FL
If (StrComp(Right$(Message, Len(MSG_FRIENDSCH_END)), MSG_FRIENDSCH_END, vbTextCompare) = 0) And _
((StrComp(Left$(Message, Len(MSG_FRIENDSCH_ADDED)), MSG_FRIENDSCH_ADDED, vbTextCompare) = 0) Or _
(StrComp(Left$(Message, Len(MSG_FRIENDSCH_REMOVED)), MSG_FRIENDSCH_REMOVED, vbTextCompare) = 0) Or _
(StrComp(Left$(Message, Len(MSG_FRIENDSCH_PROMOTED)), MSG_FRIENDSCH_PROMOTED, vbTextCompare) = 0) Or _
(StrComp(Left$(Message, Len(MSG_FRIENDSCH_DEMOTED)), MSG_FRIENDSCH_DEMOTED, vbTextCompare) = 0)) Then

If Config.FriendsListTab Then
If Not frmChat.FriendListHandler.SupportsFriendPackets(Config.Game) Then
Call frmChat.FriendListHandler.RequestFriendsList
End If
End If
End If

'Ban Evasion and banned-user tracking
temp = Split(Message, " ")(1)


'banned-user tracking
User = Split(Message, Space$(1))(1)
' added 1/21/06 thanks to
' http://www.stealthbot.net/forum/index.php?showtopic=24582

If (Len(temp) > 0) Then
Dim Banning As Boolean
Dim Unbanning As Boolean
Dim User As String
Dim cOperator As String
Dim msgPos As Integer
Dim pos As Integer
Dim tmp As String
Dim banpos As Integer
Dim j As Integer
Dim Reason As String

If (InStr(1, Message, MSG_BANNED, vbTextCompare) > 0) Then
User = Left$(Message, _
(InStr(1, Message, MSG_BANNED, vbBinaryCompare) - 1))

Reason = Mid$(Message, InStr(1, Message, MSG_BANNED, vbBinaryCompare) + Len(MSG_BANNED) + 1) ' trim out username and banned message
If (InStr(1, Reason, " (", vbBinaryCompare)) Then 'Did they give a message?
Reason = Mid$(Reason, InStr(1, Reason, " (") + 2) 'trim out the banning name (Note, when banned by a rep using Len(Username) won't work as its banned "By a Blizzard Representative")
Reason = Left$(Reason, Len(Reason) - 2) 'Trim off the trailing ")."
Else
Reason = vbNullString
End If

If (Len(User) > 0) Then
pos = g_Channel.GetUserIndex(Username)

If (pos > 0) Then
Dim BanlistObj As clsBanlistUserObj

banpos = g_Channel.IsOnBanList(User, Username)

If (banpos > 0) Then
g_Channel.Banlist.Remove banpos
Else
g_Channel.BanCount = (g_Channel.BanCount + 1)
End If

If ((BotVars.StoreAllBans) Or _
(StrComp(Username, GetCurrentUsername, vbBinaryCompare) = 0)) Then

Set BanlistObj = New clsBanlistUserObj

With BanlistObj
.Name = User
.Operator = Username
.DateOfBan = UtcNow
.IsDuplicateBan = (g_Channel.IsOnBanList(User) > 0)
.Reason = Reason
End With

If (Len(User) > 0) Then
If (InStr(1, Message, MSG_BAN, vbTextCompare) > 0) Then
If (StrComp(User, Left$(Message, (InStr(1, Message, MSG_BAN, vbBinaryCompare) - 1)), vbTextCompare) = 0) Then
' " was banned by " must follow User (first word)
Dim Reason As String
Dim BanlistObj As clsBanlistUserObj
Dim pos As Integer
Dim banpos As Integer

Reason = Mid$(Message, InStr(1, Message, MSG_BAN, vbBinaryCompare) + Len(MSG_BAN) + 1) ' trim out username and banned message
If (InStr(1, Reason, " (", vbBinaryCompare)) Then 'Did they give a message?
Reason = Mid$(Reason, InStr(1, Reason, " (") + 2) 'trim out the banning name (Note, when banned by a rep using Len(Username) won't work as its banned "By a Blizzard Representative")
Reason = Left$(Reason, Len(Reason) - 2) 'Trim off the trailing ")."
Else
Reason = vbNullString
End If

If (Len(User) > 0) Then
pos = g_Channel.GetUserIndex(Username)

If (BanlistObj.IsDuplicateBan) Then
With g_Channel.Banlist(g_Channel.IsOnBanList(User))
.IsDuplicateBan = False
If (pos > 0) Then
banpos = g_Channel.IsOnBanList(User, Username)

If (banpos > 0) Then
g_Channel.Banlist.Remove banpos
Else
g_Channel.BanCount = (g_Channel.BanCount + 1)
End If

If ((BotVars.StoreAllBans) Or _
(StrComp(Username, GetCurrentUsername, vbBinaryCompare) = 0)) Then

Set BanlistObj = New clsBanlistUserObj

With BanlistObj
.Name = User
.Operator = Username
.DateOfBan = UtcNow
.IsDuplicateBan = (g_Channel.IsOnBanList(User) > 0)
.Reason = Reason
End With

If (BanlistObj.IsDuplicateBan) Then
With g_Channel.Banlist(g_Channel.IsOnBanList(User))
.IsDuplicateBan = False
End With
End If

g_Channel.Banlist.Add BanlistObj
End If

g_Channel.Banlist.Add BanlistObj
End If

Call RemoveBanFromQueue(User)
End If

If (frmChat.mnuHideBans.Checked) Then
bHide = True
End If

Call RemoveBanFromQueue(User)
End If

If (frmChat.mnuHideBans.Checked) Then
bHide = True
End If
ElseIf (InStr(1, Message, MSG_UNBANNED, vbTextCompare) > 0) Then
User = Left$(Message, _
(InStr(1, Message, MSG_UNBANNED, vbBinaryCompare) - 1))

If (Len(User) > 0) Then
g_Channel.BanCount = (g_Channel.BanCount - 1)

Do
banpos = g_Channel.IsOnBanList(User)

If (banpos > 0) Then
g_Channel.Banlist.Remove banpos
End If
Loop While (banpos <> 0)
End If
End If

'// backup channel
If (InStr(1, Message, "kicked you out", vbTextCompare) > 0) Then
If (BotVars.UseBackupChan) Then
If (Len(BotVars.BackupChan) > 0) Then
frmChat.AddQ "/join " & BotVars.BackupChan
ElseIf (InStr(1, Message, MSG_UNBAN, vbTextCompare) > 0) Then
If (StrComp(User, Left$(Message, (InStr(1, Message, MSG_UNBAN, vbBinaryCompare) - 1)), vbTextCompare) = 0) Then
' " was unbanned by " must follow User (first word)
Dim rembanpos As Integer

If (Len(User) > 0) Then
g_Channel.BanCount = (g_Channel.BanCount - 1)

Do
rembanpos = g_Channel.IsOnBanList(User)

If (rembanpos > 0) Then
g_Channel.Banlist.Remove rembanpos
End If
Loop While (rembanpos <> 0)
End If
Else
frmChat.AddQ "/join " & g_Channel.Name
End If
End If

If (InStr(1, Message, " has been unsquelched", vbTextCompare) > 0) Then
If ((g_Channel.IsSilent) And (frmChat.mnuDisableVoidView.Checked = False)) Then
frmChat.lvChannel.ListItems.Clear
End If

' backup channel
If (StrComp(Right$(Message, Len(MSG_RECVKICK)), MSG_RECVKICK, vbTextCompare) = 0) Then
If (BotVars.UseBackupChan) Then
If (Len(BotVars.BackupChan) > 0) Then
frmChat.AddQ "/join " & BotVars.BackupChan
End If
Else
frmChat.AddQ "/join " & g_Channel.Name
End If
End If

If (InStr(1, Message, "designated heir", vbTextCompare) <> 0) Then
g_Channel.OperatorHeir = Left$(Message, Len(Message) - 29)

' silent channel unsquelch
If (StrComp(Right$(Message, Len(MSG_UNSQUELCH)), MSG_UNSQUELCH, vbTextCompare) = 0) Then
If ((g_Channel.IsSilent) And (frmChat.mnuDisableVoidView.Checked = False)) Then
frmChat.lvChannel.ListItems.Clear
End If
End If


temp = "Your friends are:"

If (StrComp(Left$(Message, Len(temp)), temp) = 0) Then

' store designated
If (StrComp(Right$(Message, Len(MSG_DESIGNATED)), MSG_DESIGNATED, vbTextCompare) = 0) Then
g_Channel.OperatorHeir = Left$(Message, Len(Message) - Len(MSG_DESIGNATED))
End If

' friends hiding
If (StrComp(Message, MSG_FRIENDS, vbTextCompare) = 0) Then
If (Not (BotVars.ShowOfflineFriends)) Then
Message = Message & _
" ÿci(StealthBot is hiding your offline friends)"
Message = Message & MSG_FRIENDS_SB_HIDING
End If
End If

End If ' message contains a space

If (StrComp(Right$(Message, 9), ", offline", vbTextCompare) = 0) Then
If (BotVars.ShowOfflineFriends) Then
frmChat.AddChat RTBColors.ServerInfoText, Message
End If
Else
If (Not (bHide)) Then
frmChat.AddChat RTBColors.ServerInfoText, Message
If (StrComp(Right$(Message, Len(MSG_FRIEND_OFFLINE)), MSG_FRIEND_OFFLINE, vbTextCompare) = 0) Then
If (BotVars.ShowOfflineFriends) Then
frmChat.AddChat RTBColors.ServerInfoText, Message
End If
Else
If (Not (bHide)) Then
frmChat.AddChat RTBColors.ServerInfoText, Message
End If
End If
End If

End If ' message contains a space

RunInAll "Event_ServerInfo", Message
Exit Sub

0 comments on commit 20fddbe

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