Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArg = {...}
- local w, h = term.getSize()
- local Account
- local Balance
- local Pin
- local Secure = false
- settings.load("os/settings.txt")
- local modem = peripheral.find("modem")
- function Menu()
- App.Clear()
- App.newText("text_title","Banking",w/2 - 3,1)
- App.newText("text_account","Account: "..Account,1,2)
- App.newText("text_balance","Balance: "..Balance,1,3)
- App.newText("text_options","options",w/2 - 3, 4)
- if modem ~= nil and Secure == true then
- App.newButton("button_transfer","Transfer","tsk.openTransfer",w/2 - 4, 5)
- App.newButton("button_transactions","Transactions","tsk.openTransactions",w/2 - 6, 7)
- elseif modem == nil then
- App.newButton("error_noModem","network functions unavailable","lnk.os/System/Programs/SettingsApp.lua",w/2 - 14, 5)
- elseif Secure == false then
- App.newButton("error_notSecure","system not secure","lnk.os/System/Programs/SettingsApp.lua", w/2 - 8, 5)
- end
- end
- function PayAuthorize()
- App.Clear()
- App.newText("text_title","Purchase Details",w/2 - 8, 1)
- App.newText("text_sender","sender: "..sender,1,2)
- App.newText("text_cost","cost: "..cost,1,3)
- App.newText("text_details","details: "..details,1,4)
- App.newButton("button_accept","accept","tsk.acceptTransfer",w/2 - 3,6)
- App.newButton("button_cancel","cancel","tsk.cancelTransfer",w/2 - 3, 8)
- end
- function Purchase(t)
- local file = fs.open("os/Files/Banking/Draft.txt","r")
- local cost = file.readLine()
- local sender = file.readLine()
- local pin = file.readLine()
- local details = file.readLine()
- file.close()
- local message
- if t == true then
- message = textutils.serialize({os.getID(),pin,true})
- UpdateBalance(cost * -1)
- CreateLog(cost,sender,details)
- elseif t == false then
- message = textutils.serialize({os.getID(),pin,false})
- end
- modem.transmit(12,8,message)
- Menu()
- end
- function CreateDraft(cost,sender,pin,details)
- local file = fs.open("os/Files/Banking/Draft.txt","w")
- file.writeLine(cost)
- file.writeLine(sender)
- file.writeLine(pin)
- file.writeLine(details)
- file.writeLine(os.time())
- file.close()
- end
- function CreateLog(c,s,d)
- local file = fs.open(fs.combine("os/Files/Logs","Banking_"..tostring(os.time())..".txt"),"w")
- file.writeLine(s)
- file.writeLine(c)
- file.writeLine(d)
- file.writeLine(settings.get("active_user"))
- file.close()
- end
- function UpdateBalance(amount)
- local Path = fs.combine("os/Users",settings.get("active_user"),".bankAccount.txt")
- local file = fs.open(Path,"r")
- Pin = file.readLine()
- Balance = file.readLine()
- file.close()
- local Doc = fs.open(Path,"w")
- Doc.writeLine(Pin)
- Balance = Balance + amount
- Doc.writeLine(Balance)
- Doc.close()
- end
- function LoadAccount()
- local Path = fs.combine("os/Users",settings.get("active_user"),".bankAccount.txt")
- if fs.exists(Path) then
- local file = fs.open(Path,"r")
- Pin = file.readLine()
- Balance = file.readLine()
- file.close()
- else
- AccountCreation(Path)
- end
- end
- function AccountCreation(path)
- Pin = math.random(12345,98765)
- Balance = 0
- local file = fs.open(path,"w")
- file.writeLine(Pin)
- file.writeLine(Balance)
- file.close()
- end
- function CheckSecurity()
- Secure = Sec.CheckSecurity()
- end
- LoadAccount()
- CheckSecurity()
- Account = settings.get("active_user")
- if tArg[1] == "start" then
- if tArg[2] == "openDraft" then
- PayAuthorize()
- else
- Menu()
- end
- elseif tArg[1] == "setup" then
- elseif tArg[1] == "acceptTransfer" then
- Purchase(true)
- elseif tArg[1] == "cancelTransfer" then
- Purchase(false)
- elseif tArg[1] == "direct_message" then
- os.queueEvent("system_message","Banking","purchase awaiting confirmation","os/System/BankingApp.lua","openDraft")
- local Table = textutils.unserialize(tArg[2])
- local C = Table[1]
- local S = Table[2]
- local P = Table[3]
- local D = Table[4]
- CreateDraft(C,S,P,D)
- elseif string.find(tArg[1],"open") then
- if tArg[1] == "openTransfer" then
- elseif tArg[1] == "openTransactions" then
- end
- end
Add Comment
Please, Sign In to add comment