Wiiplay123

RSP Server

Apr 12th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. --RSP Server
  2. side = peripheral.find("modem")
  3. rednet.open(side)
  4. idp = {}
  5. function func()
  6.     rednet.host("rspserv",tostring(os.getComputerID()))
  7.     function snd(arg)
  8.         for i,v in ipairs(idp) do
  9.             rednet.send(v,arg)
  10.         end
  11.     end
  12.     oldShutdown = os.shutdown
  13.     function os.shutdown()
  14.         rednet.unhost("rspserv",tostring(os.getComputerID()))
  15.         sleep(0.5)
  16.         oldShutdown()
  17.     end
  18.     nx, ny = term.getSize()
  19.     function term.getSize()
  20.         return nx, ny
  21.     end
  22.     oldR = os.reboot
  23.     function os.reboot()
  24.         rednet.unhost("rspserv",tostring(os.getComputerID()))
  25.         sleep(0.5)
  26.         oldReboot()
  27.     end
  28.     oldw = term.write
  29.     function term.write(t)
  30.         oldw(t)
  31.         snd({"write",t})
  32.     end
  33.     olds = term.scroll
  34.     function term.scroll(t)
  35.         olds(t)
  36.         snd({"scroll",t})
  37.     end
  38.     oldp = term.setCursorPos
  39.     function term.setCursorPos(t,y)
  40.         oldp(t,y)
  41.         snd({"pos",t,y})
  42.     end
  43.     oldcl = term.clear
  44.     function term.clear()
  45.         oldcl()
  46.         snd({"clear"})
  47.     end
  48.     oldColor = term.isColor
  49.     function term.isColor()
  50.         return true
  51.     end
  52.     oldbc = term.setBackgroundColor
  53.     function term.setBackgroundColor(t)
  54.         if oldColor() then
  55.             oldbc(t)
  56.         end
  57.         snd({"bc",t})
  58.     end
  59.     oldtc = term.setTextColor
  60.     function term.setTextColor(t)
  61.         if oldColor() then
  62.             oldtc(t)
  63.         end
  64.         snd({"tc",t})
  65.     end
  66.     term.setTextColour = term.setTextColor
  67.     term.setBackgroundColour = term.setBackgroundColor
  68.     term.isColour = term.isColor
  69.     oldcl = term.clearLine
  70.     function term.clearLine()
  71.         oldcl()
  72.         snd({"cl"})
  73.     end
  74.     oldbl = term.setCursorBlink
  75.     function term.setCursorBlink(b)
  76.         oldbl(b)
  77.         snd({"bl",b})
  78.     end
  79.     oldPull = os.pullEventRaw
  80.     function os.pullEventRaw(f)
  81.         while true do
  82.             local e = {oldPullRaw()}
  83.             if e[1] == "rednet_message" then
  84.                 if type(e[3]) == "table" then
  85.                     if e[3][1] == "key" then
  86.                         return "key",e[3][2]
  87.                     elseif e[3][1] == "char" then
  88.                         return "char",e[3][2]
  89.                     elseif e[3][1] == "init" then
  90.                         local canz = true
  91.                         for i, v in pairs(idp) do
  92.                             if v == e[2] then
  93.                                 canz = false
  94.                             end
  95.                         end
  96.                         if canz then
  97.                             table.insert(idp,e[2])
  98.                         end
  99.                         nx, ny = e[3][2], e[3][3]
  100.                         term.clear()
  101.                         term.setCursorPos(1,1)
  102.                     elseif e[3][1] == "label" then
  103.                         rednet.send(e[2],{os.getComputerLabel()})
  104.                     elseif e[3][1] == "dc" then
  105.                         local canz = true
  106.                         for i, v in pairs(idp) do
  107.                             if v == e[2] then
  108.                                 table.remove(idp,i)
  109.                             end
  110.                         end
  111.                     else
  112.                         return unpack(e)
  113.                     end
  114.                 end
  115.             end
  116.             return unpack(e)
  117.         end
  118.     end
  119. end
  120. parallel.waitForAll((function() sleep(0.5) term.clear() term.setCursorPos(1,1) shell.run("shell")),func)
Advertisement
Add Comment
Please, Sign In to add comment