.
This commit is contained in:
parent
2e9a644e37
commit
6757e1eb10
@ -48,10 +48,10 @@ function sendLog(to, targetPath, logMsg)
|
|||||||
local payloadTable = {}
|
local payloadTable = {}
|
||||||
|
|
||||||
payloadTable[0] = targetPath
|
payloadTable[0] = targetPath
|
||||||
payloadTable[1] = basic.getCurrentTime() .. ": " .. logMsg
|
payloadTable[1] = "[" .. basic.getCurrentTime() .. "]: " .. logMsg
|
||||||
|
|
||||||
sendMessage(to, "log", payloadTable)
|
sendMessage(to, "log", payloadTable)
|
||||||
basic.ntfy(os.getComputerLabel() .. ": " .. payloadTable[1])
|
basic.ntfy("[" .. os.getComputerLabel() .. "] " .. payloadTable[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
function sendFile(to, originPath, targetPath)
|
function sendFile(to, originPath, targetPath)
|
||||||
|
@ -2,21 +2,112 @@ basic = require("lib.basic")
|
|||||||
hash = require("lib.hash")
|
hash = require("lib.hash")
|
||||||
|
|
||||||
local pwHash = ""
|
local pwHash = ""
|
||||||
|
local config = {}
|
||||||
|
|
||||||
local function setState()
|
local function setConfig()
|
||||||
basic.writeToFile("/brulijam/config/systemlock.config", asdasd)
|
basic.writeToFile("/brulijam/config/systemlock.config", textutils.serialize(config))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getState()
|
local function getConfig()
|
||||||
if not fs.exists "/brulijam/config/systemlock.config" then
|
if not fs.exists "/brulijam/config/systemlock.config" then
|
||||||
config = {}
|
|
||||||
config["locked"] = true
|
config["locked"] = true
|
||||||
config["pwHash"] = createPwHash()
|
config["pwHash"] = createPwHash()
|
||||||
|
config["keepUnlockedFor"] = 600
|
||||||
|
setConfig()
|
||||||
|
else
|
||||||
|
config = basic.readFileAll("brulijam/config/systemlock.config")
|
||||||
|
config = textutils.unserialize(config)
|
||||||
|
end
|
||||||
|
return config
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createPwHash()
|
local function createPwHash()
|
||||||
print("Create a new password: ")
|
write("Create a new password : ")
|
||||||
local input = read("*")
|
local input = read("*")
|
||||||
pwHash = hash.digestStr(input .. os.getComputerID())
|
pwHash = hash.digestStr(input .. os.getComputerID())
|
||||||
return pwHash
|
return pwHash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function inputTimeout()
|
||||||
|
sleep(10)
|
||||||
|
eventTimeout = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local function inputPrompt()
|
||||||
|
write("Enter Password: ")
|
||||||
|
inputHash = hash.digestStr(read("*") .. os.getComputerID())
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function unlockDevice()
|
||||||
|
config = getConfig()
|
||||||
|
pwHash = config["pwHash"]
|
||||||
|
inputHash = ""
|
||||||
|
eventTimeout = false
|
||||||
|
|
||||||
|
while true do
|
||||||
|
parallel.waitForAny(inputTimeout, inputPrompt)
|
||||||
|
local pwCorrect = pwHash == inputHash
|
||||||
|
|
||||||
|
if pwCorrect then --correct input
|
||||||
|
config["locked"] = false
|
||||||
|
setConfig()
|
||||||
|
print("Unlocking.")
|
||||||
|
sleep(0.2)
|
||||||
|
elseif eventTimeout then --timeout
|
||||||
|
config["locked"] = true
|
||||||
|
setConfig()
|
||||||
|
print("Timeout...")
|
||||||
|
sleep(0.5)
|
||||||
|
os.reboot()
|
||||||
|
else --wrong input
|
||||||
|
config["locked"] = true
|
||||||
|
setConfig()
|
||||||
|
print("Wrong password...")
|
||||||
|
sleep(1)
|
||||||
|
print("Rebooting...")
|
||||||
|
sleep(1)
|
||||||
|
os.reboot()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shellRun()
|
||||||
|
shell.run("shell")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shellStopCheck()
|
||||||
|
parallel.waitForAny(shellStopTimer)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shellStopTimer()
|
||||||
|
while true do
|
||||||
|
if timer < 1 then
|
||||||
|
os.reboot()
|
||||||
|
end
|
||||||
|
timer = timer - 1
|
||||||
|
sleep(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shellStopKeyEvent()
|
||||||
|
eventName = nil
|
||||||
|
while true do
|
||||||
|
eventName, _ = os.pullEvent("key")
|
||||||
|
if eventName == "key" then
|
||||||
|
timer = config["keepUnlockedFor"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function main()
|
||||||
|
config = getConfig()
|
||||||
|
local timer = config["keepUnlockedFor"]
|
||||||
|
|
||||||
|
unlockDevice()
|
||||||
|
|
||||||
|
parallel.waitForAny(shellRun, shellStopCheck)
|
||||||
|
os.reboot()
|
||||||
|
end
|
||||||
|
|
||||||
|
main()
|
@ -26,16 +26,17 @@ oreList = {
|
|||||||
keepList = {
|
keepList = {
|
||||||
[0] = "computercraft:wireless_modem_advanced",
|
[0] = "computercraft:wireless_modem_advanced",
|
||||||
[1] = "minecraft:chest",
|
[1] = "minecraft:chest",
|
||||||
[2] = "minecraft:raw_gold",
|
[2] = "minecraft:barrel",
|
||||||
[3] = "minecraft:raw_iron",
|
[3] = "minecraft:raw_gold",
|
||||||
[4] = "minecraft:coal",
|
[4] = "minecraft:raw_iron",
|
||||||
[5] = "minecraft:lapis_lazuli",
|
[5] = "minecraft:coal",
|
||||||
[6] = "minecraft:diamond",
|
[6] = "minecraft:lapis_lazuli",
|
||||||
[7] = "minecraft:redstone",
|
[7] = "minecraft:diamond",
|
||||||
[8] = "minecraft:emerald",
|
[8] = "minecraft:redstone",
|
||||||
[9] = "minecraft:quartz",
|
[9] = "minecraft:emerald",
|
||||||
[10] = "minecraft:gold_nugget",
|
[10] = "minecraft:quartz",
|
||||||
[11] = "minecraft:ancient_debris",
|
[11] = "minecraft:gold_nugget",
|
||||||
|
[12] = "minecraft:ancient_debris",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,11 +77,11 @@ local function savePos(prefix)
|
|||||||
turtle.equipRight()
|
turtle.equipRight()
|
||||||
posZ, posY, posX = gps.locate()
|
posZ, posY, posX = gps.locate()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
if prefix == "Chest placed" then
|
if prefix == "Chest placed at" then
|
||||||
posY = posY + 1
|
posY = posY + 1
|
||||||
end
|
end
|
||||||
basic.appendToFileNl("/brulijam/files/chests-turtle-miner-fibo.txt", "[" .. prefix .. "] " .. posX .. ", " .. posY .. ", " .. posZ)
|
basic.appendToFileNl("/brulijam/files/chests-turtle-miner-fibo.txt", prefix .. posX .. ", " .. posY .. ", " .. posZ)
|
||||||
networking.sendLog("all", "/brulijam/logs/chests-to-collect.txt", "[" .. prefix .. "] " .. posX .. ", " .. posY .. ", " .. posZ)
|
networking.sendLog("all", "/brulijam/logs/chests-to-collect.txt", prefix .. posX .. ", " .. posY .. ", " .. posZ)
|
||||||
turtle.equipRight()
|
turtle.equipRight()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -99,7 +100,7 @@ local function inventoryRework()
|
|||||||
if itemDetail.name == "minecraft:coal" then
|
if itemDetail.name == "minecraft:coal" then
|
||||||
turtle.refuel()
|
turtle.refuel()
|
||||||
spaceAvailable = true
|
spaceAvailable = true
|
||||||
elseif itemDetail.name == "minecraft:chest" then
|
elseif itemDetail.name == "minecraft:chest" or itemDetail.name == "minecraft:barrel" then
|
||||||
chestAvailable = true
|
chestAvailable = true
|
||||||
chestSlot = i
|
chestSlot = i
|
||||||
else --check if item can be thrown away
|
else --check if item can be thrown away
|
||||||
@ -127,13 +128,13 @@ local function inventoryRework()
|
|||||||
basic.secureDigUp()
|
basic.secureDigUp()
|
||||||
turtle.select(chestSlot)
|
turtle.select(chestSlot)
|
||||||
turtle.placeUp()
|
turtle.placeUp()
|
||||||
savePos("Chest placed")
|
savePos("Chest placed at")
|
||||||
|
|
||||||
for k=1, 16 do
|
for k=1, 16 do
|
||||||
turtle.select(k)
|
turtle.select(k)
|
||||||
itemDetail = turtle.getItemDetail()
|
itemDetail = turtle.getItemDetail()
|
||||||
if itemDetail ~= nil then
|
if itemDetail ~= nil then
|
||||||
if itemDetail.name ~= "minecraft:chest" and itemDetail.name ~= "computercraft:wireless_modem_advanced" then
|
if (itemDetail.name ~= "minecraft:chest" or itemDetail.name ~= "minecraft:barrel") and itemDetail.name ~= "computercraft:wireless_modem_advanced" then
|
||||||
turtle.dropUp()
|
turtle.dropUp()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,8 +3,6 @@ local repo = "https://git.brulijam.com/brulijam/Computercraft/raw/branch/main/sr
|
|||||||
local labelPrefix = "SPHEAL"
|
local labelPrefix = "SPHEAL"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--fetch sync script
|
--fetch sync script
|
||||||
getRequest = http.get(repo .. "/brulijam/sync.lua")
|
getRequest = http.get(repo .. "/brulijam/sync.lua")
|
||||||
file = fs.open("/brulijam/sync.lua", "w")
|
file = fs.open("/brulijam/sync.lua", "w")
|
||||||
@ -33,6 +31,7 @@ if os.getComputerLabel() == nil then
|
|||||||
os.setComputerLabel(labelPrefix .. "-" .. labelMainPart)
|
os.setComputerLabel(labelPrefix .. "-" .. labelMainPart)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--shell.run("/brulijam/systemlock.lua")
|
--shell.run("/brulijam/systemlock.lua")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user