<feat: New release>

This commit is contained in:
Alessandro Autiero
2023-09-09 12:46:16 +02:00
parent badf41b044
commit 485e757e83
424 changed files with 37224 additions and 818815 deletions

View File

@@ -1,48 +1,30 @@
import 'dart:convert';
import 'dart:io';
import 'package:process_run/process_run.dart';
import 'package:reboot_common/common.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_proxy/shelf_proxy.dart';
final authenticatorDirectory = Directory("${assetsDirectory.path}\\authenticator");
final authenticatorStartExecutable = File("${authenticatorDirectory.path}\\lawinserver.exe");
final authenticatorKillExecutable = File("${authenticatorDirectory.path}\\kill.bat");
final authenticatorLogFile = File("${logsDirectory.path}\\authenticator.log");
final authenticatorDirectory = Directory("${assetsDirectory.path}\\lawin");
final authenticatorExecutable = File("${authenticatorDirectory.path}\\run.bat");
Future<Process> startEmbeddedAuthenticator(bool detached) async {
if(!authenticatorExecutable.existsSync()) {
throw StateError("${authenticatorExecutable.path} doesn't exist");
}
var process = await Process.start(
authenticatorExecutable.path,
[],
workingDirectory: authenticatorDirectory.path,
mode: detached ? ProcessStartMode.detached : ProcessStartMode.normal
);
if(!detached) {
authenticatorLogFile.createSync(recursive: true);
process.outLines.forEach((element) => authenticatorLogFile.writeAsStringSync("$element\n", mode: FileMode.append));
process.errLines.forEach((element) => authenticatorLogFile.writeAsStringSync("$element\n", mode: FileMode.append));
}
return process;
}
Future<int> startEmbeddedAuthenticator(bool detached) async => startBackgroundProcess(
executable: authenticatorStartExecutable,
window: detached
);
Future<HttpServer> startRemoteAuthenticatorProxy(Uri uri) async => await serve(proxyHandler(uri), kDefaultAuthenticatorHost, int.parse(kDefaultAuthenticatorPort));
Future<bool> isAuthenticatorPortFree() async => isPortFree(int.parse(kDefaultAuthenticatorPort));
Future<bool> freeAuthenticatorPort() async {
var releaseBat = File("${assetsDirectory.path}\\lawin\\kill_lawin.bat");
await Process.run(releaseBat.path, []);
await Process.run(authenticatorKillExecutable.path, []);
var standardResult = await isAuthenticatorPortFree();
if(standardResult) {
return true;
}
var elevatedResult = await runElevatedProcess(releaseBat.path, "");
var elevatedResult = await runElevatedProcess(authenticatorKillExecutable.path, "");
if(!elevatedResult) {
return false;
}
@@ -50,9 +32,7 @@ Future<bool> freeAuthenticatorPort() async {
return await isAuthenticatorPortFree();
}
Future<Uri?> pingSelf(String port) async => ping(kDefaultAuthenticatorHost, port);
Future<Uri?> ping(String host, String port, [bool https=false]) async {
Future<Uri?> pingAuthenticator(String host, String port, [bool https=false]) async {
var hostName = _getHostName(host);
var declaredScheme = _getScheme(host);
try{
@@ -66,10 +46,9 @@ Future<Uri?> ping(String host, String port, [bool https=false]) async {
..connectionTimeout = const Duration(seconds: 5);
var request = await client.getUrl(uri);
var response = await request.close();
var body = utf8.decode(await response.single);
return body.contains("epicgames") || body.contains("lawinserver") ? uri : null;
return response.statusCode == 200 || response.statusCode == 404 ? uri : null;
}catch(_){
return https || declaredScheme != null ? null : await ping(host, port, true);
return https || declaredScheme != null ? null : await pingAuthenticator(host, port, true);
}
}