t8rt0t

doxxer.lua

May 27th, 2024 (edited)
120
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.33 KB | None | 1 0
  1. local pdor = peripheral.find("playerDetector")
  2. if not pdor then error("no player detector found") end
  3. local cb = peripheral.find("chatBox")
  4. local mon = peripheral.find("monitor")
  5. if mon then term.redirect(mon) end
  6. local messageQueue = {}
  7. local SCAN_FREQUENCY = 30 --seconds between scans
  8. local max_file_size = 2^15
  9. shell.openTab("sh")
  10. local verifiedUsers = {t8rt0t=true,ckupen=true,Minecraft_3699=true,SirTZN=true}
  11. local messages = {
  12.     {"sendMessageToPlayer","Your position has been located and saved."},
  13.     {"sendMessageToPlayer","I can see you!"},
  14.     {"sendMessageToPlayer","Big Brother is watching you"},
  15.     {"sendMessageToPlayer","Dispatching missiles to [%d,%d,%d]"},
  16.     {"sendMessageToPlayer","Nice base you have there"},
  17.     {"sendMessageToPlayer","Located player %s at %d %d %d"},
  18.     {"sendMessageToPlayer","I am watching you..."},
  19.     {"sendMessageToPlayer","You cannot hide from me"},
  20.     {"sendMessage","ATTENTION EVERYONE","I HAVE A VERY IMPORTANT ANNOUNCEMENT","PLAYER %s WAS JUST SPOTTED AT %d %d %d"},
  21.     {"sendMessage","Located %s at %d %d %d"},
  22.     {"sendMessageToPlayer","Saving your position at [%d,%d,%d]"},
  23.     {"sendMessageToPlayer","Your position has been logged. Please contact your local [Doxxer] representative if you believe this was a mistake"},
  24.     {"sendMessage","%s is at [%d, %d, %d] in dimension %s"},
  25.     {"sendToastToPlayer","%d %d %d"},
  26.     {"sendToastToPlayer","I am watching you"},
  27.     {"sendMessageToPlayer","%d %d %d"},
  28.     {"sendMessage","%s %s %d %d %d"}
  29. }
  30. local logFile = fs.open("latest.log","w+")
  31. local function log(...)
  32.     if true then return unpack({...}) end
  33.     for k,v in ipairs({...}) do
  34.         if type(v) == "table" then
  35.             logFile.write(textutils.serialise(v),{compact=true})
  36.         else
  37.             logFile.write(tostring(v))
  38.         end
  39.         logFile.write(", ")
  40.     end
  41.     logFile.write("\n")
  42.     logFile.flush()
  43.     return unpack({...})
  44. end
  45.  
  46. local function handleMessageQueue()
  47.     while true do
  48.         if #messageQueue > 0 then
  49.             local msg = table.remove(messageQueue,1)
  50.             log("chatMsg",msg)
  51.             if cb then
  52.                 local s,err = cb[msg.type](unpack(msg.args))
  53.                 if not s and err:match("cooldown") then table.insert(messageQueue,1,msg)
  54.                 else
  55.                     sleep(1)
  56.                 end
  57.             end
  58.         else
  59.             sleep(0.1)
  60.         end
  61.     end
  62. end
  63.            
  64.  
  65. --Byte 0-251 = pos offset of (byte - 126)
  66. --Byte 252 = read next 4 bytes as signed integer
  67. --Byte 253 = read next 2 bytes as a signed short
  68. --Byte 254 = next byte is length of string (unsigned), followed by that number of bytes of string
  69. --Byte 255 = next 3 bytes are epoch (in seconds)
  70. --epoch ticks up by SCAN_FREQUENCY each time
  71.  
  72. local function getLastPos(player)
  73.     if not fs.exists("pos/" .. player .. ".dat") then return "overworld", {0,0,0},0 end
  74.     local lastPos,thisPos = {0,0,0},{}
  75.     local lastEpoch = 0
  76.     local dim = "overworld"
  77.     local file = fs.open("pos/" .. player .. ".dat","rb")
  78.     local byte = file.read()
  79.     while byte do
  80.         if byte == 255 then
  81.             lastEpoch = 0
  82.             for i=1,3 do
  83.                 lastEpoch = lastEpoch * 255 + tonumber(file.read() or 0)
  84.             end
  85.         elseif byte == 254 then
  86.             local len = file.read() or 0
  87.             dim = file.read(len) or ""
  88.             lastEpoch = lastEpoch + SCAN_FREQUENCY
  89.         else
  90.             local num = byte - 126
  91.             if byte == 253 then
  92.                 num = tonumber(file.read() or 0)*255 + tonumber(file.read() or 0) - 2^15
  93.             elseif byte == 252 then
  94.                 num = 0
  95.                 for i=1,4 do
  96.                     num = num*255 + tonumber(file.read() or 0)
  97.                 end
  98.                 num = num - 2^31
  99.             end
  100.             local idx = #thisPos + 1
  101.             thisPos[idx] = lastPos[idx] + num
  102.             if #thisPos >= 3 then
  103.                 lastPos = thisPos
  104.                 thisPos = {}
  105.             end
  106.             lastEpoch = lastEpoch + SCAN_FREQUENCY
  107.         end
  108.         byte = file.read()
  109.     end
  110.     return dim,lastPos,lastEpoch
  111. end
  112.  
  113. local LAST_POS = {}
  114.  
  115. local function moveToDisk(file)
  116.     local epoch = math.floor(os.epoch("utc")/1000)
  117.     if not fs.exists(file) then return false end
  118.     local fileSize = fs.getSize(file)
  119.     local player = file:match("[%w_%-/]-/(%w+)%.dat")
  120.     if not fs.isDir("disk") then return false end
  121.     if fs.getFreeSpace("disk") > fileSize then
  122.         return pcall(function() fs.move(file,"disk/pos/" .. epoch .. "-" .. type(player) == "string" and player or "file" .. ".dat") end)
  123.     end
  124.     local index = 2
  125.     while fs.isDir("disk"..index) do
  126.         if fs.getFreeSpace("disk"..index) > fileSize then
  127.             return pcall(function() fs.move(file,"disk"..index.."/pos/" .. epoch .. "-" .. type(player) == "string" and player or "file" .. ".dat") end)
  128.         end
  129.         index = index + 1
  130.     end
  131.     return false
  132. end
  133.  
  134. local function writePos(player,dimension,pos)
  135.     log("writePos",player,dimension,pos)
  136.     lastPos = LAST_POS[player] or {getLastPos(player)}
  137.     local file = fs.open("pos/"..player..".dat",fs.exists("pos/"..player..".dat") and "ab" or "wb")
  138.     dimension = dimension:gsub("[^:]+:","")
  139.     if dimension ~= lastPos[1] then
  140.         file.write(254)
  141.         file.write(math.min(#dimension,255))
  142.         file.write(dimension:sub(1,255))
  143.     end
  144.     for i=1,#pos do
  145.         local num = math.floor(pos[i] - lastPos[2][i])
  146.         if num >= -126 and num <= 125 then
  147.             log(num)
  148.             file.write(num + 126)
  149.         elseif num + 2^15 >= 0 and num + 2^15 < 2^16 then
  150.             num = num + 2^15
  151.             file.write(log(253))
  152.             file.write(log(math.floor(num/256)))
  153.             file.write(log(num%256))
  154.         else
  155.             num = num + 2^31
  156.             file.write(log(252))
  157.             local str = ""
  158.             for i=1,4 do
  159.                 str = string.char(log(num%256)) .. str
  160.                 num = math.floor(num/256)
  161.             end
  162.             file.write(str)
  163.         end
  164.     end
  165.     local epoch = math.floor(os.epoch("utc")/1000)
  166.     if lastPos[3] + SCAN_FREQUENCY ~= epoch then
  167.         file.write(255)
  168.         local temp = epoch
  169.         local str = ""
  170.         for i=1,3 do
  171.             str = string.char(temp%256) .. str
  172.             temp = math.floor(temp/256)
  173.         end
  174.         file.write(str)
  175.     end
  176.     LAST_POS[player] = {dimension,pos,epoch}
  177.     file.close()
  178.     if fs.getSize("pos/"..player..".dat") > max_file_size then
  179.         moveToDisk("pos/"..player..".dat")
  180.     end
  181. end
  182.  
  183. local function getAndSavePos(p)
  184.     local pos = pdor.getPlayerPos(p)
  185.     if pos and pos.dimension then
  186.         writePos(p,pos.dimension,{math.floor(pos.x),math.floor(pos.y),math.floor(pos.z)})
  187.     end
  188.     return LAST_POS[p]
  189. end
  190.  
  191. local function ui()
  192.     if not fs.exists("pos") or not fs.isDir("pos") then return end
  193.     for k,v in ipairs(fs.list("pos")) do
  194.         local player = v:match("(%w+)%.dat")
  195.         local pos = LAST_POS[player] or getLastPos(player)
  196.         print(string.format("%s: %d %d %d | %s",player,pos[2][1],pos[2][2],pos[2][3],pos[1]))
  197.     end
  198. end
  199.  
  200. local function loop()
  201.     while true do
  202.         local players = pdor.getOnlinePlayers()
  203.         local index = math.random() > 0.05 and 0 or math.random(#players)
  204.         term.clear()
  205.         if mon then
  206.             term.setCursorPos(1,8)
  207.         else
  208.             term.setCursorPos(1,1)
  209.         end
  210.         for k,v in ipairs(players) do
  211.             local pos = getAndSavePos(v)
  212.             if not verifiedUsers[v] and index == k then
  213.                 local msg = messages[math.random(#messages)]
  214.                 for i=2,#msg do
  215.                     msg[i] = msg[i]:format(v,pos[2][1],pos[2][2],pos[2][3],pos[1],pos[3])
  216.                     if msg[1]:match("ToPlayer$") then
  217.                         table.insert(messageQueue,{type=msg[1],args={msg[i],v,"DOXXER","[]","&4"}})
  218.                     else
  219.                         table.insert(messageQueue,{type=msg[1],args={msg[i],"DOXXER","[]","&4"}})
  220.                     end
  221.                 end
  222.             end
  223.             --print(string.format("%s: %d %d %d | %s",v,pos[2][1],pos[2][2],pos[2][3],pos[1]))
  224.         end
  225.         ui()
  226.         sleep(SCAN_FREQUENCY)
  227.     end
  228. end
  229.  
  230. parallel.waitForAll(handleMessageQueue,loop)
Advertisement
Add Comment
Please, Sign In to add comment