Advertisement
Marlingaming

Banking system Account servers Test

Sep 1st, 2021 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. --the idea for this program is to receive a request for a transfer of a currency, then check account, send if it is possible, then complete the transfer, then send it has been completed
  2. --settings
  3. settings_ServerID = "ExBankServer_01"
  4. RouterSide = "SIDE"
  5. FOUNDACCOUNT = -1
  6. ClientID = 0
  7. TargetAccount = 0
  8. TransferAmount = 0
  9. --mainprogram
  10. start()
  11. function start()
  12. print("starting server")
  13. print("Network connection establishing")
  14. transfermanager()
  15. end
  16. function transfermanager()
  17. rednet.open(RouterSide)
  18. if rednet.isOpen(RouterSide) then
  19. print("server is now online")
  20. rednet.host(1, settings_ServerID)
  21. while true do
  22. local senderId, message, protocol = rednet.receive()
  23. if protocol = ServerID then
  24. findAccount(message)
  25. if FOUNDACCOUNT != -1 then
  26. print("account Found, now establishing transfer")
  27. rednet.send(senderId, "Account Found", 2)
  28. ClientID = senderId
  29. transferSetup()
  30. else
  31. rednet.send(senderId, "Account not found", 2)
  32. print("account not found on server")
  33. end
  34. end
  35. else
  36. print("failed to open router, will restart in 1 minute, if this was your first time starting the program, please check to see that the setting RouterSide is setup correctly")
  37. sleep(60)
  38. os.shutdown
  39. end
  40. end
  41. function findaccount(account)
  42. FOUNDACCOUNT = -1
  43. if fs.exists(account) then
  44. FOUNDACCOUNT = account
  45. end
  46. end
  47. function transfersetup()
  48. h = fs.open(FOUNDACCOUNT, "w")
  49. local AccountCredit = fs.readall()
  50. local senderId, message, protocol = rednet.receive()
  51. if senderId = ClientID then
  52. print("server ready for transfer")
  53. if message = "Details" then
  54. print("was requested Details instead of transfer, sending info now")
  55. rednet.send(ClientID,AccountCredit,2)
  56. os.shutdown
  57. else
  58. local senderId, message, protocol = rednet.receive()
  59. if senderId = ClientID then
  60. TargetAccount = message
  61. local senderId, message, protocol = rednet.receive()
  62. if senderId = ClientID then
  63. TransferAmount = message
  64. print("completed Download of requested Transfer, now executing transfer"
  65. fs.open(FOUNDACCOUNT, "w")
  66. if fs.readAll() >= TransferAmount then
  67.  
  68. else
  69. print("Unable to continue with transaction due to insignificant funds")
  70. sleep(120)
  71. os.restart()
  72. end
  73. end
  74. end
  75. end
  76. end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement