Skip to content

Commit 604a09b

Browse files
committed
Enhance -p/--protocol-version to accept game version string
Now you can pass `-p 1.7.10` as an alternative to `-p 5`, etc
1 parent 1688611 commit 604a09b

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

protocol/src/protocol/versions.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,50 @@ mod v15w39c;
1313
mod v1_8_9;
1414
mod v1_7_10;
1515

16+
// https://wiki.vg/Protocol_History
17+
// https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
18+
19+
pub fn protocol_name_to_protocol_version(s: String) -> i32 {
20+
match s.as_ref() {
21+
"" => SUPPORTED_PROTOCOLS[0],
22+
"1.14" => 477,
23+
"19w02a" => 452,
24+
"18w50a" => 451,
25+
"1.13.2" => 404,
26+
"1.12.2" => 340,
27+
"1.11.2" => 316,
28+
"1.11" => 315,
29+
"1.10.2" => 210,
30+
"1.9.2" => 109,
31+
"1.9" => 107,
32+
"15w39c" => 74,
33+
"1.8.9" => 47,
34+
"1.7.10" => 5,
35+
_ => {
36+
if let Ok(n) = s.parse::<i32>() {
37+
n
38+
} else {
39+
panic!("Unrecognized protocol name: {}", s)
40+
}
41+
}
42+
}
43+
}
44+
1645
pub fn translate_internal_packet_id_for_version(version: i32, state: State, dir: Direction, id: i32, to_internal: bool) -> i32 {
1746
match version {
18-
// https://wiki.vg/Protocol_History
19-
// https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
20-
2147
477 => v1_14::translate_internal_packet_id(state, dir, id, to_internal),
22-
23-
// 19w02a
2448
452 => v19w02a::translate_internal_packet_id(state, dir, id, to_internal),
25-
26-
// 18w50a
2749
451 => v18w50a::translate_internal_packet_id(state, dir, id, to_internal),
28-
29-
// 1.13.2
3050
404 => v1_13_2::translate_internal_packet_id(state, dir, id, to_internal),
31-
32-
// 1.12.2
3351
340 => v1_12_2::translate_internal_packet_id(state, dir, id, to_internal),
34-
35-
// 1.11.2
3652
316 => v1_11_2::translate_internal_packet_id(state, dir, id, to_internal),
37-
38-
// 1.11
3953
315 => v1_11_2::translate_internal_packet_id(state, dir, id, to_internal),
40-
41-
// 1.10.2
4254
210 => v1_10_2::translate_internal_packet_id(state, dir, id, to_internal),
43-
44-
// 1.9.2
4555
109 => v1_9_2::translate_internal_packet_id(state, dir, id, to_internal),
46-
47-
// 1.9
4856
107 => v1_9::translate_internal_packet_id(state, dir, id, to_internal),
49-
50-
// 15w39a/b/c
5157
74 => v15w39c::translate_internal_packet_id(state, dir, id, to_internal),
52-
53-
// 1.8.9 - 1.8
5458
47 => v1_8_9::translate_internal_packet_id(state, dir, id, to_internal),
55-
56-
// 1.7.10 - 1.7.6
5759
5 => v1_7_10::translate_internal_packet_id(state, dir, id, to_internal),
58-
59-
_ => panic!("unsupported protocol version"),
60+
_ => panic!("unsupported protocol version: {}", version),
6061
}
6162
}

0 commit comments

Comments
 (0)