ConanServerManager/lib/main.dart

146 lines
5.2 KiB
Dart
Raw Permalink Normal View History

2023-11-01 03:28:33 -07:00
import 'package:flutter/material.dart';
import 'package:libac_dart/packets/packets.dart';
import 'package:servermanager/packets/ClientPackets.dart';
2024-07-02 17:48:06 -07:00
import 'package:servermanager/pages/ACL.dart';
import 'package:servermanager/pages/Constants.dart';
2024-06-16 16:42:50 -07:00
import 'package:servermanager/pages/DiscordConfigPage.dart';
import 'package:servermanager/pages/GameServerPage.dart';
import 'package:servermanager/pages/ModManager.dart';
import 'package:servermanager/pages/autorestart.dart';
import 'package:servermanager/pages/home.dart';
2024-07-01 23:43:48 -07:00
import 'package:servermanager/pages/snapshots.dart';
import 'package:servermanager/structs/settings.dart';
import 'pages/ServerSettings.dart';
2023-11-01 03:28:33 -07:00
Future<void> main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
Settings appSettings = Settings();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Server Manager',
theme: ThemeData.dark(useMaterial3: true),
routes: {
2024-05-22 16:09:36 -07:00
"/": (context) => ServerPage(),
2023-11-01 03:28:33 -07:00
"/home": (context) => HomePage(settings: appSettings),
2024-07-02 17:48:06 -07:00
"/acl": (context) => AccessControlListPage(),
2024-07-02 17:57:40 -07:00
"/acl/edit": (context) => ACLEdit(),
2023-11-01 03:28:33 -07:00
"/server": (context) => GameServerPage(settings: appSettings),
2023-11-04 15:15:33 -07:00
"/server/autorestart": (context) => AutoRestartPage(),
2023-11-05 00:03:15 -07:00
"/server/ports": (context) => ServerSettingsPage(),
2023-11-01 03:28:33 -07:00
"/server/mods": (context) => ModManager(settings: appSettings),
"/server/mods/edit": (context) => ModPage(),
2024-07-01 23:43:48 -07:00
"/server/discord": (context) => DiscordConfigPage(),
"/server/snapshots": (context) => SnapshotsPage(),
"/server/snapshots/restore": (context) => SnapshotListPage()
2023-11-01 03:28:33 -07:00
});
}
}
2024-05-22 16:09:36 -07:00
class ServerPage extends StatelessWidget {
TextEditingController serverIP = TextEditingController();
TextEditingController username = TextEditingController();
TextEditingController password = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Conan Exiles Server Manager - Login"),
backgroundColor: Constants.TITLEBAR_COLOR,
),
floatingActionButton: ElevatedButton(
onPressed: () async {
2024-05-22 16:09:36 -07:00
// Send login packet to server
Settings settings = Settings();
settings.client = PacketClient();
2024-06-03 18:33:13 -07:00
int port = 25306;
String ip = serverIP.text;
List<String> ipParts = ip.split(':');
if (ipParts.length == 2) {
ip = ipParts[0];
port = int.parse(ipParts[1]);
}
2024-07-01 23:15:08 -07:00
print("Attempting to connect to FQDN/IP : $ip on port $port");
2024-06-03 18:33:13 -07:00
await settings.client!.startConnect(ip, port);
C2SLoginPacket login = C2SLoginPacket();
login.username = username.text;
login.password = password.text;
S2CResponse response = await settings.client!.send(login, true);
2024-05-23 22:18:59 -07:00
S2CLoginReply loginResponse = S2CLoginReply();
loginResponse.decodeTag(response.contents);
loginResponse.handleClientPacket();
if (loginResponse.valid) {
2024-07-02 16:01:06 -07:00
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content:
Text("Login Success - Downloading remote Settings")));
2024-07-02 16:36:27 -07:00
int retryCount = 0;
2024-07-02 16:01:06 -07:00
while (true) {
try {
2024-07-02 16:36:27 -07:00
if (retryCount > 0)
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"> Retrying to download settings in 10 seconds (Attempt $retryCount")));
await Future.delayed(Duration(seconds: 10));
2024-07-02 16:01:06 -07:00
S2CResponse settingsData = await settings.client!
.send(C2SRequestSettingsPacket(), true);
C2SRequestSettingsPacket settingsBack =
C2SRequestSettingsPacket();
settingsBack.decodeTag(settingsData.contents);
settingsBack.handleClientPacket();
break;
2024-07-02 16:36:27 -07:00
} catch (E) {
retryCount++;
}
2024-07-02 16:01:06 -07:00
}
Navigator.pushNamed(context, "/home");
} else {
print("Login not valid");
}
2024-05-22 16:09:36 -07:00
},
child: Text("Login"),
),
body: SingleChildScrollView(
child: Column(
children: [
ListTile(
title: Text("Server IP/FQDN"),
subtitle: TextField(
controller: serverIP,
decoration: InputDecoration(hintText: "ex. 192.168.1.100"),
),
),
ListTile(
title: Text("Username"),
subtitle: TextField(
controller: username,
decoration: InputDecoration(hintText: "the_user"),
),
),
ListTile(
title: Text("Password"),
subtitle: TextField(
controller: password,
decoration: InputDecoration(hintText: "pass"),
obscureText: true,
),
)
],
),
));
}
}