Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ping command:
- pcmd="Ping"
- --modem side:
- side="right"
- --ping timeout:
- timeout=0.2
- --ping-range:
- minid=10
- maxid=20
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function startup()
- i1=0
- trigger=true
- clear()
- print("Starting server...")
- rednet.open(side) --enable the modem attached to the right side of the PC
- sleep(0.1)
- print("0%")
- sleep(0.1)
- print("20%")
- sleep(0.1)
- print("37%")
- sleep(0.1)
- print("80%")
- sleep(0.1)
- print("95%")
- sleep(0.1)
- print("100%")
- sleep(0.2)
- clear()
- print("Server has started!")
- load()
- clear()
- ownid=os.getComputerID()
- end
- function ping()
- data={}
- for i=minid, maxid do
- rednet.send(i,pcmd)
- tmp, msg = rednet.receive(timeout)
- if msg==nil then
- msg=0
- print("Nothing on "..i.."!")
- else
- temp=tmp.." "..msg
- data[i1]=temp
- i1=i1+1
- print("Found something on "..i.."!")
- end
- end
- i1=0
- sleep(0.5)
- clear()
- end
- function output()
- for i=0, table.getn(data) do
- if data[i]==ownid.." "..pcmd then
- else
- print(data[i])
- end
- end
- end
- function refresh()
- clear()
- print("Saving data...")
- save()
- sleep(0.5)
- clear()
- print("Reconfiguring...")
- print("Please be patient!")
- sleep(0.5)
- ping()
- sleep(0.5)
- output()
- end
- function save()
- doc=fs.open("data", "w") --doc = fs.open(filename, mode(w))
- doc.writeLine(pcmd)
- doc.writeLine(side)
- doc.writeLine(timeout)
- doc.writeLine(minid)
- doc.writeLine(maxid)
- doc.close()
- end
- function load()
- doc=fs.open("data", "r")
- if doc==nil then
- else
- pcmd=doc.readLine()
- side=doc.readLine()
- timeout=tonumber(doc.readLine())
- minid=tonumber(doc.readLine())
- maxid=tonumber(doc.readLine())
- doc.close()
- end
- end
- function configure()
- clear()
- x,y=term.getSize()
- for i=0,x-1 do
- write("-")
- end
- print("Enter the new ping command!")
- print("Default: 'Ping'")
- print("Current: ".."'"..pcmd.."'")
- pcmd=read()
- print("Set to: "..pcmd)
- sleep(0.5)
- clear()
- for i=0,x-1 do
- write("-")
- end
- print("Enter the new modem side!")
- print("Default: 'right'")
- print("Current: ".."'"..side.."'")
- side=read()
- print("Set to: "..side)
- sleep(0.5)
- clear()
- for i=0,x-1 do
- write("-")
- end
- print("Enter the new timeout for the ping!")
- print("Default: '0.2'")
- print("Current: ".."'"..timeout.."'")
- timeout=tonumber(read())
- print("Set to: "..timeout)
- sleep(0.5)
- clear()
- for i=0,x-1 do
- write("-")
- end
- print("Enter the new min. ping range!")
- print("Default: '10'")
- print("Current: ".."'"..minid.."'")
- minid=tonumber(read())
- print("Set to: "..minid)
- sleep(0.5)
- clear()
- for i=0,x-1 do
- write("-")
- end
- print("Enter the new max. ping range!")
- print("Default: '20'")
- print("Current: ".."'"..maxid.."'")
- maxid=tonumber(read())
- print("Set to: "..maxid)
- sleep(0.5)
- refresh()
- end
- function main()
- load()
- clear()
- print("Listening for input...")
- event,param1=os.pullEvent("redstone")
- if trigger==false then
- trigger=true
- else
- trigger=false
- end
- if trigger==true then
- rednet.send(63,"open")
- rednet.send(64,"open")
- rednet.send(65,"open")
- clear()
- print("Command sent!")
- sleep(2)
- else
- rednet.send(63,"close")
- rednet.send(64,"close")
- rednet.send(65,"close")
- clear()
- print("Command sent!")
- sleep(2)
- end
- main()
- end
- startup()
- print("Getting connected ID's...")
- ping()
- main()
Advertisement
Add Comment
Please, Sign In to add comment