Advertisement
gravitowl

[gravicard] database

Jan 8th, 2021 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. local modem = peripheral.wrap("right")
  2. local backupModem = peripheral.wrap("bottom")
  3. backupModem.open(69)
  4. modem.open(420)
  5. local db = {}
  6.  
  7.  
  8. while true do
  9. local _, side, freq, rfreq, name = os.pullEvent('modem_message')
  10. if side == "bottom" then
  11. if type(name) == "table" then
  12. db = name
  13. print("Backup received.")
  14. elseif name == "askForDB" then
  15. backupModem.transmit(69, 69, db)
  16. print("Sent database to backup.")
  17. end
  18. elseif side == "right" then
  19. if db[name] then
  20. modem.transmit(420, 420, {"Found", db[name]["bal"]})
  21. print("Account already existed.")
  22. else
  23. db[name] = {}
  24. db[name]["bal"] = 0
  25. modem.transmit(420, 420, {"Not Found", db[name]["bal"]})
  26. backupModem.transmit(69, 69, db)
  27. print("Created new account with name "..name)
  28. end
  29. end
  30. end
  31.  
  32. modem.close()
  33. backupModem.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement