sqpp15

Untitled

Jun 15th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. -- LUA BY CSENDES MARCELL
  2.  
  3. -- MySQL Connection Details:
  4. sql_host = "" -- Host
  5. sql_user = "" -- USER
  6. sql_password = "" --Pass
  7. sql_db_name = "cs2d" -- DBNAME
  8. sql_port = 3306 -- Default Port usually this, do not change it, if you are not sure what is it.
  9.  
  10. -- Adding Hooks
  11. addhook("join", "logPlayer")
  12. addhook("join", "JoinMessage")
  13. addhook("minute", "saveStats")
  14. addhook("say", "logChat")
  15. addhook("say","RegisterLogin")
  16. addhook("say","testsay")
  17.  
  18.  
  19.  
  20. -- Configuration --
  21. server = " CS2D Online" -- server name
  22. version = " 0.1a" -- version of script
  23. LoggedIn = false -- Unregisted user's status, when he/she joins to server.
  24.  
  25.  
  26. color = {
  27.         "©552220000", -- CS2D (yellow) 1
  28.         "©255255255", -- white 2
  29.         "©255000000", -- red 3
  30.         "©000255000", -- green 4
  31.         "©000000255", -- blue 5
  32.         "©220220220", -- light grey 6
  33.         "©064179162", -- PM - light blue 7
  34.         "©255025000", -- T 8
  35.         "©050150255", -- CT 9
  36.         "©100100100" -- pretty dark grey - tag 10
  37. }
  38.  
  39. -- Connection LUA and between MySQL Server
  40. luasql = require "luasql.mysql"
  41. env = assert (luasql.mysql())
  42. con = assert(env:connect(sql_db_name,sql_user,sql_password,sql_host,sql_port))
  43.  
  44. -- Functions
  45.  
  46. function CheckMySQL()
  47.     if assert(env:connect(sql_db_name,sql_user,sql_password,sql_host,sql_port)) then
  48.     print("©000255000The connection for MySQL server was successfully")
  49.     else
  50.     print("©255000000The connection wasn't successful for MySQL check your server and/or configuration in index.lua")
  51.     end
  52. end
  53.  
  54. CheckMySQL()
  55.    
  56. function JoinMessage(id)
  57.     msg2(id, "©255255255Welcome on the ©55220000"..server.." ©255255255server!")
  58.     msg2(id, "©255255255Our Gamemode running under ©55220000"..version.." ©255255255version.")
  59.     msg2(id, "©000255000To register on our server just use !register <username> <password>")
  60.     msg2(id, "©000255000You will be automatically logged in after you register an account.")
  61. end
  62.  
  63. function DoLogin(id)
  64.  
  65. local usgn = player(id, "usgn")
  66. if usgn > 0 then
  67.     LoggedIn = true
  68.     end
  69. end
  70.  
  71. function _DoLogin(id)
  72.     DoLogin(id)
  73.     if LoggedIn then
  74.         msg2(id, "©000255000You have been successfully logged in.")
  75.     end
  76. end
  77.  
  78. function DoLogout(id)
  79.  
  80. local usgn = player(id, "usgn")
  81.  
  82. if usgn > 0 then
  83.     LoggedIn = false
  84.     end
  85. end
  86.  
  87. function VerifyLogin(id)
  88.  
  89. local usgn = player(id, "usgn")
  90. if usgn > 0 then
  91.     if LoggedIn == false then
  92.     msg2(id, "Please register or log in to play on the server.")
  93.     elseif LoggedIn == true then
  94.         return 0;
  95.     end
  96. end
  97. end
  98.  
  99. function RegisterLogin(id,txt)
  100.  
  101. local usgn = player(id, "usgn")
  102. local space = txt:find(" ") or #txt + 1
  103. local cmd = txt:sub(1, space - 1)
  104.  
  105. if cmd == "!login" then
  106.         cur = con:execute("select * from users")
  107.         row = cur:fetch({}, 'a')
  108.         for k, v in pairs(row) do
  109.         print(k, v)
  110.     end
  111. end
  112.  
  113.  
  114. if cmd=="!register" then
  115.                 local regName, regPW = txt:match("!register ([%a|%d]+) ([%a|%d]+)")
  116.                 local regDate = os.date("%c")
  117.  
  118.                 if usgn > 0 then
  119.                         res = assert (con:execute(string.format([[INSERT INTO users VALUES ('%s', '%s', '%s')]], regName, regPW, regDate)))
  120.                 msg2(id, "©000255000Congratulations! You have been successfully registered!")
  121.                 msg2(id, "©000255000Username: ©255255255"..regName)
  122.                 msg2(id, "©000255000Password: ©255255255"..regPW)
  123.                 msg2(id, "©255255255You will be automatically logged in after 5 second(s)")
  124.                 timer(5000,'parse','lua _DoLogin('..id..')')
  125.         end
  126.         end
  127. end
  128.  
  129.  
  130. function logPlayer(id)
  131.  
  132. local usgn = player(id, "usgn")
  133. local ip = player(id, "ip")
  134. local name = player(id, "name")
  135. local datime = os.date("%c")
  136.  
  137.     if usgn > 0 then
  138.         res = assert (con:execute(string.format([[
  139.             INSERT INTO logins
  140.             VALUES ('%s', '%s', '%s', '%s')]], usgn, ip, name, datime)
  141.         ))
  142.     elseif usgn == 0 then
  143.         res = assert (con:execute(string.format([[
  144.             INSERT INTO bots
  145.             VALUES ('%s', '%s')]], name, datime)
  146.         ))
  147.     end
  148. end
  149.  
  150.        
  151. function logChat(id, msg)
  152.  
  153. local usgn = player(id, "usgn")
  154. local ip = player(id, "ip")
  155. local name = player(id, "name")
  156. local datime = os.date("%c")
  157.        
  158.         if usgn > 0 then
  159.         res = assert (con:execute(string.format([[
  160.                 INSERT INTO chats
  161.                 VALUES ('%s', '%s', '%s', '%s', '%s')]], usgn, ip, name, datime, msg)
  162.         ))
  163.         end
  164. end
  165.  
  166. function saveStats(id)
  167.                 for _, id in pairs(player(0,"table")) do
  168.                 local usgn = player(id, "usgn")
  169.                 local level = player(id, "score")
  170.                 local ip = player(id, "ip")
  171.                 local name = player(id, "name")
  172.                 local datime = os.date("%c")
  173.                 if usgn > 0 then
  174.                 if VerifyLogin(id) then
  175.                 if level > 0 then
  176.                           res = assert (con:execute(string.format([[
  177.                           INSERT INTO stats
  178.                           VALUES ('%s', '%s', '%s', '%s', '%s')]], usgn, ip, name, datime, level)
  179.                           ))
  180.                 print("©000255000The players's stats have been saved into MYSQL on ©255255255"..datime)
  181.                 else
  182.                         return 0;
  183.                 end
  184.             end
  185.         end
  186.     end
  187. end
Advertisement
Add Comment
Please, Sign In to add comment