Advertisement
DOGGYWOOF

server 3

Jan 6th, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. -- Server side (Updated for continuous admin log display and server status)
  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 server status and server ID on the right monitor
  6. local function displayStatus(statusMessage, 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(statusMessage)
  16.  
  17. -- Keep displaying the log
  18. while true do
  19. sleep(2) -- Adjust the duration between log updates
  20. monitor.scroll(1) -- Scroll the monitor content
  21. monitor.setCursorPos(1, 4)
  22. monitor.write(" ") -- Clear previous log message
  23. monitor.setCursorPos(1, 4)
  24. monitor.write(statusMessage) -- Display the updated log message
  25. end
  26. end
  27.  
  28. -- Function to handle displaying status and server ID
  29. local function displayServerStatus(senderID, message)
  30. print("Received file from ID: " .. senderID)
  31.  
  32. -- Save the file to the DGOS directory
  33. local file = fs.open("DGOS/" .. message.fileName, "w")
  34. file.write(message.fileContent)
  35. file.close()
  36.  
  37. print("File saved as " .. message.fileName)
  38.  
  39. -- Display server status and server ID on the right monitor
  40. local statusMessage = "File received from ID: " .. senderID .. "\nFile saved as " .. message.fileName
  41. displayStatus(statusMessage, senderID)
  42. end
  43.  
  44. while true do
  45. local senderID, message, protocol = rednet.receive()
  46.  
  47. if protocol == "file_transfer" then
  48. displayServerStatus(senderID, message)
  49. end
  50. end
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement