Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local modemLocations = {}
- -- Initialize modem and open Rednet
- local function initializeModem()
- for _, side in ipairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" then
- rednet.open(side)
- print("Rednet opened on side:", side)
- return true
- end
- end
- print("No modem found.")
- return false
- end
- -- Function to log the location of the current computer
- local function logComputerLocation()
- local computerID = os.computerID()
- local computerLabel = os.getComputerLabel() or "Unnamed"
- modemLocations[computerID] = {label = computerLabel, location = os.getComputerLabel()}
- print("Logged computer ID:", computerID, "with label:", computerLabel)
- end
- -- Function to send the computer's ID to the main computer
- local function sendComputerID()
- local mainComputerID = 77 -- Replace with the ID of the main computer
- rednet.send(mainComputerID, os.computerID())
- print("Sent computer ID:", os.computerID(), "to main computer ID:", mainComputerID)
- end
- -- Main function to handle receiving and executing commands
- local function main()
- -- Initialize modem and open Rednet
- if not initializeModem() then
- return -- Exit if no modem is found
- end
- -- Log the location of the current computer
- logComputerLocation()
- -- Send the computer's ID to the main computer
- sendComputerID()
- -- Main loop to listen for incoming commands
- while true do
- local senderID, message = rednet.receive()
- -- Check if the message is intended for this computer
- if type(message) == "string" then
- print("Received command:", message)
- -- Execute the received command
- shell.run(message)
- elseif message == "screen_request" then
- -- Capture the screen and send it back to the requester
- local screen = {}
- for y = 1, 16 do
- screen[y] = ""
- for x = 1, 51 do
- screen[y] = screen[y] .. (term.getTextColor(x, y) * 16 + term.getBackgroundColor(x, y)) % 16
- end
- end
- rednet.send(senderID, screen)
- end
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement