· 4 years ago · Jun 22, 2021, 02:56 PM
1--/ CCash Wallet /--
2os.pullEvent = os.pullEventRaw
3local ccashAPI = "/apis/ccash.lua"
4local walletDataStore = "/.walletData"
5
6if not fs.exists(ccashAPI) then
7 printError("CCASH API is not installed")
8 print("You can change the API path in the wallet script")
9 print("If you have RPM, run 'rpm install ccash-api'")
10 print()
11 write("Automatically install CCASH API (y/n): ")
12 local choice = read()
13 if string.lower(choice) == "y" then
14 local h = http.get("https://raw.githubusercontent.com/Reactified/rpm/main/packages/ccash-api/api.lua")
15 if h then
16 f = fs.open(ccashAPI,"w")
17 f.writeLine(h.readAll())
18 f.close()
19 h.close()
20 print("CCASH API Installed")
21 sleep(2)
22 else
23 printError("An error occured.")
24 return
25 end
26 end
27end
28os.loadAPI(ccashAPI)
29local shortName = ccashAPI
30while true do
31 local findPos = string.find(shortName,"/")
32 if findPos then
33 shortName = string.sub(shortName,findPos+1,#shortName)
34 else
35 break
36 end
37end
38shortName = string.gsub(shortName,".lua","")
39
40local fullApi = _G[shortName]
41local api = _G[shortName].simple
42if not api then
43 printError("Could not extract simple API")
44 return
45end
46
47--/ Settings /--
48local cname = "CCash"
49local csn = "CSH"
50
51--/ Wallet Data /--
52local walletData = {}
53if fs.exists(walletDataStore) then
54 f = fs.open(walletDataStore,"r")
55 walletData = textutils.unserialise(f.readAll())
56 f.close()
57end
58local function saveWalletData()
59 f = fs.open(walletDataStore,"w")
60 f.writeLine(textutils.serialise(walletData))
61 f.close()
62end
63
64--/ Initialization /--
65local w,h = term.getSize()
66term.setPaletteColor(colors.brown,1,0.8,0.2)
67
68--/ Functions /--
69local function drawLogo(x,y)
70 term.setCursorPos(x,y)
71 term.setBackgroundColor(colors.orange)
72 term.setTextColor(colors.white)
73 term.write("/")
74 term.setBackgroundColor(colors.brown)
75 term.write("\\")
76 term.setCursorPos(x,y+1)
77 term.write("\\")
78 term.setBackgroundColor(colors.yellow)
79 term.write("/")
80end
81local function drawHeader()
82 term.setBackgroundColor(colors.black)
83 term.clear()
84 paintutils.drawFilledBox(1,1,w,4,colors.gray)
85 drawLogo(2,2)
86 term.setBackgroundColor(colors.gray)
87 term.setCursorPos(5,2)
88 term.setTextColor(colors.brown)
89 write(cname)
90 term.setCursorPos(5,3)
91 term.setTextColor(colors.lightGray)
92 write("Wallet")
93 term.setBackgroundColor(colors.black)
94end
95local function rightAlign(str,ln)
96 term.setCursorPos(w-#str,ln)
97 write(str)
98end
99local function center(str,ln)
100 local w,h = term.getSize()
101 term.setCursorPos((w/2)-(#str/2)+1,ln)
102 write(str)
103end
104
105--/ Debounce /--
106local apiBusy = false
107local function apiDebounce()
108 repeat
109 sleep(0.25)
110 until not apiBusy
111end
112
113--/ Routine /--
114local username = false
115local autologin = walletData.username
116
117local online = nil
118local balance = -1
119
120local function balanceRoutine()
121 while true do
122 apiDebounce()
123 apiBusy = true
124 local fetchedStatus,fetchedBalance = fullApi.bal(username or "React")
125 if fetchedStatus then
126 online = true
127 if username then
128 balance = fetchedBalance
129 else
130 balance = -1
131 end
132 else
133 online = false
134 end
135 apiBusy = false
136 sleep(5)
137 end
138end
139
140local function writeBalance()
141 if balance >= 0 then
142 write(tostring(balance).." "..csn)
143 else
144 write("Loading...")
145 end
146end
147
148local function masterRoutine()
149 -- Wait for connection
150 drawHeader()
151 term.setCursorPos(2,6)
152 term.setTextColor(colors.brown)
153 center("<< Connecting >>",h/2+3)
154 repeat
155 sleep(0.5)
156 until online ~= nil
157
158 -- Routine
159 while true do
160 username = false
161 drawHeader()
162 term.setCursorPos(2,6)
163 term.setTextColor(colors.brown)
164 write("Welcome!")
165 term.setCursorPos(2,7)
166 term.setTextColor(colors.lightGray)
167 write("To get started, log in")
168 term.setCursorPos(2,8)
169 write("or create an account.")
170 term.setCursorPos(2,10)
171 term.setTextColor(colors.white)
172 term.setBackgroundColor(colors.gray)
173 write(" Log In ")
174 term.setCursorPos(11,10)
175 term.setTextColor(colors.gray)
176 term.setBackgroundColor(colors.brown)
177 write(" Sign Up ")
178 term.setCursorPos(2,h-1)
179 term.setTextColor(colors.lightGray)
180 term.setBackgroundColor(colors.black)
181 term.setCursorPos(2,12)
182 term.setTextColor(colors.gray)
183 write("Connnecting")
184 term.setCursorPos(2,12)
185 if not autologin then
186 if online then
187 term.setTextColor(colors.brown)
188 write("Connected ")
189 else
190 term.setTextColor(colors.red)
191 write("Connection Failed")
192 end
193 end
194 local e,c,x,y = "autologin", 0, 0, 0
195 if not autologin then
196 e,c,x,y = os.pullEvent("mouse_click")
197 end
198 if y == h-1 then
199 term.setBackgroundColor(colors.black)
200 term.clear()
201 term.setCursorPos(1,1)
202 return
203 elseif y == 10 or autologin then
204 if x < 11 or autologin then
205 username = false
206 balance = -1
207 -- Log In
208 drawHeader()
209 term.setCursorPos(2,6)
210 term.setTextColor(colors.brown)
211 write("Log In")
212 term.setCursorPos(2,8)
213 term.setTextColor(colors.lightGray)
214 write("Username")
215 term.setCursorPos(2,10)
216 write("Password")
217 term.setCursorPos(11,8)
218 term.setBackgroundColor(colors.gray)
219 term.setTextColor(colors.lightGray)
220 write(string.rep(" ",w-11))
221 term.setCursorPos(11,10)
222 write(string.rep(" ",w-11))
223 term.setCursorPos(12,8)
224 term.setTextColor(colors.white)
225 local password
226 if autologin then
227 write(walletData.username)
228 username = walletData.username
229 else
230 username = read()
231 end
232 term.setCursorPos(12,10)
233 term.setTextColor(colors.white)
234 if autologin and walletData.password then
235 write(string.rep("*",#walletData.password))
236 password = walletData.password
237 else
238 password = read("*")
239 end
240 term.setBackgroundColor(colors.black)
241 term.setTextColor(colors.gray)
242 term.setCursorPos(2,12)
243 write("Loading...")
244 apiDebounce()
245 apiBusy = true
246 if api.verify(username,password) then
247 apiBusy = false
248 term.setCursorPos(2,12)
249 term.setTextColor(colors.brown)
250 term.clearLine()
251 term.setCursorPos(2,12)
252 write("Accepted!")
253 if not autologin then
254 sleep(1)
255 end
256 -- Interface
257 local transferTO = ""
258 local transferAMT = "0"
259 local tabs = {
260 "Dashboard",
261 "Transfer",
262 "Transactions",
263 "Settings",
264 "Leaderboard",
265 }
266 local tab = 1
267 local scroll = 1
268 local rawTransactions
269 local lastTransBalance
270 local joinedLeaderboard = false
271 while true do
272 -- UI Draw
273 term.setBackgroundColor(colors.black)
274 term.clear()
275 paintutils.drawFilledBox(1,1,w,3,colors.gray)
276 term.setCursorPos(2,2)
277 term.setTextColor(colors.lightGray)
278 write("<- ")
279 term.setTextColor(colors.brown)
280 center(tabs[tab],2)
281 term.setTextColor(colors.lightGray)
282 term.setCursorPos(w-2,2)
283 write("->")
284 -- Tab Draw
285 if tab == 1 then
286 drawLogo(2,5)
287 term.setCursorPos(5,5)
288 term.setBackgroundColor(colors.black)
289 term.setTextColor(colors.lightGray)
290 write(username)
291 term.setTextColor(colors.brown)
292 term.setCursorPos(5,6)
293 writeBalance()
294 term.setTextColor(colors.gray)
295 for i=2,w-1 do
296 term.setCursorPos(i,8)
297 write(string.char(math.random(129,140)))
298 end
299 term.setCursorPos(2,h-1)
300 term.setTextColor(colors.lightGray)
301 write("> Logout")
302 elseif tab == 2 then
303 drawLogo(2,h-2)
304 term.setCursorPos(5,h-2)
305 term.setBackgroundColor(colors.black)
306 term.setTextColor(colors.lightGray)
307 write(username)
308 term.setTextColor(colors.brown)
309 term.setCursorPos(5,h-1)
310 writeBalance()
311 term.setTextColor(colors.gray)
312 for i=2,w-1 do
313 term.setCursorPos(i,h-4)
314 write(string.char(math.random(129,140)))
315 end
316 term.setCursorPos(2,5)
317 term.setTextColor(colors.brown)
318 write("Transfer Funds")
319 term.setCursorPos(2,7)
320 term.setTextColor(colors.lightGray)
321 write("Target")
322 term.setCursorPos(2,9)
323 write("Amount")
324 term.setCursorPos(9,7)
325 term.setBackgroundColor(colors.gray)
326 term.setTextColor(colors.lightGray)
327 write(string.rep(" ",w-9))
328 term.setCursorPos(9,9)
329 write(string.rep(" ",w-9))
330 term.setCursorPos(10,7)
331 write(string.sub(transferTO,1,w-11))
332 term.setCursorPos(10,9)
333 write(string.sub(transferAMT,1,w-15).." "..csn)
334 term.setCursorPos(2,11)
335 term.setBackgroundColor(colors.brown)
336 term.setTextColor(colors.gray)
337 write(" Send ")
338 elseif tab == 3 then
339 drawLogo(2,5)
340 term.setCursorPos(5,5)
341 term.setBackgroundColor(colors.black)
342 term.setTextColor(colors.lightGray)
343 write(username)
344 term.setCursorPos(5,6)
345 term.setTextColor(colors.brown)
346 write("Transactions")
347 term.setTextColor(colors.gray)
348 for i=2,w-1 do
349 term.setCursorPos(i,8)
350 write(string.char(math.random(129,140)))
351 end
352
353 if lastTransBalance ~= balance then
354 apiDebounce()
355 apiBusy = true
356 rawTransactions = api.transactions(username, password)
357 apiBusy = false
358 lastTransBalance = balance
359 end
360 if type(rawTransactions) == "table" then
361 local trans = {}
362 local vx = 0
363 if vx < 1 then
364 vx = 1
365 end
366 for i=1,#rawTransactions do
367 local transx = rawTransactions[i]
368 local val = {}
369
370 -- calculate age
371 local age = math.floor((os.epoch("utc")-transx.time )/1000)
372
373 local ageSeconds = age
374 local ageMinutes = math.floor(ageSeconds/60)
375 local ageHours = math.floor(ageMinutes/60)
376 local ageDays = math.floor(ageHours/24)
377 local ageMonths = math.floor(ageDays/31)
378 local ageYears = math.floor(ageMonths/12)
379
380 ageSeconds = ageSeconds - (ageMinutes * 60)
381 ageMinutes = ageMinutes - (ageHours * 60)
382 ageHours = ageHours - (ageDays * 24)
383 ageDays = ageDays - (ageMonths * 31)
384 ageMonths = ageMonths - (ageYears * 12)
385
386 if w > 30 then
387 -- large displays
388 if ageYears > 0 then
389 val.age = tostring(ageYears).."y "..tostring(ageMonths).."m"
390 elseif ageMonths > 0 then
391 val.age = tostring(ageMonths).."mo "..tostring(ageDays).."d"
392 elseif ageDays > 0 then
393 val.age = tostring(ageDays).."d "..tostring(ageHours).."h"
394 elseif ageHours > 0 then
395 val.age = tostring(ageHours).."h "..tostring(ageMinutes).."m"
396 elseif ageMinutes > 0 then
397 val.age = tostring(ageMinutes).."m "..tostring(ageSeconds).."s"
398 else
399 val.age = tostring(ageSeconds).."s"
400 end
401 else
402 -- small displays
403 if ageYears > 0 then
404 val.age = tostring(ageYears).."y"
405 elseif ageMonths > 0 then
406 val.age = tostring(ageMonths).."mo"
407 elseif ageDays > 0 then
408 val.age = tostring(ageDays).."d"
409 elseif ageHours > 0 then
410 val.age = tostring(ageHours).."h"
411 elseif ageMinutes > 0 then
412 val.age = tostring(ageMinutes).."m"
413 else
414 val.age = tostring(ageSeconds).."s"
415 end
416 end
417
418 if transx.to == username then
419 val.address = transx.from
420 val.amount = transx.amount
421 elseif transx.from == username then
422 val.address = transx.to
423 val.amount = -transx.amount
424 else
425 val.address = "Unknown"
426 val.amount = transx.amount
427 end
428 val.id = i
429 trans[#trans+1] = val
430 end
431 local yp = 10
432 local nameAlign = 0
433 for i=scroll,h+scroll-11 do
434 if trans[i] and #tostring(trans[i].amount) > nameAlign then
435 nameAlign = #tostring(trans[i].amount)
436 end
437 end
438 for i=scroll,h+scroll-11 do
439 local v = trans[i]
440 if v then
441 term.setTextColor(colors.gray)
442 if w > 30 then
443 rightAlign(v.age .. " ago",yp)
444 else
445 rightAlign(v.age,yp)
446 end
447
448 term.setTextColor(colors.lightGray)
449 term.setCursorPos(nameAlign+8,yp)
450 write(v.address,yp)
451
452 local str = tostring(v.amount)
453 term.setCursorPos(2,yp)
454 if v.amount > 0 then
455 str = "+"..str.." <<"
456 term.setTextColor(colors.lime)
457 else
458 str = str .. " >>"
459 term.setTextColor(colors.red)
460 end
461 write(str,yp)
462 yp = yp + 1
463 end
464 end
465 else
466 term.setTextColor(colors.gray)
467 center("No transactions",14)
468 end
469 elseif tab == 4 then
470 term.setCursorPos(2,5)
471 term.setBackgroundColor(colors.black)
472 term.setTextColor(colors.lightGray)
473 write("Wallet Settings")
474 term.setTextColor(colors.brown)
475 term.setCursorPos(2,7)
476 write("Autologin: ")
477 if walletData.username and walletData.password then
478 term.setTextColor(colors.brown)
479 write("Full")
480 elseif walletData.username then
481 term.setTextColor(colors.brown)
482 write("User")
483 else
484 term.setTextColor(colors.gray)
485 write("Off")
486 end
487 term.setTextColor(colors.gray)
488 for i=2,w-1 do
489 term.setCursorPos(i,9)
490 write(string.char(math.random(129,140)))
491 end
492 term.setCursorPos(2,11)
493 term.setBackgroundColor(colors.black)
494 term.setTextColor(colors.lightGray)
495 write("Account Settings")
496 term.setTextColor(colors.brown)
497 term.setCursorPos(2,13)
498 write("Change Password")
499 term.setTextColor(colors.red)
500 term.setCursorPos(2,14)
501 write("Delete Account")
502 elseif tab == 5 then
503 if not leaderboard then
504 if not fs.exists("/apis/leaderboard.lua") then
505 if fs.exists('/rpm.lua') then
506 os.loadAPI("/rpm.lua")
507 rpm.api.install("ccash-api/leaderboard")
508 end
509 end
510 if fs.exists("/apis/leaderboard.lua") then
511 os.loadAPI("apis/leaderboard.lua")
512 end
513 else
514 local board = leaderboard.leaderboard()
515 local onLeaderboard = false
516 for i,v in pairs(board) do
517 if v[1] == username then
518 onLeaderboard = true
519 end
520 end
521 if onLeaderboard or joinedLeaderboard then
522 local yp = 5
523 for i=1,math.floor((h-4)/3) do
524 if board[i] then
525 drawLogo(2,yp)
526 term.setCursorPos(5,yp)
527 term.setBackgroundColor(colors.black)
528 term.setTextColor(colors.lightGray)
529 if i == 1 then
530 term.setTextColor(colors.brown)
531 elseif i == 2 then
532 term.setTextColor(colors.white)
533 elseif i == 3 then
534 term.setTextColor(colors.orange)
535 end
536 write("#"..tostring(i)..": "..board[i][1])
537 term.setCursorPos(5,yp+1)
538 term.setBackgroundColor(colors.black)
539 term.setTextColor(colors.gray)
540 write(tostring(board[i][2]).." "..csn)
541 yp = yp + 3
542 end
543 end
544 else
545 term.setTextColor(colors.brown)
546 term.setBackgroundColor(colors.black)
547 term.setCursorPos(2,5)
548 write("Leaderboard")
549 term.setCursorPos(2,6)
550 term.setTextColor(colors.lightGray)
551 write("To view, join the board.")
552 term.setCursorPos(2,8)
553 term.setTextColor(colors.gray)
554 term.setBackgroundColor(colors.brown)
555 write(" Join ")
556 end
557 end
558 end
559 -- Event Handling
560 local e,c,x,y
561 while true do
562 e,c,x,y = os.pullEvent()
563 if e == "mouse_click" or e == "mouse_scroll" then
564 break
565 end
566 end
567 if e == "mouse_scroll" then
568 scroll = scroll + c
569 if scroll < 1 then
570 scroll = 1
571 end
572 elseif e == "mouse_click" then
573 if y == 1 or y == 2 or y == 3 then
574 if x < w/2 then
575 tab = tab - 1
576 if tab == 0 then
577 tab = #tabs
578 end
579 elseif x > w/2 then
580 tab = tab + 1
581 if tab > #tabs then
582 tab = 1
583 end
584 end
585 elseif tab == 1 then
586 if y == h-1 then
587 break
588 end
589 elseif tab == 2 then
590 if y == 7 then
591 term.setBackgroundColor(colors.gray)
592 term.setTextColor(colors.white)
593 term.setCursorPos(10,7)
594 transferTO = read()
595 elseif y == 9 then
596 term.setBackgroundColor(colors.gray)
597 term.setTextColor(colors.white)
598 term.setCursorPos(10,9)
599 transferAMT = read()
600 elseif y == 11 and x >= 2 and x <= 8 then
601 term.setBackgroundColor(colors.black)
602 term.setTextColor(colors.brown)
603 term.setCursorPos(10,11)
604 write("...")
605 term.setCursorPos(10,11)
606 if tonumber(transferAMT) then
607 if tonumber(transferAMT) > 0 then
608 apiDebounce()
609 apiBusy = true
610 local ok,err = api.send(username,password,transferTO,tonumber(transferAMT))
611 if ok and balance ~= api.balance(username) then
612 write("Success!")
613 else
614 write("Failed.")
615 end
616 apiBusy = false
617 else
618 write("Invalid amount.")
619 end
620 else
621 write("Invalid amount.")
622 end
623 os.pullEvent("mouse_click")
624 end
625 elseif tab == 4 then
626 if y == 7 then
627 -- autologin
628 term.setBackgroundColor(colors.black)
629 for i=4,h do
630 term.setCursorPos(1,i)
631 term.clearLine()
632 end
633 term.setCursorPos(2,5)
634 term.setTextColor(colors.lightGray)
635 write("Autologin Setup")
636 term.setCursorPos(2,7)
637 term.setTextColor(colors.brown)
638 write("Full")
639 term.setCursorPos(2,8)
640 term.setTextColor(colors.gray)
641 write("UNENCRYPTED PASSWORD")
642 term.setCursorPos(2,10)
643 term.setTextColor(colors.brown)
644 write("User")
645 term.setCursorPos(2,11)
646 term.setTextColor(colors.gray)
647 write("AUTOFILL USERNAME")
648 term.setCursorPos(2,13)
649 term.setTextColor(colors.brown)
650 write("None")
651 term.setCursorPos(2,14)
652 term.setTextColor(colors.gray)
653 write("NO AUTOLOGIN")
654 local e,c,x,y = os.pullEvent("mouse_click")
655 if y == 7 or y == 8 then
656 term.setCursorPos(2,16)
657 term.setTextColor(colors.brown)
658 write("Enter Password")
659 term.setCursorPos(2,17)
660 term.setTextColor(colors.lightGray)
661 write("> ")
662 -- full
663 walletData.username = username
664 walletData.password = read("*")
665 elseif y == 10 or y == 11 then
666 -- user
667 walletData.username = username
668 walletData.password = nil
669 elseif y == 13 or y == 14 then
670 -- none
671 walletData.username = nil
672 walletData.password = nil
673 end
674 saveWalletData()
675 elseif y == 13 then
676 -- change password
677 term.setBackgroundColor(colors.black)
678 for i=4,h do
679 term.setCursorPos(1,i)
680 term.clearLine()
681 end
682 term.setCursorPos(2,5)
683 term.setTextColor(colors.brown)
684 write("Change Password")
685 term.setTextColor(colors.gray)
686 for i=2,w-1 do
687 term.setCursorPos(i,7)
688 write(string.char(math.random(129,140)))
689 end
690 term.setCursorPos(2,9)
691 term.setTextColor(colors.brown)
692 write("Old Password")
693 term.setCursorPos(2,10)
694 term.setTextColor(colors.lightGray)
695 write("> ")
696 local old_password = read("*")
697 term.setCursorPos(2,12)
698 term.setTextColor(colors.brown)
699 if old_password ~= password then
700 write("Invalid Password")
701 sleep(2)
702 else
703 write("New Password")
704 term.setCursorPos(2,13)
705 term.setTextColor(colors.lightGray)
706 write("> ")
707 local new_password = read("*")
708 term.setCursorPos(2,14)
709 term.setTextColor(colors.lightGray)
710 write("> ")
711 local new_password_confirm = read("*")
712 term.setCursorPos(2,16)
713 term.setTextColor(colors.brown)
714 if new_password == new_password_confirm then
715 apiDebounce()
716 apiBusy = true
717 local ok,res = fullApi.changepass(username, old_password, new_password)
718 apiBusy = false
719 if ok and res then
720 write("Password changed")
721 else
722 write("Error occured")
723 end
724 sleep(2)
725 else
726 write("Passwords must match")
727 sleep(2)
728 end
729 end
730 elseif y == 14 then
731 -- delete account
732 term.setBackgroundColor(colors.black)
733 for i=4,h do
734 term.setCursorPos(1,i)
735 term.clearLine()
736 end
737 term.setCursorPos(2,5)
738 term.setTextColor(colors.red)
739 write("Delete Account")
740 term.setTextColor(colors.gray)
741 for i=2,w-1 do
742 term.setCursorPos(i,7)
743 write(string.char(math.random(129,140)))
744 end
745 term.setCursorPos(2,9)
746 term.setTextColor(colors.brown)
747 write("Enter Password")
748 term.setCursorPos(2,10)
749 term.setTextColor(colors.lightGray)
750 write("> ")
751 local delete_password = read("*")
752 term.setCursorPos(2,12)
753 term.setTextColor(colors.brown)
754 if password ~= delete_password then
755 write("Invalid Password")
756 sleep(2)
757 else
758 write("Confirm Username")
759 term.setCursorPos(2,13)
760 term.setTextColor(colors.lightGray)
761 write("> ")
762 local delete_user = read()
763 if delete_user == username then
764 for i=8,h do
765 term.setCursorPos(1,i)
766 term.clearLine()
767 end
768 term.setBackgroundColor(colors.red)
769 term.setTextColor(colors.black)
770 term.setCursorPos(1,9)
771 term.clearLine()
772 term.setCursorPos(2,9)
773 write("!!! ACCOUNT DELETION !!!")
774 term.setBackgroundColor(colors.black)
775 term.setCursorPos(2,15)
776 term.setTextColor(colors.gray)
777 write("Press any key to abort")
778 term.setCursorPos(2,11)
779 term.setTextColor(colors.red)
780 write("All funds will be lost!")
781 term.setCursorPos(2,12)
782 write("This cannot be undone!")
783 local abort = false
784 for i=20,0,-1 do
785 if abort then
786 break
787 end
788 term.setCursorPos(1,14)
789 term.clearLine()
790 term.setCursorPos(2,14)
791 write("T-"..tostring(i).." DELETION")
792 local abort_tmr = os.startTimer(1)
793 while true do
794 local e,k = os.pullEvent()
795 if e == "timer" and k == abort_tmr then
796 break
797 elseif e == "key" then
798 abort = true
799 break
800 end
801 end
802 if i == 0 and not abort then
803 term.setBackgroundColor(colors.black)
804 term.clear()
805 term.setCursorPos(1,1)
806 term.setTextColor(colors.red)
807 print("Account Deleted.")
808 apiDebounce()
809 apiBusy = true
810 fullApi.delete(username,password)
811 apiBusy = false
812 return
813 end
814 end
815 term.setCursorPos(2,17)
816 term.setTextColor(colors.lime)
817 write("Aborted.")
818 sleep(2)
819 else
820 term.setCursorPos(2,15)
821 term.setTextColor(colors.brown)
822 write("Aborted.")
823 end
824 end
825 end
826 elseif tab == 5 then
827 if y == 8 then
828 if leaderboard and type(leaderboard.submit) == "function" then
829 leaderboard.submit(username)
830 joinedLeaderboard = true
831 end
832 end
833 end
834 end
835 end
836 else
837 apiBusy = false
838 term.setCursorPos(2,12)
839 term.setTextColor(colors.brown)
840 term.clearLine()
841 term.setCursorPos(2,12)
842 write("Invalid credentials.")
843 sleep(2)
844 end
845 else
846 -- Sign Up
847 drawHeader()
848 term.setCursorPos(2,6)
849 term.setTextColor(colors.brown)
850 write("Sign Up")
851 term.setCursorPos(2,8)
852 term.setTextColor(colors.lightGray)
853 write("Username")
854 term.setCursorPos(2,10)
855 write("Password")
856 term.setCursorPos(2,12)
857 write("Confirm")
858 term.setCursorPos(11,8)
859 term.setBackgroundColor(colors.gray)
860 term.setTextColor(colors.lightGray)
861 write(string.rep(" ",w-11))
862 term.setCursorPos(11,10)
863 write(string.rep(" ",w-11))
864 term.setCursorPos(11,12)
865 write(string.rep(" ",w-11))
866 term.setCursorPos(12,8)
867 term.setTextColor(colors.white)
868 local username = read()
869 term.setCursorPos(12,10)
870 term.setTextColor(colors.white)
871 local password = read("*")
872 term.setCursorPos(12,12)
873 local confirm = read("*")
874 term.setBackgroundColor(colors.black)
875 term.setTextColor(colors.gray)
876 term.setCursorPos(2,14)
877 write("Loading...")
878 if #username > 32 then
879 term.setCursorPos(2,14)
880 term.setTextColor(colors.brown)
881 term.clearLine()
882 term.setCursorPos(2,14)
883 write("Name too long!")
884 sleep(2)
885 elseif string.find(username," ") then
886 term.setCursorPos(2,14)
887 term.setTextColor(colors.brown)
888 term.clearLine()
889 term.setCursorPos(2,14)
890 write("Name cannot have spaces")
891 sleep(2)
892 elseif password == confirm then
893 apiDebounce()
894 apiBusy = true
895 if api.register(username,password) then
896 term.setCursorPos(2,14)
897 term.setTextColor(colors.brown)
898 term.clearLine()
899 term.setCursorPos(2,14)
900 write("Account created!")
901 sleep(2)
902 else
903 term.setCursorPos(2,14)
904 term.setTextColor(colors.brown)
905 term.clearLine()
906 term.setCursorPos(2,14)
907 write("Username in use.")
908 sleep(2)
909 end
910 apiBusy = false
911 else
912 term.setCursorPos(2,14)
913 term.setTextColor(colors.brown)
914 term.clearLine()
915 term.setCursorPos(2,14)
916 write("Passwords must match.")
917 sleep(2)
918 end
919 end
920 end
921 autologin = false
922 end
923end
924
925--/ Multithreading /--
926parallel.waitForAny(masterRoutine, balanceRoutine)