local check = exports.mysql:_QuerySingle(\"select * from accounts where username = ? \",username)
Tedd az username oszlopot unique-ra
dbExec( connection, \"INSERT INTO accounts VALUES (?,?,?,?,?)\", 1, \"username\",\"password\",\"email\",\"ip\" )
addEvent(\"loginPlayer\", true)function loginPlayer(player, username, password, serial) local check = exports.mta_connection:_QuerySingle(\"SELECT * FROM accounts WHERE username = ?\",username) local serial = getPlayerSerial(player) if check then local checkPass = check.password local checkSerial = check.serial if ( checkSerial == serial ) then if (checkPass == password) then logIn(player,tostring(username),tostring(password)) outputDebugString(\"User is loggined!\") triggerClientEvent(player,\"showHide\",getRootElement()) else exports[\"notices\"]:addNotification(root,\"Hibás felhasználónév/jelszó!\",\'error\') end else exports[\"notices\"]:addNotification(root,\"Ez a felhasználó nem ehhez a számítógéphez van társítva!\",\'error\') end else exports[\"notices\"]:addNotification(root,\"Hibás felhasználónév/jelszó!\",\'error\') endendaddEventHandler(\"loginPlayer\", getRootElement(),loginPlayer)addEvent(\"registerPlayer\", true)function registerPlayer(player, username, password, email, serial, ip, money) local serial = getPlayerSerial(player) local check = exports.mta_connection:_QuerySingle(\"SELECT * FROM accounts WHERE serial = ?\",serial) if ( check ~= serial ) then local account = getAccount(username) if account == false then local ip = getPlayerIP(player) local money = 100 exports.mta_connection:_Exec(\"INSERT INTO accounts(username,password,email,serial,ip,money) values (?,?,?,?,?,?)\",username,password,email,serial,ip,money) local addAccount = addAccount(tostring(username), tostring(password)) if addAccount then exports[\"notices\"]:addNotification(root,\"A felhasználó sikeresen létrehozva!\",\'succes\') else exports[\"notices\"]:addNotification(root,\"Hiba történt! Keress fel egy fejlesztőt a problémával kapcsolatban!\",\'error\') end else exports[\"notices\"]:addNotification(root,\"Ez a felhasználónév már foglalt! Válassz másikat!\",\'error\') end else exports[\"notices\"]:addNotification(root,\"Ehhez a számítógéphez van felhasználó társítva!\",\'error\') endendaddEventHandler(\"registerPlayer\", getRootElement(), registerPlayer)
local serial = getPlayerSerial(player)local query = dbQuery(connect,\"SELECT * FROM accounts WHERE serial = serial\", serial)local result, num_rows = dbPoll(query, -1)if not ( result == nil ) then outputServerLog(result[1][\"serial\"])else dbFree(query)end
local connection = niladdEventHandler(\"onResourceStart\",resourceRoot,function(resource) connection = dbConnect(\"mysql\",\"dbname=ig_mta;host=localhost;port=3306;\",\"root\",\"martinka02\") if connection then outputDebugString(getResourceName(resource) .. \" : connected to database.\") return true else outputDebugString(getResourceName(resource) .. \" : Unable to connect with database. Please contact Developer.\") return false end end)function _Query( ... ) if connection then local query = dbQuery(connection, ... ) local result = dbPoll(query,-1) return result else return false endendfunction _QuerySingle(str,...) if connection then local result = _Query(str,...) if type(result) == \'table\' then return result[1] end else return false endendfunction _Exec(str,...) if connection then local query = dbExec(connection,str,...) return query else return false endend