Main Question:I want to write a centrel OC program, that acts as a central login for severel ComputerCraft controled Doors, similarly to this one, but on my own accord.
I achievd that only those Doors open, where I gave my password, but the problem is, that I can only do it in a specific order. First the first PC, then the second and the may use the first again.
Is there a way to make it possible to open the doors in any order?
Second minor question: I am using a light board from computertronics in my server Rack to see the status of the doors (change in color between green when idle and orange when opened). But because i am waiting for the client to tell me, that the door closed, i can't start a password request from my second pc. Is there a way to allow me to do this at the same time with one single program?
Third minor question:How do i have to right my code in the function, that the while loop makes the counting, so that I wouldn't need an additional if to break my loop.
Code:
CC-Client:
switch = peripheral.wrap("right")
while true do
term.clear() -- Read my password
term.setCursorPos(1,1)
print("Please enter Password:")
input = read("*")
input = textutils.serialise(input) -- Send password to server
switch.transmit(2001,1,input)
switch.open(2002) -- Get Answer whether or not the password was correct
local _,_,_,_,message = os.pullEvent("modem_message")
if message == "true" then -- If password is correct, open door
rs.setAnalogOutput("left",15)
sleep(2)
rs.setAnalogOutput("left",0)
switch.transmit(2003,1,textutils.serialise("closed")) -- Tell server that door has closed
end
end
OP-Server:
component = require("component")
event = require("event")
term = require("term")
serialization = require("serialization")
gpu = component.gpu
modem = component.modem
light = component.light_board
local password = "12345" -- My test password
function ColorSet (index,color) -- Set the color of the light board in the server rack
if index == 1 then -- Change color of the light board on the left side
while (true) do
light.setColor(index,color)
light.setActive(index,true)
index = index +1
if (index >= 6) then
break
end
end
else -- Change color on the right side
index = index +5
while (true) do
light.setColor(index,color)
light.setActive(index,true)
index = index +1
if (index >= 11) then
break
end
end
end
return true
end
ColorSet(1,0x33FF00) -- First initialization of lightboard
ColorSet(2,0x33FF00)
term.clear() -- Clear window and debug info
gpu.set(1,1,"No Requests known.")
gpu.set(1,4,"No Requests known.")
while true do
modem.open(2001) -- Get password from first computer
_,source1,_,_,_,signal1 = event.pull("modem_message")
modem.close(2001)
signal1 = serialization.unserialize(signal1)
gpu.set(1,1,"PC1 did send: "..signal1.." ")
--debug info about send password
if signal1 == password then
ColorSet(1,0xFF6600) -- Change color of light board
gpu.set(1,2,"Password accepted") -- debug info
modem.broadcast(2002,"true") -- tell client to open door
modem.open(2003) -- wait for closed door
_,_,_,_,_,close = event.pull("modem_message")
modem.close(2003)
ColorSet(1,0x33FF00) -- reset light board
else
gpu.set(1,2,"Password is wrong") -- debug info and message that password was wrong
modem.broadcast(2002,"false")
end
modem.open(3001)-- repetion from above to other PC (Light board not implemented in this part of the code)
_,source2,_,_,_,signal2 = event.pull("modem_message")
modem.close(3001)
signal2 = serialization.unserialize(signal2)
gpu.set(1,4,"PC2 did send: "..signal1.." ")
if signal2 == password then
gpu.set(1,5,"Password accepted")
modem.broadcast(3002,"true")
else
gpu.set(1,5,"Password is wrong")
modem.broadcast(3002,"false")
end
end
If there are any additionel question, I will try to answer them.
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Explenation:
Main Question: I want to write a centrel OC program, that acts as a central login for severel ComputerCraft controled Doors, similarly to this one, but on my own accord.
I achievd that only those Doors open, where I gave my password, but the problem is, that I can only do it in a specific order. First the first PC, then the second and the may use the first again.
Is there a way to make it possible to open the doors in any order?
Second minor question: I am using a light board from computertronics in my server Rack to see the status of the doors (change in color between green when idle and orange when opened). But because i am waiting for the client to tell me, that the door closed, i can't start a password request from my second pc. Is there a way to allow me to do this at the same time with one single program?
Third minor question: How do i have to right my code in the function, that the while loop makes the counting, so that I wouldn't need an additional if to break my loop.
Code:
CC-Client:
OP-Server:
If there are any additionel question, I will try to answer them.
Link to post
Share on other sites