diff --git a/bin/server.dart b/bin/server.dart index cedf5dd..b3658d0 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -18,7 +18,7 @@ void main() async { await settings.Read(); print( - "Server Admin Credentials\nUsername: ${settings.serverLoginCreds.username}\nPassword: ${settings.serverLoginCreds.password}\n\n"); + "Server Admin Credentials\nUsername: ${settings.superuser.name}\nPassword (Default): changeMe123\n\n"); PathHelper helper = PathHelper(pth: Directory.current.path); helper = helper.resolve("data").mkdir(); @@ -33,22 +33,26 @@ void main() async { print("Setup of local system variables completed"); + if (settings.FTS) { + Settings.Clear(); // Initialize the super-user account + print("Super-User Account initialized with default credentials"); + settings.server = true; + } + settings.Write(); print("Wrote settings.dat"); - if (settings.FTS) - settings.superuser = User.make( - settings.serverLoginCreds.username, - settings.serverLoginCreds.password, - UserLevel.Super_User); // Initialize the super-user account - print("Initializing SteamCMD"); await settings.initializeSteamCmd(); print("Initialized Steamcmd"); print("Running winetricks"); - //if (!Directory(settings.getWinePrefixPath()).existsSync()) - // await settings.initializeWine(); + if (!settings.wineInitialized) { + await settings.initializeWine(); + settings.wineInitialized = true; + settings.Write(); + } + print("Finished installing needed DLLs"); print("Checking for game server updates..."); diff --git a/lib/main.dart b/lib/main.dart index c871efd..c686c90 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,7 +7,6 @@ import 'package:servermanager/pages/DiscordConfigPage.dart'; import 'package:servermanager/pages/GameServerPage.dart'; import 'package:servermanager/pages/ModManager.dart'; import 'package:servermanager/pages/autorestart.dart'; -import 'package:servermanager/pages/credentials_prompt.dart'; import 'package:servermanager/pages/home.dart'; import 'package:servermanager/pages/snapshots.dart'; import 'package:servermanager/structs/settings.dart'; @@ -30,7 +29,6 @@ class MyApp extends StatelessWidget { routes: { "/": (context) => ServerPage(), "/home": (context) => HomePage(settings: appSettings), - "/creds": (context) => CredentialsPage(), "/acl": (context) => AccessControlListPage(), "/acl/edit": (context) => ACLEdit(), "/server": (context) => GameServerPage(settings: appSettings), diff --git a/lib/pages/ACL.dart b/lib/pages/ACL.dart index 9d80887..e73271c 100644 --- a/lib/pages/ACL.dart +++ b/lib/pages/ACL.dart @@ -76,6 +76,7 @@ class ACLEditorState extends State { var newUser = false; TextEditingController username = TextEditingController(); TextEditingController password = TextEditingController(); + var canDelete = true; User? current; @@ -84,11 +85,15 @@ class ACLEditorState extends State { var args = ModalRoute.of(context)!.settings.arguments; if (args == null) { newUser = true; + canDelete = false; } else { User usr = args as User; username.text = usr.name; current = usr; + canDelete = true; + + if (usr.permissions == UserLevel.Super_User) canDelete = false; } setState(() {}); @@ -186,7 +191,7 @@ class ACLEditorState extends State { SizedBox( height: 50, ), - if (!newUser) + if (canDelete) ListTile( title: Text("DELETE USER"), leading: Icon(Icons.delete), diff --git a/lib/pages/credentials_prompt.dart b/lib/pages/credentials_prompt.dart deleted file mode 100644 index 760fc3a..0000000 --- a/lib/pages/credentials_prompt.dart +++ /dev/null @@ -1,100 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:servermanager/structs/credentials.dart'; - -class CredentialsPage extends StatefulWidget { - @override - CredentialsPrompt createState() => CredentialsPrompt(); -} - -// Returns a Credentials Object -class CredentialsPrompt extends State { - TextEditingController username = TextEditingController(); - TextEditingController password = TextEditingController(); - bool initialInitDone = false; - - @override - void initState() {} - - @override - void didChangeDependencies() { - final args = ModalRoute.of(context)!.settings.arguments as Credentials?; - - if (args != null) { - if (!initialInitDone) { - username.text = args.username; - password.text = args.password; - initialInitDone = true; - } - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("Conan Exiles Server Manager - Credentials"), - backgroundColor: Color.fromARGB(255, 100, 0, 0), - ), - floatingActionButton: ElevatedButton( - child: Text("Save"), - onPressed: () { - Navigator.pop( - context, - Credentials( - username: username.text, - password: password.text, - )); - }, - ), - body: 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))), - ), - ) - ], - ), - ], - ))); - } -} diff --git a/lib/pages/home.dart b/lib/pages/home.dart index cb537ac..668ed01 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -97,11 +97,14 @@ class HomePageState extends State { Text("Edit ServerManager credentials (SUPER USER ONLY)"), leading: Icon(Icons.key), onTap: () async { - var reply = await Navigator.pushNamed(context, "/creds", - arguments: settings.superuser.name); - if (reply != null) { - Credentials creds = reply as Credentials; - settings.serverLoginCreds = creds; + if (settings.loggedInUser!.permissions == + UserLevel.Super_User) { + var reply = await Navigator.pushNamed(context, "/acl/edit", + arguments: settings.superuser); + if (reply != null) { + var creds = reply as User; + settings.superuser = creds; + } } }, ), diff --git a/lib/structs/credentials.dart b/lib/structs/credentials.dart index 67b1d8c..e6ef307 100644 --- a/lib/structs/credentials.dart +++ b/lib/structs/credentials.dart @@ -5,34 +5,6 @@ import 'package:libac_dart/utils/Hashing.dart'; import 'package:servermanager/structs/discordHookHelper.dart'; import 'package:servermanager/structs/settings.dart'; -class Credentials { - String username; - String password; - - Credentials({ - required this.username, - required this.password, - }); - - CompoundTag save() { - CompoundTag tag = CompoundTag(); - tag.put(TAG_USERNAME, StringTag.valueOf(username)); - tag.put(TAG_PASSWORD, StringTag.valueOf(password)); - - return tag; - } - - static Credentials deserialize(CompoundTag tag) { - return Credentials( - username: tag.get(TAG_USERNAME)?.asString() ?? "", - password: tag.get(TAG_PASSWORD)?.asString() ?? ""); - } - - static const TAG_NAME = "credentials"; - static const TAG_USERNAME = "username"; - static const TAG_PASSWORD = "password"; -} - class User { String name; String passwordHash; diff --git a/lib/structs/settings.dart b/lib/structs/settings.dart index 4f18ddb..73db217 100644 --- a/lib/structs/settings.dart +++ b/lib/structs/settings.dart @@ -29,14 +29,13 @@ class Settings { static final Settings Instance = Settings._(); bool server = true; + bool wineInitialized = false; String steamcmd_path = ""; String game_path = ""; String base_path = ""; String gameServerDBFile = ""; bool FTS = true; - Credentials serverLoginCreds = - Credentials(username: "admin", password: "changeMe123"); UUID remoteLoginToken = UUID.ZERO; PacketClient? client; @@ -57,8 +56,8 @@ class Settings { tag.put("base", StringTag.valueOf(base_path)); tag.put("dbfile", StringTag.valueOf(getWorldGameDB())); NbtUtils.writeBoolean(tag, "fts", FTS); + NbtUtils.writeBoolean(tag, "wine_init", wineInitialized); - tag.put("server_creds", serverLoginCreds.save()); tag.put("superuser", superuser.serialize()); NbtUtils.writeUUID(tag, "token", NbtUUID.fromUUID(remoteLoginToken)); @@ -86,8 +85,7 @@ class Settings { FTS = NbtUtils.readBoolean(tag, "fts"); // First Time Setup. // FTS should be disabled by the client when sending it back to the server in a C2SApplySettingsPacket - serverLoginCreds = - Credentials.deserialize(tag.get("server_creds")!.asCompoundTag()); + superuser = User.deserialize(tag.get("superuser")!.asCompoundTag()); if (tag.containsKey("main")) { inst = SettingsEntry.deserialize(tag.get("main")!.asCompoundTag()); @@ -102,21 +100,13 @@ class Settings { var tag = await NbtIo.read("settings.dat"); inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag); - serverLoginCreds = Credentials.deserialize( - tag.get(Credentials.TAG_NAME)!.asCompoundTag()); + wineInitialized = NbtUtils.readBoolean(tag, "wine_init"); FTS = NbtUtils.readBoolean(tag, "fts"); } catch (E) { print("No existing settings file found, initializing default settings"); inst = SettingsEntry(); - inst!.steam_creds = Credentials( - username: "", - password: "", - ); - serverLoginCreds = Credentials( - username: "admin", - password: "changeMe123", - ); + superuser = User.make("admin", "changeMe123", UserLevel.Super_User); FTS = true; } } @@ -128,8 +118,9 @@ class Settings { if (inst == null) return; CompoundTag tag = CompoundTag(); tag.put("entry", inst!.serialize()); - tag.put(Credentials.TAG_NAME, serverLoginCreds.save()); + tag.put("superuser", superuser.serialize()); NbtUtils.writeBoolean(tag, "fts", FTS); + NbtUtils.writeBoolean(tag, "wine_init", wineInitialized); NbtIo.write("settings.dat", tag); } @@ -319,7 +310,6 @@ class Settings { Future initializeWine() async { await runWinetrick("win10"); - await runWinetrick("w_workaround_wine_bug-50894"); await runWinetrick("cmd"); await runWinetrick("vcrun2013"); await runWinetrick("vcrun2015"); @@ -413,7 +403,8 @@ class Settings { static void Clear() { Instance.inst = SettingsEntry(); Instance.subsys = StateMachine(); - Instance.serverLoginCreds = Credentials(username: "admin", password: ""); + Instance.superuser = + User.make("admin", "changeMe123", UserLevel.Super_User); Instance.server = false; } } diff --git a/lib/structs/settingsEntry.dart b/lib/structs/settingsEntry.dart index ab80525..2ddd399 100644 --- a/lib/structs/settingsEntry.dart +++ b/lib/structs/settingsEntry.dart @@ -15,7 +15,7 @@ class SettingsEntry { DiscordHookProps discord = DiscordHookProps(url: "", serverName: "", enabled: false); - Credentials? steam_creds; + bool pterodactylMode = true; // Default is to be compatible AutomaticRestartInfo timer = AutomaticRestartInfo(time: Time(hours: 0, minutes: 0, seconds: 0)); diff --git a/pubspec.yaml b/pubspec.yaml index 6966848..47a220f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.0+36 +version: 1.1.0+39 environment: sdk: '>=3.1.4 <4.0.0'