Guest User

Untitled

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