diff --git a/lib/consts.dart b/lib/consts.dart index b9e3858..1b3b851 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -1,3 +1,3 @@ class Consts { - static const VERSION = "1.1.112324.1803"; + static const VERSION = "1.1.112324.1951"; } diff --git a/lib/main.dart b/lib/main.dart index 324a2f2..4c1aba5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -89,10 +89,11 @@ class ServerPage extends StatelessWidget { int retryCount = 0; while (true) { try { - if (retryCount > 0) + if (retryCount > 0) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( "> Retrying to download settings in 10 seconds (Attempt $retryCount"))); + } await Future.delayed(Duration(seconds: 10)); S2CResponse settingsData = await settings.client! diff --git a/lib/packets/ClientPackets.dart b/lib/packets/ClientPackets.dart index 8725dee..d526bcb 100644 --- a/lib/packets/ClientPackets.dart +++ b/lib/packets/ClientPackets.dart @@ -106,12 +106,12 @@ class C2SLoginPacket implements IPacket { // Attempt to log in. Settings settings = Settings(); - if (settings.superuser!.login(username, password)) { + if (settings.superuser.login(username, password)) { settings.remoteLoginToken = UUID.generate(4); loginReply.valid = true; loginReply.token = settings.remoteLoginToken; - settings.superuser!.sendDiscordActionLog("Login Success"); + settings.superuser.sendDiscordActionLog("Login Success"); settings.loggedInUser = settings.superuser; } else { @@ -121,7 +121,7 @@ class C2SLoginPacket implements IPacket { // Properly handle the disabled account if (loginReply.valid && username == "_disabled") loginReply.valid = false; - if (!loginReply.valid && settings.superuser!.name != username) { + if (!loginReply.valid && settings.superuser.name != username) { // Check for a lower level user if (settings.inst!.admins.any((T) => T.name == username)) { User theUser = @@ -358,12 +358,20 @@ class C2SUploadSettingsPacket implements IPacket { // Send a webhook with all the mods listed String modListText = ""; for (var entry in settings.inst!.mods) { - modListText += "${entry.mod_name}\n"; + if (entry.enabled) modListText += "${entry.mod_name}\n"; } modListText = modListText.trim(); - DiscordHookHelper.sendWebHook(settings.inst!.discord, - DiscordHookProps.INACTIVE, "Mod List", modListText); + if (modListText.isEmpty) { + DiscordHookHelper.sendWebHook( + settings.inst!.discord, + DiscordHookProps.INACTIVE, + "Mod List", + "The Server is currently vanilla"); + } else { + DiscordHookHelper.sendWebHook(settings.inst!.discord, + DiscordHookProps.INACTIVE, "Mod List", modListText); + } // Check if server is running, if not, stop immediately // If server is running, schedule restart for 1 minute and send a alert to all players, then perform stop or restart depending on if running in Pterodactyl Compatibility mode @@ -456,7 +464,7 @@ class C2SRequestCreateBackup implements IPacket { world.copy(pth.build()); settings.loggedInUser! - .sendDiscordActionLog("Created a new backup named ${fileName}"); + .sendDiscordActionLog("Created a new backup named $fileName"); } return PacketResponse.nil; @@ -651,7 +659,7 @@ class C2SRequestSnapshotDeletion implements IPacket { ph.deleteFile(); settings.loggedInUser!.sendDiscordActionLog( - "Requested snapshot deletion of backup named: ${snapshotName}"); + "Requested snapshot deletion of backup named: $snapshotName"); return PacketResponse.nil; } @@ -714,7 +722,7 @@ class C2SRequestWorldRestore implements IPacket { SessionData.CURRENT_INTERVAL = WarnIntervals.NONE; settings.loggedInUser!.sendDiscordActionLog( - "Requested world restore, and initiated a immediate restart. World restored: ${snapshot}"); + "Requested world restore, and initiated a immediate restart. World restored: $snapshot"); return PacketResponse.nil; } diff --git a/lib/pages/ACL.dart b/lib/pages/ACL.dart index e73271c..44ab4c6 100644 --- a/lib/pages/ACL.dart +++ b/lib/pages/ACL.dart @@ -27,7 +27,7 @@ class AccessControlState extends State { if (reply == null) return; if (reply is User) { setState(() { - settings.inst!.admins.add(reply as User); + settings.inst!.admins.add(reply); }); } }, diff --git a/lib/pages/ModManager.dart b/lib/pages/ModManager.dart index eb4aa5d..4362587 100644 --- a/lib/pages/ModManager.dart +++ b/lib/pages/ModManager.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:servermanager/structs/discordHookHelper.dart'; import '../structs/mod.dart'; import '../structs/settings.dart'; @@ -24,28 +23,31 @@ class ModManagerState extends State { backgroundColor: Color.fromARGB(255, 100, 0, 0), actions: [ IconButton( - onPressed: () { + onPressed: () async { for (Mod M in settings.inst!.mods) { M.enabled = false; + await Future.delayed(Duration(milliseconds: 500)); + settings.loggedInUser! .sendDiscordActionLog("${M.mod_name} was disabled"); - ; - } - setState(() {}); + setState(() {}); + } }, icon: Icon(Icons.swipe_down)), IconButton( - onPressed: () { + onPressed: () async { for (Mod M in settings.inst!.mods) { M.enabled = true; + await Future.delayed(Duration(milliseconds: 500)); + settings.loggedInUser! .sendDiscordActionLog("${M.mod_name} was enabled"); - } - setState(() {}); + setState(() {}); + } }, icon: Icon(Icons.swipe_up)) ], @@ -65,7 +67,7 @@ class ModManagerState extends State { settings.inst!.mods[end] = item; settings.loggedInUser!.sendDiscordActionLog( - "Reordered Mod List\n\n${item.mod_name} is now in load order ${end}"); + "Reordered Mod List\n\n${item.mod_name} is now in load order $end"); } else if (oldIndex > newIndex) { //From bottom to top Mod item = settings.inst!.mods[oldIndex]; @@ -75,7 +77,7 @@ class ModManagerState extends State { settings.inst!.mods[newIndex] = item; settings.loggedInUser!.sendDiscordActionLog( - "Reordered Mod List\n\n${item.mod_name} is now in load order ${newIndex}"); + "Reordered Mod List\n\n${item.mod_name} is now in load order $newIndex"); } setState(() { settings.Write(); diff --git a/lib/pages/autorestart.dart b/lib/pages/autorestart.dart index f4751a2..89e3dcb 100644 --- a/lib/pages/autorestart.dart +++ b/lib/pages/autorestart.dart @@ -119,7 +119,7 @@ class AutoRestartState extends State { ElevatedButton( onPressed: () { settings.loggedInUser!.sendDiscordActionLog( - "Updated AutoRestart Information\n\nEnabled: ${enabled}\nTimer: ${time}"); + "Updated AutoRestart Information\n\nEnabled: $enabled\nTimer: $time"); Navigator.pop(context, AutomaticRestartInfo(enabled: enabled, time: time)); diff --git a/lib/structs/credentials.dart b/lib/structs/credentials.dart index e6ef307..35aaca2 100644 --- a/lib/structs/credentials.dart +++ b/lib/structs/credentials.dart @@ -13,17 +13,20 @@ class User { final String userHash; bool login(String username, String passwordHash) { - if (userHash != generateValidityCheck()) + if (userHash != generateValidityCheck()) { return false; // User will be thrown away next time the data is reloaded + } if (name == username) { - if (Hashing.sha256Hash("${passwordSalt}:${passwordHash}") == + if (Hashing.sha256Hash("$passwordSalt:$passwordHash") == this.passwordHash) { return true; - } else + } else { return false; - } else + } + } else { return false; + } } Future sendDiscordActionLog(String actionMessage) async { @@ -33,7 +36,7 @@ class User { settings.inst!.discord, DiscordHookProps.ALERT, "User Action Alert", - "${this}: ${actionMessage}"); + "$this: $actionMessage"); } User( @@ -65,8 +68,8 @@ class User { factory User.make(String name, String password, UserLevel level) { String salt = Hashing.sha256Hash( - "${Hashing.md5Hash("${Hashing.sha256Hash("${DateTime.now().millisecondsSinceEpoch}")}")}"); - String hash = Hashing.sha256Hash("${salt}:${Hashing.sha256Hash(password)}"); + Hashing.md5Hash(Hashing.sha256Hash("${DateTime.now().millisecondsSinceEpoch}"))); + String hash = Hashing.sha256Hash("$salt:${Hashing.sha256Hash(password)}"); String validityCode = generateValidityCode(name, hash, salt, level); return User( @@ -79,13 +82,13 @@ class User { String generateValidityCheck() { return Hashing.sha256Hash( - "${name}:${passwordHash}:${passwordSalt}:${permissions.ord()}}"); + "$name:$passwordHash:$passwordSalt:${permissions.ord()}}"); } static String generateValidityCode(String name, String passwordHash, String passwordSalt, UserLevel permissions) { return Hashing.sha256Hash( - "${name}:${passwordHash}:${passwordSalt}:${permissions.ord()}}"); + "$name:$passwordHash:$passwordSalt:${permissions.ord()}}"); } static const TAG_NAME = "name"; @@ -96,7 +99,7 @@ class User { @override String toString() { - return "${permissions.name}: ${name}"; + return "${permissions.name}: $name"; } } diff --git a/lib/structs/settings.dart b/lib/structs/settings.dart index f1f15cb..a76c62b 100644 --- a/lib/structs/settings.dart +++ b/lib/structs/settings.dart @@ -85,11 +85,13 @@ 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 - if (tag.containsKey("superuser")) + if (tag.containsKey("superuser")) { superuser = User.deserialize(tag.get("superuser")!.asCompoundTag()); + } - if (tag.containsKey("wine_init")) + if (tag.containsKey("wine_init")) { wineInitialized = NbtUtils.readBoolean(tag, "wine_init"); + } if (tag.containsKey("main")) { inst = SettingsEntry.deserialize(tag.get("main")!.asCompoundTag()); @@ -105,11 +107,13 @@ class Settings { inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag); - if (tag.containsKey("wine_init")) + if (tag.containsKey("wine_init")) { wineInitialized = NbtUtils.readBoolean(tag, "wine_init"); + } - if (tag.containsKey("superuser")) + if (tag.containsKey("superuser")) { superuser = User.deserialize(tag.get("superuser")!.asCompoundTag()); + } FTS = NbtUtils.readBoolean(tag, "fts"); } catch (E) { diff --git a/lib/structs/settingsEntry.dart b/lib/structs/settingsEntry.dart index 2ddd399..d741279 100644 --- a/lib/structs/settingsEntry.dart +++ b/lib/structs/settingsEntry.dart @@ -52,7 +52,7 @@ class SettingsEntry { st.admins.add(loadedUser); } else { print( - "/!\\ FATAL /!\\\n\n${loadedUser} failed to pass the validity check and has been tampered with"); + "/!\\ FATAL /!\\\n\n$loadedUser failed to pass the validity check and has been tampered with"); } } } diff --git a/pubspec.yaml b/pubspec.yaml index 8398dad..6a03ba4 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.112324+1803 +version: 1.1.112324+1951 environment: sdk: ">=3.1.4 <4.0.0"