Advertisement
Alakazard12

Custom Users

Dec 12th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. local dfile = "/files"
  2. local ufile = "/users"
  3. local cfile = dfile.."/alak"
  4.  
  5. local users = {
  6.     ["alak"] = "admin";
  7. }
  8.  
  9. if not fs.exists(ufile) then
  10.     local pm = fs.open(ufile, "w")
  11.     pm.write(textutils.serialize(users))
  12.     pm.close()
  13. else
  14.     local pm = fs.open(ufile, "r")
  15.     users = textutils.unserialize(pm.readAll())
  16.     pm.close()
  17. end
  18.  
  19. if not fs.exists(dfile) then
  20.     fs.makeDir(dfile)
  21. end
  22.  
  23. for i,v in pairs(users) do
  24.     if not fs.exists(dfile.."/"..i) then
  25.         fs.makeDir(dfile.."/"..i)
  26.     end
  27. end
  28.  
  29. local oldfs = {}
  30. for i,v in pairs(fs) do
  31.     oldfs[i] = v
  32. end
  33.  
  34. local function resolve(path)
  35.     while true do
  36.         if string.sub(path, 1, 1) == "/" then
  37.             path = string.sub(path, 2)
  38.         else
  39.             break
  40.         end
  41.     end
  42.     while true do
  43.         if string.sub(path, #path, #path) == "/" then
  44.             path = string.sub(path, 1, #path-1)
  45.         else
  46.             break
  47.         end
  48.     end
  49.     return path
  50. end
  51.  
  52. for i,v in pairs(fs.list("/")) do
  53.     if v ~= dfile and v ~= ufile and v ~= "rom" and v ~= "cu" then
  54.         -- fs.delete(v)
  55.     end
  56. end
  57.  
  58. for i,v in pairs(fs.list(cfile)) do
  59.     fs.copy(cfile.."/"..v, "/")
  60. end
  61.  
  62. --[[
  63. function fs.open(path, typ)
  64.     return oldfs.open(cfile.."/"..resolve(path), typ)
  65. end
  66.  
  67. function fs.list(path)
  68.     return oldfs.list(cfile.."/"..resolve(path))
  69. end
  70.  
  71. while true do
  72.     term.setTextColor(colors.yellow)
  73.     write(shell.dir().."> ")
  74.     term.setTextColor(colors.white)
  75.     local rd = read()
  76.     local isp = shell.run(rd)
  77.     if not isp and fs.exists("programs/"..rd) then
  78.         shell.run("programs/"..rd)
  79.     end
  80. end
  81. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement