Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gamemode/config/sh_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ nut.config.add("oocLimit", 0, "Character limit per OOC message. 0 means no limit
category = "chat"
})

nut.config.add("oocDelayAdmin", false, "Whether or not OOC chat delay is enabled for admins.", nil, {
nut.config.add("oocDelayAdmin", false, "Whether or not OOC chat delay is enabled for users with the permission \"NS.OOC.BypassDelay\".", nil, {
category = "chat"
})

Expand All @@ -102,7 +102,7 @@ nut.config.add("loocDelay", 0, "The delay before a player can use LOOC chat agai
category = "chat"
})

nut.config.add("loocDelayAdmin", false, "Whether or not LOOC chat delay is enabled for admins.", nil, {
nut.config.add("loocDelayAdmin", false, "Whether or not LOOC chat delay is enabled for users with the permission \"NS.OOC.BypassDelay\".", nil, {
category = "chat"
})

Expand Down
12 changes: 7 additions & 5 deletions gamemode/core/hooks/sv_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,14 @@ function GM:CharacterPreSave(character)
end

function GM:OnServerLog(client, logType, ...)
for _, v in pairs(nut.util.getAdmins()) do

if (hook.Run("CanPlayerSeeLog", v, logType) ~= false) then
nut.log.send(v, nut.log.getString(client, logType, ...))
local vararg = {...}
CAMI.GetPlayersWithAccess("NS.Logs", function(allowedPlys)
for _, v in ipairs(allowedPlys) do
if (hook.Run("CanPlayerSeeLog", v, logType) ~= false) then
nut.log.send(v, nut.log.getString(client, logType, unpack(vararg)))
end
end
end
end)
end

-- this table is based on mdl's prop keyvalue data. FIX IT WILLOX!
Expand Down
46 changes: 35 additions & 11 deletions gamemode/core/libs/sh_chatbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,29 @@ else
end)
end

CAMI.RegisterPrivilege({
Name = "NS.OOC.BypassDelay",
MinAccess = "admin"
})

CAMI.RegisterPrivilege({
Name = "NS.OOC.Shield",
MinAccess = "superadmin"
})

CAMI.RegisterPrivilege({
Name = "NS.OOC.Star",
MinAccess = "admin"
})

CAMI.RegisterPrivilege({
Name = "NS.OOC.Wrench"
})

CAMI.RegisterPrivilege({
Name = "NS.OOC.Heart"
})

-- Add the default chat types here.
do
-- Load the chat types after the configs so we can access changed configs.
Expand Down Expand Up @@ -297,8 +320,10 @@ do
if (delay > 0 and speaker.nutLastOOC) then
local lastOOC = CurTime() - speaker.nutLastOOC

local hasBypassDelayPermission = CAMI.PlayerHasAccess(speaker, "NS.OOC.BypassDelay")

-- Use this method of checking time in case the oocDelay config changes (may not affect admins).
if (lastOOC <= delay and (not speaker:IsAdmin() or speaker:IsAdmin() and nut.config.get("oocDelayAdmin", false))) then
if (lastOOC <= delay and (not hasBypassDelayPermission or hasBypassDelayPermission and nut.config.get("oocDelayAdmin", false))) then
speaker:notifyLocalized("oocDelay", delay - math.ceil(lastOOC))

return false
Expand All @@ -323,13 +348,13 @@ do
-- it's on your own.
if (customIcons[speaker:SteamID()]) then
icon = customIcons[speaker:SteamID()]
elseif (speaker:IsSuperAdmin()) then
elseif (CAMI.PlayerHasAccess(speaker, "NS.OOC.Shield")) then
icon = "icon16/shield.png"
elseif (speaker:IsAdmin()) then
elseif (CAMI.PlayerHasAccess(speaker, "NS.OOC.Star")) then
icon = "icon16/star.png"
elseif (speaker:IsUserGroup("moderator") or speaker:IsUserGroup("operator")) then
elseif (CAMI.PlayerHasAccess(speaker, "NS.OOC.Wrench")) then
icon = "icon16/wrench.png"
elseif (speaker:IsUserGroup("vip") or speaker:IsUserGroup("donator") or speaker:IsUserGroup("donor")) then
elseif (CAMI.PlayerHasAccess(speaker, "NS.OOC.Heart")) then
icon = "icon16/heart.png"
end

Expand All @@ -351,11 +376,13 @@ do
local delay = nut.config.get("loocDelay", 0)

-- Only need to check the time if they have spoken in LOOC chat before.
if (speaker:IsAdmin() and nut.config.get("loocDelayAdmin", false) and delay > 0 and speaker.nutLastLOOC) then
if (delay > 0 and speaker.nutLastLOOC) then
local lastLOOC = CurTime() - speaker.nutLastLOOC

local hasBypassDelayPermission = CAMI.PlayerHasAccess(speaker, "NS.OOC.BypassDelay")

-- Use this method of checking time in case the oocDelay config changes (may not affect admins).
if (lastLOOC <= delay and (not speaker:IsAdmin() or speaker:IsAdmin() and nut.config.get("loocDelayAdmin", false))) then
if (lastLOOC <= delay and (not hasBypassDelayPermission or hasBypassDelayPermission and nut.config.get("loocDelayAdmin", false))) then
speaker:notifyLocalized("loocDelay", delay - math.ceil(lastLOOC))

return false
Expand Down Expand Up @@ -403,13 +430,10 @@ local color_orange = Color(255, 150, 0)

-- Global events.
nut.chat.register("event", {
onCanSay = function(speaker, text)
return speaker:IsAdmin()
end,
onChatAdd = function(speaker, text)
chat.AddText(nut.chat.timestamp(false), color_orange, text)
end,
prefix = {"/event"}
deadCanChat = true
})

-- Why does ULX even have a /me command?
Expand Down
27 changes: 15 additions & 12 deletions gamemode/core/libs/sh_command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@ function nut.command.add(command, data)

-- Store the old onRun because we're able to change it.
if (!data.onCheckAccess) then
-- Check if the command is for basic admins only.
if (data.adminOnly) then
data.onCheckAccess = function(client)
return client:IsAdmin()
end
-- Or if it is only for super administrators.
elseif (data.superAdminOnly) then
data.onCheckAccess = function(client)
return client:IsSuperAdmin()
end
-- Or if we specify a usergroup allowed to use this.
elseif (data.group) then
-- cami is better than this rigmarole, but keep it for compat
if (data.group) then
-- The group property can be a table of usergroups.
if istable(data.group) then
data.onCheckAccess = function(client)
Expand All @@ -46,6 +36,19 @@ function nut.command.add(command, data)
end
end
end

local privilege = "NS.Commands." .. (data.privilege and data.privilege or command)

if (!CAMI.GetPrivilege(privilege)) then
CAMI.RegisterPrivilege({
Name = privilege,
MinAccess = data.adminOnly and "admin" or (data.superAdminOnly and "superadmin" or "user")
})
end

data.onCheckAccess = function(client)
return CAMI.PlayerHasAccess(client, privilege) == true
end
end

local onCheckAccess = data.onCheckAccess
Expand Down
9 changes: 8 additions & 1 deletion gamemode/core/libs/sh_log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ nut.log.color = {
}
local consoleColor = Color(50, 200, 50)

CAMI.RegisterPrivilege({
Name = "NS.Logs",
MinAccess = "admin"
})

if (SERVER) then
if (not nut.db) then
include("sv_database.lua")
Expand Down Expand Up @@ -101,7 +106,9 @@ if (SERVER) then
-- @realm server
function nut.log.addRaw(logString, shouldNotify, flag)
if (shouldNotify) then
nut.log.send(nut.util.getAdmins(), logString, flag)
CAMI.GetPlayersWithAccess("NS.Logs", function(allowedPlys)
nut.log.send(allowedPlys, logString, flag)
end)
end

Msg("[LOG] ", logString.."\n")
Expand Down
Loading