Posted 14 July 2012 - 11:22 PM
This my first API/utilities and lua scirpt ever! :)/>/>. I think there are others and better programms or API's for this, but anyway I thought I upload it! So here it is… :)/>/>
Feature:
- a receiver function with adjustable passcode/password to open/close a door on defined side
- "log" on the receiver screen
- adjustable PCinfo (a PCinfo.txt in /)to identify the receiver
- a Connection Terminal
- check the available status of all PC's using the receiver function
functions():
connect.receiver((string) modemside, (string) redstone-out, (int) loop, (int) usepassword, (string) password, (int) terminateable)
connect.terminal((string) modemside)
Code (litte bit disorderly ;)/>/> ) :
function receiver(redside,rsside1,loop,usepass,pass,terminate)
print("PC-ID: " .. os.computerID())
–Defaults
if redside == nil then
redside="top"
end
if rsside1 == nil then
rsside1="left"
end
if usepass == nil then
usepass = 0
end
if pass == nil then
pass="qwert"
end
if loop == nil then
loop=1
end
if terminate == 1 then
os.pullEvent = os.pullEventRaw
end
rednet.open(redside)
while true do
event, id, text = os.pullEvent()
if event == "rednet_message" then
print(id .. " >> " .. text)
end
if text == "open" then
print("> attempting to open")
if usepass == 1 then
rednet.send(id, "passcode")
ip, passcode = rednet.receive(10)
if passcode == pass then
redstone.setOutput(rsside1, true)
rednet.send(ip, "opened")
print("> opened")
elseif ip == id then
print("> Invalid passcode! Opening FAILED")
rednet.send(id, "ACESS DENIED!")
elseif ip == nil then
print("> timed out")
end
elseif usepass == 0 then
rednet.send(id, "no-passcode")
print("> opened")
redstone.setOutput(rsside1, true)
end
if loop == 0 then
break
end
end
if text == "close" then
print("> attempting to close")
if usepass == 1 then
rednet.send(id, "passcode")
ip, passcode = rednet.receive(10)
if passcode == pass then
redstone.setOutput(rsside1, false)
rednet.send(ip, "closed")
print("> closed")
else
print("> Invalid passcode! Closing FAILED!")
rednet.send(id, "ACESS DENIED!")
end
elseif usepass == 0 then
rednet.send(id, "no-passcode")
redstone.setOutput(rsside1, false)
print("> closed")
end
if loop == 0 then
break
end
end
if text == "status" then
rednet.send(id,"ready")
sleep(5)
end
if text == "info" then
file=io.open("PCinfo.txt", "r")
if file == nil then
rednet.send(id, "info")
rednet.send(id, "No PCinfo.txt on this PC")
else
info=file:read()
rednet.send(id, "info")
rednet.send(id, info)
print("> sended PCinfo")
file:close()
end
end
if text == "help" then
rednet.send(id, "nAvailable commands: open, close, info, statusnn'open': opens the door/set redstone ON on the predefined side (default left)n'close': close the door/set redstone OFF on predefined side (default left)n'info': sends the (first line of) PCinfo in /PCinfo.txt to the Terminaln'status': checks the status of this PCn")
end
end
end –RECEIVER
– TERMINAL
function terminal(redside2)
if redside2 == nil then
redside2="top"
end
print ("n–Connection Terminal–")
rednet.open(redside2)
while true do
print ("Type 'help' for help")
z = io.read()
–Start 'list'
if z == "list" then
rednet.broadcast("status")
print ("press a key to break")
for i=1,50 do
event, id, text = os.pullEvent()
if event == "key" then
break
end
if event == "rednet_message" then
print(id .. "> " .. text)
end
end
end
–End 'list'
–Start 'connect'
if z == "connect" then
print ("n–CONNECTING–n")
print ("To which PC?n(note some PC's require a Passcode!)")
pc=io.read()
print ("What should be done?")
act = io.read()
pc=tonumber(pc)
rednet.send(pc,act)
id, text = rednet.receive(2)
if text == "passcode" then
print ("passcode:")
p=read("*")
rednet.send(id, p)
end
if text == "info" then
id, info = rednet.receive(1)
print ("PCinfo:n" .. info)
end
print(text)
end
–end 'connect'
–start quit
if z == "quit" then
break
end
–end quit :P/>/>
–start help
if z == "help" then
print("nAvailable Commands: list, connect, quitnn'list': Checks the PC statusesn'connect': Connects to a PC (at Conecting type 'help' to get, if available, additional informations/commands)n'quit': Quits the program")
end
print ("n")
end –ENDE
end –TERMINALJust copy the file in the API Folder ;)/>/>
(and soory if my english is bad ;)/>/>)
Feature:
- a receiver function with adjustable passcode/password to open/close a door on defined side
- "log" on the receiver screen
- adjustable PCinfo (a PCinfo.txt in /)to identify the receiver
- a Connection Terminal
- check the available status of all PC's using the receiver function
functions():
connect.receiver((string) modemside, (string) redstone-out, (int) loop, (int) usepassword, (string) password, (int) terminateable)
connect.terminal((string) modemside)
Code (litte bit disorderly ;)/>/> ) :
Spoiler
– RECEIVERfunction receiver(redside,rsside1,loop,usepass,pass,terminate)
print("PC-ID: " .. os.computerID())
–Defaults
if redside == nil then
redside="top"
end
if rsside1 == nil then
rsside1="left"
end
if usepass == nil then
usepass = 0
end
if pass == nil then
pass="qwert"
end
if loop == nil then
loop=1
end
if terminate == 1 then
os.pullEvent = os.pullEventRaw
end
rednet.open(redside)
while true do
event, id, text = os.pullEvent()
if event == "rednet_message" then
print(id .. " >> " .. text)
end
if text == "open" then
print("> attempting to open")
if usepass == 1 then
rednet.send(id, "passcode")
ip, passcode = rednet.receive(10)
if passcode == pass then
redstone.setOutput(rsside1, true)
rednet.send(ip, "opened")
print("> opened")
elseif ip == id then
print("> Invalid passcode! Opening FAILED")
rednet.send(id, "ACESS DENIED!")
elseif ip == nil then
print("> timed out")
end
elseif usepass == 0 then
rednet.send(id, "no-passcode")
print("> opened")
redstone.setOutput(rsside1, true)
end
if loop == 0 then
break
end
end
if text == "close" then
print("> attempting to close")
if usepass == 1 then
rednet.send(id, "passcode")
ip, passcode = rednet.receive(10)
if passcode == pass then
redstone.setOutput(rsside1, false)
rednet.send(ip, "closed")
print("> closed")
else
print("> Invalid passcode! Closing FAILED!")
rednet.send(id, "ACESS DENIED!")
end
elseif usepass == 0 then
rednet.send(id, "no-passcode")
redstone.setOutput(rsside1, false)
print("> closed")
end
if loop == 0 then
break
end
end
if text == "status" then
rednet.send(id,"ready")
sleep(5)
end
if text == "info" then
file=io.open("PCinfo.txt", "r")
if file == nil then
rednet.send(id, "info")
rednet.send(id, "No PCinfo.txt on this PC")
else
info=file:read()
rednet.send(id, "info")
rednet.send(id, info)
print("> sended PCinfo")
file:close()
end
end
if text == "help" then
rednet.send(id, "nAvailable commands: open, close, info, statusnn'open': opens the door/set redstone ON on the predefined side (default left)n'close': close the door/set redstone OFF on predefined side (default left)n'info': sends the (first line of) PCinfo in /PCinfo.txt to the Terminaln'status': checks the status of this PCn")
end
end
end –RECEIVER
– TERMINAL
function terminal(redside2)
if redside2 == nil then
redside2="top"
end
print ("n–Connection Terminal–")
rednet.open(redside2)
while true do
print ("Type 'help' for help")
z = io.read()
–Start 'list'
if z == "list" then
rednet.broadcast("status")
print ("press a key to break")
for i=1,50 do
event, id, text = os.pullEvent()
if event == "key" then
break
end
if event == "rednet_message" then
print(id .. "> " .. text)
end
end
end
–End 'list'
–Start 'connect'
if z == "connect" then
print ("n–CONNECTING–n")
print ("To which PC?n(note some PC's require a Passcode!)")
pc=io.read()
print ("What should be done?")
act = io.read()
pc=tonumber(pc)
rednet.send(pc,act)
id, text = rednet.receive(2)
if text == "passcode" then
print ("passcode:")
p=read("*")
rednet.send(id, p)
end
if text == "info" then
id, info = rednet.receive(1)
print ("PCinfo:n" .. info)
end
print(text)
end
–end 'connect'
–start quit
if z == "quit" then
break
end
–end quit :P/>/>
–start help
if z == "help" then
print("nAvailable Commands: list, connect, quitnn'list': Checks the PC statusesn'connect': Connects to a PC (at Conecting type 'help' to get, if available, additional informations/commands)n'quit': Quits the program")
end
print ("n")
end –ENDE
end –TERMINAL
(and soory if my english is bad ;)/>/>)