Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- relay = 76
- server = 75
- status = 84
- atmb = 69
- atmno = 1
- atmprot = "atm"..atmno
- rednet.open("top")
- table1 = {}
- receiptvar = {}
- table2 = {}
- table3 = {}
- printer = peripheral.wrap("back")
- function receive()
- senderId, message, protocol = rednet.receive("bank")
- end
- function deposit()
- deptable = {"deposit"}
- rednet.send(atmb,deptable,atmprot)
- senderId, message, protocol = rednet.receive(atmprot,7)
- term.setCursorPos(15,15)
- if senderId == atmb then
- if message[1] == "confirmed" then
- print(message[2].." added to your account")
- bal = bal + message[2]
- table.insert(receiptvar,1,"deposit "..message[2])
- else
- print(message[1])
- end
- end
- os.sleep(1)
- end
- function finish()
- signout = true
- --receipt
- if receiptvar[1] ~= nil then
- printer.newPage()
- w, h = printer.getPageSize()
- printer.setCursorPos(1,1)
- printer.write("x------<ChockBank>------x")
- printer.setCursorPos(1,h)
- printer.write("x-----------------------x")
- height = h
- while h > 2 do
- printer.setCursorPos(1,h - 1)
- printer.write("| |")
- h = h - 1
- end
- receipty = 1
- testvar = {"15","14"}
- while receiptvar[receipty] ~= nil do
- printer.setCursorPos(5,receipty + 2)
- printer.write(receiptvar[receipty])
- receipty = receipty + 1
- end
- file = io.open("receiptno","r")
- receiptno = file:read()
- file:close()
- fs.delete("receiptno")
- file = io.open("receiptno","w")
- contents = tonumber(receiptno) + 1
- file:write(tostring(contents))
- file:close()
- receiptid = atmprot..tonumber(receiptno)
- printer.setCursorPos(3, height - 1)
- printer.write(receiptid.." "..username)
- printer.setPageTitle("receipt-"..receiptid)
- printer.endPage()
- file = io.open("receipts/"..receiptid,"w")
- table.insert(receiptvar,1,username)
- file:write(textutils.serialize(receiptvar))
- file:close()
- receiptmes = {75,username,"receipt",receiptvar,receiptid}
- rednet.send(76,receiptmes,"bank")
- receiptvar = {}
- term.clear()
- backdrop()
- term.setCursorPos(13,7)
- print("please take your receipt")
- end
- timeout = os.startTimer(5)
- os.sleep(2)
- os.reboot()
- end
- function withdraw()
- term.clear()
- backdrop()
- term.setCursorPos(15,6)
- print("Enter Value:")
- table2 = {}
- term.setCursorPos(27,6)
- amount = tonumber(read())
- term.setCursorPos(27,6)
- if amount == nil then
- print("invalid value")
- end
- if (bal > amount or bal == amount) and amount ~= nil then
- table2 = {"withdraw",amount}
- rednet.send(atmb,table2,atmprot)
- senderId, message, protocol = rednet.receive(atmprot,7)
- if message == nil then
- print("error")
- end
- if senderId == atmb and message[1] == "confirmed" then
- print("Confirmed")
- table3 = {}
- table3 = {server,username,"withdraw",password,amount}
- table.insert(receiptvar,1,"withdraw "..amount)
- rednet.send(relay,table3,"bank")
- bal = bal - amount
- end
- if senderId == atmb and message[1] == "denied" then
- print("Too large, maximum:"..message[2])
- end
- else
- print("Insufficient funds")
- end
- end
- function atmselect()
- term.setCursorPos(1,6)
- print("| x-----------x x-----------x")
- print("| | Withdraw | | Deposit |")
- print("| x-----------x x-----------x")
- term.setCursorPos(1,10)
- print("| x-----------------x x-----------x")
- print("| | Balance: | | Finish |")
- print("| x-----------------x x-----------x")
- term.setCursorPos(16,11)
- print(bal)
- end
- function atm()
- signout = false
- while signout == false do
- term.clear()
- backdrop()
- atmselect()
- event, button, x, y = os.pullEvent("mouse_click")
- if x > 10 and x < 20 then
- if y == 7 then
- withdraw()
- end
- end
- if x > 32 and x < 42 then
- if y == 7 then
- deposit()
- end
- if y == 11 then
- finish()
- end
- end
- os.sleep(1)
- end
- end
- function signin()
- term.clear()
- backdrop()
- term.setCursorPos(17,9)
- print("Enter Username:")
- term.setCursorPos(17,10)
- print("_______________")
- term.setCursorPos(17,10)
- username = read()
- table1 = {server,username,"signin"}
- rednet.send(relay,table1,"bank")
- local senderId, message, protocol = rednet.receive("bank")
- if message[3] == "confirmed" then
- term.setCursorPos(17,9)
- print("Enter Passphrase:")
- term.setCursorPos(17,10)
- print("__________________")
- term.setCursorPos(17,10)
- password = read("*")
- table1 = {server,username,"signin2",password}
- rednet.send(relay,table1,"bank")
- message[3] = nil
- senderId, message, protocol = rednet.receive("bank")
- if message[3] == "confirmed" and username ~= "" then
- bal = tonumber(message[4])
- os.sleep(0.2)
- atm()
- else
- term.setCursorPos(17,10)
- print("Incorrect passphrase")
- os.sleep(1)
- end
- else
- term.setCursorPos(17,10)
- print("Invalid username ")
- os.sleep(1)
- end
- end
- function backdrop()
- term.setCursorPos(1,1)
- print("x------------<ChockBank Cash Machine>-------------x")
- backdropn = 0
- while backdropn < 16 do
- term.setCursorPos(1,backdropn + 2)
- print("|")
- term.setCursorPos(51,backdropn + 2)
- print("|")
- backdropn = backdropn + 1
- end
- print("x-------------------------------------------------x")
- end
- local timeout = os.startTimer(5)
- while true do
- statvar = {"idle",atmid}
- statmes = {status,statvar}
- term.clear()
- backdrop()
- term.setCursorPos(15,9)
- if printer.getInkLevel() ~= 0 and printer.getPaperLevel() ~= 0 then
- print("Press Any Key To Begin >")
- event = {os.pullEvent()}
- if event[1] == "key" then
- os.sleep(0.2)
- signin()
- elseif event[1] == "timer" and event[2] == timeout then
- timeout = os.startTimer(5)
- rednet.send(relay,statmes,"bank")
- end
- else
- print(" Out of ink/paper")
- os.sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement