[1.3] Door Lock with Server
Kolpa 24 Mar 2012
so this program is parted into a server and the door client
Client:
Server:
ps: @Espen if u wanna improve have fun ^^
Client:
Spoiler
Server:
Spoiler
ps: @Espen if u wanna improve have fun ^^
Espen 24 Mar 2012
Alright Kolpa, as requested (kinda^^) I took a look at it and rewrote some stuff. I tried to leave the original code as much as possible.
I moved the password check to the server though. Because checking valid credentials should always happen server-side, or else someone could just rewrite their client to ignore the password-check.^^
Other smaller changes include setting locals wherever I could, removing redundant table accesses (os & io), etc.
If you have any questions about something in the code, don't hesitate to ask.
K, hope it's of any use, here goes:
Client:
Server:
Cheers />
I moved the password check to the server though. Because checking valid credentials should always happen server-side, or else someone could just rewrite their client to ignore the password-check.^^
Other smaller changes include setting locals wherever I could, removing redundant table accesses (os & io), etc.
If you have any questions about something in the code, don't hesitate to ask.
K, hope it's of any use, here goes:
Client:
Spoiler
Server:
Spoiler
Cheers />
Wolvan 24 Mar 2012
Epic! I made something like this on a PServer already but this seems much more and working
Wirklich cooles Programm!
PS: Ich bin einen Rang gestiegen /> Next Rank! Oh yeah />
Wirklich cooles Programm!
PS: Ich bin einen Rang gestiegen /> Next Rank! Oh yeah />
Kolpa 24 Mar 2012
Kolpa 24 Mar 2012
Espen, on 24 March 2012 - 03:53 PM, said:
Alright Kolpa, as requested (kinda^^) I took a look at it and rewrote some stuff. I tried to leave the original code as much as possible.
I moved the password check to the server though. Because checking valid credentials should always happen server-side, or else someone could just rewrite their client to ignore the password-check.^^
Other smaller changes include setting locals wherever I could, removing redundant table accesses (os & io), etc.
If you have any questions about something in the code, don't hesitate to ask.
K, hope it's of any use, here goes:
Client:
Server:
Cheers />
I moved the password check to the server though. Because checking valid credentials should always happen server-side, or else someone could just rewrite their client to ignore the password-check.^^
Other smaller changes include setting locals wherever I could, removing redundant table accesses (os & io), etc.
If you have any questions about something in the code, don't hesitate to ask.
K, hope it's of any use, here goes:
Client:
Spoiler
Server:
Spoiler
Cheers />
Kolpa 24 Mar 2012
Kolpa 24 Mar 2012
Espen, on 24 March 2012 - 03:53 PM, said:
Alright Kolpa, as requested (kinda^^) I took a look at it and rewrote some stuff. I tried to leave the original code as much as possible.
I moved the password check to the server though. Because checking valid credentials should always happen server-side, or else someone could just rewrite their client to ignore the password-check.^^
Other smaller changes include setting locals wherever I could, removing redundant table accesses (os & io), etc.
If you have any questions about something in the code, don't hesitate to ask.
K, hope it's of any use, here goes:
Client:
Server:
Cheers />
I moved the password check to the server though. Because checking valid credentials should always happen server-side, or else someone could just rewrite their client to ignore the password-check.^^
Other smaller changes include setting locals wherever I could, removing redundant table accesses (os & io), etc.
If you have any questions about something in the code, don't hesitate to ask.
K, hope it's of any use, here goes:
Client:
Spoiler
Server:
Spoiler
Cheers />
Espen 24 Mar 2012
Kolpa, on 24 March 2012 - 07:16 PM, said:
something else what does the locale actualy do ? ^^ never used it so i have 0 idea
They limit the use of the variables to the scope they were defined in and downwards (e.g. even in nested functions within the same scope). Also they're faster than global variables.
The thing is, if you define a global variable in your program in CC, then even after your program has ended, that global variable is still set and if another program makes use of the same variable, this could lead to complications.
If you're interested, here you can read a little bit more about the difference bwtween locals and globals, as well as the reasons for choosing the former over the latter as a default: http://www.lua.org/pil/4.2.html
ShadowLamp 10 Nov 2014
Could the client be added to this?
Edited by ShadowLamp, 10 November 2014 - 04:19 PM.
sleep(0) side = "left" function save(usr, pass) if not fs.exists(fs.combine("users", usr)) then if not fs.exists("users") then fs.makeDir("users") end fs.makeDir(fs.combine("users", usr)) end local h = fs.open(fs.combine(fs.combine("users", usr), "password"), "w") if h then h.writeLine(pass) h.close() else error("Couldn't open file handle!") end end while true do term.clear() term.setCursorPos(1,1) term.write("Input Username: ") username = read() term.setCursorPos(1,2) term.write("Input Password: ") password = read("*") result = check(username,password) if result == true then redstone.setOutput(side,true) sleep(2) redstone.setOutput(side,false) elseif result == "admin" then term.clear() term.setCursorPos(1,1) term.write("Input new Account username: ") newUser = read() term.setCursorPos(1,2) term.write("Input passowrd for account "..newUser..": ") newPass = read("*") save(newUser,newPass) elseif result == false then print("Invalid password") sleep(2) elseif result == "nousr" then print("No such user") sleep(2) end end
Edited by ShadowLamp, 10 November 2014 - 04:19 PM.