Skip to content

Commit

Permalink
Improved load order, new command
Browse files Browse the repository at this point in the history
Made the admin system initialize for the first time in GM:PostGamemodeLoaded, so that a new hook can be properly utilized; any successive reloads using the reload commands will reload as normal
This new hook allows a server to further fine-tune what is available, and is "BAdmin.AddCommand"; it passes the command name and the settings for it along, and has 3 total returns for controlling it. First is a boolean to overall control whether or not the command should even be added, and the second is a boolean to control overriding settings using the third return
Each of these will modify the console output accordingly, to keep you apprised of any modifications to commands

Also added a new command to use the new(ish) physenv.SetPhysicsPaused function, to overall stop physics from iterating incase someone is being unruly.
  • Loading branch information
LiddulBOFH committed Jan 23, 2025
1 parent a4cf1d6 commit 0d0a344
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 31 deletions.
71 changes: 46 additions & 25 deletions lua/autorun/badmin_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,6 @@ if SERVER then
end
local Load = BAdmin.Utilities.loadFile

-- Core folder will always load first, afterwards anything in "lua/badmin/addon" will be loaded, order depending on operating system

MsgN("+ Loading core files...")
Load("badmin/core")

BAdmin.Utilities.cullBanList()

-- Load our own commands first
MsgN("+ Adding core commands...")
Load("badmin/corecommands")

-- Load any command files that the current gamemode might have, if they opt to write any
MsgN("+ Adding gamemode commands...")
Load(engine.ActiveGamemode() .. "/badmin/addon")

-- Load any command files that another addon might have
MsgN("+ Adding addon commands...")
Load("badmin/addon")

MsgN("+ Finished adding commands!")

----------------------------------------------------------------------------------------------------------------
-- autocomplete networking
----------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -212,8 +191,13 @@ if SERVER then
BAdmin.Autocomplete.CMDData[k] = Data
end
end

BAdmin.Autocomplete.build()

timer.Simple(0.5,function()
BAdmin.Autocomplete.broadcast()
end)

-- Broadcasts autocomplete data to all of the players
function BAdmin.Autocomplete.broadcast()
net.Start("BAdmin.commandList")
Expand All @@ -230,10 +214,6 @@ if SERVER then
net.Send(ply)
end

timer.Simple(0.5,function()
BAdmin.Autocomplete.broadcast()
end)

net.Receive("BAdmin.requestCommands",function(_,ply) -- also the first breathing moment the player can do anything
BAdmin.Utilities.initialRank(ply)

Expand Down Expand Up @@ -273,6 +253,47 @@ if SERVER then
BAdmin.Utilities.initialRank(ply)
end)

-- Core folder will always load first, afterwards anything in "lua/badmin/addon" will be loaded, order depending on operating system

local function LoadBM()
MsgN("+ Loading core files...")
Load("badmin/core")

BAdmin.Utilities.cullBanList()

-- Load our own commands first
MsgN("+ Adding core commands...")
Load("badmin/corecommands")

-- Load any command files that the current gamemode might have, if they opt to write any
MsgN("+ Adding gamemode commands...")
Load(engine.ActiveGamemode() .. "/badmin/addon")

-- Load any command files that another addon might have
MsgN("+ Adding addon commands...")
Load("badmin/addon")

MsgN("+ Finished adding commands!")

BAdmin.Autocomplete.build()

timer.Simple(0.5,function()
BAdmin.Autocomplete.broadcast()
end)
end

hook.Add("PostGamemodeLoaded", "BAdmin.PostGamemodeLoad", function()
LoadBM()

BAdmin.Initialized = true

hook.Remove("PostGamemodeLoaded", "BAdmin.PostGamemodeLoad")
end)

if BAdmin.Initialized then
LoadBM()
end

MsgN("Finished loading BAdmin!")
MsgN("+-----------END BADMIN-----------+")
elseif CLIENT then --------------------------------------------------------
Expand Down
33 changes: 28 additions & 5 deletions lua/badmin/core/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ local BAdmin = BAdmin

MsgN("+ Loading command system...")

--[[
When a command is being added, a hook will also be run before anything is truly added
BAdmin.AddCommand
Args: Command name (string), Settings (table)
Return: Disable (boolean), Override (boolean), NewSettings (table)
]]

--[[ Variables for the commands
MinimumPrivilege | 0 - User (anyone, also is default if this is left out), 1 - Admin, 2 - Superadmin, 3 - RCON or Host of localhost server
CanTargetEqual | Whether the player can target an equally ranked person
Expand Down Expand Up @@ -37,13 +48,25 @@ MsgN("+ Loading command system...")
}
-- This calls the built-in function to create the command, where it can be seen with autocomplete and usable by the approriate players
BAdmin.Utilities.addCommand("kick",callfunc,cmdSettings)
BAdmin.Utilities.addCommand(
"kick", -- The command string itself
callfunc, -- The function defined above
cmdSettings, -- The settings defined above
false -- Special boolean for ignoring the hook.Run check, leave false except for extremely special commands (like the force reload ones)
)
]]

function BAdmin.Utilities.addCommand(cmdString,func,settings)
function BAdmin.Utilities.addCommand(cmdString, func, settings, forceDefine)
local CMDData = {}

if not forceDefine then
local Disable, Override, NewSettings = hook.Run("BAdmin.AddCommand", cmdString, settings)

if Disable then MsgN("X Blocked " .. cmdString) return end
if Override then MsgN("V Overridden settings for " .. cmdString) table.Merge(settings, NewSettings, false) end
end

table.Merge(CMDData,settings)
CMDData["func"] = func

Expand Down Expand Up @@ -128,7 +151,7 @@ cmdSettings = {
}

-- This calls the built-in function to create the command, where it can be seen with autocomplete and usable by the approriate players
BAdmin.Utilities.addCommand("@@ba_reload",callfunc,cmdSettings)
BAdmin.Utilities.addCommand("@@ba_reload", callfunc, cmdSettings, true)


--- Individual reload list
Expand All @@ -148,7 +171,7 @@ cmdSettings = {
["MinimumPrivilege"] = 2,
["RCONCanUse"] = true
}
BAdmin.Utilities.addCommand("@@ba_indreloadlist",callfunc,cmdSettings)
BAdmin.Utilities.addCommand("@@ba_indreloadlist", callfunc, cmdSettings, true)


--- Individual reload command
Expand All @@ -171,4 +194,4 @@ cmdSettings = {
["MinimumPrivilege"] = 2,
["RCONCanUse"] = true
}
BAdmin.Utilities.addCommand("@@ba_indreload",callfunc,cmdSettings)
BAdmin.Utilities.addCommand("@@ba_indreload", callfunc, cmdSettings, true)
19 changes: 18 additions & 1 deletion lua/badmin/corecommands/plymgmt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,29 @@ function callfunc(ply,args) -- Freezing the whole map
return true
end
cmdSettings = {
["Help"] = "Freezes the entire map in props.",
["Help"] = "Freezes all of the props across the map.",
["MinimumPrivilege"] = 2,
["RCONCanUse"] = true
}
BAdmin.Utilities.addCommand("freezemap",callfunc,cmdSettings)

-- Toggle physics

function callfunc(ply,args) -- Freezing the whole map

physenv.SetPhysicsPaused(not physenv.GetPhysicsPaused())

BAdmin.Utilities.broadcastPrint({Color(255,127,127),BAdmin.Utilities.checkName(ply),Color(200,200,200)," just toggled the physics simulation!"})

return true
end
cmdSettings = {
["Help"] = "Toggles physics sim for the whole server.",
["MinimumPrivilege"] = 2,
["RCONCanUse"] = true
}
BAdmin.Utilities.addCommand("togglephysics",callfunc,cmdSettings)

--======== Set Jail Position

function callfunc(ply,args) -- Jail position
Expand Down

0 comments on commit 0d0a344

Please sign in to comment.