mirror of
https://github.com/Grocel/3D-Stream-Radio.git
synced 2025-03-04 03:03:07 -05:00
Added better URL logging with less spam. Fixed Lua error.
This commit is contained in:
parent
47990e1939
commit
d4716dc4dd
@ -1,2 +1,2 @@
|
||||
448
|
||||
1732383526
|
||||
449
|
||||
1733522924
|
||||
|
@ -7,6 +7,7 @@ local StreamRadioLib = StreamRadioLib
|
||||
local LIBNetwork = StreamRadioLib.Network
|
||||
local LIBWire = StreamRadioLib.Wire
|
||||
local LIBUtil = StreamRadioLib.Util
|
||||
local LIBHook = StreamRadioLib.Hook
|
||||
|
||||
local WireLib = WireLib
|
||||
|
||||
@ -50,6 +51,10 @@ function ENT:SetupDataTables()
|
||||
|
||||
StreamRadioLib.RegisterRadio(self)
|
||||
LIBNetwork.SetupDataTables(self)
|
||||
|
||||
self:AddDTNetworkVar( "Entity", "RadioOwner" )
|
||||
self:AddDTNetworkVar( "Entity", "LastUser" )
|
||||
self:AddDTNetworkVar( "Entity", "LastUsingEntity" )
|
||||
end
|
||||
|
||||
function ENT:SetAnim( Animation, Frame, Rate )
|
||||
@ -660,7 +665,14 @@ function ENT:PlayStreamInternal(url, name)
|
||||
end
|
||||
|
||||
function ENT:OnPlayStreamInternal(url, name)
|
||||
-- Override me
|
||||
local owner = self:GetRealRadioOwner()
|
||||
local lastUser = self:GetLastUser()
|
||||
|
||||
if not IsValid(lastUser) then
|
||||
lastUser = owner
|
||||
end
|
||||
|
||||
LIBHook.RunCustom("OnPlayStream", url, name, self, lastUser)
|
||||
end
|
||||
|
||||
function ENT:GetStreamURL()
|
||||
|
@ -618,7 +618,6 @@ function ENT:SetupDataTables()
|
||||
if not g_isLoaded then return end
|
||||
BaseClass.SetupDataTables(self)
|
||||
|
||||
self:AddDTNetworkVar( "Entity", "RadioOwner" )
|
||||
self:AddDTNetworkVar( "Bool", "HasPlaylist" )
|
||||
|
||||
self:AddDTNetworkVar( "Bool", "DisableDisplay", {
|
||||
|
@ -25,8 +25,6 @@ function ENT:SetupDataTables( )
|
||||
|
||||
self:AddDTNetworkVar("Bool", "WireMode")
|
||||
self:AddDTNetworkVar("Bool", "ToolMode")
|
||||
self:AddDTNetworkVar("Entity", "LastUser")
|
||||
self:AddDTNetworkVar("Entity", "LastUsingEntity")
|
||||
self:AddDTNetworkVar("Entity", "MasterRadio")
|
||||
|
||||
local adv_wire = nil
|
||||
|
@ -57,7 +57,9 @@ function LIB.GetLinkButton(text, urlStr)
|
||||
local infoRed = Color(160, 0, 0)
|
||||
|
||||
button.Think = function(this)
|
||||
if oldThink then
|
||||
oldThink(this)
|
||||
end
|
||||
|
||||
local lastGameMenuVisible = this._gameMenuVisible
|
||||
local gameMenuVisible = gui.IsGameUIVisible()
|
||||
@ -124,7 +126,9 @@ function LIB.GetAdminButton(label, ignoreVR)
|
||||
|
||||
local oldThink = button.Think
|
||||
button.Think = function(this)
|
||||
if oldThink then
|
||||
oldThink(this)
|
||||
end
|
||||
|
||||
local changeAdmin, isAdmin = handleAdmin(this)
|
||||
local changeVR, isVR = handleVR(this)
|
||||
@ -447,7 +451,10 @@ function LIB.PatchComboBox(combobox, label)
|
||||
|
||||
local oldSetText = combobox.SetText
|
||||
combobox.SetText = function(this, ...)
|
||||
if oldSetText then
|
||||
oldSetText(this, ...)
|
||||
end
|
||||
|
||||
StreamRadioLib.Timedcall(updateIcon)
|
||||
end
|
||||
|
||||
|
@ -111,10 +111,17 @@ local function AddSecurityMenuPanel(CPanel)
|
||||
|
||||
subpanel:AddItem(LIBMenu.GetSpacerLine())
|
||||
|
||||
subpanel:CheckBox(
|
||||
local urlLogCombobox, urlLogLabel = subpanel:ComboBox(
|
||||
"Log stream URLs to console",
|
||||
"sv_streamradio_url_request_log_enable"
|
||||
"sv_streamradio_url_log_mode"
|
||||
)
|
||||
StreamRadioLib.Menu.PatchComboBox(urlLogCombobox, urlLogLabel)
|
||||
|
||||
urlLogCombobox:SetSortItems(false)
|
||||
urlLogCombobox:AddChoice("No logging", 0, false, "icon16/collision_off.png")
|
||||
urlLogCombobox:AddSpacer()
|
||||
urlLogCombobox:AddChoice("Log online URLs only", 1, false, "icon16/page_world.png")
|
||||
urlLogCombobox:AddChoice("Log all URLs", 2, false, "icon16/world.png")
|
||||
|
||||
local urlWhitelistCombobox, urlWhitelistLabel = subpanel:ComboBox(
|
||||
"URL Whitelist",
|
||||
|
@ -1,7 +1,7 @@
|
||||
local StreamRadioLib = StreamRadioLib
|
||||
|
||||
local g_allowSpectrum = false
|
||||
local g_enableUrlRequestLog = false
|
||||
local g_streamUrlLogMode = 1
|
||||
local g_enableUrlWhitelist = true
|
||||
local g_enableUrlWhitelistOnCFCWhitelist = true
|
||||
local g_enableUrlWhitelistTrustAdminRadios = true
|
||||
@ -15,11 +15,11 @@ local g_cvMaxServerSpectrum = CreateConVar(
|
||||
"Sets the maximum count of radios that can have advanced wire outputs such as FFT spectrum or song tags. 0 = Off, Default: 5"
|
||||
)
|
||||
|
||||
local g_cvUrlRequestLogEnable = CreateConVar(
|
||||
"sv_streamradio_url_request_log_enable",
|
||||
local g_cvStreamUrlLogMode = CreateConVar(
|
||||
"sv_streamradio_url_log_mode",
|
||||
"1",
|
||||
bit.bor( FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_GAMEDLL, FCVAR_REPLICATED ),
|
||||
"Log requested stream URLs to console. Always logs on developer > 0. 0 = Disable, 1 = Enable, Default: 1"
|
||||
"Log stream URLs to console. Always logs all URLs on developer > 0. 0 = Disable, 1 = Online URLs only, 2 = All URLs, Default: 1"
|
||||
)
|
||||
|
||||
local g_cvUrlWhitelistEnable = CreateConVar(
|
||||
@ -72,29 +72,24 @@ function StreamRadioLib.AllowSpectrum()
|
||||
return g_allowSpectrum
|
||||
end
|
||||
|
||||
function StreamRadioLib.IsUrlRequestLogEnabled()
|
||||
if not g_enableUrlRequestLog then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
function StreamRadioLib.IsUrlWhitelistEnabled()
|
||||
if not g_enableUrlWhitelist then return false end
|
||||
return true
|
||||
return g_enableUrlWhitelist
|
||||
end
|
||||
|
||||
function StreamRadioLib.IsUrlWhitelistEnabledOnCFCWhitelist()
|
||||
if not g_enableUrlWhitelistOnCFCWhitelist then return false end
|
||||
return true
|
||||
return g_enableUrlWhitelistOnCFCWhitelist
|
||||
end
|
||||
|
||||
function StreamRadioLib.IsUrlWhitelistAdminRadioTrusted()
|
||||
if not g_enableUrlWhitelistTrustAdminRadios then return false end
|
||||
return true
|
||||
return g_enableUrlWhitelistTrustAdminRadios
|
||||
end
|
||||
|
||||
function StreamRadioLib.GetStreamLogMode()
|
||||
return g_streamUrlLogMode
|
||||
end
|
||||
|
||||
function StreamRadioLib.GetRebuildCommunityPlaylistsMode()
|
||||
local mode = g_cvRebuildCommunityPlaylists:GetInt()
|
||||
|
||||
mode = math.Clamp(mode, 0, 2)
|
||||
|
||||
return mode
|
||||
@ -110,11 +105,15 @@ local function calcAllowSpectrum()
|
||||
return StreamRadioLib.GetStreamingRadioCount() < max
|
||||
end
|
||||
|
||||
local function calcEnableUrlRequestLog()
|
||||
if StreamRadioLib.Util.IsDebug() then return true end
|
||||
if not g_cvUrlRequestLogEnable:GetBool() then return false end
|
||||
local function calcStreamUrlLogMode()
|
||||
if StreamRadioLib.Util.IsDebug() then
|
||||
return StreamRadioLib.LOG_STREAM_URL_ALL
|
||||
end
|
||||
|
||||
return true
|
||||
local mode = g_cvStreamUrlLogMode:GetInt()
|
||||
mode = math.Clamp(mode, 0, 2)
|
||||
|
||||
return mode
|
||||
end
|
||||
|
||||
local function calcUrlWhitelistEnabled()
|
||||
@ -159,7 +158,7 @@ StreamRadioLib.Hook.Add("Think", "ConvarsUpdate", function()
|
||||
|
||||
if g_lastThink < now then
|
||||
g_allowSpectrum = calcAllowSpectrum()
|
||||
g_enableUrlRequestLog = calcEnableUrlRequestLog()
|
||||
g_streamUrlLogMode = calcStreamUrlLogMode()
|
||||
|
||||
local old_enableUrlWhitelist = g_enableUrlWhitelist
|
||||
local old_enableUrlWhitelistOnCFCWhitelist = g_enableUrlWhitelistOnCFCWhitelist
|
||||
|
@ -134,9 +134,12 @@ Online content:
|
||||
StreamRadioLib.STREAM_URL_INFO = string.gsub(StreamRadioLib.STREAM_URL_INFO, "\r", "")
|
||||
StreamRadioLib.STREAM_URL_INFO = string.Trim(StreamRadioLib.STREAM_URL_INFO)
|
||||
|
||||
|
||||
StreamRadioLib.STREAM_URL_MAX_LEN_ONLINE = 480
|
||||
StreamRadioLib.STREAM_URL_MAX_LEN_OFFLINE = 260
|
||||
|
||||
StreamRadioLib.LOG_STREAM_URL_ALL = 2
|
||||
StreamRadioLib.LOG_STREAM_URL_ONLINE = 1
|
||||
StreamRadioLib.LOG_STREAM_URL_NONE = 0
|
||||
|
||||
return true
|
||||
|
||||
|
@ -1,9 +1,48 @@
|
||||
local StreamRadioLib = StreamRadioLib
|
||||
|
||||
local LIBNet = StreamRadioLib.Net
|
||||
local LIBUrl = StreamRadioLib.Url
|
||||
local LIBHook = StreamRadioLib.Hook
|
||||
local LIBPrint = StreamRadioLib.Print
|
||||
|
||||
LIBNet.Receive("Control", function( len, ply )
|
||||
local trace = StreamRadioLib.Trace( ply )
|
||||
StreamRadioLib.Control(ply, trace, net.ReadBool())
|
||||
end)
|
||||
|
||||
LIBHook.AddCustom("OnPlayStream", "UrlLogging", function(url, name, ent, user)
|
||||
local mode = StreamRadioLib.GetStreamLogMode()
|
||||
|
||||
if mode == StreamRadioLib.LOG_STREAM_URL_NONE then
|
||||
return
|
||||
end
|
||||
|
||||
local offline = LIBUrl.IsOfflineURL(url)
|
||||
if mode == StreamRadioLib.LOG_STREAM_URL_ONLINE and offline then
|
||||
return
|
||||
end
|
||||
|
||||
if name == "" then
|
||||
name = url
|
||||
end
|
||||
|
||||
local nameHasUrl = false
|
||||
|
||||
if string.find(name, url, 0, true) then
|
||||
nameHasUrl = true
|
||||
end
|
||||
|
||||
local msgstring = nil
|
||||
local onlinestring = offline and "file" or "online"
|
||||
|
||||
if nameHasUrl then
|
||||
msgstring = LIBPrint.Format("STREAM - Radio '%s' plays %s => %s", ent, onlinestring, name)
|
||||
else
|
||||
msgstring = LIBPrint.Format("STREAM - Radio '%s' plays %s => %s: %s", ent, onlinestring, name, url)
|
||||
end
|
||||
|
||||
LIBPrint.Log(user, msgstring)
|
||||
end)
|
||||
|
||||
return true
|
||||
|
||||
|
@ -677,27 +677,8 @@ local function BuildWhitelistInternal()
|
||||
LIBFilesystem.Find("", recursiveLookup)
|
||||
end
|
||||
|
||||
local function AddUrlLogger()
|
||||
LIBHook.AddCustom("UrlIsAllowed", "UrlLogging", function(url, ply, ent)
|
||||
if not StreamRadioLib.IsUrlRequestLogEnabled() then
|
||||
return
|
||||
end
|
||||
|
||||
local msgstring = nil
|
||||
|
||||
if IsValid(ent) then
|
||||
msgstring = LIBPrint.Format("STREAM URL - Requested via %s: %s", tostring(ent), url)
|
||||
else
|
||||
msgstring = LIBPrint.Format("STREAM URL - Requested: %s", url)
|
||||
end
|
||||
|
||||
LIBPrint.Log(ply, msgstring)
|
||||
end)
|
||||
end
|
||||
|
||||
function LIB.Load()
|
||||
BuildWhitelistInternal()
|
||||
AddUrlLogger()
|
||||
end
|
||||
|
||||
function LIB.BuildWhitelist()
|
||||
|
Loading…
Reference in New Issue
Block a user