178 lines
5.2 KiB
Dart
178 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/IntTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/StringTag.dart';
|
|
|
|
class ServerSettings {
|
|
final String RconPassword;
|
|
final int RconPort;
|
|
final int GamePort;
|
|
final int QueryPort;
|
|
|
|
const ServerSettings(
|
|
{required this.RconPassword,
|
|
required this.RconPort,
|
|
required this.GamePort,
|
|
required this.QueryPort});
|
|
|
|
static ServerSettings deserialize(CompoundTag tag) {
|
|
return ServerSettings(
|
|
RconPassword: tag.get(TAG_PASSWORD)?.asString() ?? "",
|
|
RconPort: tag.get(TAG_RCON_PORT)?.asInt() ?? 25565,
|
|
GamePort: tag.get(TAG_GAME_PORT)?.asInt() ?? 0,
|
|
QueryPort: tag.get(TAG_QUERY_PORT)?.asInt() ?? 0);
|
|
}
|
|
|
|
CompoundTag serialize() {
|
|
CompoundTag tag = CompoundTag();
|
|
tag.put(TAG_PASSWORD, StringTag.valueOf(RconPassword));
|
|
tag.put(TAG_RCON_PORT, IntTag.valueOf(RconPort));
|
|
tag.put(TAG_GAME_PORT, IntTag.valueOf(GamePort));
|
|
tag.put(TAG_QUERY_PORT, IntTag.valueOf(QueryPort));
|
|
|
|
return tag;
|
|
}
|
|
|
|
static const TAG_NAME = "serverSettings";
|
|
static const TAG_PASSWORD = "password";
|
|
static const TAG_RCON_PORT = "rcon";
|
|
static const TAG_GAME_PORT = "game";
|
|
static const TAG_QUERY_PORT = "query";
|
|
}
|
|
|
|
class ServerSettingsPage extends StatefulWidget {
|
|
ServerSettingsPage({super.key});
|
|
|
|
@override
|
|
ServerSettingsState createState() => ServerSettingsState();
|
|
}
|
|
|
|
class ServerSettingsState extends State<ServerSettingsPage> {
|
|
bool firstRun = true;
|
|
String pass = "";
|
|
TextEditingController passwordController = TextEditingController();
|
|
int rconPort = 0;
|
|
int gPort = 0;
|
|
int qPort = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (firstRun) {
|
|
var args = ModalRoute.of(context)!.settings.arguments as ServerSettings;
|
|
|
|
passwordController.text = args.RconPassword;
|
|
rconPort = args.RconPort;
|
|
gPort = args.GamePort;
|
|
qPort = args.QueryPort;
|
|
|
|
firstRun = false;
|
|
}
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("Server Settings"),
|
|
backgroundColor: Color.fromARGB(255, 100, 0, 0),
|
|
),
|
|
body: WillPopScope(
|
|
onWillPop: () async {
|
|
Navigator.pop(
|
|
context,
|
|
ServerSettings(
|
|
RconPassword: passwordController.text,
|
|
RconPort: rconPort,
|
|
GamePort: gPort,
|
|
QueryPort: qPort));
|
|
return true;
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 256,
|
|
child: ListTile(title: Text("Rcon Password")),
|
|
),
|
|
Expanded(
|
|
child: TextField(
|
|
controller: passwordController,
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8))),
|
|
))
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 256,
|
|
child: ListTile(
|
|
title: Text("Rcon Port"),
|
|
subtitle: Text("${rconPort}"),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Slider(
|
|
value: rconPort.toDouble(),
|
|
onChanged: (value) {
|
|
setState(() {
|
|
rconPort = value.toInt();
|
|
});
|
|
},
|
|
min: 5000,
|
|
max: 8000,
|
|
))
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 256,
|
|
child: ListTile(
|
|
title: Text("Game Port"),
|
|
subtitle: Text("${gPort}"),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Slider(
|
|
value: gPort.toDouble(),
|
|
onChanged: (value) {
|
|
setState(() {
|
|
gPort = value.toInt();
|
|
});
|
|
},
|
|
min: 5000,
|
|
max: 8000,
|
|
))
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 256,
|
|
child: ListTile(
|
|
title: Text("Query Port"),
|
|
subtitle: Text("${qPort}"),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Slider(
|
|
value: qPort.toDouble(),
|
|
onChanged: (value) {
|
|
setState(() {
|
|
qPort = value.toInt();
|
|
});
|
|
},
|
|
min: 5000,
|
|
max: 8000,
|
|
))
|
|
],
|
|
)
|
|
],
|
|
)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|