ConanServerManager/lib/pages/GameServerPage.dart

215 lines
8.1 KiB
Dart

import 'dart:io';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import '../game.dart';
import '../statemachine.dart';
import '../structs/autorestarts.dart';
import '../structs/serversettings.dart';
import '../structs/settings.dart';
class GameServerPage extends StatefulWidget {
Settings settings;
GameServerPage({super.key, required this.settings});
@override
GameServerPageState createState() => GameServerPageState(settings: settings);
}
class GameServerPageState extends State<GameServerPage> {
Settings settings;
GameServerPageState({required this.settings});
var downloading = false;
late Stream<List<int>> download_stream;
TextEditingController ValueControl = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Conan Exiles Server Manager - Game Server"),
backgroundColor: Color.fromARGB(255, 100, 0, 0),
),
body: WillPopScope(
onWillPop: () async {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Wait until the download completes")));
return false;
} else {
return true;
}
},
child: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: Column(
children: [
ListTile(
title: settings.serverInstalled()
? Text("Update / Validate Server Install")
: Text("Initial Server Download"),
subtitle: settings.serverInstalled()
? Text(
"Validates game files or performs an update. This is done when starting the server as well.")
: Text(
"Download the game server. This is step 1, after having downloaded steamcmd."),
leading: Icon(Icons.numbers),
onTap: () async {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Wait until the download completes")));
return;
}
if (!settings.isValid()) return;
Directory(settings.getServerPath()).createSync();
setState(() {
downloading = true;
});
// Start server download into folder
await settings.RunUpdate();
setState(() {
downloading = false;
});
},
),
if (downloading)
ListTile(
title: Text("Downloading..."),
leading: Icon(Icons.downloading),
),
ListTile(
title: Text("Mods"),
leading: Icon(Icons.build),
subtitle: Text("Server Mod Management"),
onTap: () {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Wait until the download completes")));
return;
}
Navigator.pushNamed(context, "/server/mods");
},
),
if (settings.inst!.downloadMods)
ListTile(
title: Text("Download Mods"),
subtitle: Text("Downloads the mods"),
leading: Icon(Icons.download_sharp),
onTap: () async {
setState(() {
downloading = true;
});
await doDownloadMods(settings.getModPath());
setState(() {
downloading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Scanning mods...")));
var mods = await doScanMods(settings.getModPath());
setState(() {
settings.inst!.mods = mods;
settings.Write();
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Mod scanning complete")));
},
),
if (!settings.inst!.downloadMods)
ListTile(
title: Text("Conan Exiles Install Path"),
subtitle:
Text("Set the Steam Library location of Conan Exiles"),
leading: Icon(Icons.folder),
onTap: () async {
// Open the folder select prompt
var path = await getDirectoryPath();
setState(() {
settings.inst!.conanExilesLibraryPath =
path ?? settings.inst!.conanExilesLibraryPath;
if (path == null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"You must select a valid SteamLibrary folder")));
}
});
},
),
ListTile(
title: Text("Configure AutoRestart"),
leading: Icon(Icons.timer),
onTap: () async {
if (downloading) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Wait until the download completes")));
return;
}
var reply = await Navigator.pushNamed(
context, "/server/autorestart",
arguments: settings.inst!.timer);
setState(() {
settings.inst!.timer = reply as AutomaticRestartInfo;
});
},
),
SwitchListTile(
value: settings.inst!.downloadMods,
onChanged: (value) {
setState(() {
settings.inst!.downloadMods = value;
});
},
title: Text("Automatic Download of Mods"),
subtitle: Text(
"If enabled, downloads mods using steamcmd, if disabled, you must configure the SteamLibrary folder location"),
),
ListTile(
title: Text("Configure Server Ports"),
leading: Icon(Icons.numbers),
onTap: () async {
var reply = await Navigator.pushNamed(
context, "/server/ports",
arguments: settings.inst!.serverSettings);
setState(() {
settings.inst!.serverSettings = reply as ServerSettings;
settings.Write();
});
},
),
ListTile(
title: Text("Status:"),
subtitle: Text(settings.subsys.currentState != States.Inactive
? "Active"
: "Not Running"),
leading: Icon(settings.subsys.currentState != States.Inactive
? Icons.play_arrow
: Icons.error),
onTap: () async {
// Toggle state
setState(() {
if (settings.subsys.currentState == States.Inactive) {
settings.subsys.changeState(States.Starting);
} else
settings.subsys.changeState(States.FullStop);
});
},
),
],
)),
),
);
}
}