Advertisement
gravitowl

[gravicard] databaseBackup

Jan 8th, 2021 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. local modem = peripheral.wrap("top")
  2. modem.open(69)
  3.  
  4. local dbbu = {}
  5.  
  6. local function waitForBackup()
  7. while true do
  8. local _, side, freq, rfreq, database = os.pullEvent('modem_message')
  9. dbbu = database
  10. print("Database received from main database.")
  11. end
  12. end
  13.  
  14.  
  15. local function sendBackupBack()
  16. while true do
  17. local input = read()
  18. if input == "sendBackup" then
  19. modem.transmit(69, 69, dbbu)
  20. print("Backup send to main database.")
  21. elseif input == "getDatabase" then
  22. modem.transmit(69, 69, "askForDB")
  23. local _, side, freq, rfreq, database = os.pullEvent('modem_message')
  24. dbbu = database
  25. print("Database received from main database.")
  26. end
  27. end
  28. end
  29.  
  30. parallel.waitForAll(waitForBackup, sendBackupBack)
  31. print("[EMERGENCY] BACKUP DATABASE OFFLINE.")
  32.  
  33. modem.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement