diff --git a/gui/lib/src/button/game_start_button.dart b/gui/lib/src/button/game_start_button.dart index 199d072..b8dd4df 100644 --- a/gui/lib/src/button/game_start_button.dart +++ b/gui/lib/src/button/game_start_button.dart @@ -325,19 +325,34 @@ class _LaunchButtonState extends State { handleGameOutput( line: line, host: host, - onShutdown: () => _onStop(reason: _StopReason.normal, host: host), - onTokenError: () => _onStop(reason: _StopReason.tokenError, host: host), + onShutdown: () { + log("[${host ? 'HOST' : 'GAME'}] Called shutdown"); + _onStop(reason: _StopReason.normal, host: host); + }, + onTokenError: () { + log("[${host ? 'HOST' : 'GAME'}] Called token error"); + _onStop(reason: _StopReason.tokenError, host: host); + }, onBuildCorrupted: () { if(instance == null) { + log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: no instance"); return; }else if(!instance.launched) { + log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: not launched"); _onStop(reason: _StopReason.corruptedVersionError, host: host); }else { + log("[${host ? 'HOST' : 'GAME'}] Called build corrupted: crash"); _onStop(reason: _StopReason.crash, host: host); } }, - onLoggedIn: () =>_onLoggedIn(host), - onMatchEnd: () => _onMatchEnd(version) + onLoggedIn: () { + log("[${host ? 'HOST' : 'GAME'}] Called logged in"); + _onLoggedIn(host); + }, + onMatchEnd: () { + log("[${host ? 'HOST' : 'GAME'}] Called match end"); + _onMatchEnd(version); + } ); } gameProcess.stdOutput.listen((line) => onGameOutput(line, false)); diff --git a/gui/lib/src/controller/dll_controller.dart b/gui/lib/src/controller/dll_controller.dart index 6571aa1..b0f1eda 100644 --- a/gui/lib/src/controller/dll_controller.dart +++ b/gui/lib/src/controller/dll_controller.dart @@ -4,14 +4,18 @@ import 'dart:io'; import 'package:fluent_ui/fluent_ui.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; -import 'package:path/path.dart' as path; import 'package:path/path.dart'; import 'package:reboot_common/common.dart'; import 'package:reboot_launcher/main.dart'; -import 'package:reboot_launcher/src/util/translations.dart'; import 'package:reboot_launcher/src/messenger/info_bar.dart'; +import 'package:reboot_launcher/src/page/settings_page.dart'; +import 'package:reboot_launcher/src/util/translations.dart'; import 'package:version/version.dart'; +import 'package:path/path.dart' as path; +import 'package:reboot_launcher/src/controller/game_controller.dart'; +import 'package:reboot_launcher/src/controller/hosting_controller.dart'; +// TODO: Refactor me class DllController extends GetxController { static const String storageName = "v3_dll_storage"; @@ -26,6 +30,7 @@ class DllController extends GetxController { late final RxBool customGameServer; late final RxnInt timestamp; late final Rx status; + late final Map _subscriptions; DllController() { _storage = appWithNoStorage ? null : GetStorage(storageName); @@ -44,6 +49,7 @@ class DllController extends GetxController { customGameServer.listen((value) => _storage?.write("custom_game_server", value)); timestamp = RxnInt(_storage?.read("ts")); timestamp.listen((value) => _storage?.write("ts", value)); + _subscriptions = {}; } TextEditingController _createController(String key, GameDll dll) { @@ -73,6 +79,7 @@ class DllController extends GetxController { try { if(customGameServer.value) { status.value = UpdateStatus.success; + _listenToFileEvents(GameDll.gameServer); return true; } @@ -82,6 +89,7 @@ class DllController extends GetxController { ); if(!needsUpdate) { status.value = UpdateStatus.success; + _listenToFileEvents(GameDll.gameServer); return true; } @@ -121,6 +129,7 @@ class DllController extends GetxController { duration: infoBarShortDuration ); } + _listenToFileEvents(GameDll.gameServer); return true; }catch(message) { infoBarEntry?.close(); @@ -215,6 +224,7 @@ class DllController extends GetxController { if(!force && File(filePath).existsSync()) { log("[DLL] $dll already exists"); + _listenToFileEvents(dll); return true; } @@ -252,6 +262,7 @@ class DllController extends GetxController { }else { log("[DLL] Not showing success dialog for $dll"); } + _listenToFileEvents(dll); return true; }catch(message) { log("[DLL] An error occurred while downloading $dll: $message"); @@ -287,6 +298,63 @@ class DllController extends GetxController { } } } + + void _listenToFileEvents(GameDll injectable) { + final controller = getDllEditingController(injectable); + final defaultPath = getDefaultDllPath(injectable); + + void onFileEvent(FileSystemEvent event, String filePath) { + if (!path.equals(event.path, filePath)) { + return; + } + + if(path.equals(filePath, defaultPath)) { + Get.find() + .instance + .value + ?.kill(); + Get.find() + .instance + .value + ?.kill(); + showRebootInfoBar( + translations.downloadDllAntivirus(antiVirusName ?? defaultAntiVirusName, injectable.name), + duration: infoBarLongDuration, + severity: InfoBarSeverity.error + ); + } + + _updateInput(injectable); + } + + StreamSubscription subscribe(String filePath) => File(filePath) + .parent + .watch(events: FileSystemEvent.delete | FileSystemEvent.move) + .listen((event) => onFileEvent(event, filePath)); + + controller.addListener(() { + _subscriptions[injectable]?.cancel(); + _subscriptions[injectable] = subscribe(controller.text); + }); + _subscriptions[injectable] = subscribe(controller.text); + } + + void _updateInput(GameDll injectable) { + switch(injectable) { + case GameDll.console: + settingsConsoleDllInputKey.currentState?.validate(); + break; + case GameDll.auth: + settingsAuthDllInputKey.currentState?.validate(); + break; + case GameDll.gameServer: + settingsGameServerDllInputKey.currentState?.validate(); + break; + case GameDll.memoryLeak: + settingsMemoryDllInputKey.currentState?.validate(); + break; + } + } } enum UpdateStatus { diff --git a/gui/lib/src/controller/hosting_controller.dart b/gui/lib/src/controller/hosting_controller.dart index 12b6538..7f6e74a 100644 --- a/gui/lib/src/controller/hosting_controller.dart +++ b/gui/lib/src/controller/hosting_controller.dart @@ -25,7 +25,6 @@ class HostingController extends GetxController { late final RxBool headless; late final RxBool autoRestart; late final RxBool started; - late final RxBool published; late final Rxn instance; late final TextEditingController customLaunchArgs; @@ -51,7 +50,6 @@ class HostingController extends GetxController { autoRestart = RxBool(_storage?.read("auto_restart") ?? true); autoRestart.listen((value) => _storage?.write("auto_restart", value)); started = RxBool(false); - published = RxBool(false); showPassword = RxBool(false); instance = Rxn(); customLaunchArgs = TextEditingController(text: _storage?.read("custom_launch_args") ?? ""); diff --git a/gui/lib/src/page/host_page.dart b/gui/lib/src/page/host_page.dart index 2d74167..1b9b3f3 100644 --- a/gui/lib/src/page/host_page.dart +++ b/gui/lib/src/page/host_page.dart @@ -309,10 +309,6 @@ class _HostingPageState extends AbstractPageState { ); Future _updateServer() async { - if(!_hostingController.published()) { - return; - } - try { final server = await _hostingController.createServerBrowserEntry(); _serverBrowserController.addServer(server); @@ -321,7 +317,6 @@ class _HostingPageState extends AbstractPageState { } } - void _showCopiedLink() => showRebootInfoBar( translations.hostShareLinkMessageSuccess, severity: InfoBarSeverity.success diff --git a/server_browser_backend/lib/src/server_browser_entry.dart b/server_browser_backend/lib/src/server_browser_entry.dart index 7e610bc..830cc92 100644 --- a/server_browser_backend/lib/src/server_browser_entry.dart +++ b/server_browser_backend/lib/src/server_browser_entry.dart @@ -7,7 +7,6 @@ class ServerBrowserEntry { final DateTime timestamp; final String ip; final String author; - final bool discoverable; ServerBrowserEntry({ required this.id, @@ -17,8 +16,7 @@ class ServerBrowserEntry { required this.password, required this.timestamp, required this.ip, - required this.author, - required this.discoverable, + required this.author }); Map toJson() { @@ -30,8 +28,7 @@ class ServerBrowserEntry { 'password': password, 'timestamp': timestamp.toIso8601String(), 'ip': ip, - 'author': author, - 'discoverable': discoverable, + 'author': author }; } @@ -44,8 +41,7 @@ class ServerBrowserEntry { password: json['password'], timestamp: DateTime.parse(json['timestamp']), ip: json['ip'], - author: json['author'], - discoverable: json['discoverable'], + author: json['author'] ); } } \ No newline at end of file