mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 03:02:22 +01:00
<feat: New release>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const String kDefaultPlayerName = "Player";
|
||||
const String kDefaultGameServerHost = "127.0.0.1";
|
||||
const String kDefaultGameServerPort = "7777";
|
||||
const String shutdownLine = "FOnlineSubsystemGoogleCommon::Shutdown()";
|
||||
const List<String> corruptedBuildErrors = [
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
|
||||
class GameInstance {
|
||||
final String versionName;
|
||||
final int gamePid;
|
||||
final int? launcherPid;
|
||||
final int? eacPid;
|
||||
@@ -10,11 +11,11 @@ class GameInstance {
|
||||
bool tokenError;
|
||||
bool linkedHosting;
|
||||
|
||||
GameInstance(this.gamePid, this.launcherPid, this.eacPid, this.hosting, this.linkedHosting)
|
||||
GameInstance(this.versionName, this.gamePid, this.launcherPid, this.eacPid, this.hosting, this.linkedHosting)
|
||||
: tokenError = false,
|
||||
assert(!linkedHosting || !hosting, "Only a game instance can have a linked hosting server");
|
||||
|
||||
GameInstance._fromJson(this.gamePid, this.launcherPid, this.eacPid, this.observerPid,
|
||||
GameInstance._fromJson(this.versionName, this.gamePid, this.launcherPid, this.eacPid, this.observerPid,
|
||||
this.hosting, this.tokenError, this.linkedHosting);
|
||||
|
||||
static GameInstance? fromJson(Map<String, dynamic>? json) {
|
||||
@@ -27,13 +28,14 @@ class GameInstance {
|
||||
return null;
|
||||
}
|
||||
|
||||
var version = json["versionName"];
|
||||
var launcherPid = json["launcher"];
|
||||
var eacPid = json["eac"];
|
||||
var observerPid = json["observer"];
|
||||
var hosting = json["hosting"];
|
||||
var tokenError = json["tokenError"];
|
||||
var linkedHosting = json["linkedHosting"];
|
||||
return GameInstance._fromJson(gamePid, launcherPid, eacPid, observerPid, hosting, tokenError, linkedHosting);
|
||||
return GameInstance._fromJson(version, gamePid, launcherPid, eacPid, observerPid, hosting, tokenError, linkedHosting);
|
||||
}
|
||||
|
||||
void kill() {
|
||||
@@ -50,6 +52,7 @@ class GameInstance {
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'versionName': versionName,
|
||||
'game': gamePid,
|
||||
'launcher': launcherPid,
|
||||
'eac': eacPid,
|
||||
|
||||
@@ -4,29 +4,75 @@ import 'dart:io';
|
||||
import 'package:ini/ini.dart';
|
||||
|
||||
import 'package:reboot_common/common.dart';
|
||||
import 'package:sync/semaphore.dart';
|
||||
|
||||
final matchmakerDirectory = Directory("${assetsDirectory.path}\\matchmaker");
|
||||
final matchmakerStartExecutable = File("${matchmakerDirectory.path}\\fortmatchmaker.exe");
|
||||
final matchmakerKillExecutable = File("${authenticatorDirectory.path}\\kill.bat");
|
||||
final matchmakerConfigFile = File("${authenticatorDirectory.path}\\Config\\config.ini");
|
||||
String? _lastIp;
|
||||
String? _lastPort;
|
||||
Semaphore _semaphore = Semaphore();
|
||||
|
||||
Future<int> startEmbeddedMatchmaker(bool detached) async => startBackgroundProcess(
|
||||
executable: matchmakerStartExecutable,
|
||||
window: detached
|
||||
);
|
||||
|
||||
Future<void> writeMatchmakingIp(String text) async {
|
||||
var file = File("${authenticatorDirectory}\\Config\\config.ini");
|
||||
if(!file.existsSync()){
|
||||
Stream<String?> watchMatchmakingIp() async* {
|
||||
if(!matchmakerConfigFile.existsSync()){
|
||||
return;
|
||||
}
|
||||
|
||||
var observer = matchmakerConfigFile.parent.watch(events: FileSystemEvent.modify);
|
||||
yield* observer.where((event) => event.path == matchmakerConfigFile.path).asyncMap((event) async {
|
||||
try {
|
||||
var config = Config.fromString(await matchmakerConfigFile.readAsString());
|
||||
var ip = config.get("GameServer", "ip");
|
||||
if(ip == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var port = config.get("GameServer", "port");
|
||||
if(port == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(_lastIp == ip && _lastPort == port) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return port == kDefaultGameServerPort ? ip : "$ip:$port";
|
||||
}finally {
|
||||
try {
|
||||
_semaphore.release();
|
||||
} on StateError catch(_) {
|
||||
// Intended behaviour
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> writeMatchmakingIp(String text) async {
|
||||
var exists = await matchmakerConfigFile.exists();
|
||||
if(!exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
_semaphore.acquire();
|
||||
var splitIndex = text.indexOf(":");
|
||||
var ip = splitIndex != -1 ? text.substring(0, splitIndex) : text;
|
||||
var port = splitIndex != -1 ? text.substring(splitIndex + 1) : kDefaultGameServerPort;
|
||||
var config = Config.fromString(file.readAsStringSync());
|
||||
if(port.isBlank) {
|
||||
port = kDefaultGameServerPort;
|
||||
}
|
||||
|
||||
_lastIp = ip;
|
||||
_lastPort = port;
|
||||
var config = Config.fromString(await matchmakerConfigFile.readAsString());
|
||||
config.set("GameServer", "ip", ip);
|
||||
config.set("GameServer", "port", port);
|
||||
file.writeAsStringSync(config.toString());
|
||||
await matchmakerConfigFile.writeAsString(config.toString(), flush: true);
|
||||
}
|
||||
|
||||
Future<bool> isMatchmakerPortFree() async => isPortFree(int.parse(kDefaultMatchmakerPort));
|
||||
@@ -86,3 +132,18 @@ String? _getHostName(String host) => host.replaceFirst("ws://", "").replaceFirst
|
||||
|
||||
String? _getScheme(String host) => host.startsWith("ws://") ? "ws" : host.startsWith("wss://") ? "wss" : null;
|
||||
|
||||
extension StringExtension on String {
|
||||
bool get isBlank {
|
||||
if(isEmpty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(var char in this.split("")) {
|
||||
if(char != " ") {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ dependencies:
|
||||
archive: ^3.3.7
|
||||
ini: ^2.1.0
|
||||
shelf_proxy: ^1.0.2
|
||||
process_run: ^0.13.1
|
||||
sync: ^0.3.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_lints: ^2.0.1
|
||||
Reference in New Issue
Block a user