Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("back");
- local HOSTNAME = "portable"
- local PROTOCOL = "taffle"
- local CHANNEL = 1;
- modem.open(CHANNEL);
- function send_message (recipient, channel, command, content)
- modem.transmit(channel, 1, {protocol=PROTOCOL, recipient=recipient, from=HOSTNAME, command=command, content=content})
- end
- send_message("taffle", 1, "LOADSTRING", "print(\"hello\"")
- while 1 do
- local event, modemSide, senderChannel,
- replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if type(message) == "table" and type(message.protocol) == "string" and message.protocol == "taffle" then
- if HOSTNAME == message.recipient then
- if message.command == "LOADSTRING" then
- local succ,res = pcall(loadstring, message.content)
- if succ then
- setfenv(res, getfenv())
- pcall(res)
- else
- send_message(message.from, replyChannel, "WRITE_STDOUT", "LOADSTRING_ERR: " .. res)
- end
- end
- if message.command == "WRITE_STDOUT" then
- print(message.from .. "@" .. protocol .. "#" .. replyChannel .. ": " .. message.content)
- end
- else
- print("Different hostname, ignoring...");
- end
- else
- modem.transmit(replyChannel, 1, HOSTNAME .. "@" .. PROTOCOL .. "#" .. CHANNEL .. ":" .. ERR_MALFORMED_MESSAGE)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement