Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program is the new Banking App
- settings.load(".settings")
- local SecureProtocol = settings.get("Secure_WirelessProtocol")
- local BankingFormat = "banking_public1"
- local LocalDevices = {}
- local UserInfo = {}
- local System = settings.get("banking_System")
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function GetLocalDevices()
- rednet.broadcast(BankingFormat)
- for i = 1, 6 do
- local id, message, protocol = rednet.recieve()
- if message == BankingFormat then
- LocalDevices[#LocalDevices + 1 ] = {id, protocol}
- end
- end
- end
- function CUI(m) --declare function
- n=1
- local l = #m
- while true do
- term.setCursorPos(1,4)
- for i=1, #m, 1 do --traverse the table of options
- if i==n then term.clearLine() print(i, " ["..m[i].."]") else term.clearLine() print(i, " ", m[i]) end --print them
- end
- a, b= os.pullEvent("key") --wait for keypress
- if b==keys.w and n>1 then n=n-1 end
- if b==keys.s and n<l then n=n+1 end
- if b==keys.enter then break end
- end
- return n --return the value
- end
- local function RemoteTransfer(Message,id)
- Clear()
- print("Transfer Request")
- print(Message[3])--Sender Name
- print(Message[2])--amount
- print(Message[4])--item
- print("Accept? y/n")
- local event, key
- repeat
- event, key = os.pullEvent("key")
- until key == keys.y or key == keys.n
- if key == keys.y then
- if settings.get("banking_Balance") - Message[2] >= 0 then
- rednet.send(id,"accepted",SecureProtocol)
- if Message[5] == "deposit" then
- shell.run(System, "deposit", Message[2])
- else
- shell.run(System, "withdraw", Message[2])
- end
- else
- rednet.send(id,"declined",SecureProtocol)
- print("Transfer Declined, Insignificant Funds")
- end
- end
- os.sleep(3)
- MainFun()
- end
- local function DecryptDetails(data)
- end
- local function TransferMenu()
- Clear()
- print("transfer Menu")
- local options = {"send","receive","return"}
- local n = CUI(options)
- local Decide = 0
- if options[n] == "send" then
- Clear()
- Decide = 1
- elseif options[n] == "receive" then
- Decide = -1
- elseif options[n] == "return" then
- MainFun()
- end
- if Decide == 0 then
- else
- Clear()
- print("Please Enter Protocol")
- local input
- local event, key
- while true do
- event, key = os.pullEvent("key")
- input = read
- if key == keys.enter then break end
- end
- local Proto = input
- Clear()
- print("enter Amount")
- input = 0
- key = keys.one
- while true do
- event, key = os.pullEvent("key")
- input = read
- if key == keys.enter then break end
- end
- shell.run(System,"balance")
- if settings.get("banking_Balance") + (input * Decide) >= 0 then
- shell.run("banking_public1_NetworkManager", Proto, (input (Decide * -1)), "Transfer")
- local Data = {BankingFormat,}
- rednet.send(Data,)
- local Respond = rednet.receive(Proto)
- if Respond == "accepted" then
- print("Accepted")
- if input * Decide > 0 then
- shell.run(System,"deposit",input)
- elseif input * Decide < 0 then
- shell.run(System,"withdraw",input)
- end
- os.sleep(3)
- MainFun()
- elseif Respond == "declined" then
- print("Receiver declined")
- os.sleep(3)
- MainFun()
- end
- else
- print("insignificant Funds")
- os.sleep(3)
- MainFun()
- end
- end
- end
- local function GetUserDetails()
- UserInfo[1] = settings.get("os_Username")
- shell.run(System,"balance")
- end
- local function DrawMenu()
- term.setBackgroundColor(colors.orange)
- Clear()
- print("Online Banking Service")
- print("Version = "..BankingFormat)
- print("hello, "..UserInfo[1])
- print("Balance "..settings.get("banking_Balance").."€")
- print("1 - exit")
- print("2 - send cash")
- print("3 - other")
- end
- function MainFun()
- term.setBackgroundColor(colors.orange)
- Clear()
- GetUserDetails()
- DrawMenu()
- local Details
- local Sender
- local Result = "n"
- while true do
- local a, b, c, d = os.pullEvent()
- if a == "key" then
- if b == keys.one then Result = "exit" end
- if b == keys.two then Result = "Send" end
- if b == keys.three then Result = "other" end
- elseif a == "rednet_recieve" then
- Details = {c}
- Sender = b
- if Details[1] == BankingFormat and d == SecureProtocol then Result = "Transfer" end
- end
- if Result ~= "n" then break end
- end
- if Result == "exit" then shell.run(settings.get("os_DesktopLoc")) end
- if Result == "Send" then TransferMenu() end
- if Result == "other" then end
- if Result == "Transfer" then RemoteTransfer(Details,Sender) end
- end
- MainFun()
Add Comment
Please, Sign In to add comment