Guest User

Untitled

a guest
Sep 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. function OpenAll()
  2. for _,side in ipairs(rs.getSides()) do
  3. rednet.open(side)
  4. end
  5. end
  6.  
  7. function split(str, pat)
  8. local t = { }
  9. local fpat = "(.-)"..pat
  10. local last_end = 1
  11. local s, e, cap = str:find(fpat, 1)
  12. while s do
  13. if s ~= 1 or cap ~= "" then
  14. table.insert(t,cap)
  15. end
  16. last_end = e+1
  17. s, e, cap = str:find(fpat, last_end)
  18. end
  19. if last_end <= #str then
  20. cap = str:sub(last_end)
  21. table.insert(t, cap)
  22. end
  23. return t
  24. end
  25.  
  26. function runApp()
  27. OpenAll()
  28. id, msg, d = rednet.receive()
  29. if id == 35 then
  30. t = split(msg, "!SP!")
  31. nuser = t[1]
  32. npass = t[2]
  33. if fs.isDir(nuser) = true then
  34. rednet.send(35, "usererror")
  35. runApp()
  36. else
  37. fs.makeDir(nuser)
  38. r = fs.open(nuser.."/password", "w")
  39. r.write(npass)
  40. r.close
  41. rednet.send("usradded")
  42. runApp()
  43. end
  44. else
  45. tbl = split(msg, "!SP!")
  46. usr = t[1]
  47. pswrd = t[2]
  48. if fs.isDir(usr) == true then
  49. w = fs.open(usr.."/password", "r")
  50. y = w.readAll()
  51. if y == pswrd then
  52. rednet.send(id, "cnfrmd")
  53. runApp()
  54. else
  55. rednet.send(id, "wrongpswrd")
  56. runApp()
  57. end
  58. else
  59. rednet.send(id, "wrngusr")
  60. runApp()
  61. end
  62. end
  63.  
  64. runApp()
Add Comment
Please, Sign In to add comment