Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local receiverId;
- local arg={...};
- local function help()
- print("This program turns a PC into a message repeater. The PC resends the messages it receives to another PC (which may itself be a repeater).");
- print("To use this program put a wireless modem on the left side of the computer.");
- end
- if (#arg==0)
- then
- printError("You have to specify an argument.");
- print("\nArguments:");
- print("help: Display an help guide.");
- print("id: Get the id of this computer to use with rednet.");
- print("start id: Start the program. \"id\" is the id of the receiver.");
- return;
- else
- if (arg[1]=="id")
- then
- print("Receiver id: "..os.getComputerID());
- return;
- elseif (arg[1]=="help")
- then
- help();
- return;
- elseif (arg[1]=="start")
- then
- if (arg[2]~=nil)
- then
- receiverId=tonumber(arg[2]);
- if (receiverId==nil)
- then
- printError("\"id\" must be a number!");
- return;
- end
- else
- printError("You have to specify the id of the receiver computer!");
- return;
- end
- else
- printError("Wrong argument!");
- return;
- end
- end
- rednet.open("left");
- term.clear();
- term.setCursorPos(1, 1);
- while(true)
- do
- senderId, msg, protocol=rednet.receive();
- term.clear();
- term.setCursorPos(1, 1);
- if (protocol==nil)
- then
- protocol="No protocol";
- end
- print("Message received:");
- print("\nSender ID: "..senderId);
- print("Message: "..msg);
- print("Protocol: "..protocol);
- rednet.send(receiverId, msg);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement