Got more things functional
This commit is contained in:
parent
a1141cd2b8
commit
fc0c1c7e7a
23 changed files with 1080 additions and 876 deletions
|
@ -5,14 +5,19 @@ import 'package:dio/dio.dart';
|
|||
import 'package:libac_flutter/nbt/NbtIo.dart';
|
||||
import 'package:libac_flutter/nbt/NbtUtils.dart';
|
||||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_flutter/nbt/impl/StringTag.dart';
|
||||
import 'package:libac_flutter/packets/packets.dart';
|
||||
import 'package:libac_flutter/utils/IOTools.dart';
|
||||
import 'package:libac_flutter/utils/uuid/NbtUUID.dart';
|
||||
import 'package:libac_flutter/utils/uuid/UUID.dart';
|
||||
import 'package:rcon/rcon.dart';
|
||||
import 'package:servermanager/statemachine.dart';
|
||||
import 'package:servermanager/structs/credentials.dart';
|
||||
import 'package:servermanager/structs/mod.dart';
|
||||
import 'package:servermanager/structs/settingsEntry.dart';
|
||||
|
||||
import '../proton.dart';
|
||||
|
||||
class Settings {
|
||||
final String windows =
|
||||
"https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip";
|
||||
|
@ -28,13 +33,15 @@ class Settings {
|
|||
Settings._();
|
||||
static final Settings Instance = Settings._();
|
||||
|
||||
bool server = true;
|
||||
|
||||
String steamcmd_path = "";
|
||||
String game_path = "";
|
||||
String proton_path = "";
|
||||
String base_path = "";
|
||||
bool FTS = true;
|
||||
Credentials serverLoginCreds = Credentials(
|
||||
username: "admin", password: "changeMe123", secret: "", has_2fa: false);
|
||||
Credentials serverLoginCreds =
|
||||
Credentials(username: "admin", password: "changeMe123");
|
||||
UUID remoteLoginToken = UUID.ZERO;
|
||||
|
||||
PacketClient? client;
|
||||
|
@ -45,9 +52,50 @@ class Settings {
|
|||
return Instance;
|
||||
}
|
||||
|
||||
CompoundTag serialize() {
|
||||
CompoundTag tag = CompoundTag();
|
||||
tag.put("steamcmd", StringTag.valueOf(steamcmd_path));
|
||||
tag.put("game", StringTag.valueOf(game_path));
|
||||
tag.put("proton", StringTag.valueOf(proton_path));
|
||||
tag.put("base", StringTag.valueOf(base_path));
|
||||
NbtUtils.writeBoolean(tag, "fts", FTS);
|
||||
|
||||
tag.put("server_creds", serverLoginCreds.save());
|
||||
NbtUtils.writeUUID(tag, "token", NbtUUID.fromUUID(remoteLoginToken));
|
||||
|
||||
if (inst != null) tag.put("main", inst!.serialize());
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
void deserialize(CompoundTag tag) {
|
||||
// Verify Remote Login Token
|
||||
UUID ID = NbtUtils.readUUID(tag, "token").toUUID();
|
||||
if (ID.toString() != remoteLoginToken.toString()) {
|
||||
// Invalid session
|
||||
print(
|
||||
"Invalid login session detected, or two admins are connected at once");
|
||||
}
|
||||
|
||||
steamcmd_path = tag.get("steamcmd")!.asString();
|
||||
game_path = tag.get("game")!.asString();
|
||||
proton_path = tag.get("proton")!.asString();
|
||||
base_path = tag.get("proton")!.asString();
|
||||
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
|
||||
|
||||
serverLoginCreds =
|
||||
Credentials.deserialize(tag.get("server_creds")!.asCompoundTag());
|
||||
|
||||
if (tag.containsKey("main")) {
|
||||
inst = SettingsEntry.deserialize(tag.get("main")!.asCompoundTag());
|
||||
}
|
||||
}
|
||||
|
||||
SettingsEntry? inst;
|
||||
|
||||
Future<void> Read() async {
|
||||
if (!server) return;
|
||||
try {
|
||||
var tag = await NbtIo.read("settings.dat");
|
||||
|
||||
|
@ -58,19 +106,23 @@ class Settings {
|
|||
} catch (E) {
|
||||
print("No existing settings file found, initializing default settings");
|
||||
inst = SettingsEntry();
|
||||
inst!.steam_creds =
|
||||
Credentials(username: "", password: "", secret: "", has_2fa: false);
|
||||
inst!.steam_creds = Credentials(
|
||||
username: "",
|
||||
password: "",
|
||||
);
|
||||
|
||||
serverLoginCreds = Credentials(
|
||||
username: "admin",
|
||||
password: "changeMe123",
|
||||
secret: "",
|
||||
has_2fa: false);
|
||||
username: "admin",
|
||||
password: "changeMe123",
|
||||
);
|
||||
FTS = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Write() {
|
||||
if (!server) {
|
||||
return; // safeguard against writing to a settings file on the client
|
||||
}
|
||||
if (inst == null) return;
|
||||
CompoundTag tag = CompoundTag();
|
||||
tag.put("entry", inst!.serialize());
|
||||
|
@ -110,10 +162,6 @@ class Settings {
|
|||
return steamcmd_path;
|
||||
}
|
||||
|
||||
String getSteamCmd2FA() {
|
||||
return "$steamcmd_path${Platform.pathSeparator}steamcmd-2fa${Platform.isWindows ? ".exe" : ""}";
|
||||
}
|
||||
|
||||
String getModPath() {
|
||||
return PathHelper(pth: base_path).resolve("mods").build();
|
||||
}
|
||||
|
@ -180,8 +228,9 @@ class Settings {
|
|||
|
||||
if (await dir.exists()) {
|
||||
return;
|
||||
} else
|
||||
} else {
|
||||
await dir.create(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
File getModListFile() {
|
||||
|
@ -204,7 +253,7 @@ class Settings {
|
|||
.resolve("content")
|
||||
.resolve("440900")
|
||||
.resolve("${mod.mod_id}")
|
||||
.resolve("${mod.mod_pak}")
|
||||
.resolve(mod.mod_pak)
|
||||
.build();
|
||||
if (Platform.isWindows) {
|
||||
paths.add(pth);
|
||||
|
@ -220,6 +269,18 @@ class Settings {
|
|||
flush: true, mode: FileMode.writeOnly);
|
||||
}
|
||||
|
||||
Future<void> initializeProtonPrefix() async {
|
||||
runProton("echo", ["hello"]);
|
||||
}
|
||||
|
||||
Future<String> sendRconCommand(String command) async {
|
||||
Client cli =
|
||||
await Client.create("127.0.0.1", inst!.serverSettings.RconPort);
|
||||
Message msg = Message.create(cli, PacketType.command, command);
|
||||
|
||||
return cli.send(msg).payload;
|
||||
}
|
||||
|
||||
Future<void> initializeProton() async {
|
||||
Dio dio = Dio();
|
||||
print("Downloading proton...");
|
||||
|
@ -257,7 +318,7 @@ class Settings {
|
|||
|
||||
if (Platform.isWindows) {
|
||||
// Download zip file
|
||||
final path = "${steamcmd_path}${Platform.pathSeparator}windows.zip";
|
||||
final path = "$steamcmd_path${Platform.pathSeparator}windows.zip";
|
||||
final reply = await dio.download(windows, path);
|
||||
|
||||
final bytes = File(path).readAsBytesSync();
|
||||
|
@ -283,7 +344,7 @@ class Settings {
|
|||
print("Completed.");
|
||||
} else {
|
||||
// Download tgz file
|
||||
final path = "${steamcmd_path}${Platform.pathSeparator}linux.tgz";
|
||||
final path = "$steamcmd_path${Platform.pathSeparator}linux.tgz";
|
||||
final reply = await dio.download(linux, path);
|
||||
|
||||
final bytes = File(path).readAsBytesSync();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue