· 4 years ago · May 25, 2021, 05:20 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 while true do
271 -- UI Draw
272 term.setBackgroundColor(colors.black)
273 term.clear()
274 paintutils.drawFilledBox(1,1,w,3,colors.gray)
275 term.setCursorPos(2,2)
276 term.setTextColor(colors.lightGray)
277 write("<- ")
278 term.setTextColor(colors.brown)
279 center(tabs[tab],2)
280 term.setTextColor(colors.lightGray)
281 term.setCursorPos(w-2,2)
282 write("->")
283 -- Tab Draw
284 if tab == 1 then
285 drawLogo(2,5)
286 term.setCursorPos(5,5)
287 term.setBackgroundColor(colors.black)
288 term.setTextColor(colors.lightGray)
289 write(username)
290 term.setTextColor(colors.brown)
291 term.setCursorPos(5,6)
292 writeBalance()
293 term.setTextColor(colors.gray)
294 for i=2,w-1 do
295 term.setCursorPos(i,8)
296 write(string.char(math.random(129,140)))
297 end
298 term.setCursorPos(2,h-1)
299 term.setTextColor(colors.lightGray)
300 write("> Logout")
301 elseif tab == 2 then
302 drawLogo(2,h-2)
303 term.setCursorPos(5,h-2)
304 term.setBackgroundColor(colors.black)
305 term.setTextColor(colors.lightGray)
306 write(username)
307 term.setTextColor(colors.brown)
308 term.setCursorPos(5,h-1)
309 writeBalance()
310 term.setTextColor(colors.gray)
311 for i=2,w-1 do
312 term.setCursorPos(i,h-4)
313 write(string.char(math.random(129,140)))
314 end
315 term.setCursorPos(2,5)
316 term.setTextColor(colors.brown)
317 write("Transfer Funds")
318 term.setCursorPos(2,7)
319 term.setTextColor(colors.lightGray)
320 write("Target")
321 term.setCursorPos(2,9)
322 write("Amount")
323 term.setCursorPos(9,7)
324 term.setBackgroundColor(colors.gray)
325 term.setTextColor(colors.lightGray)
326 write(string.rep(" ",w-9))
327 term.setCursorPos(9,9)
328 write(string.rep(" ",w-9))
329 term.setCursorPos(10,7)
330 write(string.sub(transferTO,1,w-11))
331 term.setCursorPos(10,9)
332 write(string.sub(transferAMT,1,w-15).." "..csn)
333 term.setCursorPos(2,11)
334 term.setBackgroundColor(colors.brown)
335 term.setTextColor(colors.gray)
336 write(" Send ")
337 elseif tab == 3 then
338 drawLogo(2,5)
339 term.setCursorPos(5,5)
340 term.setBackgroundColor(colors.black)
341 term.setTextColor(colors.lightGray)
342 write(username)
343 term.setCursorPos(5,6)
344 term.setTextColor(colors.brown)
345 write("Transactions")
346 term.setTextColor(colors.gray)
347 for i=2,w-1 do
348 term.setCursorPos(i,8)
349 write(string.char(math.random(129,140)))
350 end
351
352 if lastTransBalance ~= balance then
353 apiDebounce()
354 apiBusy = true
355 rawTransactions = api.transactions(username, password)
356 apiBusy = false
357 lastTransBalance = balance
358 end
359 if type(rawTransactions) == "table" then
360 local trans = {}
361 local vx = 0
362 if vx < 1 then
363 vx = 1
364 end
365 for i=1,#rawTransactions do
366 local transx = rawTransactions[i]
367 local val = {}
368
369 -- calculate age
370 local age = math.floor((os.epoch("utc")-transx.time )/1000)
371
372 local ageSeconds = age
373 local ageMinutes = math.floor(ageSeconds/60)
374 local ageHours = math.floor(ageMinutes/60)
375 local ageDays = math.floor(ageHours/24)
376 local ageMonths = math.floor(ageDays/31)
377 local ageYears = math.floor(ageMonths/12)
378
379 ageSeconds = ageSeconds - (ageMinutes * 60)
380 ageMinutes = ageMinutes - (ageHours * 60)
381 ageHours = ageHours - (ageDays * 24)
382 ageDays = ageDays - (ageMonths * 31)
383 ageMonths = ageMonths - (ageYears * 12)
384
385 if w > 30 then
386 -- large displays
387 if ageYears > 0 then
388 val.age = tostring(ageYears).."y "..tostring(ageMonths).."m"
389 elseif ageMonths > 0 then
390 val.age = tostring(ageMonths).."mo "..tostring(ageDays).."d"
391 elseif ageDays > 0 then
392 val.age = tostring(ageDays).."d "..tostring(ageHours).."h"
393 elseif ageHours > 0 then
394 val.age = tostring(ageHours).."h "..tostring(ageMinutes).."m"
395 elseif ageMinutes > 0 then
396 val.age = tostring(ageMinutes).."m "..tostring(ageSeconds).."s"
397 else
398 val.age = tostring(ageSeconds).."s"
399 end
400 else
401 -- small displays
402 if ageYears > 0 then
403 val.age = tostring(ageYears).."y"
404 elseif ageMonths > 0 then
405 val.age = tostring(ageMonths).."mo"
406 elseif ageDays > 0 then
407 val.age = tostring(ageDays).."d"
408 elseif ageHours > 0 then
409 val.age = tostring(ageHours).."h"
410 elseif ageMinutes > 0 then
411 val.age = tostring(ageMinutes).."m"
412 else
413 val.age = tostring(ageSeconds).."s"
414 end
415 end
416
417 if transx.to == username then
418 val.address = transx.from
419 val.amount = transx.amount
420 elseif transx.from == username then
421 val.address = transx.to
422 val.amount = -transx.amount
423 else
424 val.address = "Unknown"
425 val.amount = transx.amount
426 end
427 val.id = i
428 trans[#trans+1] = val
429 end
430 local yp = 10
431 local nameAlign = 0
432 for i=scroll,h+scroll-11 do
433 if trans[i] and #tostring(trans[i].amount) > nameAlign then
434 nameAlign = #tostring(trans[i].amount)
435 end
436 end
437 for i=scroll,h+scroll-11 do
438 local v = trans[i]
439 if v then
440 term.setTextColor(colors.gray)
441 if w > 30 then
442 rightAlign(v.age .. " ago",yp)
443 else
444 rightAlign(v.age,yp)
445 end
446
447 term.setTextColor(colors.lightGray)
448 term.setCursorPos(nameAlign+8,yp)
449 write(v.address,yp)
450
451 local str = tostring(v.amount)
452 term.setCursorPos(2,yp)
453 if v.amount > 0 then
454 str = "+"..str.." <<"
455 term.setTextColor(colors.lime)
456 else
457 str = str .. " >>"
458 term.setTextColor(colors.red)
459 end
460 write(str,yp)
461 yp = yp + 1
462 end
463 end
464 else
465 term.setTextColor(colors.gray)
466 center("No transactions",14)
467 end
468 elseif tab == 4 then
469 term.setCursorPos(2,5)
470 term.setBackgroundColor(colors.black)
471 term.setTextColor(colors.lightGray)
472 write("Wallet Settings")
473 term.setTextColor(colors.brown)
474 term.setCursorPos(2,7)
475 write("Autologin: ")
476 if walletData.username and walletData.password then
477 term.setTextColor(colors.brown)
478 write("Full")
479 elseif walletData.username then
480 term.setTextColor(colors.brown)
481 write("User")
482 else
483 term.setTextColor(colors.gray)
484 write("Off")
485 end
486 term.setTextColor(colors.gray)
487 for i=2,w-1 do
488 term.setCursorPos(i,9)
489 write(string.char(math.random(129,140)))
490 end
491 term.setCursorPos(2,11)
492 term.setBackgroundColor(colors.black)
493 term.setTextColor(colors.lightGray)
494 write("Account Settings")
495 term.setTextColor(colors.brown)
496 term.setCursorPos(2,13)
497 write("Change Password")
498 term.setTextColor(colors.red)
499 term.setCursorPos(2,14)
500 write("Delete Account")
501 elseif tab == 5 then
502 apiDebounce()
503 apiBusy = true
504 local leaderboard = api.leaderboard()
505 apiBusy = false
506 local yp = 5
507 for i=1,math.floor((h-4)/3) do
508 if leaderboard[i] then
509 drawLogo(2,yp)
510 term.setCursorPos(5,yp)
511 term.setBackgroundColor(colors.black)
512 term.setTextColor(colors.white)
513 if i == 1 then
514 term.setTextColor(colors.brown)
515 elseif i == 2 then
516 term.setTextColor(colors.lightGray)
517 elseif i == 3 then
518 term.setTextColor(colors.orange)
519 end
520 write("#"..tostring(i)..": "..leaderboard[i][1])
521 term.setCursorPos(5,yp+1)
522 term.setBackgroundColor(colors.black)
523 term.setTextColor(colors.gray)
524 write(tostring(leaderboard[i][2]).." "..csn)
525 yp = yp + 3
526 end
527 end
528 end
529 -- Event Handling
530 local e,c,x,y
531 while true do
532 e,c,x,y = os.pullEvent()
533 if e == "mouse_click" or e == "mouse_scroll" then
534 break
535 end
536 end
537 if e == "mouse_scroll" then
538 scroll = scroll + c
539 if scroll < 1 then
540 scroll = 1
541 end
542 elseif e == "mouse_click" then
543 if y == 1 or y == 2 or y == 3 then
544 if x < w/2 then
545 tab = tab - 1
546 if tab == 0 then
547 tab = #tabs
548 end
549 elseif x > w/2 then
550 tab = tab + 1
551 if tab > #tabs then
552 tab = 1
553 end
554 end
555 elseif tab == 1 then
556 if y == h-1 then
557 break
558 end
559 elseif tab == 2 then
560 if y == 7 then
561 term.setBackgroundColor(colors.gray)
562 term.setTextColor(colors.white)
563 term.setCursorPos(10,7)
564 transferTO = read()
565 elseif y == 9 then
566 term.setBackgroundColor(colors.gray)
567 term.setTextColor(colors.white)
568 term.setCursorPos(10,9)
569 transferAMT = read()
570 elseif y == 11 and x >= 2 and x <= 8 then
571 term.setBackgroundColor(colors.black)
572 term.setTextColor(colors.brown)
573 term.setCursorPos(10,11)
574 write("...")
575 term.setCursorPos(10,11)
576 if tonumber(transferAMT) then
577 if tonumber(transferAMT) > 0 then
578 apiDebounce()
579 apiBusy = true
580 local ok,err = api.send(username,password,transferTO,tonumber(transferAMT))
581 if ok and balance ~= api.balance(username) then
582 write("Success!")
583 else
584 write("Failed.")
585 end
586 apiBusy = false
587 else
588 write("Invalid amount.")
589 end
590 else
591 write("Invalid amount.")
592 end
593 os.pullEvent("mouse_click")
594 end
595 elseif tab == 4 then
596 if y == 7 then
597 -- autologin
598 term.setBackgroundColor(colors.black)
599 for i=4,h do
600 term.setCursorPos(1,i)
601 term.clearLine()
602 end
603 term.setCursorPos(2,5)
604 term.setTextColor(colors.lightGray)
605 write("Autologin Setup")
606 term.setCursorPos(2,7)
607 term.setTextColor(colors.brown)
608 write("Full")
609 term.setCursorPos(2,8)
610 term.setTextColor(colors.gray)
611 write("UNENCRYPTED PASSWORD")
612 term.setCursorPos(2,10)
613 term.setTextColor(colors.brown)
614 write("User")
615 term.setCursorPos(2,11)
616 term.setTextColor(colors.gray)
617 write("AUTOFILL USERNAME")
618 term.setCursorPos(2,13)
619 term.setTextColor(colors.brown)
620 write("None")
621 term.setCursorPos(2,14)
622 term.setTextColor(colors.gray)
623 write("NO AUTOLOGIN")
624 local e,c,x,y = os.pullEvent("mouse_click")
625 if y == 7 or y == 8 then
626 term.setCursorPos(2,16)
627 term.setTextColor(colors.brown)
628 write("Enter Password")
629 term.setCursorPos(2,17)
630 term.setTextColor(colors.lightGray)
631 write("> ")
632 -- full
633 walletData.username = username
634 walletData.password = read("*")
635 elseif y == 10 or y == 11 then
636 -- user
637 walletData.username = username
638 walletData.password = nil
639 elseif y == 13 or y == 14 then
640 -- none
641 walletData.username = nil
642 walletData.password = nil
643 end
644 saveWalletData()
645 elseif y == 13 then
646 -- change password
647 term.setBackgroundColor(colors.black)
648 for i=4,h do
649 term.setCursorPos(1,i)
650 term.clearLine()
651 end
652 term.setCursorPos(2,5)
653 term.setTextColor(colors.brown)
654 write("Change Password")
655 term.setTextColor(colors.gray)
656 for i=2,w-1 do
657 term.setCursorPos(i,7)
658 write(string.char(math.random(129,140)))
659 end
660 term.setCursorPos(2,9)
661 term.setTextColor(colors.brown)
662 write("Old Password")
663 term.setCursorPos(2,10)
664 term.setTextColor(colors.lightGray)
665 write("> ")
666 local old_password = read("*")
667 term.setCursorPos(2,12)
668 term.setTextColor(colors.brown)
669 if old_password ~= password then
670 write("Invalid Password")
671 sleep(2)
672 else
673 write("New Password")
674 term.setCursorPos(2,13)
675 term.setTextColor(colors.lightGray)
676 write("> ")
677 local new_password = read("*")
678 term.setCursorPos(2,14)
679 term.setTextColor(colors.lightGray)
680 write("> ")
681 local new_password_confirm = read("*")
682 term.setCursorPos(2,16)
683 term.setTextColor(colors.brown)
684 if new_password == new_password_confirm then
685 apiDebounce()
686 apiBusy = true
687 local ok,res = fullApi.changepass(username, old_password, new_password)
688 apiBusy = false
689 if ok and res then
690 write("Password changed")
691 else
692 write("Error occured")
693 end
694 sleep(2)
695 else
696 write("Passwords must match")
697 sleep(2)
698 end
699 end
700 elseif y == 14 then
701 -- delete account
702 term.setBackgroundColor(colors.black)
703 for i=4,h do
704 term.setCursorPos(1,i)
705 term.clearLine()
706 end
707 term.setCursorPos(2,5)
708 term.setTextColor(colors.red)
709 write("Delete Account")
710 term.setTextColor(colors.gray)
711 for i=2,w-1 do
712 term.setCursorPos(i,7)
713 write(string.char(math.random(129,140)))
714 end
715 term.setCursorPos(2,9)
716 term.setTextColor(colors.brown)
717 write("Enter Password")
718 term.setCursorPos(2,10)
719 term.setTextColor(colors.lightGray)
720 write("> ")
721 local delete_password = read("*")
722 term.setCursorPos(2,12)
723 term.setTextColor(colors.brown)
724 if password ~= delete_password then
725 write("Invalid Password")
726 sleep(2)
727 else
728 write("Confirm Username")
729 term.setCursorPos(2,13)
730 term.setTextColor(colors.lightGray)
731 write("> ")
732 local delete_user = read()
733 if delete_user == username then
734 for i=8,h do
735 term.setCursorPos(1,i)
736 term.clearLine()
737 end
738 term.setBackgroundColor(colors.red)
739 term.setTextColor(colors.black)
740 term.setCursorPos(1,9)
741 term.clearLine()
742 term.setCursorPos(2,9)
743 write("!!! ACCOUNT DELETION !!!")
744 term.setBackgroundColor(colors.black)
745 term.setCursorPos(2,15)
746 term.setTextColor(colors.gray)
747 write("Press any key to abort")
748 term.setCursorPos(2,11)
749 term.setTextColor(colors.red)
750 write("All funds will be lost!")
751 term.setCursorPos(2,12)
752 write("This cannot be undone!")
753 local abort = false
754 for i=20,0,-1 do
755 if abort then
756 break
757 end
758 term.setCursorPos(1,14)
759 term.clearLine()
760 term.setCursorPos(2,14)
761 write("T-"..tostring(i).." DELETION")
762 local abort_tmr = os.startTimer(1)
763 while true do
764 local e,k = os.pullEvent()
765 if e == "timer" and k == abort_tmr then
766 break
767 elseif e == "key" then
768 abort = true
769 break
770 end
771 end
772 if i == 0 and not abort then
773 term.setBackgroundColor(colors.black)
774 term.clear()
775 term.setCursorPos(1,1)
776 term.setTextColor(colors.red)
777 print("Account Deleted.")
778 apiDebounce()
779 apiBusy = true
780 fullApi.delete(username,password)
781 apiBusy = false
782 return
783 end
784 end
785 term.setCursorPos(2,17)
786 term.setTextColor(colors.lime)
787 write("Aborted.")
788 sleep(2)
789 else
790 term.setCursorPos(2,15)
791 term.setTextColor(colors.brown)
792 write("Aborted.")
793 end
794 end
795 end
796 end
797 end
798 end
799 else
800 apiBusy = false
801 term.setCursorPos(2,12)
802 term.setTextColor(colors.brown)
803 term.clearLine()
804 term.setCursorPos(2,12)
805 write("Invalid credentials.")
806 sleep(2)
807 end
808 else
809 -- Sign Up
810 drawHeader()
811 term.setCursorPos(2,6)
812 term.setTextColor(colors.brown)
813 write("Sign Up")
814 term.setCursorPos(2,8)
815 term.setTextColor(colors.lightGray)
816 write("Username")
817 term.setCursorPos(2,10)
818 write("Password")
819 term.setCursorPos(2,12)
820 write("Confirm")
821 term.setCursorPos(11,8)
822 term.setBackgroundColor(colors.gray)
823 term.setTextColor(colors.lightGray)
824 write(string.rep(" ",w-11))
825 term.setCursorPos(11,10)
826 write(string.rep(" ",w-11))
827 term.setCursorPos(11,12)
828 write(string.rep(" ",w-11))
829 term.setCursorPos(12,8)
830 term.setTextColor(colors.white)
831 local username = read()
832 term.setCursorPos(12,10)
833 term.setTextColor(colors.white)
834 local password = read("*")
835 term.setCursorPos(12,12)
836 local confirm = read("*")
837 term.setBackgroundColor(colors.black)
838 term.setTextColor(colors.gray)
839 term.setCursorPos(2,14)
840 write("Loading...")
841 if #username > 32 then
842 term.setCursorPos(2,14)
843 term.setTextColor(colors.brown)
844 term.clearLine()
845 term.setCursorPos(2,14)
846 write("Name too long!")
847 sleep(2)
848 elseif string.find(username," ") then
849 term.setCursorPos(2,14)
850 term.setTextColor(colors.brown)
851 term.clearLine()
852 term.setCursorPos(2,14)
853 write("Name cannot have spaces")
854 sleep(2)
855 elseif password == confirm then
856 apiDebounce()
857 apiBusy = true
858 if api.register(username,password) then
859 term.setCursorPos(2,14)
860 term.setTextColor(colors.brown)
861 term.clearLine()
862 term.setCursorPos(2,14)
863 write("Account created!")
864 sleep(2)
865 else
866 term.setCursorPos(2,14)
867 term.setTextColor(colors.brown)
868 term.clearLine()
869 term.setCursorPos(2,14)
870 write("Username in use.")
871 sleep(2)
872 end
873 apiBusy = false
874 else
875 term.setCursorPos(2,14)
876 term.setTextColor(colors.brown)
877 term.clearLine()
878 term.setCursorPos(2,14)
879 write("Passwords must match.")
880 sleep(2)
881 end
882 end
883 end
884 autologin = false
885 end
886end
887
888--/ Multithreading /--
889parallel.waitForAny(masterRoutine, balanceRoutine)