Skip to content

Commit 8bec408

Browse files
Bm0nBmonAffectedArc07
authored
Adds Play Internet Sound (ParadiseSS13#28183)
* death to the OGG * lint * adresses issues * nukes shells * sounds should still stop even if you muted someone * Update code/modules/admin/verbs/playsound.dm Co-authored-by: AffectedArc07 <[email protected]> Signed-off-by: Bm0n <[email protected]> * deconflict * as mentioned * minortypomoment * i prefer this wording * updates catches and moves admin logging.fixes span * fixes another weird edge case with muting admins * 516 support * linters? * further idiot proofing * typescript player update * more typescript player updates --------- Signed-off-by: Bm0n <[email protected]> Co-authored-by: Bmon <[email protected]> Co-authored-by: AffectedArc07 <[email protected]>
1 parent 8e6c2f3 commit 8bec408

File tree

11 files changed

+334
-230
lines changed

11 files changed

+334
-230
lines changed

code/_globalvars/_regexes.dm

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
GLOBAL_DATUM_INIT(filename_forbidden_chars, /regex, regex(@{""|[\\\n\t/?%*:|<>]|\.\."}, "g"))
22
GLOBAL_DATUM_INIT(is_color, /regex, regex("^#\[0-9a-fA-F]{6}$"))
33
GLOBAL_DATUM_INIT(regex_rgb_text, /regex, regex(@"^#?(([0-9a-fA-F]{8})|([0-9a-fA-F]{6})|([0-9a-fA-F]{3}))$"))
4+
GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://"))
45
GLOBAL_PROTECT(filename_forbidden_chars)

code/controllers/configuration/sections/system_configuration.dm

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
var/list/region_map = list()
3131
/// Send a system toast on init completion?
3232
var/toast_on_init_complete = FALSE
33+
/// The URL for a ss13-yt-wrap server (https://github.com/Absolucy/ss13-yt-wrap) to use.
34+
var/ytdlp_url = null
3335

3436
/datum/configuration_section/system_configuration/load_data(list/data)
3537
// Use the load wrappers here. That way the default isnt made 'null' if you comment out the config line
@@ -50,6 +52,7 @@
5052
CONFIG_LOAD_STR(internal_ip, data["internal_ip"])
5153

5254
CONFIG_LOAD_STR(override_map, data["override_map"])
55+
CONFIG_LOAD_STR(ytdlp_url, data["ytdlp_url"])
5356

5457
// Load region overrides
5558
if(islist(data["regional_servers"]))

code/modules/admin/admin_verbs.dm

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ GLOBAL_LIST_INIT(admin_verbs_sounds, list(
8181
/client/proc/play_server_sound,
8282
/client/proc/play_intercomm_sound,
8383
/client/proc/stop_global_admin_sounds,
84-
/client/proc/stop_sounds_global
84+
/client/proc/stop_sounds_global,
85+
/client/proc/play_web_sound
8586
))
8687
GLOBAL_LIST_INIT(admin_verbs_event, list(
8788
/client/proc/object_talk,

code/modules/admin/verbs/playsound.dm

+107
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ GLOBAL_LIST_EMPTY(sounds_cache)
1212
message_admins("[key_name_admin(src)] stopped admin sounds.", 1)
1313
for(var/mob/M in GLOB.player_list)
1414
M << awful_sound
15+
var/client/C = M.client
16+
C?.tgui_panel?.stop_music()
1517

1618
/client/proc/play_sound(S as sound)
1719
set category = "Event"
@@ -127,3 +129,108 @@ GLOBAL_LIST_EMPTY(sounds_cache)
127129
SEND_SOUND(M, sound(null))
128130
var/client/C = M.client
129131
C?.tgui_panel?.stop_music()
132+
133+
/client/proc/play_web_sound()
134+
set category = "Event"
135+
set name = "Play Internet Sound"
136+
if(!check_rights(R_SOUNDS))
137+
return
138+
139+
if(!GLOB.configuration.system.ytdlp_url)
140+
to_chat(src, "<span class='boldwarning'>yt-dlp was not configured, action unavailable</span>") //Check config
141+
return
142+
143+
144+
var/web_sound_input = tgui_input_text(src, "Enter content URL (supported sites only, leave blank to stop playing)", "Play Internet Sound", null)
145+
if(istext(web_sound_input))
146+
var/web_sound_url = ""
147+
var/stop_web_sounds = FALSE
148+
var/list/music_extra_data = list()
149+
if(length(web_sound_input))
150+
web_sound_input = trim(web_sound_input)
151+
if(findtext(web_sound_input, ":") && !findtext(web_sound_input, GLOB.is_http_protocol))
152+
to_chat(src, "<span class='boldwarning'>Non-http(s) URIs are not allowed.</span>")
153+
to_chat(src, "<span class='warning'>For yt-dlp shortcuts like ytsearch: please use the appropriate full url from the website.</span>")
154+
return
155+
156+
// Prepare the body
157+
var/list/request_body = list("url" = web_sound_input)
158+
// Send the request off
159+
var/datum/http_request/media_poll_request = new()
160+
// The fact we are using GET with a body offends me
161+
media_poll_request.prepare(RUSTG_HTTP_METHOD_GET, GLOB.configuration.system.ytdlp_url, json_encode(request_body))
162+
// Start it off and wait
163+
media_poll_request.begin_async()
164+
UNTIL(media_poll_request.is_complete())
165+
var/datum/http_response/media_poll_response = media_poll_request.into_response()
166+
167+
if(media_poll_response.status_code == 200)
168+
var/list/data
169+
try
170+
data = json_decode(media_poll_response.body)
171+
catch(var/exception/e)
172+
to_chat(src, "<span class='boldwarning'>yt-dlp JSON parsing FAILED:</span>")
173+
to_chat(src, "<span class='warning'>[e]: [media_poll_response.body]</span>")
174+
return
175+
176+
if(data["sound_url"])
177+
web_sound_url = data["sound_url"]
178+
var/title = "[data["title"]]"
179+
var/webpage_url = title
180+
if(data["webpage_url"])
181+
webpage_url = "<a href=\"[data["webpage_url"]]\">[title]</a>"
182+
music_extra_data["start"] = data["start"]
183+
music_extra_data["end"] = data["end"]
184+
music_extra_data["link"] = data["webpage_url"]
185+
music_extra_data["title"] = data["title"]
186+
187+
var/res = tgui_alert(src, "Show the title of and link to this song to the players?\n[title]", "Show Info?", list("Yes", "No", "Cancel"))
188+
switch(res)
189+
if("Yes")
190+
log_admin("[key_name(src)] played web sound: [web_sound_input]")
191+
message_admins("[key_name(src)] played web sound: [web_sound_input]")
192+
to_chat(world, "<span class='boldannounceooc'>[src.ckey] played: [webpage_url]</span>")
193+
if("No")
194+
music_extra_data["link"] = "Song Link Hidden"
195+
music_extra_data["title"] = "Song Title Hidden"
196+
music_extra_data["artist"] = "Song Artist Hidden"
197+
log_admin("[key_name(src)] played web sound: [web_sound_input]")
198+
message_admins("[key_name(src)] played web sound: [web_sound_input]")
199+
to_chat(world, "<span class='boldannounceooc'>[src.ckey] played an internet sound</span>")
200+
if("Cancel")
201+
return
202+
203+
SSblackbox.record_feedback("tally", "admin_verb", 1, "Play Internet Sound")
204+
205+
else
206+
to_chat(src, "<span class='boldwarning'>yt-dlp URL retrieval FAILED:</span>")
207+
to_chat(src, "<span class='warning'>[media_poll_response.body]</span>")
208+
209+
else //pressed ok with blank
210+
log_admin("[key_name(src)] stopped web sound")
211+
message_admins("[key_name(src)] stopped web sound")
212+
web_sound_url = null
213+
stop_web_sounds = TRUE
214+
215+
if(web_sound_url && !findtext(web_sound_url, GLOB.is_http_protocol))
216+
to_chat(src, "<span class='boldwarning'>BLOCKED: Content URL not using http(s) protocol</span>", confidential = TRUE)
217+
to_chat(src, "<span class='warning'>The media provider returned a content URL that isn't using the HTTP or HTTPS protocol</span>", confidential = TRUE)
218+
return
219+
220+
if(web_sound_url || stop_web_sounds)
221+
for(var/mob/M in GLOB.player_list)
222+
var/client/C = M.client
223+
var/this_uid = M.client.UID()
224+
if(stop_web_sounds)
225+
C.tgui_panel?.stop_music()
226+
continue
227+
if(C.prefs.sound & SOUND_MIDI)
228+
if(ckey in M.client.prefs.admin_sound_ckey_ignore)
229+
to_chat(C, "<span class='warning'>But [src.ckey] is muted locally in preferences!</span>")
230+
continue
231+
else
232+
C.tgui_panel?.play_music(web_sound_url, music_extra_data)
233+
to_chat(C, "<span class='warning'>(<a href='byond://?src=[this_uid];action=silenceSound'>SILENCE</a>) (<a href='byond://?src=[this_uid];action=muteAdmin&a=[ckey]'>ALWAYS SILENCE THIS ADMIN</a>)</span>")
234+
else
235+
to_chat(C, "<span class='warning'>But Admin MIDIs are disabled in preferences!</span>")
236+
return

code/modules/client/client_procs.dm

+2
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@
192192

193193
if("silenceSound")
194194
usr.stop_sound_channel(CHANNEL_ADMIN)
195+
tgui_panel?.stop_music()
195196
return
196197

197198
if("muteAdmin")
198199
usr.stop_sound_channel(CHANNEL_ADMIN)
200+
tgui_panel?.stop_music()
199201
prefs.admin_sound_ckey_ignore |= href_list["a"]
200202
to_chat(usr, "You will no longer hear admin playsounds from <code>[href_list["a"]]</code>. To remove them, go to Preferences --&gt; <code>Manage Admin Sound Mutes</code>.")
201203
prefs.save_preferences(src)

code/modules/client/preference/preferences_toggles.dm

+1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
set category = "Special Verbs"
323323
set desc = "Silence the current admin midi playing"
324324
usr.stop_sound_channel(CHANNEL_ADMIN)
325+
tgui_panel?.stop_music()
325326
to_chat(src, "The current admin midi has been silenced")
326327

327328
/datum/preference_toggle/toggle_runechat

code/modules/tgui/tgui_panel/audio.dm

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
/datum/tgui_panel/proc/play_music(url, extra_data)
2323
if(!is_ready())
2424
return
25+
if(!findtext(url, GLOB.is_http_protocol))
26+
return
2527
var/list/payload = list()
2628
if(length(extra_data) > 0)
2729
for(var/key in extra_data)

config/example/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ regional_servers = [
751751
]
752752
# Send a toast on server init completion. You probably dont need this on in production
753753
toast_on_init_complete = true
754+
# The URL for a ss13-yt-wrap server (https://github.com/Absolucy/ss13-yt-wrap) to use.
755+
#ytdlp_url = "http://ytdlpserverurlhere"
754756

755757
################################################################
756758

tgui/packages/tgui-panel/audio/player.js

-112
This file was deleted.

0 commit comments

Comments
 (0)