Bizzycola 1 Posted April 30, 2014 Share Posted April 30, 2014 If you don't have ICBM Component: http://oc.cil.li/index.php?/topic/64-mc-164oc-12icbm-component/ I created a server and client recently for my own ICBM use. It may not be perfect but it stores waypoints and can even open a silo door(well, it outputs redstone) Here is the server, you may want to remove the thing that requires redstone output to fire: -- explode(seperator, string) function explode(d,p) local t, ll t={} ll=0 if(#p == 1) then return {p} end while true do l=string.find(p,d,ll,true) -- find the next d in the string if l~=nil then -- if "not not" found then.. table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array. ll=l+1 -- save just after where we found it for searching next time. else table.insert(t, string.sub(p,ll)) -- Save what's left in our array. break -- Break at end, as it should be, according to the lua manual. end end return t end local sides = require("sides") local event = require("event") local component = require("component") local icbm = component.icbm_bridge local modem = component.modem local rs = component.redstone modem.open(284) io.write("Listening..\n") while true do local scc, _, from, port, _, message = event.pull(3, "modem_message") if port == 284 then local tbl = explode("::", message) if #tbl > 0 then local cmd = tbl[1] if cmd == "launch" then if not icbm.isConnected() then modem.send(from, port, "Server not connected to launcher bridge.") elseif not icbm.canLaunch() then modem.send(from, port, "Failed to launch: "..icbm.getStatus()) elseif rs.getOutput(sides.top) > 0 then modem.send(from, port, "The silo door is closed.") else local x,y,z = icbm.getTarget() io.write("Missile fired at: "..x..", "..y..", "..z..".\n") icbm.launch() modem.send(from, port, "launch::success") end elseif cmd == "setcoords" then if #tbl < 4 then modem.send(from, port, "Invalid arguments. Usage: setcoords::x,y,z") else if not icbm.isConnected() then modem.send(from, port, "Server not connected to launcher bridge.") else --io.write("Setting target: "..tbl[2].."::"..tbl[3].."::"..tbl[4]..".\n") tbl[2] = string.gsub(tbl[2], "%:", "") tbl[3] = string.gsub(tbl[3], "%:", "") tbl[4] = string.gsub(tbl[4], "%:", "") io.write("Setting target: "..tonumber(tbl[2])..", "..tonumber(tbl[3])..", "..tonumber(tbl[4])..".\n") icbm.setTarget(tonumber(tbl[2]), tonumber(tbl[3]), tonumber(tbl[4])) modem.send(from, port, "setcoords::success") end end elseif cmd == "opendoor" then rs.setOutput(sides.top, 0) modem.send(from, port, "opendoor::success") elseif cmd == "closedoor" then rs.setOutput(sides.top, 255) modem.send(from, port, "closedoor::success") else modem.send(from, port, "Invalid command: "..tbl[1]) end else modem.send(from, port, "No command sent.") end end end Here is the client, you may want to make these more secure too. Change the variable at the top to point to the location you want your marker file to be stored. -- explode(seperator, string) function explode(d,p) local t, ll t={} ll=0 if(#p == 1) then return {p} end while true do l=string.find(p,d,ll,true) -- find the next d in the string if l~=nil then -- if "not not" found then.. table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array. ll=l+1 -- save just after where we found it for searching next time. else table.insert(t, string.sub(p,ll)) -- Save what's left in our array. break -- Break at end, as it should be, according to the lua manual. end end return t end local args = {...} local markerFile = "/mnt/d79/icbm_markers.dat" local serial = require("serialization") local event = require("event") local fs = require("filesystem") local component = require("component") local modem = component.modem modem.open(284) local markers = {} if fs.exists(markerFile) then local fll = io.open(markerFile, "r") local data = fll:read(fs.size(markerFile)) markers = serial.unserialize(data) fll:close() end function launch() print("Launching..") local sent = modem.broadcast(284, "launch::") if not sent then print("Launch failed: failed to send required network message(unknown error occured).") else local scc, _, from, port, _, message = event.pull(3, "modem_message") if not scc then print("Launch inconclusive: The message was sent but the server failed to respond, the missile may or may not have been sent(timeout occured).") else if message == "launch::success" then print("Launch Success: The server has reported that the ICBM has been launched successfully!") else print("Launch Error: "..message) end end end end function openDoor() print("Opening silo...") local sent = modem.broadcast(284, "opendoor::") if not sent then print("Operation failed: failed to send required network message(unknown error occured).") else local scc, _, from, port, _, message = event.pull(3, "modem_message") if not scc then print("Operatin inconclusive: The message was sent but the server failed to respond, the missile may or may not have been sent(timeout occured).\nThis means the door may not have opened. DO NOT LAUNCH.") else if message == "opendoor::success" then print("Door has been opened!") else print("Operation Error: "..message) end end end end function closeDoor() print("Closing silo...") local sent = modem.broadcast(284, "opendoor::") if not sent then print("Operation failed: failed to send required network message(unknown error occured).") else local scc, _, from, port, _, message = event.pull(3, "modem_message") if not scc then print("Operatin inconclusive: The message was sent but the server failed to respond, the missile may or may not have been sent(timeout occured).") else if message == "closedoor::success" then print("Silo has been closed!") else print("Operation Error: "..message) end end end end function setcoords(x,y,z) print("Setting launcher Coordinates("..x..","..y..","..z..")..") local sent = modem.broadcast(284, "setcoords::"..x.."::"..y.."::"..z) if not sent then print("Set Coords Error: The message couldnt't be sent(unknown network error)") else local scc, _, from, port, _, message = event.pull(3, "modem_message") if not scc then print("Set Coords Inconclusive: The network message was sent but the server did not respond(maybe it isn't running?).") else if message == "setcoords::success" then print("The server says the launcher coords were set successfully!") else print("Set Coords Error: "..message) end end end end function createMarker(args) if #args < 5 then print("usage: icbm createmarker [name] [x] [y] [z]") else markers[args[2]] = args[3]..","..args[4]..","..args[5] print("Saved marker '"..args[2].."' ("..args[3]..","..args[4]..","..args[5]..").") end end function listMarkers(markers) for k,v in pairs(markers) do print(k, v) end end function setMarker(args) if #args < 2 then print("Usage: icbm setmarker [name]") else if not markers[args[2]] then print("No marker with that name could be found("..args[2]..")") else local tbl = explode(",", markers[args[2]]) setcoords(tbl[1],tbl[2],tbl[3]) end end end if #args < 1 then print("Usage: icbm [command] (try help)") else if args[1] == "help" then print("Commands:\nlaunch (Launches the ICBM)") print("setcoords [x] [y] [z] (Set the ICBM launcher coords)") print("createmarker [name] [x] [y] [z] (Creates a marker with the specified name and coords)") print("setmarker [name] (Sets the ICBM launcher to the coords stored in the marker with the specified name)") prin("opensilo (opens the missile silo)") prin("closesilo (closes the missile silo)") elseif args[1] == "launch" then launch() elseif args[1] == "setcoords" then if #args < 4 then print("Usage: icbm setcoords [x] [y] [z]") else setcoords(args) end elseif args[1] == "createmarker" then createMarker(args) elseif args[1] == "setmarker" then setMarker(args) elseif args[1] == "listmarkers" then listMarkers(markers) elseif args[1] == "opensilo" then openDoor() elseif args[1] == "closesilo" then closeDoor() else print("Unknown Command.\nUsage: icbm [command] (try help)") end end local fl = io.open(markerFile, "w") fl:write(serial.serialize(markers)) fl:close() Quote Link to post Share on other sites