@@ -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