Adds a Request Restart switch

This commit is contained in:
zontreck 2024-07-01 23:13:04 -07:00
parent bdebdf89d5
commit fa26d2f914
2 changed files with 20 additions and 2 deletions

View file

@ -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;

View file

@ -17,6 +17,7 @@ class HomePage extends StatefulWidget {
class HomePageState extends State<HomePage> {
Settings settings = Settings();
bool requireRestart=false;
HomePageState({required this.settings});
@ -112,15 +113,22 @@ class HomePageState extends State<HomePage> {
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"),)
],
)),
);