Bjornir90

Coreplugin

Dec 5th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. {[1]="coreplugin", [2]="1",}
  2.  
  3. local idSender, msg = rednet.receive()
  4. local msgT = textutils.unserialize(msg)
  5. local idAdressee = msgT[1]
  6. local type = msgT[2]
  7. local body = msgT[3]
  8. if idAdressee == idServer then
  9.  term.setTextColor(colors.yellow)
  10.  print("Message for the server received")
  11.  term.setTextColor(colors.black)
  12.  if type == "#/program#" then
  13.   local idSender, arg = rednet.receive()
  14.   shell.run(body, arg)
  15.  elseif type == "#/file#" then
  16.   local idSender, toDo = rednet.receive()
  17.   if toDo == "%save%" then
  18.    local idSender, nameOfFile = rednet.receive()
  19.    local file = fs.open("/usermade/"..nameOfFile, "w")
  20.    file.write(body)
  21.    file.close()
  22.    rednet.send(tonumber(idSender), "<saved>")
  23.   elseif toDo == "%run%" then
  24.    loadstring(body)
  25.    rednet.send(tonumber(idSender), "<executed>")
  26.   else
  27.    rednet.send(tonumber(idSender), "<error:fileinfo:wrongcommand>")
  28.   end
  29.  elseif type == "#/command#" then
  30.   local idSender, command = rednet.receive()
  31.   if command == "#/exit#" then
  32.    return
  33.   else
  34.    rednet.send(tonumber(idSender), "<error:commandinfo:
  35. wrongcommand>")
  36.   end
  37.  else
  38.   rednet.send(tonumber(idSender), "<error:typerequest:wrongtype>")
  39.  end
  40. else
  41.  term.setTextColor(colors.black)
  42.  print("Request for : "..idAdressee.." received")
  43.  rednet.send(tonumber(idAdressee), body)
  44.  while true do
  45.   local idReceiver, msgConfirm = rednet.receive(5)
  46.   if msgConfirm == "<success:messagereceived>" then
  47.    term.setTextColor(colors.green)
  48.    print("Message successfully sent")
  49.    term.setTextColor(colors.black)
  50.    rednet.send(tonumber(idSender), "<success:messagesent>")
  51.    break
  52.   end
  53.  end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment