Skip to content

Commit d4716dc

Browse files
committed
Added better URL logging with less spam. Fixed Lua error.
1 parent 47990e1 commit d4716dc

File tree

10 files changed

+97
-52
lines changed

10 files changed

+97
-52
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
448
2-
1732383526
1+
449
2+
1733522924

lua/entities/base_streamradio.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local StreamRadioLib = StreamRadioLib
77
local LIBNetwork = StreamRadioLib.Network
88
local LIBWire = StreamRadioLib.Wire
99
local LIBUtil = StreamRadioLib.Util
10+
local LIBHook = StreamRadioLib.Hook
1011

1112
local WireLib = WireLib
1213

@@ -50,6 +51,10 @@ function ENT:SetupDataTables()
5051

5152
StreamRadioLib.RegisterRadio(self)
5253
LIBNetwork.SetupDataTables(self)
54+
55+
self:AddDTNetworkVar( "Entity", "RadioOwner" )
56+
self:AddDTNetworkVar( "Entity", "LastUser" )
57+
self:AddDTNetworkVar( "Entity", "LastUsingEntity" )
5358
end
5459

5560
function ENT:SetAnim( Animation, Frame, Rate )
@@ -660,7 +665,14 @@ function ENT:PlayStreamInternal(url, name)
660665
end
661666

662667
function ENT:OnPlayStreamInternal(url, name)
663-
-- Override me
668+
local owner = self:GetRealRadioOwner()
669+
local lastUser = self:GetLastUser()
670+
671+
if not IsValid(lastUser) then
672+
lastUser = owner
673+
end
674+
675+
LIBHook.RunCustom("OnPlayStream", url, name, self, lastUser)
664676
end
665677

666678
function ENT:GetStreamURL()

lua/entities/base_streamradio_gui.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ function ENT:SetupDataTables()
618618
if not g_isLoaded then return end
619619
BaseClass.SetupDataTables(self)
620620

621-
self:AddDTNetworkVar( "Entity", "RadioOwner" )
622621
self:AddDTNetworkVar( "Bool", "HasPlaylist" )
623622

624623
self:AddDTNetworkVar( "Bool", "DisableDisplay", {

lua/entities/sent_streamradio/shared.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ function ENT:SetupDataTables( )
2525

2626
self:AddDTNetworkVar("Bool", "WireMode")
2727
self:AddDTNetworkVar("Bool", "ToolMode")
28-
self:AddDTNetworkVar("Entity", "LastUser")
29-
self:AddDTNetworkVar("Entity", "LastUsingEntity")
3028
self:AddDTNetworkVar("Entity", "MasterRadio")
3129

3230
local adv_wire = nil

lua/streamradio_core/client/cl_menu.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function LIB.GetLinkButton(text, urlStr)
5757
local infoRed = Color(160, 0, 0)
5858

5959
button.Think = function(this)
60-
oldThink(this)
60+
if oldThink then
61+
oldThink(this)
62+
end
6163

6264
local lastGameMenuVisible = this._gameMenuVisible
6365
local gameMenuVisible = gui.IsGameUIVisible()
@@ -124,7 +126,9 @@ function LIB.GetAdminButton(label, ignoreVR)
124126

125127
local oldThink = button.Think
126128
button.Think = function(this)
127-
oldThink(this)
129+
if oldThink then
130+
oldThink(this)
131+
end
128132

129133
local changeAdmin, isAdmin = handleAdmin(this)
130134
local changeVR, isVR = handleVR(this)
@@ -447,7 +451,10 @@ function LIB.PatchComboBox(combobox, label)
447451

448452
local oldSetText = combobox.SetText
449453
combobox.SetText = function(this, ...)
450-
oldSetText(this, ...)
454+
if oldSetText then
455+
oldSetText(this, ...)
456+
end
457+
451458
StreamRadioLib.Timedcall(updateIcon)
452459
end
453460

lua/streamradio_core/client/settings/admin.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,17 @@ local function AddSecurityMenuPanel(CPanel)
111111

112112
subpanel:AddItem(LIBMenu.GetSpacerLine())
113113

114-
subpanel:CheckBox(
114+
local urlLogCombobox, urlLogLabel = subpanel:ComboBox(
115115
"Log stream URLs to console",
116-
"sv_streamradio_url_request_log_enable"
116+
"sv_streamradio_url_log_mode"
117117
)
118+
StreamRadioLib.Menu.PatchComboBox(urlLogCombobox, urlLogLabel)
119+
120+
urlLogCombobox:SetSortItems(false)
121+
urlLogCombobox:AddChoice("No logging", 0, false, "icon16/collision_off.png")
122+
urlLogCombobox:AddSpacer()
123+
urlLogCombobox:AddChoice("Log online URLs only", 1, false, "icon16/page_world.png")
124+
urlLogCombobox:AddChoice("Log all URLs", 2, false, "icon16/world.png")
118125

119126
local urlWhitelistCombobox, urlWhitelistLabel = subpanel:ComboBox(
120127
"URL Whitelist",

lua/streamradio_core/convar.lua

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local StreamRadioLib = StreamRadioLib
22

33
local g_allowSpectrum = false
4-
local g_enableUrlRequestLog = false
4+
local g_streamUrlLogMode = 1
55
local g_enableUrlWhitelist = true
66
local g_enableUrlWhitelistOnCFCWhitelist = true
77
local g_enableUrlWhitelistTrustAdminRadios = true
@@ -15,11 +15,11 @@ local g_cvMaxServerSpectrum = CreateConVar(
1515
"Sets the maximum count of radios that can have advanced wire outputs such as FFT spectrum or song tags. 0 = Off, Default: 5"
1616
)
1717

18-
local g_cvUrlRequestLogEnable = CreateConVar(
19-
"sv_streamradio_url_request_log_enable",
18+
local g_cvStreamUrlLogMode = CreateConVar(
19+
"sv_streamradio_url_log_mode",
2020
"1",
2121
bit.bor( FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_GAMEDLL, FCVAR_REPLICATED ),
22-
"Log requested stream URLs to console. Always logs on developer > 0. 0 = Disable, 1 = Enable, Default: 1"
22+
"Log stream URLs to console. Always logs all URLs on developer > 0. 0 = Disable, 1 = Online URLs only, 2 = All URLs, Default: 1"
2323
)
2424

2525
local g_cvUrlWhitelistEnable = CreateConVar(
@@ -72,29 +72,24 @@ function StreamRadioLib.AllowSpectrum()
7272
return g_allowSpectrum
7373
end
7474

75-
function StreamRadioLib.IsUrlRequestLogEnabled()
76-
if not g_enableUrlRequestLog then return false end
77-
return true
78-
end
79-
8075
function StreamRadioLib.IsUrlWhitelistEnabled()
81-
if not g_enableUrlWhitelist then return false end
82-
return true
76+
return g_enableUrlWhitelist
8377
end
8478

8579
function StreamRadioLib.IsUrlWhitelistEnabledOnCFCWhitelist()
86-
if not g_enableUrlWhitelistOnCFCWhitelist then return false end
87-
return true
80+
return g_enableUrlWhitelistOnCFCWhitelist
8881
end
8982

9083
function StreamRadioLib.IsUrlWhitelistAdminRadioTrusted()
91-
if not g_enableUrlWhitelistTrustAdminRadios then return false end
92-
return true
84+
return g_enableUrlWhitelistTrustAdminRadios
85+
end
86+
87+
function StreamRadioLib.GetStreamLogMode()
88+
return g_streamUrlLogMode
9389
end
9490

9591
function StreamRadioLib.GetRebuildCommunityPlaylistsMode()
9692
local mode = g_cvRebuildCommunityPlaylists:GetInt()
97-
9893
mode = math.Clamp(mode, 0, 2)
9994

10095
return mode
@@ -110,11 +105,15 @@ local function calcAllowSpectrum()
110105
return StreamRadioLib.GetStreamingRadioCount() < max
111106
end
112107

113-
local function calcEnableUrlRequestLog()
114-
if StreamRadioLib.Util.IsDebug() then return true end
115-
if not g_cvUrlRequestLogEnable:GetBool() then return false end
108+
local function calcStreamUrlLogMode()
109+
if StreamRadioLib.Util.IsDebug() then
110+
return StreamRadioLib.LOG_STREAM_URL_ALL
111+
end
116112

117-
return true
113+
local mode = g_cvStreamUrlLogMode:GetInt()
114+
mode = math.Clamp(mode, 0, 2)
115+
116+
return mode
118117
end
119118

120119
local function calcUrlWhitelistEnabled()
@@ -159,7 +158,7 @@ StreamRadioLib.Hook.Add("Think", "ConvarsUpdate", function()
159158

160159
if g_lastThink < now then
161160
g_allowSpectrum = calcAllowSpectrum()
162-
g_enableUrlRequestLog = calcEnableUrlRequestLog()
161+
g_streamUrlLogMode = calcStreamUrlLogMode()
163162

164163
local old_enableUrlWhitelist = g_enableUrlWhitelist
165164
local old_enableUrlWhitelistOnCFCWhitelist = g_enableUrlWhitelistOnCFCWhitelist

lua/streamradio_core/enum.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ Online content:
134134
StreamRadioLib.STREAM_URL_INFO = string.gsub(StreamRadioLib.STREAM_URL_INFO, "\r", "")
135135
StreamRadioLib.STREAM_URL_INFO = string.Trim(StreamRadioLib.STREAM_URL_INFO)
136136

137-
138137
StreamRadioLib.STREAM_URL_MAX_LEN_ONLINE = 480
139138
StreamRadioLib.STREAM_URL_MAX_LEN_OFFLINE = 260
140139

140+
StreamRadioLib.LOG_STREAM_URL_ALL = 2
141+
StreamRadioLib.LOG_STREAM_URL_ONLINE = 1
142+
StreamRadioLib.LOG_STREAM_URL_NONE = 0
143+
141144
return true
142145

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
1+
local StreamRadioLib = StreamRadioLib
2+
13
local LIBNet = StreamRadioLib.Net
4+
local LIBUrl = StreamRadioLib.Url
5+
local LIBHook = StreamRadioLib.Hook
6+
local LIBPrint = StreamRadioLib.Print
27

38
LIBNet.Receive("Control", function( len, ply )
49
local trace = StreamRadioLib.Trace( ply )
510
StreamRadioLib.Control(ply, trace, net.ReadBool())
611
end)
712

13+
LIBHook.AddCustom("OnPlayStream", "UrlLogging", function(url, name, ent, user)
14+
local mode = StreamRadioLib.GetStreamLogMode()
15+
16+
if mode == StreamRadioLib.LOG_STREAM_URL_NONE then
17+
return
18+
end
19+
20+
local offline = LIBUrl.IsOfflineURL(url)
21+
if mode == StreamRadioLib.LOG_STREAM_URL_ONLINE and offline then
22+
return
23+
end
24+
25+
if name == "" then
26+
name = url
27+
end
28+
29+
local nameHasUrl = false
30+
31+
if string.find(name, url, 0, true) then
32+
nameHasUrl = true
33+
end
34+
35+
local msgstring = nil
36+
local onlinestring = offline and "file" or "online"
37+
38+
if nameHasUrl then
39+
msgstring = LIBPrint.Format("STREAM - Radio '%s' plays %s => %s", ent, onlinestring, name)
40+
else
41+
msgstring = LIBPrint.Format("STREAM - Radio '%s' plays %s => %s: %s", ent, onlinestring, name, url)
42+
end
43+
44+
LIBPrint.Log(user, msgstring)
45+
end)
46+
847
return true
948

lua/streamradio_core/server/sv_whitelist.lua

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -677,27 +677,8 @@ local function BuildWhitelistInternal()
677677
LIBFilesystem.Find("", recursiveLookup)
678678
end
679679

680-
local function AddUrlLogger()
681-
LIBHook.AddCustom("UrlIsAllowed", "UrlLogging", function(url, ply, ent)
682-
if not StreamRadioLib.IsUrlRequestLogEnabled() then
683-
return
684-
end
685-
686-
local msgstring = nil
687-
688-
if IsValid(ent) then
689-
msgstring = LIBPrint.Format("STREAM URL - Requested via %s: %s", tostring(ent), url)
690-
else
691-
msgstring = LIBPrint.Format("STREAM URL - Requested: %s", url)
692-
end
693-
694-
LIBPrint.Log(ply, msgstring)
695-
end)
696-
end
697-
698680
function LIB.Load()
699681
BuildWhitelistInternal()
700-
AddUrlLogger()
701682
end
702683

703684
function LIB.BuildWhitelist()

0 commit comments

Comments
 (0)