Refactor project, get server-client coms working
This commit is contained in:
parent
6fadb92a26
commit
7cddfd2de6
22 changed files with 730 additions and 677 deletions
220
lib/pages/steamcmd.dart
Normal file
220
lib/pages/steamcmd.dart
Normal file
|
@ -0,0 +1,220 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:servermanager/pages/dialogbox.dart';
|
||||
import 'package:servermanager/structs/credentials.dart';
|
||||
import 'package:servermanager/structs/settings.dart';
|
||||
|
||||
class SteamCMD extends StatefulWidget {
|
||||
Settings settings;
|
||||
SteamCMD({super.key, required this.settings});
|
||||
|
||||
@override
|
||||
SteamCMDState createState() => SteamCMDState(settings: settings);
|
||||
}
|
||||
|
||||
class SteamCMDState extends State<SteamCMD> {
|
||||
Settings settings = Settings();
|
||||
SteamCMDState({required this.settings});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Conan Exiles Server Manager - Steam Command"),
|
||||
backgroundColor: Color.fromARGB(255, 100, 0, 0),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text("Download/Initialize SteamCmd"),
|
||||
leading: Icon(CupertinoIcons.cloud_download),
|
||||
subtitle: Text(
|
||||
"Creates the steamcmd folder, and downloads the steamcmd bootstrap. Then performs the initial update."),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (X) => InputBox(
|
||||
"",
|
||||
promptText:
|
||||
"This action will delete any existing copy of SteamCMD and download a fresh copy. \nAre you sure?",
|
||||
changed: (X) {},
|
||||
onSubmit: () async {
|
||||
settings.initializeSteamCmd();
|
||||
},
|
||||
onCancel: () {},
|
||||
isDefault: false,
|
||||
hasInputField: false,
|
||||
));
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Download SteamCmd-2fa"),
|
||||
leading: Icon(CupertinoIcons.lock_shield_fill),
|
||||
subtitle: Text(
|
||||
"Downloads a modified version of steamcmd-2fa from https://github.com/zontreck/steamcmd-2fa"),
|
||||
onTap: () async {
|
||||
final dio = Dio();
|
||||
await dio.download(
|
||||
settings.Base2FAPath + (Platform.isWindows ? ".exe" : ""),
|
||||
settings.steamcmd_path +
|
||||
Platform.pathSeparator +
|
||||
(Platform.isWindows
|
||||
? "steamcmd-2fa.exe"
|
||||
: "steamcmd-2fa"));
|
||||
if (!Platform.isWindows) {
|
||||
var proc = await Process.start("chmod", [
|
||||
"+x",
|
||||
"${settings.steamcmd_path}${Platform.pathSeparator}steamcmd-2fa"
|
||||
]);
|
||||
}
|
||||
}),
|
||||
ListTile(
|
||||
title: Text("Credentials"),
|
||||
leading: Icon(Icons.key_sharp),
|
||||
subtitle: Text("Steam Credentials"),
|
||||
onTap: () async {
|
||||
var creds = await Navigator.pushNamed(context, "/steamcmd/creds",
|
||||
arguments: settings.inst!.steam_creds);
|
||||
if (creds != null) {
|
||||
Credentials cred = creds as Credentials;
|
||||
setState(() {
|
||||
settings.inst!.steam_creds = cred;
|
||||
settings.Write();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a Credentials Object
|
||||
class CredentialsPrompt extends StatelessWidget {
|
||||
TextEditingController username = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
TextEditingController secret = TextEditingController();
|
||||
bool initialInitDone = false;
|
||||
bool z2fa = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final args = ModalRoute.of(context)!.settings.arguments as Credentials?;
|
||||
|
||||
if (args != null) {
|
||||
if (!initialInitDone) {
|
||||
username.text = args.username;
|
||||
password.text = args.password;
|
||||
secret.text = args.secret;
|
||||
initialInitDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title:
|
||||
Text("Conan Exiles Server Manager - Steam Command - Credentials"),
|
||||
backgroundColor: Color.fromARGB(255, 100, 0, 0),
|
||||
),
|
||||
body: WillPopScope(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.person),
|
||||
Text("Username:"),
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: username,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4))),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.key),
|
||||
Text("Password:"),
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: password,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4))),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.dangerous),
|
||||
Text("Secret:"),
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: secret,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(4)),
|
||||
hintText:
|
||||
"2FA Shared Secret Code (Do Not Share With Others!)"),
|
||||
))
|
||||
],
|
||||
),
|
||||
SwitchListTile(
|
||||
value: z2fa,
|
||||
title: Text("Enable 2FA"),
|
||||
subtitle: Text(
|
||||
"This may or may not be broken... steamcmd is shit!"),
|
||||
onChanged: (value) {
|
||||
z2fa = value;
|
||||
})
|
||||
],
|
||||
)),
|
||||
onWillPop: () async {
|
||||
Navigator.pop(
|
||||
context,
|
||||
Credentials(
|
||||
username: username.text,
|
||||
password: password.text,
|
||||
secret: secret.text,
|
||||
has_2fa: z2fa));
|
||||
return true;
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue