Guest User

Untitled

a guest
May 8th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.97 KB | None | 0 0
  1. ----------------------------------
  2. -----------| Settings |-----------
  3. ----------------------------------
  4.  
  5. blackLoginScreen = true -- Set to 'true' to display a black screen to the player untill they log in or choose to play as a guest.
  6.  
  7. enableKickPlayer = true -- Set whether to kick the player after they fail to login specified amount of times.
  8.  
  9. disallowLogout = false -- Set whether to show the userpanel to the players if they log out of their accounts.
  10.  
  11. removeBlackScreenTime = 4 -- The time it takes for the black screen to dissapear - If you choose to display the black screen. [IN SECONDS]
  12.  
  13. maxLoginAttempts = 5 -- Set the maximum incorrect login attempts before the player gets kicked - If player kicking is enabled.
  14.  
  15. ----------------------------------
  16.  
  17.  
  18.  
  19. -- Set the text you want displayed in the "rules" window here - use '\n' to go into the next line
  20. infoText = "------ Rules ------ \n\n* No cheating!\n* No insulting and spamming!\n* No Hacking\n\nEdit the text however you like\n\n\n\n\n\n\n\nLogin panel by Ravi"
  21.  
  22.  
  23.  
  24. -- Screen and GUI window sizes
  25. screenWidth,screenHeight = guiGetScreenSize()
  26. mainWidth,mainHeight = 749,472
  27. regWidth,regHeight = 439,344
  28.  
  29.  
  30. -- Generate the XML file name
  31. function getServerName()
  32. triggerServerEvent("onClientLoginLoaded",getLocalPlayer())
  33. end
  34. addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerName)
  35.  
  36. function setXmlFileName(sName)
  37. xmlFileName = tostring("login_"..sName..".xml")
  38. loginPanel()
  39. end
  40. addEvent("onGetServerData",true)
  41. addEventHandler("onGetServerData",getRootElement(),setXmlFileName)
  42.  
  43.  
  44.  
  45.  
  46.  
  47. ----------------------------------
  48.  
  49. addEvent("onRequestIncreaseAttempts",true)
  50. addEvent("onRequestDisplayPanel",true)
  51.  
  52. function loginPanel()
  53. -- Check if autologin is enabled - If yes, then log the player in, else create and show the userpanel
  54. local xmlFile = xmlLoadFile(xmlFileName)
  55. if xmlFile then
  56. status = xmlNodeGetAttribute(xmlFile,"autologin")
  57. if (status == "true") then
  58. local username = tostring(xmlNodeGetAttribute(xmlFile,"username"))
  59. local password = tostring(xmlNodeGetAttribute(xmlFile,"password"))
  60. if not (username == "") and not (password == "") then
  61. triggerServerEvent("onRequestAutologin",getLocalPlayer(),username,password)
  62. end
  63. else
  64. if blackLoginScreen == true then
  65. fadeCamera(false,0,0,0,0)
  66. end
  67. mainWindow = guiCreateWindow(screenWidth/2-mainWidth/2,screenHeight/2-mainHeight/2,mainWidth,mainHeight,"Login panel",false)
  68. guiWindowSetSizable(mainWindow,false)
  69.  
  70. mInfo = guiCreateMemo(21,36,411,278,infoText,false,mainWindow)
  71. guiMemoSetReadOnly(mInfo,true)
  72.  
  73. editUsername = guiCreateEdit(53,364,187,25,"",false,mainWindow)
  74. guiEditSetMaxLength(editUsername,30)
  75.  
  76. editPassword = guiCreateEdit(53,421,187,25,"",false,mainWindow)
  77. guiEditSetMaxLength(editPassword,30)
  78. guiEditSetMasked(editPassword,true)
  79.  
  80. lblUsername = guiCreateLabel(67,330,158,38,"Username:",false,mainWindow)
  81. guiLabelSetColor(lblUsername,0,85,255)
  82. guiLabelSetVerticalAlign(lblUsername,"center")
  83. guiLabelSetHorizontalAlign(lblUsername,"center",false)
  84. guiSetFont(lblUsername,"default-bold-small")
  85.  
  86. lblPassword = guiCreateLabel(67,389,158,38,"Password:",false,mainWindow)
  87. guiLabelSetColor(lblPassword,0,85,255)
  88. guiLabelSetVerticalAlign(lblPassword,"center")
  89. guiLabelSetHorizontalAlign(lblPassword,"center",false)
  90. guiSetFont(lblPassword,"default-bold-small")
  91.  
  92. btnPlayAsGuest = guiCreateButton(548,368,168,74,"Play as guest",false,mainWindow)
  93. guiSetFont(btnPlayAsGuest,"default-bold-small")
  94.  
  95. btnLogin = guiCreateButton(280,368,242,74,"Login",false,mainWindow)
  96. guiSetFont(btnLogin,"sa-header")
  97.  
  98. btnToggleRegister = guiCreateButton(490,246,206,68,"Register an account",false,mainWindow)
  99. guiSetFont(btnToggleRegister,"default-bold-small")
  100.  
  101. registerWindow = guiCreateWindow(screenWidth/2-regWidth/2,screenHeight/2-regHeight/2,regWidth,regHeight,"Registration",false)
  102. guiWindowSetSizable(registerWindow,false)
  103.  
  104. editRegistrationUsername = guiCreateEdit(98,138,242,25,"",false,registerWindow)
  105.  
  106. editRegistrationPassword = guiCreateEdit(98,195,242,25,"",false,registerWindow)
  107. guiEditSetMasked(editRegistrationPassword,true)
  108.  
  109. editRegistrationRepeatPassword = guiCreateEdit(99,252,242,25,"",false,registerWindow)
  110. guiEditSetMasked(editRegistrationRepeatPassword,true)
  111.  
  112. lblRegister = guiCreateLabel(24,24,391,97,"Register",false,registerWindow)
  113. guiLabelSetColor(lblRegister,0,85,255)
  114. guiLabelSetVerticalAlign(lblRegister,"center")
  115. guiLabelSetHorizontalAlign(lblRegister,"center",false)
  116. guiSetFont(lblRegister,"sa-gothic")
  117.  
  118. lblRUsername = guiCreateLabel(98,113,242,17,"Username:",false,registerWindow)
  119. guiLabelSetColor(lblRUsername,0,85,255)
  120. guiLabelSetVerticalAlign(lblRUsername,"center")
  121. guiLabelSetHorizontalAlign(lblRUsername,"center",false)
  122. guiSetFont(lblRUsername,"default-bold-small")
  123.  
  124. lblRPassword = guiCreateLabel(98,171,242,17,"Password:",false,registerWindow)
  125. guiLabelSetColor(lblRPassword,0,85,255)
  126. guiLabelSetVerticalAlign(lblRPassword,"center")
  127. guiLabelSetHorizontalAlign(lblRPassword,"center",false)
  128. guiSetFont(lblRPassword,"default-bold-small")
  129.  
  130. lblRepeatPassword = guiCreateLabel(98,230,242,17,"Repeat password:",false,registerWindow)
  131. guiLabelSetColor(lblRepeatPassword,0,85,255)
  132. guiLabelSetVerticalAlign(lblRepeatPassword,"center")
  133. guiLabelSetHorizontalAlign(lblRepeatPassword,"center",false)
  134. guiSetFont(lblRepeatPassword,"default-bold-small")
  135.  
  136. btnCancel = guiCreateButton(232,292,179,38,"Cancel",false,registerWindow)
  137. guiSetFont(btnCancel,"default-bold-small")
  138.  
  139. btnConfirmRegistration = guiCreateButton(29,292,179,38,"Confirm & register!",false,registerWindow)
  140. guiSetFont(btnConfirmRegistration,"default-bold-small")
  141.  
  142. guiCreateStaticImage(440,23,300,225,"logo.png",false,mainWindow)
  143.  
  144. guiSetVisible(mainWindow, true)
  145. guiSetVisible(registerWindow, false)
  146. guiSetInputEnabled(true)
  147. showCursor(true)
  148. addEventHandler("onClientGUIClick",btnLogin,onClickLogin)
  149. addEventHandler("onClientGUIClick",btnToggleRegister,onClickRegisterToggle)
  150. addEventHandler("onClientGUIClick",btnPlayAsGuest,onClickGuest)
  151. addEventHandler("onClientGUIClick",btnConfirmRegistration,onClickRegisterConfirm)
  152. addEventHandler("onClientGUIClick",btnCancel,onClickCancel)
  153. addEventHandler("onRequestIncreaseAttempts",getRootElement(),increaseAttempts)
  154. attemptedLogins = 0
  155. end
  156. xmlUnloadFile(xmlFile)
  157. else
  158. xmlFileHandler(true)
  159. end
  160. addEventHandler("onRequestDisplayPanel",getRootElement(),logoutHandler)
  161. end
  162. --addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),loginPanel)
  163.  
  164.  
  165.  
  166. -- Disable autologin
  167. function removeAutoLogin()
  168. local xmlFile = xmlLoadFile(xmlFileName)
  169. if xmlFile then
  170. local status = xmlNodeGetAttribute(xmlFile,"autologin")
  171. if status == "true" then
  172. xmlNodeSetAttribute(xmlFile,"autologin","false")
  173. outputChatBox("#0000FF* #FFFFFFAuto-login is now #FF0000DISABLED#FFFFFF!",255,255,255,true)
  174. xmlSaveFile(xmlFile)
  175. xmlUnloadFile(xmlFile)
  176. else
  177. outputChatBox("#0000FF* #FFFFFFAuto-login is already #FF0000DISABLED#FFFFFF!",255,255,255,true)
  178. xmlUnloadFile(xmlFile)
  179. end
  180. end
  181. end
  182. addCommandHandler("disableauto", removeAutoLogin)
  183.  
  184.  
  185.  
  186. -- Enable autologin
  187. function addAutoLogin()
  188. local xmlFile = xmlLoadFile(xmlFileName)
  189. if xmlFile then
  190. local status = xmlNodeGetAttribute(xmlFile,"autologin")
  191. if status == "false" then
  192. xmlNodeSetAttribute(xmlFile,"autologin","true")
  193. outputChatBox("#0000FF* #FFFFFFAuto-login is now #00FF00ENABLED#FFFFFF! You will be automatically logged in every time you join the server.",255,255,255,true)
  194. setTimer(outputChatBox,1000,1,"#0000FF* #FFFFFFTo #FF0000DISABLE#FFFFFF auto-login, use #ABCDEF/disableauto#FFFFFF!",255,255,255,true)
  195. xmlSaveFile(xmlFile)
  196. xmlUnloadFile(xmlFile)
  197. else
  198. outputChatBox("#0000FF* #FFFFFFAuto-login is already #00FF00ENABLED#FFFFFF!",255,255,255,true)
  199. xmlUnloadFile(xmlFile)
  200. end
  201. end
  202. end
  203. addCommandHandler("enableauto", addAutoLogin)
  204.  
  205.  
  206.  
  207. -- LOGIN PLAYER
  208. function onClickLogin(button,state)
  209. if(button == "left" and state == "up") then
  210. if (source == btnLogin) then
  211. username = guiGetText(editUsername)
  212. password = guiGetText(editPassword)
  213. triggerServerEvent("onRequestLogin",getLocalPlayer(),username,password,enableKickPlayer,attemptedLogins,maxLoginAttempts)
  214. xmlFileHandler()
  215. end
  216. end
  217. end
  218.  
  219.  
  220.  
  221. -- REGISTER PLAYER
  222. function onClickRegisterConfirm(button,state)
  223. if(button == "left" and state == "up") then
  224. if (source == btnConfirmRegistration) then
  225. username = guiGetText(editRegistrationUsername)
  226. password = guiGetText(editRegistrationPassword)
  227. passwordConfirm = guiGetText(editRegistrationRepeatPassword)
  228. triggerServerEvent("onRequestRegister",getLocalPlayer(),username,password,passwordConfirm)
  229. end
  230. end
  231. end
  232.  
  233.  
  234.  
  235. -- Open registration window
  236. function onClickRegisterToggle(button,state)
  237. if(button == "left" and state == "up") then
  238. if (source == btnToggleRegister) then
  239. guiSetVisible(registerWindow, true)
  240. guiBringToFront(registerWindow)
  241. guiSetInputEnabled(true)
  242. showCursor(true)
  243. end
  244. end
  245. end
  246.  
  247.  
  248.  
  249. -- Cancel registration
  250. function onClickCancel(button,state)
  251. if(button == "left" and state == "up") then
  252. if (source == btnCancel) then
  253. guiSetVisible(mainWindow, true)
  254. guiSetVisible(registerWindow, false)
  255. guiSetInputEnabled(true)
  256. showCursor(true)
  257. end
  258. end
  259. end
  260.  
  261.  
  262.  
  263. -- Guest mode
  264. function onClickGuest(button,state)
  265. if(button == "left" and state == "up") then
  266. if (source == btnPlayAsGuest) then
  267. guiSetVisible(mainWindow, false)
  268. guiSetVisible(registerWindow, false)
  269. guiSetInputEnabled(false)
  270. showCursor(false)
  271. outputChatBox("#0000FF* #FFFFFFYou've chosen to play as a #ABCDEFGUEST#FFFFFF!",255,255,255,true)
  272. if blackLoginScreen == true then
  273. fadeCamera(true,removeBlackScreenTime)
  274. end
  275. end
  276. end
  277. end
  278.  
  279.  
  280.  
  281. -- Show login window
  282. function showLoginWindow()
  283. guiSetVisible(mainWindow, true)
  284. guiSetVisible(registerWindow, false)
  285. guiSetInputEnabled(true)
  286. showCursor(true)
  287. end
  288. addEvent("showLoginWindow", true)
  289. addEventHandler("showLoginWindow",getRootElement(),showLoginWindow)
  290.  
  291.  
  292.  
  293. -- Hide login window
  294. function hideLoginWindow()
  295. guiSetInputEnabled(false)
  296. guiSetVisible(mainWindow, false)
  297. guiSetVisible(registerWindow, false)
  298. showCursor(false)
  299. if blackLoginScreen == true then
  300. fadeCamera(true,removeBlackScreenTime)
  301. end
  302. end
  303. addEvent("hideLoginWindow", true)
  304. addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow)
  305.  
  306.  
  307.  
  308. -- Hide register window
  309. function hideRegisterWindow()
  310. guiSetInputEnabled(true)
  311. guiSetVisible(mainWindow, true)
  312. guiSetVisible(registerWindow, false)
  313. showCursor(true)
  314. end
  315. addEvent("hideRegisterWindow", true)
  316. addEventHandler("hideRegisterWindow", getRootElement(), hideRegisterWindow)
  317.  
  318.  
  319. -- Show login panel when a player logs out if 'dissalowLogout' is set to TRUE
  320. function logoutHandler()
  321. if (disallowLogout == true) then
  322. loginPanel()
  323. setTimer(outputChatBox,600,1,"#0000FF* #FFFFFFWarning! You have logged out. Please login again.",255,255,255,true)
  324. end
  325. end
  326.  
  327. -----------------------------------------------------------------------------------------------|
  328.  
  329. -- XML File Handler
  330. function xmlFileHandler(gReturn)
  331. local xmlFile = xmlLoadFile(xmlFileName)
  332. if not xmlFile then
  333. xmlFile = xmlCreateFile(xmlFileName,"settings")
  334. xmlNodeSetAttribute(xmlFile,"autologin","false")
  335. end
  336. xmlNodeSetAttribute(xmlFile,"username",tostring(guiGetText(editUsername)))
  337. xmlNodeSetAttribute(xmlFile,"password",tostring(guiGetText(editPassword)))
  338. xmlSaveFile(xmlFile)
  339. xmlUnloadFile(xmlFile)
  340. if (gReturn) then
  341. if (gReturn == true) then
  342. loginPanel()
  343. else
  344. return
  345. end
  346. end
  347. end
  348.  
  349.  
  350. -- Increase Login Attepts
  351. function increaseAttempts()
  352. attemptedLogins = attemptedLogins+1
  353. end
Add Comment
Please, Sign In to add comment