Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LUA BY CSENDES MARCELL
- -- MySQL Connection Details:
- sql_host = "" -- Host
- sql_user = "" -- USER
- sql_password = "" --Pass
- sql_db_name = "cs2d" -- DBNAME
- sql_port = 3306 -- Default Port usually this, do not change it, if you are not sure what is it.
- -- Adding Hooks
- addhook("join", "logPlayer")
- addhook("join", "JoinMessage")
- addhook("minute", "saveStats")
- addhook("say", "logChat")
- addhook("say","RegisterLogin")
- addhook("say","testsay")
- -- Configuration --
- server = " CS2D Online" -- server name
- version = " 0.1a" -- version of script
- LoggedIn = false -- Unregisted user's status, when he/she joins to server.
- color = {
- "©552220000", -- CS2D (yellow) 1
- "©255255255", -- white 2
- "©255000000", -- red 3
- "©000255000", -- green 4
- "©000000255", -- blue 5
- "©220220220", -- light grey 6
- "©064179162", -- PM - light blue 7
- "©255025000", -- T 8
- "©050150255", -- CT 9
- "©100100100" -- pretty dark grey - tag 10
- }
- -- Connection LUA and between MySQL Server
- luasql = require "luasql.mysql"
- env = assert (luasql.mysql())
- con = assert(env:connect(sql_db_name,sql_user,sql_password,sql_host,sql_port))
- -- Functions
- function CheckMySQL()
- print("Connecting to sql server") -- you need most prints BEFORE executing stuff, not after doing that
- if assert(env:connect(sql_db_name,sql_user,sql_password,sql_host,sql_port)) then -- dont you do that in line 42 already?
- print("©000255000The connection for MySQL server was successfully")
- else
- print("©255000000The connection wasn't successful for MySQL check your server and/or configuration in index.lua")
- end
- end
- CheckMySQL()
- function JoinMessage(id)
- msg2(id, "©255255255Welcome on the ©55220000"..server.." ©255255255server!")
- msg2(id, "©255255255Our Gamemode running under ©55220000"..version.." ©255255255version.")
- msg2(id, "©000255000To register on our server just use !register <username> <password>")
- msg2(id, "©000255000You will be automatically logged in after you register an account.")
- end
- function DoLogin(id)
- local usgn = player(id, "usgn")
- if usgn > 0 then
- LoggedIn = true
- end
- end
- function _DoLogin(id)
- DoLogin(id)
- if LoggedIn then
- msg2(id, "©000255000You have been successfully logged in.")
- end
- end
- function DoLogout(id)
- local usgn = player(id, "usgn")
- if usgn > 0 then
- LoggedIn = false
- end
- end
- function VerifyLogin(id)
- local usgn = player(id, "usgn")
- if usgn > 0 then
- if LoggedIn == false then
- msg2(id, "Please register or log in to play on the server.")
- elseif LoggedIn == true then
- return 0;
- end
- end
- end
- function RegisterLogin(id,txt)
- print("Received command! ".. tostring(id) .." ; "..tostring(txt))
- local usgn = player(id, "usgn")
- local space = txt:find(" ") or #txt + 1
- local cmd = txt:sub(1, space - 1)
- if cmd == "!login" then
- print("Command is !login")
- cur = con:execute("select * from users")
- print("cur/row line")
- row = cur:fetch({}, 'a')
- print("row succeeded")
- for k, v in pairs(row) do
- print("pairs...")
- print(k, v)
- end
- end
- if cmd=="!register" then
- local regName, regPW = txt:match("!register ([%a|%d]+) ([%a|%d]+)")
- local regDate = os.date("%c")
- if usgn > 0 then
- res = assert (con:execute(string.format([[INSERT INTO users VALUES ('%s', '%s', '%s')]], regName, regPW, regDate)))
- msg2(id, "©000255000Congratulations! You have been successfully registered!")
- msg2(id, "©000255000Username: ©255255255"..regName)
- msg2(id, "©000255000Password: ©255255255"..regPW)
- msg2(id, "©255255255You will be automatically logged in after 5 second(s)")
- timer(5000,'parse','lua _DoLogin('..id..')')
- end
- end
- end
- function logPlayer(id)
- print("logPlayer: " ..tostring(id))
- local usgn = player(id, "usgn")
- local ip = player(id, "ip")
- local name = player(id, "name")
- local datime = os.date("%c")
- if usgn > 0 then
- print("logPlayer: USGN>0")
- res = assert (con:execute(string.format([[
- INSERT INTO logins
- VALUES ('%s', '%s', '%s', '%s')]], usgn, ip, name, datime)
- ))
- print("logPlayer: USGN>0 STATUS: OK")
- elseif usgn == 0 then
- print("logPlayer: USGN==0")
- res = assert (con:execute(string.format([[
- INSERT INTO bots
- VALUES ('%s', '%s')]], name, datime)
- ))
- print("logPlayer: USGN==0 STATUS: OK")
- end
- end
- function logChat(id, msg)
- print("logChat")
- local usgn = player(id, "usgn")
- local ip = player(id, "ip")
- local name = player(id, "name")
- local datime = os.date("%c")
- if usgn > 0 then
- print("logChat USGN>0")
- res = assert (con:execute(string.format([[
- INSERT INTO chats
- VALUES ('%s', '%s', '%s', '%s', '%s')]], usgn, ip, name, datime, msg)
- ))
- end
- print("logChat STATUS: OK")
- end
- function saveStats(id)
- print("SaveStats")
- for _, id in pairs(player(0,"table")) do
- local usgn = player(id, "usgn")
- local level = player(id, "score")
- local ip = player(id, "ip")
- local name = player(id, "name")
- local datime = os.date("%c")
- if usgn > 0 then
- if VerifyLogin(id) then
- if level > 0 then
- print("logStats level > 0")
- res = assert (con:execute(string.format([[
- INSERT INTO stats
- VALUES ('%s', '%s', '%s', '%s', '%s')]], usgn, ip, name, datime, level)
- ))
- print("©000255000The players's stats have been saved into MYSQL on ©255255255"..datime)
- else
- print("logSTATS: return 0")
- return 0;
- end
- end
- end
- end
- print("logStats STATUS: OK")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement