Advertisement
Chaos_Cash

Connection sub test

Feb 7th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. function startup()
  2.  
  3. connected_pcs={}
  4.  
  5. rednet.open("top")
  6. connections=fs.open("connections","a")
  7. connections.close()
  8.  
  9.  
  10. if not fs.exists("connection_code") then
  11.  
  12. term.clear()
  13. term.setCursorPos(1,1)
  14. term.setTextColor(colors.green)
  15. print("Please enter the name you want to use to connect")
  16. print("to other PC´s")
  17. print()
  18. term.setTextColor(colors.white)
  19. connection_name=read()
  20.  
  21. connection_code=fs.open("connection_code","w")
  22. connection_code.writeLine(connection_name)
  23. connection_code.flush()
  24. connection_code.close()
  25.  
  26. end
  27.  
  28. assign_name()
  29.  
  30. assign_connections()
  31.  
  32.  
  33. if connected_pcs["name"][1]==nil then
  34.  
  35. term.clear()
  36. term.setCursorPos(1,1)
  37. term.setTextColor(colors.green)
  38. print("Please enter the name of the PC you want to")
  39. print("connect to")
  40. print()
  41. term.setTextColor(colors.white)
  42. connecting_to=read()
  43.  
  44. connections=fs.open("connections","w")
  45. connections.writeLine(connecting_to)
  46. connections.flush()
  47. connections.close()
  48.  
  49. end
  50.  
  51. for i=1,250 do
  52.  
  53. rednet.send(i,{["connecting_to"]=connecting_to,["name"]=connection_name})
  54.  
  55. end
  56.  
  57. assign_connections()
  58.  
  59. end
  60.  
  61.  
  62.  
  63.  
  64.  
  65. function pull()
  66.  
  67. while true do
  68.  
  69. info_1, info_2, info_3, info_4 = os.pullEvent()
  70.  
  71. if info_1=="rednet_message" and info_3["sending_to"]==connection_name then
  72.  
  73. if info_3["status"]=="on" then
  74.  
  75. redstone.setOutput("bottom",true)
  76. redstone.setOutput("top",true)
  77. redstone.setOutput("back",true)
  78. redstone.setOutput("front",true)
  79. redstone.setOutput("right",true)
  80. redstone.setOutput("left",true)
  81.  
  82. else
  83.  
  84. redstone.setOutput("bottom",false)
  85. redstone.setOutput("top",false)
  86. redstone.setOutput("back",false)
  87. redstone.setOutput("front",false)
  88. redstone.setOutput("right",false)
  89. redstone.setOutput("left",false)
  90.  
  91. end
  92.  
  93. end
  94.  
  95. end
  96. end
  97.  
  98.  
  99.  
  100. function assign_connections()
  101.  
  102. connections=fs.open("connections","r")
  103.  
  104. connected_pcs["name"]={}
  105. connected_pcs["len"]=0
  106. connected_pcs["id"]={}
  107. connected_pcs["id"][0]="0"
  108. i=0
  109. while tonumber(connected_pcs["id"][i])~=nil do
  110.  
  111. i=i+1
  112.  
  113. connected_pcs["name"][i] = connections.readLine()
  114. connected_pcs["id"][i] = connections.readLine()
  115.  
  116. if tonumber(connected_pcs["id"][i])~=nil then
  117. connected_pcs["len"]=connected_pcs["len"]+1
  118. end
  119.  
  120. end
  121. connections.close()
  122. end
  123.  
  124.  
  125.  
  126. function assign_name()
  127.  
  128. connection_code = fs.open("connection_code","r")
  129. connection_name = connection_code.readLine()
  130. connection_code.close()
  131.  
  132. end
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. startup()
  142. pull()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement