Advertisement
DOGGYWOOF

server - with monitor info

Jan 6th, 2024 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. -- Server side (Updated to display only critical information)
  2. -- Make sure the modem is open on the side you're using
  3. rednet.open("top") -- Replace "top" with the side where your modem is placed
  4.  
  5. -- Function to display critical server status on the right monitor
  6. local function displayCriticalInfo(criticalMessage, serverID)
  7. local monitor = peripheral.wrap("right") -- Replace "right" with the side where your monitor is connected
  8.  
  9. monitor.clear()
  10. monitor.setCursorPos(1, 1)
  11. monitor.write("Server ID: " .. tostring(serverID))
  12. monitor.setCursorPos(1, 2)
  13. monitor.write("Server Online")
  14. monitor.setCursorPos(1, 4)
  15. monitor.write("Critical: " .. criticalMessage)
  16.  
  17. -- Keep displaying the critical info
  18. while true do
  19. sleep(2) -- Adjust the duration between updates
  20. monitor.setCursorPos(1, 4)
  21. monitor.write(" ") -- Clear previous critical message
  22. monitor.setCursorPos(1, 4)
  23. monitor.write("Critical: " .. criticalMessage) -- Display updated critical message
  24. end
  25. end
  26.  
  27. -- Function to handle displaying critical information
  28. local function displayCriticalInformation(criticalMessage, serverID)
  29. print("Critical Error: " .. criticalMessage)
  30. displayCriticalInfo(criticalMessage, serverID)
  31. end
  32.  
  33. -- Display initial server ID on the monitor
  34. local modemSide = "top" -- Replace with the actual side where your modem is placed
  35. local serverID = os.getComputerID()
  36. rednet.open(modemSide)
  37. local monitor = peripheral.wrap("right")
  38. monitor.clear()
  39. monitor.setCursorPos(1, 1)
  40. monitor.write("Server ID: " .. tostring(serverID))
  41. monitor.setCursorPos(1, 2)
  42. monitor.write("Server Online")
  43.  
  44. while true do
  45. local senderID, message, protocol = rednet.receive()
  46.  
  47. if protocol == "file_transfer" then
  48. print("Received file from ID: " .. senderID)
  49.  
  50. -- Save the file to the DGOS directory
  51. local file = fs.open("DGOS/" .. message.fileName, "w")
  52. file.write(message.fileContent)
  53. file.close()
  54.  
  55. print("File saved as " .. message.fileName)
  56. else
  57. -- Assuming other protocols indicate critical information
  58. displayCriticalInformation(message, senderID)
  59. end
  60. end
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement