diff --git a/lib/main.dart b/lib/main.dart index 8f59a5e..7d204a3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,7 +8,6 @@ import 'package:servermanager/proton.dart'; import 'package:servermanager/serversettings.dart'; import 'package:servermanager/settings.dart'; import 'package:servermanager/settingsEntry.dart'; -import 'package:servermanager/steamcmd.dart'; Future main() async { await Hive.initFlutter(); @@ -34,14 +33,15 @@ class MyApp extends StatelessWidget { routes: { "/home": (context) => HomePage(settings: appSettings), "/proton": (context) => Proton(settings: appSettings), - "/steamcmd": (context) => SteamCMD( - settings: appSettings, - ), + //"/steamcmd": (context) => SteamCMD( + // settings: appSettings, + // ), "/server": (context) => GameServerPage(settings: appSettings), "/server/autorestart": (context) => AutoRestartPage(), "/server/ports": (context) => ServerSettingsPage(), "/server/mods": (context) => ModManager(settings: appSettings), "/server/mods/edit": (context) => ModPage(), + //"/steamcmd/creds": (context) => CredentialsPrompt() }); } } diff --git a/lib/steamcmd.dart b/lib/steamcmd.dart index 06e28af..38204c5 100644 --- a/lib/steamcmd.dart +++ b/lib/steamcmd.dart @@ -4,6 +4,7 @@ import 'package:archive/archive_io.dart'; import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:servermanager/credentials.dart'; import 'package:servermanager/dialogbox.dart'; import 'package:servermanager/settings.dart'; @@ -66,8 +67,7 @@ class SteamCMDState extends State { if (Platform.isWindows) { // Download zip file - final path = - "${settings.steamcmd_path}${Platform.pathSeparator}windows.zip"; + final path = "${settings.steamcmd_path}${Platform.pathSeparator}windows.zip"; final reply = await dio.download(windows, path); final bytes = File(path).readAsBytesSync(); @@ -91,8 +91,7 @@ class SteamCMDState extends State { await Process.start("steamcmd.exe", ["+quit"]); } else { // Download tgz file - final path = - "${settings.steamcmd_path}${Platform.pathSeparator}linux.tgz"; + final path = "${settings.steamcmd_path}${Platform.pathSeparator}linux.tgz"; final reply = await dio.download(linux, path); final bytes = File(path).readAsBytesSync(); @@ -148,8 +147,139 @@ class SteamCMDState extends State { ]); } }), + ListTile( + title: Text("Credentials"), + leading: Icon(Icons.key_sharp), + subtitle: Text("Steam Credentials"), + onTap: () async { + var creds = await Navigator.pushNamed(context, "/steamcmd/creds", + arguments: settings.inst!.steam_creds); + if (creds != null) { + Credentials cred = creds as Credentials; + setState(() { + settings.inst!.steam_creds = cred; + settings.Write(); + }); + } + }, + ), ], )), ); } } + +// Returns a Credentials Object +class CredentialsPrompt extends StatelessWidget { + TextEditingController username = TextEditingController(); + TextEditingController password = TextEditingController(); + TextEditingController secret = TextEditingController(); + bool initialInitDone = false; + + @override + Widget build(BuildContext context) { + final args = ModalRoute.of(context)!.settings.arguments as Credentials?; + + if (args != null) { + if (!initialInitDone) { + username.text = args.username; + password.text = args.password; + secret.text = args.secret; + initialInitDone = true; + } + } + + return Scaffold( + appBar: AppBar( + title: + Text("Conan Exiles Server Manager - Steam Command - Credentials"), + backgroundColor: Color.fromARGB(255, 100, 0, 0), + ), + body: WillPopScope( + child: SingleChildScrollView( + padding: EdgeInsets.all(16), + child: Column( + children: [ + Row( + children: [ + SizedBox( + width: 150, + child: Row( + children: [ + Icon(Icons.person), + Text("Username:"), + ], + )), + Expanded( + child: TextField( + controller: username, + decoration: InputDecoration( + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(4))), + ), + ) + ], + ), + SizedBox( + height: 16, + ), + Row( + children: [ + SizedBox( + width: 150, + child: Row( + children: [ + Icon(Icons.key), + Text("Password:"), + ], + )), + Expanded( + child: TextField( + controller: password, + keyboardType: TextInputType.visiblePassword, + decoration: InputDecoration( + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(4))), + ), + ) + ], + ), + SizedBox( + height: 16, + ), + Row( + children: [ + SizedBox( + width: 150, + child: Row( + children: [ + Icon(Icons.dangerous), + Text("Secret:"), + ], + )), + Expanded( + child: TextField( + controller: secret, + keyboardType: TextInputType.visiblePassword, + decoration: InputDecoration( + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(4)), + hintText: + "2FA Shared Secret Code (Do Not Share With Others!)"), + )) + ], + ) + ], + )), + onWillPop: () async { + Navigator.pop( + context, + Credentials( + username: username.text, + password: password.text, + secret: secret.text)); + return true; + }, + )); + } +}