14478
|
1 |
use base64::encode;
|
12126
|
2 |
use mio;
|
14478
|
3 |
use std::iter::Iterator;
|
12126
|
4 |
|
14478
|
5 |
pub const PROTOCOL_VERSION: u32 = 3;
|
13500
|
6 |
pub const SERVER: mio::Token = mio::Token(1_000_000_000);
|
13416
|
7 |
|
14478
|
8 |
pub fn is_name_illegal(name: &str) -> bool {
|
|
9 |
name.len() > 40
|
|
10 |
|| name.trim().is_empty()
|
|
11 |
|| name
|
|
12 |
.chars()
|
|
13 |
.any(|c| "$()*+?[]^{|}\x7F".contains(c) || '\x00' <= c && c <= '\x1F')
|
13423
|
14 |
}
|
|
15 |
|
|
16 |
pub fn to_engine_msg<T>(msg: T) -> String
|
14478
|
17 |
where
|
|
18 |
T: Iterator<Item = u8> + Clone,
|
13423
|
19 |
{
|
|
20 |
let mut tmp = Vec::new();
|
|
21 |
tmp.push(msg.clone().count() as u8);
|
|
22 |
tmp.extend(msg);
|
|
23 |
encode(&tmp)
|
13775
|
24 |
}
|
|
25 |
|
|
26 |
pub fn protocol_version_string(protocol_number: u16) -> &'static str {
|
|
27 |
match protocol_number {
|
|
28 |
17 => "0.9.7-dev",
|
|
29 |
19 => "0.9.7",
|
|
30 |
20 => "0.9.8-dev",
|
|
31 |
21 => "0.9.8",
|
|
32 |
22 => "0.9.9-dev",
|
|
33 |
23 => "0.9.9",
|
|
34 |
24 => "0.9.10-dev",
|
|
35 |
25 => "0.9.10",
|
|
36 |
26 => "0.9.11-dev",
|
|
37 |
27 => "0.9.11",
|
|
38 |
28 => "0.9.12-dev",
|
|
39 |
29 => "0.9.12",
|
|
40 |
30 => "0.9.13-dev",
|
|
41 |
31 => "0.9.13",
|
|
42 |
32 => "0.9.14-dev",
|
|
43 |
33 => "0.9.14",
|
|
44 |
34 => "0.9.15-dev",
|
|
45 |
35 => "0.9.14.1",
|
|
46 |
37 => "0.9.15",
|
|
47 |
38 => "0.9.16-dev",
|
|
48 |
39 => "0.9.16",
|
|
49 |
40 => "0.9.17-dev",
|
|
50 |
41 => "0.9.17",
|
|
51 |
42 => "0.9.18-dev",
|
|
52 |
43 => "0.9.18",
|
|
53 |
44 => "0.9.19-dev",
|
|
54 |
45 => "0.9.19",
|
|
55 |
46 => "0.9.20-dev",
|
|
56 |
47 => "0.9.20",
|
|
57 |
48 => "0.9.21-dev",
|
|
58 |
49 => "0.9.21",
|
|
59 |
50 => "0.9.22-dev",
|
|
60 |
51 => "0.9.22",
|
|
61 |
52 => "0.9.23-dev",
|
|
62 |
53 => "0.9.23",
|
|
63 |
54 => "0.9.24-dev",
|
|
64 |
55 => "0.9.24",
|
|
65 |
56 => "0.9.25-dev",
|
14477
|
66 |
57 => "0.9.25",
|
|
67 |
58 => "1.0.0-dev",
|
14478
|
68 |
_ => "Unknown",
|
13775
|
69 |
}
|
14477
|
70 |
}
|