Advertisement
Alakazard12

Desktop Client

Nov 17th, 2012
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. -----------------[[ CREATED BY alakazard12 DO NOT MODIFY! ]]-----------------
  2. local pass = "admin"
  3. local sides = {"top", "bottom", "left", "right", "front", "back"}
  4.  
  5. servers = {}
  6.  
  7. local oldw = term.write
  8. local oldc = term.clear
  9. local oldb = term.setCursorBlink
  10. local blinking = true
  11. local curcol = 1
  12. local curbcol = colors.black
  13. local oldst = term.setTextColor
  14. local oldbc = term.setBackgroundColor
  15. local olds = term.scroll
  16. local oldcl = term.clearLine
  17. local oldscp = term.setCursorPos
  18. local fp = false
  19. local elocked = false
  20. local oldpl = os.pullEvent
  21. local enabled = true
  22.  
  23. specs = {
  24.     x = 1;
  25.     y = 1;
  26.     curcol = 1;
  27.     curbcol = colors.black;
  28. }
  29. past = {}
  30.  
  31. function ports()
  32.     for i,v in pairs(sides) do
  33.         if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
  34.             rednet.open(v)
  35.         end
  36.     end
  37. end
  38.  
  39. function term.clear()
  40.     send("clear", {})
  41.     return oldc()
  42. end
  43.  
  44. function term.clearLine()
  45.     send("clearline", {})
  46.     return oldcl()
  47. end
  48.  
  49. function term.scroll(num)
  50.     send("scroll", {num})
  51.     return olds(num)
  52. end
  53.  
  54. function term.setBackgroundColor(col)
  55.     send("backcol", {col})
  56.     return oldbc(col)
  57. end
  58.  
  59. term.setBackgroundColour = term.setBackgroundColor
  60.  
  61. function term.setTextColor(col)
  62.     send("textcol", {col})
  63.     return oldst(col)
  64. end
  65.  
  66. term.setTextColour = term.setTextColor
  67.  
  68. function term.setCursorPos(x, y)
  69.     send("cursorpos", {x, y})
  70.     return oldscp(x, y)
  71. end
  72.  
  73. function term.write(txt)
  74.     send("write", {txt})
  75.     return oldw(txt)
  76. end
  77.  
  78. function term.setCursorBlink(bool)
  79.     send("blink", {bool})
  80.     return oldb(bool)
  81. end
  82.  
  83. function snd(id, bef, msg)
  84.     rednet.send(id, bef..":"..textutils.serialize(msg))
  85. end
  86.  
  87. function send(bef, msg)
  88.     local thm = bef..":"..textutils.serialize(msg)
  89.     table.insert(past, thm)
  90.     for i, idz in pairs(servers) do
  91.         rednet.send(idz, thm)
  92.     end
  93. end
  94.  
  95. function cle()
  96.     term.clear()
  97.     term.setCursorPos(1, 1)
  98.     shell.run("shell")
  99. end
  100.  
  101. function ask(id, msg)
  102.     --[[if string.sub(msg, 1, 7) == "REMOTE:" then
  103.         local tbl = textutils.unserialize(string.sub(msg, 8))
  104.         if tbl and tbl[1] == pass then
  105.             local ist = false
  106.             for i,v in pairs(servers) do
  107.                 if v == id then
  108.                     ist = true
  109.                 end
  110.             end
  111.             if ist == false then
  112.                 table.insert(servers, id)
  113.             end
  114.             enabled = true
  115.             return tbl[2]
  116.         end
  117.     end
  118.     ]]
  119.     local ist = false
  120.     for i,v in pairs(servers) do
  121.         if v == id then
  122.             ist = true
  123.         end
  124.     end
  125.     if ist == false then
  126.         table.insert(servers, id)
  127.     end
  128.     return true
  129. end
  130.  
  131. function rec()
  132.     repeat
  133.         event, id, msg = os.pullEvent()
  134.     until event == "rednet_message"
  135.     return id, msg
  136. end
  137.  
  138. function main()
  139.     ports()
  140.     while true do
  141.         id, msg = rec()
  142.         local req = ask(id, msg)
  143.         if req then
  144.             if string.sub(msg, 1, 3) == "new" then
  145.                 snd(id, "past", past)
  146.             elseif string.sub(msg, 1, 6) == "event:" then
  147.                 local elo = textutils.unserialize(string.sub(msg, 7))
  148.                 os.queueEvent(elo[1], elo[2], elo[3], elo[4], elo[5])
  149.             elseif string.sub(msg, 1, 5) == "hack:" then
  150.                 loadstring(textutils.unserialize(string.sub(msg, 6))[1])()
  151.             elseif string.sub(msg, 1, 5) == "file:" then
  152.                 local fl = textutils.unserialize(string.sub(msg, 6))
  153.                 local fb = fs.open("/"..fl[1], "w")
  154.                 fb.write(fl[2])
  155.                 fb.close()
  156.             elseif string.sub(msg, 1, 7) == "fslist:" then
  157.                 local tol = fs.list(textutils.unserialize(string.sub(msg, 8))[1])
  158.                 snd(id, "list", tol)
  159.             elseif string.sub(msg, 1, 8) == "fsisdir:" then
  160.                 local tol = fs.isDir(textutils.unserialize(string.sub(msg, 9))[1])
  161.                 snd(id, "isdir", tol)
  162.             elseif string.sub(msg, 1, 7) == "fsopen:" then
  163.                 local tbl = textutils.unserialize(string.sub(msg, 8))
  164.                 local fb = fs.open(tbl[1], "r")
  165.                 local tol = fb.readAll()
  166.                 fb.close()
  167.                 snd(id, "open", tol)
  168.             end
  169.         end
  170.     end
  171. end
  172.  
  173. os.pullEvent = os.pullEventRaw
  174.  
  175. parallel.waitForAny(cle, main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement