summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorU-DESKTOP-FOJ6TK1\Alex <alex@cogarr.net>2025-02-12 16:44:31 -0600
committerU-DESKTOP-FOJ6TK1\Alex <alex@cogarr.net>2025-02-12 16:44:31 -0600
commita102c25ab7987d5650fb8cc1ef52a5b29a01ffaa (patch)
tree85c1cc06867222545ecef6619bf48056a8d4e131
parentb5b9efc28bb65fa3a53db8867310ac42d00f2bc6 (diff)
downloadnadmin-master.tar.gz
nadmin-master.tar.bz2
nadmin-master.zip
Final commitHEADmaster
-rw-r--r--lua/autorun/cl_nadmin.lua724
-rw-r--r--lua/autorun/sh_nadmin.lua340
-rw-r--r--lua/autorun/sv_nadmin.lua456
-rw-r--r--lua/vgui/dtiltedlabel.lua78
4 files changed, 778 insertions, 820 deletions
diff --git a/lua/autorun/cl_nadmin.lua b/lua/autorun/cl_nadmin.lua
index 31f7730..5b87058 100644
--- a/lua/autorun/cl_nadmin.lua
+++ b/lua/autorun/cl_nadmin.lua
@@ -1,374 +1,350 @@
-AddCSLuaFile()
-if SERVER then return end
-local nadmin = include("sh_nadmin.lua")
-
---Functions
-local add_group_to_groupsheet
-local remove_group_from_groupsheet
-
---Override what print() does, just for this file
-local oldprint = print
-local print = function(...)
- local args = {...}
- table.insert(args,1,"[NADMIN]")
- oldprint(unpack(args))
-end
---The variables that hold things
---local groups = nadmin.groups
---local players = nadmin.players
---local privileges = nadmin.privileges
-
-local usergroup_dropdowns = {}
-local function add_usergroup_to_usergroup_dropdowns(name)
- for k,v in pairs(usergroup_dropdowns) do
- if v:IsValid() then
- v:AddChoice(name)
- else
- usergroup_dropdowns[k] = nil
- end
- end
-end
-local function delete_usergroup_from_usergroup_dropdowns(group)
- for _,v in pairs(usergroup_dropdowns) do
- print("Looking at object:",v)
- table.RemoveByValue(v.Choices, name)
- if v.Menu then
- v.Menu:Remove()
- v.Menu = nil
- end
- if v:GetText() == group.group.Name then
- v:SetText(group.group.MinAccess)
- end
- end
-end
-net.Receive("nadmin_init_privileges", function(len)
- print("got privileges")
- nadmin.privileges = net.ReadTable()
-end)
-net.Receive("nadmin_init_players", function(len)
- print("got players")
- nadmin.players = net.ReadTable()
-end)
-net.Receive("nadmin_init_groups", function(len)
- print("got groups")
- nadmin.groups = net.ReadTable()
- PrintTable(nadmin.groups)
-end)
-
-net.Receive("nadmin_update_privilege", function(len)
- local exists = net.ReadBool()
- local privilege = net.ReadTable()
- if exists then
- nadmin.privileges[privilege.Name] = privilege
- else
- nadmin.privileges[privilege.Name] = nil
- end
-end)
-net.Receive("nadmin_create_group", function(len)
- local name = net.ReadString()
- local inherits = net.ReadString()
- local source = net.ReadString()
- nadmin.groups[name] = {
- name = name,
- group = {
- Name = name,
- Inherits = inherits
- },
- privileges = {},
- nadmin = source == "nadmin",
- src = source
- }
- add_group_to_groupsheet(nadmin.groups[name])
- add_usergroup_to_usergroup_dropdowns(name)
- CAMI.RegisterUsergroup(nadmin.groups[name].group, "nadmin")
-end)
-net.Receive("nadmin_update_group", function(len)
- local name = net.ReadString()
- local privilege = net.ReadString()
- local exists = net.ReadBool()
- if exists then
- nadmin.groups[name].privileges[privilege] = exists
- else
- nadmin.groups[name].privileges[privilege] = nil
- end
-end)
-net.Receive("nadmin_delete_group", function(len)
- local name = net.ReadString()
- remove_group_from_groupsheet(nadmin.groups[name])
- delete_usergroup_from_usergroup_dropdowns(nadmin.groups[name])
- nadmin.groups[name] = nil
- CAMI.UnregisterUsergroup(name,"nadmin")
-end)
-net.Receive("nadmin_update_player", function(len)
- local player = net.ReadEntity()
- local group = net.ReadString()
- local sid = player:SteamID64()
- print("At time of nadmin_update_player, player is", player)
- nadmin.players[sid] = nadmin.players[sid] or {}
- nadmin.players[sid].group = group
- nadmin.players[sid].last_name = player:Name()
- if nadmin.players[sid].combo then
- nadmin.players[sid].combo:SetValue(group)
- end
- if nadmin.players[sid].line then
- nadmin.players[sid].line:SetColumnText(2,player:Name())
- end
- CAMI.SignalSteamIDUserGroupChanged(sid,group,"nadmin")
-end)
-
-concommand.Add("cl_print_privileges", function(ply,cmd,args)
- PrintTable(nadmin.privileges)
-end)
-concommand.Add("cl_print_groups", function(ply,cmd,args)
- print("NAdmin groups:",nadmin.groups)
- PrintTable(nadmin.groups)
- print("Local groups:",groups)
- PrintTable(nadmin.groups)
-end)
-concommand.Add("cl_print_players", function(ply,cmd,args)
- PrintTable(nadmin.players)
-end)
-
-local function create_usergroup_combo(parent)
- local ret = vgui.Create("DComboBox",parent)
- for groupname, _ in pairs(nadmin.groups) do
- ret:AddChoice(groupname)
- end
- table.insert(usergroup_dropdowns, ret)
- return ret
-end
-
-local nadmin_frame,users_tbl,groups_tbl = nil,nil,nil
-local users_sheet,groups_sheet = nil,nil
---ply :: entity
-local function add_user_to_usersheet(steamid,ply)
- if not nadmin_frame then return end
- local player_ent = player.GetBySteamID64(steamid)
- local line = users_tbl:AddLine(steamid, ply.last_name, ply.group)
- local dropdown = create_usergroup_combo(line)
- if nadmin.players[steamid] then
- dropdown:SetValue(nadmin.players[steamid].group)
- else
- dropdown:SetValue("user")
- end
- dropdown.OnSelect = function(self, index, value)
- net.Start("nadmin_request_set_user_group")
- net.WriteEntity(player_ent)
- net.WriteString(value)
- net.SendToServer()
- end
- line:SetColumnText(3,dropdown)
- ply.combo = dropdown --Update the combo box when someone else updates the group
- ply.line = line
-end
-
---ply :: entity
-local function remove_user_from_usersheet(ply)
- if not nadmin_frame then return end
- if not ply.line then return end
- users_tbl:RemoveLine(ply.line.m_iID)
-end
-
-local privilege_checkboxes = {}
-local function add_privilege_to_groupsheet(privilege)
- local ordered_privileges = {}
- for _,privilege in pairs(nadmin.privileges) do
- table.insert(ordered_privileges,privilege)
- end
- table.sort(ordered_privileges, function(a,b) return a.Name > b.Name end)
- local privilege_num = 0
- for num,ordered_privilege in pairs(ordered_privileges) do
- if ordered_privilege == privilege then
- privilege_num = num
- break
- end
- end
- local column = groups_tbl:AddColumn(privilege.Name)
- column.DoClick = function(self)
- local explain_frame = vgui.Create("DFrame")
- explain_frame:SetTitle(privilege.Name)
- local description = vgui.Create("DLabel",explain_frame)
- description:SetWrap(true)
- if privilege.Description then
- description:SetText(privilege.Description)
- else
- description:SetText("This privilege does not have a description")
- end
- explain_frame:SetSize(ScrW() / 6, ScrH() / 4)
- explain_frame:SetPos(ScrW() / 4 + 100,ScrH() / 4 + 50)
- explain_frame:MakePopup()
- description:Dock(FILL)
- end
- column:SetWrap(true)
- for groupname,group in pairs(nadmin.groups) do
- local checkbox = vgui.Create("DCheckBox", group.line)
- privilege_checkboxes[groupname] = checkbox
- print("Group:")
- PrintTable(group)
- if group.nadmin then
- checkbox:SetChecked(group.privileges[privilege.Name])
- checkbox.OnChange = function(self,value)
- net.Start("nadmin_request_update_group")
- net.WriteString(groupname)
- net.WriteString(privilege.Name)
- net.WriteBool(value)
- net.SendToServer()
- end
- else
- checkbox:SetDisabled(true)
- end
- group.line:SetColumnText(privilege_num + 2,checkbox)
- end
-end
-
-local function remove_privilege_from_groupsheet(privilege)
-
-end
-
-add_group_to_groupsheet = function(group)
- if not groups_tbl then return end
- local line = groups_tbl:AddLine(group.group.Name)
- local ordered_privileges = {}
- for _,privilege in pairs(nadmin.privileges) do
- table.insert(ordered_privileges,privilege)
- end
- table.sort(ordered_privileges, function(a,b) return a.Name > b.Name end)
- local delete_group_button = vgui.Create("DButton",line)
- delete_group_button:SetText("-")
- delete_group_button:SetEnabled(group.nadmin)
- delete_group_button.DoClick = function(self)
- net.Start("nadmin_request_delete_group")--(group :: string)
- net.WriteString(group.group.Name)
- net.SendToServer()
- end
- line:SetColumnText(2,delete_group_button)
- for n,privilege_name in pairs(ordered_privileges) do
- local privilege_checkbox = vgui.Create("DCheckBox",line)
- line:SetColumnText(n + 2,privilege_checkbox)
- if group.nadmin then
- privilege_checkbox:SetChecked(group.privileges[privilege_name])
- privilege_checkbox.OnChange = function(self,val)
- net.Start("nadmin_request_update_group") --(group :: string, privilege :: string, set :: bool)
- net.WriteString(group.group.Name)
- net.WriteString(privilege_name.Name)
- net.WriteBool(val)
- net.SendToServer()
- end
- else
- privilege_checkbox:SetDisabled(true)
- end
- end
- group.line = line
- group.line_id = #groups_tbl.Lines
-end
-
-function remove_group_from_groupsheet(group)
- groups_tbl:RemoveLine(group.line_id)
-end
-
-local function create_new_group_dialog()
- local dialog = vgui.Create("DFrame")
- dialog:SetTitle("Create Group")
-
- local inherits_label = vgui.Create("DLabel",dialog)
- inherits_label:Dock(TOP)
- inherits_label:SetText("Inherits from")
-
- local inherits = create_usergroup_combo(dialog)
- inherits:Dock(TOP)
-
- local groupname_label = vgui.Create("DLabel",dialog)
- groupname_label:Dock(TOP)
- groupname_label:SetText("Group Name")
-
- local groupname = vgui.Create("DTextEntry",dialog)
- groupname:Dock(TOP)
-
- local createbtn = vgui.Create("DButton",dialog)
- createbtn:SetText("Create Group")
- createbtn.DoClick = function(self)
- net.Start("nadmin_request_create_group")
- net.WriteString(groupname:GetText())
- net.WriteString(inherits:GetText())
- net.SendToServer()
- dialog:Close()
- end
- createbtn:Dock(BOTTOM)
-
- dialog:SetSize(250,150)
- dialog:Center()
- dialog:MakePopup()
-end
-
-local function create_nadmin_panel()
- if nadmin_frame ~= nil and nadmin_frame:IsValid() then
- nadmin_frame:SetVisible(true)
- return
- end
-
- nadmin_frame = vgui.Create("DFrame")
- nadmin_frame:SetTitle("nAdmin")
- nadmin_frame.OnClose = function(self)
- self:SetVisible(false)
- return false
- end
- nadmin_frame:SetSizable(true)
- local prop_sheet = vgui.Create("DPropertySheet",nadmin_frame)
- prop_sheet:Dock(FILL)
- users_tbl = vgui.Create("DListView",prop_sheet)
- users_tbl:AddColumn("SteamID")
- users_tbl:AddColumn("Name")
- users_tbl:AddColumn("Group")
- for steamid,player in pairs(nadmin.players) do
- add_user_to_usersheet(steamid,player)
- end
-
- prop_sheet:AddSheet("Users",users_tbl,nil,true,true,"Sets users to particular groups")
-
- users_tbl:Dock(FILL)
-
- local groups_scroller = vgui.Create("DHorizontalScroller",prop_sheet)
- groups_tbl = vgui.Create("DListView",groups_scroller)
- groups_scroller:Dock(FILL)
- local gcol = groups_tbl:AddColumn("Group")
- local dcol = groups_tbl:AddColumn("Delete")
- gcol:SetEnabled(false)
- dcol:SetEnabled(false)
- local tot_columns = 0
- local tot_width = 0
- --Don't do anything if the user clicks the Group or Delete headers
- for _,v in pairs(groups_tbl.Columns) do
- v.DoClick = function() end
- end
- local add_line = groups_tbl:AddLine("")
- local add_btn = vgui.Create("DButton",add_line)
- add_btn:SetText("+")
- add_btn.DoClick = function(self)
- create_new_group_dialog()
- end
- add_line:SetColumnText(1,add_btn)
- for groupname,group in pairs(nadmin.groups) do
- tot_columns = tot_columns + 1
- add_group_to_groupsheet(group)
- tot_width = tot_width + string.len(groupname)*30 --10 pixels for each character?
- end
-
- for privilegename, privilege in pairs(nadmin.privileges) do
- add_privilege_to_groupsheet(privilege)
- end
- groups_tbl:SetWidth(tot_width)
- prop_sheet:AddSheet("Groups",groups_scroller,nil,true,true,"Set the privileges for a group")
- groups_scroller:AddPanel(groups_tbl)
-
- nadmin_frame:SetSize(ScrW() / 2, ScrH() / 2)
- nadmin_frame:SetPos(ScrW() / 4, ScrH() / 4)
- nadmin_frame:MakePopup()
-end
-
-concommand.Add("cl_nadmin", function(ply,cmd,args)
- create_nadmin_panel()
-end)
-concommand.Add("cl_nadmin_new", function(ply,cmd,args)
- nadmin_frame = nil
- create_nadmin_panel()
-end)
+AddCSLuaFile()
+if SERVER then return end
+local nadmin = include("sh_nadmin.lua")
+
+--Functions
+local add_group_to_groupsheet
+local remove_group_from_groupsheet
+
+--Override what print() does, just for this file
+local oldprint = print
+local print = function(...)
+ local args = {...}
+ table.insert(args,1,"[NADMIN]")
+ oldprint(unpack(args))
+end
+
+local usergroup_dropdowns = {}
+local function add_usergroup_to_usergroup_dropdowns(name)
+ for k,v in pairs(usergroup_dropdowns) do
+ if v:IsValid() then
+ v:AddChoice(name)
+ else
+ usergroup_dropdowns[k] = nil
+ end
+ end
+end
+local function delete_usergroup_from_usergroup_dropdowns(group)
+ for _,v in pairs(usergroup_dropdowns) do
+ table.RemoveByValue(v.Choices, name)
+ if v.Menu then
+ v.Menu:Remove()
+ v.Menu = nil
+ end
+ if v:GetText() == group.group.Name then
+ v:SetText(group.group.MinAccess)
+ end
+ end
+end
+
+net.Receive("nadmin_init_privileges", function(len)
+ nadmin.privileges = net.ReadTable()
+end)
+net.Receive("nadmin_init_players", function(len)
+ nadmin.players = net.ReadTable()
+end)
+net.Receive("nadmin_init_groups", function(len)
+ nadmin.groups = net.ReadTable()
+end)
+
+net.Receive("nadmin_update_privilege", function(len)
+ local exists = net.ReadBool()
+ local privilege = net.ReadTable()
+ if exists then
+ nadmin.privileges[privilege.Name] = privilege
+ else
+ nadmin.privileges[privilege.Name] = nil
+ end
+end)
+net.Receive("nadmin_create_group", function(len)
+ local name = net.ReadString()
+ local inherits = net.ReadString()
+ local source = net.ReadString()
+ nadmin.groups[name] = {
+ name = name,
+ group = {
+ Name = name,
+ Inherits = inherits
+ },
+ privileges = {},
+ nadmin = source == "nadmin",
+ src = source
+ }
+ add_group_to_groupsheet(nadmin.groups[name])
+ add_usergroup_to_usergroup_dropdowns(name)
+ CAMI.RegisterUsergroup(nadmin.groups[name].group, "nadmin")
+end)
+net.Receive("nadmin_update_group", function(len)
+ local name = net.ReadString()
+ local privilege = net.ReadString()
+ local exists = net.ReadBool()
+ if exists then
+ nadmin.groups[name].privileges[privilege] = exists
+ else
+ nadmin.groups[name].privileges[privilege] = nil
+ end
+end)
+net.Receive("nadmin_delete_group", function(len)
+ local name = net.ReadString()
+ remove_group_from_groupsheet(nadmin.groups[name])
+ delete_usergroup_from_usergroup_dropdowns(nadmin.groups[name])
+ nadmin.groups[name] = nil
+ CAMI.UnregisterUsergroup(name,"nadmin")
+end)
+net.Receive("nadmin_update_player", function(len)
+ local player = net.ReadEntity()
+ local group = net.ReadString()
+ local sid = player:SteamID64()
+ nadmin.players[sid] = nadmin.players[sid] or {}
+ nadmin.players[sid].group = group
+ nadmin.players[sid].last_name = player:Name()
+ if nadmin.players[sid].combo then
+ nadmin.players[sid].combo:SetValue(group)
+ end
+ if nadmin.players[sid].line then
+ nadmin.players[sid].line:SetColumnText(2,player:Name())
+ end
+ CAMI.SignalSteamIDUserGroupChanged(sid,group,"nadmin")
+end)
+
+local function create_usergroup_combo(parent)
+ local ret = vgui.Create("DComboBox",parent)
+ for groupname, _ in pairs(nadmin.groups) do
+ ret:AddChoice(groupname)
+ end
+ table.insert(usergroup_dropdowns, ret)
+ return ret
+end
+
+local nadmin_frame,users_tbl,groups_tbl = nil,nil,nil
+local users_sheet,groups_sheet = nil,nil
+--ply :: entity
+local function add_user_to_usersheet(steamid,ply)
+ if not nadmin_frame then return end
+ local player_ent = player.GetBySteamID64(steamid)
+ local line = users_tbl:AddLine(steamid, ply.last_name, ply.group)
+ local dropdown = create_usergroup_combo(line)
+ if nadmin.players[steamid] then
+ dropdown:SetValue(nadmin.players[steamid].group)
+ else
+ dropdown:SetValue("user")
+ end
+ dropdown.OnSelect = function(self, index, value)
+ net.Start("nadmin_request_set_user_group")
+ net.WriteEntity(player_ent)
+ net.WriteString(value)
+ net.SendToServer()
+ end
+ line:SetColumnText(3,dropdown)
+ ply.combo = dropdown --Update the combo box when someone else updates the group
+ ply.line = line
+end
+
+--ply :: entity
+local function remove_user_from_usersheet(ply)
+ if not nadmin_frame then return end
+ if not ply.line then return end
+ users_tbl:RemoveLine(ply.line.m_iID)
+end
+
+local privilege_checkboxes = {}
+local function add_privilege_to_groupsheet(privilege)
+ local ordered_privileges = {}
+ for _,privilege in pairs(nadmin.privileges) do
+ table.insert(ordered_privileges,privilege)
+ end
+ table.sort(ordered_privileges, function(a,b) return a.Name > b.Name end)
+ local privilege_num = 0
+ for num,ordered_privilege in pairs(ordered_privileges) do
+ if ordered_privilege == privilege then
+ privilege_num = num
+ break
+ end
+ end
+ local column = groups_tbl:AddColumn(privilege.Name)
+ column.DoClick = function(self)
+ local explain_frame = vgui.Create("DFrame")
+ explain_frame:SetTitle(privilege.Name)
+ local description = vgui.Create("DLabel",explain_frame)
+ description:SetWrap(true)
+ if privilege.Description then
+ description:SetText(privilege.Description)
+ else
+ description:SetText("This privilege does not have a description")
+ end
+ explain_frame:SetSize(ScrW() / 6, ScrH() / 4)
+ explain_frame:SetPos(ScrW() / 4 + 100,ScrH() / 4 + 50)
+ explain_frame:MakePopup()
+ description:Dock(FILL)
+ end
+ column:SetWrap(true)
+ for groupname,group in pairs(nadmin.groups) do
+ local checkbox = vgui.Create("DCheckBox", group.line)
+ privilege_checkboxes[groupname] = checkbox
+ if group.nadmin then
+ checkbox:SetChecked(group.privileges[privilege.Name])
+ checkbox.OnChange = function(self,value)
+ net.Start("nadmin_request_update_group")
+ net.WriteString(groupname)
+ net.WriteString(privilege.Name)
+ net.WriteBool(value)
+ net.SendToServer()
+ end
+ else
+ checkbox:SetDisabled(true)
+ end
+ group.line:SetColumnText(privilege_num + 2,checkbox)
+ end
+end
+
+local function remove_privilege_from_groupsheet(privilege)
+
+end
+
+add_group_to_groupsheet = function(group)
+ if not groups_tbl then return end
+ local line = groups_tbl:AddLine(group.group.Name)
+ local ordered_privileges = {}
+ for _,privilege in pairs(nadmin.privileges) do
+ table.insert(ordered_privileges,privilege)
+ end
+ table.sort(ordered_privileges, function(a,b) return a.Name > b.Name end)
+ local delete_group_button = vgui.Create("DButton",line)
+ delete_group_button:SetText("-")
+ delete_group_button:SetEnabled(group.nadmin)
+ delete_group_button.DoClick = function(self)
+ net.Start("nadmin_request_delete_group")--(group :: string)
+ net.WriteString(group.group.Name)
+ net.SendToServer()
+ end
+ line:SetColumnText(2,delete_group_button)
+ for n,privilege_name in pairs(ordered_privileges) do
+ local privilege_checkbox = vgui.Create("DCheckBox",line)
+ line:SetColumnText(n + 2,privilege_checkbox)
+ if group.nadmin then
+ privilege_checkbox:SetChecked(group.privileges[privilege_name])
+ privilege_checkbox.OnChange = function(self,val)
+ net.Start("nadmin_request_update_group") --(group :: string, privilege :: string, set :: bool)
+ net.WriteString(group.group.Name)
+ net.WriteString(privilege_name.Name)
+ net.WriteBool(val)
+ net.SendToServer()
+ end
+ else
+ privilege_checkbox:SetDisabled(true)
+ end
+ end
+ group.line = line
+ group.line_id = #groups_tbl.Lines
+end
+
+function remove_group_from_groupsheet(group)
+ groups_tbl:RemoveLine(group.line_id)
+end
+
+local function create_new_group_dialog()
+ local dialog = vgui.Create("DFrame")
+ dialog:SetTitle("Create Group")
+
+ local inherits_label = vgui.Create("DLabel",dialog)
+ inherits_label:Dock(TOP)
+ inherits_label:SetText("Inherits from")
+
+ local inherits = create_usergroup_combo(dialog)
+ inherits:Dock(TOP)
+
+ local groupname_label = vgui.Create("DLabel",dialog)
+ groupname_label:Dock(TOP)
+ groupname_label:SetText("Group Name")
+
+ local groupname = vgui.Create("DTextEntry",dialog)
+ groupname:Dock(TOP)
+
+ local createbtn = vgui.Create("DButton",dialog)
+ createbtn:SetText("Create Group")
+ createbtn.DoClick = function(self)
+ net.Start("nadmin_request_create_group")
+ net.WriteString(groupname:GetText())
+ net.WriteString(inherits:GetText())
+ net.SendToServer()
+ dialog:Close()
+ end
+ createbtn:Dock(BOTTOM)
+
+ dialog:SetSize(250,150)
+ dialog:Center()
+ dialog:MakePopup()
+end
+
+local function create_nadmin_panel()
+ if nadmin_frame ~= nil and nadmin_frame:IsValid() then
+ nadmin_frame:SetVisible(true)
+ return
+ end
+
+ nadmin_frame = vgui.Create("DFrame")
+ nadmin_frame:SetTitle("nAdmin")
+ nadmin_frame.OnClose = function(self)
+ self:SetVisible(false)
+ return false
+ end
+ nadmin_frame:SetSizable(true)
+ local prop_sheet = vgui.Create("DPropertySheet",nadmin_frame)
+ prop_sheet:Dock(FILL)
+ users_tbl = vgui.Create("DListView",prop_sheet)
+ users_tbl:AddColumn("SteamID")
+ users_tbl:AddColumn("Name")
+ users_tbl:AddColumn("Group")
+ for steamid,player in pairs(nadmin.players) do
+ add_user_to_usersheet(steamid,player)
+ end
+
+ prop_sheet:AddSheet("Users",users_tbl,nil,true,true,"Sets users to particular groups")
+
+ users_tbl:Dock(FILL)
+
+ local groups_scroller = vgui.Create("DHorizontalScroller",prop_sheet)
+ groups_tbl = vgui.Create("DListView",groups_scroller)
+ groups_scroller:Dock(FILL)
+ local gcol = groups_tbl:AddColumn("Group")
+ local dcol = groups_tbl:AddColumn("Delete")
+ gcol:SetEnabled(false)
+ dcol:SetEnabled(false)
+ local tot_columns = 0
+ local tot_width = 0
+ --Don't do anything if the user clicks the Group or Delete headers
+ for _,v in pairs(groups_tbl.Columns) do
+ v.DoClick = function() end
+ end
+ local add_line = groups_tbl:AddLine("")
+ local add_btn = vgui.Create("DButton",add_line)
+ add_btn:SetText("+")
+ add_btn.DoClick = function(self)
+ create_new_group_dialog()
+ end
+ add_line:SetColumnText(1,add_btn)
+ for groupname,group in pairs(nadmin.groups) do
+ tot_columns = tot_columns + 1
+ add_group_to_groupsheet(group)
+ tot_width = tot_width + string.len(groupname)*30 --10 pixels for each character?
+ end
+
+ for privilegename, privilege in pairs(nadmin.privileges) do
+ add_privilege_to_groupsheet(privilege)
+ end
+ groups_tbl:SetWidth(tot_width)
+ prop_sheet:AddSheet("Groups",groups_scroller,nil,true,true,"Set the privileges for a group")
+ groups_scroller:AddPanel(groups_tbl)
+
+ nadmin_frame:SetSize(ScrW() / 2, ScrH() / 2)
+ nadmin_frame:SetPos(ScrW() / 4, ScrH() / 4)
+ nadmin_frame:MakePopup()
+end
+
+concommand.Add("cl_nadmin", function(ply,cmd,args)
+ create_nadmin_panel()
+end)
+concommand.Add("cl_nadmin_new", function(ply,cmd,args)
+ nadmin_frame = nil
+ create_nadmin_panel()
+end)
diff --git a/lua/autorun/sh_nadmin.lua b/lua/autorun/sh_nadmin.lua
index 392daec..46f0cce 100644
--- a/lua/autorun/sh_nadmin.lua
+++ b/lua/autorun/sh_nadmin.lua
@@ -1,174 +1,166 @@
-include("sh_cami.lua")
-AddCSLuaFile()
-local nadmin = {}
-
---[[
-Groups is a table of
-["group_name"] = {
- nadmin :: bool --Wether the group was created by nAdmin or not
- --nAdmin will only allow you to delete groups
- --that were created with it. You cannot delete
- --groups that were created with another mod.
-
- group :: CAMI_USERGROUP -- the usergroup table given by CAMI,
- -- see sh_cami.lua for details.
-
- src :: string --The source of the usergroup, can be "cami", nAdmin,
- --or the name of the mod that introduced the usergroup.
-
- privileges :: table --An array of ["privilege_name"] = true, for
- --each privilege the group has
-}
-]]
-nadmin.groups = {}
-for _,v in pairs(CAMI.GetUsergroups()) do
- print("Initalizing usergroups, this usergroup was",v)
- PrintTable(v)
- nadmin.groups[v.Name] = {
- nadmin = false,
- group = v,
- src = "cami",
- privileges = {},
- }
- for _,privilege in pairs(CAMI.GetPrivileges()) do
- if privilege.MinAccess == v.Name then
- nadmin.groups[v.Name].privileges[privilege.Name] = true
- end
- end
-end
---[[
-Players is a table of
-[player_steamid] = {
- group :: CAMI_USERGROUP --The usergroup table given by CAMI that
- --the player is a part of, see sh_cami.lua for
- --details
-
- last_name :: string --The last name that the player joined the server
- --with, this is used to set player's permissions
- --even when the player is offline.
-]]
-nadmin.players = {}
-nadmin.privileges = CAMI.GetPrivileges()
-
-function nadmin.AddUserGroup(src,usergroup)
- nadmin.groups[usergroup.Name] = {
- nadmin = src == "nadmin",
- group = usergroup,
- src = src,
- privileges = {}
- }
-end
-
-function nadmin.DeleteUserGroup(name,src)
- nadmin.groups[name] = nil
-end
-
-function nadmin.save_config()
- if not SERVER then return end
- local file_parts = {"return {"}
-
- --Save groups
- table.insert(file_parts,"groups = {")
- for groupname, group in pairs(nadmin.groups) do
- if group.nadmin then
- local privileges_tbl = {}
- for privilege_name,_ in pairs(group.privileges) do
- table.insert(privileges_tbl,string.format("[%q] = true",privilege_name))
- end
- table.insert(file_parts,string.format([[
- [%q] = {
- name = %q,
- inherits = %q,
- privileges = {%s}
- },]],groupname, group.group.Name, group.group.Inherits, table.concat(privileges_tbl,",")))
- end
- end
- table.insert(file_parts,"},")
-
- --Save players
- table.insert(file_parts,"players = {")
- for playerid, player in pairs(nadmin.players) do
- table.insert(file_parts,string.format([[
- [%q] = {
- last_name = %q,
- group = %q
- },]], playerid, player.last_name, player.group))
- end
- table.insert(file_parts,"},")
-
- --Finish off
- table.insert(file_parts,"}")
- --And save to file
- file.Write("nadmin.txt",table.concat(file_parts,"\n"))
-end
-
---Notify client of changes to the groups table
-hook.Add("CAMI.OnUsergroupRegistered","nadmin_OnUserGroupRegistered",function(usergroup,src)
- print("hook nadmin_OnUserGroupRegistered called, src was", src)
- src = src or ""
- print("Usergroup was:",usergroup, usergroup.Name, usergroup.Inherits)
- nadmin.AddUserGroup(src,usergroup)
- if SERVER then
- net.Start("nadmin_create_group")
- net.WriteString(usergroup.Name)
- net.WriteString(usergroup.Inherits or "users") --Some mods call this hook without an "Inherits"
- net.WriteString(src)
- net.Broadcast()
- nadmin.save_config()
- end
-end)
-
-hook.Add("CAMI.OnUsergroupUnregistered","nadmin_OnUserGroupUnregistered",function(usergroup,src)
- nadmin.DeleteUserGroup(usergroup.Name, src)
- if SERVER then
- net.Start("nadmin_delete_group")
- net.WriteString(usergroup.Name)
- net.Broadcast()
- nadmin.save_config()
- end
-end)
-
-hook.Add("CAMI.PlayerUsergroupChanged","nadmin_PlayerUsergroupChanged",function(ply,from,to,src)
- local sid = ply:SteamID64()
- nadmin.players[sid] = nadmin.players[sid] or {}
- nadmin.players[sid].group = to
- if SERVER then
- net.Start("nadmin_update_player")
- net.WriteEntity(ply)
- net.WriteString(to)
- net.Broadcast()
- nadmin.save_config()
- end
-end)
-
-hook.Add("CAMI.OnPrivilegeRegistered", "nadmin_OnPrivilegeRegistered", function(privilege)
- nadmin.privileges[privilege.Name] = privilege
- nadmin.save_config()
-end)
-
-hook.Add("CAMI.OnPrivilegeUnregistered", "nadmin_OnPrivilegeUnregistered", function(privilege)
- nadmin.privileges[privilege.Name] = nil
-end)
-
-hook.Add("CAMI.PlayerHasAccess","nadmin_PlayerHasAccess",function(ply,name,callback,target,extra)
- if (not ply) or (not ply:IsValid()) then return end
- print("At time of PlayerHasAccess call, players was",nadmin.players, "for", ply)
- local sid = ply:SteamID64()
- if not nadmin.players[sid] then return end
- local group = nadmin.players[ply:SteamID64()].group
- if group and type(group) == "table" and group.nadmin and group.privileges[name] then
- return true
- end
-end)
-
-hook.Add("CAMI.SteamIDHasAccess","nadmin_SteamIDHasAccess",function(id,privilege,callback,target,extra)
- local group = nadmin.players[id].group
- if group and group.nadmin and group.privileges[privilege] then
- return true
- end
-end)
-
---nadmin.groups = groups
---nadmin.players = players
---nadmin.privileges = privileges
-return nadmin
+include("sh_cami.lua")
+AddCSLuaFile()
+local nadmin = {}
+
+--[[
+Groups is a table of
+["group_name"] = {
+ nadmin :: bool --Wether the group was created by nAdmin or not
+ --nAdmin will only allow you to delete groups
+ --that were created with it. You cannot delete
+ --groups that were created with another mod.
+
+ group :: CAMI_USERGROUP -- the usergroup table given by CAMI,
+ -- see sh_cami.lua for details.
+
+ src :: string --The source of the usergroup, can be "cami", nAdmin,
+ --or the name of the mod that introduced the usergroup.
+
+ privileges :: table --An array of ["privilege_name"] = true, for
+ --each privilege the group has
+}
+]]
+nadmin.groups = {}
+for _,v in pairs(CAMI.GetUsergroups()) do
+ nadmin.groups[v.Name] = {
+ nadmin = false,
+ group = v,
+ src = "cami",
+ privileges = {},
+ }
+ for _,privilege in pairs(CAMI.GetPrivileges()) do
+ if privilege.MinAccess == v.Name then
+ nadmin.groups[v.Name].privileges[privilege.Name] = true
+ end
+ end
+end
+--[[
+Players is a table of
+[player_steamid] = {
+ group :: CAMI_USERGROUP --The usergroup table given by CAMI that
+ --the player is a part of, see sh_cami.lua for
+ --details
+
+ last_name :: string --The last name that the player joined the server
+ --with, this is used to set player's permissions
+ --even when the player is offline.
+]]
+nadmin.players = {}
+nadmin.privileges = CAMI.GetPrivileges()
+
+function nadmin.AddUserGroup(src,usergroup)
+ nadmin.groups[usergroup.Name] = {
+ nadmin = src == "nadmin",
+ group = usergroup,
+ src = src,
+ privileges = {}
+ }
+end
+
+function nadmin.DeleteUserGroup(name,src)
+ nadmin.groups[name] = nil
+end
+
+function nadmin.save_config()
+ if not SERVER then return end
+ local file_parts = {"return {"}
+
+ --Save groups
+ table.insert(file_parts,"groups = {")
+ for groupname, group in pairs(nadmin.groups) do
+ if group.nadmin then
+ local privileges_tbl = {}
+ for privilege_name,_ in pairs(group.privileges) do
+ table.insert(privileges_tbl,string.format("[%q] = true",privilege_name))
+ end
+ table.insert(file_parts,string.format([[
+ [%q] = {
+ name = %q,
+ inherits = %q,
+ privileges = {%s}
+ },]],groupname, group.group.Name, group.group.Inherits, table.concat(privileges_tbl,",")))
+ end
+ end
+ table.insert(file_parts,"},")
+
+ --Save players
+ table.insert(file_parts,"players = {")
+ for playerid, player in pairs(nadmin.players) do
+ table.insert(file_parts,string.format([[
+ [%q] = {
+ last_name = %q,
+ group = %q
+ },]], playerid, player.last_name, player.group))
+ end
+ table.insert(file_parts,"},")
+
+ --Finish off
+ table.insert(file_parts,"}")
+ --And save to file
+ file.Write("nadmin.txt",table.concat(file_parts,"\n"))
+end
+
+--Notify client of changes to the groups table
+hook.Add("CAMI.OnUsergroupRegistered","nadmin_OnUserGroupRegistered",function(usergroup,src)
+ src = src or ""
+ nadmin.AddUserGroup(src,usergroup)
+ if SERVER then
+ net.Start("nadmin_create_group")
+ net.WriteString(usergroup.Name)
+ net.WriteString(usergroup.Inherits or "users") --Some mods call this hook without an "Inherits"
+ net.WriteString(src)
+ net.Broadcast()
+ nadmin.save_config()
+ end
+end)
+
+hook.Add("CAMI.OnUsergroupUnregistered","nadmin_OnUserGroupUnregistered",function(usergroup,src)
+ nadmin.DeleteUserGroup(usergroup.Name, src)
+ if SERVER then
+ net.Start("nadmin_delete_group")
+ net.WriteString(usergroup.Name)
+ net.Broadcast()
+ nadmin.save_config()
+ end
+end)
+
+hook.Add("CAMI.PlayerUsergroupChanged","nadmin_PlayerUsergroupChanged",function(ply,from,to,src)
+ local sid = ply:SteamID64()
+ nadmin.players[sid] = nadmin.players[sid] or {}
+ nadmin.players[sid].group = to
+ if SERVER then
+ net.Start("nadmin_update_player")
+ net.WriteEntity(ply)
+ net.WriteString(to)
+ net.Broadcast()
+ nadmin.save_config()
+ end
+end)
+
+hook.Add("CAMI.OnPrivilegeRegistered", "nadmin_OnPrivilegeRegistered", function(privilege)
+ nadmin.privileges[privilege.Name] = privilege
+ nadmin.save_config()
+end)
+
+hook.Add("CAMI.OnPrivilegeUnregistered", "nadmin_OnPrivilegeUnregistered", function(privilege)
+ nadmin.privileges[privilege.Name] = nil
+end)
+
+hook.Add("CAMI.PlayerHasAccess","nadmin_PlayerHasAccess",function(ply,name,callback,target,extra)
+ if (not ply) or (not ply:IsValid()) then return end
+ local sid = ply:SteamID64()
+ if not nadmin.players[sid] then return end
+ local group = nadmin.players[ply:SteamID64()].group
+ if group and type(group) == "table" and group.nadmin and group.privileges[name] then
+ return true
+ end
+end)
+
+hook.Add("CAMI.SteamIDHasAccess","nadmin_SteamIDHasAccess",function(id,privilege,callback,target,extra)
+ local group = nadmin.players[id].group
+ if group and group.nadmin and group.privileges[privilege] then
+ return true
+ end
+end)
+
+return nadmin
diff --git a/lua/autorun/sv_nadmin.lua b/lua/autorun/sv_nadmin.lua
index b581711..50776f4 100644
--- a/lua/autorun/sv_nadmin.lua
+++ b/lua/autorun/sv_nadmin.lua
@@ -1,233 +1,223 @@
-if CLIENT then return end
-include("sh_cami.lua")
-local nadmin = include("sh_nadmin.lua")
-
---Override what print() does, just for this file
-local oldprint = print
-print = function(...)
- local args = {...}
- table.insert(args,1,"[NADMIN]")
- oldprint(unpack(args))
-end
-for _,v in pairs({
- --Server to client
- "nadmin_update_privilege", -- (exists :: bool, privilege :: CAMI_PRIVILEGE)
-
- "nadmin_create_group", -- (name :: string, inherits :: string, source :: string)
- "nadmin_update_group", -- (name :: string, privilege :: string, exists :: bool)
- "nadmin_delete_group", -- (name :: string)
-
- "nadmin_update_player", -- (entity :: player, group :: string)
-
- "nadmin_init_privileges", -- (privileges :: table)
- "nadmin_init_players", -- (players :: table)
- "nadmin_init_groups", -- (groups :: table)
-
- --Client to server
- "nadmin_request_set_user_group", --(player :: entity, group :: string)
- "nadmin_request_create_group", --(group :: string, inherits :: string)
- "nadmin_request_update_group", --(group :: string, privilege :: string, set :: bool)
- "nadmin_request_delete_group", --(group :: string)
-}) do
- util.AddNetworkString(v)
-end
---Load saved groups & privileges
-local groups = nadmin.groups
-local players = nadmin.players
-local privileges = nadmin.privileges
---Delete the HasAccess functions
-for _,privilege in pairs(privileges) do
- privilege.HasAccess = nil
-end
-if file.Exists("nadmin.txt","DATA") then
- local func, err = CompileString(file.Read("nadmin.txt","DATA"), "nadmin.txt")
- local func_sandboxed = setfenv(func,{}) --Empty environment, you can't even print from inside (you could do an infinite loop, I guess)
- local succ, nadmindata = pcall(func_sandboxed)
- if not succ then
- error("Failed to load groups:", nadmindata)
- return --stop loading the file
- end
- local mygroups, myplayers = nadmindata.groups, nadmindata.players
- for groupname, group in pairs(mygroups) do
- local camigroup = {
- Name = group.name,
- Inherits = group.inherits,
- }
- CAMI.RegisterUsergroup(camigroup)
- groups[groupname] = {
- nadmin = true,
- group = camigroup,
- src = "nadmin",
- privileges = group.privileges
- }
- end
-end
-
---[[
-Creates a new group that players can be
-added to. All groups must inherit from a
-group, except for the "user" "admin" and
-"superadmin" groups.
-]]
---(group :: string, inherits :: string)
-local function create_usergroup(name,inherits)
- local group = {
- Name = name,
- Inherits = inherits
- }
- CAMI.RegisterUsergroup(group, "nadmin")
- nadmin.save_config()
-end
-
---[[
-Edits the privileges on a usergroup.
-Players added to the usergroup will
-now have the privilege set.
-]]
---name :: string, privilegename :: string, set :: bool
-local function edit_usergroup(name,privilegename,set)
- if set then
- groups[name].privileges[privilegename] = set
- else
- groups[name].privileges[privilegename] = nil
- end
- net.Start("nadmin_update_group")
- net.WriteString(name)
- net.WriteString(privilegename)
- net.WriteBool(set)
- net.Broadcast()
- nadmin.save_config()
-end
-
---[[
-Deletes a usergroup. Any players assigned
-to the deleted group will be reassigned
-to the usergroup that the deleted group
-inherited from. Any groups that inherited
-from the usergroup in the heiarchy will
-inherit from the group the usergroup
-inherited from.
-]]
---(group :: string)
-local function delete_usergroup(name)
- local inherited_from_name = groups[name].group.Inherits
- local inherited_from = groups[inherited_from_name]
- local group = groups[name]
- for _,v in pairs(players) do
- if v.group == groups[name] then
- v.group = inherited_from
- end
- end
- for _,v in pairs(groups) do
- if v.group.Inherits == group then
- v.group.Inherits = inherited_from
- end
- end
- CAMI.UnregisterUsergroup(group, "nadmin")
- groups[name] = nil
-end
-
-local function set_user_to_group(ply,group)
- local id,name = ply:SteamID64(), ply:Name()
- players[id] = {
- group = group,
- last_name = name
- }
- net.Start("nadmin_update_player")
- net.WriteEntity(ply)
- net.WriteString(group)
- net.Broadcast()
- nadmin.save_config()
-end
-
-local function send_init_info(ply)
- net.Start("nadmin_init_privileges")
- local light_privileges = {}
- for privilege_name,privilege in pairs(privileges) do
- light_privileges[privilege_name] = {
- Description = privilege.Description,
- MinAccess = privilege.MinAccess,
- Name = privilege.Name
- }
- end
- net.WriteTable(light_privileges)
- net.Send(ply)
-
- net.Start("nadmin_init_players")
- net.WriteTable(players)
- net.Send(ply)
-
- net.Start("nadmin_init_groups")
- net.WriteTable(groups)
- net.Send(ply)
-end
-
-net.Receive("nadmin_request_set_user_group",function(len,ply)
- if not ply:IsSuperAdmin() then return end
- local player = net.ReadEntity()
- local group = net.ReadString()
- set_user_to_group(player,group)
-end)
-
-net.Receive("nadmin_request_create_group",function(len,ply)
- if not ply:IsSuperAdmin() then return end
- local groupname = net.ReadString()
- local inherits = net.ReadString()
- create_usergroup(groupname,inherits)
-end)
-
-net.Receive("nadmin_request_update_group",function(len,ply)
- if not ply:IsSuperAdmin() then return end
- local groupname = net.ReadString()
- local privilegename = net.ReadString()
- local set = net.ReadBool()
- edit_usergroup(groupname,privilegename,set)
-end)
-
-net.Receive("nadmin_request_delete_group", function(len,ply)
- if not ply:IsSuperAdmin() then return end
- local group = net.ReadString()
- delete_usergroup(group)
-end)
-
-hook.Add("PlayerInitialSpawn","nadmin_init_tables",function(ply)
- timer.Simple(5,function()
- if players[ply:SteamID64()] == nil then
- local igroup = "user"
- if ply:IsSuperAdmin() then igroup = "superadmin"
- elseif ply:IsAdmin() then igroup = "admin" end
- players[ply:SteamID64()] = {
- group = igroup,
- last_name = ply:Name()
- }
- set_user_to_group(ply,igroup)
- end
- if ply:IsSuperAdmin() then
- send_init_info(ply)
- end
- end)
-end)
-
-concommand.Add("sv_resave", function(ply,cmd,args)
- if not ply:IsSuperAdmin() then return end
- nadmin.save_config()
-end)
-
-concommand.Add("sv_print_privileges", function(ply,cmd,args)
- if not ply:IsSuperAdmin() then return end
- PrintTable(privileges)
-end)
-concommand.Add("sv_print_groups", function(ply,cmd,args)
- if not ply:IsSuperAdmin() then return end
- PrintTable(groups)
-end)
-concommand.Add("sv_print_players", function(ply,cmd,args)
- if not ply:IsSuperAdmin() then return end
- PrintTable(players)
-end)
-concommand.Add("sv_resend_init",function(ply,cmd,args)
- if not ply:IsSuperAdmin() then return end
- send_init_info(ply)
-end)
---Reset the print function
-print = oldprint
+if CLIENT then return end
+include("sh_cami.lua")
+local nadmin = include("sh_nadmin.lua")
+
+--Override what print() does, just for this file
+local oldprint = print
+print = function(...)
+ local args = {...}
+ table.insert(args,1,"[NADMIN]")
+ oldprint(unpack(args))
+end
+for _,v in pairs({
+ --Server to client
+ "nadmin_update_privilege", -- (exists :: bool, privilege :: CAMI_PRIVILEGE)
+
+ "nadmin_create_group", -- (name :: string, inherits :: string, source :: string)
+ "nadmin_update_group", -- (name :: string, privilege :: string, exists :: bool)
+ "nadmin_delete_group", -- (name :: string)
+
+ "nadmin_update_player", -- (entity :: player, group :: string)
+
+ "nadmin_init_privileges", -- (privileges :: table)
+ "nadmin_init_players", -- (players :: table)
+ "nadmin_init_groups", -- (groups :: table)
+
+ --Client to server
+ "nadmin_request_set_user_group", --(player :: entity, group :: string)
+ "nadmin_request_create_group", --(group :: string, inherits :: string)
+ "nadmin_request_update_group", --(group :: string, privilege :: string, set :: bool)
+ "nadmin_request_delete_group", --(group :: string)
+}) do
+ util.AddNetworkString(v)
+end
+--Load saved groups & privileges
+local groups = nadmin.groups
+local players = nadmin.players
+local privileges = nadmin.privileges
+--Delete the HasAccess functions
+for _,privilege in pairs(privileges) do
+ privilege.HasAccess = nil
+end
+if file.Exists("nadmin.txt","DATA") then
+ local func, err = CompileString(file.Read("nadmin.txt","DATA"), "nadmin.txt")
+ local func_sandboxed = setfenv(func,{}) --Empty environment, you can't even print from inside (you could do an infinite loop, I guess)
+ local succ, nadmindata = pcall(func_sandboxed)
+ if not succ then
+ error("Failed to load groups:", nadmindata)
+ return --stop loading the file
+ end
+ local mygroups, myplayers = nadmindata.groups, nadmindata.players
+ for groupname, group in pairs(mygroups) do
+ local camigroup = {
+ Name = group.name,
+ Inherits = group.inherits,
+ }
+ CAMI.RegisterUsergroup(camigroup)
+ groups[groupname] = {
+ nadmin = true,
+ group = camigroup,
+ src = "nadmin",
+ privileges = group.privileges
+ }
+ end
+end
+
+--[[
+Creates a new group that players can be
+added to. All groups must inherit from a
+group, except for the "user" "admin" and
+"superadmin" groups.
+]]
+--(group :: string, inherits :: string)
+local function create_usergroup(name,inherits)
+ local group = {
+ Name = name,
+ Inherits = inherits
+ }
+ CAMI.RegisterUsergroup(group, "nadmin")
+ nadmin.save_config()
+end
+
+--[[
+Edits the privileges on a usergroup.
+Players added to the usergroup will
+now have the privilege set.
+]]
+--name :: string, privilegename :: string, set :: bool
+local function edit_usergroup(name,privilegename,set)
+ if set then
+ groups[name].privileges[privilegename] = set
+ else
+ groups[name].privileges[privilegename] = nil
+ end
+ net.Start("nadmin_update_group")
+ net.WriteString(name)
+ net.WriteString(privilegename)
+ net.WriteBool(set)
+ net.Broadcast()
+ nadmin.save_config()
+end
+
+--[[
+Deletes a usergroup. Any players assigned
+to the deleted group will be reassigned
+to the usergroup that the deleted group
+inherited from. Any groups that inherited
+from the usergroup in the heiarchy will
+inherit from the group the usergroup
+inherited from.
+]]
+--(group :: string)
+local function delete_usergroup(name)
+ assert(groups[name], "Tried to delete a group that doesn't exist:\"" .. name .. "\"")
+ local inherited_from_name = groups[name].group.Inherits
+ local inherited_from = groups[inherited_from_name]
+ local group = groups[name]
+ for _,v in pairs(players) do
+ if v.group == groups[name] then
+ v.group = inherited_from
+ end
+ end
+ for _,v in pairs(groups) do
+ if v.group.Inherits == group then
+ v.group.Inherits = inherited_from
+ end
+ end
+ CAMI.UnregisterUsergroup(group, "nadmin")
+ groups[name] = nil
+ nadmin.save_config()
+end
+
+local function set_user_to_group(ply,group)
+ local id,name = ply:SteamID64(), ply:Name()
+ players[id] = {
+ group = group,
+ last_name = name
+ }
+ net.Start("nadmin_update_player")
+ net.WriteEntity(ply)
+ net.WriteString(group)
+ net.Broadcast()
+ nadmin.save_config()
+end
+
+local function send_init_info(ply)
+ net.Start("nadmin_init_privileges")
+ local light_privileges = {}
+ for privilege_name,privilege in pairs(privileges) do
+ light_privileges[privilege_name] = {
+ Description = privilege.Description,
+ MinAccess = privilege.MinAccess,
+ Name = privilege.Name
+ }
+ end
+ net.WriteTable(light_privileges)
+ net.Send(ply)
+
+ net.Start("nadmin_init_players")
+ net.WriteTable(players)
+ net.Send(ply)
+
+ net.Start("nadmin_init_groups")
+ net.WriteTable(groups)
+ net.Send(ply)
+end
+
+net.Receive("nadmin_request_set_user_group",function(len,ply)
+ if not ply:IsSuperAdmin() then return end
+ local player = net.ReadEntity()
+ local group = net.ReadString()
+ set_user_to_group(player,group)
+end)
+
+net.Receive("nadmin_request_create_group",function(len,ply)
+ if not ply:IsSuperAdmin() then return end
+ local groupname = net.ReadString()
+ local inherits = net.ReadString()
+ create_usergroup(groupname,inherits)
+end)
+
+net.Receive("nadmin_request_update_group",function(len,ply)
+ if not ply:IsSuperAdmin() then return end
+ local groupname = net.ReadString()
+ local privilegename = net.ReadString()
+ local set = net.ReadBool()
+ edit_usergroup(groupname,privilegename,set)
+end)
+
+net.Receive("nadmin_request_delete_group", function(len,ply)
+ if not ply:IsSuperAdmin() then return end
+ local group = net.ReadString()
+ delete_usergroup(group)
+end)
+
+hook.Add("PlayerInitialSpawn","nadmin_init_tables",function(ply)
+ timer.Simple(5,function()
+ if players[ply:SteamID64()] == nil then
+ local igroup = "user"
+ if ply:IsSuperAdmin() then igroup = "superadmin"
+ elseif ply:IsAdmin() then igroup = "admin" end
+ players[ply:SteamID64()] = {
+ group = igroup,
+ last_name = ply:Name()
+ }
+ set_user_to_group(ply,igroup)
+ end
+ if ply:IsSuperAdmin() then
+ send_init_info(ply)
+ end
+ end)
+end)
+
+concommand.Add("sv_resave", function(ply,cmd,args)
+ if not ply:IsSuperAdmin() then return end
+ nadmin.save_config()
+end)
+
+concommand.Add("sv_resend_init",function(ply,cmd,args)
+ if not ply:IsSuperAdmin() then return end
+ send_init_info(ply)
+end)
+--Reset the print function
+print = oldprint
diff --git a/lua/vgui/dtiltedlabel.lua b/lua/vgui/dtiltedlabel.lua
index a0aaf7d..1d34f6b 100644
--- a/lua/vgui/dtiltedlabel.lua
+++ b/lua/vgui/dtiltedlabel.lua
@@ -1,39 +1,39 @@
-local PANEL = {}
-local base = vgui.GetControlTable("DLabel")
-setmetatable(PANEL,{__index=base})
-
---Function stolen from the lua wiki
-function draw.TextRotated( text, x, y, color, font, ang )
- render.PushFilterMag( TEXFILTER.ANISOTROPIC )
- render.PushFilterMin( TEXFILTER.ANISOTROPIC )
- surface.SetFont( font )
- surface.SetTextColor( color )
- surface.SetTextPos( 0, 0 )
- local textWidth, textHeight = surface.GetTextSize( text )
- local rad = -math.rad( ang )
- x = x - ( math.cos( rad ) * textWidth / 2 + math.sin( rad ) * textHeight / 2 )
- y = y + ( math.sin( rad ) * textWidth / 2 + math.cos( rad ) * textHeight / 2 )
- local m = Matrix()
- m:SetAngles( Angle( 0, ang, 0 ) )
- m:SetTranslation( Vector( x, y, 0 ) )
- cam.PushModelMatrix( m )
- surface.DrawText( text )
- cam.PopModelMatrix()
- render.PopFilterMag()
- render.PopFilterMin()
-end
-function PANEL:Paint(w,h)
- local x,y = self:LocalToScreen(0,0)
- print("x",x,"y",y)
- draw.TextRotated(self:GetText(),0,y,Color(0,0,0,255),"DermaDefault",-45)
-end
-function PANEL:GetHeaderHeight()
- return 0--10 * #(self.Header:GetText())
-end
-function PANEL:Init()
-
- --self.Header = vgui.Create( "DButton", self )
- --self.Header.DoClick = function() self:DoClick() end
- --self.Header.DoRightClick = function() self:DoRightClick() end
-end
-vgui.Register("DTiltedLabel", PANEL, "DLabel")
+local PANEL = {}
+local base = vgui.GetControlTable("DLabel")
+setmetatable(PANEL,{__index=base})
+
+--Function stolen from the lua wiki
+function draw.TextRotated( text, x, y, color, font, ang )
+ render.PushFilterMag( TEXFILTER.ANISOTROPIC )
+ render.PushFilterMin( TEXFILTER.ANISOTROPIC )
+ surface.SetFont( font )
+ surface.SetTextColor( color )
+ surface.SetTextPos( 0, 0 )
+ local textWidth, textHeight = surface.GetTextSize( text )
+ local rad = -math.rad( ang )
+ x = x - ( math.cos( rad ) * textWidth / 2 + math.sin( rad ) * textHeight / 2 )
+ y = y + ( math.sin( rad ) * textWidth / 2 + math.cos( rad ) * textHeight / 2 )
+ local m = Matrix()
+ m:SetAngles( Angle( 0, ang, 0 ) )
+ m:SetTranslation( Vector( x, y, 0 ) )
+ cam.PushModelMatrix( m )
+ surface.DrawText( text )
+ cam.PopModelMatrix()
+ render.PopFilterMag()
+ render.PopFilterMin()
+end
+function PANEL:Paint(w,h)
+ local x,y = self:LocalToScreen(0,0)
+ print("x",x,"y",y)
+ draw.TextRotated(self:GetText(),0,y,Color(0,0,0,255),"DermaDefault",-45)
+end
+function PANEL:GetHeaderHeight()
+ return 0--10 * #(self.Header:GetText())
+end
+function PANEL:Init()
+
+ --self.Header = vgui.Create( "DButton", self )
+ --self.Header.DoClick = function() self:DoClick() end
+ --self.Header.DoRightClick = function() self:DoRightClick() end
+end
+vgui.Register("DTiltedLabel", PANEL, "DLabel")