Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('user')
- os.loadAPI('comp')
- local modem = peripheral.wrap("left");
- local cmpsOnline = {};
- function openModemChannels()
- modem.open(100); -- Computer Authentication
- modem.open(101); -- User Authentication
- modem.open(102); --
- modem.open(103); --
- end --openModemChannels()
- function receivedComputer(rChannel, data)
- local msg = textutils.unserialize(data);
- if( msg.task == 'register') then
- comp.create( msg.cmp.id, msg.cmp.name );
- local cmp = comp.get( msg.cmp.id);
- cmp.respChannel = math.random(10500, 11000);
- cmpsOnline[#cmpsOnline+1] = cmp;
- print(rChannel);
- modem.transmit(rChannel, 100, textutils.serialize({task = "settings", channel = cmp.respChannel}));
- end --if
- end --receivedComputer
- function modemListen()
- while true do
- local e, s, sChannel, rChannel, data, dist = os.pullEvent();
- if( e == "modem_message" ) then
- modem.transmit(rChannel, 100, 'received');
- if( sChannel == 100 ) then
- receivedComputer(rChannel, data);
- end --if
- elseif( e == "key") then
- if( s == keys.q ) then
- term.clear();
- term.setCursorPos(1,1);
- for i = 1, #cmpsOnline do
- print(cmpsOnline[i].id .. ': ' .. cmpsOnline[i].respChannel);
- end --if
- end --if
- end --if
- end
- end --modemListen
- function main()
- openModemChannels();
- modemListen();
- end --main
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement