/// <summary> /// Create start HTTP request /// </summary> private async Task<bool> StartOrResumeApp(NvHttp nv, MoonlightStreamConfiguration streamConfig) { XmlQuery serverInfo = new XmlQuery(nv.BaseUrl + "/serverinfo?uniqueid=" + nv.GetUniqueId()); string currentGameString = await serverInfo.ReadXmlElement("currentgame"); if (currentGameString == null) { return false; } string versionString = await serverInfo.ReadXmlElement("appversion"); if (versionString == null) { return false; } serverMajorVersion = Convert.ToInt32(versionString.Substring(0, 1)); byte[] aesIv = streamConfig.GetRiAesIv(); int riKeyId = (int)(((aesIv[0] << 24) & 0xFF000000U) | ((aesIv[1] << 16) & 0xFF0000U) | ((aesIv[2] << 8) & 0xFF00U) | (aesIv[3] & 0xFFU)); string riConfigString = "&rikey=" + PairingCryptoHelpers.BytesToHex(streamConfig.GetRiAesKey()) + "&rikeyid=" + riKeyId; // Launch a new game if nothing is running if (currentGameString == null || currentGameString.Equals("0")) { XmlQuery x = new XmlQuery(nv.BaseUrl + "/launch?uniqueid=" + nv.GetUniqueId() + "&appid=" + context.appId + "&mode=" + streamConfig.GetWidth() + "x" + streamConfig.GetHeight() + "x" + streamConfig.GetFps() + "&additionalStates=1&sops=1" + // FIXME: make sops configurable riConfigString); string sessionStr = await x.ReadXmlElement("gamesession"); if (sessionStr == null || sessionStr.Equals("0")) { return false; } return true; } else { // A game was already running, so resume it // FIXME: Quit and relaunch if it's not the game we came to start XmlQuery x = new XmlQuery(nv.BaseUrl + "/resume?uniqueid=" + nv.GetUniqueId() + riConfigString); string resumeStr = await x.ReadXmlElement("resume"); if (resumeStr == null || resumeStr.Equals("0")) { return false; } return true; } }
/// <summary> /// Unpair from the device /// </summary> private static async Task Unpair(NvHttp nv) { XmlQuery unpair; unpair = new XmlQuery(nv.BaseUrl + "/unpair?uniqueid=" + nv.GetUniqueId()); await unpair.Run(); }
/// <summary> /// Quit Game Event Handler /// </summary> private async Task QuitGame_Common() { Computer selected = (Computer)computerPicker.SelectedItem; // User hasn't selected anything or selected the placeholder if (selected == null || selected.IpAddress == null) { DialogUtils.DisplayDialog(this.Dispatcher, "No machine selected", "Quit Failed"); return; } PairingManager p = new PairingManager(selected); if (await p.QueryPairState() != true) { DialogUtils.DisplayDialog(this.Dispatcher, "Device not paired", "Quit Failed"); return; } try { NvHttp nv = new NvHttp(selected.IpAddress); XmlQuery quit = new XmlQuery(nv.BaseUrl + "/cancel?uniqueid=" + nv.GetUniqueId()); string cancelled = await quit.ReadXmlElement("cancel"); if (cancelled == "1") { DialogUtils.DisplayDialog(this.Dispatcher, "Successfully Quit Game", "Quit Game"); return; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } DialogUtils.DisplayDialog(this.Dispatcher, "Unable to quit", "Quit Game"); }
/// <summary> /// Create start HTTP request /// </summary> private async Task <bool> StartOrResumeApp(NvHttp nv, MoonlightStreamConfiguration streamConfig) { XmlQuery serverInfo = new XmlQuery(nv.BaseUrl + "/serverinfo?uniqueid=" + nv.GetUniqueId()); string currentGameString = await serverInfo.ReadXmlElement("currentgame"); if (currentGameString == null) { return(false); } string versionString = await serverInfo.ReadXmlElement("appversion"); if (versionString == null) { return(false); } serverMajorVersion = Convert.ToInt32(versionString.Substring(0, 1)); byte[] aesIv = streamConfig.GetRiAesIv(); int riKeyId = (int)(((aesIv[0] << 24) & 0xFF000000U) | ((aesIv[1] << 16) & 0xFF0000U) | ((aesIv[2] << 8) & 0xFF00U) | (aesIv[3] & 0xFFU)); string riConfigString = "&rikey=" + PairingCryptoHelpers.BytesToHex(streamConfig.GetRiAesKey()) + "&rikeyid=" + riKeyId; // Launch a new game if nothing is running if (currentGameString == null || currentGameString.Equals("0")) { XmlQuery x = new XmlQuery(nv.BaseUrl + "/launch?uniqueid=" + nv.GetUniqueId() + "&appid=" + context.appId + "&mode=" + streamConfig.GetWidth() + "x" + streamConfig.GetHeight() + "x" + streamConfig.GetFps() + "&additionalStates=1&sops=1" + // FIXME: make sops configurable riConfigString); string sessionStr = await x.ReadXmlElement("gamesession"); if (sessionStr == null || sessionStr.Equals("0")) { return(false); } return(true); } else { // A game was already running, so resume it // FIXME: Quit and relaunch if it's not the game we came to start XmlQuery x = new XmlQuery(nv.BaseUrl + "/resume?uniqueid=" + nv.GetUniqueId() + riConfigString); string resumeStr = await x.ReadXmlElement("resume"); if (resumeStr == null || resumeStr.Equals("0")) { return(false); } return(true); } }