Revert "Rip out the mod download function because steamcmd is shit"

This reverts commit f2f0df0f17.
This commit is contained in:
zontreck 2023-11-08 15:08:26 -07:00
parent a33a74a4e8
commit fce8632639
5 changed files with 70 additions and 14 deletions

18
lib/credentials.dart Normal file
View file

@ -0,0 +1,18 @@
import 'package:hive/hive.dart';
part 'credentials.g.dart';
@HiveType(typeId: 1)
class Credentials {
@HiveField(0)
String username;
@HiveField(1)
String password;
@HiveField(2)
String secret;
Credentials(
{required this.username, required this.password, required this.secret});
}

View file

@ -9,6 +9,43 @@ import 'package:servermanager/serversettings.dart';
import 'package:servermanager/settings.dart';
import 'package:servermanager/statemachine.dart';
Future<void> doDownloadMods(String modsFolder) async {
Settings settings = Settings();
// Now, invoke SteamCmd to download the workshop mods. This is an authenticated action, and does require Scmd2fa
var result = await Process.run(settings.getSteamCmd2FA(),
["--raw", "--secret", settings.inst!.steam_creds!.secret]);
var code = result.stdout as String;
// Build download command
List<String> manifest = [
"+@sSteamCmdForcePlatformType",
"windows",
"+force_install_dir",
modsFolder,
"+login",
settings.inst!.steam_creds!.username,
settings.inst!.steam_creds!.password,
code.trim()
];
for (Mod M in settings.inst!.mods) {
manifest.add("+workshop_download_item");
manifest.add("440900");
manifest.add("${M.mod_id}");
}
await settings.createModFolderIfNotExists();
manifest.add("+quit");
//print(
// "Running command: ${settings.getSteamCmd()} ${manifest.join(" ")}");
result = await Process.run(settings.getSteamCmd(), manifest);
print(result.stdout);
}
Future<List<Mod>> doScanMods(String modsFolder) async {
Settings settings = Settings();
@ -142,15 +179,14 @@ class GameServerPageState extends State<GameServerPage> {
},
),
ListTile(
title: Text("Check Mods"),
subtitle: Text("Checks the local mod copies against Steam"),
title: Text("Download Mods"),
subtitle: Text("Downloads the mods"),
leading: Icon(Icons.download_sharp),
onTap: () async {
setState(() {
downloading = true;
});
// TODO: Insert the copy function from the configured mod location
await doDownloadMods(settings.getModPath());
setState(() {
downloading = false;

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:servermanager/autorestart.dart';
import 'package:servermanager/credentials.dart';
import 'package:servermanager/game.dart';
import 'package:servermanager/home.dart';
import 'package:servermanager/mod.dart';
@ -8,9 +9,11 @@ import 'package:servermanager/proton.dart';
import 'package:servermanager/serversettings.dart';
import 'package:servermanager/settings.dart';
import 'package:servermanager/settingsEntry.dart';
import 'package:servermanager/steamcmd.dart';
Future<void> main() async {
await Hive.initFlutter();
Hive.registerAdapter(CredentialsAdapter());
Hive.registerAdapter(ModAdapter());
Hive.registerAdapter(SettingsEntryAdapter());
Hive.registerAdapter(AutomaticRestartInfoAdapter());
@ -33,15 +36,15 @@ class MyApp extends StatelessWidget {
routes: {
"/home": (context) => HomePage(settings: appSettings),
"/proton": (context) => Proton(settings: appSettings),
//"/steamcmd": (context) => SteamCMD(
// settings: appSettings,
// ),
"/steamcmd": (context) => SteamCMD(
settings: appSettings,
),
"/server": (context) => GameServerPage(settings: appSettings),
"/server/autorestart": (context) => AutoRestartPage(),
"/server/ports": (context) => ServerSettingsPage(),
"/server/mods": (context) => ModManager(settings: appSettings),
"/server/mods/edit": (context) => ModPage(),
//"/steamcmd/creds": (context) => CredentialsPrompt()
"/steamcmd/creds": (context) => CredentialsPrompt()
});
}
}

View file

@ -1,5 +1,6 @@
import 'package:hive/hive.dart';
import 'package:servermanager/autorestart.dart';
import 'package:servermanager/credentials.dart';
import 'package:servermanager/mod.dart';
import 'package:servermanager/serversettings.dart';
@ -10,6 +11,9 @@ class SettingsEntry {
@HiveField(0, defaultValue: [])
List<Mod> mods = [];
@HiveField(3)
Credentials? steam_creds;
@HiveField(4, defaultValue: AutomaticRestartInfo())
AutomaticRestartInfo timer = AutomaticRestartInfo();
@ -24,7 +28,4 @@ class SettingsEntry {
RconPort: 7779,
GamePort: 7780,
QueryPort: 7782);
@HiveField(6, defaultValue: "")
String conanExilesInstallLocation = "";
}

View file

@ -46,9 +46,7 @@ class StateMachine {
// Server startup in progress
Settings settings = Settings();
await settings.RunUpdate(valid: false);
// TODO: Insert mod copy from mod location function
await doDownloadMods(settings.getModPath());
settings.inst!.mods = await doScanMods(settings.getModPath());
await settings.writeOutModListFile();