From 260d716eb88aa80f1e8845857fb1706212eb82ea Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 11 Nov 2015 16:28:58 -0800 Subject: [PATCH] Fix broken app launching and resuming on GFE 2.8 --- .../com/limelight/nvstream/NvConnection.java | 3 +-- .../com/limelight/nvstream/http/NvHTTP.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/NvConnection.java b/moonlight-common/src/com/limelight/nvstream/NvConnection.java index 1241a4f9..0c87e7dc 100644 --- a/moonlight-common/src/com/limelight/nvstream/NvConnection.java +++ b/moonlight-common/src/com/limelight/nvstream/NvConnection.java @@ -216,8 +216,7 @@ public class NvConnection { private boolean launchNotRunningApp(NvHTTP h, NvApp app) throws IOException, XmlPullParserException { // Launch the app since it's not running - int gameSessionId = h.launchApp(context, app.getAppId()); - if (gameSessionId == 0) { + if (!h.launchApp(context, app.getAppId())) { context.connListener.displayMessage("Failed to launch application"); return false; } diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index 45c4c4c1..d39fba26 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -221,7 +221,7 @@ public class NvHTTP { } try { - details.runningGameId = Integer.parseInt(getXmlString(serverInfo, "currentgame").trim()); + details.runningGameId = getCurrentGame(serverInfo); } catch (NumberFormatException e) { details.runningGameId = 0; } @@ -336,8 +336,17 @@ public class NvHTTP { } public int getCurrentGame(String serverInfo) throws IOException, XmlPullParserException { - String game = getXmlString(serverInfo, "currentgame"); - return Integer.parseInt(game); + // GFE 2.8 started keeping currentgame set to the last game played. As a result, it no longer + // has the semantics that its name would indicate. To contain the effects of this change as much + // as possible, we'll force the current game to zero if the server isn't in a streaming session. + String serverState = getXmlString(serverInfo, "state").trim(); + if (serverState != null && !serverState.endsWith("_SERVER_AVAILABLE")) { + String game = getXmlString(serverInfo, "currentgame").trim(); + return Integer.parseInt(game); + } + else { + return 0; + } } public NvApp getAppById(int appId) throws IOException, XmlPullParserException { @@ -468,7 +477,7 @@ public class NvHTTP { return new String(hexChars); } - public int launchApp(ConnectionContext context, int appId) throws IOException, XmlPullParserException { + public boolean launchApp(ConnectionContext context, int appId) throws IOException, XmlPullParserException { String xmlStr = openHttpConnectionToString(baseUrlHttps + "/launch?uniqueid=" + uniqueId + "&appid=" + appId + @@ -478,7 +487,7 @@ public class NvHTTP { "&rikeyid="+context.riKeyId + "&localAudioPlayMode=" + (context.streamConfig.getPlayLocalAudio() ? 1 : 0), false); String gameSession = getXmlString(xmlStr, "gamesession"); - return Integer.parseInt(gameSession); + return gameSession != null && !gameSession.equals("0"); } public boolean resumeApp(ConnectionContext context) throws IOException, XmlPullParserException {