Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ===== Speaker Node v2 =====
- -- Auto-joins the music network. Plays whatever the main computer broadcasts.
- -- Setup: place computer + wireless modem + speaker adjacent. Save as startup.lua. Reboot.
- local PROTOCOL = "atmop_music"
- local HOSTNAME = "speaker_" .. os.getComputerID()
- -- Find wireless modem
- local modem
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "modem" and peripheral.call(side, "isWireless") then
- modem = side
- break
- end
- end
- if not modem then error("No wireless modem attached") end
- -- Find local speaker
- local speaker = peripheral.find("speaker")
- if not speaker then error("No speaker attached") end
- rednet.open(modem)
- rednet.host(PROTOCOL, HOSTNAME)
- term.clear()
- term.setCursorPos(1,1)
- print("Speaker Node Online")
- print("ID: " .. os.getComputerID())
- print("Listening on protocol: " .. PROTOCOL)
- print("Waiting for audio...")
- local decoder = require("cc.audio.dfpwm").make_decoder()
- local audioQueue = {}
- local stopFlag = false
- local currentVolume = 1.5
- -- Receiver: just stuffs incoming chunks into the queue
- local function receiverLoop()
- while true do
- local sender, msg = rednet.receive(PROTOCOL)
- if type(msg) == "table" then
- if msg.cmd == "audio" and msg.chunk then
- currentVolume = msg.volume or 1.5
- table.insert(audioQueue, msg.chunk)
- -- Cap queue size to prevent runaway memory
- if #audioQueue > 8 then
- table.remove(audioQueue, 1)
- end
- elseif msg.cmd == "stop" then
- stopFlag = true
- audioQueue = {}
- speaker.stop()
- elseif msg.cmd == "ping" then
- rednet.send(sender, {cmd="pong", id=os.getComputerID()}, PROTOCOL)
- end
- end
- end
- end
- -- Player: pulls from queue and plays, yielding properly
- local function playerLoop()
- while true do
- if #audioQueue > 0 then
- stopFlag = false
- local chunk = table.remove(audioQueue, 1)
- local ok, buffer = pcall(decoder, chunk)
- if ok and buffer then
- local played = false
- while not played do
- if stopFlag then break end
- if speaker.playAudio(buffer, currentVolume) then
- played = true
- else
- -- Wait for buffer to drain, but with timeout fallback
- local timer = os.startTimer(2)
- while true do
- local ev, p1 = os.pullEvent()
- if ev == "speaker_audio_empty" then break end
- if ev == "timer" and p1 == timer then break end
- end
- end
- end
- end
- else
- os.sleep(0.05)
- end
- end
- end
- parallel.waitForAny(receiverLoop, playerLoop)
Advertisement
Comments
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=vketxrsplw
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment