Initial commit
This commit is contained in:
34
gamemodes/darkrp/gamemode/modules/logging/cl_init.lua
Normal file
34
gamemodes/darkrp/gamemode/modules/logging/cl_init.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
--[[---------------------------------------------------------------------------
|
||||
Log a message to console
|
||||
---------------------------------------------------------------------------]]
|
||||
local function AdminLog(um)
|
||||
local colour = Color(um:ReadShort(), um:ReadShort(), um:ReadShort())
|
||||
local text = DarkRP.deLocalise(um:ReadString() .. "\n")
|
||||
|
||||
MsgC(Color(255, 0, 0), "[" .. GAMEMODE.Name .. "] ", colour, text)
|
||||
|
||||
hook.Call("DarkRPLogPrinted", nil, text, colour)
|
||||
end
|
||||
usermessage.Hook("DRPLogMsg", AdminLog)
|
||||
|
||||
--[[---------------------------------------------------------------------------
|
||||
Interface
|
||||
---------------------------------------------------------------------------]]
|
||||
DarkRP.hookStub{
|
||||
name = "DarkRPLogPrinted",
|
||||
description = "Called when a log has printed in console.",
|
||||
realm = "Client",
|
||||
parameters = {
|
||||
{
|
||||
name = "text",
|
||||
description = "The actual log.",
|
||||
type = "string"
|
||||
},
|
||||
{
|
||||
name = "colour",
|
||||
description = "The colour of the printed log.",
|
||||
type = "Color"
|
||||
}
|
||||
},
|
||||
returns = {}
|
||||
}
|
||||
26
gamemodes/darkrp/gamemode/modules/logging/sv_interface.lua
Normal file
26
gamemodes/darkrp/gamemode/modules/logging/sv_interface.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
DarkRP.log = DarkRP.stub{
|
||||
name = "log",
|
||||
description = "Log a message in DarkRP",
|
||||
parameters = {
|
||||
{
|
||||
name = "message",
|
||||
description = "The message to log",
|
||||
type = "string",
|
||||
optional = false
|
||||
},
|
||||
{
|
||||
name = "colour",
|
||||
description = "The color of the message in the admin's console. Admins won't see the message if this is not defined.",
|
||||
type = "Color",
|
||||
optional = true
|
||||
},
|
||||
{
|
||||
name = "noFileSave",
|
||||
description = "Whether to write the log to a file or not.",
|
||||
type = "boolean",
|
||||
optional = true
|
||||
}
|
||||
},
|
||||
returns = {},
|
||||
metatable = DarkRP
|
||||
}
|
||||
37
gamemodes/darkrp/gamemode/modules/logging/sv_logging.lua
Normal file
37
gamemodes/darkrp/gamemode/modules/logging/sv_logging.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
local function AdminLog(message, colour, allowedPlys)
|
||||
local RF = RecipientFilter()
|
||||
for _, v in pairs(allowedPlys) do
|
||||
local canHear = hook.Call("canSeeLogMessage", GAMEMODE, v, message, colour)
|
||||
|
||||
if canHear then
|
||||
RF:AddPlayer(v)
|
||||
end
|
||||
end
|
||||
|
||||
umsg.Start("DRPLogMsg", RF)
|
||||
umsg.Short(colour.r)
|
||||
umsg.Short(colour.g)
|
||||
umsg.Short(colour.b) -- Alpha is not needed
|
||||
umsg.String(message)
|
||||
umsg.End()
|
||||
end
|
||||
|
||||
local DarkRPFile
|
||||
function DarkRP.log(text, colour, noFileSave)
|
||||
if colour then
|
||||
CAMI.GetPlayersWithAccess("DarkRP_SeeEvents", fp{AdminLog, text, colour})
|
||||
end
|
||||
|
||||
if not GAMEMODE.Config.logging or noFileSave then return end
|
||||
|
||||
if not DarkRPFile then -- The log file of this session, if it's not there then make it!
|
||||
if not file.IsDir("darkrp_logs", "DATA") then
|
||||
file.CreateDir("darkrp_logs")
|
||||
end
|
||||
|
||||
DarkRPFile = "darkrp_logs/" .. os.date("%m_%d_%Y %I_%M %p") .. ".txt"
|
||||
file.Write(DarkRPFile, os.date() .. "\t" .. text)
|
||||
return
|
||||
end
|
||||
file.Append(DarkRPFile, "\n" .. os.date() .. "\t" .. (text or ""))
|
||||
end
|
||||
Reference in New Issue
Block a user