diff --git a/bin/server.dart b/bin/server.dart index 662eec5..d7bb7b5 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -35,7 +35,6 @@ void main() async { print("Initializing SteamCMD"); await settings.initializeSteamCmd(); - await settings.initializeSteamCmd2FA(); print("Initialized Steamcmd and Proton"); print("Checking for game server updates..."); @@ -50,13 +49,20 @@ void main() async { print( "Aborting server startup procedure, initial server setup is not yet complete\n\n[ You must log in with the ServerManager to continue ]"); } else { - print("Downloading mods..."); - await doDownloadMods(false); + try { + print("Downloading mods..."); + await doDownloadMods(false); - print("Scanning mods..."); - settings.inst!.mods = await doScanMods(); + print("Scanning mods..."); + settings.inst!.mods = await doScanMods(); + settings.Write(); - await settings.subsys.startScheduler(); + print("Starting scheduler..."); + await settings.subsys.startScheduler(); + } catch (E) { + settings.FTS = true; + settings.Write(); + } } print("Starting up server manager server wrapper"); diff --git a/lib/pages/credentials_prompt.dart b/lib/pages/credentials_prompt.dart index b27cc61..760fc3a 100644 --- a/lib/pages/credentials_prompt.dart +++ b/lib/pages/credentials_prompt.dart @@ -13,7 +13,10 @@ class CredentialsPrompt extends State { bool initialInitDone = false; @override - void initState() { + void initState() {} + + @override + void didChangeDependencies() { final args = ModalRoute.of(context)!.settings.arguments as Credentials?; if (args != null) { diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 29b33c6..24fee38 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:servermanager/packets/ClientPackets.dart'; import 'package:servermanager/pages/Constants.dart'; +import 'package:servermanager/structs/credentials.dart'; import 'package:servermanager/structs/settings.dart'; class HomePage extends StatefulWidget { @@ -93,9 +94,13 @@ class HomePageState extends State { title: Text("Manager Credentials"), subtitle: Text("Edit ServerManager credentials"), leading: Icon(Icons.key), - onTap: () { - Navigator.pushNamed(context, "/creds", + onTap: () async { + var reply = await Navigator.pushNamed(context, "/creds", arguments: settings.serverLoginCreds); + if (reply != null) { + Credentials creds = reply as Credentials; + settings.serverLoginCreds = creds; + } }, ), ListTile( diff --git a/lib/proton.dart b/lib/proton.dart index 812efb4..4bd87b2 100644 --- a/lib/proton.dart +++ b/lib/proton.dart @@ -23,7 +23,8 @@ Future runProton(String command, List argx) async { args.addAll(argx); ProcessResult res = await Process.run( - "proton", args, // Run arbitrary command with arguments + settings.getProtonExecutablePath(), + args, // Run arbitrary command with arguments environment: env, ); @@ -54,10 +55,12 @@ Future runDetachedProton( List args = ["run", command]; args.addAll(argx); - StateMachine.PROC = await Process.start( - "proton", args, // Run arbitrary command with arguments + StateMachine.PROC = await Process.start(settings.getProtonExecutablePath(), + args, // Run arbitrary command with arguments environment: env, workingDirectory: workingDir); + + StateMachine.monitorProcess(); } catch (e) { print('Error executing command: $e'); } diff --git a/lib/statemachine.dart b/lib/statemachine.dart index a0d8bec..2ef3b7c 100644 --- a/lib/statemachine.dart +++ b/lib/statemachine.dart @@ -73,6 +73,21 @@ enum WarnIntervals { class StateMachine { static Process? PROC; + static Completer DeadProcKillswitch = Completer(); + + void resetKillswitch() { + DeadProcKillswitch = Completer(); + } + + static Future monitorProcess() async { + try { + int code = await PROC!.exitCode; + DeadProcKillswitch.complete(); + } catch (E) { + DeadProcKillswitch.complete(); + } + } + var _currentState = States.Inactive; StreamController _stateController = StreamController.broadcast(); Stream get stateChanges => _stateController.stream; @@ -99,6 +114,7 @@ class StateMachine { await doDownloadMods(false); settings.inst!.mods = await doScanMods(); + settings.Write(); await settings.writeOutModListFile(); @@ -153,6 +169,8 @@ class StateMachine { SessionData.timer = settings.inst!.timer.time.copy(); changeState(States.PreStart); + resetKillswitch(); + // Schedule the server task task = Timer.periodic(Duration(seconds: 1), (timer) { switch (currentState) { @@ -201,6 +219,13 @@ class StateMachine { if (SessionData.timer.getTotalSeconds() == 0) { SessionData.shutdownPending = true; } + + // Check Dead Process + if (DeadProcKillswitch.isCompleted) { + // Switch state + changeState(States.FullStop); // This has the stop logic + } + break; } default: diff --git a/lib/structs/mod.dart b/lib/structs/mod.dart index cd70a34..39c2921 100644 --- a/lib/structs/mod.dart +++ b/lib/structs/mod.dart @@ -1,5 +1,5 @@ import 'package:libac_flutter/nbt/impl/CompoundTag.dart'; -import 'package:libac_flutter/nbt/impl/IntTag.dart'; +import 'package:libac_flutter/nbt/impl/LongTag.dart'; import 'package:libac_flutter/nbt/impl/StringTag.dart'; import 'package:libac_flutter/utils/uuid/UUID.dart'; @@ -29,7 +29,7 @@ class Mod { CompoundTag serialize() { CompoundTag tag = CompoundTag(); tag.put("name", StringTag.valueOf(mod_name)); - tag.put("id", IntTag.valueOf(mod_id)); + tag.put("id", LongTag.valueOf(mod_id)); tag.put("pak", StringTag.valueOf(mod_pak)); tag.put("hash", StringTag.valueOf(mod_hash)); @@ -41,7 +41,7 @@ class Mod { return Mod( mod_name: ct.get("name")!.asString(), - mod_id: ct.get("id")!.asInt(), + mod_id: ct.get("id")!.asLong(), mod_pak: ct.get("pak")!.asString(), mod_hash: ct.get("hash")!.asString()); } diff --git a/lib/structs/settings.dart b/lib/structs/settings.dart index 4130058..129d2f8 100644 --- a/lib/structs/settings.dart +++ b/lib/structs/settings.dart @@ -10,7 +10,6 @@ import 'package:libac_flutter/packets/packets.dart'; import 'package:libac_flutter/utils/IOTools.dart'; import 'package:libac_flutter/utils/uuid/NbtUUID.dart'; import 'package:libac_flutter/utils/uuid/UUID.dart'; -import 'package:rcon/rcon.dart'; import 'package:servermanager/statemachine.dart'; import 'package:servermanager/structs/credentials.dart'; import 'package:servermanager/structs/mod.dart'; @@ -274,11 +273,7 @@ class Settings { } Future sendRconCommand(String command) async { - Client cli = - await Client.create("127.0.0.1", inst!.serverSettings.RconPort); - Message msg = Message.create(cli, PacketType.command, command); - - return cli.send(msg).payload; + createSocket("127.0.0.1", port: inst!.serverSettings.RconPort); } Future initializeProton() async { diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 64a0ece..e71a16d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,10 +6,6 @@ #include "generated_plugin_registrant.h" -#include void fl_register_plugins(FlPluginRegistry* registry) { - g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); - file_selector_plugin_register_with_registrar(file_selector_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2db3c22..2e1de87 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - file_selector_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 14b5f7c..cccf817 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,6 @@ import FlutterMacOS import Foundation -import file_selector_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) } diff --git a/pubspec.yaml b/pubspec.yaml index 4b474f4..f436bd1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,14 +35,13 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - file_selector: archive: dio: crypto: libac_flutter: hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/ version: 1.0.20 - rcon: ^1.0.0 + mc_rcon_dart: ^1.1.0 dev_dependencies: flutter_test: diff --git a/test/rcon_command.dart b/test/rcon_command.dart index 9846a78..bf0e3dc 100644 --- a/test/rcon_command.dart +++ b/test/rcon_command.dart @@ -8,6 +8,8 @@ void main() { settings.server = false; settings.inst = SettingsEntry(); - await settings.sendRconCommand("help"); + var reply = await settings.sendRconCommand("help"); + + print(reply); }); } diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 77ab7a0..8b6d468 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,6 @@ #include "generated_plugin_registrant.h" -#include void RegisterPlugins(flutter::PluginRegistry* registry) { - FileSelectorWindowsRegisterWithRegistrar( - registry->GetRegistrarForPlugin("FileSelectorWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index a423a02..b93c4c3 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - file_selector_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST