Advertisement
DOGGYWOOF

server 2

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