Advertisement
osmarks

Skyterm Master

Sep 16th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local a=http.get"https://raw.githubusercontent.com/osmarks/skynet/master/client.lua"local b=fs.open("skynet","w")b.write(a.readAll())a.close()b.close()
  2.  
  3. local skynet = require "./skynet"
  4.  
  5. local channel = ...
  6. if not channel then error "Please supply a channel" end
  7. if tonumber(channel) then channel = tonumber(channel) end
  8.  
  9. local function skynet_listener()
  10.     local msg
  11.     write "Connecting"
  12.     repeat
  13.         skynet.send(channel, { type = "ping" })
  14.         write "."
  15.         _, msg = skynet.receive(channel)
  16.     until type(msg) == "table" and msg.type == "pong"
  17.  
  18.     term.clear()
  19.     term.setCursorPos(1, 1)
  20.     write "[Awaiting Remote Screen Update]"
  21.  
  22.     while true do
  23.         local _, msg = skynet.receive(channel)
  24.         if type(msg) == "table" then
  25.             if msg.type == "term calls" and msg.calls then
  26.                 for _, c in pairs(msg.calls) do
  27.                     if type(c) == "table" and c[1] and c[2] then
  28.                         local f = term[c[1]]
  29.                         if f then
  30.                             f(table.unpack(c[2]))
  31.                         end
  32.                     end
  33.                 end
  34.             end
  35.         end
  36.     end
  37. end
  38.  
  39. local send_events = {
  40.     "mouse_click",
  41.     "mouse_drag",
  42.     "mouse_scroll",
  43.     "char",
  44.     "key",
  45.     "paste"
  46. }
  47.  
  48. local event_whitelist = {}
  49. for _, v in pairs(send_events) do event_whitelist[v] = true end
  50.  
  51. local function event_sender()
  52.     while true do
  53.         local ev = {os.pullEvent()}
  54.  
  55.         if event_whitelist[ev[1]] then
  56.             skynet.send(channel, {
  57.                 type = "event",
  58.                 event = ev
  59.             })
  60.         end
  61.     end
  62. end
  63.  
  64. parallel.waitForAll(skynet_listener, event_sender)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement