Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string.split(inputstr, sep)
- if type(inputstr) ~= "string" then return end
- if sep == nil then
- sep = "%s"
- end
- local t = {}
- for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
- table.insert(t, str)
- end
- return t
- end
- function string.starts(str, Start)
- return string.sub(tostring(str), 1, string.len(Start)) == Start
- end
- local file = 'GO_AWAY_CODED'
- local connectedDevices = {'3'}
- local protoSub = "STOP_SPYING_ON_REDNET_"
- rednet.open("back")
- 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
- term.clear()
- local proto = protoSub .. code
- local positions = {}
- local queue = {}
- local knownSenders = {}
- local enabled = true
- local cmds = {
- ['RESTART'] = function(...)
- os.reboot()
- end,
- ['TOGGLE'] = function()
- enabled = (not enabled)
- end,
- ['EVAL'] = function(...)
- local luaStr = ...
- xpcall(function()
- loadstring(luaStr)()
- end, function(...)
- print(...)
- end)
- end,
- }
- function printQueue(str)
- table.insert(queue, str)
- end
- function flushQueue()
- term.clear()
- print(table.concat(queue, "\n"))
- queue = {}
- end
- function checkSenders()
- for sender, lastSeen in next, knownSenders do
- if os.time() - lastSeen >= 5 then
- table.remove(knownSenders, sender)
- end
- end
- end
- function floodTraffic()
- rednet.broadcast('STOP_SPYING', protoSub..math.random(0,200000))
- 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)
- local command = cmds[data.cmd]
- command(data.txt)
- end, function(...)
- print(...)
- end)
- end
- while true do
- local event, m, n, t = os.pullEvent()
- if event == "rednet_message" and t == proto and string.starts(tostring(n), '{') then
- if m == 4 then
- for sender, _ in next, knownSenders do
- print(sender)
- rednet.send(tonumber(sender), n, proto)
- end
- commandSent(n)
- else
- local pos_ = textutils.unserialize(n)
- if pos_ then
- knownSenders[m] = os.time()
- if not positions[pos_.dem] then
- positions[pos_.dem] = {}
- end
- for player, playerString in next, pos_.positions or {} do
- positions[pos_.dem][player] = playerString
- end
- end
- end
- end
- local finalStr = ''
- for i, item in next, positions do
- local x = string.split(i, ':')
- table.remove(x, 1)
- local demStr = table.concat(x, ':')
- finalStr=finalStr..'-- '..demStr..' --\n'
- for _, posStr in next, positions[i] do
- finalStr=finalStr..posStr..'\n'
- end
- end
- for _, device in next, connectedDevices do
- if enabled then
- rednet.send(tonumber(device), finalStr, 'uwu_publish')
- else
- rednet.send(tonumber(device), 'MONITOR DISABLED BY MANAGER', 'uwu_publish')
- end
- end
- checkSenders()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement