Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. /*
  2. ____ _ _ ____ __ __ _ _
  3. / ___|___ __| | ___ __| | | __ ) _ _ | \/ | __ _| | |__ ___ _ __ ___
  4. | | / _ \ / _` |/ _ \/ _` | | _ \| | | | | |\/| |/ _` | | '_ \ / _ \| '__/ _ \
  5. | |__| (_) | (_| | __/ (_| | | |_) | |_| | | | | | (_| | | |_) | (_) | | | (_) |
  6. \____\___/ \__,_|\___|\__,_| |____/ \__, | |_| |_|\__,_|_|_.__/ \___/|_| \___/
  7. |___/
  8. */
  9.  
  10. util.AddNetworkString("pp_open_menu")
  11. util.AddNetworkString("pp_info_send")
  12.  
  13. local function PermissionLoad()
  14.  
  15. if not PermaProps then PermaProps = {} end
  16. if not PermaProps.Permissions then PermaProps.Permissions = {} end
  17.  
  18. PermaProps.Permissions["admindeveloper"] = { Physgun = true, Tool = true, Property = true, Save = true, Delete = true, Update = true, Menu = true, Permissions = true, Inherits = "admin", Custom = true }
  19. PermaProps.Permissions["owner"] = { Physgun = true, Tool = true, Property = true, Save = true, Delete = true, Update = true, Menu = true, Permissions = true, Inherits = "admin", Custom = true }
  20.  
  21. PermaProps.Permissions["superadmin"] = { Physgun = true, Tool = true, Property = true, Save = true, Delete = true, Update = true, Menu = true, Permissions = true, Inherits = "admin", Custom = true }
  22. PermaProps.Permissions["admin"] = { Physgun = false, Tool = false, Property = false, Save = false, Delete = false, Update = false, Menu = false, Permissions = false, Inherits = "user", Custom = true }
  23.  
  24. PermaProps.Permissions["user"] = { Physgun = false, Tool = false, Property = false, Save = false, Delete = false, Update = false, Menu = false, Permissions = false, Inherits = "user", Custom = true }
  25. PermaProps.Permissions["headadmin"] = { Physgun = false, Tool = false, Property = false, Save = false, Delete = false, Update = false, Menu = false, Permissions = false, Inherits = "user", Custom = true }
  26.  
  27. if CAMI then
  28.  
  29. for k, v in pairs(CAMI.GetUsergroups()) do
  30.  
  31. if k == "superadmin" or k == "admin" or k == "user" then continue end
  32.  
  33. PermaProps.Permissions[k] = { Physgun = false, Tool = false, Property = false, Save = false, Delete = false, Update = false, Menu = false, Permissions = false, Inherits = v.Inherits, Custom = false }
  34.  
  35. end
  36.  
  37. end
  38.  
  39. if file.Exists( "permaprops_config.txt", "DATA" ) then
  40. file.Delete( "permaprops_config.txt" )
  41. end
  42.  
  43. if file.Exists( "permaprops_permissions.txt", "DATA" ) then
  44.  
  45. local content = file.Read("permaprops_permissions.txt", "DATA")
  46. local tablecontent = util.JSONToTable( content )
  47.  
  48. for k, v in pairs(tablecontent) do
  49.  
  50. if PermaProps.Permissions[k] == nil then
  51.  
  52. tablecontent[k] = nil
  53.  
  54. end
  55.  
  56. end
  57.  
  58. table.Merge(PermaProps.Permissions, ( tablecontent or {} ))
  59.  
  60. end
  61.  
  62. end
  63. PermissionLoad()
  64.  
  65. local function PermissionSave()
  66.  
  67. file.Write( "permaprops_permissions.txt", util.TableToJSON(PermaProps.Permissions) )
  68.  
  69. end
  70.  
  71. local function pp_open_menu( ply )
  72.  
  73. if !PermaProps.HasPermission( ply, "Menu") then ply:ChatPrint("Access denied !") return end
  74.  
  75. local SendTable = {}
  76. local Data_PropsList = sql.Query( "SELECT * FROM permaprops WHERE map = ".. sql.SQLStr(game.GetMap()) .. ";" )
  77.  
  78. if Data_PropsList and #Data_PropsList < 200 then
  79.  
  80. for k, v in pairs( Data_PropsList ) do
  81.  
  82. local data = util.JSONToTable(v.content)
  83.  
  84. SendTable[v.id] = {Model = data.Model, Class = data.Class, Pos = data.Pos, Angle = data.Angle}
  85.  
  86. end
  87.  
  88. elseif Data_PropsList and #Data_PropsList > 200 then -- Too much props dude :'(
  89.  
  90. for i = 1, 199 do
  91.  
  92. local data = util.JSONToTable(Data_PropsList[i].content)
  93.  
  94. SendTable[Data_PropsList[i].id] = {Model = data.Model, Class = data.Class, Pos = data.Pos, Angle = data.Angle}
  95.  
  96. end
  97.  
  98. end
  99.  
  100. local Content = {}
  101. Content.MProps = tonumber(sql.QueryValue("SELECT COUNT(*) FROM permaprops WHERE map = ".. sql.SQLStr(game.GetMap()) .. ";"))
  102. Content.TProps = tonumber(sql.QueryValue("SELECT COUNT(*) FROM permaprops;"))
  103.  
  104. Content.PropsList = SendTable
  105. Content.Permissions = PermaProps.Permissions
  106.  
  107. local Data = util.TableToJSON( Content )
  108. local Compressed = util.Compress( Data )
  109.  
  110. net.Start( "pp_open_menu" )
  111. net.WriteFloat( Compressed:len() )
  112. net.WriteData( Compressed, Compressed:len() )
  113. net.Send( ply )
  114.  
  115. end
  116. concommand.Add("pp_cfg_open", pp_open_menu)
  117.  
  118. local function pp_info_send( um, ply )
  119.  
  120. local Content = net.ReadTable()
  121.  
  122. if !PermaProps.HasPermission( ply, "Menu") then ply:ChatPrint("Access denied !") return end
  123.  
  124. if Content["CMD"] == "DEL" then
  125.  
  126. Content["Val"] = tonumber(Content["Val"])
  127.  
  128. if Content["Val"] != nil and Content["Val"] <= 0 then return end
  129.  
  130. sql.Query("DELETE FROM permaprops WHERE id = ".. sql.SQLStr(Content["Val"]) .. ";")
  131.  
  132. for k, v in pairs(ents.GetAll()) do
  133.  
  134. if v.PermaProps_ID == Content["Val"] then
  135.  
  136. ply:ChatPrint("You erased " .. v:GetClass() .. " with a model of " .. v:GetModel() .. " from the database.")
  137. v:Remove()
  138. break
  139.  
  140. end
  141.  
  142. end
  143.  
  144. elseif Content["CMD"] == "VAR" then
  145.  
  146. if PermaProps.Permissions[Content["Name"]] == nil or PermaProps.Permissions[Content["Name"]][Content["Data"]] == nil then return end
  147. if !isbool(Content["Val"]) then return end
  148.  
  149. if Content["Name"] == "superadmin" and ( Content["Data"] == "Custom" or Content["Data"] == "Permissions" or Content["Data"] == "Menu" ) then return end
  150.  
  151. if !PermaProps.HasPermission( ply, "Permissions") then ply:ChatPrint("Access denied !") return end
  152.  
  153. PermaProps.Permissions[Content["Name"]][Content["Data"]] = Content["Val"]
  154.  
  155. PermissionSave()
  156.  
  157. elseif Content["CMD"] == "DEL_MAP" then
  158.  
  159. sql.Query( "DELETE FROM permaprops WHERE map = ".. sql.SQLStr(game.GetMap()) .. ";" )
  160. PermaProps.ReloadPermaProps()
  161.  
  162. ply:ChatPrint("You erased all props from the map !")
  163.  
  164. elseif Content["CMD"] == "DEL_ALL" then
  165.  
  166. sql.Query( "DELETE FROM permaprops;" )
  167. PermaProps.ReloadPermaProps()
  168.  
  169. ply:ChatPrint("You erased all props !")
  170.  
  171. elseif Content["CMD"] == "CLR_MAP" then
  172.  
  173. for k, v in pairs( ents.GetAll() ) do
  174.  
  175. if v.PermaProps == true then
  176.  
  177. v:Remove()
  178.  
  179. end
  180.  
  181. end
  182.  
  183. ply:ChatPrint("You have removed all props !")
  184.  
  185. end
  186.  
  187. end
  188. net.Receive("pp_info_send", pp_info_send)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement