Jump to content




[1.3] Door Lock with Server

wireless peripheral computer

9 replies to this topic

#1 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 24 March 2012 - 02:53 PM

so this program is parted into a server and the door client

Client:
Spoiler


Server:
Spoiler


ps: @Espen if u wanna improve have fun ^^

#2 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 24 March 2012 - 03:53 PM

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:
Spoiler

Server:
Spoiler

Cheers :(/>

#3 Ian-Moone

    The Germ

  • New Members
  • 124 posts
  • LocationLiverpool (no I am not a Scouser Im form Holland)

Posted 24 March 2012 - 06:15 PM

looks good

#4 Wolvan

  • New Members
  • 384 posts
  • LocationIn the TARDIS

Posted 24 March 2012 - 06:48 PM

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 :)/>

#5 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 24 March 2012 - 07:06 PM

View PostWolvan, on 24 March 2012 - 06:48 PM, said:

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 :)/>

danke ^^
PS: GRRRRRRRR

#6 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 24 March 2012 - 07:08 PM

View PostEspen, 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:
Spoiler

Server:
Spoiler

Cheers :(/>
thanks ^^ i actualy had a version of this on a server where u coudnt ctrl+t anymore so the rewrite thing was fixed but the server is down for now so i just posted a test version that i made 4 myself in ssp probably gonna edit if the server comes back on

#7 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 24 March 2012 - 07:12 PM

View PostVandie, on 24 March 2012 - 06:15 PM, said:

looks good
ur pic makes the looks good epic :(/>

#8 Kolpa

  • New Members
  • 260 posts
  • LocationGermany

Posted 24 March 2012 - 07:16 PM

View PostEspen, 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:
Spoiler

Server:
Spoiler

Cheers :(/>
something else what does the locale actualy do ? ^^ never used it so i have 0 idea

#9 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 24 March 2012 - 07:55 PM

View PostKolpa, on 24 March 2012 - 07:16 PM, said:

something else what does the locale actualy do ? ^^ never used it so i have 0 idea
If you don't explicitly need global variables, then you should always default to using local variables.
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

#10 ShadowLamp

  • Members
  • 32 posts

Posted 10 November 2014 - 04:19 PM

Could the client be added to this?

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.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users