- Install Redis: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis
- Install Webdis
- Start a minecraft server with computercraft. You will need to have the http API enabled, which is the default.
- Put down a turtle I recommend a turtle with a crafting square and a pickaxe. I also recommend giving it a label. If you’re not trying the turtle replication challenge, either disable fuel or get a fair bit of starting fuel. Write down the computer’s id.
- Put down a chunk loader, if you’re in a modpack that has them, or DON’T log out. Computers and turtles can’t operate unless the chunks are loaded. If you’re putting down a chunkloader, I surrounded them with bedrock for foolproofing.
- Open the turtle and download the following script, changing “redis.example.com” to your own redis instance: pastebin get 8FjggG9w startup
After you have the script saved as ‘startup’, run it or reboot the computer, and it should start listening for instructions.
123456789101112131415161718192021222324252627282930313233343536373839404142redis = "http://redis.example.com"queue = "sshbot" .. os.getComputerID()return_queue = queue .. "_return"print("Remote webdis queues on icyego: " .. queue .. " and " .. return_queue)print("Receiving remote commands.")function exec(str)print("Running: " .. str)f = fs.open("tmp", "w")f.write(str)f.close()p = loadfile("tmp")status, err = pcall(function () p = loadfile("tmp"); return p() end)if status thenstatus, ret = pcall(function() return textutils.serialize(err) end)if status thenresult = retelseresult = ""endelseresult = "Error: " .. errendprint(result)return resultendprint("Now receiving remote commands.")while true dohandle = http.get(redis .. "/BRPOP/" .. queue .. "/5.txt")if (handle and handle.getResponseCode() == 200) thenstr = handle.readAll()handle.close()str = string.sub(str, string.len(queue) + 1)result = exec(str)if string.find(result, "Error: ") thenresult2 = exec("return " .. str)if string.find(result2, "Error: ") then a=0 else result=result2 endendhttp.post(redis, "LPUSH/" .. return_queue .. "/" .. result)endend - On your local machine, save the following, again replacing “redis.example.com”:
1234567891011121314151617181920#!/bin/bashfunction send() {curl -s -X POST -d "LPUSH/sshbot${1}/${2}" "http://redis.example.com" >/dev/null}function get() {curl -s -X GET "http://redis.example.com/BRPOP/sshbot${1}_return/20.json" | jq .BRPOP[1]}if [ $# -ne 1 ]; thenecho "Usage: rlwrap ./sshbot <COMPUTER_ID>"exit 1fiID=$1while read LINE; dosend ${ID} "$LINE"get ${ID}done - Run: rlwrap ./sshbot <ID>, where <ID> is the turtle’s ID. You should be able to send commands to the computer now.
Controlling a computercraft turtle remotely
Tagged computercraft, hacks, minecraft. Bookmark the permalink.
Opening up ComputerCraft to the world using the http commands was an amazing idea from the developers!