mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Fix a few parsing issues with the serverinfo XML
This commit is contained in:
parent
894110ba08
commit
dcb3e1c0e4
@ -28,6 +28,7 @@ public class NvHTTP {
|
|||||||
private String uniqueId;
|
private String uniqueId;
|
||||||
private PairingManager pm;
|
private PairingManager pm;
|
||||||
private LimelightCryptoProvider cryptoProvider;
|
private LimelightCryptoProvider cryptoProvider;
|
||||||
|
private InetAddress address;
|
||||||
|
|
||||||
public static final int PORT = 47984;
|
public static final int PORT = 47984;
|
||||||
public static final int CONNECTION_TIMEOUT = 2000;
|
public static final int CONNECTION_TIMEOUT = 2000;
|
||||||
@ -39,6 +40,7 @@ public class NvHTTP {
|
|||||||
public NvHTTP(InetAddress host, String uniqueId, String deviceName, LimelightCryptoProvider cryptoProvider) {
|
public NvHTTP(InetAddress host, String uniqueId, String deviceName, LimelightCryptoProvider cryptoProvider) {
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
this.cryptoProvider = cryptoProvider;
|
this.cryptoProvider = cryptoProvider;
|
||||||
|
this.address = host;
|
||||||
|
|
||||||
String safeAddress;
|
String safeAddress;
|
||||||
if (host instanceof Inet6Address) {
|
if (host instanceof Inet6Address) {
|
||||||
@ -104,21 +106,34 @@ public class NvHTTP {
|
|||||||
ComputerDetails details = new ComputerDetails();
|
ComputerDetails details = new ComputerDetails();
|
||||||
String serverInfo = openHttpConnectionToString(baseUrl + "/serverinfo?uniqueid=" + uniqueId);
|
String serverInfo = openHttpConnectionToString(baseUrl + "/serverinfo?uniqueid=" + uniqueId);
|
||||||
|
|
||||||
details.name = getXmlString(serverInfo, "hostname");
|
details.name = getXmlString(serverInfo, "hostname").trim();
|
||||||
details.uuid = UUID.fromString(getXmlString(serverInfo, "uniqueid"));
|
details.uuid = UUID.fromString(getXmlString(serverInfo, "uniqueid").trim());
|
||||||
details.localIp = InetAddress.getByName(getXmlString(serverInfo, "LocalIP"));
|
|
||||||
details.remoteIp = InetAddress.getByName(getXmlString(serverInfo, "ExternalIP"));
|
|
||||||
details.macAddress = getXmlString(serverInfo, "mac");
|
details.macAddress = getXmlString(serverInfo, "mac");
|
||||||
|
|
||||||
|
// If there's no LocalIP field, use the address we hit the server on
|
||||||
|
String localIpStr = getXmlString(serverInfo, "LocalIP");
|
||||||
|
if (localIpStr == null) {
|
||||||
|
localIpStr = address.getHostAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no ExternalIP field, use the address we hit the server on
|
||||||
|
String externalIpStr = getXmlString(serverInfo, "ExternalIP");
|
||||||
|
if (externalIpStr == null) {
|
||||||
|
externalIpStr = address.getHostAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
details.localIp = InetAddress.getByName(localIpStr.trim());
|
||||||
|
details.remoteIp = InetAddress.getByName(externalIpStr.trim());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
details.pairState = Integer.parseInt(getXmlString(serverInfo, "PairStatus")) == 1 ?
|
details.pairState = Integer.parseInt(getXmlString(serverInfo, "PairStatus").trim()) == 1 ?
|
||||||
PairState.PAIRED : PairState.NOT_PAIRED;
|
PairState.PAIRED : PairState.NOT_PAIRED;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
details.pairState = PairState.FAILED;
|
details.pairState = PairState.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
details.runningGameId = Integer.parseInt(getXmlString(serverInfo, "currentgame"));
|
details.runningGameId = Integer.parseInt(getXmlString(serverInfo, "currentgame").trim());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
details.runningGameId = 0;
|
details.runningGameId = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user