Advertisement
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
- 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()
- output()
- print("Please enter an ID: Own ID:"..ownid)
- id=read()
- id=tonumber(id)
- clear()
- output()
- print("Please enter a command: Own ID:"..ownid)
- cmd=read()
- clear()
- if cmd=="stop" and id==ownid then
- clear()
- print("Logging out...")
- rednet.close(side) --disable modem on the right side of the PC
- error()
- else
- if cmd=="settings" and id==ownid then
- configure()
- else
- if cmd=="refresh" and id==ownid then
- refresh()
- else
- if cmd=="stop" then
- rednet.send(id,cmd) --Send a message
- print("Command sent!")
- id,message = rednet.receive(timeout) --Wait until a message arrives or 0.2 seconds pass
- print("")
- print("Reply message:")
- print(message)
- sleep(2)
- clear()
- ping()
- else
- rednet.send(id,cmd) --Send a message
- print("Command sent!")
- id,message = rednet.receive(timeout) --Wait until a message arrives or 0.2 seconds pass
- print("")
- print("Reply message:")
- print(message)
- sleep(2)
- end
- end
- end
- end
- clear()
- main()
- end
- startup()
- print("Getting connected ID's...")
- ping()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement