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

computer access server for lock doors

Started by G_Dog1985_, 28 March 2014 - 05:26 PM
G_Dog1985_ #1
Posted 28 March 2014 - 06:26 PM
hello, i came across this code from (https://sites.google...ft----lets-play) i would like to update for some of it to cc 1.6 were you can have it on diff networks and be able to used a pda if you want
and some diff options here the server code that I been using http://pastebin.com/HJmr5jes


local myid = os.computerID()
local doorList = { 23,24 }
local passwordForDoor = { "notch","minecraft" }
mon=peripheral.wrap("bottom")
print("Access Terminal")
rednet.open("back")

print("Computer id for Access Terminal is "..tostring(myid))
function findIndexForId(id)
   for i,v in ipairs(doorList) do
	  if id == v then
		 return i
	  end
   end
   return 0
end

--[[ for future implementation ]]--
function setPasswordForLock(id,password)
   local i = findIndexForId(id)
  
   if i == 0 then
	  return false
   end
  
   passwordForDoor[i] = password
   print("in setPasswordForLock"..id..password)
   return true
end
function checkPasswordForLock(id,password)
   local i = findIndexForId(id)
   if i == 0 then
	  return -1
   end
   if passwordForDoor[i] == password then
	  return 1
   else
	  return 0
   end
end
--[[ Not needed yet, for later when we allow remove password changes ]]-
function saveData()
  local myfile = io.open("/doorpw.dat","w")
  print(tostring(myfile))
  print("1")
  for i,pw in ipairs(passwordForDoor) do
	 myfile:write(pw)
  end
  print("4")
  myfile:close()
end

local isValid = 0
while true do
   local timeString = textutils.formatTime(os.time(),false)
   senderId, message, distance = rednet.receive()
	
   isValid = checkPasswordForLock(senderId, message)
   if isValid == -1 then
	  print("server "..senderId.." sent us a request but is not in our list")
   elseif isValid == 1 then
	  rednet.send(senderId, "Valid")
	  mon.scroll(1)
	  mon.setCursorPos(1,4)
	  mon.write("Access from "..senderId.." at "..timeString)
   else
	  rednet.send(senderId, "Not Valid")
	  mon.scroll(1)
	  mon.setCursorPos(1,4)
	  mon.write("Failure from "..senderId.." at "..timeString)
  end
end


i had some problem with it through it works with one door but when it try to do two door the the server computer saids it works but the second dorr dosed not open
(edit forgot the client side )

os.pullEvent = os.pullEventRaw
rednet.open("right")
local serverid = 13
local done = false
local myid = os.computerID()
while done == false do
term.clear()
term.setCursorPos(1,1)
write("Password:")
local password = read()
term.clear()
term.setCursorPos(1,1)
if password == "password" then
   done = true
else
rednet.send(13,password)
serverid,message,distance = rednet.receive(5)
if senderid == 13 then
if message == "Valid" then
print("Access Granted")
redstone.setOutput("left",true)
sleep(5)
redstone.setOutput("left",false)
	 end
   end
end
end
any help would be nice
Thanks
Edited on 28 March 2014 - 06:44 PM
Lyqyd #2
Posted 28 March 2014 - 06:27 PM
Moved to Ask a Pro.
Bomb Bloke #3
Posted 29 March 2014 - 12:28 AM
Does the computer attached to the problematic second door state "Access Granted", when the server says it "works"?
G_Dog1985_ #4
Posted 29 March 2014 - 07:45 AM
i mean by second door is a second computer and door i add the computer id in the server ad restart the server and the computer i went to first door/computer it works but when i go to the second door
the password show up like normal typye in the pass it said accees grant but the door fails to open
Bomb Bloke #5
Posted 29 March 2014 - 09:14 AM
If the second computer attached to the second door is stating "access granted", but the door connected to said computer isn't opening, then I'd be double-checking that connection.

Ensure that you're linking the door up to the correct side of the computer, for starters.
G_Dog1985_ #6
Posted 29 March 2014 - 10:11 AM
now client part not working grr