· 4 years ago · Jun 07, 2021, 04:52 PM
1--/ CCash Wallet /--
2local ccashAPI = "/apis/ccash.lua"
3local walletDataStore = "/.walletData"
4
5if not fs.exists(ccashAPI) then
6 printError("CCASH API is not installed")
7 print("You can change the API path in the wallet script")
8 print("If you have RPM, run 'rpm install ccash-api'")
9 print()
10 write("Automatically install CCASH API (y/n): ")
11 local choice = read()
12 if string.lower(choice) == "y" then
13 local h = http.get("https://raw.githubusercontent.com/Reactified/rpm/main/packages/ccash-api/api.lua")
14 if h then
15 f = fs.open(ccashAPI,"w")
16 f.writeLine(h.readAll())
17 f.close()
18 h.close()
19 print("CCASH API Installed")
20 sleep(2)
21 else
22 printError("An error occured.")
23 return
24 end
25 end
26end
27os.loadAPI(ccashAPI)
28local shortName = ccashAPI
29while true do
30 local findPos = string.find(shortName,"/")
31 if findPos then
32 shortName = string.sub(shortName,findPos+1,#shortName)
33 else
34 break
35 end
36end
37shortName = string.gsub(shortName,".lua","")
38
39local fullApi = _G[shortName]
40local api = _G[shortName].simple
41if not api then
42 printError("Could not extract simple API")
43 return
44end
45
46--/ Settings /--
47local cname = "CCash"
48local csn = "CSH"
49
50--/ Wallet Data /--
51local walletData = {}
52if fs.exists(walletDataStore) then
53 f = fs.open(walletDataStore,"r")
54 walletData = textutils.unserialise(f.readAll())
55 f.close()
56end
57local function saveWalletData()
58 f = fs.open(walletDataStore,"w")
59 f.writeLine(textutils.serialise(walletData))
60 f.close()
61end
62
63--/ Initialization /--
64local w,h = term.getSize()
65term.setPaletteColor(colors.brown,1,0.8,0.2)
66
67--/ Functions /--
68local function drawLogo(x,y)
69 term.setCursorPos(x,y)
70 term.setBackgroundColor(colors.orange)
71 term.setTextColor(colors.white)
72 term.write("/")
73 term.setBackgroundColor(colors.brown)
74 term.write("\\")
75 term.setCursorPos(x,y+1)
76 term.write("\\")
77 term.setBackgroundColor(colors.yellow)
78 term.write("/")
79end
80local function drawHeader()
81 term.setBackgroundColor(colors.black)
82 term.clear()
83 paintutils.drawFilledBox(1,1,w,4,colors.gray)
84 drawLogo(2,2)
85 term.setBackgroundColor(colors.gray)
86 term.setCursorPos(5,2)
87 term.setTextColor(colors.brown)
88 write(cname)
89 term.setCursorPos(5,3)
90 term.setTextColor(colors.lightGray)
91 write("Wallet")
92 term.setBackgroundColor(colors.black)
93end
94local function rightAlign(str,ln)
95 term.setCursorPos(w-#str,ln)
96 write(str)
97end
98local function center(str,ln)
99 local w,h = term.getSize()
100 term.setCursorPos((w/2)-(#str/2)+1,ln)
101 write(str)
102end
103
104--/ Debounce /--
105local apiBusy = false
106local function apiDebounce()
107 repeat
108 sleep(0.25)
109 until not apiBusy
110end
111
112--/ Routine /--
113local username = false
114local autologin = walletData.username
115
116local online = nil
117local balance = -1
118
119local function balanceRoutine()
120 while true do
121 apiDebounce()
122 apiBusy = true
123 local fetchedStatus,fetchedBalance = fullApi.bal(username or "React")
124 if fetchedStatus then
125 online = true
126 if username then
127 balance = fetchedBalance
128 else
129 balance = -1
130 end
131 else
132 online = false
133 end
134 apiBusy = false
135 sleep(5)
136 end
137end
138
139local function writeBalance()
140 if balance >= 0 then
141 write(tostring(balance).." "..csn)
142 else
143 write("Loading...")
144 end
145end
146
147local function masterRoutine()
148 -- Wait for connection
149 drawHeader()
150 term.setCursorPos(2,6)
151 term.setTextColor(colors.brown)
152 center("<< Connecting >>",h/2+3)
153 repeat
154 sleep(0.5)
155 until online ~= nil
156
157 -- Routine
158 while true do
159 username = false
160 drawHeader()
161 term.setCursorPos(2,6)
162 term.setTextColor(colors.brown)
163 write("Welcome!")
164 term.setCursorPos(2,7)
165 term.setTextColor(colors.lightGray)
166 write("To get started, log in")
167 term.setCursorPos(2,8)
168 write("or create an account.")
169 term.setCursorPos(2,10)
170 term.setTextColor(colors.white)
171 term.setBackgroundColor(colors.gray)
172 write(" Log In ")
173 term.setCursorPos(11,10)
174 term.setTextColor(colors.gray)
175 term.setBackgroundColor(colors.brown)
176 write(" Sign Up ")
177 term.setCursorPos(2,h-1)
178 term.setTextColor(colors.lightGray)
179 term.setBackgroundColor(colors.black)
180 write("Quit")
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 end
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.white)
529 if i == 1 then
530 term.setTextColor(colors.brown)
531 elseif i == 2 then
532 term.setTextColor(colors.lightGray)
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 -- Event Handling
559 local e,c,x,y
560 while true do
561 e,c,x,y = os.pullEvent()
562 if e == "mouse_click" or e == "mouse_scroll" then
563 break
564 end
565 end
566 if e == "mouse_scroll" then
567 scroll = scroll + c
568 if scroll < 1 then
569 scroll = 1
570 end
571 elseif e == "mouse_click" then
572 if y == 1 or y == 2 or y == 3 then
573 if x < w/2 then
574 tab = tab - 1
575 if tab == 0 then
576 tab = #tabs
577 end
578 elseif x > w/2 then
579 tab = tab + 1
580 if tab > #tabs then
581 tab = 1
582 end
583 end
584 elseif tab == 1 then
585 if y == h-1 then
586 break
587 end
588 elseif tab == 2 then
589 if y == 7 then
590 term.setBackgroundColor(colors.gray)
591 term.setTextColor(colors.white)
592 term.setCursorPos(10,7)
593 transferTO = read()
594 elseif y == 9 then
595 term.setBackgroundColor(colors.gray)
596 term.setTextColor(colors.white)
597 term.setCursorPos(10,9)
598 transferAMT = read()
599 elseif y == 11 and x >= 2 and x <= 8 then
600 term.setBackgroundColor(colors.black)
601 term.setTextColor(colors.brown)
602 term.setCursorPos(10,11)
603 write("...")
604 term.setCursorPos(10,11)
605 if tonumber(transferAMT) then
606 if tonumber(transferAMT) > 0 then
607 apiDebounce()
608 apiBusy = true
609 local ok,err = api.send(username,password,transferTO,tonumber(transferAMT))
610 if ok and balance ~= api.balance(username) then
611 write("Success!")
612 else
613 write("Failed.")
614 end
615 apiBusy = false
616 else
617 write("Invalid amount.")
618 end
619 else
620 write("Invalid amount.")
621 end
622 os.pullEvent("mouse_click")
623 end
624 elseif tab == 4 then
625 if y == 7 then
626 -- autologin
627 term.setBackgroundColor(colors.black)
628 for i=4,h do
629 term.setCursorPos(1,i)
630 term.clearLine()
631 end
632 term.setCursorPos(2,5)
633 term.setTextColor(colors.lightGray)
634 write("Autologin Setup")
635 term.setCursorPos(2,7)
636 term.setTextColor(colors.brown)
637 write("Full")
638 term.setCursorPos(2,8)
639 term.setTextColor(colors.gray)
640 write("UNENCRYPTED PASSWORD")
641 term.setCursorPos(2,10)
642 term.setTextColor(colors.brown)
643 write("User")
644 term.setCursorPos(2,11)
645 term.setTextColor(colors.gray)
646 write("AUTOFILL USERNAME")
647 term.setCursorPos(2,13)
648 term.setTextColor(colors.brown)
649 write("None")
650 term.setCursorPos(2,14)
651 term.setTextColor(colors.gray)
652 write("NO AUTOLOGIN")
653 local e,c,x,y = os.pullEvent("mouse_click")
654 if y == 7 or y == 8 then
655 term.setCursorPos(2,16)
656 term.setTextColor(colors.brown)
657 write("Enter Password")
658 term.setCursorPos(2,17)
659 term.setTextColor(colors.lightGray)
660 write("> ")
661 -- full
662 walletData.username = username
663 walletData.password = read("*")
664 elseif y == 10 or y == 11 then
665 -- user
666 walletData.username = username
667 walletData.password = nil
668 elseif y == 13 or y == 14 then
669 -- none
670 walletData.username = nil
671 walletData.password = nil
672 end
673 saveWalletData()
674 elseif y == 13 then
675 -- change password
676 term.setBackgroundColor(colors.black)
677 for i=4,h do
678 term.setCursorPos(1,i)
679 term.clearLine()
680 end
681 term.setCursorPos(2,5)
682 term.setTextColor(colors.brown)
683 write("Change Password")
684 term.setTextColor(colors.gray)
685 for i=2,w-1 do
686 term.setCursorPos(i,7)
687 write(string.char(math.random(129,140)))
688 end
689 term.setCursorPos(2,9)
690 term.setTextColor(colors.brown)
691 write("Old Password")
692 term.setCursorPos(2,10)
693 term.setTextColor(colors.lightGray)
694 write("> ")
695 local old_password = read("*")
696 term.setCursorPos(2,12)
697 term.setTextColor(colors.brown)
698 if old_password ~= password then
699 write("Invalid Password")
700 sleep(2)
701 else
702 write("New Password")
703 term.setCursorPos(2,13)
704 term.setTextColor(colors.lightGray)
705 write("> ")
706 local new_password = read("*")
707 term.setCursorPos(2,14)
708 term.setTextColor(colors.lightGray)
709 write("> ")
710 local new_password_confirm = read("*")
711 term.setCursorPos(2,16)
712 term.setTextColor(colors.brown)
713 if new_password == new_password_confirm then
714 apiDebounce()
715 apiBusy = true
716 local ok,res = fullApi.changepass(username, old_password, new_password)
717 apiBusy = false
718 if ok and res then
719 write("Password changed")
720 else
721 write("Error occured")
722 end
723 sleep(2)
724 else
725 write("Passwords must match")
726 sleep(2)
727 end
728 end
729 elseif y == 14 then
730 -- delete account
731 term.setBackgroundColor(colors.black)
732 for i=4,h do
733 term.setCursorPos(1,i)
734 term.clearLine()
735 end
736 term.setCursorPos(2,5)
737 term.setTextColor(colors.red)
738 write("Delete Account")
739 term.setTextColor(colors.gray)
740 for i=2,w-1 do
741 term.setCursorPos(i,7)
742 write(string.char(math.random(129,140)))
743 end
744 term.setCursorPos(2,9)
745 term.setTextColor(colors.brown)
746 write("Enter Password")
747 term.setCursorPos(2,10)
748 term.setTextColor(colors.lightGray)
749 write("> ")
750 local delete_password = read("*")
751 term.setCursorPos(2,12)
752 term.setTextColor(colors.brown)
753 if password ~= delete_password then
754 write("Invalid Password")
755 sleep(2)
756 else
757 write("Confirm Username")
758 term.setCursorPos(2,13)
759 term.setTextColor(colors.lightGray)
760 write("> ")
761 local delete_user = read()
762 if delete_user == username then
763 for i=8,h do
764 term.setCursorPos(1,i)
765 term.clearLine()
766 end
767 term.setBackgroundColor(colors.red)
768 term.setTextColor(colors.black)
769 term.setCursorPos(1,9)
770 term.clearLine()
771 term.setCursorPos(2,9)
772 write("!!! ACCOUNT DELETION !!!")
773 term.setBackgroundColor(colors.black)
774 term.setCursorPos(2,15)
775 term.setTextColor(colors.gray)
776 write("Press any key to abort")
777 term.setCursorPos(2,11)
778 term.setTextColor(colors.red)
779 write("All funds will be lost!")
780 term.setCursorPos(2,12)
781 write("This cannot be undone!")
782 local abort = false
783 for i=20,0,-1 do
784 if abort then
785 break
786 end
787 term.setCursorPos(1,14)
788 term.clearLine()
789 term.setCursorPos(2,14)
790 write("T-"..tostring(i).." DELETION")
791 local abort_tmr = os.startTimer(1)
792 while true do
793 local e,k = os.pullEvent()
794 if e == "timer" and k == abort_tmr then
795 break
796 elseif e == "key" then
797 abort = true
798 break
799 end
800 end
801 if i == 0 and not abort then
802 term.setBackgroundColor(colors.black)
803 term.clear()
804 term.setCursorPos(1,1)
805 term.setTextColor(colors.red)
806 print("Account Deleted.")
807 apiDebounce()
808 apiBusy = true
809 fullApi.delete(username,password)
810 apiBusy = false
811 return
812 end
813 end
814 term.setCursorPos(2,17)
815 term.setTextColor(colors.lime)
816 write("Aborted.")
817 sleep(2)
818 else
819 term.setCursorPos(2,15)
820 term.setTextColor(colors.brown)
821 write("Aborted.")
822 end
823 end
824 end
825 elseif tab == 5 then
826 if y == 8 then
827 if leaderboard and type(leaderboard.submit) == "function" then
828 leaderboard.submit(username)
829 joinedLeaderboard = true
830 end
831 end
832 end
833 end
834 end
835 else
836 apiBusy = false
837 term.setCursorPos(2,12)
838 term.setTextColor(colors.brown)
839 term.clearLine()
840 term.setCursorPos(2,12)
841 write("Invalid credentials.")
842 sleep(2)
843 end
844 else
845 -- Sign Up
846 drawHeader()
847 term.setCursorPos(2,6)
848 term.setTextColor(colors.brown)
849 write("Sign Up")
850 term.setCursorPos(2,8)
851 term.setTextColor(colors.lightGray)
852 write("Username")
853 term.setCursorPos(2,10)
854 write("Password")
855 term.setCursorPos(2,12)
856 write("Confirm")
857 term.setCursorPos(11,8)
858 term.setBackgroundColor(colors.gray)
859 term.setTextColor(colors.lightGray)
860 write(string.rep(" ",w-11))
861 term.setCursorPos(11,10)
862 write(string.rep(" ",w-11))
863 term.setCursorPos(11,12)
864 write(string.rep(" ",w-11))
865 term.setCursorPos(12,8)
866 term.setTextColor(colors.white)
867 local username = read()
868 term.setCursorPos(12,10)
869 term.setTextColor(colors.white)
870 local password = read("*")
871 term.setCursorPos(12,12)
872 local confirm = read("*")
873 term.setBackgroundColor(colors.black)
874 term.setTextColor(colors.gray)
875 term.setCursorPos(2,14)
876 write("Loading...")
877 if #username > 32 then
878 term.setCursorPos(2,14)
879 term.setTextColor(colors.brown)
880 term.clearLine()
881 term.setCursorPos(2,14)
882 write("Name too long!")
883 sleep(2)
884 elseif string.find(username," ") then
885 term.setCursorPos(2,14)
886 term.setTextColor(colors.brown)
887 term.clearLine()
888 term.setCursorPos(2,14)
889 write("Name cannot have spaces")
890 sleep(2)
891 elseif password == confirm then
892 apiDebounce()
893 apiBusy = true
894 if api.register(username,password) then
895 term.setCursorPos(2,14)
896 term.setTextColor(colors.brown)
897 term.clearLine()
898 term.setCursorPos(2,14)
899 write("Account created!")
900 sleep(2)
901 else
902 term.setCursorPos(2,14)
903 term.setTextColor(colors.brown)
904 term.clearLine()
905 term.setCursorPos(2,14)
906 write("Username in use.")
907 sleep(2)
908 end
909 apiBusy = false
910 else
911 term.setCursorPos(2,14)
912 term.setTextColor(colors.brown)
913 term.clearLine()
914 term.setCursorPos(2,14)
915 write("Passwords must match.")
916 sleep(2)
917 end
918 end
919 end
920 autologin = false
921 end
922end
923
924--/ Multithreading /--
925parallel.waitForAny(masterRoutine, balanceRoutine)