Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user index release on kick #391

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Codigo/Modulo_UsUaRiOs.bas
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ End Sub

Public Function ReleaseUser(ByVal UserIndex As Integer) As Boolean
On Error GoTo ErrHandler
If UserList(UserIndex).ConnIDValida Or _
UserList(UserIndex).flags.UserLogged Or _
UserList(UserIndex).flags.IsSlotFree Then
If UserList(UserIndex).flags.IsSlotFree Then
ReleaseUser = False
Exit Function
End If
Expand All @@ -70,13 +68,14 @@ End Function
Public Function GetNextAvailableUserSlot() As Integer
On Error GoTo ErrHandler
If (AvailableUserSlot.currentIndex = 0) Then
GetNextAvailableUserSlot = 0
GetNextAvailableUserSlot = -1
Return
End If
GetNextAvailableUserSlot = AvailableUserSlot.IndexInfo(AvailableUserSlot.currentIndex)
AvailableUserSlot.currentIndex = AvailableUserSlot.currentIndex - 1
If Not UserList(GetNextAvailableUserSlot).flags.IsSlotFree Then
Call TraceError(Err.Number, "Trying to active the same user slot twice", "UserMod.GetNextAvailableUserSlot", Erl)
GetNextAvailableUserSlot = -1
End If
UserList(GetNextAvailableUserSlot).flags.IsSlotFree = False
Exit Function
Expand Down Expand Up @@ -225,8 +224,8 @@ On Error GoTo Check_ConnectUser_Err
End If

If EsGM(UserIndex) Then
Call SendData(SendTarget.ToAdmins, 0, PrepareMessageConsoleMsg("Servidor » " & Name & " se conecto al juego.", e_FontTypeNames.FONTTYPE_INFOBOLD))
Call LogGM(Name, "Se conectó con IP: " & .IP)
Call SendData(SendTarget.ToAdmins, 0, PrepareMessageConsoleMsg("Servidor » " & name & " se conecto al juego.", e_FontTypeNames.FONTTYPE_INFOBOLD))
Call LogGM(name, "Se conectó con IP: " & .IP)
End If
End With

Expand Down Expand Up @@ -766,10 +765,10 @@ On Error GoTo Complete_ConnectUser_Err
1120 Call WriteLoggedMessage(UserIndex, newUser)

1125 If .Stats.ELV = 1 Then
1130 Call WriteConsoleMsg(UserIndex, "¡Bienvenido a las tierras de AO20! ¡" & .Name & " que tengas buen viaje y mucha suerte!", e_FontTypeNames.FONTTYPE_GUILD)
1130 Call WriteConsoleMsg(UserIndex, "¡Bienvenido a las tierras de AO20! ¡" & .name & " que tengas buen viaje y mucha suerte!", e_FontTypeNames.FONTTYPE_GUILD)

1135 ElseIf .Stats.ELV < 14 Then
1140 Call WriteConsoleMsg(UserIndex, "¡Bienvenido de nuevo " & .Name & "! Actualmente estas en el nivel " & .Stats.ELV & " en " & get_map_name(.Pos.Map) & ", ¡buen viaje y mucha suerte!", e_FontTypeNames.FONTTYPE_GUILD)
1140 Call WriteConsoleMsg(UserIndex, "¡Bienvenido de nuevo " & .name & "! Actualmente estas en el nivel " & .Stats.ELV & " en " & get_map_name(.pos.Map) & ", ¡buen viaje y mucha suerte!", e_FontTypeNames.FONTTYPE_GUILD)

End If

Expand Down Expand Up @@ -3433,10 +3432,10 @@ On Error GoTo DoDamageOrHeal_Err
DamageStr = PonerPuntos(Math.Abs(Amount))
If SourceType = eUser Then
If UserList(SourceIndex).ChatCombate = 1 And DoDamageText > 0 Then
Call WriteLocaleMsg(SourceIndex, DoDamageText, e_FontTypeNames.FONTTYPE_FIGHT, UserList(UserIndex).Name & "¬" & DamageStr)
Call WriteLocaleMsg(SourceIndex, DoDamageText, e_FontTypeNames.FONTTYPE_FIGHT, UserList(UserIndex).name & "¬" & DamageStr)
End If
If UserList(UserIndex).ChatCombate = 1 And GotDamageText > 0 Then
Call WriteLocaleMsg(UserIndex, GotDamageText, e_FontTypeNames.FONTTYPE_FIGHT, UserList(SourceIndex).Name & "¬" & DamageStr)
Call WriteLocaleMsg(UserIndex, GotDamageText, e_FontTypeNames.FONTTYPE_FIGHT, UserList(SourceIndex).name & "¬" & DamageStr)
End If
End If
amount = EffectsOverTime.TargetApplyDamageReduction(UserList(UserIndex).EffectOverTime, amount, SourceIndex, SourceType, DamageSourceType)
Expand Down
2 changes: 2 additions & 0 deletions Codigo/Protocol_GmCommands.bas
Original file line number Diff line number Diff line change
Expand Up @@ -4728,6 +4728,8 @@ On Error GoTo HandleDebugRequest_Err:
ElseIf debugType = 1 Then
ReDim Args(1) As String
Args(0) = Reader.ReadString8()
ElseIf debugType = 2 Then
ReDim Args(0) As String
Else
Exit Sub
End If
Expand Down
3 changes: 3 additions & 0 deletions Codigo/Protocol_Writes.bas
Original file line number Diff line number Diff line change
Expand Up @@ -5778,6 +5778,9 @@ Public Sub WriteDebugLogResponse(ByVal UserIndex As Integer, ByVal debugType, By
timeSinceLastReset = GetTickCount() - .Counters.TimeLastReset
Call Writer.WriteString8("validConnection: " & .ConnIDValida & " connectionID: " & .ConnID & " UserIndex: " & tIndex & " charNmae" & .name & " UserLogged state: " & .flags.UserLogged & ", time since last message: " & timeSinceLastReset & " timeout setting: " & DisconnectTimeout)
End With
ElseIf debugType = 2 Then
Call Writer.WriteInt16(1)
Call Writer.WriteString8("remote DEBUG: avialable user slots: " & GetAvailableUserSlot)
Else
Call Writer.WriteInt16(1)
Call Writer.WriteString8("DEBUG: failed to find user: " & args(0))
Expand Down
5 changes: 1 addition & 4 deletions Codigo/TCP.bas
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,10 @@ Sub CloseSocket(ByVal UserIndex As Integer)

Else
136 Call ResetUserSlot(UserIndex)

End If

140 .ConnIDValida = False
142 Call ReleaseUser(UserIndex)

End With


Expand All @@ -671,7 +670,6 @@ ErrHandler:

144 UserList(UserIndex).ConnIDValida = False
146 Call ResetUserSlot(UserIndex)
Call ReleaseUser(UserIndex)
148 Call TraceError(Err.Number, Err.Description, "TCP.CloseSocket", Erl)


Expand All @@ -686,7 +684,6 @@ Sub CloseSocketSL(ByVal UserIndex As Integer)
102 Call modNetwork.Kick(UserIndex)

106 UserList(UserIndex).ConnIDValida = False
Call ReleaseUser(UserIndex)
End If

Exit Sub
Expand Down
2 changes: 1 addition & 1 deletion Codigo/frmMain.frm
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ Private Sub t_Extraer_Timer()
Call Trabajar(i, UserList(i).Trabajo.TargetSkill)
End If
Next i
Call PerformTimeLimitCheck(PerformanceTimer, "Segundo_Timer", 100)
Call PerformTimeLimitCheck(PerformanceTimer, "t_Extraer_Timer", 100)
End Sub

Private Sub T_UsersOnline_Timer()
Expand Down
14 changes: 10 additions & 4 deletions Codigo/modNetwork.bas
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ On Error GoTo Kick_ErrHandler:
Call AddLogToCircularBuffer("Kick connection: " & Connection)
End If
End If
Dim UserRef As t_UserReference
UserRef = Mapping(Connection)
If IsValidUserRef(UserRef) Then
If Not UserList(UserRef.ArrayIndex).flags.UserLogged Then
Call ReleaseUser(UserRef.ArrayIndex)
End If
End If
If (message <> vbNullString) Then
Dim UserRef As t_UserReference
UserRef = Mapping(Connection)
If UserRef.ArrayIndex > 0 Then
Call Protocol_Writes.WriteErrorMsg(UserRef.ArrayIndex, Message)
If UserList(UserRef.ArrayIndex).flags.UserLogged Then
Expand Down Expand Up @@ -130,7 +135,6 @@ Public Sub close_not_logged_sockets_if_timeout()
Else
.ConnID = 0
.ConnIDValida = False
Call ReleaseUser(i)
Call TraceError(Err.Number, Err.Description, "trying to kick an invalid mapping", Erl)
End If
End If
Expand All @@ -150,6 +154,9 @@ On Error GoTo OnServerConnect_Err:
If Connection <= MaxUsers Then
Dim FreeUser As Long
FreeUser = NextOpenUser()
If FreeUser < 0 Then
Call Kick(Connection, "El server se encuentra lleno en este momento. Disculpe las molestias ocasionadas.")
End If
If UserList(FreeUser).InUse Then
Call LogError("Trying to use an user slot marked as in use! slot: " & FreeUser)
FreeUser = NextOpenUser()
Expand Down Expand Up @@ -201,7 +208,6 @@ On Error GoTo OnServerClose_Err:

132 UserList(UserRef.ArrayIndex).ConnIDValida = False
134 UserList(UserRef.ArrayIndex).ConnID = 0
136 Call ReleaseUser(UserRef.ArrayIndex)
End If
138 Call ClearUserRef(Mapping(Connection))

Expand Down