authorized digging
This commit is contained in:
parent
42eff1af2b
commit
96a8de6858
1 changed files with 152 additions and 59 deletions
|
|
@ -1,3 +1,38 @@
|
|||
local port = "48228"
|
||||
local endpoint = "http://" .. ipaddr .. ":" .. port
|
||||
|
||||
local function update(args)
|
||||
if args[1] == "nested" then
|
||||
-- no exec = stack overflow
|
||||
return false
|
||||
end
|
||||
local req = http.get(endpoint .. "/turtle/client.lua")
|
||||
if not req then
|
||||
os.reboot()
|
||||
end
|
||||
local update = req.readAll()
|
||||
req.close()
|
||||
fs.delete("startup-backup")
|
||||
if fs.exists("/startup") then
|
||||
-- pcall does not work with cc fs
|
||||
fs.move("startup", "startup-backup")
|
||||
end
|
||||
local startup = fs.open("startup", "w")
|
||||
startup.write(update)
|
||||
startup.close()
|
||||
shell.run("startup", "nested")
|
||||
return true
|
||||
end
|
||||
|
||||
local function cycle(func, n)
|
||||
for i = 1, n, 1 do
|
||||
if not func() then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if not ipaddr then
|
||||
if fs.exists("/disk/ip") then
|
||||
local ipfile = fs.open("/disk/ip")
|
||||
|
|
@ -9,10 +44,6 @@ if not ipaddr then
|
|||
end
|
||||
end
|
||||
|
||||
local port = "48228"
|
||||
|
||||
local endpoint = "http://" .. ipaddr .. ":" .. port
|
||||
|
||||
local idfile = fs.open("id", "r")
|
||||
|
||||
local id = nil
|
||||
|
|
@ -60,41 +91,54 @@ end
|
|||
|
||||
repeat
|
||||
print(command)
|
||||
local args = nil
|
||||
if type(command) == "table" then
|
||||
command, args = pairs(command)(command)
|
||||
end
|
||||
|
||||
local ret = nil
|
||||
|
||||
if command == "Wait" then
|
||||
sleep(5)
|
||||
sleep(args)
|
||||
elseif command == "Forward" then
|
||||
turtle.forward()
|
||||
ret = cycle(turtle.forward, args)
|
||||
elseif command == "Backward" then
|
||||
turtle.back()
|
||||
ret = cycle(turtle.back, args)
|
||||
elseif command == "Left" then
|
||||
turtle.turnLeft()
|
||||
ret = turtle.turnLeft()
|
||||
elseif command == "Right" then
|
||||
turtle.turnRight()
|
||||
ret = turtle.turnRight()
|
||||
elseif command == "Up" then
|
||||
turtle.up()
|
||||
ret = cycle(turtle.up, args)
|
||||
elseif command == "Down" then
|
||||
turtle.down()
|
||||
ret = cycle(turtle.down, args)
|
||||
elseif command == "Dig" then
|
||||
ret = turtle.dig()
|
||||
elseif command == "DigUp" then
|
||||
ret = turtle.digUp()
|
||||
elseif command == "DigDown" then
|
||||
ret = turtle.digDown()
|
||||
elseif command == "ItemInfo" then
|
||||
ret = { Item = turtle.getItemDetail(args) }
|
||||
elseif command == "Update" then
|
||||
args = {...}
|
||||
if args[1] == "nested" then
|
||||
-- no exec = stack overflow
|
||||
if not update({...}) then
|
||||
break
|
||||
end
|
||||
local req = http.get(endpoint .. "/turtle/client.lua")
|
||||
if not req then
|
||||
os.reboot()
|
||||
end
|
||||
|
||||
local ret_table = nil
|
||||
if type(ret) == "boolean" then
|
||||
if ret then
|
||||
ret_table = "Success"
|
||||
else
|
||||
ret_table = "Failure"
|
||||
end
|
||||
local update = req.readAll()
|
||||
req.close()
|
||||
fs.delete("startup-backup")
|
||||
if fs.exists("/startup") then
|
||||
-- pcall does not work with cc fs
|
||||
fs.move("startup", "startup-backup")
|
||||
end
|
||||
local startup = fs.open("startup", "w")
|
||||
startup.write(update)
|
||||
startup.close()
|
||||
shell.run("startup", "nested")
|
||||
else
|
||||
ret_table = ret
|
||||
end
|
||||
|
||||
if not ret_table then
|
||||
ret_table = "None"
|
||||
end
|
||||
|
||||
local ahead = "minecraft:air"
|
||||
|
|
@ -119,8 +163,10 @@ repeat
|
|||
fuel = turtle.getFuelLevel(),
|
||||
ahead = ahead,
|
||||
above = above,
|
||||
below = below
|
||||
below = below,
|
||||
ret = ret_table,
|
||||
}
|
||||
print(info.ret)
|
||||
|
||||
local rsp = http.post(
|
||||
endpoint .. "/turtle/" .. id .. "/update" ,
|
||||
|
|
|
|||
Loading…
Reference in a new issue