Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Exit type - use 'term' to exit the
- -- program, or 'stop' to shutdown the terminal.
- -- jakendrick3
- stopType = "term"
- os.loadAPI("jenisis")
- modem = peripheral.find("modem")
- scrX, scrY = term.getSize()
- if not modem then
- print("No modem connected!")
- return
- end
- if term.isColor() then
- greenbar = colors.green
- redbar = colors.red
- else
- greenbar = colors.white
- redbar = colors.white
- end
- modem.open(1024)
- function receive()
- event = {os.pullEvent("modem_message")}
- return event[5]
- end
- function broadcast(transmes)
- modem.transmit(1024, 1024, transmes)
- end
- function greenBar()
- term.setBackgroundColor(greenbar)
- term.write(string.rep(" ", scrX))
- term.setBackgroundColor(colors.black)
- end
- function redBar()
- term.setBackgroundColor(redbar)
- term.write(string.rep(" ", scrX))
- term.setBackgroundColor(colors.black)
- end
- function inputBar(prompt)
- term.setCursorPos(1, scrY - 2)
- term.clearLine()
- term.setCursorPos(1, scrY - 1)
- term.clearLine()
- term.setCursorPos(1, scrY - 3)
- greenBar()
- term.setCursorPos(1, scrY)
- greenBar()
- term.setCursorPos(1, scrY - 2)
- term.write(prompt)
- term.setCursorPos(1, scrY - 1)
- info = io.read()
- return info
- end
- function errorMes(message, barColor)
- if barColor == "green" then
- printBar = greenBar
- else
- printBar = redBar
- end
- term.setCursorPos(1, (scrY / 2) + 2)
- printBar()
- term.setCursorPos(1, (scrY / 2) + 4)
- printBar()
- term.setCursorPos(math.floor((scrX / 2) - (#message / 2)), (scrY / 2) + 3)
- term.write(message)
- os.pullEvent("key" or "mouse_click")
- end
- static = {
- "Bank ATM Utility",
- "Home Screen"
- }
- menu = {
- "Login",
- "Check funds",
- "Make transfer",
- "New account",
- "Exit"
- }
- request = {}
- request["user"] = "user"
- request["key"] = 1234567890
- request["target"] = "otheruser"
- request["amount"] = 1
- request["type"] = "transfer"
- loggedin = false
- user = "ifyouseethisonthescreenreportit"
- key = "woahwaohsodja"
- while true do
- if loggedin then
- static[3] = "Loggged in as "..user
- menu[1] = "Logout"
- request.user = user
- request.key = key
- else
- static[3] = "Not logged in."
- menu[1] = "Login"
- end
- cselected = jenisis.drawScreen(static, menu)
- if cselected == 1 then
- if not loggedin then
- info = inputBar("Enter target file, type default for default: ")
- if info == nil or "" then
- info = "default"
- end
- if info == "default" then
- if fs.exists("disk/account") and not fs.exists("account") then
- file = fs.open("disk/account", "r")
- user = file.readLine()
- key = file.readLine()
- file.close()
- loggedin = true
- elseif fs.exists("account") and not fs.exists("disk/account") then
- file = fs.open("account", "r")
- user = file.readLine()
- key = file.readLine()
- file.close()
- loggedin = true
- elseif fs.exists("account") and fs.exists("disk/account") then
- file = fs.open("disk/account", "r")
- user = file.readLine()
- key = file.readLine()
- file.close()
- loggedin = true
- else
- errorMes("Default file does not exist.", "red")
- os.pullEvent("key" or "mouse_click")
- end
- elseif fs.exists(info) and info ~= nil then
- file = fs.open(info, "r")
- user = file.readLine()
- key = file.readLine()
- file.close()
- loggedin = true
- else
- errorMes("File does not exist.", "red")
- os.pullEvent("key" or "mouse_click")
- end
- if loggedin == true then
- request.user = user
- request.key = key
- errorMes("Logged in!", "green")
- end
- elseif loggedin then
- user = nil
- key = nil
- loggedin = false
- errorMes("Logged out!", "green")
- end
- elseif cselected == 2 then
- request.type = "getmoney"
- broadcast(textutils.serialise(request))
- local mes = receive()
- if mes == "Failed" then
- printing = "The process has failed."
- errorMes(printing, "red")
- else
- local printing = ("You have $"..mes)
- errorMes(printing, "green")
- end
- elseif cselected == 3 then
- request.type = "transfer"
- request.target = inputBar("Enter target account: ")
- request.amount = inputBar("Enter amount: ")
- conFirm = inputBar("Type yes to confirm: ")
- if string.lower(conFirm) == "yes" then
- broadcast(textutils.serialize(request))
- result = receive()
- if result == "Completed!" then
- errorMes(result, "green")
- elseif result == "Failed." or result == "Not enough money." then
- errorMes(result, "red")
- else
- errorMes("Unexpected error.", "red")
- end
- else
- errorMes("Cancelled.", "green")
- end
- elseif cselected == 4 then
- request.type = "newuser"
- newuser = inputBar("Enter new account name: ")
- request.target = newuser
- broadcast(textutils.serialize(request))
- mes = receive()
- newac = textutils.unserialize(mes)
- if type(newac) == "table" then
- if newac.result == "Completed" then
- path = inputBar("Enter path for user, or 'default' or 'disk'", "green")
- if path == "default" or path == nil or path == "" then
- if fs.exists("account") and fs.exists("disk/account") then
- errorMes("Default file exists.", "red")
- else
- file = fs.open("account", "w")
- file.writeLine(newuser)
- file.writeLine(newac.key)
- file.close()
- errorMes("Completed and saved to default location!", "green")
- user = newuser
- key = newac.key
- loggedin = true
- end
- elseif path == "disk" then
- if fs.exists("disk/account") then
- errorMes("Disk account exists.", "red")
- else
- file = fs.open("disk/account", "w")
- file.writeLine(newuser)
- file.writeLine(newac.key)
- file.close()
- errorMes("Completed and saved to disk!", "green")
- user = newuser
- key = newac.key
- loggedin = true
- end
- elseif not fs.exists(path) then
- file = fs.open(path, "w")
- file.writeLine(newuser)
- file.writeLine(newac.key)
- file.close()
- errorMes("Completed!", "green")
- user = newuser
- key = newac.key
- loggedin = true
- else
- errorMes("File exists.")
- end
- elseif newac.result == "UE" then
- errorMes("User exists.", "red")
- else
- errorMes("Failed.", "red")
- end
- else
- errorMes("Unexpected error.", "red")
- end
- elseif cselected == 5 then
- if stopType == "term" then
- return
- elseif stopType == "stop" then
- os.shutdown()
- end
- end
- end
Add Comment
Please, Sign In to add comment