Burin-Zhargal's picture
download
raw
5.71 kB
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:http/http.dart' as http;
class IpxEmulatorScreen extends StatefulWidget {
@override
_IpxEmulatorScreenState createState() => _IpxEmulatorScreenState();
}
class _IpxEmulatorScreenState extends State<IpxEmulatorScreen> {
WebSocketChannel? _channel;
bool _gameLaunched = false;
String _wsStatus = "Disconnected";
// Состояние загрузки легаси-сервера 2001 года
bool _isServerLoading = true;
String? _serverError;
String _serverData = "";
@override
void initState() {
super.initState();
// Запускаем инициализацию легаси-сервера строго ОДИН РАЗ при старте экрана
_initLegacyServer();
}
Future<void> _initLegacyServer() async {
try {
// Синхронизировано: шлем запрос на порт 8081, где слушает наш отредактированный Copilot
final response = await http.post(Uri.parse('http://localhost:8081/start_legacy'));
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
setState(() {
_serverData = "2001 Server Active (PID: ${data['pid']})";
_isServerLoading = false;
});
} else {
setState(() {
_serverError = "Failed to start legacy system: HTTP ${response.statusCode}";
_isServerLoading = false;
});
}
} catch (e) {
setState(() {
_serverError = "Error connecting to Copilot: $e";
_isServerLoading = false;
});
}
}
void _connectWS() {
setState(() {
_wsStatus = "Connecting...";
});
// Подключаемся к IPX/Ethernet эмулятору сети через WebSocket на порт 4040
final ws = IOWebSocketChannel.connect('ws://localhost:4040');
ws.sink.done.catchError((_) {
setState(() {
_wsStatus = "Disconnected";
});
});
ws.stream.listen((msg) {
setState(() {
_wsStatus = "WS Message: $msg";
});
}, onDone: () {
setState(() {
_wsStatus = "Disconnected";
});
}, onError: (e) {
setState(() {
_wsStatus = "Error: $e";
});
});
setState(() {
_channel = ws;
_wsStatus = "Connected";
});
}
void _launchInsaneGame() {
// Отправляем JSON-пакет управления через активный вебсокет в сетевое ядро
_channel?.sink.add(jsonEncode({"cmd": "start_game", "payload": "1nsane"}));
setState(() {
_gameLaunched = true;
_wsStatus = "Sent start_game command";
});
}
@override
void dispose() {
_channel?.sink.close(); // Безопасно закрываем сокет при выходе, защищая память
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("1nsane™ Legacy Bridge")),
body: _buildBody(),
);
}
Widget _buildBody() {
// 1. Стадия ожидания инициализации процесса
if (_isServerLoading) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 20),
Text("Оживление прошлого: запуск OS/2 Warp Server...", style: TextStyle(color: Colors.grey)),
],
),
);
}
// 2. Стадия системной ошибки путей или портов
if (_serverError != null) {
return Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text("ERROR: $_serverError", style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
),
);
}
// 3. Успешный запуск ядра: выводим интерактивный пульт управления
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Legacy Server: $_serverData",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.indigo),
),
SizedBox(height: 30),
ElevatedButton.icon(
icon: Icon(Icons.usb),
label: Text("Подключиться по WebSocket"),
onPressed: _channel == null ? _connectWS : null,
),
SizedBox(height: 15),
ElevatedButton.icon(
icon: Icon(Icons.sports_esports),
label: Text("Запустить 1nsane Videogame™"),
onPressed: (_channel != null && !_gameLaunched) ? _launchInsaneGame : null,
),
SizedBox(height: 25),
Text(
"Статус WebSocket: $_wsStatus",
style: TextStyle(fontSize: 13, color: Colors.blueGrey, fontFamily: 'monospace'),
),
SizedBox(height: 40),
if (_gameLaunched)
Text(
"🎮 1nsane Videogame™ В ДЕЙСТВИИ!",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.green, fontSize: 20, letterSpacing: 1.2),
),
],
),
);
}
}

Xet Storage Details

Size:
5.71 kB
·
Xet hash:
6c4c06e7912b1453c2600538e96d8f7ab1e22b9fb810fa660194df7fe99024bf

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.