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