93 lines
3 KiB
Dart
93 lines
3 KiB
Dart
import 'package:libac_dart/nbt/NbtUtils.dart';
|
|
import 'package:libac_dart/nbt/Tag.dart';
|
|
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
|
import 'package:libac_dart/nbt/impl/ListTag.dart';
|
|
import 'package:libac_dart/utils/TimeUtils.dart';
|
|
import 'package:servermanager/structs/autorestarts.dart';
|
|
import 'package:servermanager/structs/credentials.dart';
|
|
import 'package:servermanager/structs/discordHookHelper.dart';
|
|
import 'package:servermanager/structs/mod.dart';
|
|
import 'package:servermanager/structs/serversettings.dart';
|
|
|
|
class SettingsEntry {
|
|
List<Mod> mods = [];
|
|
List<User> admins = [];
|
|
|
|
DiscordHookProps discord =
|
|
DiscordHookProps(url: "", serverName: "", enabled: false);
|
|
|
|
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,
|
|
WrapperPort: 25306);
|
|
|
|
static SettingsEntry deserialize(CompoundTag tag) {
|
|
SettingsEntry st = SettingsEntry();
|
|
|
|
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");
|
|
}
|
|
|
|
if (tag.containsKey(DiscordHookProps.TAG_NAME)) {
|
|
st.discord = DiscordHookProps.deserialize(
|
|
tag.get(DiscordHookProps.TAG_NAME)!.asCompoundTag());
|
|
}
|
|
|
|
if (tag.containsKey("admins")) {
|
|
ListTag adminUsers = tag.get("admins")! as ListTag;
|
|
for (int i = 0; i < adminUsers.size(); i++) {
|
|
CompoundTag entry = adminUsers.get(i).asCompoundTag();
|
|
User loadedUser = User.deserialize(entry);
|
|
if (loadedUser.userHash == loadedUser.generateValidityCheck()) {
|
|
st.admins.add(loadedUser);
|
|
} else {
|
|
print(
|
|
"/!\\ FATAL /!\\\n\n${loadedUser} failed to pass the validity check and has been tampered with");
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
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);
|
|
|
|
tag.put(DiscordHookProps.TAG_NAME, discord.serialize());
|
|
|
|
ListTag adminUsers = ListTag();
|
|
for (User usr in admins) {
|
|
adminUsers.add(usr.serialize());
|
|
}
|
|
|
|
tag.put("admins", adminUsers);
|
|
|
|
return tag;
|
|
}
|
|
}
|