mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 19:22:22 +01:00
<feat: New release>
This commit is contained in:
34
gui/lib/src/util/matchmaker.dart
Normal file
34
gui/lib/src/util/matchmaker.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:reboot_common/common.dart';
|
||||
|
||||
final File _script = File("${assetsDirectory.path}\\misc\\udp.ps1");
|
||||
|
||||
Future<bool> pingGameServer(String address, {Duration? timeout}) async {
|
||||
var start = DateTime.now();
|
||||
var firstTime = true;
|
||||
while (firstTime || (timeout != null && DateTime.now().millisecondsSinceEpoch - start.millisecondsSinceEpoch < timeout.inMilliseconds)) {
|
||||
var split = address.split(":");
|
||||
var hostname = split[0];
|
||||
var port = split.length > 1 ? split[1] : kDefaultGameServerPort;
|
||||
var result = await Process.run(
|
||||
"powershell",
|
||||
[
|
||||
_script.path,
|
||||
hostname,
|
||||
port
|
||||
]
|
||||
);
|
||||
if (result.exitCode == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(firstTime) {
|
||||
firstTime = false;
|
||||
}else {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -9,11 +9,12 @@ import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
final GameController _gameController = Get.find<GameController>();
|
||||
final HostingController _hostingController = Get.find<HostingController>();
|
||||
final File _executable = File("${assetsDirectory.path}\\misc\\watch.exe");
|
||||
|
||||
extension GameInstanceWatcher on GameInstance {
|
||||
Future<void> startObserver() async {
|
||||
if(watchPid != null) {
|
||||
Process.killPid(watchPid!, ProcessSignal.sigabrt);
|
||||
if(observerPid != null) {
|
||||
Process.killPid(observerPid!, ProcessSignal.sigabrt);
|
||||
}
|
||||
|
||||
watchProcess(gamePid).then((value) async {
|
||||
@@ -24,9 +25,15 @@ extension GameInstanceWatcher on GameInstance {
|
||||
_onGameStopped();
|
||||
});
|
||||
|
||||
watchPid = startBackgroundProcess(
|
||||
'${assetsDirectory.path}\\misc\\watch.exe',
|
||||
[_gameController.uuid, gamePid.toString(), launcherPid?.toString() ?? "-1", eacPid?.toString() ?? "-1", hosting.toString()]
|
||||
observerPid = await startBackgroundProcess(
|
||||
executable: _executable,
|
||||
args: [
|
||||
_gameController.uuid,
|
||||
gamePid.toString(),
|
||||
launcherPid?.toString() ?? "-1",
|
||||
eacPid?.toString() ?? "-1",
|
||||
hosting.toString()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user