Advertisement
Marlingaming

Heimbriech Tablet OS - Credit Application

Sep 7th, 2021 (edited)
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local oldPull = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3. --this program acts as a Credit Card, to make things less messy
  4. Requested_Amount = 0
  5. Requester_ID = 0
  6. Page = "Menu"
  7. --the following Data is Only Called when needed, then its deleted for security reasons
  8. AccountID = nil
  9. AccountName = nil
  10. AccountBalance = 0
  11. Key = 0
  12.  
  13. start()
  14.     term.setBackgroundColor("blue")
  15.     term.setTextColor("white")
  16.     Menu()
  17. function start()
  18.  
  19. end
  20.  
  21. function Menu()
  22.     term.clear()
  23.     term.setCursorPos(1,1)
  24.     print("---Credit-Remote-Transfer-V-1.0---")
  25.     local event, key = os.pullEvent("key")
  26.     if Page == "Menu" then
  27.         print("Options")
  28.         print("1 - Wait for Request")
  29.         print("2 - Check Account")
  30.         print("3 - Exit")
  31.         while true do
  32.             if key == keys.1 then
  33.                 Page == "Request"
  34.                 Menu()
  35.             else if key == keys.2 then --Opens AccountPage
  36.                 Page == "Account"
  37.                 Menu()
  38.             else if key == keys.3 then --Takes User to Main Program
  39.                 shell.run("")
  40.             end
  41.         end
  42.     else if Page == "Request" then
  43.         term.setCursorPos(1,2)
  44.         print("CONNECTION HANDLER")
  45.         term.setCursorPos(1,3)
  46.         textutils.slowWrite("Waiting for Connection.....",6]
  47.         sleep(10)
  48.         Receive()
  49.     else if Page == "Account" then
  50.         Decrypter()
  51.         term.setCursorPos(1,2)
  52.         print("--ACCOUNT PAGE--")
  53.         print("Account Name - "..AccountName)
  54.         print("Account ID - "..AccountID)
  55.         print("Account Balance - $"..AccountBalance)
  56.         AccountName = nil
  57.         AccountBalance = nil
  58.         AccountID = nil
  59.         while true do
  60.             if key == keys.enter then
  61.                 Page = "Menu"
  62.                 Menu()
  63.             end
  64.         end
  65.     end
  66. end
  67.  
  68. function Receive()
  69.     Decrypter()
  70.     rednet.receive(AccountID,5)
  71.     Requester_ID = id
  72.     rednet.send(Requester_ID,"Amount")
  73.     rednet.receive(AccountID,5)
  74.     Requested_Amount = message
  75.     if Requested_Amount < 0 then
  76.         if Account_Balance+Requested_Amount >=0 then
  77.             Payment()
  78.         else
  79.             rednet.send(Requester_ID,"Denied")
  80.             sleep(4)
  81.             print("Transaction Denied due to insignificant Funds")
  82.             sleep(6)
  83.             Page = "Menu"
  84.             Menu()
  85.         end
  86.     else
  87.         Payment()
  88.     end
  89. end
  90.  
  91. function Payment()
  92.     Decrypter()
  93.     rednet.send(Requester_ID, "confirmed",Key)
  94.     local h = fs.open(".SecuriedData","a")
  95.     h.setCursorPos(1,4)
  96.     local Decrypt = h.readline(5)
  97.     h.writeline(h.readline(4)+(Requested_Amount*Decrpyt))
  98.     h.close()
  99.     Page = "Menu"
  100.     print("Transfer Completed")
  101.     AccountName = nil
  102.     AccountBalance = nil
  103.     AccountID = nil
  104.     sleep(10)
  105.     Menu()
  106. end
  107.                    
  108. function Decrypter()
  109.     local h = fs.open(".BankDetails","r")
  110.     AccountID = h.readline(2)
  111.     AccountName = h.readline(3)
  112.     local Encrypt_Balance = h.readline(4)
  113.     local DecryptKey_Balance = h.readline(5)
  114.     AccountBalance = Encrypt_Balance/DecryptKey_Balance
  115.     h.close()
  116. end
  117. os.pullEvent = oldPull
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement