Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sVersion = "1.4"
- local tPingmap = {}
- local sPass = "pass"
- local tAuthed = {}
- local sHelp
- local sHelpFallback = "LeoSat v"..sVersion
- local bGps = true
- local x,y,z
- local tArgs = {...}
- term.clear()
- term.setCursorPos(1,1)
- function table.find(s, tAble)
- for i=1, #tAble do
- if tAble[i] == s then
- return true
- end
- end
- return false
- end
- function table.removeKey(s, tAble)
- for k, v in ipairs(tAble) do
- if v == s then
- table.remove(k, tAble)
- return true
- end
- end
- return false
- end
- print("Initalizing LeoSat "..sVersion)
- -- Checks if help file exists, reads help information from it
- if fs.exists("./help") then
- file = fs.open("./help", "r")
- sHelp = file.readAll()
- file:close()
- else
- print("No help file found, using fallback.")
- end
- rednet.open("right")
- -- Checks if user disabled GPS host
- if tArgs[1] == "false" then
- bGps = false
- print("GPS host disabled.")
- -- Checks if the user provided valid coordinates
- elseif tArgs[1] ~= nil and tArgs[2] ~= nil and tonumber(tArgs[2]) <= 254 and tArgs[3] ~= nil then
- x = tonumber(tArgs[1])
- y = tonumber(tArgs[2])
- z = tonumber(tArgs[3])
- print("Valid location provided.")
- else
- -- Tries to get position autmatically
- print("None or invalid location provided, attempting to get location via GPS...")
- x, y, z = gps.locate(2)
- if x ~= nil then
- print("Position appears to be "..x..","..y..","..z)
- else
- print("Could not determine position, disabling GPS host.")
- bGps = false
- end
- end
- while true do
- id, msg, dist = rednet.receive()
- -- Ping command
- if msg:lower() == "ping" then
- if not bGps then
- rednet.send(id, "PONG")
- else
- rednet.send(id, textutils.serialize({x,y,z}))
- end
- print(id, " executed ping.")
- -- Help command
- elseif msg:lower() == "help" then
- if sHelp ~= nil then
- rednet.send(id, sHelp)
- else
- rednet.send(id, sHelpFallback)
- end
- print(id, " executed help.")
- -- Pingmap command
- elseif msg:lower() == "pingmap" then
- print(id, " executed pingmap.")
- rednet.broadcast("PING")
- os.startTimer(2)
- local i = 0
- while true do
- local event, p1, p2, p3 = os.pullEvent()
- if event == "timer" then
- break
- elseif event == "rednet_message" then
- i = i + 1
- tPingmap[p1] = {p2, p3}
- end
- end
- rednet.send(id, textutils.serialize(tPingmap))
- -- Login command
- elseif msg:lower():sub(1, 5) == "login" then
- if msg:sub(7) == sPass then
- table.insert(tAuthed, id)
- rednet.send(id, "Successfully logged in!")
- print(id, " logged in.")
- else
- rednet.send(id, "Login failed!")
- print(id, " failed to login.")
- end
- -- Logout command
- elseif msg:lower():sub(1, 6) == "logout" then
- if table.removeKey(id, tAuthed) then
- rednet.send(id, "Successfully logged out!")
- print(id, " logged out.")
- else
- rednet.send(id, "Not logged in!")
- print(id, " failed to logout.")
- end
- -- Down command
- elseif msg:lower() == "down" then
- if table.find(id, tAuthed) then
- rednet.send(id, "Moving down...")
- print(id, " executed down.")
- while turtle.down() do
- if turtle.getFuelLevel() == 0 then
- rednet.send(id, "Out of fuel!")
- print("Out of fuel!")
- end
- end
- rednet.send(id, "Arrived at ground level!")
- print("Arrived at ground level!")
- else
- rednet.send(id, "You are not permitted to execute this command!")
- print(id, " failed to execute down.")
- end
- -- Up command
- elseif msg:lower() == "up" then
- if table.find(id, tAuthed) then
- rednet.send(id, "Moving up...")
- print(id, " executed up.")
- if turtle.getFuelLevel() > 370 then
- while turtle.up() do
- end
- if y < 254 then
- for i=1, 254-y do
- turtle.down()
- end
- if not fs.exists("startup") then
- f = fs.open("startup", "w")
- f.write("shell.run(\"leosat\", ".."\""..x.."\""..", ".."\""..y.."\""..",".."\""..z.."\")")
- f.close()
- print("Created startup file.")
- end
- end
- rednet.send(id, "Arrived at level "..y.."!")
- print("Arrived at level "..y.."!")
- else
- rednet.send(id, "Not enough fuel left, please refuel!")
- print("Low fuel level!")
- end
- else
- rednet.send(id, "You are not permitted to execute this command!")
- print(id, " failed to execute up.")
- end
- -- Reboot command
- elseif msg:lower() == "reboot" then
- if table.find(id, tAuthed) then
- rednet.send(id, "Rebooting...")
- shell.run("reboot")
- else
- rednet.send(id, "You are not permitted to execute this command!")
- print(id, " failed to execute up.")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement