Marlingaming

Banking Application

Apr 6th, 2022 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. local tArg = {...}
  2. local w, h = term.getSize()
  3. local Account
  4. local Balance
  5. local Pin
  6. local Secure = false
  7. settings.load("os/settings.txt")
  8.  
  9. local modem = peripheral.find("modem")
  10.  
  11. function Menu()
  12. App.Clear()
  13. App.newText("text_title","Banking",w/2 - 3,1)
  14. App.newText("text_account","Account: "..Account,1,2)
  15. App.newText("text_balance","Balance: "..Balance,1,3)
  16. App.newText("text_options","options",w/2 - 3, 4)
  17. if modem ~= nil and Secure == true then
  18. App.newButton("button_transfer","Transfer","tsk.openTransfer",w/2 - 4, 5)
  19. App.newButton("button_transactions","Transactions","tsk.openTransactions",w/2 - 6, 7)
  20. elseif modem == nil then
  21. App.newButton("error_noModem","network functions unavailable","lnk.os/System/Programs/SettingsApp.lua",w/2 - 14, 5)
  22.  
  23. elseif Secure == false then
  24. App.newButton("error_notSecure","system not secure","lnk.os/System/Programs/SettingsApp.lua", w/2 - 8, 5)
  25. end
  26. end
  27.  
  28. function PayAuthorize()
  29. App.Clear()
  30. App.newText("text_title","Purchase Details",w/2 - 8, 1)
  31. App.newText("text_sender","sender: "..sender,1,2)
  32. App.newText("text_cost","cost: "..cost,1,3)
  33. App.newText("text_details","details: "..details,1,4)
  34. App.newButton("button_accept","accept","tsk.acceptTransfer",w/2 - 3,6)
  35. App.newButton("button_cancel","cancel","tsk.cancelTransfer",w/2 - 3, 8)
  36.  
  37. end
  38.  
  39. function Purchase(t)
  40. local file = fs.open("os/Files/Banking/Draft.txt","r")
  41. local cost = file.readLine()
  42. local sender = file.readLine()
  43. local pin = file.readLine()
  44. local details = file.readLine()
  45. file.close()
  46. local message
  47. if t == true then
  48. message = textutils.serialize({os.getID(),pin,true})
  49. UpdateBalance(cost * -1)
  50. CreateLog(cost,sender,details)
  51. elseif t == false then
  52. message = textutils.serialize({os.getID(),pin,false})
  53. end
  54. modem.transmit(12,8,message)
  55. Menu()
  56. end
  57.  
  58.  
  59. function CreateDraft(cost,sender,pin,details)
  60. local file = fs.open("os/Files/Banking/Draft.txt","w")
  61. file.writeLine(cost)
  62. file.writeLine(sender)
  63. file.writeLine(pin)
  64. file.writeLine(details)
  65. file.writeLine(os.time())
  66. file.close()
  67. end
  68.  
  69. function CreateLog(c,s,d)
  70. local file = fs.open(fs.combine("os/Files/Logs","Banking_"..tostring(os.time())..".txt"),"w")
  71. file.writeLine(s)
  72. file.writeLine(c)
  73. file.writeLine(d)
  74. file.writeLine(settings.get("active_user"))
  75. file.close()
  76. end
  77.  
  78. function UpdateBalance(amount)
  79. local Path = fs.combine("os/Users",settings.get("active_user"),".bankAccount.txt")
  80. local file = fs.open(Path,"r")
  81. Pin = file.readLine()
  82. Balance = file.readLine()
  83. file.close()
  84. local Doc = fs.open(Path,"w")
  85. Doc.writeLine(Pin)
  86. Balance = Balance + amount
  87. Doc.writeLine(Balance)
  88. Doc.close()
  89. end
  90.  
  91. function LoadAccount()
  92. local Path = fs.combine("os/Users",settings.get("active_user"),".bankAccount.txt")
  93. if fs.exists(Path) then
  94. local file = fs.open(Path,"r")
  95. Pin = file.readLine()
  96. Balance = file.readLine()
  97. file.close()
  98. else
  99. AccountCreation(Path)
  100. end
  101. end
  102.  
  103. function AccountCreation(path)
  104. Pin = math.random(12345,98765)
  105. Balance = 0
  106. local file = fs.open(path,"w")
  107. file.writeLine(Pin)
  108. file.writeLine(Balance)
  109. file.close()
  110. end
  111.  
  112. function CheckSecurity()
  113. Secure = Sec.CheckSecurity()
  114. end
  115.  
  116.  
  117. LoadAccount()
  118. CheckSecurity()
  119. Account = settings.get("active_user")
  120. if tArg[1] == "start" then
  121. if tArg[2] == "openDraft" then
  122. PayAuthorize()
  123. else
  124. Menu()
  125. end
  126. elseif tArg[1] == "setup" then
  127.  
  128. elseif tArg[1] == "acceptTransfer" then
  129. Purchase(true)
  130. elseif tArg[1] == "cancelTransfer" then
  131. Purchase(false)
  132. elseif tArg[1] == "direct_message" then
  133. os.queueEvent("system_message","Banking","purchase awaiting confirmation","os/System/BankingApp.lua","openDraft")
  134. local Table = textutils.unserialize(tArg[2])
  135. local C = Table[1]
  136. local S = Table[2]
  137. local P = Table[3]
  138. local D = Table[4]
  139. CreateDraft(C,S,P,D)
  140. elseif string.find(tArg[1],"open") then
  141. if tArg[1] == "openTransfer" then
  142.  
  143. elseif tArg[1] == "openTransactions" then
  144.  
  145. end
  146. end
Add Comment
Please, Sign In to add comment