Posted 23 November 2012 - 04:21 PM
Cleaned up the design a bit in both of the scripts; they're a lot more readable now. The scripts now offer support for both color to color computers, and basic to basic computers, but not both.
These scripts allow one computer to transfer all terminal output to another where it will be displayed, however the receiving computer will not be able to do ANYTHING while the program is running. It's a window from one computer to another, but you can't reach through; you can only look.
Sending Script (The one the user will be using to transmit information displayed/typed):
Receiving Script (The one the user will be using to view the transmitted display):
For those who'd like to know without reading the code, I achieved this be replacing most of the term API with functions that would serialize their parameters while also executing their term counterparts.
The receiving machine only has to un-serialize the message and set the proper flags/execute the proper term functions.
These scripts allow one computer to transfer all terminal output to another where it will be displayed, however the receiving computer will not be able to do ANYTHING while the program is running. It's a window from one computer to another, but you can't reach through; you can only look.
Sending Script (The one the user will be using to transmit information displayed/typed):
Spoiler
local tArgs = { ... }
if #tArgs ~= 1 then
print("Useage: " .. fs.getName(shell.getRunningProgram()) .. " <receiverID>")
end
-- Opens any modem found on the computer.
function openModem()
for sideIndex, side in pairs(rs.getSides()) do
if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
rednet.open(side)
return
end
end
print("No modem found. Aborting.")
error()
end
-- Closes any modem found on the computer.
function closeModem()
for sideIndex, side in pairs(rs.getSides()) do
if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
rednet.close(side)
end
end
end
-- Check for restoration.
if tArgs[1] == "restore" then
term.restore()
closeModem()
return
end
openModem()
local receiverID = tonumber(tArgs[1])
local oldTerm = {}
local sendTerm = {}
function wrap(functionName)
return function(...)
rednet.send(receiverID, textutils.serialize({funcName = functionName, params = {...}}))
return oldTerm[functionName](...)
end
end
for functionName, functionObject in pairs(term.native) do
oldTerm[functionName] = functionObject
end
for functionName, functionObject in pairs(term.native) do
if type(functionName) == "string" and type(functionObject) == "function" then
sendTerm[functionName] = wrap(functionName)
end
end
term.redirect(sendTerm)
term.clear()
term.setCursorPos(1, 1)
print("Transmitting to " .. receiverID)
Receiving Script (The one the user will be using to view the transmitted display):
Spoiler
local tArgs = { ... }
if #tArgs ~= 1 then
print("Useage: " .. fs.getName(shell.getRunningProgram()) .. " <senderID>")
return
end
-- Opens any modem found on the computer.
function openModem()
for sideIndex, side in pairs(rs.getSides()) do
if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
rednet.open(side)
return
end
end
print("No modem found. Aborting.")
error()
end
local senderID = tonumber(tArgs[1])
function runFunction(functionName, params)
term.native[functionName](unpack(params))
end
function receiveAndExecute()
while true do
local id, message = rednet.receive()
if id == senderID then
local command = textutils.unserialize(message)
runFunction(command.funcName, command.params)
end
end
end
openModem()
term.clear()
term.setCursorPos(1, 1)
print("Waiting for commands from " .. senderID)
receiveAndExecute()
For those who'd like to know without reading the code, I achieved this be replacing most of the term API with functions that would serialize their parameters while also executing their term counterparts.
The receiving machine only has to un-serialize the message and set the proper flags/execute the proper term functions.