Merge pull request #3381 from 21pages/fix

mobile id suffix "\r" or "/r" for relay
This commit is contained in:
RustDesk 2023-02-26 15:01:41 +08:00 committed by GitHub
commit c0ce7a430e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 13 deletions

View File

@ -1453,10 +1453,12 @@ connectMainDesktop(String id,
connect(BuildContext context, String id, connect(BuildContext context, String id,
{bool isFileTransfer = false, {bool isFileTransfer = false,
bool isTcpTunneling = false, bool isTcpTunneling = false,
bool isRDP = false, bool isRDP = false}) async {
bool forceRelay = false}) async {
if (id == '') return; if (id == '') return;
id = id.replaceAll(' ', ''); id = id.replaceAll(' ', '');
final oldId = id;
id = await bind.mainHandleRelayId(id: id);
final forceRelay = id != oldId;
assert(!(isFileTransfer && isTcpTunneling && isRDP), assert(!(isFileTransfer && isTcpTunneling && isRDP),
"more than one connect type"); "more than one connect type");

View File

@ -151,10 +151,7 @@ class _ConnectionPageState extends State<ConnectionPage>
/// Connects to the selected peer. /// Connects to the selected peer.
void onConnect({bool isFileTransfer = false}) { void onConnect({bool isFileTransfer = false}) {
var id = _idController.id; var id = _idController.id;
var forceRelay = id.endsWith(r'/r'); connect(context, id, isFileTransfer: isFileTransfer);
if (forceRelay) id = id.substring(0, id.length - 2);
connect(context, id,
isFileTransfer: isFileTransfer, forceRelay: forceRelay);
} }
/// UI for the remote ID TextField. /// UI for the remote ID TextField.

View File

@ -840,6 +840,10 @@ pub fn main_get_user_default_option(key: String) -> SyncReturn<String> {
SyncReturn(get_user_default_option(key)) SyncReturn(get_user_default_option(key))
} }
pub fn main_handle_relay_id(id: String) -> String {
handle_relay_id(id)
}
pub fn session_add_port_forward( pub fn session_add_port_forward(
id: String, id: String,
local_port: i32, local_port: i32,

View File

@ -420,8 +420,8 @@ impl UI {
crate::lan::send_wol(id) crate::lan::send_wol(id)
} }
fn new_remote(&mut self, id: String, remote_type: String) { fn new_remote(&mut self, id: String, remote_type: String, force_relay: bool) {
new_remote(id, remote_type) new_remote(id, remote_type, force_relay)
} }
fn is_process_trusted(&mut self, _prompt: bool) -> bool { fn is_process_trusted(&mut self, _prompt: bool) -> bool {
@ -571,6 +571,10 @@ impl UI {
fn default_video_save_directory(&self) -> String { fn default_video_save_directory(&self) -> String {
default_video_save_directory() default_video_save_directory()
} }
fn handle_relay_id(&self, id: String) -> String {
handle_relay_id(id)
}
} }
impl sciter::EventHandler for UI { impl sciter::EventHandler for UI {
@ -588,7 +592,7 @@ impl sciter::EventHandler for UI {
fn set_remote_id(String); fn set_remote_id(String);
fn closing(i32, i32, i32, i32); fn closing(i32, i32, i32, i32);
fn get_size(); fn get_size();
fn new_remote(String, bool); fn new_remote(String, String, bool);
fn send_wol(String); fn send_wol(String);
fn remove_peer(String); fn remove_peer(String);
fn remove_discovered(String); fn remove_discovered(String);
@ -653,6 +657,7 @@ impl sciter::EventHandler for UI {
fn has_hwcodec(); fn has_hwcodec();
fn get_langs(); fn get_langs();
fn default_video_save_directory(); fn default_video_save_directory();
fn handle_relay_id(String);
} }
} }
@ -718,9 +723,13 @@ pub fn value_crash_workaround(values: &[Value]) -> Arc<Vec<Value>> {
} }
#[inline] #[inline]
pub fn new_remote(id: String, remote_type: String) { pub fn new_remote(id: String, remote_type: String, force_relay: bool) {
let mut lock = CHILDREN.lock().unwrap(); let mut lock = CHILDREN.lock().unwrap();
let args = vec![format!("--{}", remote_type), id.clone()]; let mut args = vec![format!("--{}", remote_type), id.clone()];
if force_relay {
args.push("".to_string()); // password
args.push("--relay".to_string());
}
let key = (id.clone(), remote_type.clone()); let key = (id.clone(), remote_type.clone());
if let Some(c) = lock.1.get_mut(&key) { if let Some(c) = lock.1.get_mut(&key) {
if let Ok(Some(_)) = c.try_wait() { if let Ok(Some(_)) = c.try_wait() {

View File

@ -62,12 +62,15 @@ function createNewConnect(id, type) {
id = id.replace(/\s/g, ""); id = id.replace(/\s/g, "");
app.remote_id.value = formatId(id); app.remote_id.value = formatId(id);
if (!id) return; if (!id) return;
var old_id = id;
id = handler.handle_relay_id(id);
var force_relay = old_id != id;
if (id == my_id) { if (id == my_id) {
msgbox("custom-error", "Error", "You cannot connect to your own computer"); msgbox("custom-error", "Error", "You cannot connect to your own computer");
return; return;
} }
handler.set_remote_id(id); handler.set_remote_id(id);
handler.new_remote(id, type); handler.new_remote(id, type, force_relay);
} }
class ShareRdp: Reactor.Component { class ShareRdp: Reactor.Component {

View File

@ -462,6 +462,7 @@ impl sciter::EventHandler for SciterSession {
impl SciterSession { impl SciterSession {
pub fn new(cmd: String, id: String, password: String, args: Vec<String>) -> Self { pub fn new(cmd: String, id: String, password: String, args: Vec<String>) -> Self {
let force_relay = args.contains(&"--relay".to_string());
let session: Session<SciterHandler> = Session { let session: Session<SciterHandler> = Session {
id: id.clone(), id: id.clone(),
password: password.clone(), password: password.clone(),
@ -486,7 +487,7 @@ impl SciterSession {
.lc .lc
.write() .write()
.unwrap() .unwrap()
.initialize(id, conn_type, None, false); .initialize(id, conn_type, None, force_relay);
Self(session) Self(session)
} }

View File

@ -970,3 +970,12 @@ async fn check_id(
} }
"" ""
} }
// if it's relay id, return id processed, otherwise return original id
pub fn handle_relay_id(id: String) -> String {
if id.ends_with(r"\r") || id.ends_with(r"/r") {
id[0..id.len() - 2].to_string()
} else {
id
}
}