1
Fork 0

turtle init

This commit is contained in:
Andy Killorin 2023-12-16 17:02:54 -06:00
parent 6a48231f6d
commit 4a4fe37e8e
Signed by: ank
GPG key ID: B6241CA3B552BCA4

47
client/client.lua Normal file
View file

@ -0,0 +1,47 @@
ipaddr = "68.46.126.104:48228"
--ipaddr = "localhost:48228"
local idfile = fs.open("id", "r")
local id = nil
local command = nil
if not idfile then
local fuel = turtle.getFuelLevel()
local stdin = io.input()
print("Direction (North, South, East, West):")
local direction = stdin:read("l")
print("X:")
local x = tonumber(stdin:read("l"))
print("Y:")
local x = tonumber(stdin:read("l"))
print("Z:")
local x = tonumber(stdin:read("l"))
local y = tonumber(stdin:read("l"))
local z = tonumber(stdin:read("l"))
local info = {
fuel = fuel,
position = {x, y, z},
facing = direction,
}
-- TODO: get from boot floppy
local turtleinfo = http.post(
"http://" .. ipaddr .. "/turtle/new",
textutils.serializeJSON(info),
{ ["Content-Type"] = "application/json" }
)
local response = textutils.unserialiseJSON(turtleinfo.readAll())
idfile = fs.open("id", "w")
idfile.write(response.id)
idfile.close()
os.setComputerLabel(response.name)
id = response.id
command = response.command
else
id = idfile.readAll()
idfile.close()
end
print(command)