Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PORT_SEND = PORT_SEND or 777;
- PORT_RECV = 778 + os.getComputerID();
- write( "Send port " .. PORT_SEND .. "\n" )
- write( "Recv port " .. PORT_RECV .. "\n" )
- MODEM = nil;
- REACTOR = nil;
- local periList = peripheral.getNames();
- for i = 1, #periList do
- if peripheral.getType(periList[i]) == "modem" then
- local modem = peripheral.wrap(periList[i]);
- if modem.isWireless() then
- if modem.isOpen(PORT_SEND) then
- modem.close(PORT_SEND);
- end
- MODEM = modem;
- end
- elseif peripheral.getType(periList[i]) == "BigReactors-Reactor" then
- REACTOR = peripheral.wrap(periList[i]);
- end
- end
- if MODEM then
- MODEM.open(PORT_SEND);
- else
- print("Terrah: No modem found!");
- return;
- end
- function Call(func,param)
- if MODEM.isOpen(PORT_SEND) then
- MODEM.close(PORT_SEND);
- end
- if param == nil then
- param = "$";
- end
- if not MODEM.isOpen(PORT_RECV) then
- MODEM.open(PORT_RECV);
- end
- MODEM.transmit( PORT_SEND, PORT_RECV, func .. "|" .. tostring(param) );
- local event, modemSide, senderChannel,replyChannel, message, senderDistance = os.pullEvent("modem_message")
- --only respond to your channel
- while senderChannel ~= PORT_RECV do
- event, modemSide, senderChannel,replyChannel, message, senderDistance = os.pullEvent("modem_message")
- end
- if message == "$" then
- message = nil;
- end
- return message;
- end
- function Event( event, modemSide, senderChannel, replyChannel, message, senderDistance )
- if PORT_SEND ~= senderChannel then
- return;
- end
- local pos = message:find("|", 0, true );
- local xfunc = message:sub( 0, pos-1 );
- local param = message:sub( 1+pos );
- if param == "$" then
- param = nil;
- end
- local func = REACTOR[xfunc];
- local ret = nil;
- write( tostring(replyChannel) .. " - " .. xfunc .. "("..tostring(param) .. ") = " );
- if type(func) == "function" then
- if param == nil then
- ret = func();
- elseif xfunc == "setActive" then
- ret = func( param:lower() == "true" );
- elseif xfunc == "getControlRodLevel" or xfunc == "getControlRodName" then
- param = tonumber(param);
- if param < REACTOR.getNumberOfControlRods() and param >= 0 then
- ret = func(tonumber(param));
- end
- else
- ret = func(tonumber(param));
- end
- end
- write( tostring( ret ) .. "\n" );
- if MODEM.isOpen(replyChannel) then
- MODEM.close(replyChannel);
- end
- if ret == nil then
- ret = "$";
- end
- --return to sender
- MODEM.transmit( replyChannel, senderChannel, tostring(ret) );
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement