ConanServerManager/lib/structs/settingsEntry.dart

64 lines
2.1 KiB
Dart

import 'package:libac_flutter/nbt/NbtUtils.dart';
import 'package:libac_flutter/nbt/Tag.dart';
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
import 'package:libac_flutter/nbt/impl/ListTag.dart';
import 'package:libac_flutter/utils/TimeUtils.dart';
import 'package:servermanager/structs/autorestarts.dart';
import 'package:servermanager/structs/credentials.dart';
import 'package:servermanager/structs/mod.dart';
import 'package:servermanager/structs/serversettings.dart';
class SettingsEntry {
List<Mod> mods = [];
Credentials? steam_creds;
bool pterodactylMode = true; // Default is to be compatible
AutomaticRestartInfo timer =
AutomaticRestartInfo(time: Time(hours: 0, minutes: 0, seconds: 0));
ServerSettings serverSettings = ServerSettings(
RconPassword: "Password01234",
RconPort: 7779,
GamePort: 7780,
QueryPort: 7782);
static SettingsEntry deserialize(CompoundTag tag) {
SettingsEntry st = SettingsEntry();
if (tag.containsKey(Credentials.TAG_NAME)) {
st.steam_creds =
Credentials.deserialize(tag.get(Credentials.TAG_NAME) as CompoundTag);
}
st.timer = AutomaticRestartInfo.deserialize(
tag.get(AutomaticRestartInfo.TAG_NAME) as CompoundTag);
st.serverSettings = ServerSettings.deserialize(
tag.get(ServerSettings.TAG_NAME) as CompoundTag);
if (tag.containsKey("pterodactyl")) {
st.pterodactylMode = NbtUtils.readBoolean(tag, "pterodactyl");
}
st.mods.clear();
ListTag lMods = tag.get("mods") as ListTag;
for (Tag tag in lMods.value) {
CompoundTag cTag = tag.asCompoundTag();
st.mods.add(Mod.deserialize(cTag));
}
return st;
}
CompoundTag serialize() {
CompoundTag tag = CompoundTag();
if (steam_creds != null) tag.put(Credentials.TAG_NAME, steam_creds!.save());
tag.put(AutomaticRestartInfo.TAG_NAME, timer.serialize());
tag.put(ServerSettings.TAG_NAME, serverSettings.serialize());
NbtUtils.writeBoolean(tag, "pterodactyl", pterodactylMode);
ListTag lMods = ListTag();
for (Mod mod in mods) {
lMods.add(mod.serialize());
}
tag.put("mods", lMods);
return tag;
}
}