From 3a05db554c9ce64dfe933854fb22c7c26bcd9cd6 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sat, 16 Dec 2023 19:33:09 -0600 Subject: [PATCH] bootstrap from floppy --- client/client.lua | 44 ++++++++++++++++++++++++++++++++++++-------- server/src/main.rs | 7 +++++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/client/client.lua b/client/client.lua index a5e9dc7..a7749b5 100644 --- a/client/client.lua +++ b/client/client.lua @@ -1,4 +1,18 @@ +-- wget run http://68.46.126.104:48228/turtle/client.lua + local ipaddr = "68.46.126.104" + +if not ipaddr then + if fs.exists("/disk/ip") then + local ipfile = fs.open("/disk/ip") + ipaddr = ipfile.readAll() + ipfile.close() + else + print("enter server ip:") + ipaddr = read("l") + end +end + local port = "48228" local endpoint = "http://" .. ipaddr .. ":" .. port @@ -11,17 +25,18 @@ local backoff = 0; if not idfile then local fuel = turtle.getFuelLevel() - local stdin = io.input() + if fs.exists("/disk/pos") then + io.input("/disk/pos") + end + local startpos = io.input() print("Direction (North, South, East, West):") - local direction = stdin:read("l") + local direction = startpos:read("l") print("X:") - local x = tonumber(stdin:read("l")) + local x = tonumber(startpos:read("l")) print("Y:") - local x = tonumber(stdin:read("l")) + local y = tonumber(startpos:read("l")) print("Z:") - local x = tonumber(stdin:read("l")) - local y = tonumber(stdin:read("l")) - local z = tonumber(stdin:read("l")) + local z = tonumber(startpos:read("l")) local info = { fuel = fuel, @@ -60,13 +75,26 @@ repeat elseif command == "Right" then turtle.right() elseif command == "Update" then + args = {...} + if args[1] == "nested" then + -- no exec = stack overflow + break + 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() - os.reboot() + shell.run("startup", "nested") end local ahead = "minecraft:air" diff --git a/server/src/main.rs b/server/src/main.rs index 773930a..75ff12e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -115,7 +115,7 @@ async fn create_turtle( println!("turt {id}"); - Json(TurtleResponse {name: Name::from_num(id).to_str(), id, command: TurtleCommand::Wait}) + Json(TurtleResponse {name: Name::from_num(id).to_str(), id, command: TurtleCommand::Update}) } async fn command( @@ -125,9 +125,10 @@ async fn command( ) -> Json { let turtles = &state.read().await.turtles; println!("{id}"); + println!("above: {}, below: {}, ahead: {}", req.above, req.below, req.ahead); - Json(TurtleCommand::Update) + Json(TurtleCommand::Wait) } #[derive(Serialize, Deserialize)] @@ -152,6 +153,8 @@ struct TurtleUpdate { fuel: usize, /// Block name ahead: String, + above: String, + below: String, } #[derive(Serialize, Deserialize)]