Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. local ucl = ULib.ucl -- Make it easier for us to refer to
  2.  
  3. local function reloadGroups()
  4. -- Try to read from the safest locations first
  5. local noMount = true
  6. local path = ULib.UCL_GROUPS
  7.  
  8. local needsBackup = false
  9. local err
  10. ucl.groups, err = ULib.parseKeyValues( ULib.removeCommentHeader( ULib.fileRead( path, noMount ) or "", "/" ) )
  11.  
  12. if not ucl.groups or not ucl.groups[ ULib.ACCESS_ALL ] then
  13. needsBackup = false
  14. -- Totally messed up! Clear it.
  15. local err2
  16. ucl.groups, err2 = ULib.parseKeyValues( ULib.removeCommentHeader( defaultGroupsText, "/" ) )
  17.  
  18. else
  19. -- Check to make sure it passes a basic validity test
  20. ucl.groups[ ULib.ACCESS_ALL ].inherit_from = nil -- Ensure this is the case
  21. for groupName, groupInfo in pairs( ucl.groups ) do
  22. if type( groupName ) ~= "string" then
  23. needsBackup = true
  24. ucl.groups[ groupName ] = nil
  25. else
  26.  
  27. if type( groupInfo ) ~= "table" then
  28. needsBackup = true
  29. groupInfo = {}
  30. ucl.groups[ groupName ] = groupInfo
  31. end
  32.  
  33. if type( groupInfo.allow ) ~= "table" then
  34. needsBackup = true
  35. groupInfo.allow = {}
  36. end
  37.  
  38. local inherit_from = groupInfo.inherit_from
  39. if inherit_from and inherit_from ~= "" and not ucl.groups[ groupInfo.inherit_from ] then
  40. needsBackup = true
  41. groupInfo.inherit_from = nil
  42. end
  43.  
  44. -- Check for cycles
  45. local group = ucl.groupInheritsFrom( groupName )
  46. while group do
  47. if group == groupName then
  48. needsBackup = false
  49. groupInfo.inherit_from = nil -- nil
  50. end
  51. group = ucl.groupInheritsFrom( group )
  52. end
  53.  
  54. if groupName ~= ULib.ACCESS_ALL and not groupInfo.inherit_from or groupInfo.inherit_from == "" then
  55. groupInfo.inherit_from = ULib.ACCESS_SUPERADMIN -- Clean :)
  56. end
  57.  
  58. -- Lower case'ify
  59. for k, v in pairs( groupInfo.allow ) do
  60. if type( k ) == "string" and k:lower() ~= k then
  61. groupInfo.allow[ k:lower() ] = v
  62. groupInfo.allow[ k ] = nil
  63. else
  64. groupInfo.allow[ k ] = v
  65. end
  66. end
  67. end
  68. end
  69. end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement