This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
RoD's profile picture

Remote shell

Started by RoD, 03 June 2014 - 04:31 PM
RoD #1
Posted 03 June 2014 - 06:31 PM
I am trying to make my own remote shell ( i know of lyqyd's nsh ). I dont really get much of his code (just too much form me :P/>)
As i want to make a really simple thing, not so good as his, i want to know:
  • In his code i can see he uses term.redirect() to make the program work. Can someone show a simpler way of redirecting a terminal object from one computer to other and get the remote shell working?
  • There is an even easier way of doing a remote shell (that returns the command output)
Thanks :)/>
Edited on 03 June 2014 - 05:12 PM
Lyqyd #2
Posted 03 June 2014 - 08:09 PM
Nsh is pretty close to as simple as it gets. If you want even simpler, you could try taking a look at my vncd program. It's meant to be used in conjunction with nsh, but has slightly different functionality. It's only for the server side (the screen to be transmitted) and is pretty stripped-down to just bare functionality for screen transmission and event receiving. Looking at that might help give you a base to better understand nsh.
RoD #3
Posted 04 June 2014 - 06:09 PM
I have been playing arround and i overwrote some default functions.
I go a 'thing' that can't be called remote shell, but i got the colors, text and input to work from a remote computer:

Client:

rednet.open("right")
--rednet.send(31, term)
function main()
rednet.send(31, "code:getdir")
local id, dir = rednet.receive()
write(dir.."> ")
com = read()
if string.sub(com, 1, 6) == "local:" then
  loc = string.sub(com, 7, #com)
  shell.run(loc)
else
  rednet.send(31, com)
  if com == "clear" then
   term.clear()
   term.setCursorPos(1,1)
  end
  cx, cy = term.getCursorPos()
  while true do
   local id, resp = rednet.receive(0.4)
   --print("resp:"..resp)
   if resp == "code:text" then
    local id, txt = rednet.receive()
    tx, ty = term.getCursorPos()
    if txt == " " then
	 term.setCursorPos(tx, ty)
    end
    write(txt)
   elseif resp == "code:color" then
    local id, col = rednet.receive()
    term.setTextColor(col)
   elseif resp == "code:pos" then
    local id, x = rednet.receive()
    local id, y = rednet.receive()
    term.setCursorPos(x,y)
   elseif resp == "input_request" then
    inp = read()
    rednet.send(id, inp)
   elseif resp == ">" or resp == nil then
    --term.setCursorPos(x, )
    main()
   end
  end
end
end
main()

Server:

rednet.open("right")
local id, obj = rednet.receive()
--shell.run(obj)
term_write = term_write or term.write
term.write = function(text)
  term_write(text)
  rednet.send(id, "code:text")
  rednet.send(id, text)
end
print = function( txt )
  term.write( txt.."\n" )
end
term_setTextColor = term_setTextColor or term.setTextColor
term.setTextColor = function(color)
  term_setTextColor(color)
  rednet.send(id, "code:color")
  rednet.send(id, color)
end
term_setCursorPos = term_setCursorPos or term.setCursorPos
term.setCursorPos = function(x, y)
  term_setCursorPos(x, y)
  rednet.send(id, "code:pos")
  rednet.send(id, x)
  rednet.send(id, y)
end
io_read = io_read or read
read = function()
  rednet.send(id, "input_request")
  local id, inp = rednet.receive()
  term_write(inp)
  return inp
end
--[[
term_clear = term_clear or term.clear
term.clear = function()
  if term.isColor() then term.setBackgroundColor(colors.black) term_clear() end
end
]]--
if obj == "code:getdir" then
  rednet.send(id, shell.dir())
else
  shell.run(obj)
end
x, y = term.getCursorPos()
term.setCursorPos(x, y+1)

shell.run("/sv")