Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local id = os.getComputerID()
- local clientList = {}
- rednet.open("top")
- function save(name, data)
- local file = fs.open(name, "w")
- file.write(textutils.serialize(data))
- file.close()
- end
- function load(name)
- local file = fs.open(name, "r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- if fs.exists("clientlist") then
- clientList = load("clientlist")
- end
- while true do
- write("$ ")
- local commandText = read()
- local command = {}
- for word in commandText:gmatch("%S+") do
- table.insert(command, word)
- end
- if command[1] == "listen" then
- id, message = rednet.receive()
- if message == "me turtle, you server" then
- local newClient = true
- for k,v in pairs(clientList) do
- if id == v then
- newClient = false
- end
- end
- if newClient then
- table.insert(clientList, id)
- end
- save("clientlist", clientList)
- print("Client ID "..tostring(id).." connected")
- end
- elseif command[1] == "list" then
- for k,v in pairs(clientList) do
- print(tostring(k)..": "..tostring(v))
- end
- elseif command[1] == "id" then
- print(os.getComputerID())
- elseif command[1] == "exit" then
- return
- elseif command[1] == "help" then
- print("id: print server ID")
- print("listen: wait for new turtle to connect")
- print("list: list all connected clients")
- print("use [client ID] [command] to send command")
- print("send commands:")
- print("move home: move turtle to home")
- print("move [x] [y] [z]: move turtle to coordinate")
- print("mine [x1] [y1] [z1] [x2] [y2] [z2]: mine area")
- print("setposition [x] [y] [z]: reset internal coordinate")
- print("sethome: set current location as home")
- print("resume: resume interrupted mining")
- elseif tonumber(command[1]) ~= nil then
- local message = ""
- if command[2] == "move" then
- if command[3] == "home" then
- message = "move home"
- else
- message = "move "..command[3].." "..command[4].." "..command[5]
- end
- elseif command[2] == "mine" then
- message = "mine"
- for i = 3, 8 do
- message = message.." "..command[i]
- end
- elseif command[2] == "sethome" then
- message = "sethome"
- elseif command[2] == "resume" then
- message = "resume"
- elseif command[2] == "setposition" then
- message = "setposition "..command[3].." "..command[4].." "..command[5].." "..command[6]
- end
- rednet.send(tonumber(command[1]), message)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement