Skip to content

Commit a2cd939

Browse files
committed
Fix #67
* Just abort creating WebAudio receiver if owner isn't valid * Disabled discord because they blocked steam's http headers :\ (If you want discord, get `gmod-chttp` or `gmsv_reqwest`, replace the `HTTP()` and have the server whitelist it.
1 parent 60000a4 commit a2cd939

File tree

3 files changed

+66
-56
lines changed

3 files changed

+66
-56
lines changed

WHITELIST.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This is the default whitelist that webaudio will abide by unless a ``webaudio_wh
1111
| --- | --- | --- | --- | --- |
1212
| Soundcloud | ✔️ | sndcdn.com | Soundcloud api | 🚧 |
1313
| Google Translate | ✔️ | translate.google.com | Google translate api, can be used for tts | 🚧 |
14-
| Discord | ✔️ | cdn.discordapp.com | Discord file uploads, you can post an mp3 and get the link to use it. | https://cdn.discordapp.com/attachments/732861600708690010/866579835706015765/Sound_Chimera.mp3 | 🚧 |
14+
| Discord | | cdn.discordapp.com | Discord file uploads, you can post an mp3 and get the link to use it. Disabled because discord blocked steam http headers :\\. | https://cdn.discordapp.com/attachments/732861600708690010/866579835706015765/Sound_Chimera.mp3 | 🚧 |
1515
| Reddit | 🖼️ | i.redditmedia.com | Reddit media uploads. Think this is for images so might be removed. | 🚧 |
1616
| Reddit | 🖼️ | i.redd.it | Reddit uploads | 🚧 |
1717
| Reddit | 🖼️ | preview.redd.it | Reddit uploads. | 🚧 |

lua/autorun/webaudio.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ local Whitelist = {
534534
-- Google Translate Api, Needs an api key.
535535
simple [[translate.google.com]],
536536

537-
-- Discord
538-
pattern [[cdn[%w-_]*%.discordapp%.com/.+]],
537+
-- Discord ( Disabled because discord blocked steam http headers :\ )
538+
-- pattern [[cdn[%w-_]*%.discordapp%.com/.+]],
539539

540540
-- Reddit
541541
simple [[i.redditmedia.com]],

lua/webaudio/receiver.lua

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ net.Receive("wa_create", function(len)
9494
local id, url, owner = WebAudio.readID(), net.ReadString(), net.ReadEntity()
9595
local verbosity = Verbosity:GetInt()
9696

97+
if not IsValid(owner) then return end -- Owner left ?
9798

98-
local warn
99-
local notify
99+
local warn, notify
100100
if verbosity >= 2 then
101101
-- Very verbose (old default)
102102
warn = wa_warn
@@ -113,15 +113,15 @@ net.Receive("wa_create", function(len)
113113
if not Enabled:GetBool() then
114114
-- Shouldn't happen anymore as net messages won't send to users who have webaudio disabled.
115115
return notify(
116-
"%s(%s) attempted to create a WebAudio object with url [\"%s\"], but you have WebAudio disabled!",
116+
"%s(%s) attempted to create a WebAudio object with url [%q], but you have WebAudio disabled!",
117117
owner:Nick(),
118118
owner:SteamID64() or "multirun",
119119
url
120120
)
121121
end
122122

123123
if not WebAudio.isWhitelistedURL(url) then
124-
return warn("User %s(%s) tried to create unwhitelisted WebAudio object with url [\"%s\"]", owner:Nick(), owner:SteamID64() or "multirun", url)
124+
return warn("User %s(%s) tried to create unwhitelisted WebAudio object with url [%q]", owner:Nick(), owner:SteamID64() or "multirun", url)
125125
end
126126

127127
local is_stream_owner = owner == LocalPlayer()
@@ -139,67 +139,77 @@ net.Receive("wa_create", function(len)
139139
end
140140
end
141141

142-
notify("User %s(%s) created WebAudio object with url [\"%s\"]", owner:Nick(), owner:SteamID64() or "multirun", url)
142+
notify("User %s(%s) created WebAudio object with url [%q]", owner:Nick(), owner:SteamID64() or "multirun", url)
143143

144-
sound.PlayURL(url, "3d noblock noplay", function(bass, errid, errname)
145-
if errid then
144+
http.Fetch(url, function(body, size, headers)
145+
if body:find("#EXTM3U", 1, true) then
146146
streamFailed()
147-
return warn("Error when creating WebAudio receiver with id %d, Error [%s]", id, errname)
147+
return warn("User %s(%s) tried to create WebAudio object with unwhitelisted file format (m3u)", owner:Nick(), owner:SteamID64() or "multirun")
148148
end
149149

150-
if not bass:IsValid() then
151-
streamFailed()
152-
return warn("WebAudio object with id [%d]'s IGModAudioChannel object was null!", id)
153-
end
154-
155-
local self = WebAudio.getFromID(id)
156-
if not ( self and self:IsValid() ) then
157-
bass:Stop()
158-
bass = nil
159-
streamFailed()
150+
sound.PlayURL(url, "3d noblock noplay", function(bass, errid, errname)
151+
if errid then
152+
streamFailed()
153+
return warn("Error when creating WebAudio receiver with id %d, Error [%s]", id, errname)
154+
end
160155

161-
if is_stream_owner then
162-
-- Have it only warn for the owner in preparation for #33
163-
-- Shouldn't be possible right now unless some one sends a destroy net message to a random id with sv lua.
164-
warn("Invalid WebAudio with id [" .. id .. "], did you destroy it before it even loaded?")
156+
if not bass:IsValid() then
157+
streamFailed()
158+
return warn("WebAudio object with id [%d]'s IGModAudioChannel object was null!", id)
165159
end
166-
return
167-
end
168160

169-
if bass:IsBlockStreamed() then
170-
streamFailed()
171-
bass:Stop()
172-
bass = nil
173-
return warn("URL [%s] was incompatible for WebAudio; It is block-streamed!", url)
174-
end
161+
local self = WebAudio.getFromID(id)
162+
if not ( self and self:IsValid() ) then
163+
bass:Stop()
164+
bass = nil
165+
streamFailed()
166+
167+
if is_stream_owner then
168+
-- Have it only warn for the owner in preparation for #33
169+
-- Shouldn't be possible right now unless some one sends a destroy net message to a random id with sv lua.
170+
warn("Invalid WebAudio with id [" .. id .. "], did you destroy it before it even loaded?")
171+
end
172+
return
173+
end
175174

176-
self.bass = bass
177-
self.length = bass:GetLength()
178-
self.filename = bass:GetFileName()
175+
if bass:IsBlockStreamed() then
176+
streamFailed()
177+
bass:Stop()
178+
bass = nil
179+
return warn("URL [%s] was incompatible for WebAudio; It is block-streamed!", url)
180+
end
179181

180-
local changes_awaiting = AwaitingChanges[id]
181-
if changes_awaiting then
182-
updateObject(id, changes_awaiting, true, false)
183-
AwaitingChanges[id] = nil
184-
end
182+
self.bass = bass
183+
self.length = bass:GetLength()
184+
self.filename = bass:GetFileName()
185185

186-
if owner == LocalPlayer() then
187-
if not self:IsValid() then
188-
-- It was destroyed inside of AwaitingChanges. Usually some dude spamming it.
189-
return
186+
local changes_awaiting = AwaitingChanges[id]
187+
if changes_awaiting then
188+
updateObject(id, changes_awaiting, true, false)
189+
AwaitingChanges[id] = nil
190190
end
191-
-- Only send WebAudio info if LocalPlayer is the owner of the WebAudio object. Will also check on server to avoid abuse.
192-
net.Start("wa_info", true)
193-
WebAudio.writeID(id)
194-
net.WriteBool(false)
195-
local continuous = self.length < 0
196-
net.WriteBool(continuous) -- If the stream is continuous, it should return something less than 0.
197-
if not continuous then
198-
net.WriteUInt(self.length, 16)
191+
192+
if owner == LocalPlayer() then
193+
if not self:IsValid() then
194+
-- It was destroyed inside of AwaitingChanges. Usually some dude spamming it.
195+
return
199196
end
200-
net.WriteString(self.filename)
201-
net.SendToServer()
202-
end
197+
-- Only send WebAudio info if LocalPlayer is the owner of the WebAudio object. Will also check on server to avoid abuse.
198+
net.Start("wa_info", true)
199+
WebAudio.writeID(id)
200+
net.WriteBool(false)
201+
local continuous = self.length < 0
202+
net.WriteBool(continuous) -- If the stream is continuous, it should return something less than 0.
203+
if not continuous then
204+
net.WriteUInt(self.length, 16)
205+
end
206+
net.WriteString(self.filename)
207+
net.SendToServer()
208+
end
209+
end)
210+
end, function(err)
211+
streamFailed()
212+
return warn("HTTP error when creating WebAudio receiver with id %d, Error [%q]", id, err)
203213
end)
204214

205215
WebAudio.new(url, owner, nil, id) -- Register object

0 commit comments

Comments
 (0)