Hey,
ich hab ja ein Login/Register Panel gemacht und man kann nur einen Account erstellen.
Weitere werden nicht angelegt obowohl in der Chatbox steht das er angelegt wurde. Keine Fehler!
Code:
Server:
Lua
addEvent("onRegister",true)
addEvent("onLogin",true)
function resourceStart ()
handler = dbConnect("mysql", "dbname=**;host=**", "**, "**")
if handler then
outputServerLog("[Login]: Verbindung zum Datenbank Server erfolgreich!")
else
outputServerLog("[Login]: Verbindung zum Datenbank Server konnte nicht hergestellt werden!")
end
end
addEventHandler("onResourceStart",getResourceRootElement(), resourceStart)
function onRegister (Name, Password)
local sql = dbQuery(handler,"SELECT * FROM players WHERE Name = '"..Name.."'")
local result, num_rows = dbPoll(sql,-1)
if num_rows == 0 then
local Passwordverschluesselt = md5 (Password)
dbExec(handler,"INSERT INTO players (Name, Password) VALUES ( '"..Name.."','"..Passwordverschluesselt.."')")
outputChatBox("[Info]: Du hast dich erfolgreich Registriert!", source, 0,125,0)
triggerClientEvent(source,"closeRegister", source)
else
outputChatBox("[Info]: Du bist bereits Registriert!", source, 125,0,0)
end
end
addEventHandler("onRegister",getRootElement(), onRegister)
function onLogin (Name, Password)
local Passwordverschluesselt = md5 (Password)
local sql = dbQuery(handler, "SELECT * FROM players WHERE Name = '"..Name.."' AND Password ='"..Passwordverschluesselt.."'")
local result, num_rows =dbPoll(sql,-1)
if num_rows == 1 then
outputChatBox("[Info]: Du hast dich erfolgreich eingeloggt!",source, 0,125,0)
triggerClientEvent(source,"closeLogin", source)
else
outputChatBox("[Info]: Dein Passwort oder dein Name ist falsch!", source, 125,0,0)
end
end
addEventHandler("onLogin",getRootElement(), onLogin)
Alles anzeigen
Client:
Lua
Login = {
tab = {},
tabpanel = {},
edit = {},
button = {},
window = {},
label = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
function()
local screenW, screenH = guiGetScreenSize()
Login.window[1] = guiCreateWindow((screenW - 401) / 2, (screenH - 168) / 2, 401, 168, "Login/Register", false)
guiWindowSetSizable(Login.window[1], false)
Login.tabpanel[1] = guiCreateTabPanel(10, 30, 381, 128, false, Login.window[1])
Login.tab[1] = guiCreateTab("Login", Login.tabpanel[1])
Login.label[1] = guiCreateLabel(7, 12, 64, 20, "Name:", false, Login.tab[1])
Login.label[2] = guiCreateLabel(7, 47, 64, 20, "Password:", false, Login.tab[1])
Login.edit[1] = guiCreateEdit(81, 10, 126, 26, "", false, Login.tab[1])
Login.edit[2] = guiCreateEdit(81, 41, 126, 26, "", false, Login.tab[1])
Login.button[1] = guiCreateButton(274, 70, 97, 29, "Login", false, Login.tab[1])
guiSetProperty(Login.button[1], "NormalTextColour", "FFFFFFFF")
Login.label[3] = guiCreateLabel(8, 82, 169, 16, "UTS | Unlimited Tactics Server", false, Login.tab[1])
guiLabelSetColor(Login.label[3], 255, 17, 11)
addEventHandler("onClientGUIClick",Login.button[1], onLogin, false)
Login.button[3] = guiCreateButton(192, 81, 56, 17, "Guest", false, Login.tab[1])
guiSetProperty(Login.button[3], "NormalTextColour", "FFEC0AF4")
guiEditSetMasked(Login.edit[2],true)
showCursor(true)
Login.tab[2] = guiCreateTab("Register", Login.tabpanel[1])
Login.label[4] = guiCreateLabel(8, 13, 58, 18, "Name:", false, Login.tab[2])
Login.label[5] = guiCreateLabel(8, 41, 58, 18, "Password:", false, Login.tab[2])
Login.edit[3] = guiCreateEdit(77, 12, 123, 25, "", false, Login.tab[2])
Login.edit[4] = guiCreateEdit(77, 41, 123, 25, "", false, Login.tab[2])
Login.button[2] = guiCreateButton(293, 69, 78, 25, "Register", false, Login.tab[2])
Login.label[6] = guiCreateLabel(8, 84, 202, 15, "UTS | Unlimited Tactics Server", false, Login.tab[2])
guiEditSetMasked(Login.edit[4],true)
guiLabelSetColor(Login.label[6], 255, 11, 11)
addEventHandler("onClientGUIClick",Login.button[2], onRegister, false)
addEventHandler("onClientGUIClick",Login.button[3], close1, false)
end
)
addEvent("closeLogin",true)
addEventHandler("closeLogin",getRootElement(), function()
showCursor(false)
guiSetVisible(Login.window[1],false)
end
)
addEvent("closeRegister",true)
addEventHandler("closeRegister",getRootElement(), function()
showCursor(false)
guiSetVisible(Login.window[1],false)
end
)
function close1()
showCursor(false)
guiSetVisible(Login.window[1],false)
outputChatBox("[Info]: Du spielst nun als Gast!", 255,255,255)
end
function onLogin ()
local Name = guiGetText(Login.edit[1])
local Password = guiGetText (Login.edit[2])
if Password:len() >= 6 then
triggerServerEvent("onLogin",getLocalPlayer(),Name,Password)
else
outputChatBox("Dein Password muss mindestens 6 Zeichen lang sein!", 125,0,0)
end
end
function onRegister ()
local Name = guiGetText(Login.edit[3])
local Password = guiGetText (Login.edit[4])
if Password:len() >= 6 then
triggerServerEvent("onRegister",getLocalPlayer(),Name,Password)
else
outputChatBox("Dein Password muss mindestens 6 Zeichen lang sein!", 125,0,0)
end
end
Alles anzeigen