Marlingaming

CC Tweaked banking_public3 - Banking Server

Feb 24th, 2022 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. local Protocol = "4523"
  2. local Balance = 0
  3. rednet.open(peripherals.find("modem”))
  4.  
  5. function Loop()
  6. rednet.host(Protocol,"Ser_B_1")
  7. while true do
  8. local Req = "Accepted"
  9. local a, b, c = rednet.receive(Protocol)
  10. local id, Acc, Key, Amount, Item = textutils.unserialize(b)
  11. local Result = FindAccount(Acc)
  12. if Result ~= false then
  13. if Amount > 40 and Key == "0000" then
  14. Req = "declined"
  15. else
  16. if Balance - Amount >= 0 then Req = "accepted" ChangeBalance(Result,Amount) end
  17. end
  18. else
  19. Req = "declined"
  20. end
  21. rednet.send(a,Req,Protocol)
  22. end
  23. end
  24.  
  25. function ChangeBalance(account,Amount)
  26. local file = fs.open(account,"r")
  27. local Code = file.readLine()
  28. local Bal = file.readLine()
  29. file.close()
  30. local F = fs.open(account,"w")
  31. F.writeLine(Code)
  32. F.writeLine(Bal - Amount)
  33. F.close()
  34. end
  35.  
  36. function FindAccount(Code)
  37. local Res = false
  38. local List = fs.list("accounts")
  39. for i = 1, #List do
  40. local File = fs.open(fs.combine("accounts",List[i]),"r")
  41. if File.readLine() == Code then Res = fs.combine("accounts",List[i]) Balance = File.readLine() end
  42. File.close()
  43. end
  44. return Res
  45. end
Add Comment
Please, Sign In to add comment