How to send a command over rednet to another computer and tell the 2nd computer to run the program and control it from the 1st computer
#1
Posted 12 May 2013 - 12:26 PM
#2
Posted 12 May 2013 - 12:43 PM
The server side would have some sort of GUI/Menu and send commands to the clients. The client itself would then have to listen for those messages, interpret them and call some of the client side functions (like in your case launch a missile or something) and maybe even give feedback to the master computer.
I guess most of the work you have ahead of you is developing some sort of simple protocol for the communication between your master and the slave computers.
I hope this answer wasn't to theoretical and it for sure wasn't a CC Pro reply... Anyway mabe this points you in the right direction...
#3
Posted 12 May 2013 - 01:02 PM
#4
Posted 12 May 2013 - 01:18 PM
C = '20' --replace with the computer id that is sending the command
while true do --So it will loop
id, cmd = rednet.receive()
if id == C then --So you it wont do anything unless the id matches
if cmd == 'Launch 1' then -- Customize the commands here... this is just an example
rs.setOutput('back', true) --Change the side to what ever side you want... if you don't know, this will set a redstone current, which you need when launching a missile (In ICBM)
sleep(0.1)
rs.setOutput('back', false)
end
end
end
#5
Posted 12 May 2013 - 04:18 PM
local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
local silos = {}
local argv = {...}
local selected = 1
local color = {"silver"}
for i,v in pairs(colors) do
if i ~= "combine" and i ~= "subtract" and i ~= "test" and i ~= "lightGray" then
table.insert(color, i)
end
end
print("Detecting silos...")
for i,side in ipairs(rs.getSides()) do
if argv[1] == "--debug" then
print("Checking: "..side)
end
if peripheral.getType(side) == "cable" then
if argv[1] == "--debug" then
print("Found a peripheral cable.")
end
for i2, color in ipairs(color) do
if argv[1] == "--debug" then
print("Checking: "..side..":"..color)
end
if peripheral.getType(side..":"..color) == "ICBMLauncher" then
print("Silo found on side:"..side..":"..color)
table.insert(silos, {side..":"..color, peripheral.wrap(side..":"..color)})
end
end
elseif peripheral.getType(side) == "ICBMLauncher" then
print("Silo found on side:"..side)
table.insert(silos, {side, peripheral.wrap(side)})
end
end
if #silos == 0 then
print("No silos detected.")
print("Please place a launcher control panel next to the computer.")
os.sleep(2)
return
elseif #silos == 1 then
print("Found 1 silo.")
else
print("Found "..#silos.." silos.")
end
os.sleep(0.75)
local function getPW()
if fs.exists("launchCode") then
term.clear()
term.setCursorPos(5, 8)
write("Please enter a launch code.")
local handle = fs.open("launchCode", "r")
local code = handle.readAll()
handle.close()
local userPW = read()
term.clear()
term.setCursorPos(1,1)
return (code == userPW)
else
return true
end
end
local function printColored(...)
for i=1, arg["n"] do
if type(arg[i]) == "string" then
write(arg[i])
elseif type(arg[i]) == "number" then
if term.isColor() then
term.setTextColor(arg[i])
end
end
end
print("")
term.setTextColor(colors.white)
end
local function doCountdown(length)
for i=length, 1, -1 do
term.clear()
term.setCursorPos(12,9)
write("Launching in: "..i.." seconds...")
term.setCursorPos(3,10)
write("Press any key (except escape) to abort launch.")
local timer = os.startTimer(1)
while true do
local event, id = os.pullEvent()
if event == "key" then
if id ~= 1 then
term.setCursorPos(17,11)
write("Aborting launch!")
os.sleep(0.5)
return false
end
elseif event == "timer" then
if id == timer then
break
end
end
end
end
return true
end
while true do
term.clear()
term.setCursorPos(1,1)
printColored(colors.white, "Silo ", colors.lime, tostring(selected), colors.white, " selected.")
print("")
print("Details: ")
print("")
printColored("Frequency: ", colors.lime, tostring(silos[selected][2].getFrequency()))
local targetX, targetY, targetZ = silos[selected][2].getTarget()
print("Targeted: ")
printColored("X: ", colors.lime, tostring(targetX))
printColored("Y: ", colors.lime, tostring(targetY))
printColored("Z: ", colors.lime, tostring(targetZ))
print("")
print("Options: ")
printColored("1. ", colors.lime, "Select Silo")
printColored("2. ", colors.orange, "Set Silo Target")
printColored("3. ", colors.orange, "Set Silo Frequency")
printColored("4. ", colors.red, "Launch")
printColored("5. ", colors.red, "Launch All")
printColored("6. ", colors.orange, "Set All Silo Frequencies")
printColored("7. ", colors.orange, "Set All Silo Targets")
local event, key = os.pullEvent("key")
if key == 2 then
term.clear()
term.setCursorPos(1,1)
print("Detected silos:")
for i,v in ipairs(silos) do
print(i..". Silo on: "..v[1].." side")
end
local x, y = term.getCursorPos()
while true do
term.setCursorPos(x,y)
term.clearLine()
write("Selection> ")
local data = tonumber(read())
if data then
if silos[data] then
selected = data
break
end
end
end
elseif key == 3 then
local x, y, z = 0
while true do
term.setCursorPos(1,7)
term.clearLine()
write("X: ")
local selX = read()
if tonumber(selX) then
x = tonumber(selX)
break
end
end
while true do
term.setCursorPos(1,8)
term.clearLine()
write("Y: ")
local selY = read()
if tonumber(selY) then
y = tonumber(selY)
break
end
end
while true do
term.setCursorPos(1,9)
term.clearLine()
write("Z: ")
local selZ = read()
if tonumber(selZ) then
z = tonumber(selZ)
break
end
end
silos[selected][2].setTarget(x,y,z)
elseif key == 4 then
while true do
term.setCursorPos(1,5)
term.clearLine()
write("Frequency: ")
local selFreq = read()
if tonumber(selFreq) then
silos[selected][2].setFrequency(tonumber(selFreq))
break
end
end
elseif key == 5 then
if getPW() then
if doCountdown(10) then
silos[selected][2].launch()
end
else
term.clear()
term.setCursorPos(12,9)
print("Incorrect code!")
os.sleep(2)
end
elseif key == 6 then
if getPW() then
if doCountdown(10) then
for i,v in ipairs(silos) do
v[2].launch()
os.sleep(3)
end
end
else
term.clear()
term.setCursorPos(12,9)
print("Incorrect code!")
os.sleep(2)
end
elseif key == 7 then
while true do
term.setCursorPos(1,5)
term.clearLine()
write("Frequency: ")
local selFreq = read()
if tonumber(selFreq) then
for i,v in ipairs(silos) do
v[2].setFrequency(tonumber(selFreq))
end
break
end
end
elseif key == 8 then
local x, y, z = 0
while true do
term.setCursorPos(1,7)
term.clearLine()
write("X: ")
local selX = read()
if tonumber(selX) then
x = tonumber(selX)
break
end
end
while true do
term.setCursorPos(1,8)
term.clearLine()
write("Y: ")
local selY = read()
if tonumber(selY) then
y = tonumber(selY)
break
end
end
while true do
term.setCursorPos(1,9)
term.clearLine()
write("Z: ")
local selZ = read()
if tonumber(selZ) then
z = tonumber(selZ)
break
end
end
for i,v in ipairs(silos) do
v[2].setTarget(x,y,z)
end
end
end
os.pullEvent = oldPull
#6
Posted 12 May 2013 - 05:23 PM
#7
Posted 12 May 2013 - 07:29 PM
(At least 2)
Edited by superanonymous, 12 May 2013 - 07:29 PM.
#8
Posted 12 May 2013 - 08:11 PM
#9
Posted 12 May 2013 - 11:50 PM
And you realize how easy rednet is right? Here's an example to send a user input over rednet, then having the receiving comp do something with it.
rednet.open('top') --This opens the top modem...
term.write('Code: ')
local cmd = read()
rednet.broadcast(cmd) --this will broadcast the message in all directions... any computer with rednet.receive() will get the command
--This will be the receiving comp... you CAN NOT use just one comp.
rednet.open('top') --Again... this opens the modem
cSender = '20' --Id of the sender, so it will ONLY use the command if the id matches..
id, cmd = rednet.receive()
if id == cSender then
--Do stuff here.
end
Rednet is simple... so it shouldn't be hard to make the program yourself.
#10
Posted 13 May 2013 - 12:41 AM
#11
Posted 13 May 2013 - 03:28 AM
rednet.open("right")
while true do
senderID, message, distance = rednet.receive()
print(message)
shell.run(message)
end
Sending computer/turtle
rednet.open("right")
rednet.send(1, "The program name on your receiving computer/turtle")
#12
Posted 13 May 2013 - 02:42 PM
#13
Posted 13 May 2013 - 05:13 PM
#14
Posted 13 May 2013 - 11:30 PM
pig101z, on 13 May 2013 - 05:13 PM, said:
--Sender
rednet.open('top') --Replace the side 'top' with the modem side...
rednet.broadcast(id,'missile_silo_control')
--ALL THE OTHER COMPS
rednet.open('top') --Same as 'Sender'
Control = '20' --REPLACE 20 WITH THE ID OF YOUR CONTROL COMP... THIS WILL INSURE PROTECTION
id, msg = rednet.receive()
if id == Control then
shell.run(msg)
end
#15
Posted 14 May 2013 - 09:00 AM
pig101z, on 14 May 2013 - 06:48 AM, said:
-- this marks the start of a code comment, it will only use one line. And can be at the end of a line of code.
I'm using rednet API in the program I made for you, you NEED two computers for this.
Take the code from line 2 - 3 and put it in your 'Control' Computer... were you will control the silos, exactly how you wanted.... I could add a GUI for you, but you didn't ask, so I didn't
Then take lines 6 - 11 and put it in your 'Silo' Computers, MAKE sure you have a rednet wireless modem the recipe is the enderpearl it used to be a redstone torch... not anymore though, UNLESS you are using computercraft below v.1.51, then the redstone torch WILL work.
If you want a nice GUI then just PM me, and I would be more than happy to make one.
#16
Posted 14 May 2013 - 09:38 AM
As to where you put this code, you need to put it in a program file. You can use the inbuilt edit program to do this, or you can edit your game files, in \world\computers\<computer ID>.
I've gone ahead and put your code in [code] tags, but I recommend using them yourself in the future. It really helps us identify the issues easier.
As a personal note, I also recommend proper punctuation. It really turns people off when you post an entire paragraph without a single comma or period. Run-on sentences are not fun to read.
Don't be a dick on these forums, and you will have a much more pleasant time. Happy hacking!
#17
Posted 14 May 2013 - 04:22 PM
#18
Posted 14 May 2013 - 10:41 PM
pig101z, on 14 May 2013 - 04:22 PM, said:
But on to topic, make sure to post exactly what happens, if you need further help, such as how to get the program to install on to your computers, just say, or if you are on a server, then I can always help you even better (I think you can get the point on what I mean).
#19
Posted 15 May 2013 - 03:06 PM
and how to do it
#20
Posted 15 May 2013 - 05:04 PM
pig101z, on 15 May 2013 - 03:06 PM, said:
and how to do it
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











