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

Rednet comparing issue

Started by jurre1996, 27 January 2013 - 08:58 AM
jurre1996 #1
Posted 27 January 2013 - 09:58 AM
Hello,

I'm trying to add some security to my Quarry frame Computer.

so I wrote this scrip for the Quarry computer:


rednet.close("top")
rednet.open("top")
print("Rednet Opened")
print("Waiting for joiner")
senderID, message, dis = rednet.receive()
rednet.send(senderID, "Welcome my name is GLADOS")
print("Announced myself to computer: "..senderID)
print("Starting Authorisation")
rednet.send(senderID, "1")
senderID, message, dis = rednet.receive(10)
print("SenderID="..senderID.." ,SenderCode="..message)
if senderID==message then
	print("login Script accepted"
	rednet.send(senderID, "Password Please:")
	rednet.receive(10)
  else
	rednet.send(senderID, "Login Script Failed, Unkown Computer!")
	print("DEBUG: Expected: "..senderID.."got: "..message..".")
end
sleep(10)
shell.run("monitor right clear")
shell.run("online")

and this is the code for the terminals trying to control the thing.


rednet.close("top")
rednet.open("top")
print("Looking for computers...")
sleep(2)
rednet.announce()
computerID = os.computerID()
print("I told the network that I'm "..computerID..".")
senderID, message, dis = rednet.receive()
print("Connected with: "..senderID..".")
print(message)
senderID, message, dis = rednet.receive(10)
if message == "1" then
  rednet.send(senderID,"computerID")
  print("Starting Authorisation")
end
senderID, message,dis = rednet.receive(10)
print(message)

I still haven't implemented a lot. but right now. One of the security things is that it will send a messages what has the same ID as the computer.
Then the quarry computer will check if the Message(ComputerID) = SenderID.
But for some reason it will always return false.

Could anyone help me?

regards jurre
Lyqyd #2
Posted 27 January 2013 - 10:00 AM
Split to new topic.
jurre1996 #3
Posted 27 January 2013 - 10:07 AM
Split to new topic.

Thanks :)/>
remiX #4
Posted 27 January 2013 - 10:09 AM
senderID is a number, where as message is a string so it will always return false as you stated.

Changing
if senderID==message then
to
 if senderID == tonumber(message) then
should work
jurre1996 #5
Posted 27 January 2013 - 11:40 AM
senderID is a number, where as message is a string so it will always return false as you stated.

Changing
if senderID==message then
to
 if senderID == tonumber(message) then
should work

Thank You, you saved the day :P/>
jurre1996 #6
Posted 27 January 2013 - 12:37 PM
New Question:


rednet.close("right")
rednet.open("right")
print("Rednet Opened")
print("Waiting for joiner")
senderID, message, dis = rednet.receive()
rednet.send(senderID, "Welcome my name is GLADOS")
print("Announced myself to computer: "..senderID)
print("Starting Authorisation")
rednet.send(senderID, "1")
senderID, message, dis = rednet.receive(10)
if senderID == tonumber(message) then
	rednet.send(senderID, "Enter Your Password To Gain Access to GLADOS:")
	print("login Script accepted")
	senderID, message, dis = rednet.receive(30)
	if message == "Yolo" then
	  print("Someone logged in using computer; "..senderID..". He is "..dis.." blocks away")
	   rednet.send(senderID, "2")
		 function run()
		   senderID, message, dis = rednet.receive()
		   shell.run(message)
		 end
		 run()
	  
	 else
	  shell.run("monitor top clear")
	  shell.run("monitor top online")
	end
  else
	rednet.send(senderID, "Login Script Failed, Unkown Computer!")
  
end
shell.run("monitor top clear")
shell.run("online")

Is there a way that if a error accures somewhere in the script that it will just reboot the computer?

Also It works great now, but only after Im logged in and ran 1 command, it doest go back to function run(), but I do call run() after end, how do I fix this?
remiX #7
Posted 27 January 2013 - 08:52 PM
Use an infinite loop (while true do)


rednet.close("right")
rednet.open("right")
while true do
print("Rednet Opened")
print("Waiting for joiner")
senderID, message, dis = rednet.receive()
rednet.send(senderID, "Welcome my name is GLADOS")
print("Announced myself to computer: "..senderID)
print("Starting Authorisation")
rednet.send(senderID, "1")
senderID, message, dis = rednet.receive(10)
if senderID == tonumber(message) then
        rednet.send(senderID, "Enter Your Password To Gain Access to GLADOS:")
        print("login Script accepted")
        senderID, message, dis = rednet.receive(30)
        if message == "Yolo" then
          print("Someone logged in using computer; "..senderID..". He is "..dis.." blocks away")
           rednet.send(senderID, "2")
                 function run()
                   senderID, message, dis = rednet.receive()
                   shell.run(message)
                 end
                 run()

         else
          shell.run("monitor top clear")
          shell.run("monitor top online")
        end
  else
        rednet.send(senderID, "Login Script Failed, Unkown Computer!")

end
shell.run("monitor top clear")
shell.run("online") -- what is this program?
end