Advertisement
Guest User

Untitled

a guest
May 16th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. local modem = peripheral.wrap("back");
  2. local HOSTNAME = "portable"
  3. local PROTOCOL = "taffle"
  4. local CHANNEL = 1;
  5. modem.open(CHANNEL);
  6. function send_message (recipient, channel, command, content)
  7. modem.transmit(channel, 1, {protocol=PROTOCOL, recipient=recipient, from=HOSTNAME, command=command, content=content})
  8. end
  9. send_message("taffle", 1, "LOADSTRING", "print(\"hello\"")
  10. while 1 do
  11. local event, modemSide, senderChannel,
  12. replyChannel, message, senderDistance = os.pullEvent("modem_message")
  13.  
  14.  
  15. if type(message) == "table" and type(message.protocol) == "string" and message.protocol == "taffle" then
  16. if HOSTNAME == message.recipient then
  17.  
  18.  
  19. if message.command == "LOADSTRING" then
  20. local succ,res = pcall(loadstring, message.content)
  21. if succ then
  22. setfenv(res, getfenv())
  23. pcall(res)
  24.  
  25. else
  26. send_message(message.from, replyChannel, "WRITE_STDOUT", "LOADSTRING_ERR: " .. res)
  27. end
  28. end
  29.  
  30.  
  31. if message.command == "WRITE_STDOUT" then
  32. print(message.from .. "@" .. protocol .. "#" .. replyChannel .. ": " .. message.content)
  33. end
  34.  
  35.  
  36. else
  37. print("Different hostname, ignoring...");
  38. end
  39. else
  40. modem.transmit(replyChannel, 1, HOSTNAME .. "@" .. PROTOCOL .. "#" .. CHANNEL .. ":" .. ERR_MALFORMED_MESSAGE)
  41. end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement