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

Refactor connections #393

Merged
merged 4 commits into from
Sep 22, 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
2 changes: 1 addition & 1 deletion Codigo/CharacterPersistence.bas
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Public Function LoadCharacterFromDB(ByVal userIndex As Integer) As Boolean
If Not LoadCharacterInventory(UserIndex) Then Exit Function
If Not LoadCharacterBank(UserIndex) Then Exit Function
Call RegisterUserName(.id, .name)
Call Execute("update account set last_ip = ? where id = ?", .IP, .AccountID)
Call Execute("update account set last_ip = ? where id = ?", .ConnectionDetails.IP, .AccountID)
morgolock marked this conversation as resolved.
Show resolved Hide resolved
.Stats.Creditos = 0
Set RS = Query("Select is_active_patron from account where id = ?", .AccountID)
If Not RS Is Nothing Then
Expand Down
17 changes: 9 additions & 8 deletions Codigo/Declares.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2144,10 +2144,6 @@ Public Type t_UserCounters
TimerBarra As Integer
LastResetTick As Long
LastTransferGold As Long
TimeLastReset As Long
PacketCount As Long

OnConnectTimestamp As Long

End Type

Expand Down Expand Up @@ -2289,6 +2285,13 @@ Public Type t_HotkeyEntry
LastKnownSlot As Integer
End Type

Public Type t_ConnectionInfo
IP As String
ConnIDValida As Boolean
ConnID As Long
OnConnectTimestamp As Long
End Type

Public Const HotKeyCount As Integer = 10
'Tipo de los Usuarios
Public Type t_User
Expand Down Expand Up @@ -2330,8 +2333,8 @@ Public Type t_User

Pos As t_WorldPos

ConnIDValida As Boolean
ConnID As Long
ConnectionDetails As t_ConnectionInfo

CurrentInventorySlots As Byte

BancoInvent As t_BancoInventario
Expand Down Expand Up @@ -2359,8 +2362,6 @@ Public Type t_User
LogOnTime As Date
UpTime As Long
#End If

IP As String

'[Alejo]
ComUsu As t_ComercioUsuario
Expand Down
2 changes: 1 addition & 1 deletion Codigo/GameLogic.bas
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ Function IP_Index(ByVal inIP As String) As Integer

104 UserIndex = 1

106 Do Until UserList(UserIndex).IP = inIP
106 Do Until UserList(UserIndex).ConnectionDetails.IP = inIP

108 UserIndex = UserIndex + 1

Expand Down
11 changes: 5 additions & 6 deletions Codigo/General.bas
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Sub Main()

'Resetea las conexiones de los usuarios
258 For LoopC = 1 To MaxUsers
262 UserList(LoopC).ConnIDValida = False
262 UserList(LoopC).ConnectionDetails.ConnIDValida = False
268 Next LoopC

'¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿
Expand Down Expand Up @@ -909,10 +909,9 @@ Sub Restart()
116 ReDim UserList(1 To MaxUsers) As t_User

118 For LoopC = 1 To MaxUsers
122 UserList(LoopC).ConnIDValida = False
Call ReleaseUser(LoopC)
122 UserList(LoopC).ConnectionDetails.ConnIDValida = False
128 Next LoopC

Call InitializeUserIndexHeap(MaxUsers)
130 LastUser = 0
132 NumUsers = 0

Expand Down Expand Up @@ -1981,7 +1980,7 @@ Sub ForzarActualizar()

100 For i = 1 To LastUser

102 If UserList(i).ConnIDValida Then
102 If UserList(i).ConnectionDetails.ConnIDValida Then

104 Call WriteForceUpdate(i)

Expand Down Expand Up @@ -2240,7 +2239,7 @@ Public Sub CerrarServidor()

Dim LoopC As Long
106 For LoopC = 1 To MaxUsers
108 If UserList(LoopC).ConnIDValida Then
108 If UserList(LoopC).ConnectionDetails.ConnIDValida Then
110 Call CloseSocket(LoopC)
End If
Next
Expand Down
16 changes: 8 additions & 8 deletions Codigo/Modulo_UsUaRiOs.bas
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ On Error GoTo Check_ConnectUser_Err

With UserList(userIndex)
If .flags.UserLogged Then
Call LogSecurity("User " & .Name & " trying to log and already an already logged character from IP: " & .IP)
Call LogSecurity("User " & .name & " trying to log and already an already logged character from IP: " & .ConnectionDetails.IP)
Call CloseSocketSL(UserIndex)
Call Cerrar_Usuario(UserIndex)
Exit Function
Expand All @@ -190,7 +190,7 @@ On Error GoTo Check_ConnectUser_Err
If tIndex.ArrayIndex > 0 Then
If Not IsValidUserRef(tIndex) Then
Call CloseSocket(tIndex.ArrayIndex)
ElseIf IsFeatureEnabled("override_same_ip_connection") And .IP = UserList(tIndex.ArrayIndex).IP Then
ElseIf IsFeatureEnabled("override_same_ip_connection") And .ConnectionDetails.IP = UserList(tIndex.ArrayIndex).ConnectionDetails.IP Then
Call WriteShowMessageBox(tIndex.ArrayIndex, "Alguien está ingresando con tu personaje. Si no has sido tú, por favor cambia la contraseña de tu cuenta.")
Call CloseSocket(tIndex.ArrayIndex)
Else
Expand Down Expand Up @@ -228,7 +228,7 @@ On Error GoTo Check_ConnectUser_Err

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 LogGM(name, "Se conectó con IP: " & .ConnectionDetails.IP)
End If
End With

Expand Down Expand Up @@ -1524,7 +1524,7 @@ Function MoveUserChar(ByVal UserIndex As Integer, ByVal nHeading As e_Heading) A
If tempIndex <> UserIndex Then
If UserList(tempIndex).AreasInfo.AreaReciveX And UserList(UserIndex).AreasInfo.AreaPerteneceX Then 'Esta en el area?
If UserList(tempIndex).AreasInfo.AreaReciveY And UserList(UserIndex).AreasInfo.AreaPerteneceY Then
If UserList(tempIndex).ConnIDValida Then
If UserList(tempIndex).ConnectionDetails.ConnIDValida Then
If UserList(tempIndex).flags.Muerto = 0 Or MapInfo(UserList(tempIndex).pos.Map).Seguro = 1 Then
If Distancia(.Pos, UserList(tempIndex).Pos) > DISTANCIA_ENVIO_DATOS And .Counters.timeFx + .Counters.timeChat = 0 Then
If Abs(.Pos.X - UserList(tempIndex).Pos.X) <= RANGO_VISION_X And Abs(.Pos.y - UserList(tempIndex).Pos.y) <= RANGO_VISION_Y Then
Expand Down Expand Up @@ -1679,7 +1679,7 @@ Function NextOpenUser() As Integer
If IsFeatureEnabled("use_old_user_slot_check") Then
100 For LoopC = 1 To MaxUsers + 1
102 If LoopC > MaxUsers Then Exit For
104 If (Not UserList(LoopC).ConnIDValida And UserList(LoopC).flags.UserLogged = False) Then Exit For
104 If (Not UserList(LoopC).ConnectionDetails.ConnIDValida And UserList(LoopC).flags.UserLogged = False) Then Exit For
106 Next LoopC
108 NextOpenUser = LoopC
Else
Expand Down Expand Up @@ -2215,7 +2215,7 @@ Sub UserDie(ByVal UserIndex As Integer)

If UserList(tempIndex).AreasInfo.AreaReciveX And AreaX Then 'Esta en el area?
If UserList(tempIndex).AreasInfo.AreaReciveY And AreaY Then
If UserList(tempIndex).ConnIDValida Then
If UserList(tempIndex).ConnectionDetails.ConnIDValida Then
'Si no soy el que se murió
If UserIndex <> tempIndex And (Not EsGM(UserIndex)) And MapInfo(UserList(UserIndex).Pos.map).Seguro = 0 And UserList(tempIndex).flags.AdminInvisible = 1 Then
If UserList(UserIndex).GuildIndex = 0 Then
Expand Down Expand Up @@ -2665,10 +2665,10 @@ Public Sub CancelExit(ByVal UserIndex As Integer)
'Last Modification: 04/02/08
'
'***************************************************
100 If UserList(UserIndex).Counters.Saliendo And UserList(UserIndex).ConnIDValida Then
100 If UserList(UserIndex).Counters.Saliendo And UserList(UserIndex).ConnectionDetails.ConnIDValida Then

' Is the user still connected?
102 If UserList(UserIndex).ConnIDValida Then
102 If UserList(UserIndex).ConnectionDetails.ConnIDValida Then
104 UserList(UserIndex).Counters.Saliendo = False
106 UserList(UserIndex).Counters.Salir = 0
108 Call WriteConsoleMsg(UserIndex, "/salir cancelado.", e_FontTypeNames.FONTTYPE_WARNING)
Expand Down
Loading