Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public ServerDatabase As ADODB.Connection
- Private RS As ADODB.Recordset
- Private Const DB_DRIVER As String = "MySQL ODBC 5.3 ANSI Driver"
- Private Const DB_HOST As String = "localhost"
- Private Const DB_NOMBRE As String = "mitosao"
- Private Const DB_PASSWD As String = "FsQ54SdQHK8yhgG47f8$#25&756#$234#$df"
- Private Const DB_USER As String = "argentum"
- Public Sub LoadDatabase()
- '*************************************************
- ' • Cargamos la base de datos
- '*************************************************
- On Error GoTo ErrHandler
- Set ServerDatabase = New ADODB.Connection
- With ServerDatabase
- .ConnectionString = "DRIVER={" & DB_DRIVER & "};" & "SERVER=" & DB_HOST & ";" & _
- " DATABASE=" & DB_NOMBRE & ";" & "UID=" & DB_USER & "; PWD=" & DB_PASSWD & "; OPTION=3"
- .CursorLocation = adUseClient
- .Open
- End With
- Exit Sub
- ErrHandler:
- MsgBox "Error en LoadDatabase: " & Err.description & " String: " & ServerDatabase.ConnectionString
- End
- End Sub
- Public Sub CloseDatabase()
- '*************************************************
- ' • Cerramos la base de datos
- '*************************************************
- On Error GoTo ErrHandler
- ServerDatabase.Close
- Set ServerDatabase = Nothing
- Exit Sub
- ErrHandler:
- MsgBox "Error en CloseDataBase: " & Err.description & " String: " & ServerDatabase.ConnectionString
- End
- End Sub
- Private Sub SaveUserFlags(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save of user flags
- '*************************************************
- Dim str As String
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Flags` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Flags` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Flags` SET PjIndex=" & .PjIndex
- str = str & ",Muerto=" & .flags.Muerto
- str = str & ",Escondido=" & .flags.Escondido
- str = str & ",Hambre=" & .flags.Hambre
- str = str & ",Sed=" & .flags.Sed
- str = str & ",Desnudo=" & .flags.Desnudo
- str = str & ",Ban=" & .flags.Ban
- str = str & ",Navegando=" & .flags.Navegando
- str = str & ",Envenenado=" & .flags.Envenenado
- str = str & ",Paralizado=" & .flags.Paralizado
- str = str & ",LastMap=" & .flags.lastMap
- str = str & ",Consejo=" & .flags.Consejo
- str = str & " WHERE PjIndex=" & .PjIndex
- End With
- End Sub
- Private Sub SaveUserInit(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save of user init
- '*************************************************
- Dim str As String
- Dim TempDate As Date
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Init` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Init` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Init` SET PjIndex=" & .PjIndex & ",Nombre='" & UCase$(.Name) & "'"
- str = str & ",Email='" & .Email & "'"
- str = str & ",Password='" & .Password & "'"
- str = str & ",AccountIndex=" & .AccountIndex
- str = str & ",GuildIndex=" & .GuildIndex
- str = str & ",Genero=" & .Genero
- str = str & ",Raza=" & .Raza
- str = str & ",Clase=" & .Clase
- str = str & ",Hogar=" & .Hogar
- str = str & ",Desc=" & .desc
- str = str & ",Heading=" & .Char.heading
- str = str & ",Head=" & .OrigChar.Head
- If .flags.Muerto = 0 Then
- If .Char.body <> 0 Then
- str = str & ",Body=" & .Char.body
- End If
- End If
- str = str & ",Arma=" & .Char.WeaponAnim
- str = str & ",Escudo=" & .Char.ShieldAnim
- str = str & ",Casco=" & .Char.CascoAnim
- #If ConUpTime Then
- TempDate = Now - .LogOnTime
- .LogOnTime = Now
- .UpTime = .UpTime + (Abs(Day(TempDate) - 30) * 24 * 3600) + Hour(TempDate) * 3600 + Minute(TempDate) * 60 + Second(TempDate)
- .UpTime = .UpTime
- str = str & ",UpTime='" & .UpTime & "'"
- #End If
- str = str & ",LastIp=" & .ip
- str = str & ",Position='" & .Pos.Map & "-" & .Pos.X & "-" & .Pos.Y & "'"
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserCounters(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save of user counters
- '*************************************************
- Dim str As String
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Counters` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Counters` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Counters` SET PjIndex=" & .PjIndex
- str = str & ",Pena=" & .Counters.Pena
- str = str & ",SkillsAsignados=" & .Counters.AsignedSkills
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserFaction(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save of user faction
- '*************************************************
- Dim str As String
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Facciones` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Facciones` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Facciones` SET PjIndex=" & .PjIndex
- str = str & ",EjercitoReal=" & .Faccion.ArmadaReal
- str = str & ",EjercitoCaos=" & .Faccion.FuerzasCaos
- str = str & ",CiudMatados=" & .Faccion.CiudadanosMatados
- str = str & ",CrimMatados=" & .Faccion.CriminalesMatados
- str = str & ",rArCaos=" & .Faccion.RecibioArmaduraCaos
- str = str & ",rArReal=" & .Faccion.RecibioArmaduraReal
- str = str & ",rExCaos=" & .Faccion.RecibioExpInicialCaos
- str = str & ",rExReal=" & .Faccion.RecibioExpInicialReal
- str = str & ",recCaos=" & .Faccion.RecompensasCaos
- str = str & ",recReal=" & .Faccion.RecompensasReal
- str = str & ",Reenlistadas=" & .Faccion.Reenlistadas
- str = str & ",NivelIngreso=" & .Faccion.NivelIngreso
- str = str & ",FechaIngreso=" & .Faccion.FechaIngreso
- str = str & ",MatadosIngreso=" & .Faccion.MatadosIngreso
- str = str & ",NextRecompensa=" & .Faccion.NextRecompensa
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserAtributtes(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user atributtes
- '*************************************************
- Dim str As String, LoopC As Long
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Skills` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Skills` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Atributos` SET PjIndex=" & .PjIndex
- If Not .flags.TomoPocion Then
- For LoopC = 1 To UBound(.Stats.UserAtributos)
- str = str & ",AT" & i & "=" & .Stats.UserAtributos(LoopC)
- Next LoopC
- Else
- For LoopC = 1 To UBound(.Stats.UserAtributos)
- str = str & ",AT" & i & "=" & .Stats.UserAtributosBackUP(LoopC)
- Next LoopC
- End If
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserSkills(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user skills
- '*************************************************
- Dim str As String, LoopC As Long
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Skills` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Skills` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Skills` SET PjIndex=" & .PjIndex
- For LoopC = 1 To UBound(.Stats.UserSkills)
- str = str & ",Sk" & LoopC & "=" & .Stats.UserSkills(LoopC)
- str = str & ",SkExp" & LoopC & "=" & .Stats.EluSkills(LoopC)
- str = str & ",SkElu" & LoopC & "=" & .Stats.ExpSkills(LoopC)
- Next LoopC
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserStats(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user stats
- '*************************************************
- Dim str As String
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Stats` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Stats` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Stats` SET PjIndex=" & .PjIndex
- str = str & ",Gld=" & .Stats.GLD
- str = str & ",MinHp=" & .Stats.MinHp & ",MaxHp=" & .Stats.MaxHp
- str = str & ",MinSta=" & .Stats.MinSta & ",MaxSta=" & .Stats.MaxSta
- str = str & ",MinMan=" & .Stats.MinMAN & ",MaxMan=" & .Stats.MaxMAN
- str = str & ",MinHit=" & .Stats.MinHIT & ",MaxHit=" & .Stats.MaxHIT
- str = str & ",MinAgu=" & .Stats.MinAGU & ",MaxAgu=" & .Stats.MaxAGU
- str = str & ",MinHam=" & .Stats.MinHam & ",MaxHam=" & .Stats.MaxHam
- str = str & ",SkillPtsLibres=" & .Stats.SkillPts
- str = str & ",Exp=" & .Stats.Exp
- str = str & ",Elv=" & .Stats.ELV
- str = str & ",Elu=" & .Stats.ELU
- str = str & ",UserMuertes=" & .Stats.UsuariosMatados
- str = str & ",NpcsMuertes=" & .Stats.NPCsMuertos
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserInventory(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user Inventory
- '*************************************************
- Dim str As String, LoopC As Long
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Inventory` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Inventory` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Inventory` SET PjIndex=" & .PjIndex
- str = str & ",CantidadItems=" & .Invent.NroItems
- For LoopC = 1 To MAX_INVENTORY_SLOTS
- str = str & ",Obj" & LoopC & "=" & .Invent.Object(LoopC).ObjIndex & "-" & .Invent.Object(LoopC).Amount & "-" & .Invent.Object(LoopC).Equipped
- Next LoopC
- str = str & "WeaponEqpSlot=" & .Invent.WeaponEqpSlot
- str = str & "ArmourEqpSlot=" & .Invent.ArmourEqpSlot
- str = str & "CascoEqpSlot=" & .Invent.CascoEqpSlot
- str = str & "EscudoEqpSlot=" & .Invent.EscudoEqpSlot
- str = str & "BarcoSlot=" & .Invent.BarcoSlot
- str = str & "MunicionSlot=" & .Invent.MunicionEqpSlot
- str = str & "MochilaSlot=" & .Invent.MochilaEqpSlot
- str = str & "AnilloSlot=" & .Invent.AnilloEqpSlot
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserReputation(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user Reputation
- '*************************************************
- Dim str As String, P As Long
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Reputacion` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Reputacion` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Reputacion` SET PjIndex=" & .PjIndex
- str = str & ",Asesino=" & .Reputacion.AsesinoRep
- str = str & ",Bandido=" & .Reputacion.BandidoRep
- str = str & ",Burguesia=" & .Reputacion.BurguesRep
- str = str & ",Ladrones=" & .Reputacion.LadronesRep
- str = str & ",Nobles=" & .Reputacion.NobleRep
- str = str & ",Plebe=" & .Reputacion.PlebeRep
- P = (-.Reputacion.AsesinoRep) + _
- (-.Reputacion.BandidoRep) + _
- .Reputacion.BurguesRep + _
- (-.Reputacion.LadronesRep) + _
- .Reputacion.NobleRep + _
- .Reputacion.PlebeRep
- P = P / 6
- str = str & ",Promedio=" & P
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserSpells(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user Spells
- '*************************************************
- Dim str As String, LoopC As Long, SpellIndex As Integer
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Spells` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Spells` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Spells` SET PjIndex=" & .PjIndex
- For LoopC = 1 To MAXUSERHECHIZOS
- str = str & ",Spell" & LoopC & "=" & .Stats.UserHechizos(LoopC)
- Next LoopC
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub SaveUserPet(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save user Pet
- '*************************************************
- Dim str As String, LoopC As Long, NroMascotas As Long, cad As String
- With UserList(UserIndex)
- DatabaseExecute ServerDatabase, "SELECT * FROM `Pet` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Pet` (PjIndex) VALUES (" & .PjIndex & ")"
- str = "UPDATE `Pet` SET PjIndex=" & .PjIndex
- NroMascotas = .NroMascotas
- For LoopC = 1 To MAXMASCOTAS
- If .MascotasIndex(LoopC) > 0 Then
- If Npclist(.MascotasIndex(LoopC)).Contadores.TiempoExistencia = 0 Then
- cad = .MascotasType(LoopC)
- Else
- cad = "0"
- NroMascotas = NroMascotas - 1
- End If
- str = str & ",PET" & LoopC & "=" & cad
- Else
- cad = .MascotasType(LoopC)
- str = str & ",PET" & LoopC & "=" & cad
- End If
- Next LoopC
- str = str & ",NroMascotas=" & NroMascotas
- str = str & " WHERE PjIndex=" & .PjIndex
- Call ServerDatabase.Execute(str)
- End With
- End Sub
- Private Sub DatabaseExecute(ByVal db As ADODB.Connection, ByVal strSelect As String, ByVal strInsert As String)
- '*************************************************
- ' • Database Execute
- '*************************************************
- Set RS = db.Execute(strSelect)
- If RS.BOF Or RS.EOF Then
- db.Execute strInsert
- End If
- Set RS = Nothing
- End Sub
- Public Sub SaveDatabaseUser(ByVal UserIndex As Integer)
- '*************************************************
- ' • Save to the user
- '*************************************************
- On Error GoTo ErrHandler
- Dim LoopC As Integer
- With UserList(UserIndex)
- ' • Personaje nulo
- If (.Clase = 0) Or (.Stats.ELV = 0) Or (Len(.Name) = 0) Then
- Call LogCriticEvent("Estoy intentantdo guardar un usuario nulo de nombre: " & .Name)
- Exit Sub
- End If
- ' • Personaje mimetizado vuelve normal
- If .flags.Mimetizado = 1 Then
- .Char.body = .CharMimetizado.body
- .Char.Head = .CharMimetizado.Head
- .Char.CascoAnim = .CharMimetizado.CascoAnim
- .Char.ShieldAnim = .CharMimetizado.ShieldAnim
- .Char.WeaponAnim = .CharMimetizado.WeaponAnim
- .Counters.Mimetismo = 0
- .flags.Mimetizado = 0
- .flags.Ignorado = False
- End If
- Set RS = New ADODB.Recordset
- Set RS = ServerDatabase.Execute("SELECT * FROM `Init` WHERE Nombre='" & UCase$(.Name) & "'")
- If RS.BOF Or RS.EOF Then
- ServerDatabase.Execute "INSERT INTO `Init` (NOMBRE) VALUES ('" & UCase$(.Name) & "')"
- Set RS = Nothing
- Set RS = ServerDatabase.Execute("SELECT * FROM `Init` WHERE Nombre='" & UCase$(.Name) & "'")
- .PjIndex = RS!PjIndex
- Else
- Set RS = ServerDatabase.Execute("SELECT * FROM `Init` WHERE PjIndex=" & .PjIndex)
- .PjIndex = RS!PjIndex
- End If
- Set RS = Nothing
- SaveUserFlags UserIndex
- SaveUserInit UserIndex
- SaveUserCounters UserIndex
- SaveUserFaction UserIndex
- SaveUserAtributtes UserIndex
- SaveUserSkills UserIndex
- SaveUserStats UserIndex
- SaveUserInventory UserIndex
- SaveUserReputation UserIndex
- SaveUserPet UserIndex
- ' • Comento lo del banco ya que va a ser vía account web
- '*******************************************************************************************
- 'Call Manager.ChangeValue("BancoInventory", "CantidadItems", val(.BancoInvent.NroItems))
- 'For loopd = 1 To MAX_BANCOINVENTORY_SLOTS
- 'Call Manager.ChangeValue("BancoInventory", "Obj" & loopd, .BancoInvent.Object(loopd).ObjIndex & "-" & .BancoInvent.Object(loopd).Amount)
- 'Next loopd
- '*******************************************************************************************
- 'Guarda los mensajes privados del usuario.
- 'Call GuardarMensajes(UserIndex, Manager)
- 'Devuelve el head de muerto
- If .flags.Muerto = 1 Then
- .Char.Head = iCabezaMuerto
- End If
- End With
- Exit Sub
- ErrHandler:
- Call LogError("Error en SaveUser")
- Set RS = Nothing
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement