Guest User

Untitled

a guest
May 8th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. --------------------------
  2. -- Login panel by NeXTreme
  3. --------------------------
  4.  
  5.  
  6. -- Login handling
  7. function loginPlayer(username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts)
  8. if not (username == "") then
  9. if not (password == "") then
  10. local account = getAccount ( username, password )
  11. if ( account ~= false ) then
  12. logIn (source, account, password)
  13. outputChatBox ("#0000FF* #FFFFFFYou have sucessfully logged in!",source,255,255,255,true)
  14. setTimer(outputChatBox,700,1,"#0000FF* #FFFFFFTo enable auto-login, use #ABCDEF/enableauto#FFFFFF!",source,255,255,255,true)
  15. triggerClientEvent (source,"hideLoginWindow",getRootElement())
  16. else
  17. if enableKickPlayer == true then
  18. if (attemptedLogins >= maxLoginAttempts-1) then
  19. outputChatBox ("#0000FF* #FFFFFFError! Wrong username and/or password!",source,255,255,255,true)
  20. setTimer(outputChatBox,500,1,"#0000FF* #FFFFFFWarning! Maximum login attempts reached! [#008AFF"..attemptedLogins+1 .."/"..maxLoginAttempts.."#FFFFFF]",source,255,255,255,true)
  21. setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFYou will be kicked in #008AFF5 seconds#FFFFFF!",source,255,255,255,true)
  22. setTimer(kickPlayer,5000,1,source,"Failed to login")
  23. else
  24. outputChatBox ("#0000FF* #FFFFFFError! Wrong username and/or password!",source,255,255,255,true)
  25. setTimer(outputChatBox,500,1,"#0000FF* #FFFFFFLogin attempts: [#008AFF"..attemptedLogins+1 .."/"..maxLoginAttempts.."#FFFFFF]",source,255,255,255,true)
  26. triggerClientEvent(source,"onRequestIncreaseAttempts",source)
  27. end
  28. else
  29. outputChatBox ("#0000FF* #FFFFFFError! Wrong username and/or password!",source,255,255,255,true)
  30. end
  31. end
  32. else
  33. outputChatBox ("#0000FF* #FFFFFFError! Please enter your password!",source,255,255,255,true)
  34. end
  35. else
  36. outputChatBox ("#0000FF* #FFFFFFError! Please enter your username!",source,255,255,255,true)
  37. end
  38. end
  39.  
  40.  
  41.  
  42. -- Registration here
  43. function registerPlayer(username,password,passwordConfirm)
  44. if not (username == "") then
  45. if not (password == "") then
  46. if not (passwordConfirm == "") then
  47. if password == passwordConfirm then
  48. local account = getAccount (username,password)
  49. if (account == false) then
  50. local accountAdded = addAccount(tostring(username),tostring(password))
  51. if (accountAdded) then
  52. triggerClientEvent(source,"hideRegisterWindow",getRootElement())
  53. outputChatBox ("#0000FF* #FFFFFFYou have sucessfuly registered! [Username: #ABCDEF" .. username .. " #FF0000| #FFFFFFPassword: #ABCDEF" .. password .. "#FFFFFF]",source,255,255,255,true )
  54. setTimer(outputChatBox,800,1,"#0000FF* #FFFFFFYou can now login with your new account.",source,255,255,255,true )
  55. else
  56. outputChatBox ("#0000FF* #FFFFFFAn unknown error has occured! Please choose a different username/password and try again.",source,255,255,255,true )
  57. end
  58. else
  59. outputChatBox ("#0000FF* #FFFFFFError! An account with this username already exists!",source,255,255,255,true )
  60. end
  61. else
  62. outputChatBox ("#0000FF* #FFFFFFError! Passwords do not match!",source,255,255,255,true)
  63. end
  64. else
  65. outputChatBox ("#0000FF* #FFFFFFError! Please confirm your password!",source,255,255,255,true)
  66. end
  67. else
  68. outputChatBox ("#0000FF* #FFFFFFError! Please enter a password!",source,255,255,255,true)
  69. end
  70. else
  71. outputChatBox ("#0000FF* #FFFFFFError! Please enter a username you would like to register with!",source,255,255,255,true)
  72. end
  73. end
  74.  
  75.  
  76.  
  77. -- Auto-login handling
  78. function autologinPlayer(username,password)
  79. if not (username == "") then
  80. if not (password == "") then
  81. local account = getAccount ( username, password )
  82. if not (account == false) then
  83. logIn (source, account, password)
  84. outputChatBox("#0000FF* #FFFFFFYou have been automatically logged in.",source,255,255,255,true)
  85. setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFTo disable auto-login, use #ABCDEF/disableauto.",source,255,255,255,true)
  86. triggerClientEvent ( source, "hideLoginWindow", getRootElement())
  87. else
  88. outputChatBox ("#FF0000* #FFFFFFAuto-login error - Username & password do not match",source,255,255,255,true)
  89. end
  90. else
  91. outputChatBox ("#FF0000* #FFFFFFAuto-login error - Failed to retrieve password",source,255,255,255,true)
  92. end
  93. else
  94. outputChatBox ("#FF0000* #FFFFFFAuto-login error - Failed to retrieve username",source,255,255,255,true)
  95. end
  96. end
  97.  
  98.  
  99.  
  100. -- When the player logs out, trigger the client event to check if the login panel will request them to login again
  101. function logoutHandler()
  102. triggerClientEvent(source,"onRequestDisplayPanel",source)
  103. end
  104. addEventHandler("onPlayerLogout",getRootElement(),logoutHandler)
  105.  
  106.  
  107.  
  108.  
  109. -- Get the server's name
  110. function getData()
  111. local sName = string.gsub(getServerName()," ","")
  112. triggerClientEvent(source,"onGetServerData",getRootElement(),sName)
  113. end
  114.  
  115.  
  116.  
  117.  
  118. addEvent("onRequestLogin",true)
  119. addEvent("onRequestRegister",true)
  120. addEvent("onRequestAutologin",true)
  121. addEvent("onClientLoginLoaded",true)
  122. addEventHandler("onRequestLogin",getRootElement(),loginPlayer)
  123. addEventHandler("onRequestRegister",getRootElement(),registerPlayer)
  124. addEventHandler("onRequestAutologin",getRootElement(),autologinPlayer)
  125. addEventHandler("onClientLoginLoaded",getRootElement(),getData)
Add Comment
Please, Sign In to add comment