forked from itslewiswatson/ucd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
594 lines (545 loc) · 23.4 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
-------------------------------------------------------------------
--// PROJECT: Union of Clarity and Diversity
--// RESOURCE: UCDaccounts
--// DEVELOPER(S): Lewis Watson (Noki)
--// DATE: 13.12.2014
--// PURPOSE: A login interface.
--// FILE: \UCDaccounts\login\client.lua [client]
-------------------------------------------------------------------
-- XML is the one used to save credentials on a client's computer [We could possibly use a unique signature per person]
-- C2S is the one used to encrypt client-to-server transfer, so we aren't passing plain text (easily snooped)
local keys = {xml = [[7C6933A1239C7493F7F8A71A0EDA9553]], C2S = [[place_hash_here]]}
local sX, sY = guiGetScreenSize()
local nX, nY = 1920, 1080
local login = {edit = {}, button = {}, label = {}, checkbox = {}}
local registration = {button = {}, window = {}, label = {}, edit = {}}
local scale = {
[1] = 2,
[2] = 2,
[3] = 2,
[4] = 2,
[5] = 2,
}
local b2s = {}
local buttons = {
{(567 / nX) * sX, (433 / nY) * sY, dxGetTextWidth("Login", 2, "default-bold"), (30 / nY) * sY},
{(567 / nX) * sX, (483 / nY) * sY, dxGetTextWidth("Register", 2, "default-bold"), (30 / nY) * sY},
{(567 / nX) * sX, (533 / nY) * sY, dxGetTextWidth("About UCD", 2, "default-bold"), (30 / nY) * sY},
{(567 / nX) * sX, (583 / nY) * sY, dxGetTextWidth("Admins Online", 2, "default-bold"), (30 / nY) * sY},
{(567 / nX) * sX, (633 / nY) * sY, dxGetTextWidth("Disconnect", 2, "default-bold"), (30 / nY) * sY},
}
local scalar = 5
if (dxGetTextWidth("Union of Clarity and Diversity", 5, "default-bold") > sX) then
scalar = 3
end
-- Interpolation shit
local start = false
local index
local inout
function centerWindow(center_window)
local windowW, windowH = guiGetSize(center_window, false)
local x, y = (sX - windowW) /2, (sY - windowH) / 2
guiSetPosition(center_window, x, y, false)
end
function trunc()
if (index and start) then
for k, v in pairs(scale) do
if (k == index) then
if (inout == "in") then
local now = getTickCount()
local endTime = start + 500
local elapsed = now - start
local duration = endTime - start
local prog = elapsed / duration
scale[index] = interpolateBetween(Vector3(scale[index], 0, 0), Vector3(3, 0, 0), prog, "Linear")
else
local now = getTickCount()
local endTime = start + 250
local elapsed = now - start
local duration = endTime - start
local prog = elapsed / duration
scale[index] = interpolateBetween(Vector3(scale[index], 0, 0), Vector3(2, 0, 0), prog, "Linear")
if (prog >= 1) then
index = nil
start = false
end
end
else
if (not start) then
return
end
local now = getTickCount()
local endTime = start + 250
local elapsed = now - start
local duration = endTime - start
local prog = elapsed / duration
scale[k] = interpolateBetween(Vector3(scale[k], 0, 0), Vector3(2, 0, 0), prog, "Linear")
end
end
end
end
addEventHandler("onClientRender", root, trunc)
-- Button animations
addEventHandler("onClientMouseEnter", guiRoot,
function ()
if (b2s[source]) then
inout = "in"
index = b2s[source]
start = getTickCount()
end
end
)
addEventHandler("onClientMouseLeave", guiRoot,
function (_, _, o)
if (b2s[source]) then
inout = "out"
index = b2s[source]
start = getTickCount()
end
end
)
function drawElements()
dxDrawRectangle(0, 0, sX, sY, tocolor(0, 0, 0, 75), false, false, false, false)
if (login.button.visible) then
dxDrawText("Remember my credentials", (1086 / nX) * sX, (595 / nY) * sY, (1329 / nX) * sX, (612 / nY) * sY, tocolor(255, 255, 255, 255), 1, "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Account Name", (1047 / nX) * sX, (433 / nY) * sY, (1329 / nX) * sX, (463 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Password", (1047 / nX) * sX, (513 / nY) * sY, (1329 / nX) * sX, (543 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
end
if (registration.button.visible) then
dxDrawText("Account Name", (1047 / nX) * sX, (323 / nY) * sY, (1329 / nX) * sX, (353 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Email", (1047 / nX) * sX, (413 / nY) * sY, (1329 / nX) * sX, (443 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Password", (1047 / nX) * sX, (493 / nY) * sY, (1329 / nX) * sX, (523 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Confirm Password", (1047 / nX) * sX, (573 / nY) * sY, (1329 / nX) * sX, (603 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
--dxDrawText("Account Name", (1047 / nX) * sX, (383 / nY) * sY, (1329 / nX) * sX, (413 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
--dxDrawText("Email", (1047 / nX) * sX, (463 / nY) * sY, (1329 / nX) * sX, (493 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
--dxDrawText("Password", (1047 / nX) * sX, (543 / nY) * sY, (1329 / nX) * sX, (573 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
--dxDrawText("Confirm Password", (1047 / nX) * sX, (623 / nY) * sY, (1329 / nX) * sX, (653 / nY) * sY, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "center", false, false, false, false, true)
end
--dxDrawRectangle((567 / nX) * sX, (433 / nY) * sY, dxGetTextWidth("Login", 2, "default-bold"), (30 / nY) * sY, tocolor(0, 0, 0, 255), false, false, false, false)
--dxDrawRectangle((567 / nX) * sX, (483 / nY) * sY, dxGetTextWidth("Register", 2, "default-bold"), (30 / nY) * sY, tocolor(0, 0, 0, 255), false, false, false, false)
--dxDrawRectangle((567 / nX) * sX, (533 / nY) * sY, dxGetTextWidth("About UCD", 2, "default-bold"), (30 / nY) * sY, tocolor(0, 0, 0, 255), false, false, false, false)
--dxDrawRectangle((567 / nX) * sX, (583 / nY) * sY, dxGetTextWidth("Admins Online", 2, "default-bold"), (30 / nY) * sY, tocolor(0, 0, 0, 255), false, false, false, false)
--dxDrawRectangle((567 / nX) * sX, (633 / nY) * sY, dxGetTextWidth("Disconnect", 2, "default-bold"), (30 / nY) * sY, tocolor(0, 0, 0, 255), false, false, false, false)
dxDrawText("Login", (567 / nX) * sX, (433 / nY) * sY, (725 / nX) * sX, (463 / nY) * sY, tocolor(255, 255, 255, 255), scale[1], "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Register", (567 / nX) * sX, (483 / nY) * sY, (725 / nX) * sX, (513 / nY) * sY, tocolor(255, 255, 255, 255), scale[2], "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("About UCD", (567 / nX) * sX, (533 / nY) * sY, (725 / nX) * sX, (563 / nY) * sY, tocolor(255, 255, 255, 255), scale[3], "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Admins Online", (567 / nX) * sX, (583 / nY) * sY, (725 / nX) * sX, (613 / nY) * sY, tocolor(255, 255, 255, 255), scale[4], "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Disconnect", (567 / nX) * sX, (633 / nY) * sY, (725 / nX) * sX, (663 / nY) * sY, tocolor(255, 255, 255, 255), scale[5], "default-bold", "left", "center", false, false, false, false, true)
dxDrawText("Union of Clarity and Diversity", 0, (150 / nY) * sY, sX, (244 / nY) * sY, tocolor(255, 255, 255, 255), scalar or 5, "default-bold", "center", "center", false, false, false, false, true)
end
function onClientClick(button, state, aX, aY)
-- Register button
local rX, rY = (567 / nX) * sX, (483 / nY) * sY
local rW, rH = rX + dxGetTextWidth("Register", 2, "default-bold"), rY + (30 / nY) * sY
-- Login button
local lX, lY = (567 / nX) * sX, (433 / nY) * sY
local lW, lH = lX + dxGetTextWidth("Login", 2, "default-bold"), lY + (30 / nY) * sY
if (button == "left" and state == "up") then
-- Register button
if (aX >= rX and aX <= rW and aY >= rY and aY <= rH) then
onClickRegister(button, state)
end
-- Login button
if (aX >= lX and aX <= lW and aY >= lY and aY <= lH) then
for k, v in pairs(RPE) do
v.visible = false
end
for k, v in pairs(LPE) do
v.visible = true
end
end
end
end
addEventHandler("onClientClick", root, onClientClick)
function displayUpdates(data)
if (data == "ERROR") then
data = "Could not fetch updates - try again later"
else
data = tostring(data):gsub("\n\n\n", "\n\n")
end
login.memo.text = data
end
-- Actual login
addEventHandler("onClientResourceStart", resourceRoot,
function ()
if (not isPlayerLoggedIn(localPlayer)) then
triggerServerEvent("UCDaccounts.removeLoginText", resourceRoot)
triggerServerEvent("UCDadmin.banCheck", resourceRoot)
--triggerServerEvent("UCDaccounts.fetchUpdates", resourceRoot)
guiSetInputEnabled(true)
for k, v in ipairs(buttons) do
local b = GuiButton(v[1], v[2], v[3], v[4], "", false)
b2s[b] = k
b.alpha = 0
end
login.button = GuiButton((1047 / nX) * sX, (622 / nY) * sY, (272 / nX) * sX, (42 / nY) * sY, "Login", false)
login.checkbox = GuiCheckBox((1061 / nX) * sX, (595 / nY) * sY, (15 / nX) * sX, (17 / nY) * sY, "", false, false)
login.edit["usr"] = GuiEdit((1037 / nX) * sX, (467 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
login.edit["passwd"] = GuiEdit((1037 / nX) * sX, (549 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
login.edit["passwd"].masked = true
login.memo = GuiMemo((577 / nX) * sX, (719 / nY) * sY, (740 / nX) * sX, (316 / nY) * sY, "", false)
login.memo.readOnly = true
login.memo.text = "Fetching updates.."
fetchRemote("http://ucdmta.com/updates.txt", displayUpdates)
login.button.enabled = false
LPE = {login.button, login.checkbox, login.edit["usr"], login.edit["passwd"]}
for k, v in pairs(LPE) do
v.visible = false
end
addEventHandler("onClientGUIClick", login.button, onClickLogin, false)
--addEventHandler("onClientGUIClick", login.button[2], onClickRegister, false)
addEventHandler("onClientGUIChanged", guiRoot, onLoginEditsChanged)
registration.button = GuiButton((1047/ nX) * sX, (657 / nY) * sY, (272 / nX) * sX, (42 / nY) * sY, "Register", false)
registration.edit["usr"] = GuiEdit((1037/ nX) * sX, (367 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["email"] = GuiEdit((1037/ nX) * sX, (447 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["passwd"] = GuiEdit((1037/ nX) * sX, (527 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["passwd_confirm"] = GuiEdit((1037/ nX) * sX, (607 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["passwd"].masked = true
registration.edit["passwd_confirm"].masked = true
--[[
registration.button = GuiButton((1047/ nX) * sX, (707 / nY) * sY, (272 / nX) * sX, (42 / nY) * sY, "Register", false)
registration.edit["usr"] = GuiEdit((1037/ nX) * sX, (417 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["email"] = GuiEdit((1037/ nX) * sX, (497 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["passwd"] = GuiEdit((1037/ nX) * sX, (577 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
registration.edit["passwd_confirm"] = GuiEdit((1037/ nX) * sX, (657 / nY) * sY, (292 / nX) * sX, (40 / nY) * sY, "", false)
]]
RPE = {registration.button, registration.edit["usr"], registration.edit["email"], registration.edit["passwd"], registration.edit["passwd_confirm"]}
for k, v in pairs(RPE) do
v.visible = false
end
addEventHandler("onClientGUIClick", registration.button, onClickRegisterConfirm)
--addEventHandler("onClientGUIChanged", registration.window[1], onRegistrationEditsChanged)
if (File.exists("@credentials.xml")) then
local f = XML.load("@credentials.xml")
login.edit["usr"]:setText(tostring(f:findChild("usr", 0):getValue()))
login.edit["passwd"]:setText(tostring(teaDecode(f:findChild("passwd", 0):getValue(), keys.xml)))
f:unload()
login.checkbox:setSelected(true)
end
end
end
)
function isLoginWindowOpen()
if (not login.button:getVisible()) or (not isElement(login.button)) then
return false
end
return true
end
function onLoginEditsChanged()
if (source == login.edit["usr"] or source == login.edit["passwd"]) then
local usr, passwd = login.edit["usr"].text, login.edit["passwd"].text
if (usr:len() >= 3 and not usr:match("%W") and passwd:len() >= 6) then
login.button:setEnabled(true)
else
login.button:setEnabled(false)
end
end
end
function onRegistrationEditsChanged()
-- Account name
if (source == registration.edit[1]) then
local usr = source.text
if (not usr or usr == "") then
registration.label[6]:setText("Enter your desired account name")
registration.label[6]:setColor(255, 255, 0)
else
if (usr:match("%W")) then
registration.label[6]:setText("Account name can only contain A- Z, 0 - 9")
registration.label[6]:setColor(255, 0, 0)
else
if (usr:len() < 3) then
registration.label[6]:setText("Account name is too short")
registration.label[6]:setColor(255, 0, 0)
else
-- Syntax is correct, just need to check if it's an actual account
registration.label[6]:setText("Checking")
registration.label[6]:setColor(255, 255, 0)
triggerServerEvent("UCDaccounts.login.isAccount", localPlayer, usr)
end
end
end
-- Emails
elseif (source == registration.edit["email"]) then
local email = source.text:lower()
if (email == "" or not email) then
registration.label[5]:setText("Enter your email address")
registration.label[5]:setColor(255, 255, 0)
elseif (not email:find("@")) or (email:find(" ")) or (not email:find(".")) then
registration.label[5]:setText("Invalid email address")
registration.label[5]:setColor(255, 0, 0)
else
local domain = gettok(email, 2, "@")
if (not domain) then
registration.label[5]:setText("Invalid email address")
registration.label[5]:setColor(255, 0, 0)
elseif (domain:match("%.")) then
local usrname = gettok(email, 1, "@")
local sitename = gettok(domain, 1, ".")
local extension = gettok(domain, 2, ".")
if (not extension or extension:len() == 0 or extension:match("%W") or sitename:match("%W") or usrname:match("%W")) then
if usrname:match("%W") ~= "." and usrname:match("%W") ~= "_" then
registration.label[5]:setText("Invalid email address")
registration.label[5]:setColor(255, 0, 0)
else
registration.label[5]:setText("Valid email address")
registration.label[5]:setColor(0, 255, 0)
end
else
if (extension:find("%_") or domain:find("%_") or sitename:find("%_")) then
registration.label[5]:setText("Invalid email address")
registration.label[5]:setColor(255, 0, 0)
else
if (usrname:find("%_")) then
registration.label[5]:setText("Valid email address")
registration.label[5]:setColor(0, 255, 0)
else
registration.label[5]:setText("Valid email address")
registration.label[5]:setColor(0, 255, 0)
end
end
end
end
end
-- Password
elseif (source == registration.edit["passwd"]) then
local pass = registration.edit["passwd"].text
if (not pass or pass == "") then
registration.label[8].text = "Enter your desired password"
registration.label[8]:setColor(255, 255, 0)
else
if (pass:len() < 6) then
registration.label[8].text = "Password is too short"
registration.label[8]:setColor(255, 0, 0)
else
registration.label[8].text = "Valid password"
registration.label[8]:setColor(0, 255, 0)
end
end
-- Password confirmation
elseif (source == registration.edit["passwd_confirm"]) then
local conf = registration.edit["passwd_confirm"].text
if (not conf or conf == "") then
registration.label[9].text = "Re-enter your password"
registration.label[9]:setColor(255, 255, 0)
else
if (conf ~= registration.edit["passwd"].text) then
registration.label[9].text = "Passwords do not match"
registration.label[9]:setColor(255, 0, 0)
else
registration.label[9].text = "Passwords match"
registration.label[9]:setColor(0, 255, 0)
end
end
end
-- This handles the registration button in the registration window
if (registration.window[1]:getVisible() == true) then
local ar, ag, ab = registration.label[5]:getColor()
local br, bg, bb = registration.label[6]:getColor()
local cr, cg, cb = registration.label[8]:getColor()
local dr, dg, db = registration.label[9]:getColor()
if (ar == 0 and ag == 255 and ab == 0) and (br == 0 and bg == 255 and bb == 0) and (cr == 0 and cg == 255 and cb == 0) and (dr == 0 and dg == 255 and db == 0) then
registration.button[1]:setEnabled(true)
else
registration.button[1]:setEnabled(false)
end
end
Timer(
function ()
if (registration.window[1]:getVisible() == true) then
local ar, ag, ab = registration.label[5]:getColor()
local br, bg, bb = registration.label[6]:getColor()
local cr, cg, cb = registration.label[8]:getColor()
local dr, dg, db = registration.label[9]:getColor()
if (ar == 0 and ag == 255 and ab == 0) and (br == 0 and bg == 255 and bb == 0) and (cr == 0 and cg == 255 and cb == 0) and (dr == 0 and dg == 255 and db == 0) then
registration.button[1]:setEnabled(true)
else
registration.button[1]:setEnabled(false)
end
end
end, (getPlayerPing(localPlayer) + 50) or 400, 1
)
end
function onClickLogin(button, state)
if (source == login.button) then
if (button == "left" and state == "up") then
if (isTransferBoxActive()) then
exports.UCDdx:new("You are still downloading server files - you cannot login yet", 255, 255, 255)
else
local usr = login.edit["usr"].text
local passwd = login.edit["passwd"].text
if (usr == "" and passwd == "") then
exports.UCDdx:new("Please enter your account credentials", 255, 255, 255)
else
if (usr == "" and passwd ~= "") then
exports.UCDdx:new("Please enter your account name", 255, 255, 255)
elseif (usr ~= "" and passwd == "") then
exports.UCDdx:new("Please enter your password", 255, 255, 255)
elseif (user ~= "" and passwd ~= "") then
triggerServerEvent("UCDaccounts.login.logIn", resourceRoot, usr, passwd)
exports.UCDdx:new("Loading...", 255, 255, 255)
toggleLogin()
end
end
end
end
end
end
-- Register player
function onClickRegisterConfirm(button, state)
if (button == "left" and state == "up") then
if (source == registration.button) then
local usr = registration.edit["usr"].text
local email = registration.edit["email"].text
local passwd = registration.edit["passwd"].text
local conf = registration.edit["passwd_confirm"].text
if (passwd ~= conf) then
exports.UCDdx:new("Your passwords do not match", 255, 255, 255)
return
end
triggerEvent("UCDaccounts.login.toggleRegisterConfirm", resourceRoot, false)
triggerServerEvent("UCDaccounts.login.register", resourceRoot, usr, email, passwd, conf)
end
end
end
function toggleRegisterConfirm(state)
if (source) then
registration.button.enabled = state
end
end
addEvent("UCDaccounts.login.toggleRegisterConfirm", true)
addEventHandler("UCDaccounts.login.toggleRegisterConfirm", root, toggleRegisterConfirm)
-- Open registration window
function onClickRegister(button, state)
if (button == "left" and state == "up") then
--if (source == login.button[2]) then
--guiSetVisible(registration.window[1], true)
--exports.UCDutil:centerWindow(registration.window[1])
--guiBringToFront(registration.window[1])
--guiSetInputEnabled(true)
for _, v in pairs(RPE) do
v.visible = true
end
-- Hide other login elements
for _, v in pairs(LPE) do
v.visible = false
end
if (not isCursorShowing()) then showCursor(true) end
--end
end
end
-- Cancel registration
function onClickCancel(button, state)
if (button == "left" and state == "up") then
if (source == registration.button[2]) then
guiSetVisible(registration.window[1], false)
guiSetInputEnabled(true)
-- Hide other login elements
for _, v in pairs(LPE) do
v:setVisible(true)
end
if (not isCursorShowing()) then showCursor(true) end
end
end
end
-- Show login window
function showLoginInterface()
for _, v in pairs(RPE) do
v.visible = false
end
for _, v in pairs(LPE) do
v.visible = true
end
showCursor(true)
addEventHandler("onClientRender", root, drawElements)
end
addEvent("UCDaccounts.login.showLoginInterface", true)
addEventHandler("UCDaccounts.login.showLoginInterface", root, showLoginInterface)
-- Hide login window
function hideLoginInterface()
guiSetInputEnabled(false)
for _, v in pairs(LPE) do
v:setVisible(false)
end
showCursor(false)
--removeEventHandler("onClientRender", root, drawElements)
end
addEvent("UCDaccounts.login.hideLoginInterface", true)
addEventHandler("UCDaccounts.login.hideLoginInterface", root, hideLoginInterface)
-- Hide register window
function hideRegistrationInterface()
for _, v in pairs(RPE) do
v.visible = false
end
end
addEvent("UCDaccounts.login.hideRegistrationInterface", true)
addEventHandler("UCDaccounts.login.hideRegistrationInterface", root, hideRegistrationInterface)
-- We won't need to keep it in memory as the player will only use it once
function destroyInterface()
if (isCursorShowing()) then showCursor(false) end
for _, v in pairs(LPE) do
v:destroy()
end
for _, v in pairs(RPE) do
v:destroy()
end
login.memo:destroy()
login = nil
removeEventHandler("onClientRender", root, drawElements)
end
addEvent("UCDaccounts.login.destroyInterface", true)
addEventHandler("UCDaccounts.login.destroyInterface", root, destroyInterface)
function toggleLogin()
if (login.button and isElement(login.button)) then
login.button.enabled = not login.button.enabled
end
end
addEvent("UCDaccounts.login.toggleLogin", true)
addEventHandler("UCDaccounts.login.toggleLogin", root, toggleLogin)
-- Callback for checking if an account exists
function updateValidationLabel(value, bad)
registration.label[6]:setText(value)
if (bad == true) then
registration.label[6]:setColor(255, 0, 0)
else
registration.label[6]:setColor(0, 255, 0)
end
--[[
if (value == true) then
registration.label[6]:setText("Available account name")
registration.label[6]:setColor(0, 255, 0)
elseif (value == false) then
registration.label[6]:setText("This account name is taken")
registration.label[6]:setColor(255, 0, 0)
else
registration.label[6]:setText("An error has occured")
registration.label[6]:setColor(255, 0, 0)
end
--]]
end
addEvent("UCDaccounts.login.updateValidationLabel", true)
addEventHandler("UCDaccounts.login.updateValidationLabel", root, updateValidationLabel)
function xmllol()
if guiCheckBoxGetSelected(login.checkbox) then
local usr = login.edit["usr"].text
local passwd = teaEncode(login.edit["passwd"].text, keys.xml)
if (not File.exists("@credentials.xml")) then
local f = XML("@credentials.xml", "login")
f:createChild("usr"):setValue(usr)
f:createChild("passwd"):setValue(passwd)
f:saveFile()
f:unload()
else
local f = XML.load("@credentials.xml")
f:findChild("usr", 0):setValue(usr)
f:findChild("passwd", 0):setValue(passwd)
f:saveFile()
f:unload()
end
else
if (File.exists("@credentials.xml")) then
File.delete("@credentials.xml")
end
end
end
addEvent("UCDaccounts.login.saveAccountCredentials", true)
addEventHandler("UCDaccounts.login.saveAccountCredentials", root, xmllol)