protected void Page_Load(object sender, EventArgs e) { // We store the game in the Session, but use a dictionary keyed by GUIDs which // are stored in the ViewState. This allows the same user in the same browser // to open multiple games in different browser tabs. if (Games == null) { Games = new Dictionary<string, PlayerHandler>(); } if (OutputBuffers == null) { OutputBuffers = new Dictionary<string, OutputBuffer>(); } if (Resources == null) { Resources = new SessionResources(); } m_gameId = (string)ViewState["GameId"]; if (m_gameId == null) { m_gameId = Guid.NewGuid().ToString(); ViewState["GameId"] = m_gameId; } if (Page.IsPostBack) { if (Games.ContainsKey(m_gameId)) { m_player = Games[m_gameId]; } if (!OutputBuffers.ContainsKey(m_gameId)) { // TO DO: Think this only ever happens while debugging? return; } m_buffer = OutputBuffers[m_gameId]; } else { m_buffer = new OutputBuffer(); OutputBuffers.Add(m_gameId, m_buffer); bool saveVisible = IsLoggedIn && (!string.IsNullOrEmpty(Request["id"]) || !string.IsNullOrEmpty(Request["load"])); m_buffer.AddJavaScriptToBuffer("showSaveButton", new BooleanParameter(saveVisible)); } }
protected void Page_Load(object sender, EventArgs e) { // We store the game in the Session, but use a dictionary keyed by GUIDs which // are stored in the ViewState. This allows the same user in the same browser // to open multiple games in different browser tabs. if (Games == null) { Games = new Dictionary <string, PlayerHandler>(); } if (OutputBuffers == null) { OutputBuffers = new Dictionary <string, OutputBuffer>(); } if (Resources == null) { Resources = new SessionResources(); } m_gameId = (string)ViewState["GameId"]; if (m_gameId == null) { m_gameId = Guid.NewGuid().ToString(); ViewState["GameId"] = m_gameId; } if (Page.IsPostBack) { if (Games.ContainsKey(m_gameId)) { m_player = Games[m_gameId]; } if (!OutputBuffers.ContainsKey(m_gameId)) { // TO DO: Think this only ever happens while debugging? return; } m_buffer = OutputBuffers[m_gameId]; } else { m_buffer = new OutputBuffer(m_gameId); OutputBuffers.Add(m_gameId, m_buffer); m_buffer.AddJavaScriptToBuffer("setOutputBufferId", new StringParameter(m_gameId)); } }
protected string GetUI() { return(PlayerHandler.GetUI()); }
private string LoadGame(string gameFile, bool?isCompiled, string id, string folder, string loadData, AzureFileManager.ApiGame apiGameData) { if (string.IsNullOrEmpty(gameFile) && loadData == null) { return("No game specified"); } string rootPath = folder ?? ConfigurationManager.AppSettings["GameFolder"]; string libPath = ConfigurationManager.AppSettings["LibraryFolder"]; string filename; if (Config.ReadGameFileFromAzureBlob) { filename = gameFile; } else { filename = WebPlayer.Play.GetGameFilename(gameFile, rootPath); if (filename == null) { return("Invalid filename"); } } List <string> errors; try { m_player = new PlayerHandler(filename, m_buffer); m_player.LoadData = loadData; m_player.ApiGameData = apiGameData; m_player.GameId = m_gameId; m_player.LibraryFolder = libPath; Games[m_gameId] = m_player; m_player.BeginWait += m_player_BeginWait; m_player.BeginPause += m_player_BeginPause; m_player.ShowMenuDelegate = m_player_ShowMenu; m_player.ShowQuestionDelegate = m_player_ShowQuestion; m_player.AddResource += AddResource; m_player.PlayAudio += m_player_PlayAudio; m_player.StopAudio += m_player_StopAudio; if (Config.ReadGameFileFromAzureBlob) { m_player.ResourceUrlRoot = AzureFileManager.GetResourceUrlRoot(id); } if (m_player.Initialise(out errors, isCompiled)) { Resources.AddGame(m_player.Game); // Successful game start return(m_player.ClearBuffer()); } } catch (Exception ex) { return("<b>Error loading game:</b><br/>" + ex.Message); } string output = string.Empty; if (errors != null) { foreach (string error in errors) { output += error + "<br/>"; } } return(output); }
void m_player_PlayAudio(object sender, PlayerHandler.PlayAudioEventArgs e) { string functionName = null; if (e.Filename.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase)) functionName = "playWav"; if (e.Filename.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase)) functionName = "playMp3"; if (functionName == null) return; string url = m_player.GetURL(e.Filename); m_buffer.AddJavaScriptToBuffer( functionName, new StringParameter(url), new BooleanParameter(e.Synchronous), new BooleanParameter(e.Looped)); }
private string LoadGame(string gameFile, bool? isCompiled, string id, string folder, string loadData, AzureFileManager.ApiGame apiGameData) { if (string.IsNullOrEmpty(gameFile) && loadData == null) { return "No game specified"; } string rootPath = folder ?? ConfigurationManager.AppSettings["GameFolder"]; string libPath = ConfigurationManager.AppSettings["LibraryFolder"]; string filename; if (Config.ReadGameFileFromAzureBlob) { filename = gameFile; } else { filename = WebPlayer.Play.GetGameFilename(gameFile, rootPath); if (filename == null) { return "Invalid filename"; } } List<string> errors; try { m_player = new PlayerHandler(filename, m_buffer); m_player.LoadData = loadData; m_player.ApiGameData = apiGameData; m_player.GameId = m_gameId; m_player.LibraryFolder = libPath; Games[m_gameId] = m_player; m_player.BeginWait += m_player_BeginWait; m_player.BeginPause += m_player_BeginPause; m_player.ShowMenuDelegate = m_player_ShowMenu; m_player.ShowQuestionDelegate = m_player_ShowQuestion; m_player.AddResource += AddResource; m_player.PlayAudio += m_player_PlayAudio; m_player.StopAudio += m_player_StopAudio; if (Config.ReadGameFileFromAzureBlob) { m_player.ResourceUrlRoot = AzureFileManager.GetResourceUrlRoot(id); } if (m_player.Initialise(out errors, isCompiled)) { Resources.AddGame(m_player.Game); // Successful game start return m_player.ClearBuffer(); } } catch (Exception ex) { return "<b>Error loading game:</b><br/>" + ex.Message; } string output = string.Empty; if (errors != null) { foreach (string error in errors) { output += error + "<br/>"; } } return output; }
private string LoadGame(string gameFile) { if (string.IsNullOrEmpty(gameFile)) { return "No game specified"; } // Block attempts to access files outside the GameFolder if (gameFile.Contains("..")) { return "Invalid filename"; } string rootPath = ConfigurationManager.AppSettings["GameFolder"]; string libPath = ConfigurationManager.AppSettings["LibraryFolder"]; string filename = System.IO.Path.Combine(rootPath, gameFile); List<string> errors; try { m_player = new PlayerHandler(filename, m_buffer); m_player.GameId = m_gameId; m_player.LibraryFolder = libPath; m_gamesInSession[m_gameId] = m_player; m_player.BeginWait += m_player_BeginWait; m_player.BeginPause += m_player_BeginPause; m_player.ShowMenuDelegate = m_player_ShowMenu; m_player.ShowQuestionDelegate = m_player_ShowQuestion; m_player.AddResource += AddResource; m_player.PlayAudio += m_player_PlayAudio; m_player.StopAudio += m_player_StopAudio; if (m_player.Initialise(out errors)) { // Successful game start return m_player.ClearBuffer(); } } catch (Exception ex) { return "<b>Error loading game:</b><br/>" + ex.Message; } string output = string.Empty; foreach (string error in errors) { output += error + "<br/>"; } return output; }
protected void Page_Load(object sender, EventArgs e) { string style = Request["style"]; if (!string.IsNullOrEmpty(style)) { if (style == "fluid") { styleLink.Href = "fluid.css"; } } // We store the game in the Session, but use a dictionary keyed by GUIDs which // are stored in the ViewState. This allows the same user in the same browser // to open multiple games in different browser tabs. m_gamesInSession = (Dictionary<string, PlayerHandler>)Session["Games"]; if (m_gamesInSession == null) { m_gamesInSession = new Dictionary<string, PlayerHandler>(); Session["Games"] = m_gamesInSession; } Dictionary<string, OutputBuffer> outputBuffersInSession = (Dictionary<string, OutputBuffer>)Session["OutputBuffers"]; if (outputBuffersInSession == null) { outputBuffersInSession = new Dictionary<string, OutputBuffer>(); Session["OutputBuffers"] = outputBuffersInSession; } m_gameId = (string)ViewState["GameId"]; if (m_gameId == null) { m_gameId = Guid.NewGuid().ToString(); ViewState["GameId"] = m_gameId; } if (Page.IsPostBack) { if (m_gamesInSession.ContainsKey(m_gameId)) { m_player = m_gamesInSession[m_gameId]; } if (!outputBuffersInSession.ContainsKey(m_gameId)) { // TO DO: Think this only ever happens while debugging? return; } m_buffer = outputBuffersInSession[m_gameId]; } else { m_buffer = new OutputBuffer(); outputBuffersInSession.Add(m_gameId, m_buffer); } }
private string LoadGame(string gameFile, string id, string folder) { if (string.IsNullOrEmpty(gameFile)) { return "No game specified"; } string rootPath = folder ?? ConfigurationManager.AppSettings["GameFolder"]; string libPath = ConfigurationManager.AppSettings["LibraryFolder"]; var filename = GetGameFilename(gameFile, rootPath); if (filename == null) { return "Invalid filename"; } List<string> errors; try { m_player = new PlayerHandler(filename, m_buffer, id, SessionManagerLoader.GetSessionManager().GetUser()); m_player.GameId = m_gameId; m_player.LibraryFolder = libPath; Games[m_gameId] = m_player; m_player.BeginWait += m_player_BeginWait; m_player.BeginPause += m_player_BeginPause; m_player.ShowMenuDelegate = m_player_ShowMenu; m_player.ShowQuestionDelegate = m_player_ShowQuestion; m_player.AddResource += AddResource; m_player.PlayAudio += m_player_PlayAudio; m_player.StopAudio += m_player_StopAudio; if (m_player.Initialise(out errors)) { Resources.AddGame(m_player.Game); // Successful game start return m_player.ClearBuffer(); } } catch (Exception ex) { return "<b>Error loading game:</b><br/>" + ex.Message; } string output = string.Empty; foreach (string error in errors) { output += error + "<br/>"; } return output; }