Advertisement
Marlingaming

Banking Server

Apr 11th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2. modem.open(57)
  3.  
  4. function Loop()
  5. while true do
  6. local event, a, b, c, d, e, f, g = os.pullEvent()
  7. if event == "modem_message" then
  8. local ReplyChannel = c
  9. local Message = d
  10. local Distance = e
  11. local Data = textutils.unserialize(Message)
  12. local Pin = Data[1]
  13. local Account = Data[2]
  14. local Amount = Data[3]
  15. if Transfer(Pin,Account,Amount) == true then
  16. local Re = textutils.serialize({Account,"accepted"})
  17. modem.transmit(ReplayChannel,57,Re)
  18. end
  19. else
  20.  
  21. end
  22. os.queueEvent("pass")
  23. end
  24. end
  25.  
  26. function Transfer(pin,account,amount)
  27. local file = fs.open(fs.combine("Accounts",account,"Details.txt"),"r")
  28. local ConfirmPin = file.readLine()
  29. local Balance = file.readLine()
  30. file.close()
  31. if ConfirmPin == pin then
  32. Balance = Balance + amount
  33. local Doc = fs.open(fs.combine("Accounts",account,"Details.txt"),"w")
  34. Doc.writeLine(ConfirmPin)
  35. Doc.writeLine(Balance)
  36. Doc.Close()
  37. return true
  38. end
  39. end
  40.  
  41. Loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement