diff --git a/lib/packets/ClientPackets.dart b/lib/packets/ClientPackets.dart index 19e93b0..daa1141 100644 --- a/lib/packets/ClientPackets.dart +++ b/lib/packets/ClientPackets.dart @@ -13,6 +13,7 @@ import 'package:libac_dart/utils/uuid/NbtUUID.dart'; import 'package:libac_dart/utils/uuid/UUID.dart'; import 'package:servermanager/statemachine.dart'; import 'package:servermanager/structs/SessionData.dart'; +import 'package:servermanager/structs/discordHookHelper.dart'; import 'package:servermanager/structs/settings.dart'; class ClientPackets { @@ -246,6 +247,8 @@ class C2SRequestSettingsPacket implements IPacket { class C2SUploadSettingsPacket implements IPacket { CompoundTag srvSettings = CompoundTag(); + bool performRestart = false; + @override void decodeJson(String params) {} @@ -269,6 +272,7 @@ class C2SUploadSettingsPacket implements IPacket { Tag encodeTag() { CompoundTag tag = CompoundTag(); tag.put("settings", Settings().serialize()); + NbtUtils.writeBoolean(tag, "restart", performRestart); return tag; } @@ -295,9 +299,15 @@ class C2SUploadSettingsPacket implements IPacket { settings.deserialize(srvSettings); settings.Write(); + if(!performRestart){ + DiscordHookHelper.sendWebHook(settings.inst!.discord, DiscordHookProps.ONLINE_ALERT, "Server Wrapper Settings", "Server wrapper settings have been updated.\n\n${performRestart ? "A restart has been requested" : "A restart is not needed"}"); + + return PacketResponse.nil; + } + // 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 - SessionData.shutdownMessage = "Server wrapper updated. Restart required."; + SessionData.shutdownMessage = "Server wrapper restart"; SessionData.timer.apply(60); SessionData.CURRENT_INTERVAL = WarnIntervals.NONE; diff --git a/lib/pages/home.dart b/lib/pages/home.dart index f400616..d43d54e 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -17,6 +17,7 @@ class HomePage extends StatefulWidget { class HomePageState extends State { Settings settings = Settings(); + bool requireRestart=false; HomePageState({required this.settings}); @@ -112,15 +113,22 @@ class HomePageState extends State { C2SUploadSettingsPacket upload = C2SUploadSettingsPacket(); upload.srvSettings = settings.serialize(); + upload.performRestart=requireRestart; await settings.client!.send(upload, false); Settings.Clear(); setState(() {}); - Navigator.pop(context); + if(requireRestart) + Navigator.pop(context); }, ) + , SwitchListTile(value: requireRestart, onChanged: (V) { + setState(() { + requireRestart = V; + }); + }, title: Text("Perform Restart"), subtitle: Text("Whether a immediate server restart should be performed in combination with this wrapper settings update"),) ], )), );