mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 11:12:23 +01:00
<feat: New project structure>
<feat: New release>
This commit is contained in:
74
cli/lib/src/server.dart
Normal file
74
cli/lib/src/server.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:reboot_common/common.dart';
|
||||
import 'package:reboot_common/src/util/authenticator.dart' as server;
|
||||
|
||||
Future<bool> startServerCli(String? host, String? port, ServerType type) async {
|
||||
stdout.writeln("Starting backend server...");
|
||||
switch(type){
|
||||
case ServerType.local:
|
||||
var result = await server.ping(host ?? kDefaultAuthenticatorHost, port ?? kDefaultAuthenticatorPort);
|
||||
if(result == null){
|
||||
throw Exception("Local backend server is not running");
|
||||
}
|
||||
|
||||
stdout.writeln("Detected local backend server");
|
||||
return true;
|
||||
case ServerType.embedded:
|
||||
stdout.writeln("Starting an embedded server...");
|
||||
await server.startEmbeddedAuthenticator(false);
|
||||
var result = await server.ping(host ?? kDefaultAuthenticatorHost, port ?? kDefaultAuthenticatorPort);
|
||||
if(result == null){
|
||||
throw Exception("Cannot start embedded server");
|
||||
}
|
||||
|
||||
return true;
|
||||
case ServerType.remote:
|
||||
if(host == null){
|
||||
throw Exception("Missing host for remote server");
|
||||
}
|
||||
|
||||
if(port == null){
|
||||
throw Exception("Missing host for remote server");
|
||||
}
|
||||
|
||||
stdout.writeln("Starting a reverse proxy to $host:$port");
|
||||
return await _changeReverseProxyState(host, port) != null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<HttpServer?> _changeReverseProxyState(String host, String port) async {
|
||||
host = host.trim();
|
||||
if(host.isEmpty){
|
||||
throw Exception("Missing host name");
|
||||
}
|
||||
|
||||
port = port.trim();
|
||||
if(port.isEmpty){
|
||||
throw Exception("Missing port");
|
||||
}
|
||||
|
||||
if(int.tryParse(port) == null){
|
||||
throw Exception("Invalid port, use only numbers");
|
||||
}
|
||||
|
||||
try{
|
||||
var uri = await server.ping(host, port);
|
||||
if(uri == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
return await server.startRemoteAuthenticatorProxy(uri);
|
||||
}catch(error){
|
||||
throw Exception("Cannot start reverse proxy");
|
||||
}
|
||||
}
|
||||
|
||||
void kill() async {
|
||||
try {
|
||||
await Process.run("taskkill", ["/f", "/im", "FortniteLauncher.exe"]);
|
||||
await Process.run("taskkill", ["/f", "/im", "FortniteClient-Win64-Shipping_EAC.exe"]);
|
||||
}catch(_){
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user