As I don't have the mod there will be some psudo-code mostly where the program interacts with the peripheral.
The code I'm giving uses a version of the rednet API which was added with CC 1.6 If you have an older version of ComputerCraft installed then my example will not run. It should also be noted that I haven't tested this code and that I haven't used the protocol part of rednet very much, even when running the correct version of CC it may not work.
Master/Server/Controller
--# server/master/controller
--# User config section
local hostName = "Andrew2060_Silo_System"
local protocolName = "Lupus590_Silo_Demo"
--# End of user config section
rednet.host(protocolName, hostName)
local silo = {}
local function printSiloInfo()
if silo[1] then
textutils.pagedTabulate({"ID", "Type", "Armed"}, unpack(silo))
else print("No connected slaves") end
end
local function listenForSilos()
while true do
local message = {rednet.recive()}
if message[3] == protocolName then
--# message is expected protocol, continue
silo[#silo+1] = message[2]
end
end
end
local function fire(ID)
if silo[ID][3] then
rednet.send(silo[ID][1],"fire", protocolName )
else print("Silo not armed, can't fire while not armed") end
end
local function arm(ID)
silo[ID][3] = "true"
rednet.send(silo[ID][1],"arm", protocolName )
end
local function disarm(ID)
silo[ID][3] = "false"
rednet.send(silo[ID][1],"disarm", protocolName )
end
local function main()
local command = read()
--# string manipulation is something I have never done before, so I will leave this to better people
end
parallel.waitForAny(listenForSilos, main)
[namedspoiler='Slave/Silo][code]–# slave/silo
–# User config section
local hostName = "Andrew2060_Silo_System" –# must match master variable
local protocolName = "Lupus590_Silo_Demo" –# must match master variable
–# End of user config section
local silo = peripheral.find("ICBM_Silo") –# you may need to change this
if not silo then error("can't find silo") end
–# peripheral dummy functions (because I don't have the mod)
local function silo.getMissileType()
–# interigate the silo
end
local function silo.geteArmStatus()
–# interigate the silo
end
local function silo.setArmState(newState)
–# peripheral stuff
end
local function silo.fire()
–# peripheral stuff
end
–# end of peripheral dummy functions
local masterServer = rednet.lookup(protocolName, hostName)
if not masterServer then error("can't find master server") end
local function getSiloState()
return {os.getComputerID, silo.getMissileType(), tostring(silo.getMissileArmStatus())}
end
rednet.send(masterServer, getSiloState(), protocolName) –# send first message so that the master server knows about this silo
while true do
local message = {rednet.recive()}
if message[3] == protocolName then
–# message is expected protocol, continue
if message[1] == masterServer then
–# the message if from our master server, continue
if message[2] == "arm" then silo.setArmState(true)
elseif message[2] == "disarm" then silo.setArmState(false)
elseif message[2] == "fire" then silo.fire()
else –# bad message, ignore
end
end
end
end