mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-16 22:01:14 +00:00
@@ -98,8 +98,31 @@ public class AddComputerManually extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private URI parseRawUserInputToUri(String rawUserInput) {
|
||||||
|
try {
|
||||||
|
// Try adding a scheme and parsing the remaining input.
|
||||||
|
// This handles input like 127.0.0.1:47989, [::1], [::1]:47989, and 127.0.0.1.
|
||||||
|
URI uri = new URI("moonlight://" + rawUserInput);
|
||||||
|
if (uri.getHost() != null && !uri.getHost().isEmpty()) {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException ignored) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Attempt to escape the input as an IPv6 literal.
|
||||||
|
// This handles input like ::1.
|
||||||
|
URI uri = new URI("moonlight://[" + rawUserInput + "]");
|
||||||
|
if (uri.getHost() != null && !uri.getHost().isEmpty()) {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException ignored) {}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void doAddPc(String rawUserInput) throws InterruptedException {
|
private void doAddPc(String rawUserInput) throws InterruptedException {
|
||||||
boolean wrongSiteLocal = false;
|
boolean wrongSiteLocal = false;
|
||||||
|
boolean invalidInput = false;
|
||||||
boolean success;
|
boolean success;
|
||||||
int portTestResult;
|
int portTestResult;
|
||||||
|
|
||||||
@@ -109,26 +132,26 @@ public class AddComputerManually extends Activity {
|
|||||||
try {
|
try {
|
||||||
ComputerDetails details = new ComputerDetails();
|
ComputerDetails details = new ComputerDetails();
|
||||||
|
|
||||||
// Use URI-style parsing for the host address input
|
// Check if we parsed a host address successfully
|
||||||
URI uri = new URI("moonlight://" + rawUserInput);
|
URI uri = parseRawUserInputToUri(rawUserInput);
|
||||||
|
if (uri != null && uri.getHost() != null && !uri.getHost().isEmpty()) {
|
||||||
|
String host = uri.getHost();
|
||||||
|
int port = uri.getPort();
|
||||||
|
|
||||||
String host = uri.getHost();
|
// If a port was not specified, use the default
|
||||||
int port = uri.getPort();
|
if (port == -1) {
|
||||||
|
port = NvHTTP.DEFAULT_HTTP_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
// URI allows empty hosts, but we don't want that
|
details.manualAddress = new ComputerDetails.AddressTuple(host, port);
|
||||||
if (host == null || host.isEmpty()) {
|
success = managerBinder.addComputerBlocking(details);
|
||||||
throw new URISyntaxException(rawUserInput, "Host failed to parse");
|
if (!success){
|
||||||
}
|
wrongSiteLocal = isWrongSubnetSiteLocalAddress(host);
|
||||||
|
}
|
||||||
// If a port was not specified, use the default
|
} else {
|
||||||
if (port == -1) {
|
// Invalid user input
|
||||||
port = NvHTTP.DEFAULT_HTTP_PORT;
|
success = false;
|
||||||
}
|
invalidInput = true;
|
||||||
|
|
||||||
details.manualAddress = new ComputerDetails.AddressTuple(host, port);
|
|
||||||
success = managerBinder.addComputerBlocking(details);
|
|
||||||
if (!success){
|
|
||||||
wrongSiteLocal = isWrongSubnetSiteLocalAddress(host);
|
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// Propagate the InterruptedException to the caller for proper handling
|
// Propagate the InterruptedException to the caller for proper handling
|
||||||
@@ -139,13 +162,11 @@ public class AddComputerManually extends Activity {
|
|||||||
// https://github.com/square/okhttp/blob/okhttp_27/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java#L705
|
// https://github.com/square/okhttp/blob/okhttp_27/okhttp/src/main/java/com/squareup/okhttp/HttpUrl.java#L705
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
success = false;
|
success = false;
|
||||||
} catch (URISyntaxException e) {
|
invalidInput = true;
|
||||||
e.printStackTrace();
|
|
||||||
success = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep the SpinnerDialog open while testing connectivity
|
// Keep the SpinnerDialog open while testing connectivity
|
||||||
if (!success && !wrongSiteLocal) {
|
if (!success && !wrongSiteLocal && !invalidInput) {
|
||||||
// Run the test before dismissing the spinner because it can take a few seconds.
|
// Run the test before dismissing the spinner because it can take a few seconds.
|
||||||
portTestResult = MoonBridge.testClientConnectivity(ServerHelper.CONNECTION_TEST_SERVER, 443,
|
portTestResult = MoonBridge.testClientConnectivity(ServerHelper.CONNECTION_TEST_SERVER, 443,
|
||||||
MoonBridge.ML_PORT_FLAG_TCP_47984 | MoonBridge.ML_PORT_FLAG_TCP_47989);
|
MoonBridge.ML_PORT_FLAG_TCP_47984 | MoonBridge.ML_PORT_FLAG_TCP_47989);
|
||||||
@@ -156,7 +177,10 @@ public class AddComputerManually extends Activity {
|
|||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
if (wrongSiteLocal) {
|
if (invalidInput) {
|
||||||
|
Dialog.displayDialog(this, getResources().getString(R.string.conn_error_title), getResources().getString(R.string.addpc_unknown_host), false);
|
||||||
|
}
|
||||||
|
else if (wrongSiteLocal) {
|
||||||
Dialog.displayDialog(this, getResources().getString(R.string.conn_error_title), getResources().getString(R.string.addpc_wrong_sitelocal), false);
|
Dialog.displayDialog(this, getResources().getString(R.string.conn_error_title), getResources().getString(R.string.addpc_wrong_sitelocal), false);
|
||||||
}
|
}
|
||||||
else if (!success) {
|
else if (!success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user