Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- makeUserServer = 5
- function OpenAll()
- for _,side in ipairs(rs.getSides()) do
- rednet.open(side)
- end
- end
- function split(str, pat)
- local t = { }
- local fpat = "(.-)"..pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function runApp()
- OpenAll()
- id, msg, d = rednet.receive()
- if msg == nil then
- runApp()
- else
- if id == makeUserServer then
- t = split(msg, "!SP!")
- nuser = t[1]
- npass = t[2]
- if nuser == nil then
- runApp()
- else
- if fs.isDir(nuser) == true then
- rednet.send(makeUserServer, "USER EXISTS ALREADY")
- runApp()
- else
- fs.makeDir(nuser)
- r = fs.open(nuser.."/password", "w")
- r.write(npass)
- r.close()
- rednet.send(makeUserServer, "USER HAS BEEN ADDED")
- runApp()
- end
- end
- else
- tbl = split(msg, "!SP!")
- usr = tbl[1]
- pswrd = tbl[2]
- if usr == nil then
- runApp()
- else
- if fs.isDir(usr) == true then
- w = fs.open(usr.."/password", "r")
- y = w.readAll()
- if y == pswrd then
- rednet.send(id, "YOU HAVE BEEN LOGGED IN")
- runApp()
- else
- rednet.send(id, "ERROR: WRONG PASSWORD")
- runApp()
- else
- rednet.send(id, "ERROR: WRONG USERNAME")
- runApp()
- end
- end
- end
- end
- end
- runApp()
Add Comment
Please, Sign In to add comment