Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Minecraft Intranet
- Repeater program
- --]]
- print("Minecraft Intranet :: Repeater")
- print()
- -- Load dependencies
- dofile("/common/all")
- program.load("message", "names", "device")
- program.load("devices/repeater")
- -- Create repeater
- local configPath = "/repeater.conf"
- local defaultConfig = {
- device = "repeater",
- detectTimeout = 1
- }
- local config = common.loadStore(configPath, defaultConfig)
- local repeater = mcnet.device.Repeater:new()
- print(" Computer ID: "..tostring(os.computerID()))
- print()
- -- Register handlers
- repeater:on("forwardMessage", function(success, senderId, msg)
- if success then
- print("Forwarded from "..senderId)
- else
- print("Failed to forwarded from "..senderId)
- end
- end)
- repeater:on("char", function(char)
- if char == "q" then
- -- Confirm quit
- write("Confirm quit? [y/n] > ")
- local event, char = os.pullEvent("char")
- -- Check response
- local response = (string.lower(char) == "y" and "y") or "n"
- print(response)
- if (response == "y") then
- repeater:stop()
- end
- end
- end)
- repeater:on("error", function(errorType, errorMessage)
- print("[ERROR] "..errorMessage)
- end)
- -- Start
- print("Starting...")
- repeater:start(config.detectTimeout)
- write(" Detected:")
- for i,deviceId in pairs(repeater:neighbours()) do
- write(" "..deviceId)
- end
- print()
- print()
- -- Main loop
- print("Listening...")
- print(" Press Q to quit")
- print()
- while repeater.isRunning do
- repeater:trigger(os.pullEvent())
- end
- -- Stop
- print()
- print("Stopped")
- print()
Advertisement
Add Comment
Please, Sign In to add comment