Advertisement
EdgeLordKirito

Server 2

May 30th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. -- Valid commands
  2. -- line startHeight length
  3. --
  4.  
  5. function Main()
  6. rednet.open("back")
  7. os.setComputerLabel("Server")
  8. print("Please Enter the Ids of the Slaves seperated by a Space")
  9. SLAVES = NewGetSlaves()
  10. local fueltype = GetFuelType()
  11. --Sending
  12. MessageAllSlaves(fueltype)
  13. PrintSysMessage("Fueltype Send now Sleeping for 3 to let the Slaves Process")
  14. sleep(1)
  15. local command = GetCommand()
  16. MessageAllSlaves(command)
  17. sleep(3)
  18. --Sending closed
  19. while true do
  20. ReceiveReturnMessage()
  21. end
  22. PrintSysMessage("Programm has terminated with Code 0 " .. tostring(os.epoch("utc")))
  23. end
  24.  
  25.  
  26. function MySplit (inputstr, sep)
  27. if sep == nil then
  28. sep = "%s"
  29. end
  30. local t={}
  31. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  32. table.insert(t, str)
  33. end
  34. return t
  35. end
  36.  
  37. function GetFuelType()
  38. print("Enter the Type of Fuel available")
  39. local result = io.read()
  40. return result
  41. end
  42.  
  43. function EvaluateFuelType(input)
  44. if input == "minecraft:coal" or input == "minecraft:charcoal" then
  45. return 1
  46. else if input == "minecraft:coal_block" or input == "thermal:charcoal_block" then
  47. return 2
  48. end
  49. end
  50. end
  51.  
  52. function GetChestCoords()
  53. print("Please Enter the Coordinates of the Chest")
  54. return GetCoords()
  55. end
  56.  
  57. function GetFuelCoords()
  58. print("Please Enter the Coordinates of the Fuelhub")
  59. return GetCoords()
  60. end
  61.  
  62. function GetCommand()
  63. print("Please enter your Command")
  64. local command = io.read()
  65. return command
  66. end
  67.  
  68. function PrintAllSlaveIds()
  69. for i = 1, table.getn(SLAVES) do
  70. print(SLAVES[i])
  71. end
  72. end
  73.  
  74. function ReceiveReturnMessage()
  75. local id, message = rednet.receive()
  76. PrintSysMessage(("Computer %d sent message %s"):format(id, message))
  77. EvaluateResponse(message)
  78. end
  79.  
  80. function EvaluateResponse(input)
  81. local message = input
  82. MessageAllSlaves("Retreat")
  83. end
  84.  
  85. function GetCoords()
  86. local coords = io.read()
  87. local coordTable = MySplit(coords)
  88. local x,y,z = nil,nil,nil
  89. local resultstring = coordTable[1] .. " " .. coordTable[2] .. " " .. coordTable[3]
  90. x = tonumber(coordTable[1])
  91. y = tonumber(coordTable[2])
  92. z = tonumber(coordTable[3])
  93. return x,y,z, resultstring
  94. end
  95.  
  96. function GetSlaves()
  97. local listOfSlaves = {}
  98. local counter = 1
  99. local input = ""
  100. print("Please enter the Slave ComputerIDs: " .. tostring(os.epoch("utc")))
  101. while (not BreakOff(input)) do
  102. input = io.read()
  103. if BreakOff(input)
  104. then
  105. break
  106. end
  107. listOfSlaves[counter] = input
  108. counter = counter + 1
  109. end
  110. return listOfSlaves
  111. end
  112.  
  113. function NewGetSlaves()
  114. local listOfSlaves = {}
  115. local input = io.read()
  116. local inputList = MySplit(input)
  117. for i = 1, table.getn(inputList) do
  118. listOfSlaves[i] = (tonumber(inputList[i]))
  119. end
  120. return listOfSlaves
  121. end
  122.  
  123. function MessageAllSlaves( message)
  124. for i = 1, table.getn(SLAVES) do
  125. rednet.send(SLAVES[i],message)
  126. end
  127. end
  128.  
  129. function BreakOff(input)
  130. input = string.upper(input)
  131. if (input == "STOP")
  132. then
  133. return true
  134. else
  135. return false
  136. end
  137. end
  138.  
  139. function TakeUserInput()
  140. print("What do you want to Send? " .. tostring(os.epoch("utc")))
  141. print("Available commands are:")
  142. PrintStringInColor("Go",colors.green)
  143. PrintStringInColor("Terminate",colors.red)
  144. ResetTerminal()
  145. return io.read()
  146. end
  147.  
  148.  
  149.  
  150. function EvaluateUserInput(input)
  151. local command = string.upper(input)
  152. if (command == "GO")
  153. then
  154. if (COMMANDS[1] == true)
  155. then
  156. PrintSysMessage("The Go signal has already been send")
  157. return
  158. else
  159. MessageAllSlaves(SLAVES,"Go")
  160. COMMANDS[1] = true
  161. term.setTextColor(colors.green)
  162. PrintSysMessage("All Slaves have been notified to Go " .. tostring(os.epoch("utc")))
  163. return
  164. end
  165. end
  166.  
  167. if (command == "TERMINATE")
  168. then
  169. if (COMMANDS[2] == true)
  170. then
  171. PrintSysMessage("The Terminate signal has already been send")
  172. return
  173. else
  174. MessageAllSlaves(SLAVES,"Terminate")
  175. COMMANDS[2] = true
  176. term.setTextColor(colors.red)
  177. PrintSysMessage("All Slaves have been notified to Terminate " .. tostring(os.epoch("utc")))
  178. ACTIVE = false
  179. return
  180. end
  181. end
  182. end
  183.  
  184.  
  185.  
  186. function PrintStringInColor(string,color)
  187. term.setTextColor(color)
  188. print(string)
  189. ResetTerminal()
  190. end
  191.  
  192. function PrintSysMessage(string)
  193. PrintStringInColor(string,colors.magenta)
  194. end
  195.  
  196. function ResetTerminal()
  197. term.setTextColor(colors.white)
  198. end
  199.  
  200. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement