Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local colorT = colors.white
- os.loadAPI("gcapi.lua")
- os.loadAPI("apis")
- local sides = rs.getSides()
- local chnl = 9584
- local modem, xd, yd
- local curr = "activity"
- local stop = false
- local open = false
- for i = 1, #sides do
- if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == "modem" then
- modem = peripheral.wrap(sides[i])
- modem.open(chnl)
- open = true
- end
- end
- assert(open, "Attach a Wireless Modem.")
- local user, pass, sid, id, dEnable
- local x, y = term.getSize()
- local win = window.create(1, y/4, x, y)
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- function bar()
- paintutils.drawLine(1, 1, x, 1, colors.orange)
- local s = "Glo"
- but = {"Activity ", "Actions ", "X"}
- butN = {"activity", "action", "logout"}
- local prevLen = 0
- term.setTextColor(colors.white)
- for i = #but, 1, -1 do
- apis.button.add(x-(prevLen+string.len(but[i])), 1, x-(prevLen-1), 1, butN[i])
- term.setCursorPos(x-(prevLen+string.len(but[i])-1), 1)
- term.setTextColor(colors.white)
- term.write(but[i])
- prevLen = prevLen+string.len(but[i])
- end
- term.setCursorPos(1, 1)
- term.write(s)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colorT)
- end
- function checkDefault()
- local x, y = term.getSize()
- file = fs.open(".default", "r")
- if not file then
- local tfile = fs.open(".default", "w")
- tfile.writeLine("false")
- tfile.close()
- denable = false
- else
- dEnable = file.readLine()
- if dEnable == "true" then dEnable = true else dEnable = false end
- end
- if xd and yd then
- local x0 = xd
- local y0 = yd
- apis.button.add(x0, y0, x0+4, y0, "default")
- term.setTextColor(colors.yellow)
- if dEnable == true then
- paintutils.drawLine(x0, y0, x0+4, y0, colors.green)
- term.setCursorPos(x0+1, y0)
- term.write("on")
- else
- paintutils.drawLine(x0, y0, x0+4, y0, colors.red)
- term.setCursorPos(x0+1, y0)
- term.write("off")
- end
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colorT)
- end
- end
- function toggleDefault()
- local file = fs.open(".default", "w")
- file.writeLine(not dEnable)
- dEnable = not dEnable
- file.close()
- end
- function sendDeposit()
- repeat
- while dEnable do
- e,side,freq,rfreq,msg,dist = os.pullEvent("modem_message")
- if type(dist) == "number" and dist <= 10 then
- modem.transmit(rfreq, freq, id)
- end
- end
- sleep(.5)
- until true == false
- end
- function doTransfer()
- tBPos = {}
- local passt
- local x, y = term.getSize()
- apis.button.clear()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- bar()
- term.setTextColor(colors.gray)
- local boxes = {{"toUser", "Username"}, {"amt", "Amount"}, {"desc", "Description"}}
- for i = 1, #boxes do
- local x0, y0 = 2, (y/4)*i
- apis.button.add(x0, (y/4)*i, x-1, (y/4)*i, boxes[i][1])
- paintutils.drawLine(x0, (y/4)*i, x-1, (y/4)*i, colors.white)
- term.setCursorPos(x0, y0)
- term.write(boxes[i][2])
- tBPos[#tBPos+1] = {x0, (y/4)*i, x-1, (y/4)*i}
- end
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- apis.button.add(2, y-1, x-2, y-1, "cancel")
- paintutils.drawLine(2, y-1, x-2, y-1, colors.red)
- local ca = "Cancel"
- term.setCursorPos((x/2)-(string.len(ca)/2)-1, y-1)
- term.write(ca)
- term.setBackgroundColor(colors.white)
- repeat
- local name = apis.button.check()
- if name then
- for i = 1, #boxes do
- if name == boxes[i][1] then
- term.setTextColor(colors.black)
- paintutils.drawLine(tBPos[i][1], tBPos[i][2], tBPos[i][3], tBPos[i][4], colors.white)
- term.setCursorPos(tBPos[i][1], tBPos[i][2])
- local inp = read()
- boxes[i][3] = inp
- end
- end
- all = 0
- for i = 1, #boxes do
- if boxes[i][3] then
- all = all+1
- end
- end
- if all == #boxes then
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.red)
- if not boxes[1][3] == "" then
- local s = "Insert Valid ID"
- apis.text.center(s, boxes[1][2]+1)
- elseif not tonumber(boxes[2][3]) and boxes[2][3] ~= "0" then
- local s = "Insert Valid Amount"
- apis.text.center(s, boxes[2][2]+1)
- elseif boxes[1][3] ~= "" and tonumber(boxes[2][3]) then
- passt = true
- end
- end
- for i = 1, #boxes do
- if boxes[i][3] == "" then
- paintutils.drawLine(tBPos[i][1], tBPos[i][2], tBPos[i][3], tBPos[i][4], colors.white)
- term.setCursorPos(tBPos[i][1], tBPos[i][2])
- term.setTextColor(colors.gray)
- term.write(boxes[i][2])
- end
- end
- end
- until name == "cancel" or passt == true or name == "exit"
- if passt then
- if boxes[1][3] then
- suc, uid = gc.getAccountID(boxes[1][3])
- else
- suc, uid = gc.getNearestID()
- end
- local suc, res
- if not pass then
- suc, res = gc.transferAID2AID(id, uid, tonumber(boxes[2][3]), boxes[3][3])
- else
- suc, res = gc.transferSID2AID(sid, uid, tonumber(boxes[2][3]), boxes[3][3])
- end
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- if not suc then
- apis.text.center("Transfer failed", y/2)
- apis.text.center(res, (y/2)+1)
- else
- apis.text.center("Transfer succeeded", y/2)
- end
- sleep(1)
- end
- if name == "cancel" then
- return "back"
- elseif name == "exit" then
- return "exit"
- end
- end
- function loginDisp()
- local x, y = term.getSize()
- local def = false
- apis.button.clear()
- local suc, id = gc.getAccountID(user)
- if suc and not def then
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- repeat
- while not stop do
- local suc, bal = gc.getBalance(id)
- term.setCursorPos(1, 3)
- term.write("Balance: ")
- term.setCursorPos(x/2, 3)
- if suc then
- term.write(bal.." GLO")
- else
- term.write("Not Found")
- end
- term.setCursorPos(1, 4)
- term.write("User ID:")
- term.setCursorPos(x/2, 4)
- term.write(id)
- term.setCursorPos(1, 4)
- term.write("Broadcast Deposit: ")
- xd, yd = term.getCursorPos()
- elseif not suc then
- apis.text.center("Failed to load user", y/2)
- apis.text.center(user, (y/2)+1)
- sleep(1)
- break
- end
- sleep(5)
- end
- sleep(5)
- until true == false
- end
- end
- function actionDisp()
- repeat
- term.redirect(win)
- local tBtns = {{"transfer", colors.orange, "Transfer"}, {"withdraw", colors.lightGray, "Withdraw (NYI)"}} --, {"logout", colors.red, "Log Out"}}
- term.setBackgroundColor(colors.white)
- checkDefault()
- term.setTextColor(colors.yellow)
- for i = 1, #tBtns do
- local ys = {}
- for j = -1+i, i do
- table.insert(ys, (y/(#tBtns*2))*(j+#tBtns))
- end
- if i ~= 2 then
- apis.button.add(1, ys[1]+1, x, ys[2], tBtns[i][1])
- end
- paintutils.drawFilledBox(1, ys[1]+1, x, ys[2], tBtns[i][2])
- apis.text.center(tBtns[i][3], ys[1]+2)
- end
- def = false
- term.redirect(term.native())
- name = apis.button.check()
- if name == "transfer" then
- name = doTransfer()
- elseif name == "withdraw" then
- checkDeposit()
- elseif name == "default" then
- toggleDefault()
- checkDefault()
- def = true
- elseif name == "logout" then
- user = nil
- pass = nil
- sid = nil
- id = nil
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- loginScreen()
- end
- until name == "exit"
- return true
- end
- function activityDisp()
- term.redirect(win)
- term.redirect(term.current())
- end
- function genDisp()
- end
- function doLogin()
- local x, y = term.getSize()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setTextColor(colors.yellow)
- local s = "Logging in..."
- apis.text.center(s, y/2)
- local suc
- suc, id = gc.getAccountID(user)
- if type(pass) == "string" and pass then
- suc, sid = gc.login(user, pass)
- end
- if suc then
- term.clear()
- apis.text.center("Logged in Successfully", y/2)
- sleep(.5)
- ex = genDisp()
- if ex then return "exit" end
- else
- term.clear()
- apis.text.center("Login Failed:", y/2)
- if pass then
- apis.text.center(sid, (y/2)+1)
- else
- apis.text.center(id, (y/2)+1)
- end
- sleep(.5)
- return "exit"
- end
- end
- function loginScreen()
- apis.button.clear()
- local x, y = term.getSize()
- term.setTextColor(colors.orange)
- apis.text.center("Glo.Cash", (y/2)-3)
- local x0, y0 = 2, (y/2)-1
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- apis.button.add(x0, y0, x-1, y0, "name")
- paintutils.drawLine(x0, y0, x-1, y0, colors.white)
- term.setCursorPos(x0, y0)
- term.write("Username")
- local x1, y1 = 2, (y/2)+1
- apis.button.add(x1, y1, x-1, y1, "pass")
- paintutils.drawLine(x1, y1, x-1, y1, colors.white)
- term.setCursorPos(x1, y1)
- term.write("Password (optional)")
- paintutils.drawLine(2, (y/2)+3, x-1, (y/2)+3, colors.orange)
- apis.button.add(2, (y/2)+3, x-1, (y/2)+3, "valid")
- term.setTextColor(colors.white)
- apis.text.center("Log In", (y/2)+3)
- repeat
- term.setTextColor(colors.black)
- name = apis.button.check()
- if name ~= nil and name ~= "exit" then
- if name == "name" then
- paintutils.drawLine(x0, y0, x-1, y0, colors.white)
- term.setCursorPos(x0, y0)
- user = read()
- if user == "" then
- user = nil
- paintutils.drawLine(x0, y0, x-1, y0, colors.white)
- term.setCursorPos(x0, y0)
- term.setTextColor(colors.gray)
- term.write("Username")
- end
- end
- if name == "pass" then
- paintutils.drawLine(x1, y1, x-1, y1, colors.white)
- term.setCursorPos(x1, y1)
- pass = read("*")
- if pass == "" then
- pass = nil
- paintutils.drawLine(x1, y1, x-1, y1, colors.white)
- term.setCursorPos(x1, y1)
- term.setTextColor(colors.gray)
- term.write("Password (optional)")
- end
- end
- if name == "valid" then
- name = doLogin()
- end
- elseif name == "exit" then
- break
- end
- until name ~= nil and name == "exit"
- end
- repeat
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- parallel.waitForAny(loginScreen, sendDeposit)
- until true == false
Add Comment
Please, Sign In to add comment