This commit is contained in:
Julian Brammer 2024-06-08 20:35:45 +02:00
parent 2e9a644e37
commit 6757e1eb10
4 changed files with 117 additions and 26 deletions

View File

@ -48,10 +48,10 @@ function sendLog(to, targetPath, logMsg)
local payloadTable = {}
payloadTable[0] = targetPath
payloadTable[1] = basic.getCurrentTime() .. ": " .. logMsg
payloadTable[1] = "[" .. basic.getCurrentTime() .. "]: " .. logMsg
sendMessage(to, "log", payloadTable)
basic.ntfy(os.getComputerLabel() .. ": " .. payloadTable[1])
basic.ntfy("[" .. os.getComputerLabel() .. "] " .. payloadTable[1])
end
function sendFile(to, originPath, targetPath)

View File

@ -2,21 +2,112 @@ basic = require("lib.basic")
hash = require("lib.hash")
local pwHash = ""
local config = {}
local function setState()
basic.writeToFile("/brulijam/config/systemlock.config", asdasd)
local function setConfig()
basic.writeToFile("/brulijam/config/systemlock.config", textutils.serialize(config))
end
local function getState()
local function getConfig()
if not fs.exists "/brulijam/config/systemlock.config" then
config = {}
config["locked"] = true
config["pwHash"] = createPwHash()
config["keepUnlockedFor"] = 600
setConfig()
else
config = basic.readFileAll("brulijam/config/systemlock.config")
config = textutils.unserialize(config)
end
return config
end
local function createPwHash()
print("Create a new password: ")
write("Create a new password : ")
local input = read("*")
pwHash = hash.digestStr(input .. os.getComputerID())
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()

View File

@ -26,16 +26,17 @@ oreList = {
keepList = {
[0] = "computercraft:wireless_modem_advanced",
[1] = "minecraft:chest",
[2] = "minecraft:raw_gold",
[3] = "minecraft:raw_iron",
[4] = "minecraft:coal",
[5] = "minecraft:lapis_lazuli",
[6] = "minecraft:diamond",
[7] = "minecraft:redstone",
[8] = "minecraft:emerald",
[9] = "minecraft:quartz",
[10] = "minecraft:gold_nugget",
[11] = "minecraft:ancient_debris",
[2] = "minecraft:barrel",
[3] = "minecraft:raw_gold",
[4] = "minecraft:raw_iron",
[5] = "minecraft:coal",
[6] = "minecraft:lapis_lazuli",
[7] = "minecraft:diamond",
[8] = "minecraft:redstone",
[9] = "minecraft:emerald",
[10] = "minecraft:quartz",
[11] = "minecraft:gold_nugget",
[12] = "minecraft:ancient_debris",
}
@ -76,11 +77,11 @@ local function savePos(prefix)
turtle.equipRight()
posZ, posY, posX = gps.locate()
sleep(1)
if prefix == "Chest placed" then
if prefix == "Chest placed at" then
posY = posY + 1
end
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)
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)
turtle.equipRight()
end
end
@ -99,7 +100,7 @@ local function inventoryRework()
if itemDetail.name == "minecraft:coal" then
turtle.refuel()
spaceAvailable = true
elseif itemDetail.name == "minecraft:chest" then
elseif itemDetail.name == "minecraft:chest" or itemDetail.name == "minecraft:barrel" then
chestAvailable = true
chestSlot = i
else --check if item can be thrown away
@ -127,13 +128,13 @@ local function inventoryRework()
basic.secureDigUp()
turtle.select(chestSlot)
turtle.placeUp()
savePos("Chest placed")
savePos("Chest placed at")
for k=1, 16 do
turtle.select(k)
itemDetail = turtle.getItemDetail()
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()
end
end

View File

@ -3,8 +3,6 @@ local repo = "https://git.brulijam.com/brulijam/Computercraft/raw/branch/main/sr
local labelPrefix = "SPHEAL"
--fetch sync script
getRequest = http.get(repo .. "/brulijam/sync.lua")
file = fs.open("/brulijam/sync.lua", "w")
@ -33,6 +31,7 @@ if os.getComputerLabel() == nil then
os.setComputerLabel(labelPrefix .. "-" .. labelMainPart)
end
--shell.run("/brulijam/systemlock.lua")