From 56c82f332bebee24d70611cde15ccadf8503fa41 Mon Sep 17 00:00:00 2001 From: Bernardo Lopes Date: Sat, 8 Apr 2023 20:49:58 -0300 Subject: [PATCH 1/2] Fix what length is used in the sendOtp for loop. --- lib/communication.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/communication.dart b/lib/communication.dart index ccd1ce4..cdb3b8e 100644 --- a/lib/communication.dart +++ b/lib/communication.dart @@ -29,7 +29,7 @@ class Communication { List? ipList = ips.split(';'); - for (var currentIp = 0; currentIp < ips.length; currentIp++) { + for (var currentIp = 0; currentIp < ipList.length; currentIp++) { var ip = ipList[currentIp]; var uri = Uri.http("$ip:4646", "ffxivlauncher/$otp"); try { From af5fef77a30f19460e6cd33342c3c4b6dcf01173 Mon Sep 17 00:00:00 2001 From: Bernardo Lopes Date: Sat, 8 Apr 2023 21:42:32 -0300 Subject: [PATCH 2/2] Better handling of multi-IP OTP send. Now, it'll basically shoot the OTP at the same time to all registered IPs. Since any IP that actually has XL waiting for the code will reply quickly, it'll return true if any client received the code. If no client is running, any fail response is good. --- lib/communication.dart | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/communication.dart b/lib/communication.dart index cdb3b8e..7a17a8f 100644 --- a/lib/communication.dart +++ b/lib/communication.dart @@ -27,24 +27,25 @@ class Communication { if (ips == null) return false; - List? ipList = ips.split(';'); - - for (var currentIp = 0; currentIp < ipList.length; currentIp++) { - var ip = ipList[currentIp]; - var uri = Uri.http("$ip:4646", "ffxivlauncher/$otp"); - try { - await http.get(uri); - } on http - .ClientException catch (e) { // This happens since the XL http server is badly implemented, no problem though - developer.log('ClientException: ' + uri.toString(), - name: 'com.goatsoft.xl_otpsend', error: e); - return true; - } - catch (e) { - developer.log('could not send to: ' + uri.toString(), - name: 'com.goatsoft.xl_otpsend', error: e); - } + List ipList = ips.split(";"); + return await Future.any(ipList.map((e) => sendOtpToIp(otp, e))); + } + + static Future sendOtpToIp(String otp, String ip) async { + var uri = Uri.http("$ip:4646", "ffxivlauncher/$otp"); + try { + await http.get(uri).timeout(const Duration(seconds: 5)); + return true; + } on http + .ClientException catch (e) { // This happens since the XL http server is badly implemented, no problem though + developer.log('ClientException: ' + uri.toString(), + name: 'com.goatsoft.xl_otpsend', error: e); + return true; + } + catch (e) { + developer.log('could not send to: ' + uri.toString(), + name: 'com.goatsoft.xl_otpsend', error: e); } - return true; + return false; } } \ No newline at end of file