Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Valid commands
- -- line startHeight length
- --
- function Main()
- rednet.open("back")
- os.setComputerLabel("Server")
- print("Please Enter the Ids of the Slaves seperated by a Space")
- SLAVES = NewGetSlaves()
- local fueltype = GetFuelType()
- --Sending
- MessageAllSlaves(fueltype)
- PrintSysMessage("Fueltype Send now Sleeping for 3 to let the Slaves Process")
- sleep(1)
- local command = GetCommand()
- MessageAllSlaves(command)
- sleep(3)
- --Sending closed
- while true do
- ReceiveReturnMessage()
- end
- PrintSysMessage("Programm has terminated with Code 0 " .. tostring(os.epoch("utc")))
- end
- function MySplit (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function GetFuelType()
- print("Enter the Type of Fuel available")
- local result = io.read()
- return result
- end
- function EvaluateFuelType(input)
- if input == "minecraft:coal" or input == "minecraft:charcoal" then
- return 1
- else if input == "minecraft:coal_block" or input == "thermal:charcoal_block" then
- return 2
- end
- end
- end
- function GetChestCoords()
- print("Please Enter the Coordinates of the Chest")
- return GetCoords()
- end
- function GetFuelCoords()
- print("Please Enter the Coordinates of the Fuelhub")
- return GetCoords()
- end
- function GetCommand()
- print("Please enter your Command")
- local command = io.read()
- return command
- end
- function PrintAllSlaveIds()
- for i = 1, table.getn(SLAVES) do
- print(SLAVES[i])
- end
- end
- function ReceiveReturnMessage()
- local id, message = rednet.receive()
- PrintSysMessage(("Computer %d sent message %s"):format(id, message))
- EvaluateResponse(message)
- end
- function EvaluateResponse(input)
- local message = input
- MessageAllSlaves("Retreat")
- end
- function GetCoords()
- local coords = io.read()
- local coordTable = MySplit(coords)
- local x,y,z = nil,nil,nil
- local resultstring = coordTable[1] .. " " .. coordTable[2] .. " " .. coordTable[3]
- x = tonumber(coordTable[1])
- y = tonumber(coordTable[2])
- z = tonumber(coordTable[3])
- return x,y,z, resultstring
- end
- function GetSlaves()
- local listOfSlaves = {}
- local counter = 1
- local input = ""
- print("Please enter the Slave ComputerIDs: " .. tostring(os.epoch("utc")))
- while (not BreakOff(input)) do
- input = io.read()
- if BreakOff(input)
- then
- break
- end
- listOfSlaves[counter] = input
- counter = counter + 1
- end
- return listOfSlaves
- end
- function NewGetSlaves()
- local listOfSlaves = {}
- local input = io.read()
- local inputList = MySplit(input)
- for i = 1, table.getn(inputList) do
- listOfSlaves[i] = (tonumber(inputList[i]))
- end
- return listOfSlaves
- end
- function MessageAllSlaves( message)
- for i = 1, table.getn(SLAVES) do
- rednet.send(SLAVES[i],message)
- end
- end
- function BreakOff(input)
- input = string.upper(input)
- if (input == "STOP")
- then
- return true
- else
- return false
- end
- end
- function TakeUserInput()
- print("What do you want to Send? " .. tostring(os.epoch("utc")))
- print("Available commands are:")
- PrintStringInColor("Go",colors.green)
- PrintStringInColor("Terminate",colors.red)
- ResetTerminal()
- return io.read()
- end
- function EvaluateUserInput(input)
- local command = string.upper(input)
- if (command == "GO")
- then
- if (COMMANDS[1] == true)
- then
- PrintSysMessage("The Go signal has already been send")
- return
- else
- MessageAllSlaves(SLAVES,"Go")
- COMMANDS[1] = true
- term.setTextColor(colors.green)
- PrintSysMessage("All Slaves have been notified to Go " .. tostring(os.epoch("utc")))
- return
- end
- end
- if (command == "TERMINATE")
- then
- if (COMMANDS[2] == true)
- then
- PrintSysMessage("The Terminate signal has already been send")
- return
- else
- MessageAllSlaves(SLAVES,"Terminate")
- COMMANDS[2] = true
- term.setTextColor(colors.red)
- PrintSysMessage("All Slaves have been notified to Terminate " .. tostring(os.epoch("utc")))
- ACTIVE = false
- return
- end
- end
- end
- function PrintStringInColor(string,color)
- term.setTextColor(color)
- print(string)
- ResetTerminal()
- end
- function PrintSysMessage(string)
- PrintStringInColor(string,colors.magenta)
- end
- function ResetTerminal()
- term.setTextColor(colors.white)
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement