This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Stevenseegal's profile picture

Remote Lock v. 1.0

Started by Stevenseegal, 10 August 2012 - 08:06 PM
Stevenseegal #1
Posted 10 August 2012 - 10:06 PM
As i searched the forums i could only find passwordlocks for the use with 1 computer of with 2 but the client has to emit the redstone signal.
This easily bypassed with the use of a disk.
I made a little doorlock script witch require 2 computers connected with a modem.
The client side only asks for a password en sends that to the server. The server will check if the password is correct and emit a redstone signal.
Fairly safe.

I do admit that i'm a noob scripter so if anyone has a better code feel free to add ;)/>/>


Client code
Spoiler


os.pullEvent = os.pullEventRaw
local server = 2 -- Here goes the server ID
local modemside = "back" -- Here goes the modem side

rednet.open(modemside)
while true do
  term.clear()
  term.setCursorPos(1, 1)
  print("Remote Lock v. 1.0 Client")
  print("Enter password:")
  local pass = read("*")
  rednet.send(server, pass)
  local id, access
  repeat
	id, access = rednet.receive()
  until id == server
  if access == "granted" then
	print("ACCESS GRANTED")
	sleep(5)
  else
	print("ACCESS  DENIED")
	sleep(5)
  end
end

Server code
Spoiler


os.pullEvent = os.pullEventRaw
local client = 3 --  Here goes the client id
local pass = "password" -- Here goes the password
local rsside = "left" -- Here goes the redstone output side
local rstime = "5" -- Here goes the time the redstone signal will stay on
local modemside = "back" -- Here goes the modem side

rednet.open(modemside)
term.clear()
term.setCursorPos(1, 1)
print("Remote Lock v. 1.0 Server")
while true do
  local id, receivedpass
  repeat
	id, receivedpass = rednet.receive()
  until id == client
  if receivedpass == pass then
	sleep(1)
	rednet.send(client, "granted")
	redstone.setOutput(rsside, true)
	sleep(rstime)
	redstone.setOutput(rsside, false)
	sleep(2)
  else
	sleep(1)
	rednet.send(client, "denied")
  end
end
odd_kid #2
Posted 11 August 2012 - 03:16 PM
do you have to have a separate server for each door?
Stevenseegal #3
Posted 11 August 2012 - 05:50 PM
If you mean you want to open the doors seperatly, with this little code yes. But i guess it can be made compatible with more redstone outputs and even a bundeled cable
masaki84 #4
Posted 30 August 2012 - 07:52 AM
I have a piston door setup I'm trying to use this with, And I have 2 clients on either side of the door and I have the server with a not gate in front of the signal to keep the pistons engaged until you enter the password. my issue is will this script allow for multiple clients accessing the server? i noticed the way the server accessed the specific client Id after I was done getting the program on each console. right now I just use 2 servers hooked to the same redstone output. both running the same program and password
Tiin57 #5
Posted 30 August 2012 - 12:19 PM
Masaki, I'll set something up for you when I get home.
masaki84 #6
Posted 30 August 2012 - 04:31 PM
awesome thanks :)/>/>
Mr. Fang #7
Posted 21 September 2012 - 06:13 PM
I really like this idea, I'm going to use it too! Thanx.