----------------------------------
-----------| Settings |-----------
----------------------------------
blackLoginScreen = true -- Set to 'true' to display a black screen to the player untill they log in or choose to play as a guest.
enableKickPlayer = true -- Set whether to kick the player after they fail to login specified amount of times.
disallowLogout = false -- Set whether to show the userpanel to the players if they log out of their accounts.
removeBlackScreenTime = 4 -- The time it takes for the black screen to dissapear - If you choose to display the black screen. [IN SECONDS]
maxLoginAttempts = 5 -- Set the maximum incorrect login attempts before the player gets kicked - If player kicking is enabled.
----------------------------------
-- Screen and GUI window sizes
screenWidth,screenHeight = guiGetScreenSize()
mainWidth,mainHeight = 749,472
regWidth,regHeight = 439,344
-- Generate the XML file name
myFont = guiCreateFont( "verdana.ttf", 13 )
myFont2 = guiCreateFont( "verdana.ttf", 9 )
myFont3 = guiCreateFont( "verdana.ttf", 8 )
myFont4 = guiCreateFont( "verdana.ttf", 18 )
function getServerName()
triggerServerEvent("onClientLoginLoaded",getLocalPlayer())
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerName)
sound = playSound("Som/music.mp3",true) -- Iniciar a música
function setXmlFileName(sName)
xmlFileName = tostring("ContaLMTactics_"..sName..".xml")
loginPanel()
end
addEvent("onGetServerData",true)
addEventHandler("onGetServerData",getRootElement(),setXmlFileName)
----------------------------------
addEvent("onRequestIncreaseAttempts",true)
addEvent("onRequestDisplayPanel",true)
function loginPanel()
-- Check if autologin is enabled - If yes, then log the player in, else create and show the userpanel
local xmlFile = xmlLoadFile(xmlFileName)
if xmlFile then
status = xmlNodeGetAttribute(xmlFile,"autologin")
if (status == "true") then
local username = tostring(xmlNodeGetAttribute(xmlFile,"user"))
local password = tostring(xmlNodeGetAttribute(xmlFile,"pass"))
if not (username == "") and not (password == "") then
triggerServerEvent("onRequestAutologin",getLocalPlayer(),username,password)
end
else
if blackLoginScreen == true then
fadeCamera(false,0,0,0,0)
end
mainWindow = guiCreateWindow(412, 157, 387, 456, "Login [BR-PT]", false)
guiWindowSetSizable(mainWindow, false)
guiSetAlpha(mainWindow, 1.00)
editUsername = guiCreateEdit(93, 116, 187, 25,"",false,mainWindow)
guiEditSetMaxLength(editUsername,30)
editPassword = guiCreateEdit(93, 199, 187, 25,"",false,mainWindow)
guiEditSetMaxLength(editPassword,30)
guiEditSetMasked(editPassword,true)
lblUsername = guiCreateLabel(103, 68, 158, 38,"Usuario:",false,mainWindow)
guiLabelSetColor(lblUsername,254, 254, 254)
guiLabelSetVerticalAlign(lblUsername,"center")
guiLabelSetHorizontalAlign(lblUsername,"center",false)
guiSetFont(lblUsername,myFont2)
lblPassword = guiCreateLabel(103, 151, 158, 38,"Senha:",false,mainWindow)
guiLabelSetColor(lblPassword,254, 254, 254)
guiLabelSetVerticalAlign(lblPassword,"center")
guiLabelSetHorizontalAlign(lblPassword,"center",false)
guiSetFont(lblPassword,myFont2)
btnLogin = guiCreateButton(108, 260, 162, 44,"Login",false,mainWindow)
guiSetFont(btnLogin,myFont)
btnToggleRegister = guiCreateButton(92, 340, 198, 60,"Criar Uma Conta",false,mainWindow)
guiSetFont(btnToggleRegister,myFont)
registerWindow = guiCreateWindow(screenWidth/2-regWidth/2,screenHeight/2-regHeight/2,regWidth,regHeight,"Registro LM Tactics Server v1.2 By Jonas",false)
guiWindowSetSizable(registerWindow,false)
guiSetAlpha(registerWindow, 1.00)
editRegistrationUsername = guiCreateEdit(98, 90, 242, 25,"",false,registerWindow)
editRegistrationPassword = guiCreateEdit(98, 162, 242, 25,"",false,registerWindow)
guiEditSetMasked(editRegistrationPassword,true)
editRegistrationRepeatPassword = guiCreateEdit(93, 240, 242, 25,"",false,registerWindow)
guiEditSetMasked(editRegistrationRepeatPassword,true)
lblRUsername = guiCreateLabel(98, 56, 242, 17,"Usuario:",false,registerWindow)
guiLabelSetColor(lblRUsername,254, 254, 254)
guiLabelSetVerticalAlign(lblRUsername,"center")
guiLabelSetHorizontalAlign(lblRUsername,"center",false)
guiSetFont(lblRUsername,myFont2)
lblRPassword = guiCreateLabel(98, 130, 242, 17,"Senha:",false,registerWindow)
guiLabelSetColor(lblRPassword,254, 254, 254)
guiLabelSetVerticalAlign(lblRPassword,"center")
guiLabelSetHorizontalAlign(lblRPassword,"center",false)
guiSetFont(lblRPassword,myFont2)
lblRepeatPassword = guiCreateLabel(99, 203, 242, 17,"Confirme sua senha:",false,registerWindow)
guiLabelSetColor(lblRepeatPassword,254, 254, 254)
guiLabelSetVerticalAlign(lblRepeatPassword,"center")
guiLabelSetHorizontalAlign(lblRepeatPassword,"center",false)
guiSetFont(lblRepeatPassword,myFont2)
btnCancel = guiCreateButton(232, 292, 179, 38,"Cancelar",false,registerWindow)
guiSetFont(btnCancel,myFont2)
btnConfirmRegistration = guiCreateButton(29,292,179,38,"Registrar",false,registerWindow)
guiSetFont(btnConfirmRegistration,myFont2)
guiSetVisible(mainWindow, true)
guiSetVisible(registerWindow, false)
guiSetInputEnabled(true)
showCursor(true)
addEventHandler("onClientGUIClick",btnLogin,onClickLogin)
addEventHandler("onClientGUIClick",btnToggleRegister,onClickRegisterToggle)
addEventHandler("onClientGUIClick",btnConfirmRegistration,onClickRegisterConfirm)
addEventHandler("onClientGUIClick",btnCancel,onClickCancel)
addEventHandler("onRequestIncreaseAttempts",getRootElement(),increaseAttempts)
attemptedLogins = 0
end
xmlUnloadFile(xmlFile)
else
xmlFileHandler(true)
end
addEventHandler("onRequestDisplayPanel",getRootElement(),logoutHandler)
end
--addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),loginPanel)
-- Desativar Auto Login
function removeAutoLogin()
local xmlFile = xmlLoadFile(xmlFileName)
if xmlFile then
local status = xmlNodeGetAttribute(xmlFile,"autologin")
if status == "true" then
xmlNodeSetAttribute(xmlFile,"autologin","false")
outputChatBox("#FF0000[INFO] - #FFFFFFAuto-login #FF0000Desativado!",255,255,255,true)
xmlSaveFile(xmlFile)
xmlUnloadFile(xmlFile)
else
outputChatBox("#FF0000[INFO] - #FFFFFFAuto-login já está #FF0000Desativado!",255,255,255,true)
xmlUnloadFile(xmlFile)
end
end
end
addCommandHandler("desativarauto", removeAutoLogin)
-- Ativar autologin
function addAutoLogin()
local xmlFile = xmlLoadFile(xmlFileName)
if xmlFile then
local status = xmlNodeGetAttribute(xmlFile,"autologin")
if status == "false" then
xmlNodeSetAttribute(xmlFile,"autologin","true")
outputChatBox("#00FF00[INFO] - #FFFFFFAuto-login #00FF00Ativado!",255,255,255,true)
setTimer(outputChatBox,1000,1,"#FF0000[AVISO] - #FFFFFFPara desabilitar o login automático, use #FF0000/desativarauto.",255,255,255,true)
xmlSaveFile(xmlFile)
xmlUnloadFile(xmlFile)
else
outputChatBox("#00FF00[INFO] - #FFFFFFAuto-login já está #00FF00Ativado!",255,255,255,true)
xmlUnloadFile(xmlFile)
end
end
end
addCommandHandler("ativarauto", addAutoLogin)
-- LOGIN PLAYER
function onClickLogin(button,state)
if(button == "left" and state == "up") then
if (source == btnLogin) then
username = guiGetText(editUsername)
password = guiGetText(editPassword)
triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts)
xmlFileHandler()
end
end
end
-- REGISTER PLAYER
function onClickRegisterConfirm(button,state)
if(button == "left" and state == "up") then
if (source == btnConfirmRegistration) then
username = guiGetText(editRegistrationUsername)
password = guiGetText(editRegistrationPassword)
passwordConfirm = guiGetText(editRegistrationRepeatPassword)
triggerServerEvent("onRequestRegister",getLocalPlayer(),username,password,passwordConfirm)
end
end
end
-- Open registration window
function onClickRegisterToggle(button,state)
if(button == "left" and state == "up") then
if (source == btnToggleRegister) then
guiSetVisible(registerWindow, true)
guiBringToFront(registerWindow)
guiSetInputEnabled(true)
showCursor(true)
end
end
end
-- Cancel registration
function onClickCancel(button,state)
if(button == "left" and state == "up") then
if (source == btnCancel) then
guiSetVisible(mainWindow, true)
guiSetVisible(registerWindow, false)
guiSetInputEnabled(true)
showCursor(true)
end
end
end
-- Show login window
function showLoginWindow()
guiSetVisible(mainWindow, true)
guiSetVisible(registerWindow, false)
guiSetInputEnabled(true)
showCursor(true)
end
addEvent("showLoginWindow", true)
addEventHandler("showLoginWindow",getRootElement(),showLoginWindow)
-- Hide login window
function hideLoginWindow()
guiSetInputEnabled(false)
guiSetVisible(mainWindow, false)
guiSetVisible(registerWindow, false)
showCursor(false)
stopSound(sound) -- Parar a música
if blackLoginScreen == true then
fadeCamera(true,removeBlackScreenTime)
end
end
addEvent("hideLoginWindow", true)
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow)
-- Hide register window
function hideRegisterWindow()
guiSetInputEnabled(true)
guiSetVisible(mainWindow, true)
guiSetVisible(registerWindow, false)
showCursor(true)
end
addEvent("hideRegisterWindow", true)
addEventHandler("hideRegisterWindow", getRootElement(), hideRegisterWindow)
-- Show login panel when a player logs out if 'dissalowLogout' is set to TRUE
function logoutHandler()
if (disallowLogout == true) then
loginPanel()
setTimer(outputChatBox,600,1,"#FF0000[AVISO] - #FFFFFF Você foi desconectado. Por favor, faça login novamente.",255,255,255,true)
end
end
-----------------------------------------------------------------------------------------------|
-- XML File Handler
function xmlFileHandler(gReturn)
local xmlFile = xmlLoadFile(xmlFileName)
if not xmlFile then
xmlFile = xmlCreateFile(xmlFileName,"settings")
xmlNodeSetAttribute(xmlFile,"autologin","false")
end
xmlNodeSetAttribute(xmlFile,"user",tostring(guiGetText(editUsername)))
xmlNodeSetAttribute(xmlFile,"pass",tostring(guiGetText(editPassword)))
xmlSaveFile(xmlFile)
xmlUnloadFile(xmlFile)
if (gReturn) then
if (gReturn == true) then
loginPanel()
else
return
end
end
end
-- Increase Login Attepts
function increaseAttempts()
attemptedLogins = attemptedLogins+1
end
é warning