Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Copyright Oliver Marks 2018
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- Modifications must be reported to the copyright holder, Oliver Marks.
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- ]]
- local chat = peripheral.find "chat_box"
- local radar = peripheral.find "radar"
- local checkForSpam = false
- chat.setDistance(math.huge)
- rednet.open "top"
- -- A primitive spam filter. Respects checkForSpam variable
- function isSpam(msg, usr)
- if not checkForSpam then return false end
- if usr == "TerraInc" or string.find(msg, "TerraInc") then return true end
- return false
- end
- -- Listens to rednet & broadcasts to chat
- function rednetListen()
- while true do
- -- DAG Protocol: Rednet -> Chat
- local _, rawMsg = rednet.receive "chat_announce"
- local msg, usr = nil, "Announcer"
- if type(rawMsg) == "table" then
- if rawMsg[1] and rawMsg[2] then
- usr = rawMsg[1]
- msg = rawMsg[2]
- end
- else
- -- Support for old string-only protocol
- msg = tostring(rawMsg)
- end
- if not isSpam(msg, usr) then
- chat.setName(usr)
- chat.say(msg)
- lastMessage = msg
- end
- end
- end
- -- Listen to chat and broadcast on rednet.
- function chatListen()
- while true do
- local _, _, username, msg = os.pullEvent "chat_message"
- -- For debugging
- print(username, msg)
- -- Reverse messages from TheDacinator.
- if username == "TheDacinator" then
- msg = string.reverse(msg)
- end
- -- DAG Protocol - Chat -> Rednet
- rednet.broadcast({username, msg}, "chat_message")
- end
- end
- -- Detect items dropped on the ground.
- function detectLittering()
- local hasAnnouncedAlready = false
- while true do
- local items = radar.getItems()
- if #items > 0 then
- if not hasAnnouncedAlready then
- local players = radar.getPlayers()
- local item = items[1]
- local msg = "Littering Detected. The item littered is: " .. item.label .. ". "
- if players[1] then
- local name = players[1].name
- if name == "osmarks" then name = "nagoL2015" end
- msg = msg .. name .. " was detected at the crime scene."
- end
- if item.label ~= "Egg" then
- chat.setName "TidyStreet5000"
- chat.say(msg)
- rednet.broadcast({"TidyStreet5000", msg}, "chat_announce")
- hasAnnouncedAlready = true
- end
- end
- else
- hasAnnouncedAlready = false
- end
- sleep(0.5)
- end
- end
- -- Listens to DAG commands.
- function commandListen()
- local _, cmd = rednet.receive "announcer_command"
- if cmd == "reboot" then
- chat.setName "Announcer"
- chat.say "This node is rebooting."
- os.reboot()
- end
- end
- -- Transmit player location data
- function scanForPlayers()
- local x, y, z = gps.locate()
- while true do
- local players = radar.getPlayers()
- for _, p in pairs(players) do
- p.x = p.x + x
- p.y = p.y + y
- p.z = p.z + z
- p.time = os.time()
- p.day = os.day()
- rednet.broadcast(p, "player_tracking")
- end
- sleep(1)
- end
- end
- -- Relays GPS. May not be very accurate as it will just amplify errors in existing GPS host systems.
- function gpsRelay()
- print "Hosting GPS."
- shell.run "gps host"
- end
- pcall(function()
- parallel.waitForAll(chatListen, rednetListen, commandListen)
- end)
- sleep(10)
- os.reboot()
Add Comment
Please, Sign In to add comment