←  Programs

ComputerCraft | Programmable Computers for Minecraft

»

[1.3] Door Lock with Server

Kolpa's Photo Kolpa 24 Mar 2012

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

Client:
Spoiler


Server:
Spoiler


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

Espen's Photo 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:
Spoiler

Server:
Spoiler

Cheers :(/>
Quote

Ian-Moone's Photo Ian-Moone 24 Mar 2012

looks good
Quote

Wolvan's Photo 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 :)/>
Quote

Kolpa's Photo Kolpa 24 Mar 2012

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
Quote

Kolpa's Photo Kolpa 24 Mar 2012

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
Quote

Kolpa's Photo Kolpa 24 Mar 2012

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

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

Kolpa's Photo Kolpa 24 Mar 2012

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
Quote

Espen's Photo Espen 24 Mar 2012

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
Quote

ShadowLamp's Photo ShadowLamp 10 Nov 2014

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.
Quote