1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use crate::minecraft::models::rule::Rule;
use crate::utils::either::Either;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Arguments {
pub game: Vec<Argument>,
pub jvm: Vec<Argument>,
}
impl Arguments {
pub fn jvm_arguments(&self) -> Vec<String> {
Self::collect_args(&self.jvm)
}
pub fn game_arguments(&self) -> Vec<String> {
Self::collect_args(&self.game)
}
fn collect_args(args: &[Argument]) -> Vec<String> {
let mut arguments = vec![];
for argument in args {
match argument {
Argument::Simple(simple_argument) => {
if check_skip_argument(simple_argument) {
continue;
}
arguments.push(simple_argument.to_string());
}
Argument::Complex(complex_arg) => {
if !complex_arg.check_use() {
continue;
}
let values = complex_arg
.value()
.into_iter()
.filter(|arg| !check_skip_argument(arg));
arguments.extend(values);
}
}
}
arguments
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Argument {
Simple(String),
Complex(ComplexArgument),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ComplexArgument {
#[serde(alias = "compatibilityRules")]
pub rules: Vec<Rule>,
pub value: Either<String, Vec<String>>,
}
impl ComplexArgument {
pub fn check_use(&self) -> bool {
for rule in &self.rules {
if !rule.allows() {
return false;
}
}
true
}
pub fn value(&self) -> Vec<String> {
match &self.value {
Either::Left(val) => vec![val.clone()],
Either::Right(x) => x.clone(),
}
}
}
fn check_skip_argument(arg: &str) -> bool {
matches!(
arg,
"--clientId" | "--xuid" | "${clientid}" | "${auth_xuid}"
)
}