Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Broadcast V1.0 program made by Anonomit
- local bDebugDefault = true
- for _, side in pairs( rs.getSides() ) do
- rednet.open( side )
- end --for _, side in pairs( rs.getSides() )
- local tArgs = { ... }
- local bDebug = tArgs[1] == "debug" and true or ( tArgs[1] == "noDebug" and false or bDebugDefault )
- local tLoggerData = {}
- local xTerm, yTerm = term.getSize()
- term.setCursorPos( 1, 3 )
- local function round( _number, _dp)
- local nMultiple = 10^( _dp or 0 )
- return math.floor( _number * nMultiple + 0.5 ) / nMultiple
- end --local function round( _number, _dp )
- if fs.exists( "broadcastSettings" ) then
- local file = fs.open( "broadcastSettings", "r" )
- tLoggerData = textutils.unserialize( file.readLine() )
- file.close()
- end --if fs.exists( "broadcastSettings" )
- local function display( _text )
- if bDebug and _text then
- print( _text )
- end --if bDebug and _text
- local xCursorPos, yCursorPos = term.getCursorPos()
- term.setCursorPos( 1, 1 )
- term.clearLine()
- print( "BROADCAST CONSOLE #" .. os.computerID() )
- term.clearLine()
- for i = 1, xTerm - 1 do
- write( "~" )
- end --for i = 1, xTerm - 1
- term.setCursorPos( xCursorPos, yCursorPos )
- end --local function display( _text )
- term.clear()
- display()
- local function rednetSend( _receiverID, _message )
- rednet.send( _receiverID, _message )
- display( ">Sent '" .. _message .. "' to #" .. _receiverID )
- end --local function rednetSend( receiverID, _message )
- local function handler( _id, _msg, _dist, _value )
- display( "<Received '" .. _msg .. "' from #" .. _id )
- tLoggerData[_id] = _value
- local file = fs.open( "broadcastSettings", "w" )
- file.write( textutils.serialize( tLoggerData ) )
- file.close()
- end --local function handler( _id, _msg, _dist, _value )
- while true do
- local event, param1, param2, param3 = os.pullEvent()
- if event == "rednet_message" and param2 == "loggerPing" then
- handler( param1, param2, param3, "loggerDoneLogging" )
- rednetSend( param1, "loggerPong" )
- elseif event == "rednet_message" and param2 == "broadcastPing" then
- display( "<Received '" .. param2 .. "' from #" .. param1 )
- rednetSend( param1, "broadcastPong" )
- elseif event == "rednet_message" and param2 == "loggerRequestStart" then
- display( "<Received '" .. param2 .. "' from #" .. param1 )
- local foo = true
- rednetSend( param1, textutils.serialize( tLoggerData ) )
- for id, state in pairs( tLoggerData ) do
- if state ~= "loggerDoneLogging" then
- foo = false
- end --if state == "loggerDoneLogging"
- end --for id, state in pairs( tLoggerData )
- if foo then
- for id, state in pairs( tLoggerData ) do
- if state == "loggerDoneLogging" then
- rednetSend( id, "loggerStartLogging" )
- end --if state == "loggerDoneLogging"
- end --for id, state in pairs( tLoggerData )
- end --if foo
- elseif event == "rednet_message" and ( param2 == "loggerLogging" or param2 == "loggerDoneLogging" or param2 == "loggerLowSaplings" or param2 == "loggerNoSaplings" ) then
- handler( param1, param2, param3, param2 )
- elseif event == "rednet_message" and param2 == "loggerForget" then
- handler( param1, param2, param3, nil )
- rednetSend( param1, "loggerForgot" )
- elseif event == "rednet_message" then
- display( "<Ignoring '" .. param2 .. "' from #" .. param1 .. " from " .. round( param3, 0 ).. " away" )
- end --if event == "rednet_message" and param2 == "broadcastPing"
- end --while true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement