Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local files = {
- --startup
- ["startup.lua"] = [[shell.openTab("simpledoxxer")]],
- ["simpledoxxer.lua"] = [[local json = require("json")
- local multi = require("multiTurtle")
- local pos_dir = "shared/ppos/"
- local self_pos_path = "shared/"..multi:getID().."/pos.txt"
- if not fs.exists(self_pos_path) then
- print("please enter the position of the turtle")
- local pos = read()
- local file = fs.open(self_pos_path,"w+")
- file.write(pos)
- file.close()
- end
- if not fs.isDir(pos_dir) then fs.makeDir(pos_dir) end
- local pdor = peripheral.find("playerDetector")
- local onlinePlayers = json("shared/onlinePlayers.json")
- local players = {}
- for k,v in ipairs(fs.list(pos_dir)) do
- players[v] = json(pos_dir..v..".json")
- end
- local function getPositions()
- local p = pdor.getOnlinePlayers()
- for k,v in ipairs(p) do
- local s,pos = pcall(pdor.getPlayerPos,v)
- if s and pos and pos.x and pos.dimension then
- pos.epoch = os.epoch("utc")
- print(v,pos.x,pos.y,pos.z)
- if not players[v] then players[v] = json(pos_dir..v..".json") end
- players[v][pos.dimension] = pos
- end
- end
- onlinePlayers.players = p
- end
- local function printPlayers(players)
- term.setCursorPos(1,1)
- term.clear()
- for k,v in ipairs(players) do
- if not players[v] then players[v] = json(pos_dir..v..".json") end
- local maxEpoch,pos,dim = 0
- for j,w in pairs(players[v]) do
- if w.epoch > maxEpoch then
- maxEpoch = w.epoch
- pos = w
- dim=j
- end
- end
- if pos and dim then
- print(string.format("%s %s: <%d,%d,%d>",dim:gsub("[^:]+:",""),v,pos.x,pos.y,pos.z))
- end
- end
- end
- if pdor then
- while true do
- getPositions()
- sleep(1)
- end
- else
- while true do
- printPlayers(onlinePlayers.players or {})
- sleep(1)
- end
- end]],
- --multiTurtle
- ["multiTurtle.lua"] = [[--Multi turtle stuff
- local MULTI = {}
- --Assignment
- local assignmentsPath = "metadata/.multi_assignment.json"
- local assignmentsDir = "metadata/ids/"
- --metadata/.multi_assignment.json layout
- -- {
- -- "custom_filters":{
- -- "type":"functionStr(test1,test2,test3) return true if conditionsMet else return false end"
- -- },
- -- "new_id":"functionStr() return newID,conditionTable end"
- --}
- --metadata/ids/<id>.json layout
- -- {
- -- "type": "any" | "all",
- -- "conditions": [
- -- {
- -- "type": "(conditionType)",
- -- "conditions": [
- -- "test1",
- -- true,
- -- "test3"
- -- ]
- -- }
- -- ]
- -- }
- local function between(test,a,b)
- return test >= math.min(a,b) and test <= math.max(a,b)
- end
- --Define default filters
- MULTI.FILTERS = {
- ["all"] = function(...)
- for _,condition in ipairs(...) do
- if not MULTI.VALIDATE(condition) then
- return false
- end
- end
- return true
- end,
- ["any"] = function(...)
- for _,condition in ipairs(...) do
- if MULTI.VALIDATE(condition) then
- return true
- end
- end
- return false
- end,
- ["not"] = function(condition)
- return not MULTI.VALIDATE(condition)
- end,
- ["label.exact"] = function(test) return os.getComputerLabel() == test end,
- ["label.contains"] = function(test,useRegex) return os.getComputerLabel() and os.getComputerLabel():find(test,1,useRegex) end,
- ["label.within"] = function(test,useRegex) return os.getComputerLabel() and test:find(os.getComputerLabel(),1,useRegex) end,
- ["computer.pocket"] = function() return pocket end,
- ["computer.turtle"] = function() return turtle end,
- ["computer.advanced"] = function() return term.isColor() end,
- ["computer.command"] = function() return command end,
- ["computer.normal"] = function() return not pocket and not turtle and not command end,
- ["peripheral.type"] = function(pType) return peripheral.find(pType) end,
- ["peripheral.name"] = function(pName) return peripheral.wrap(pName) end,
- ["gps.exact"] = function(x,y,z)
- local s,a,b,c = pcall(gps.locate)
- return s and x == a and y == b and z == c
- end,
- ["gps.range"] = function(x1,y1,z1,x2,y2,z2)
- local s,a,b,c = pcall(gps.locate)
- return s and between(a,x1,x2) and between(b,y1,y2) and between(c,z1,z2)
- end,
- ["files.find"] = function(regex) return #fs.find(regex) > 0 end, --Useful for external disks
- --More dangerous types
- ["turtle.fuel.exact"] = function(value) return turtle and turtle.getFuelLevel() == value end,
- ["turtle.fuel.range"] = function(lowerLimit,upperLimit) return turtle and between(turtle.getFuelLevel(),lowerLimit,upperLimit) end,
- ["turtle.inventory.contains"] = function(name)
- if not turtle then return false end
- for i=1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == name then
- return true
- end
- end
- return false
- end,
- ["turtle.inventory.exactSlot"] = function(slot,name,count)
- if turtle and turtle.getItemCount(slot) > 0 then
- return turtle.getItemDetail(slot).name == name and (not count or (turtle.getItemCount(slot) == count))
- end
- return false
- end
- }
- function MULTI.NEW_ID()
- local id = string.format("%x",os.epoch("utc")%0x1000000)
- local label = string.char(167) .. string.format("%x",math.random(16)-1) .. string.char(167) .. "k" .. id
- os.setComputerLabel(label)
- return label,{["type"] = "label.exact",conditions = {label}}
- end
- function MULTI.VALIDATE(condition)
- local cType = condition.type
- if not cType or type(MULTI.FILTERS[cType]) ~= "function" then return false end
- local conditions = condition.conditions
- if type(conditions or {}) ~= "table" then return false end
- local s,isValid = pcall(MULTI.FILTERS[cType],unpack(conditions or {}))
- return s and isValid
- end
- --Load metadata
- if fs.exists(assignmentsPath) then
- local file = fs.open(assignmentsPath,"r")
- local data = textutils.unserialiseJSON(file.readAll()) or {}
- file.close()
- if type(data.custom_filters) == "table" then
- for k,v in pairs(data.custom_filters) do
- local f = loadstring(tostring(v))
- if f then
- local _,filter = pcall(f)
- if type(filter) == "function" then
- MULTI[k] = filter
- end
- end
- end
- end
- if type(data.new_id) == "string" then
- local f = loadstring(data.new_id)
- if f then
- local _,idFunction = pcall(f)
- if type(idFunction) == "function" then
- MULTI.NEW_ID = idFunction
- end
- end
- end
- end
- function MULTI:getID()
- if self.id then return self.id end
- if fs.exists(assignmentsDir) and fs.isDir(assignmentsDir) then
- for k,v in pairs(fs.list(assignmentsDir)) do
- local file = fs.open(fs.combine(assignmentsDir,v),"r")
- local conditions = textutils.unserialise(file.readAll())
- file.close()
- if MULTI.VALIDATE(conditions) then
- self.id = v
- return v
- end
- end
- end
- local id,conditions = MULTI.NEW_ID()
- self.id = id
- local file = fs.open(fs.combine(assignmentsDir,id),"w+")
- file.write(assert(textutils.serialise(conditions),"could not serialize conditions table!"))
- file.close()
- return id
- end
- function MULTI:getIDS()
- return fs.list(assignmentsDir)
- end
- local function getBroadcastFolder(id)
- local folder = "shared/"..id.."/inbox/"
- if not fs.exists(folder) then fs.makeDir(folder) end
- return folder
- end
- function MULTI:new()
- local multi = {}
- multi.message_queue = {}
- setmetatable(multi,self)
- self.__index = self
- local id = multi:getID()
- multi.personalFolder = "private/"..id
- if not fs.exists(multi.personalFolder) then
- fs.makeDir(multi.personalFolder)
- end
- multi.sharedFolder = "shared/"..id
- if not fs.exists(multi.sharedFolder) then
- fs.makeDir(multi.sharedFolder)
- end
- return multi
- end
- function MULTI:__tostring()
- return "MULTI: " .. tostring(self.id)
- end
- --Returns senderID,message,protocol
- function MULTI:receive(otherID,nTimeOut)
- if not self.sharedFolder then error("Multi not initialized") end
- if otherID then
- if not self.message_queue[otherID] then self.message_queue[otherID] = {} --Make sure theres queue for the other id
- elseif #self.message_queue[otherID] > 0 then return otherID,unpack(table.remove(self.message_queue[otherID])) end --If theres already message queue for that id then return that message
- local targetPath = getBroadcastFolder(self.id) .. otherID .. ".broadcast"
- local endEpoch = os.epoch("utc") + (nTimeOut or 0)*1000
- while not nTimeOut or os.epoch("utc") <= endEpoch do
- if fs.exists(targetPath) then
- local file = fs.open(targetPath,"r")
- local data = file.readAll()
- file.close()
- fs.delete(targetPath)
- for msg in data:gsub("[^\n]+") do
- msg = textutils.unserialiseJSON(msg)
- if msg then
- table.insert(self.message_queue[otherID],msg)
- end
- end
- if #self.message_queue[otherID] > 0 then return otherID,unpack(table.remove(self.message_queue[otherID])) end
- end
- sleep(0)
- end
- else
- local ids = self:getIDs()
- local id = self:getID()
- local funcs = {}
- local output = {}
- for k,v in ipairs(ids) do
- if v ~= id then
- table.insert(funcs,function() output = {self:receive(v,nTimeOut)};return end)
- end
- end
- parallel.waitForAny(unpack(funcs))
- return unpack(output)
- end
- end
- function MULTI:send(otherID,msg,protocol)
- if id == self:getID() then return false end
- if not self.sharedFolder then error("Multi not initialized") end
- local packet = {msg}
- if protocol then packet = {msg,protocol} end
- packet = assert(textutils.serialiseJSON(packet),"Could not serialise json for the message")
- local targetPath = getBroadcastFolder(otherID) .. self:getID() .. ".broadcast"
- local file = fs.open(targetPath,fs.exists(targetPath) and "a" or "w")
- file.writeLine(packet)
- file.close()
- end
- function MULTI:broadcast(msg,protocol)
- local ids = self:getIDs()
- for k,v in ipairs(ids) do
- self:send(v,msg,protocol)
- end
- end
- return MULTI:new()]],
- --json
- ["json.lua"] = [[--Concurrent JSON editing
- local JSON = {}
- local loaded_files = {}
- function JSON:__refresh()
- local filePath = rawget(self,"__filePath")
- if filePath and fs.exists(filePath) then
- local file = fs.open(filePath,"r")
- rawset(self,"__data",textutils.unserialiseJSON(file.readAll()) or rawget(self,"__data"))
- file.close()
- end
- end
- function JSON:__new(filePath)
- if loaded_files[filePath] then return loaded_files[filePath] end
- local json = {__data = {},__filePath = filePath}
- if fs.exists(filePath) then
- local file = fs.open(filePath,"r")
- json.__data = textutils.unserialiseJSON(file.readAll()) or {}
- file.close()
- end
- json.__name = tostring(json.__data):gsub("table","json")
- setmetatable(json,self)
- loaded_files[filePath] = json
- return json
- end
- function JSON:__tostring()
- return rawget(self,"__name") or ""
- end
- function JSON:__pairs()
- self:__refresh()
- return pairs(rawget(self,"__data"))
- end
- function JSON:__ipairs()
- self:__refresh()
- return ipairs(rawget(self,"__data"))
- end
- function JSON:__len()
- return #rawget(self,"__data")
- end
- function JSON:__totable()
- self:__refresh()
- return rawget(self,"__data")
- end
- function JSON:__index(idx)
- if not rawget(self,"__data") then return rawget(self,idx) end
- local item = rawget(JSON,idx)
- if item ~= nil then return item
- else
- self:__refresh()
- return rawget(self,"__data")[idx]
- end
- end
- --Last thing defined
- JSON.__newindex = function(self,key,value)
- if not rawget(self,"__filePath") then return rawset(self,key,value) end
- self:__refresh()
- rawget(self,"__data")[key] = value
- local file = fs.open(rawget(self,"__filePath"),"w+")
- file.write(textutils.serialiseJSON(rawget(self,"__data")))
- file.close()
- end
- local serialize,serializeJSON = textutils.serialize,textutils.serializeJSON
- textutils.serialize = function( t )
- if getmetatable(t) == JSON then return serialize(rawget(t,"__data")) end
- return serialize(t)
- end
- textutils.serialise = textutils.serialize
- textutils.serializeJSON = function( t, bNBTStyle )
- if getmetatable(t) == JSON then return serializeJSON(rawget(t,"__data"), bNBTStyle) end
- return serializeJSON(t,bNBTStyle)
- end
- textutils.serialiseJSON = textutils.serializeJSON
- return function(path) return JSON:__new(path) end]]
- }
- for k,v in pairs(files) do
- local file = fs.open(k,"w+")
- file.write(v)
- file.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment