Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9de38091e |
@@ -18,6 +18,7 @@ class GameServer {
|
|||||||
final bool hasIcon;
|
final bool hasIcon;
|
||||||
final bool hasImage;
|
final bool hasImage;
|
||||||
final bool custom;
|
final bool custom;
|
||||||
|
final String? bluemapUrl;
|
||||||
|
|
||||||
const GameServer({
|
const GameServer({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -36,6 +37,7 @@ class GameServer {
|
|||||||
this.hasIcon = false,
|
this.hasIcon = false,
|
||||||
this.hasImage = false,
|
this.hasImage = false,
|
||||||
this.custom = false,
|
this.custom = false,
|
||||||
|
this.bluemapUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory GameServer.fromJson(Map<String, dynamic> json) => GameServer(
|
factory GameServer.fromJson(Map<String, dynamic> json) => GameServer(
|
||||||
@@ -55,8 +57,11 @@ class GameServer {
|
|||||||
hasIcon: json['has_icon'] as bool? ?? false,
|
hasIcon: json['has_icon'] as bool? ?? false,
|
||||||
hasImage: json['has_image'] as bool? ?? false,
|
hasImage: json['has_image'] as bool? ?? false,
|
||||||
custom: json['custom'] as bool? ?? false,
|
custom: json['custom'] as bool? ?? false,
|
||||||
|
bluemapUrl: json['bluemap_url'] as String?,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bool get hasMap => (bluemapUrl ?? '').isNotEmpty;
|
||||||
|
|
||||||
bool get isUp => status == 'online' || status == 'running';
|
bool get isUp => status == 'online' || status == 'running';
|
||||||
bool get isBusy => status == 'starting' || status == 'partial';
|
bool get isBusy => status == 'starting' || status == 'partial';
|
||||||
bool get isPreprod => env == 'preprod';
|
bool get isPreprod => env == 'preprod';
|
||||||
@@ -111,3 +116,40 @@ class DockerContainer {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Infos « Se connecter » d'un serveur (API `/api/servers/{id}/connect`).
|
||||||
|
class ConnectInfo {
|
||||||
|
const ConnectInfo({
|
||||||
|
this.address,
|
||||||
|
this.mcVersion,
|
||||||
|
this.loader,
|
||||||
|
this.bluemapUrl,
|
||||||
|
this.voiceChatPort,
|
||||||
|
this.mrpackUrl,
|
||||||
|
this.instructions,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String? address;
|
||||||
|
final String? mcVersion;
|
||||||
|
final String? loader;
|
||||||
|
final String? bluemapUrl;
|
||||||
|
final int? voiceChatPort;
|
||||||
|
final String? mrpackUrl; // absolue (préfixée par la base API)
|
||||||
|
final List<String>? instructions;
|
||||||
|
|
||||||
|
bool get hasPack => (mrpackUrl ?? '').isNotEmpty;
|
||||||
|
|
||||||
|
/// `base` = URL de l'API, pour rendre `mrpack_url` (relatif) absolu.
|
||||||
|
factory ConnectInfo.fromJson(Map<String, dynamic> j, String base) {
|
||||||
|
final rel = j['mrpack_url'] as String?;
|
||||||
|
return ConnectInfo(
|
||||||
|
address: j['address'] as String?,
|
||||||
|
mcVersion: j['mc_version'] as String?,
|
||||||
|
loader: j['loader'] as String?,
|
||||||
|
bluemapUrl: j['bluemap_url'] as String?,
|
||||||
|
voiceChatPort: (j['voice_chat_port'] as num?)?.toInt(),
|
||||||
|
mrpackUrl: rel == null ? null : '$base$rel',
|
||||||
|
instructions: (j['instructions'] as List?)?.map((e) => e.toString()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import 'package:url_launcher/url_launcher.dart';
|
|||||||
|
|
||||||
import '../models.dart';
|
import '../models.dart';
|
||||||
import '../services/api_service.dart';
|
import '../services/api_service.dart';
|
||||||
|
import '../widgets/connect_card.dart';
|
||||||
|
import '../widgets/server_map_card.dart';
|
||||||
|
|
||||||
/// Détail d'un serveur : bannière (image importée ou thème), statut, connexion,
|
/// Détail d'un serveur : bannière (image importée ou thème), statut, connexion,
|
||||||
/// stats d'utilisation (CPU/RAM/réseau) et gestion de l'image (import/suppression).
|
/// stats d'utilisation (CPU/RAM/réseau) et gestion de l'image (import/suppression).
|
||||||
@@ -24,6 +26,8 @@ class _ServerDetailScreenState extends State<ServerDetailScreen> {
|
|||||||
|
|
||||||
Map<String, dynamic>? _stats;
|
Map<String, dynamic>? _stats;
|
||||||
Uint8List? _image;
|
Uint8List? _image;
|
||||||
|
ConnectInfo? _connect;
|
||||||
|
bool _connectLoading = true;
|
||||||
bool _busy = false;
|
bool _busy = false;
|
||||||
bool _imgBusy = false;
|
bool _imgBusy = false;
|
||||||
|
|
||||||
@@ -38,12 +42,15 @@ class _ServerDetailScreenState extends State<ServerDetailScreen> {
|
|||||||
widget.api.stats(s.id).catchError((_) => <String, dynamic>{'running': false}),
|
widget.api.stats(s.id).catchError((_) => <String, dynamic>{'running': false}),
|
||||||
widget.api.imageBytes(s.id).catchError((_) => null),
|
widget.api.imageBytes(s.id).catchError((_) => null),
|
||||||
widget.api.server(s.id).catchError((_) => _server),
|
widget.api.server(s.id).catchError((_) => _server),
|
||||||
|
widget.api.connectInfo(s.id).then<ConnectInfo?>((c) => c).catchError((_) => null),
|
||||||
]);
|
]);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_stats = results[0] as Map<String, dynamic>;
|
_stats = results[0] as Map<String, dynamic>;
|
||||||
_image = results[1] as Uint8List?;
|
_image = results[1] as Uint8List?;
|
||||||
_server = results[2] as GameServer;
|
_server = results[2] as GameServer;
|
||||||
|
_connect = results[3] as ConnectInfo?;
|
||||||
|
_connectLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,10 +164,15 @@ class _ServerDetailScreenState extends State<ServerDetailScreen> {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_toggleButton(),
|
_toggleButton(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (s.connect != null) _info(Icons.link, 'Connexion', s.connect!),
|
|
||||||
if (s.status == 'online')
|
if (s.status == 'online')
|
||||||
_info(Icons.people, 'Joueurs', '${s.players ?? 0} / ${s.maxPlayers ?? 0}'),
|
_info(Icons.people, 'Joueurs', '${s.players ?? 0} / ${s.maxPlayers ?? 0}'),
|
||||||
if (s.motd != null) _info(Icons.chat_bubble_outline, 'MOTD', s.motd!),
|
if (s.motd != null) _info(Icons.chat_bubble_outline, 'MOTD', s.motd!),
|
||||||
|
if (s.hasMap) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
ServerMapCard(url: s.bluemapUrl!, serverUp: s.isUp),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
|
ConnectCard(info: _connect, loading: _connectLoading),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_statsCard(),
|
_statsCard(),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|||||||
@@ -45,6 +45,15 @@ class ApiService {
|
|||||||
return GameServer.fromJson(jsonDecode(res.body) as Map<String, dynamic>);
|
return GameServer.fromJson(jsonDecode(res.body) as Map<String, dynamic>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bloc « Se connecter » (adresse, version, vocal, carte, lien modpack).
|
||||||
|
Future<ConnectInfo> connectInfo(String id) async {
|
||||||
|
final base = await baseUrl;
|
||||||
|
final res = await http.get(Uri.parse('$base/api/servers/$id/connect'), headers: await _headers());
|
||||||
|
if (res.statusCode == 401) throw UnauthorizedException();
|
||||||
|
if (res.statusCode != 200) throw ApiException('Erreur ${res.statusCode}');
|
||||||
|
return ConnectInfo.fromJson(jsonDecode(res.body) as Map<String, dynamic>, base);
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<DockerContainer>> containers() async {
|
Future<List<DockerContainer>> containers() async {
|
||||||
final base = await baseUrl;
|
final base = await baseUrl;
|
||||||
final res = await http.get(Uri.parse('$base/api/containers'), headers: await _headers());
|
final res = await http.get(Uri.parse('$base/api/containers'), headers: await _headers());
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
import '../models.dart';
|
||||||
|
|
||||||
|
/// Carte « Se connecter » : adresse, version/loader, chat vocal, et lien du
|
||||||
|
/// modpack (.mrpack) pour les joueurs PC.
|
||||||
|
class ConnectCard extends StatelessWidget {
|
||||||
|
const ConnectCard({super.key, required this.info, required this.loading});
|
||||||
|
|
||||||
|
final ConnectInfo? info;
|
||||||
|
final bool loading;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final i = info;
|
||||||
|
return Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.sports_esports_outlined, size: 20,
|
||||||
|
color: Theme.of(context).colorScheme.primary),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text('Se connecter', style: Theme.of(context).textTheme.titleMedium),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
if (loading && i == null)
|
||||||
|
const Center(child: Padding(padding: EdgeInsets.all(8), child: CircularProgressIndicator()))
|
||||||
|
else if (i == null)
|
||||||
|
const Text('Infos de connexion indisponibles.')
|
||||||
|
else ...[
|
||||||
|
if ((i.address ?? '').isNotEmpty)
|
||||||
|
_Row(
|
||||||
|
icon: Icons.dns_outlined,
|
||||||
|
label: 'Adresse',
|
||||||
|
value: i.address!,
|
||||||
|
onCopy: () => _copy(context, i.address!, 'Adresse copiée'),
|
||||||
|
),
|
||||||
|
if ((i.mcVersion ?? '').isNotEmpty)
|
||||||
|
_Row(
|
||||||
|
icon: Icons.layers_outlined,
|
||||||
|
label: 'Version',
|
||||||
|
value: '${i.mcVersion}${(i.loader ?? '').isNotEmpty ? ' · ${i.loader}' : ''}',
|
||||||
|
),
|
||||||
|
if (i.voiceChatPort != null)
|
||||||
|
_Row(
|
||||||
|
icon: Icons.mic_outlined,
|
||||||
|
label: 'Chat vocal',
|
||||||
|
value: 'Simple Voice Chat (UDP ${i.voiceChatPort})',
|
||||||
|
),
|
||||||
|
if (i.hasPack) ...[
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: FilledButton.tonalIcon(
|
||||||
|
onPressed: () => launchUrl(Uri.parse(i.mrpackUrl!),
|
||||||
|
mode: LaunchMode.externalApplication),
|
||||||
|
icon: const Icon(Icons.download, size: 18),
|
||||||
|
label: const Text('Modpack (.mrpack)'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
OutlinedButton.icon(
|
||||||
|
onPressed: () => _copy(context, i.mrpackUrl!, 'Lien du modpack copié'),
|
||||||
|
icon: const Icon(Icons.copy, size: 18),
|
||||||
|
label: const Text('Copier'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (i.instructions != null && i.instructions!.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
for (final step in i.instructions!)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4),
|
||||||
|
child: Text('• $step', style: Theme.of(context).textTheme.bodySmall),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _copy(BuildContext context, String text, String msg) {
|
||||||
|
Clipboard.setData(ClipboardData(text: text));
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Row extends StatelessWidget {
|
||||||
|
const _Row({required this.icon, required this.label, required this.value, this.onCopy});
|
||||||
|
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
final String value;
|
||||||
|
final VoidCallback? onCopy;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 20, color: Theme.of(context).colorScheme.primary),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(label, style: Theme.of(context).textTheme.labelMedium),
|
||||||
|
Text(value, style: Theme.of(context).textTheme.bodyLarge),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (onCopy != null)
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Copier',
|
||||||
|
icon: const Icon(Icons.copy, size: 18),
|
||||||
|
onPressed: onCopy,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
|
|
||||||
|
/// Carte BlueMap (vue web du monde) intégrée dans le détail d'un serveur.
|
||||||
|
/// Ne charge la WebView que si le serveur tourne : BlueMap n'est servi
|
||||||
|
/// que conteneur allumé.
|
||||||
|
class ServerMapCard extends StatefulWidget {
|
||||||
|
const ServerMapCard({super.key, required this.url, required this.serverUp});
|
||||||
|
|
||||||
|
final String url;
|
||||||
|
final bool serverUp;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ServerMapCard> createState() => _ServerMapCardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ServerMapCardState extends State<ServerMapCard> {
|
||||||
|
WebViewController? _controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (widget.serverUp) _initController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(ServerMapCard old) {
|
||||||
|
super.didUpdateWidget(old);
|
||||||
|
if (widget.serverUp && _controller == null) _initController();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _initController() {
|
||||||
|
_controller = WebViewController()
|
||||||
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||||
|
..setBackgroundColor(const Color(0xFF14151B))
|
||||||
|
..loadRequest(Uri.parse(widget.url));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Card(
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 16, 8, 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.map_outlined, size: 20, color: Theme.of(context).colorScheme.primary),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text('Carte', style: Theme.of(context).textTheme.titleMedium),
|
||||||
|
const Spacer(),
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Ouvrir en plein écran',
|
||||||
|
icon: const Icon(Icons.open_in_new, size: 20),
|
||||||
|
onPressed: () =>
|
||||||
|
launchUrl(Uri.parse(widget.url), mode: LaunchMode.externalApplication),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 300, child: _body()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _body() {
|
||||||
|
if (!widget.serverUp || _controller == null) {
|
||||||
|
return const _MapEmpty();
|
||||||
|
}
|
||||||
|
return WebViewWidget(controller: _controller!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MapEmpty extends StatelessWidget {
|
||||||
|
const _MapEmpty();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
color: const Color(0xFF14151B),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.map_outlined, size: 44, color: Colors.white24),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Text('Serveur éteint — démarre-le pour voir la carte',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: Colors.white54)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ dependencies:
|
|||||||
shared_preferences: ^2.3.2
|
shared_preferences: ^2.3.2
|
||||||
package_info_plus: ^8.1.1
|
package_info_plus: ^8.1.1
|
||||||
url_launcher: ^6.3.1
|
url_launcher: ^6.3.1
|
||||||
|
webview_flutter: ^4.10.0
|
||||||
path_provider: ^2.1.4
|
path_provider: ^2.1.4
|
||||||
open_filex: ^4.5.0
|
open_filex: ^4.5.0
|
||||||
image_picker: ^1.1.2
|
image_picker: ^1.1.2
|
||||||
|
|||||||
Reference in New Issue
Block a user