8 posts
Location
Germany
Posted 11 April 2013 - 06:57 AM
Hi,
I´m trying to make a login script.
The Code:
Login PC:Spoiler
print(" Login ")
print("=========")
sleep(1)
print(" ")
sleep(1)
print("Username: ")
sleep(1)
login = read()
sleep(1)
rednet.open("right")
rednet.send(3,login)
sleep(2)
x,y,z = rednet.receive()
if y == "wpw" then
print("Wrong Username")
sleep(1)
print("Restart")
sleep(2)
shell.run(clear)
shell.run(login)
else
sleep(1)
print("Password: ")
sleep(1)
pw = read()
if y == pw then
print("Access Granted!")
sleep(1)
print("Main menue following...")
else
print("Wrong password")
sleep(1)
print("Restart")
sleep(2)
shell.run(clear)
shell.run(login)
end
end
Database PC:Spoiler
rednet.open("right")
x,y,z = rednet.receive()
if y == ("user1") then
rednet.send(2,"12345")
shell.run(db)
end
if y == ("user2") then
rednet.send(2,"54321")
shell.run(db)
else
rednet.send(2,"wpw")
shell.run(db)
end
Problem is:
DB waits for message of Login PC(that´s still okay)
Login PC sends the username and DB gives following message:
shell :65: bad argument : string expected, got nil
How do i fix this?
mfg
Frostcup
695 posts
Location
In my basement.
Posted 11 April 2013 - 07:01 AM
Try shell.run("db")
758 posts
Location
Budapest, Hungary
Posted 11 April 2013 - 07:19 AM
Try shell.run("db")
Or to be a bit more precise, you have to give string(s) as parameter(s) to shell.run (in this case, "clear", "login" or "db"). If you give it just eg. clear, Lua will give it the value of "clear" variable, which is probably nil.
8 posts
Location
Germany
Posted 11 April 2013 - 07:37 AM
Try shell.run("db")
Or to be a bit more precise, you have to give string(s) as parameter(s) to shell.run (in this case, "clear", "login" or "db"). If you give it just eg. clear, Lua will give it the value of "clear" variable, which is probably nil.
Ok that helped
New Code:
Login PC:
Spoiler
print(" Login ")
print("=========")
sleep(1)
print(" ")
sleep(1)
print("Username: ")
sleep(1)
login = read()
sleep(1)
rednet.open("right")
rednet.send(3,login)
sleep(2)
x,y,z = rednet.receive()
if y == "wpw" then
print("Wrong Username")
sleep(1)
print("Restart")
sleep(2)
shell.run("clear")
shell.run("login")
else
sleep(1)
print("Password: ")
sleep(1)
pw = read()
if y == pw then
print("Access Granted!")
sleep(1)
print("Main menue following...")
else
print("Wrong password")
sleep(1)
print("Restart")
sleep(2)
shell.run("clear")
shell.run("login")
end
end
Database PC:
Spoiler
x,y,z = rednet.receive()
if y == ("user1") then
rednet.send(2,"12345")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
end
if y == ("user2") then
rednet.send(2,"54321")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
else
rednet.send(2,"wpw")
shell.run("db")
end
but it seems like the Database PC does not send the passwords, because the Login PC stops after sending the login name.
He stops. Like he is still waiting for the answer of the Database PC.
Any Logical errors in the code?
695 posts
Location
In my basement.
Posted 11 April 2013 - 07:47 AM
First of. Are The client computers id. 2 ?
Try with putting The rednet part in a loop using While true do .
758 posts
Location
Budapest, Hungary
Posted 11 April 2013 - 08:16 AM
end
if y == ("user2") then
should be
elseif y == ("user2") then
This way DB doesn't send back "wpw" (Wrong PassWord I assume?) if y is "user1". It sends back "wpw" now even if y is "user1", because then y sure ain't "user2".
Fix that first.
EDIT: Congrats, Mackan90096. Say yeah to every comment you see. Nice way to increase the post count. You see? Even I could manage to edit this post. Now this little comment doesn't increase my post count.
Yeah
(See the comment below)
695 posts
Location
In my basement.
Posted 11 April 2013 - 08:20 AM
Yeah
695 posts
Location
In my basement.
Posted 11 April 2013 - 08:35 AM
Yeah
end
if y == ("user2") then
should be
elseif y == ("user2") then
This way DB doesn't send back "wpw" (Wrong PassWord I assume?) if y is "user1". It sends back "wpw" now even if y is "user1", because then y sure ain't "user2".
Fix that first.
EDIT: Congrats, Mackan90096. Say yeah to every comment you see. Nice way to increase the post count. You see? Even I could manage to edit this post. Now this little comment doesn't increase my post count.
Yeah
(See the comment below)
Oh.. Sorry..
8 posts
Location
Germany
Posted 11 April 2013 - 08:42 AM
Like this?
Spoiler
x,y,z = rednet.receive()
if y == ("user1") then
rednet.send(2,"12345")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
elseif y == ("user2") then
rednet.send(2,"54321")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
else
rednet.send(2,"wpw")
shell.run("db")
end
758 posts
Location
Budapest, Hungary
Posted 11 April 2013 - 08:43 AM
-snip-
Yup. (Okay Mackan, I know, this is just a "yup", but this is necessary.)
8 posts
Location
Germany
Posted 11 April 2013 - 08:56 AM
ok, db prints the success message "pw has been send"
but it still seems that the client pc is not receiving anything
695 posts
Location
In my basement.
Posted 11 April 2013 - 09:13 AM
-snip-
Yup. (Okay Mackan, I know, this is just a "yup", but this is necessary.)
ok, db prints the success message "pw has been send"
but it still seems that the client pc is not receiving anything
No worries lbp..
Frost can you show The code for The db program?
8 posts
Location
Germany
Posted 11 April 2013 - 09:15 AM
Spoiler
x,y,z = rednet.receive()
if y == ("user1") then
rednet.send(2,"12345")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
elseif y == ("user2") then
rednet.send(2,"54321")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
else
rednet.send(2,"wpw")
shell.run("db")
end
695 posts
Location
In my basement.
Posted 11 April 2013 - 09:17 AM
Spoiler
x,y,z = rednet.receive()
if y == ("user1") then
rednet.send(2,"12345")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
elseif y == ("user2") then
rednet.send(2,"54321")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
else
rednet.send(2,"wpw")
shell.run("db")
end
So your'e running The program db from The program db?
52 posts
Posted 11 April 2013 - 09:32 AM
Im new to posting to forums so plz correct me if I need to fix anything but i think your problem is here:
shell.run(clear)
shell.run(login)
it needs to be:
shell.run("clear")
shell.run("login")
if that doesn't fix it plz tell me and again, Im new to posting so plz correct me on anything.
8 posts
Location
Germany
Posted 11 April 2013 - 09:37 AM
i Commented the code 4 u:
Client PC with Login Programm:Spoiler
print(" Login ")
print("=========")
sleep(1)
print(" ")
sleep(1)
print("Username: ")
sleep(1)
login = read() --you enter your username
sleep(1)
rednet.open("right") --open connection to the modem
rednet.send(3,login) --send the username to pc3(DB PC)
sleep(2)
x,y,z = rednet.receive() --waiting for the answer with the pw or wpw message
if y == "wpw" then --if wpw then start the programm again
print("Wrong Username")
sleep(1)
print("Restart")
sleep(2)
shell.run("clear")
shell.run("login")
else
sleep(1)
print("Password: ")
sleep(1)
pw = read() --user enters pw
if y == pw then --if the pw is equal to the pw send back by the DB access granted
print("Access Granted!")
sleep(1)
print("Main menue following...")
else --if its not equal start the programm again
print("Wrong password")
sleep(1)
print("Restart")
sleep(2)
shell.run("clear")
shell.run("login")
end
end
Server PC with the DB:Spoiler
rednet.open("right") --open connection to the modem
x,y,z = rednet.receive() --waiting for the entered username
if y == ("user1") then --if the username equals send back the pw
rednet.send(2,"12345")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db") --and start the db programm again to make it ready for the next query
elseif y == ("user2") then
rednet.send(2,"54321")
sleep(1)
print("pw has been send")
sleep(1)
shell.run("db")
else --if the username does not equal send wpw and start again for the next query
rednet.send(2,"wpw")
shell.run("db")
end
695 posts
Location
In my basement.
Posted 11 April 2013 - 09:43 AM
I'll help More in about 9-12 hours, need to sleep. LBPHacker or someone Else might help you during that time.
379 posts
Location
Hawaii
Posted 11 April 2013 - 03:11 PM
I'll help as soon as I get home.
Edit: Code for the client
http://pastebin.com/0923Vx5nI'll take a look at the server code soon
8 posts
Location
Germany
Posted 13 April 2013 - 03:14 AM
found the problem in the client code :)/>
login = read() --you enter your username
sleep(1)
rednet.open("right") --open connection to the modem
rednet.send(3, login) --send the username to pc3(DB PC)
sleep(2) <------ login is send and answer is sended back directly but receive starts 2 seconds after the client sends, so cause of this sleep the client does not get the answer from the database
x,y,z = rednet.receive() --waiting for the answer with the pw or wpw message
yust needed to remove the 2 seconds sleep :)/>
379 posts
Location
Hawaii
Posted 13 April 2013 - 10:48 PM
General rule of thumb: don't yield before attempting to capture events.