Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pdor = peripheral.find("playerDetector")
- if not pdor then error("no player detector found") end
- local cb = peripheral.find("chatBox")
- local mon = peripheral.find("monitor")
- if mon then term.redirect(mon) end
- local messageQueue = {}
- local SCAN_FREQUENCY = 30 --seconds between scans
- local max_file_size = 2^15
- shell.openTab("sh")
- local verifiedUsers = {t8rt0t=true,ckupen=true,Minecraft_3699=true,SirTZN=true}
- local messages = {
- {"sendMessageToPlayer","Your position has been located and saved."},
- {"sendMessageToPlayer","I can see you!"},
- {"sendMessageToPlayer","Big Brother is watching you"},
- {"sendMessageToPlayer","Dispatching missiles to [%d,%d,%d]"},
- {"sendMessageToPlayer","Nice base you have there"},
- {"sendMessageToPlayer","Located player %s at %d %d %d"},
- {"sendMessageToPlayer","I am watching you..."},
- {"sendMessageToPlayer","You cannot hide from me"},
- {"sendMessage","ATTENTION EVERYONE","I HAVE A VERY IMPORTANT ANNOUNCEMENT","PLAYER %s WAS JUST SPOTTED AT %d %d %d"},
- {"sendMessage","Located %s at %d %d %d"},
- {"sendMessageToPlayer","Saving your position at [%d,%d,%d]"},
- {"sendMessageToPlayer","Your position has been logged. Please contact your local [Doxxer] representative if you believe this was a mistake"},
- {"sendMessage","%s is at [%d, %d, %d] in dimension %s"},
- {"sendToastToPlayer","%d %d %d"},
- {"sendToastToPlayer","I am watching you"},
- {"sendMessageToPlayer","%d %d %d"},
- {"sendMessage","%s %s %d %d %d"}
- }
- local logFile = fs.open("latest.log","w+")
- local function log(...)
- if true then return unpack({...}) end
- for k,v in ipairs({...}) do
- if type(v) == "table" then
- logFile.write(textutils.serialise(v),{compact=true})
- else
- logFile.write(tostring(v))
- end
- logFile.write(", ")
- end
- logFile.write("\n")
- logFile.flush()
- return unpack({...})
- end
- local function handleMessageQueue()
- while true do
- if #messageQueue > 0 then
- local msg = table.remove(messageQueue,1)
- log("chatMsg",msg)
- if cb then
- local s,err = cb[msg.type](unpack(msg.args))
- if not s and err:match("cooldown") then table.insert(messageQueue,1,msg)
- else
- sleep(1)
- end
- end
- else
- sleep(0.1)
- end
- end
- end
- --Byte 0-251 = pos offset of (byte - 126)
- --Byte 252 = read next 4 bytes as signed integer
- --Byte 253 = read next 2 bytes as a signed short
- --Byte 254 = next byte is length of string (unsigned), followed by that number of bytes of string
- --Byte 255 = next 3 bytes are epoch (in seconds)
- --epoch ticks up by SCAN_FREQUENCY each time
- local function getLastPos(player)
- if not fs.exists("pos/" .. player .. ".dat") then return "overworld", {0,0,0},0 end
- local lastPos,thisPos = {0,0,0},{}
- local lastEpoch = 0
- local dim = "overworld"
- local file = fs.open("pos/" .. player .. ".dat","rb")
- local byte = file.read()
- while byte do
- if byte == 255 then
- lastEpoch = 0
- for i=1,3 do
- lastEpoch = lastEpoch * 255 + tonumber(file.read() or 0)
- end
- elseif byte == 254 then
- local len = file.read() or 0
- dim = file.read(len) or ""
- lastEpoch = lastEpoch + SCAN_FREQUENCY
- else
- local num = byte - 126
- if byte == 253 then
- num = tonumber(file.read() or 0)*255 + tonumber(file.read() or 0) - 2^15
- elseif byte == 252 then
- num = 0
- for i=1,4 do
- num = num*255 + tonumber(file.read() or 0)
- end
- num = num - 2^31
- end
- local idx = #thisPos + 1
- thisPos[idx] = lastPos[idx] + num
- if #thisPos >= 3 then
- lastPos = thisPos
- thisPos = {}
- end
- lastEpoch = lastEpoch + SCAN_FREQUENCY
- end
- byte = file.read()
- end
- return dim,lastPos,lastEpoch
- end
- local LAST_POS = {}
- local function moveToDisk(file)
- local epoch = math.floor(os.epoch("utc")/1000)
- if not fs.exists(file) then return false end
- local fileSize = fs.getSize(file)
- local player = file:match("[%w_%-/]-/(%w+)%.dat")
- if not fs.isDir("disk") then return false end
- if fs.getFreeSpace("disk") > fileSize then
- return pcall(function() fs.move(file,"disk/pos/" .. epoch .. "-" .. type(player) == "string" and player or "file" .. ".dat") end)
- end
- local index = 2
- while fs.isDir("disk"..index) do
- if fs.getFreeSpace("disk"..index) > fileSize then
- return pcall(function() fs.move(file,"disk"..index.."/pos/" .. epoch .. "-" .. type(player) == "string" and player or "file" .. ".dat") end)
- end
- index = index + 1
- end
- return false
- end
- local function writePos(player,dimension,pos)
- log("writePos",player,dimension,pos)
- lastPos = LAST_POS[player] or {getLastPos(player)}
- local file = fs.open("pos/"..player..".dat",fs.exists("pos/"..player..".dat") and "ab" or "wb")
- dimension = dimension:gsub("[^:]+:","")
- if dimension ~= lastPos[1] then
- file.write(254)
- file.write(math.min(#dimension,255))
- file.write(dimension:sub(1,255))
- end
- for i=1,#pos do
- local num = math.floor(pos[i] - lastPos[2][i])
- if num >= -126 and num <= 125 then
- log(num)
- file.write(num + 126)
- elseif num + 2^15 >= 0 and num + 2^15 < 2^16 then
- num = num + 2^15
- file.write(log(253))
- file.write(log(math.floor(num/256)))
- file.write(log(num%256))
- else
- num = num + 2^31
- file.write(log(252))
- local str = ""
- for i=1,4 do
- str = string.char(log(num%256)) .. str
- num = math.floor(num/256)
- end
- file.write(str)
- end
- end
- local epoch = math.floor(os.epoch("utc")/1000)
- if lastPos[3] + SCAN_FREQUENCY ~= epoch then
- file.write(255)
- local temp = epoch
- local str = ""
- for i=1,3 do
- str = string.char(temp%256) .. str
- temp = math.floor(temp/256)
- end
- file.write(str)
- end
- LAST_POS[player] = {dimension,pos,epoch}
- file.close()
- if fs.getSize("pos/"..player..".dat") > max_file_size then
- moveToDisk("pos/"..player..".dat")
- end
- end
- local function getAndSavePos(p)
- local pos = pdor.getPlayerPos(p)
- if pos and pos.dimension then
- writePos(p,pos.dimension,{math.floor(pos.x),math.floor(pos.y),math.floor(pos.z)})
- end
- return LAST_POS[p]
- end
- local function ui()
- if not fs.exists("pos") or not fs.isDir("pos") then return end
- for k,v in ipairs(fs.list("pos")) do
- local player = v:match("(%w+)%.dat")
- local pos = LAST_POS[player] or getLastPos(player)
- print(string.format("%s: %d %d %d | %s",player,pos[2][1],pos[2][2],pos[2][3],pos[1]))
- end
- end
- local function loop()
- while true do
- local players = pdor.getOnlinePlayers()
- local index = math.random() > 0.05 and 0 or math.random(#players)
- term.clear()
- if mon then
- term.setCursorPos(1,8)
- else
- term.setCursorPos(1,1)
- end
- for k,v in ipairs(players) do
- local pos = getAndSavePos(v)
- if not verifiedUsers[v] and index == k then
- local msg = messages[math.random(#messages)]
- for i=2,#msg do
- msg[i] = msg[i]:format(v,pos[2][1],pos[2][2],pos[2][3],pos[1],pos[3])
- if msg[1]:match("ToPlayer$") then
- table.insert(messageQueue,{type=msg[1],args={msg[i],v,"DOXXER","[]","&4"}})
- else
- table.insert(messageQueue,{type=msg[1],args={msg[i],"DOXXER","[]","&4"}})
- end
- end
- end
- --print(string.format("%s: %d %d %d | %s",v,pos[2][1],pos[2][2],pos[2][3],pos[1]))
- end
- ui()
- sleep(SCAN_FREQUENCY)
- end
- end
- parallel.waitForAll(handleMessageQueue,loop)
Advertisement
Add Comment
Please, Sign In to add comment