Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. --[[
  2. Project: VitaOnline
  3. File: mysql-server.lua
  4. Author(s): Werni
  5. ]]--
  6. g_mysql = {}
  7. local hasPlayersLoaded = false
  8.  
  9. function onResourceStartMysqlConnection()
  10. local xml = xmlLoadFile("./xml/config.xml")
  11. if not xml then
  12. outputServerLog("Konnte config.xml nicht finden. Laden abgebrochen!")
  13. cancelEvent()
  14. stopResource(getThisResource())
  15. return false
  16. end
  17.  
  18. --MySQL Daten
  19. local mysqlchild = xmlFindChild(xml, "mysqldata", 0)
  20. if not mysqlchild then
  21. outputServerLog("Keine MySQL Verbindungsdaten gefunden.")
  22. end
  23.  
  24. local mysqlhost = xmlGetVal(mysqlchild, "host")
  25. if mysqlhost then mysql_host = mysqlhost end
  26.  
  27. local mysqluser = xmlGetVal(mysqlchild, "user")
  28. if mysqluser then mysql_user = mysqluser end
  29.  
  30. local mysqlpsw = xmlGetVal(mysqlchild, "password")
  31. if mysqlpsw then mysql_password = mysqlpsw end
  32.  
  33. local mysqltable = xmlGetVal(mysqlchild, "table")
  34. if mysqltable then mysql_table = mysqltable end
  35.  
  36. g_mysql["connection"] = mysql_connect(mysql_host, mysql_user, mysql_password, mysql_table, 3306, nil, "")
  37.  
  38. if not g_mysql["connection"] then
  39. outputServerLog("Kann die MySQL-Verbindung nicht aufbauen!")
  40. print("Kann die MySQL-Verbindung nicht aufbauen!")
  41. stopResource(getThisResource())
  42. eventcancled = 1
  43. cancelEvent()
  44. return false
  45. end
  46.  
  47.  
  48. --------CONVERTER
  49. if not hasPlayersLoaded == true then
  50. hasPlayersLoaded = true
  51. --convertPlayerXML(0)
  52. --[[if mysql_ping ( g_mysql["connection"] ) == false then
  53. onResourceStopMysqlEnd()
  54. hasPlayersLoaded = false
  55. onResourceStartMysqlConnection()
  56. end
  57. local result = mysql_query(g_mysql["connection"], "SELECT * FROM `players` ORDER BY `id` ASC")
  58. if result then
  59. while true do
  60. local row = mysql_fetch_assoc(result)
  61. if not row then break end
  62.  
  63. local accElement = createElement ( "userAccount" )
  64. setElementData(accElement, "AccountName", row["accountname"])
  65. setElementData(accElement, "Points", tonumber(row["points"]))
  66. end
  67. mysql_free_result(result)
  68. else
  69. outputServerLog("Spieler-Elemente Laden fehlgeschlagen! Erneuter Versuch...")
  70. print("Spieler-Elemente Laden fehlgeschlagen! Erneuter Versuch...")
  71. onResourceStopMysqlEnd()
  72. hasPlayersLoaded = false
  73. onResourceStartMysqlConnection()
  74. end ]]--
  75. end
  76. end
  77. addEventHandler("onResourceStart", getResourceRootElement(), onResourceStartMysqlConnection)
  78.  
  79. function onResourceStopMysqlEnd()
  80. mysql_close(g_mysql["connection"])
  81. end
  82. addEventHandler("onResourceStop", getResourceRootElement(), onResourceStopMysqlEnd, true, "low")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement