diff --git a/data_static/streamradio/version.txt b/data_static/streamradio/version.txt index 6febb45..e4a6a3f 100644 --- a/data_static/streamradio/version.txt +++ b/data_static/streamradio/version.txt @@ -1,2 +1,2 @@ -448 -1732383526 +449 +1733522924 diff --git a/lua/entities/base_streamradio.lua b/lua/entities/base_streamradio.lua index b90f5c5..d55e72d 100644 --- a/lua/entities/base_streamradio.lua +++ b/lua/entities/base_streamradio.lua @@ -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() diff --git a/lua/entities/base_streamradio_gui.lua b/lua/entities/base_streamradio_gui.lua index d7ce4d7..755d01f 100644 --- a/lua/entities/base_streamradio_gui.lua +++ b/lua/entities/base_streamradio_gui.lua @@ -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", { diff --git a/lua/entities/sent_streamradio/shared.lua b/lua/entities/sent_streamradio/shared.lua index b78bbdf..68e1bcf 100644 --- a/lua/entities/sent_streamradio/shared.lua +++ b/lua/entities/sent_streamradio/shared.lua @@ -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 diff --git a/lua/streamradio_core/client/cl_menu.lua b/lua/streamradio_core/client/cl_menu.lua index f77bf5c..0346cf3 100644 --- a/lua/streamradio_core/client/cl_menu.lua +++ b/lua/streamradio_core/client/cl_menu.lua @@ -57,7 +57,9 @@ function LIB.GetLinkButton(text, urlStr) local infoRed = Color(160, 0, 0) button.Think = function(this) - oldThink(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) - oldThink(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, ...) - oldSetText(this, ...) + if oldSetText then + oldSetText(this, ...) + end + StreamRadioLib.Timedcall(updateIcon) end diff --git a/lua/streamradio_core/client/settings/admin.lua b/lua/streamradio_core/client/settings/admin.lua index b91cc3f..23a0c94 100644 --- a/lua/streamradio_core/client/settings/admin.lua +++ b/lua/streamradio_core/client/settings/admin.lua @@ -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", diff --git a/lua/streamradio_core/convar.lua b/lua/streamradio_core/convar.lua index 588fad6..f460730 100644 --- a/lua/streamradio_core/convar.lua +++ b/lua/streamradio_core/convar.lua @@ -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 diff --git a/lua/streamradio_core/enum.lua b/lua/streamradio_core/enum.lua index 7f0f647..6324e87 100644 --- a/lua/streamradio_core/enum.lua +++ b/lua/streamradio_core/enum.lua @@ -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 diff --git a/lua/streamradio_core/server/sv_lib.lua b/lua/streamradio_core/server/sv_lib.lua index 872a911..3876419 100644 --- a/lua/streamradio_core/server/sv_lib.lua +++ b/lua/streamradio_core/server/sv_lib.lua @@ -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 diff --git a/lua/streamradio_core/server/sv_whitelist.lua b/lua/streamradio_core/server/sv_whitelist.lua index b549419..a86ec9b 100644 --- a/lua/streamradio_core/server/sv_whitelist.lua +++ b/lua/streamradio_core/server/sv_whitelist.lua @@ -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()