m3Zz

RRS

Mar 21st, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. --ping command:
  2. pcmd="Ping"
  3. --modem side:
  4. side="right"
  5. --ping timeout:
  6. timeout=0.2
  7. --ping-range:
  8. minid=10
  9. maxid=20
  10.  
  11. function clear()
  12.  term.clear()
  13.  term.setCursorPos(1,1)
  14. end
  15.  
  16. function startup()
  17.  i1=0
  18.  trigger=true
  19.  clear()
  20.  print("Starting server...")
  21.  rednet.open(side) --enable the modem attached to the right side of the PC
  22.  sleep(0.1)
  23.  print("0%")
  24.  sleep(0.1)
  25.  print("20%")
  26.  sleep(0.1)
  27.  print("37%")
  28.  sleep(0.1)
  29.  print("80%")
  30.  sleep(0.1)
  31.  print("95%")
  32.  sleep(0.1)
  33.  print("100%")
  34.  sleep(0.2)
  35.  clear()
  36.  print("Server has started!")
  37.  load()
  38.  clear()
  39.  ownid=os.getComputerID()
  40. end
  41.  
  42. function ping()
  43. data={}
  44. for i=minid, maxid do
  45.  rednet.send(i,pcmd)
  46.  tmp, msg = rednet.receive(timeout)
  47.  if msg==nil then
  48.   msg=0
  49.   print("Nothing on "..i.."!")
  50.  else
  51.   temp=tmp.." "..msg
  52.   data[i1]=temp
  53.   i1=i1+1
  54.   print("Found something on "..i.."!")
  55.  end
  56.  end
  57. i1=0
  58. sleep(0.5)
  59. clear()
  60. end
  61.  
  62. function output()
  63.  for i=0, table.getn(data) do
  64.  if data[i]==ownid.." "..pcmd then
  65.  
  66.  else
  67.   print(data[i])
  68.  end
  69. end
  70. end
  71.  
  72. function refresh()
  73.  clear()
  74.  print("Saving data...")
  75.  save()
  76.  sleep(0.5)
  77.  clear()
  78.  print("Reconfiguring...")
  79.  print("Please be patient!")
  80.  sleep(0.5)
  81.  ping()
  82.  sleep(0.5)
  83.  output()
  84. end
  85.  
  86. function save()
  87.  doc=fs.open("data", "w") --doc = fs.open(filename, mode(w))
  88.  doc.writeLine(pcmd)
  89.  doc.writeLine(side)
  90.  doc.writeLine(timeout)
  91.  doc.writeLine(minid)
  92.  doc.writeLine(maxid)
  93.  doc.close()
  94. end
  95.  
  96. function load()
  97.  doc=fs.open("data", "r")
  98.  if doc==nil then
  99.  
  100.  else
  101.   pcmd=doc.readLine()
  102.   side=doc.readLine()
  103.   timeout=tonumber(doc.readLine())
  104.   minid=tonumber(doc.readLine())
  105.   maxid=tonumber(doc.readLine())
  106.   doc.close()
  107.  end
  108. end
  109.  
  110. function configure()
  111. clear()
  112. x,y=term.getSize()
  113.  for i=0,x-1 do
  114.   write("-")
  115.  end
  116. print("Enter the new ping command!")
  117. print("Default: 'Ping'")
  118. print("Current: ".."'"..pcmd.."'")
  119. pcmd=read()
  120. print("Set to: "..pcmd)
  121. sleep(0.5)
  122. clear()
  123.  for i=0,x-1 do
  124.   write("-")
  125.  end
  126. print("Enter the new modem side!")
  127. print("Default: 'right'")
  128. print("Current: ".."'"..side.."'")
  129. side=read()
  130. print("Set to: "..side)
  131. sleep(0.5)
  132. clear()
  133.  for i=0,x-1 do
  134.   write("-")
  135.  end
  136. print("Enter the new timeout for the ping!")
  137. print("Default: '0.2'")
  138. print("Current: ".."'"..timeout.."'")
  139. timeout=tonumber(read())
  140. print("Set to: "..timeout)
  141. sleep(0.5)
  142. clear()
  143.  for i=0,x-1 do
  144.   write("-")
  145.  end
  146. print("Enter the new min. ping range!")
  147. print("Default: '10'")
  148. print("Current: ".."'"..minid.."'")
  149. minid=tonumber(read())
  150. print("Set to: "..minid)
  151. sleep(0.5)
  152. clear()
  153.  for i=0,x-1 do
  154.   write("-")
  155.  end
  156. print("Enter the new max. ping range!")
  157. print("Default: '20'")
  158. print("Current: ".."'"..maxid.."'")
  159. maxid=tonumber(read())
  160. print("Set to: "..maxid)
  161. sleep(0.5)
  162. refresh()
  163. end
  164.  
  165. function main()
  166. load()
  167. clear()
  168. print("Listening for input...")
  169. event,param1=os.pullEvent("redstone")
  170. if trigger==false then
  171.  trigger=true
  172. else
  173.  trigger=false
  174. end
  175. if trigger==true then
  176.  rednet.send(63,"open")
  177.  rednet.send(64,"open")
  178.  rednet.send(65,"open")
  179.  clear()
  180.  print("Command sent!")
  181.  sleep(2)
  182. else
  183.  rednet.send(63,"close")
  184.  rednet.send(64,"close")
  185.  rednet.send(65,"close")
  186.  clear()
  187.  print("Command sent!")
  188.  sleep(2)
  189. end
  190. main()
  191. end
  192.  
  193. startup()
  194. print("Getting connected ID's...")
  195. ping()
  196. main()
Advertisement
Add Comment
Please, Sign In to add comment