Marlingaming

CC Tweaked Banking Service Client - banking_public1

Jan 19th, 2022 (edited)
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.68 KB | None | 0 0
  1. --this program is the new Banking App
  2. settings.load(".settings")
  3. local SecureProtocol = settings.get("Secure_WirelessProtocol")
  4. local BankingFormat = "banking_public1"
  5. local LocalDevices = {}
  6. local UserInfo = {}
  7. local System = settings.get("banking_System")
  8.  
  9. local function Clear()
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. end
  13.  
  14. local function GetLocalDevices()
  15. rednet.broadcast(BankingFormat)
  16. for i = 1, 6 do
  17.     local id, message, protocol = rednet.recieve()
  18.     if message == BankingFormat then
  19.         LocalDevices[#LocalDevices + 1 ] = {id, protocol}
  20.     end
  21. end
  22. end
  23.  
  24. function CUI(m) --declare function
  25. n=1
  26. local l = #m
  27. while true do
  28. term.setCursorPos(1,4)
  29.  
  30. for i=1, #m, 1 do --traverse the table of options
  31. if i==n then term.clearLine() print(i, " ["..m[i].."]") else term.clearLine() print(i, " ", m[i]) end --print them
  32. end
  33. a, b= os.pullEvent("key") --wait for keypress
  34. if b==keys.w and n>1 then n=n-1 end
  35. if b==keys.s and n<l then n=n+1 end
  36. if b==keys.enter then break end
  37. end
  38. return n --return the value
  39. end
  40.  
  41. local function RemoteTransfer(Message,id)
  42. Clear()
  43. print("Transfer Request")
  44. print(Message[3])--Sender Name
  45. print(Message[2])--amount
  46. print(Message[4])--item
  47. print("Accept? y/n")
  48. local event, key
  49. repeat
  50.     event, key = os.pullEvent("key")
  51. until key == keys.y or key == keys.n
  52. if key == keys.y then
  53.     if settings.get("banking_Balance") - Message[2] >= 0 then
  54.         rednet.send(id,"accepted",SecureProtocol)
  55.         if Message[5] == "deposit" then
  56.             shell.run(System, "deposit", Message[2])
  57.         else
  58.             shell.run(System, "withdraw", Message[2])
  59.         end
  60.     else
  61.         rednet.send(id,"declined",SecureProtocol)
  62.         print("Transfer Declined, Insignificant Funds")
  63.     end
  64. end
  65. os.sleep(3)
  66. MainFun()
  67. end
  68.  
  69. local function DecryptDetails(data)
  70.    
  71. end
  72.  
  73. local function TransferMenu()
  74. Clear()
  75. print("transfer Menu")
  76. local options = {"send","receive","return"}
  77. local n = CUI(options)
  78. local Decide = 0
  79. if options[n] == "send" then
  80.     Clear()
  81.     Decide = 1
  82. elseif options[n] == "receive" then
  83.     Decide = -1
  84. elseif options[n] == "return" then
  85.     MainFun()
  86. end
  87. if Decide == 0 then
  88.  
  89. else
  90.     Clear()
  91.     print("Please Enter Protocol")
  92.     local input
  93.     local event, key
  94.     while true do
  95.         event, key = os.pullEvent("key")
  96.         input = read
  97.         if key == keys.enter then break end
  98.     end
  99.     local Proto = input
  100.     Clear()
  101.     print("enter Amount")
  102.     input = 0
  103.     key = keys.one
  104.     while true do
  105.         event, key = os.pullEvent("key")
  106.         input = read
  107.         if key == keys.enter then break end
  108.     end
  109.     shell.run(System,"balance")
  110.     if settings.get("banking_Balance") + (input * Decide) >= 0 then
  111.         shell.run("banking_public1_NetworkManager", Proto, (input (Decide * -1)), "Transfer")
  112.         local Data = {BankingFormat,}
  113.         rednet.send(Data,)
  114.         local Respond = rednet.receive(Proto)
  115.         if Respond == "accepted" then
  116.             print("Accepted")
  117.             if input * Decide > 0 then
  118.                 shell.run(System,"deposit",input)
  119.             elseif input * Decide < 0 then
  120.                 shell.run(System,"withdraw",input)
  121.             end
  122.             os.sleep(3)
  123.             MainFun()
  124.         elseif Respond == "declined" then
  125.             print("Receiver declined")
  126.             os.sleep(3)
  127.             MainFun()
  128.         end
  129.     else
  130.         print("insignificant Funds")
  131.         os.sleep(3)
  132.         MainFun()
  133.     end
  134. end
  135. end
  136.  
  137. local function GetUserDetails()
  138. UserInfo[1] = settings.get("os_Username")
  139. shell.run(System,"balance")
  140. end
  141.  
  142. local function DrawMenu()
  143. term.setBackgroundColor(colors.orange)
  144. Clear()
  145. print("Online Banking Service")
  146. print("Version = "..BankingFormat)
  147. print("hello, "..UserInfo[1])
  148. print("Balance "..settings.get("banking_Balance").."€")
  149. print("1 - exit")
  150. print("2 - send cash")
  151. print("3 - other")
  152. end
  153.  
  154. function MainFun()
  155. term.setBackgroundColor(colors.orange)
  156. Clear()
  157. GetUserDetails()
  158. DrawMenu()
  159. local Details
  160. local Sender
  161. local Result = "n"
  162. while true do
  163.     local a, b, c, d = os.pullEvent()
  164.     if a == "key" then
  165.         if b == keys.one then Result = "exit" end
  166.         if b == keys.two then Result = "Send" end
  167.         if b == keys.three then Result = "other" end
  168.     elseif a == "rednet_recieve" then
  169.         Details = {c}
  170.         Sender = b
  171.         if Details[1] == BankingFormat and d == SecureProtocol then Result = "Transfer" end
  172.     end
  173.     if Result ~= "n" then break end
  174. end
  175. if Result == "exit" then shell.run(settings.get("os_DesktopLoc")) end
  176. if Result == "Send" then TransferMenu() end
  177. if Result == "other" then end
  178. if Result == "Transfer" then RemoteTransfer(Details,Sender) end
  179. end
  180.  
  181. MainFun()
Add Comment
Please, Sign In to add comment