Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Put YOUR code into the function main()
- --Tip: I think EEPROMs have a max capacity of 4K.
- local function create( first, ... )
- if first ~= nil then
- if type( first ) ~= "function" then
- error( "Expected function, got "..type( first ), 3 )
- end
- return coroutine.create(first), create( ... )
- end
- return nil
- end
- local function runUntilLimit( _routines, _limit )
- local count = #_routines
- local living = count
- local tFilters = {}
- local eventData = {}
- while true do
- for n=1,count do
- local r = _routines[n]
- if r then
- if tFilters[r] == nil or tFilters[r] == eventData[1] or eventData[1] == "terminate" then
- local ok, param = coroutine.resume( r, table.unpack(eventData) )
- if not ok then
- error( param, 0 )
- else
- tFilters[r] = param
- end
- if coroutine.status( r ) == "dead" then
- _routines[n] = nil
- living = living - 1
- if living <= _limit then
- return n
- end
- end
- end
- end
- end
- for n=1,count do
- local r = _routines[n]
- if r and coroutine.status( r ) == "dead" then
- _routines[n] = nil
- living = living - 1
- if living <= _limit then
- return n
- end
- end
- end
- eventData = { os.pullEventRaw() }
- end
- end
- local function waitForAny( ... )
- local routines = { create( ... ) }
- return runUntilLimit( routines, #routines - 1 )
- end
- function waitForAll( ... )
- local routines = { create( ... ) }
- runUntilLimit( routines, 0 )
- end
- local bios = component.proxy( component.list("eeprom")() )
- local m = component.proxy( component.list("modem")() )
- local port = 8192
- local sendport = 8193
- local whitelist = false
- local allowed = {} --Add a list of allowed network cards, must be strings, whitelist must be true.
- local allowExec = true --Allow the reqType "load"
- local function isAllowed(addr)
- if not whitelist then return true end
- for k,v in pairs(allowed) do
- if v == addr then
- return true
- end
- end
- return false
- end
- m.open(port)
- local function flashy()
- while true do
- local ev, _, from, portt, _, mes = computer.pullSignal()
- if ev == "modem_message" then
- if portt == port and isAllowed(from) and type(mes) == "string" then
- if mes:sub(1,6) == "flash;" and mes:sub(7) ~= nil then
- bios.set(mes:sub(7) )
- computer.beep(700, 0.5)
- elseif mes:sub(1,4) == "get;" then
- m.send(from, sendport, bios.getData() )
- elseif mes:sub(1,5) == "load;" and mes:sub(6) ~= nil and allowExec == true then
- load( mes:sub(6) )()
- elseif mes:sub(1,4) == "beep" then
- computer.beep(700, 0.5)
- end
- end
- end
- end
- end
- local function main()
- --Put your stuff here
- end
- waitForAll(main,flashy)
Advertisement
Add Comment
Please, Sign In to add comment