Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string.starts(String, Start)
- return string.sub(String, 1, string.len(Start)) == Start
- end
- local protoSub = 'STOP_SPYING_ON_REDNET_'
- local file = 'THECODE_'
- local id = os.getComputerID()
- rednet.open('left')
- function floodTraffic()
- rednet.broadcast('STOP_SPYING', protoSub..math.random(0,200000))
- end
- local detector = peripheral.find('playerDetector')
- if not detector then
- error('Couldn\'t find the stalker thingie')
- end
- local envDet = peripheral.find('environmentDetector')
- local code
- if not fs.exists(file) then
- print('ID?')
- code = read()
- local newFile = fs.open(file, 'w')
- newFile.write(code)
- newFile.close()
- else
- local filePass = fs.open(file, 'r')
- code = filePass.readAll()
- end
- local prot = protoSub..code
- term.clear()
- if envDet == nil then
- print('Environment Detector could not be found.')
- end
- local dim = (envDet and envDet.getDimension() or "UNKNOWN")
- local cmds = {
- ['RESTART'] = function(...)
- os.reboot()
- end,
- ['EVAL'] = function(...)
- local luaStr = ...
- xpcall(function()
- loadstring(luaStr)()
- end, function(...)
- print(...)
- end)
- end,
- }
- function commandSent(dataStr)
- if type(dataStr) ~= "string" then return end
- if not string.starts(tostring(dataStr), '{') then return end
- xpcall(function()
- local data = textutils.unserialize(dataStr)
- cmds[data.cmd](data.txt)
- end, function(...)
- print(...)
- end)
- end
- while true do
- local event,_,_, m, n, t = os.pullEvent()
- if event == "modem_message" then
- if n.sProtocol == prot and m == 1 then
- commandSent(n.message)
- end
- end
- local playerPositions = {}
- local players = detector.getOnlinePlayers()
- if players then
- for _, player in next, players do
- local position = detector.getPlayerPos(player)
- if position then
- playerPositions[player] = player..': X: '..position.x..' Y: '..position.y..' Z: '..position.z
- else
- playerPositions[player] = nil
- end
- end
- local serialized = textutils.serialize({
- ['dem'] = dim,
- ['positions'] = playerPositions
- })
- if #serialized > 2 then
- rednet.send(1, serialized, prot)
- else
- rednet.send(1, 'NONE', prot)
- end
- end
- floodTraffic()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement