Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tBanned={}
- myNet={}
- local function co() --the coroutine that manages the messages and forwards them, queues events etc
- while true do
- local input={os.pullEventRaw()}
- if input[1]=='rednet_message' then
- table.remove(input,1)
- local t=textutils.unserialize(input[2])
- if t and t[1]=='myNet' and not tBanned[t[3]] then
- tBanned[t[3]]=os.startTimer(2)
- rednet.broadcast(input[2])
- if not t[4] or t[4]==os.computerID() then
- os.queueEvent('myNet',t[2],t[3])
- end
- end
- elseif input[1]=='timer' then
- for k,v in pairs(tBanned) do
- if v==input[2] then
- tBanned[k]=nil
- break
- end
- end
- end
- end
- end
- function myNet.send(message,id)
- rednet.broadcast(textutils.serialize({'myNet',os.computerID(),message,id}))
- end
- function myNet.receive(timeout)
- local timed=false
- if type(timeout)=='number' then timed=os.startTimer(timeout) end
- while true do
- local evts={os.pullEvent()}
- if evts[1]=='timer' and evts[2]==timed then
- return nil
- elseif evts[1]=='myNet' then
- return unpack(evts,2)
- end
- end
- end
- if not fs.exists('bGo') then --1st boot that relaunches shell
- term.clear()
- term.setCursorPos(1,1)
- local oFile=io.open('bGo','w')
- oFile:write('true')
- oFile:close()
- local tThreads={coroutine.wrap(co),coroutine.wrap(function() os.run({},'rom/programs/shell') end)}
- local evts={}
- while true do
- for iNum,fThread in pairs(tThreads) do
- fThread(unpack(evts))
- end
- evts={os.pullEventRaw()}
- end
- else --2nd boot where shell has been relaunched, it launches startup2 in case you need another startup file on the PC
- fs.delete('bGo')
- if fs.exists('startup2') then
- shell.run('startup2')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement