Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public ServerDatabase As ADODB.Connection
  4. Private RS As ADODB.Recordset
  5.  
  6. Private Const DB_DRIVER As String = "MySQL ODBC 5.3 ANSI Driver"
  7. Private Const DB_HOST As String = "localhost"
  8. Private Const DB_NOMBRE As String = "mitosao"
  9. Private Const DB_PASSWD As String = "FsQ54SdQHK8yhgG47f8$#25&756#$234#$df"
  10. Private Const DB_USER As String = "argentum"
  11.  
  12. Public Sub LoadDatabase()
  13. '*************************************************
  14.    ' • Cargamos la base de datos
  15. '*************************************************
  16.  
  17. On Error GoTo ErrHandler
  18.  
  19.     Set ServerDatabase = New ADODB.Connection
  20.  
  21.     With ServerDatabase
  22.         .ConnectionString = "DRIVER={" & DB_DRIVER & "};" & "SERVER=" & DB_HOST & ";" & _
  23.                             " DATABASE=" & DB_NOMBRE & ";" & "UID=" & DB_USER & "; PWD=" & DB_PASSWD & "; OPTION=3"
  24.  
  25.         .CursorLocation = adUseClient
  26.         .Open
  27.     End With
  28. Exit Sub
  29.  
  30. ErrHandler:
  31.    MsgBox "Error en LoadDatabase: " & Err.description & " String: " & ServerDatabase.ConnectionString
  32.    End
  33. End Sub
  34.  
  35. Public Sub CloseDatabase()
  36. '*************************************************
  37.    ' • Cerramos la base de datos
  38. '*************************************************
  39.  
  40. On Error GoTo ErrHandler
  41.  
  42.     ServerDatabase.Close
  43.  
  44.     Set ServerDatabase = Nothing
  45. Exit Sub
  46.  
  47. ErrHandler:
  48.     MsgBox "Error en CloseDataBase: " & Err.description & " String: " & ServerDatabase.ConnectionString
  49.     End
  50. End Sub
  51.  
  52. Private Sub SaveUserFlags(ByVal UserIndex As Integer)
  53. '*************************************************
  54.    ' • Save of user flags
  55. '*************************************************
  56.  
  57.     Dim str As String
  58.    
  59.     With UserList(UserIndex)
  60.    
  61.         DatabaseExecute ServerDatabase, "SELECT * FROM `Flags` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Flags` (PjIndex) VALUES (" & .PjIndex & ")"
  62.        
  63.         str = "UPDATE `Flags` SET PjIndex=" & .PjIndex
  64.    
  65.         str = str & ",Muerto=" & .flags.Muerto
  66.         str = str & ",Escondido=" & .flags.Escondido
  67.         str = str & ",Hambre=" & .flags.Hambre
  68.         str = str & ",Sed=" & .flags.Sed
  69.         str = str & ",Desnudo=" & .flags.Desnudo
  70.         str = str & ",Ban=" & .flags.Ban
  71.         str = str & ",Navegando=" & .flags.Navegando
  72.         str = str & ",Envenenado=" & .flags.Envenenado
  73.         str = str & ",Paralizado=" & .flags.Paralizado
  74.         str = str & ",LastMap=" & .flags.lastMap
  75.         str = str & ",Consejo=" & .flags.Consejo
  76.        
  77.         str = str & " WHERE PjIndex=" & .PjIndex
  78.     End With
  79. End Sub
  80.  
  81. Private Sub SaveUserInit(ByVal UserIndex As Integer)
  82. '*************************************************
  83.    ' • Save of user init
  84. '*************************************************
  85.  
  86.     Dim str As String
  87.     Dim TempDate As Date
  88.    
  89.     With UserList(UserIndex)
  90.         DatabaseExecute ServerDatabase, "SELECT * FROM `Init` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Init` (PjIndex) VALUES (" & .PjIndex & ")"
  91.        
  92.         str = "UPDATE `Init` SET PjIndex=" & .PjIndex & ",Nombre='" & UCase$(.Name) & "'"
  93.    
  94.         str = str & ",Email='" & .Email & "'"
  95.         str = str & ",Password='" & .Password & "'"
  96.         str = str & ",AccountIndex=" & .AccountIndex
  97.         str = str & ",GuildIndex=" & .GuildIndex
  98.         str = str & ",Genero=" & .Genero
  99.         str = str & ",Raza=" & .Raza
  100.         str = str & ",Clase=" & .Clase
  101.         str = str & ",Hogar=" & .Hogar
  102.         str = str & ",Desc=" & .desc
  103.         str = str & ",Heading=" & .Char.heading
  104.         str = str & ",Head=" & .OrigChar.Head
  105.        
  106.         If .flags.Muerto = 0 Then
  107.             If .Char.body <> 0 Then
  108.                 str = str & ",Body=" & .Char.body
  109.             End If
  110.         End If
  111.        
  112.         str = str & ",Arma=" & .Char.WeaponAnim
  113.         str = str & ",Escudo=" & .Char.ShieldAnim
  114.         str = str & ",Casco=" & .Char.CascoAnim
  115.        
  116.         #If ConUpTime Then
  117.             TempDate = Now - .LogOnTime
  118.             .LogOnTime = Now
  119.             .UpTime = .UpTime + (Abs(Day(TempDate) - 30) * 24 * 3600) + Hour(TempDate) * 3600 + Minute(TempDate) * 60 + Second(TempDate)
  120.             .UpTime = .UpTime
  121.             str = str & ",UpTime='" & .UpTime & "'"
  122.         #End If
  123.        
  124.         str = str & ",LastIp=" & .ip
  125.         str = str & ",Position='" & .Pos.Map & "-" & .Pos.X & "-" & .Pos.Y & "'"
  126.         str = str & " WHERE PjIndex=" & .PjIndex
  127.  
  128.         Call ServerDatabase.Execute(str)
  129.     End With
  130. End Sub
  131.  
  132. Private Sub SaveUserCounters(ByVal UserIndex As Integer)
  133. '*************************************************
  134.    ' • Save of user counters
  135. '*************************************************
  136.    
  137.     Dim str As String
  138.    
  139.     With UserList(UserIndex)
  140.         DatabaseExecute ServerDatabase, "SELECT * FROM `Counters` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Counters` (PjIndex) VALUES (" & .PjIndex & ")"
  141.        
  142.         str = "UPDATE `Counters` SET PjIndex=" & .PjIndex
  143.            
  144.         str = str & ",Pena=" & .Counters.Pena
  145.         str = str & ",SkillsAsignados=" & .Counters.AsignedSkills
  146.         str = str & " WHERE PjIndex=" & .PjIndex
  147.        
  148.         Call ServerDatabase.Execute(str)
  149.    
  150.     End With
  151. End Sub
  152.  
  153. Private Sub SaveUserFaction(ByVal UserIndex As Integer)
  154. '*************************************************
  155.    ' • Save of user faction
  156. '*************************************************
  157.    
  158.     Dim str As String
  159.    
  160.     With UserList(UserIndex)
  161.         DatabaseExecute ServerDatabase, "SELECT * FROM `Facciones` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Facciones` (PjIndex) VALUES (" & .PjIndex & ")"
  162.        
  163.         str = "UPDATE `Facciones` SET PjIndex=" & .PjIndex
  164.        
  165.         str = str & ",EjercitoReal=" & .Faccion.ArmadaReal
  166.         str = str & ",EjercitoCaos=" & .Faccion.FuerzasCaos
  167.         str = str & ",CiudMatados=" & .Faccion.CiudadanosMatados
  168.         str = str & ",CrimMatados=" & .Faccion.CriminalesMatados
  169.         str = str & ",rArCaos=" & .Faccion.RecibioArmaduraCaos
  170.         str = str & ",rArReal=" & .Faccion.RecibioArmaduraReal
  171.         str = str & ",rExCaos=" & .Faccion.RecibioExpInicialCaos
  172.         str = str & ",rExReal=" & .Faccion.RecibioExpInicialReal
  173.         str = str & ",recCaos=" & .Faccion.RecompensasCaos
  174.         str = str & ",recReal=" & .Faccion.RecompensasReal
  175.         str = str & ",Reenlistadas=" & .Faccion.Reenlistadas
  176.         str = str & ",NivelIngreso=" & .Faccion.NivelIngreso
  177.         str = str & ",FechaIngreso=" & .Faccion.FechaIngreso
  178.         str = str & ",MatadosIngreso=" & .Faccion.MatadosIngreso
  179.         str = str & ",NextRecompensa=" & .Faccion.NextRecompensa
  180.         str = str & " WHERE PjIndex=" & .PjIndex
  181.        
  182.         Call ServerDatabase.Execute(str)
  183.    
  184.     End With
  185. End Sub
  186.  
  187. Private Sub SaveUserAtributtes(ByVal UserIndex As Integer)
  188. '*************************************************
  189.    ' • Save user atributtes
  190. '*************************************************
  191.  
  192.     Dim str As String, LoopC As Long
  193.    
  194.     With UserList(UserIndex)
  195.         DatabaseExecute ServerDatabase, "SELECT * FROM `Skills` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Skills` (PjIndex) VALUES (" & .PjIndex & ")"
  196.        
  197.         str = "UPDATE `Atributos` SET PjIndex=" & .PjIndex
  198.        
  199.         If Not .flags.TomoPocion Then
  200.             For LoopC = 1 To UBound(.Stats.UserAtributos)
  201.                 str = str & ",AT" & i & "=" & .Stats.UserAtributos(LoopC)
  202.             Next LoopC
  203.         Else
  204.             For LoopC = 1 To UBound(.Stats.UserAtributos)
  205.                  str = str & ",AT" & i & "=" & .Stats.UserAtributosBackUP(LoopC)
  206.             Next LoopC
  207.         End If
  208.        
  209.         str = str & " WHERE PjIndex=" & .PjIndex
  210.        
  211.         Call ServerDatabase.Execute(str)
  212.        
  213.     End With
  214. End Sub
  215. Private Sub SaveUserSkills(ByVal UserIndex As Integer)
  216. '*************************************************
  217.    ' • Save user skills
  218. '*************************************************
  219.    
  220.     Dim str As String, LoopC As Long
  221.    
  222.     With UserList(UserIndex)
  223.         DatabaseExecute ServerDatabase, "SELECT * FROM `Skills` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Skills` (PjIndex) VALUES (" & .PjIndex & ")"
  224.        
  225.         str = "UPDATE `Skills` SET PjIndex=" & .PjIndex
  226.        
  227.         For LoopC = 1 To UBound(.Stats.UserSkills)
  228.             str = str & ",Sk" & LoopC & "=" & .Stats.UserSkills(LoopC)
  229.             str = str & ",SkExp" & LoopC & "=" & .Stats.EluSkills(LoopC)
  230.             str = str & ",SkElu" & LoopC & "=" & .Stats.ExpSkills(LoopC)
  231.         Next LoopC
  232.        
  233.         str = str & " WHERE PjIndex=" & .PjIndex
  234.        
  235.         Call ServerDatabase.Execute(str)
  236.     End With
  237. End Sub
  238.  
  239. Private Sub SaveUserStats(ByVal UserIndex As Integer)
  240. '*************************************************
  241.    ' • Save user stats
  242. '*************************************************
  243.    
  244.     Dim str As String
  245.    
  246.     With UserList(UserIndex)
  247.         DatabaseExecute ServerDatabase, "SELECT * FROM `Stats` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Stats` (PjIndex) VALUES (" & .PjIndex & ")"
  248.         str = "UPDATE `Stats` SET PjIndex=" & .PjIndex
  249.        
  250.         str = str & ",Gld=" & .Stats.GLD
  251.         str = str & ",MinHp=" & .Stats.MinHp & ",MaxHp=" & .Stats.MaxHp
  252.         str = str & ",MinSta=" & .Stats.MinSta & ",MaxSta=" & .Stats.MaxSta
  253.         str = str & ",MinMan=" & .Stats.MinMAN & ",MaxMan=" & .Stats.MaxMAN
  254.         str = str & ",MinHit=" & .Stats.MinHIT & ",MaxHit=" & .Stats.MaxHIT
  255.         str = str & ",MinAgu=" & .Stats.MinAGU & ",MaxAgu=" & .Stats.MaxAGU
  256.         str = str & ",MinHam=" & .Stats.MinHam & ",MaxHam=" & .Stats.MaxHam
  257.         str = str & ",SkillPtsLibres=" & .Stats.SkillPts
  258.         str = str & ",Exp=" & .Stats.Exp
  259.         str = str & ",Elv=" & .Stats.ELV
  260.         str = str & ",Elu=" & .Stats.ELU
  261.         str = str & ",UserMuertes=" & .Stats.UsuariosMatados
  262.         str = str & ",NpcsMuertes=" & .Stats.NPCsMuertos
  263.    
  264.         str = str & " WHERE PjIndex=" & .PjIndex
  265.        
  266.         Call ServerDatabase.Execute(str)
  267.     End With
  268. End Sub
  269.  
  270. Private Sub SaveUserInventory(ByVal UserIndex As Integer)
  271. '*************************************************
  272.    ' • Save user Inventory
  273. '*************************************************
  274.    
  275.     Dim str As String, LoopC As Long
  276.    
  277.     With UserList(UserIndex)
  278.         DatabaseExecute ServerDatabase, "SELECT * FROM `Inventory` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Inventory` (PjIndex) VALUES (" & .PjIndex & ")"
  279.         str = "UPDATE `Inventory` SET PjIndex=" & .PjIndex
  280.        
  281.         str = str & ",CantidadItems=" & .Invent.NroItems
  282.    
  283.         For LoopC = 1 To MAX_INVENTORY_SLOTS
  284.             str = str & ",Obj" & LoopC & "=" & .Invent.Object(LoopC).ObjIndex & "-" & .Invent.Object(LoopC).Amount & "-" & .Invent.Object(LoopC).Equipped
  285.         Next LoopC
  286.    
  287.         str = str & "WeaponEqpSlot=" & .Invent.WeaponEqpSlot
  288.         str = str & "ArmourEqpSlot=" & .Invent.ArmourEqpSlot
  289.         str = str & "CascoEqpSlot=" & .Invent.CascoEqpSlot
  290.         str = str & "EscudoEqpSlot=" & .Invent.EscudoEqpSlot
  291.         str = str & "BarcoSlot=" & .Invent.BarcoSlot
  292.         str = str & "MunicionSlot=" & .Invent.MunicionEqpSlot
  293.         str = str & "MochilaSlot=" & .Invent.MochilaEqpSlot
  294.         str = str & "AnilloSlot=" & .Invent.AnilloEqpSlot
  295.    
  296.         str = str & " WHERE PjIndex=" & .PjIndex
  297.        
  298.         Call ServerDatabase.Execute(str)
  299.     End With
  300. End Sub
  301.  
  302. Private Sub SaveUserReputation(ByVal UserIndex As Integer)
  303. '*************************************************
  304.    ' • Save user Reputation
  305. '*************************************************
  306.    
  307.     Dim str As String, P As Long
  308.    
  309.     With UserList(UserIndex)
  310.         DatabaseExecute ServerDatabase, "SELECT * FROM `Reputacion` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Reputacion` (PjIndex) VALUES (" & .PjIndex & ")"
  311.         str = "UPDATE `Reputacion` SET PjIndex=" & .PjIndex
  312.        
  313.         str = str & ",Asesino=" & .Reputacion.AsesinoRep
  314.         str = str & ",Bandido=" & .Reputacion.BandidoRep
  315.         str = str & ",Burguesia=" & .Reputacion.BurguesRep
  316.         str = str & ",Ladrones=" & .Reputacion.LadronesRep
  317.         str = str & ",Nobles=" & .Reputacion.NobleRep
  318.         str = str & ",Plebe=" & .Reputacion.PlebeRep
  319.    
  320.    
  321.         P = (-.Reputacion.AsesinoRep) + _
  322.             (-.Reputacion.BandidoRep) + _
  323.             .Reputacion.BurguesRep + _
  324.             (-.Reputacion.LadronesRep) + _
  325.             .Reputacion.NobleRep + _
  326.             .Reputacion.PlebeRep
  327.         P = P / 6
  328.        
  329.         str = str & ",Promedio=" & P
  330.         str = str & " WHERE PjIndex=" & .PjIndex
  331.        
  332.         Call ServerDatabase.Execute(str)
  333.     End With
  334. End Sub
  335.  
  336. Private Sub SaveUserSpells(ByVal UserIndex As Integer)
  337. '*************************************************
  338.    ' • Save user Spells
  339. '*************************************************
  340.    
  341.     Dim str As String, LoopC As Long, SpellIndex As Integer
  342.    
  343.     With UserList(UserIndex)
  344.         DatabaseExecute ServerDatabase, "SELECT * FROM `Spells` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Spells` (PjIndex) VALUES (" & .PjIndex & ")"
  345.         str = "UPDATE `Spells` SET PjIndex=" & .PjIndex
  346.        
  347.    
  348.         For LoopC = 1 To MAXUSERHECHIZOS
  349.             str = str & ",Spell" & LoopC & "=" & .Stats.UserHechizos(LoopC)
  350.         Next LoopC
  351.        
  352.         str = str & " WHERE PjIndex=" & .PjIndex
  353.        
  354.         Call ServerDatabase.Execute(str)
  355.     End With
  356. End Sub
  357.  
  358. Private Sub SaveUserPet(ByVal UserIndex As Integer)
  359. '*************************************************
  360.    ' • Save user Pet
  361. '*************************************************
  362.    
  363.     Dim str As String, LoopC As Long, NroMascotas As Long, cad As String
  364.    
  365.     With UserList(UserIndex)
  366.         DatabaseExecute ServerDatabase, "SELECT * FROM `Pet` WHERE PjIndex=" & .PjIndex, "INSERT INTO `Pet` (PjIndex) VALUES (" & .PjIndex & ")"
  367.         str = "UPDATE `Pet` SET PjIndex=" & .PjIndex
  368.        
  369.         NroMascotas = .NroMascotas
  370.    
  371.         For LoopC = 1 To MAXMASCOTAS
  372.             If .MascotasIndex(LoopC) > 0 Then
  373.                
  374.                 If Npclist(.MascotasIndex(LoopC)).Contadores.TiempoExistencia = 0 Then
  375.                     cad = .MascotasType(LoopC)
  376.                 Else
  377.                     cad = "0"
  378.                     NroMascotas = NroMascotas - 1
  379.                 End If
  380.                
  381.                 str = str & ",PET" & LoopC & "=" & cad
  382.             Else
  383.                 cad = .MascotasType(LoopC)
  384.                 str = str & ",PET" & LoopC & "=" & cad
  385.             End If
  386.        
  387.         Next LoopC
  388.    
  389.         str = str & ",NroMascotas=" & NroMascotas
  390.         str = str & " WHERE PjIndex=" & .PjIndex
  391.        
  392.         Call ServerDatabase.Execute(str)
  393.     End With
  394. End Sub
  395. Private Sub DatabaseExecute(ByVal db As ADODB.Connection, ByVal strSelect As String, ByVal strInsert As String)
  396. '*************************************************
  397.    ' • Database Execute
  398. '*************************************************
  399.  
  400.     Set RS = db.Execute(strSelect)
  401.    
  402.     If RS.BOF Or RS.EOF Then
  403.         db.Execute strInsert
  404.     End If
  405.    
  406.     Set RS = Nothing
  407. End Sub
  408.  
  409. Public Sub SaveDatabaseUser(ByVal UserIndex As Integer)
  410. '*************************************************
  411.    ' • Save to the user
  412. '*************************************************
  413.  
  414. On Error GoTo ErrHandler
  415.  
  416.  
  417. Dim LoopC As Integer
  418.  
  419. With UserList(UserIndex)
  420.  
  421.     ' • Personaje nulo
  422.    If (.Clase = 0) Or (.Stats.ELV = 0) Or (Len(.Name) = 0) Then
  423.         Call LogCriticEvent("Estoy intentantdo guardar un usuario nulo de nombre: " & .Name)
  424.         Exit Sub
  425.     End If
  426.    
  427.     ' • Personaje mimetizado vuelve normal
  428.    If .flags.Mimetizado = 1 Then
  429.         .Char.body = .CharMimetizado.body
  430.         .Char.Head = .CharMimetizado.Head
  431.         .Char.CascoAnim = .CharMimetizado.CascoAnim
  432.         .Char.ShieldAnim = .CharMimetizado.ShieldAnim
  433.         .Char.WeaponAnim = .CharMimetizado.WeaponAnim
  434.         .Counters.Mimetismo = 0
  435.         .flags.Mimetizado = 0
  436.         .flags.Ignorado = False
  437.     End If
  438.    
  439.     Set RS = New ADODB.Recordset
  440.    
  441.     Set RS = ServerDatabase.Execute("SELECT * FROM `Init` WHERE Nombre='" & UCase$(.Name) & "'")
  442.    
  443.     If RS.BOF Or RS.EOF Then
  444.         ServerDatabase.Execute "INSERT INTO `Init` (NOMBRE) VALUES ('" & UCase$(.Name) & "')"
  445.         Set RS = Nothing
  446.         Set RS = ServerDatabase.Execute("SELECT * FROM `Init` WHERE Nombre='" & UCase$(.Name) & "'")
  447.         .PjIndex = RS!PjIndex
  448.     Else
  449.         Set RS = ServerDatabase.Execute("SELECT * FROM `Init` WHERE PjIndex=" & .PjIndex)
  450.         .PjIndex = RS!PjIndex
  451.     End If
  452.  
  453.     Set RS = Nothing
  454.  
  455.     SaveUserFlags UserIndex
  456.     SaveUserInit UserIndex
  457.     SaveUserCounters UserIndex
  458.     SaveUserFaction UserIndex
  459.     SaveUserAtributtes UserIndex
  460.     SaveUserSkills UserIndex
  461.     SaveUserStats UserIndex
  462.     SaveUserInventory UserIndex
  463.     SaveUserReputation UserIndex
  464.     SaveUserPet UserIndex
  465.    
  466.     ' • Comento lo del banco ya que va a ser vía account web
  467.    '*******************************************************************************************
  468.    'Call Manager.ChangeValue("BancoInventory", "CantidadItems", val(.BancoInvent.NroItems))
  469.    'For loopd = 1 To MAX_BANCOINVENTORY_SLOTS
  470.        'Call Manager.ChangeValue("BancoInventory", "Obj" & loopd, .BancoInvent.Object(loopd).ObjIndex & "-" & .BancoInvent.Object(loopd).Amount)
  471.    'Next loopd
  472.    '*******************************************************************************************
  473.    'Guarda los mensajes privados del usuario.
  474.    'Call GuardarMensajes(UserIndex, Manager)
  475.    
  476.     'Devuelve el head de muerto
  477.    If .flags.Muerto = 1 Then
  478.         .Char.Head = iCabezaMuerto
  479.     End If
  480.    
  481.    
  482. End With
  483.  
  484. Exit Sub
  485.  
  486. ErrHandler:
  487. Call LogError("Error en SaveUser")
  488. Set RS = Nothing
  489.  
  490. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement