Cache jukebox playlists at round start.

This commit is contained in:
D3athrow
2015-03-24 12:03:53 -05:00
parent e524cad0c3
commit 3f0e7db8c1
3 changed files with 84 additions and 40 deletions

View File

@@ -85,7 +85,7 @@
var/server
var/banappeals
var/wikiurl = "http://baystation12.net/wiki/index.php?title=Main_Page"
var/vgws_base_url = "http://vg13.undo.it" // No hanging slashes.
var/vgws_base_url = "http://ss13.pomf.se" // No hanging slashes.
var/forumurl = "http://baystation12.net/forums/"
var/media_base_url = "" // http://ss13.nexisonline.net/media

View File

@@ -90,6 +90,9 @@ datum/controller/game_controller/proc/setup()
setup_economy()
SetupXenoarch()
cachedamageicons()
world << "\red \b Caching Jukebox playlists..."
load_juke_playlists()
world << "\red \b Caching Jukebox playlists complete."
//if(map && map.dorf)
//mining_surprises = typesof(/mining_surprise/dorf) - /mining_surprise/dorf
//max_secret_rooms += 2

View File

@@ -15,6 +15,85 @@
#define JUKEBOX_RELOAD_COOLDOWN 600 // 60s
var/global/global_playlists = list()
/proc/load_juke_playlists()
for(var/playlist_id in list("bar", "jazz", "rock", "muzak", "emagged", "endgame", "clockwork", "vidyaone", "vidyatwo", "vidyathree", "vidyafour"))
var/url="[config.media_base_url]/index.php?playlist=[playlist_id]"
testing("Updating playlist from [url]...")
// Media Server 2 requires a secret key in order to tell the jukebox
// where the music files are. It's set in config with MEDIA_SECRET_KEY
// and MUST be the same as the media server's.
//
// Do NOT log this, it's like a password.
if(config.media_secret_key!="")
url += "&key=[config.media_secret_key]"
var/response = world.Export(url)
var/list/playlist=list()
if(response)
var/json = file2text(response["CONTENT"])
if("/>" in json)
continue
var/json_reader/reader = new()
reader.tokens = reader.ScanJson(json)
reader.i = 1
var/songdata = reader.read_value()
for(var/list/record in songdata)
playlist += new /datum/song_info(record)
if(playlist.len==0)
continue
global_playlists["[playlist_id]"] = playlist.Copy()
/obj/machinery/media/jukebox/proc/retrieve_playlist(var/playlistid = playlist_id)
playlist_id = playlistid
if(global_playlists["[playlistid]"])
var/list/temp = global_playlists["[playlistid]"]
playlist = temp.Copy()
else
var/url="[config.media_base_url]/index.php?playlist=[playlist_id]"
testing("[src] - Updating playlist from [url]...")
// Media Server 2 requires a secret key in order to tell the jukebox
// where the music files are. It's set in config with MEDIA_SECRET_KEY
// and MUST be the same as the media server's.
//
// Do NOT log this, it's like a password.
if(config.media_secret_key!="")
url += "&key=[config.media_secret_key]"
var/response = world.Export(url)
playlist=list()
if(response)
var/json = file2text(response["CONTENT"])
if("/>" in json)
visible_message("<span class='warning'>\icon[src] \The [src] buzzes, unable to update its playlist.</span>","<em>You hear a buzz.</em>")
stat &= BROKEN
update_icon()
return 0
var/json_reader/reader = new()
reader.tokens = reader.ScanJson(json)
reader.i = 1
var/songdata = reader.read_value()
for(var/list/record in songdata)
playlist += new /datum/song_info(record)
if(playlist.len==0)
visible_message("<span class='warning'>\icon[src] \The [src] buzzes, unable to update its playlist.</span>","<em>You hear a buzz.</em>")
stat &= BROKEN
update_icon()
return 0
visible_message("<span class='notice'>\icon[src] \The [src] beeps, and the menu on its front fills with [playlist.len] items.</span>","<em>You hear a beep.</em>")
else
testing("[src] failed to update playlist: Response null.")
stat &= BROKEN
update_icon()
return 0
global_playlists["[playlistid]"] = playlist.Copy()
if(autoplay)
playing=1
autoplay=0
return 1
// Represents a record returned.
/datum/song_info
var/title = ""
@@ -438,45 +517,7 @@ var/global/loopModeNames=list(
/obj/machinery/media/jukebox/process()
if(!playlist)
var/url="[config.media_base_url]/index.php?playlist=[playlist_id]"
testing("[src] - Updating playlist from [url]...")
// Media Server 2 requires a secret key in order to tell the jukebox
// where the music files are. It's set in config with MEDIA_SECRET_KEY
// and MUST be the same as the media server's.
//
// Do NOT log this, it's like a password.
if(config.media_secret_key!="")
url += "&key=[config.media_secret_key]"
var/response = world.Export(url)
playlist=list()
if(response)
var/json = file2text(response["CONTENT"])
if("/>" in json)
visible_message("<span class='warning'>\icon[src] \The [src] buzzes, unable to update its playlist.</span>","<em>You hear a buzz.</em>")
stat &= BROKEN
update_icon()
return
var/json_reader/reader = new()
reader.tokens = reader.ScanJson(json)
reader.i = 1
var/songdata = reader.read_value()
for(var/list/record in songdata)
playlist += new /datum/song_info(record)
if(playlist.len==0)
visible_message("<span class='warning'>\icon[src] \The [src] buzzes, unable to update its playlist.</span>","<em>You hear a buzz.</em>")
stat &= BROKEN
update_icon()
return
visible_message("<span class='notice'>\icon[src] \The [src] beeps, and the menu on its front fills with [playlist.len] items.</span>","<em>You hear a beep.</em>")
if(autoplay)
playing=1
autoplay=0
else
testing("[src] failed to update playlist: Response null.")
stat &= BROKEN
update_icon()
if(!retrieve_playlist())
return
if(playing)
var/datum/song_info/song