Skip to content
Permalink
Browse files

Removed extra parameters from internal chat events

UserJoins, UserInChannel, and FlagsUpdate now all have the same
signature: (Username, Flags, Message, Ping). The signature for the
scripting events has not been changed.

The Level parameter for scripting events is now correctly set (it was
previously always set to 0).

Also eliminated a few redundant statstring parsings. A user's statstring
is now only parsed once per event.
  • Loading branch information...
Davnit committed Apr 30, 2016
1 parent db9d83e commit 235ccd21d82e30afc4678b7549e382a754467fef
Showing with 39 additions and 78 deletions.
  1. +3 −6 trunk/clsUserObj.cls
  2. +6 −24 trunk/modBNCS.bas
  3. +30 −48 trunk/modEvents.bas
@@ -224,12 +224,10 @@ Public Sub DisplayQueue()

Select Case (CurrentEvent.EventID)
Case ID_USER
Call Event_UserInChannel(Name, CurrentEvent.Flags, CurrentEvent.Statstring, CurrentEvent.Ping, _
CurrentEvent.GameID, CurrentEvent.Clan, CurrentEvent.Statstring, CurrentEvent.IconCode, j)
Call Event_UserInChannel(Name, CurrentEvent.Flags, CurrentEvent.Statstring, CurrentEvent.Ping, j)

Case ID_JOIN
Call Event_UserJoins(Name, CurrentEvent.Flags, CurrentEvent.Statstring, CurrentEvent.Ping, _
CurrentEvent.GameID, CurrentEvent.Clan, CurrentEvent.Statstring, CurrentEvent.IconCode, j)
Call Event_UserJoins(Name, CurrentEvent.Flags, CurrentEvent.Statstring, CurrentEvent.Ping, j)

Case ID_TALK
Call Event_UserTalk(Name, CurrentEvent.Flags, CurrentEvent.Message, CurrentEvent.Ping, j)
@@ -238,8 +236,7 @@ Public Sub DisplayQueue()
Call Event_UserEmote(Name, CurrentEvent.Flags, CurrentEvent.Message, j)

Case ID_USERFLAGS
Call Event_FlagsUpdate(Name, CurrentEvent.Statstring, CurrentEvent.Flags, CurrentEvent.Ping, _
CurrentEvent.GameID, j)
Call Event_FlagsUpdate(Name, CurrentEvent.Flags, CurrentEvent.Statstring, CurrentEvent.Ping, j)
End Select
Next j

@@ -524,41 +524,23 @@ On Error GoTo ERROR_HANDLER:
EventID = pBuff.GetDWORD
lFlags = pBuff.GetDWORD
lPing = pBuff.GetDWORD
pBuff.GetDWORD 'IP Address
pBuff.GetDWORD 'Account Number
pBuff.GetDWORD 'Reg Auth
pBuff.GetDWORD 'IP Address
pBuff.GetDWORD 'Account Number
pBuff.GetDWORD 'Reg Auth
sUsername = pBuff.GetString
sText = pBuff.GetString


If (LenB(sText) > 0) Then
Select Case EventID
Case ID_JOIN, ID_USER, ID_USERFLAGS:
' Use the statstring parser to determine some properties.
Dim cUserStats As New clsUserStats
With cUserStats
.Statstring = sText
sProduct = .Game
sParsed = .ToString
sClanTag = .Clan
End With
Set cUserStats = Nothing
End Select
End If

If sProduct = PRODUCT_WAR3 Or sProduct = PRODUCT_W3XP Then
If Len(sText) > 4 Then sW3Icon = StrReverse(Mid$(sText, 6, 4))
End If

Select Case EventID
Case ID_JOIN: Call Event_UserJoins(sUsername, lFlags, sParsed, lPing, sProduct, sClanTag, sText, sW3Icon)
Case ID_JOIN: Call Event_UserJoins(sUsername, lFlags, sText, lPing)
Case ID_LEAVE: Call Event_UserLeaves(sUsername, lFlags)
Case ID_USER: Call Event_UserInChannel(sUsername, lFlags, sParsed, lPing, sProduct, sClanTag, sText, sW3Icon)
Case ID_USER: Call Event_UserInChannel(sUsername, lFlags, sText, lPing)
Case ID_WHISPER: Call Event_WhisperFromUser(sUsername, lFlags, sText, lPing)
Case ID_TALK: Call Event_UserTalk(sUsername, lFlags, sText, lPing)
Case ID_BROADCAST: Call Event_ServerInfo(sUsername, StringFormat("BROADCAST from {0}: {1}", sUsername, sText))
Case ID_CHANNEL: Call Event_JoinedChannel(sText, lFlags)
Case ID_USERFLAGS: Call Event_FlagsUpdate(sUsername, sText, lFlags, lPing, sProduct)
Case ID_USERFLAGS: Call Event_FlagsUpdate(sUsername, lFlags, sText, lPing)
Case ID_WHISPERSENT: Call Event_WhisperToUser(sUsername, lFlags, sText, lPing)
Case ID_CHANNELFULL, ID_CHANNELDOESNOTEXIST, ID_CHANNELRESTRICTED: Call Event_ChannelJoinError(EventID, sText)
Case ID_INFO: Call Event_ServerInfo(sUsername, sText)
@@ -18,8 +18,7 @@ End Type
Private m_arrMsgEvents() As MSGFILTER
Private m_eventCount As Integer

Public Sub Event_FlagsUpdate(ByVal Username As String, ByVal Message As String, ByVal Flags As Long, _
ByVal Ping As Long, ByVal Product As String, Optional QueuedEventID As Integer = 0)
Public Sub Event_FlagsUpdate(ByVal Username As String, ByVal Flags As Long, ByVal Message As String, ByVal Ping As Long, Optional QueuedEventID As Integer = 0)

On Error GoTo ERROR_HANDLER

@@ -56,7 +55,7 @@ Public Sub Event_FlagsUpdate(ByVal Username As String, ByVal Message As String,
.EventID = ID_USERFLAGS
.Flags = Flags
.Ping = Ping
.GameID = Product
.GameID = UserObj.Game
End With

UserObj.Queue.Add UserEvent
@@ -115,8 +114,8 @@ Public Sub Event_FlagsUpdate(ByVal Username As String, ByVal Message As String,

' we aren't in a silent channel, are we?
If (g_Channel.IsSilent) Then
AddName Username, UserObj.Name, Product, Flags, Ping, UserObj.Stats.IconCode, _
Clan
AddName Username, UserObj.Name, UserObj.Game, Flags, Ping, UserObj.Stats.IconCode, _
UserObj.Clan
Else
If ((UserObj.Queue.Count = 0) Or (QueuedEventID > 0)) Then
If (Flags <> PreviousFlags) Then
@@ -146,8 +145,8 @@ Public Sub Event_FlagsUpdate(ByVal Username As String, ByVal Message As String,
pos = 1
End If

AddName Username, UserObj.Name, Product, Flags, Ping, UserObj.Stats.IconCode, _
Clan, pos
AddName Username, UserObj.Name, UserObj.Game, Flags, Ping, UserObj.Stats.IconCode, _
UserObj.Clan, pos

' default to display this event
Displayed = False
@@ -1113,11 +1112,7 @@ ERROR_HANDLER:
StringFormat("Error: #{0}: {1} in {2}.Event_UserEmote()", Err.Number, Err.description, OBJECT_NAME))
End Sub

'Ping, Product, Clan, InitStatstring, W3Icon
Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, ByVal Message As String, _
ByVal Ping As Long, ByVal Product As String, ByVal sClan As String, ByVal originalstatstring As String, _
Optional ByVal w3icon As String, Optional QueuedEventID As Integer = 0)

Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, ByVal Statstring As String, ByVal Ping As Long, Optional QueuedEventID As Integer = 0)
On Error GoTo ERROR_HANDLER

Dim UserEvent As clsUserEventObj
@@ -1160,9 +1155,9 @@ Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, By
.EventID = ID_USER
.Flags = Flags
.Ping = Ping
.GameID = Product
.Clan = sClan
.Statstring = originalstatstring
.GameID = UserObj.Game
.Clan = UserObj.Clan
.Statstring = Statstring
End With

UserObj.Queue.Add UserEvent
@@ -1179,7 +1174,7 @@ Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, By
.Flags = Flags
.Ping = Ping
.JoinTime = g_Channel.JoinTime
.Statstring = originalstatstring
.Statstring = Statstring
End With

If (UserIndex = 0) Then
@@ -1192,7 +1187,7 @@ Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, By
If (StatUpdate = False) Then
'frmChat.AddChat vbRed, UserObj.Stats.IconCode

AddName Username, UserObj.Name, Product, Flags, Ping, UserObj.Stats.IconCode, sClan
AddName Username, UserObj.Name, UserObj.Game, Flags, Ping, UserObj.Stats.IconCode, UserObj.Clan

frmChat.lblCurrentChannel.Caption = frmChat.GetChannelString()

@@ -1284,7 +1279,7 @@ Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, By
End If

If (found.ListSubItems.Count > 0) Then
found.ListSubItems(1).Text = sClan
found.ListSubItems(1).Text = UserObj.Clan
End If

Set found = Nothing
@@ -1300,12 +1295,12 @@ Public Sub Event_UserInChannel(ByVal Username As String, ByVal Flags As Long, By
On Error Resume Next

RunInAll "Event_UserInChannel", Username, Flags, UserObj.Stats.ToString, Ping, _
Product, StatUpdate
UserObj.Game, StatUpdate
End If

If (MDebug("statstrings")) Then
frmChat.AddChat RTBColors.InformationText, "Username: " & Username & ", Statstring: " & _
originalstatstring
Statstring
End If

Exit Sub
@@ -1314,9 +1309,7 @@ ERROR_HANDLER:
StringFormat("Error: #{0}: {1} in {2}.Event_UserInChannel()", Err.Number, Err.description, OBJECT_NAME))
End Sub

Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal Message As String, _
ByVal Ping As Long, ByVal Product As String, ByVal sClan As String, ByVal originalstatstring As String, _
ByVal w3icon As String, Optional QueuedEventID As Integer = 0)
Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal Statstring As String, ByVal Ping As Long, Optional QueuedEventID As Integer = 0)

On Error GoTo ERROR_HANDLER

@@ -1334,7 +1327,7 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal
Dim UserIndex As Integer
Dim BanningUser As Boolean
Dim pStats As String
Dim isbanned As Boolean
Dim IsBanned As Boolean
Dim AcqFlags As Long
Dim ToDisplay As Boolean

@@ -1362,7 +1355,7 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal
.Flags = Flags
.Ping = Ping
.JoinTime = UtcNow
.Statstring = originalstatstring
.Statstring = Statstring
End With

If (BotVars.ChatDelay > 0) Then
@@ -1372,10 +1365,10 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal
.EventID = ID_JOIN
.Flags = Flags
.Ping = Ping
.GameID = Product
.Statstring = originalstatstring
.Clan = sClan
.IconCode = w3icon
.GameID = UserObj.Game
.Statstring = Statstring
.Clan = UserObj.Clan
.IconCode = UserObj.Stats.Icon
End With

UserObj.Queue.Add UserEvent
@@ -1405,14 +1398,7 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal

' if we have join/leaves on
If (JoinMessagesOff = False) Then
Dim UserStats As clsUserStats

' create user stats object
Set UserStats = New clsUserStats

' store o.s.s. in users stats object
UserStats.Statstring = originalstatstring

' does this event have events delayed after it?
If QueuedEventID > 0 And UserObj.Queue.Count > 0 Then

@@ -1441,12 +1427,10 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal

' is stats different / provided?
If LenB(UserEvent.Statstring) > 0 Then
If StrComp(UserEvent.Statstring, originalstatstring) Then
' create new stats object over other stats object
Set UserStats = New clsUserStats
If StrComp(UserEvent.Statstring, UserObj.Statstring) Then

' store stats update stats in object used in userjoins message generation
UserStats.Statstring = UserEvent.Statstring
UserObj.Statstring = UserEvent.Statstring
End If
End If

@@ -1488,16 +1472,14 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal
frmChat.AddChat RTBColors.JoinText, "-- ", _
UserColor, Username, _
RTBColors.JoinUsername, " [" & Ping & "ms]", _
RTBColors.JoinText, " has joined the channel using " & UserStats.ToString, _
RTBColors.JoinText, " has joined the channel using " & UserObj.Stats.ToString, _
RTBColors.JoinUsername, FDesc, _
RTBColors.JoinText, "."
End If
' dispose user stats instance
Set UserStats = Nothing
End If

' add to user list
AddName Username, UserObj.Name, Product, Flags, Ping, UserObj.Stats.IconCode, sClan
AddName Username, UserObj.Name, UserObj.Game, Flags, Ping, UserObj.Stats.IconCode, UserObj.Clan

' update caption
frmChat.lblCurrentChannel.Caption = frmChat.GetChannelString
@@ -1514,12 +1496,12 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal
Call DoLastSeen(Username)

' check is banned
isbanned = (UserObj.PendingBan)
IsBanned = (UserObj.PendingBan)

'frmChat.AddChat vbRed, IsBanned

' if not banned...
If (isbanned = False) Then
If (IsBanned = False) Then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Greet message
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
@@ -1551,7 +1533,7 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal

' print their statstring, if desired
If (MDebug("statstrings")) Then
frmChat.AddChat RTBColors.ErrorMessageText, originalstatstring
frmChat.AddChat RTBColors.ErrorMessageText, Statstring
End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
@@ -1563,7 +1545,7 @@ Public Sub Event_UserJoins(ByVal Username As String, ByVal Flags As Long, ByVal
'frmChat.AddChat vbRed, frmChat.SControl.Error.Number

RunInAll "Event_UserJoins", Username, Flags, UserObj.Stats.ToString, Ping, _
Product, 0, originalstatstring, isbanned
UserObj.Game, UserObj.Stats.Level, Statstring, IsBanned
End If

Exit Sub

0 comments on commit 235ccd2

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