Skip to content

Commit 90448ee

Browse files
committed
10.0.7
1 parent b319479 commit 90448ee

22 files changed

+585
-666
lines changed

cli/lib/cli.dart

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,89 @@
1-
import 'dart:io';
1+
import 'dart:collection';
22

3-
import 'package:args/args.dart';
4-
import 'package:reboot_cli/src/game.dart';
5-
import 'package:reboot_cli/src/reboot.dart';
6-
import 'package:reboot_cli/src/server.dart';
7-
import 'package:reboot_common/common.dart';
3+
class Parser {
4+
final List<Command> commands;
85

9-
late String? username;
10-
late bool host;
11-
late bool verbose;
12-
late String dll;
13-
late FortniteVersion version;
14-
late bool autoRestart;
6+
Parser({required this.commands});
157

16-
void main(List<String> args) async {
17-
stdout.writeln("Reboot Launcher");
18-
stdout.writeln("Wrote by Auties00");
19-
stdout.writeln("Version 1.0");
8+
CommandCall? parse(List<String> args) {
9+
var position = 0;
10+
var allowedCommands = _toMap(commands);
11+
var allowedParameters = <String>{};
12+
Command? command;
13+
CommandCall? head;
14+
CommandCall? tail;
15+
String? parameterName;
16+
while(position < args.length) {
17+
final current = args[position].toLowerCase();
18+
if(parameterName != null) {
19+
tail?.parameters[parameterName] = current;
20+
parameterName = null;
21+
}else if(allowedParameters.contains(current.toLowerCase())) {
22+
parameterName = current.substring(2);
23+
if(args.elementAtOrNull(position + 1) == '"') {
24+
position++;
25+
}
26+
}else {
27+
final newCommand = allowedCommands[current];
28+
if(newCommand != null) {
29+
final newCall = CommandCall(name: newCommand.name);
30+
if(head == null) {
31+
head = newCall;
32+
tail = newCall;
33+
}
34+
if(tail != null) {
35+
tail.subCall = newCall;
36+
}
37+
tail = newCall;
38+
command = newCommand;
39+
allowedCommands = _toMap(newCommand.subCommands);
40+
allowedParameters = _toParameters(command);
41+
}
42+
}
43+
position++;
44+
}
45+
return head;
46+
}
2047

21-
kill();
48+
Set<String> _toParameters(Command? parent) => parent?.parameters
49+
.map((e) => '--${e.toLowerCase()}')
50+
.toSet() ?? {};
2251

23-
var parser = ArgParser()
24-
..addOption("path", mandatory: true)
25-
..addOption("username")
26-
..addOption("server-type", allowed: ServerType.values.map((entry) => entry.name), defaultsTo: ServerType.embedded.name)
27-
..addOption("server-host")
28-
..addOption("server-port")
29-
..addOption("matchmaking-address")
30-
..addOption("dll", defaultsTo: rebootDllFile.path)
31-
..addFlag("update", defaultsTo: true, negatable: true)
32-
..addFlag("log", defaultsTo: false)
33-
..addFlag("host", defaultsTo: false)
34-
..addFlag("auto-restart", defaultsTo: false, negatable: true);
35-
var result = parser.parse(args);
52+
Map<String, Command> _toMap(List<Command> children) => Map.fromIterable(
53+
children,
54+
key: (command) => command.name.toLowerCase(),
55+
value: (command) => command
56+
);
57+
}
3658

37-
dll = result["dll"];
38-
host = result["host"];
39-
username = result["username"] ?? kDefaultPlayerName;
40-
verbose = result["log"];
41-
version = FortniteVersion(name: "Dummy", location: Directory(result["path"]));
59+
class Command {
60+
final String name;
61+
final List<String> parameters;
62+
final List<Command> subCommands;
4263

43-
await downloadRequiredDLLs();
44-
if(result["update"]) {
45-
stdout.writeln("Updating reboot dll...");
46-
try {
47-
await downloadRebootDll(kRebootDownloadUrl);
48-
}catch(error){
49-
stderr.writeln("Cannot update reboot dll: $error");
50-
}
51-
}
64+
const Command({required this.name, required this.parameters, required this.subCommands});
5265

53-
stdout.writeln("Launching game...");
54-
var executable = version.shippingExecutable;
55-
if(executable == null){
56-
throw Exception("Missing game executable at: ${version.location.path}");
57-
}
66+
@override
67+
String toString() => 'Command{name: $name, parameters: $parameters, subCommands: $subCommands}';
68+
}
5869

59-
final serverHost = result["server-host"]?.trim();
60-
if(serverHost?.isEmpty == true){
61-
throw Exception("Missing host name");
62-
}
70+
class Parameter {
71+
final String name;
72+
final bool Function(String) validator;
6373

64-
final serverPort = result["server-port"]?.trim();
65-
if(serverPort?.isEmpty == true){
66-
throw Exception("Missing port");
67-
}
74+
const Parameter({required this.name, required this.validator});
6875

69-
final serverPortNumber = serverPort == null ? null : int.tryParse(serverPort);
70-
if(serverPort != null && serverPortNumber == null){
71-
throw Exception("Invalid port, use only numbers");
72-
}
76+
@override
77+
String toString() => 'Parameter{name: $name, validator: $validator}';
78+
}
7379

74-
var started = await startServerCli(
75-
serverHost,
76-
serverPortNumber,
77-
ServerType.values.firstWhere((element) => element.name == result["server-type"])
78-
);
79-
if(!started){
80-
stderr.writeln("Cannot start server!");
81-
return;
82-
}
80+
class CommandCall {
81+
final String name;
82+
final Map<String, String> parameters;
83+
CommandCall? subCall;
84+
85+
CommandCall({required this.name}) : parameters = {};
8386

84-
writeMatchmakingIp(result["matchmaking-address"]);
85-
autoRestart = result["auto-restart"];
86-
await startGame();
87+
@override
88+
String toString() => 'CommandCall{name: $name, parameters: $parameters, subCall: $subCall}';
8789
}

cli/lib/main.dart

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import 'package:interact/interact.dart';
2+
import 'package:reboot_cli/cli.dart';
3+
import 'package:tint/tint.dart';
4+
5+
const Command _buildImport = Command(name: 'import', parameters: ['version', 'path'], subCommands: []);
6+
const Command _buildDownload = Command(name: 'download', parameters: ['version', 'path'], subCommands: []);
7+
const Command _build = Command(name: 'build', parameters: [], subCommands: [_buildImport, _buildDownload]);
8+
const Command _play = Command(name: 'play', parameters: [], subCommands: []);
9+
const Command _host = Command(name: 'host', parameters: [], subCommands: []);
10+
const Command _backend = Command(name: 'backend', parameters: [], subCommands: []);
11+
12+
void main(List<String> args) {
13+
_welcome();
14+
15+
final parser = Parser(commands: [_build, _play, _host, _backend]);
16+
final command = parser.parse(args);
17+
print(command);
18+
_handleRootCommand(command);
19+
}
20+
21+
void _handleRootCommand(CommandCall? call) {
22+
switch(call == null ? null : call.name) {
23+
case 'build':
24+
_handleBuildCommand(call?.subCall);
25+
break;
26+
case 'play':
27+
_handleBuildCommand(call?.subCall);
28+
break;
29+
case 'host':
30+
_handleBuildCommand(call?.subCall);
31+
break;
32+
case 'backend':
33+
_handleBuildCommand(call?.subCall);
34+
break;
35+
default:
36+
_askRootCommand();
37+
break;
38+
}
39+
}
40+
41+
void _askRootCommand() {
42+
final commands = [_build.name, _play.name, _host.name, _backend.name];
43+
final commandSelector = Select.withTheme(
44+
prompt: ' Select a command:',
45+
options: commands,
46+
theme: Theme.colorfulTheme.copyWith(inputPrefix: '❓', inputSuffix: '')
47+
);
48+
_handleRootCommand(CommandCall(name: commands[commandSelector.interact()]));
49+
}
50+
51+
void _handleBuildCommand(CommandCall? call) {
52+
switch(call == null ? null : call.name) {
53+
case 'import':
54+
_handleBuildImportCommand(call!);
55+
break;
56+
case 'download':
57+
_handleBuildDownloadCommand(call!);
58+
break;
59+
default:
60+
_askBuildCommand();
61+
break;
62+
}
63+
}
64+
65+
void _handleBuildImportCommand(CommandCall call) {
66+
final version = call.parameters['path'];
67+
final path = call.parameters['path'];
68+
print(version);
69+
print(path);
70+
}
71+
72+
void _handleBuildDownloadCommand(CommandCall call) {
73+
74+
}
75+
76+
void _askBuildCommand() {
77+
final commands = [_buildImport.name, _buildDownload.name];
78+
final commandSelector = Select.withTheme(
79+
prompt: ' Select a build command:',
80+
options: commands,
81+
theme: Theme.colorfulTheme.copyWith(inputPrefix: '❓', inputSuffix: '')
82+
);
83+
_handleBuildCommand(CommandCall(name: commands[commandSelector.interact()]));
84+
}
85+
86+
void _handlePlayCommand(CommandCall? call) {
87+
88+
}
89+
90+
void _handleHostCommand(CommandCall? call) {
91+
92+
}
93+
94+
void _handleBackendCommand(CommandCall? call) {
95+
96+
}
97+
98+
void _welcome() => print("""
99+
🎮 Reboot Launcher
100+
🔥 Launch, manage, and play Fortnite using Project Reboot!
101+
🚀 Developed by Auties00 - Version 10.0.7
102+
""".green());

cli/lib/src/game.dart

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)