gameServer2/src/utils.rs
author alfadur
Sun, 09 Sep 2018 01:20:35 +0300
changeset 13806 5fb40c8e5542
parent 13529 5359ff75da3a
permissions -rw-r--r--
port some legacy protocol support
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
     1
use std::iter::Iterator;
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
     2
use mio;
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
     3
use base64::{encode};
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
     4
12142
193dfdcb0620 - Use logging facilities instead of plain println!
unc0rr
parents: 12131
diff changeset
     5
pub const PROTOCOL_VERSION : u32 = 3;
13529
5359ff75da3a indulge clippy
alfadur
parents: 13428
diff changeset
     6
pub const SERVER: mio::Token = mio::Token(1_000_000_000);
13421
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
     7
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
     8
pub fn is_name_illegal(name: &str ) -> bool{
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
     9
    name.len() > 40 ||
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
    10
        name.trim().is_empty() ||
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
    11
        name.chars().any(|c|
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
    12
            "$()*+?[]^{|}\x7F".contains(c) ||
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
    13
                '\x00' <= c && c <= '\x1F')
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    14
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    15
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    16
pub fn to_engine_msg<T>(msg: T) -> String
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    17
    where T: Iterator<Item = u8> + Clone
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    18
{
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    19
    let mut tmp = Vec::new();
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    20
    tmp.push(msg.clone().count() as u8);
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    21
    tmp.extend(msg);
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13421
diff changeset
    22
    encode(&tmp)
13806
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    23
}
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    24
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    25
pub fn protocol_version_string(protocol_number: u16) -> &'static str {
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    26
    match protocol_number {
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    27
        17 => "0.9.7-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    28
        19 => "0.9.7",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    29
        20 => "0.9.8-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    30
        21 => "0.9.8",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    31
        22 => "0.9.9-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    32
        23 => "0.9.9",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    33
        24 => "0.9.10-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    34
        25 => "0.9.10",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    35
        26 => "0.9.11-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    36
        27 => "0.9.11",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    37
        28 => "0.9.12-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    38
        29 => "0.9.12",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    39
        30 => "0.9.13-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    40
        31 => "0.9.13",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    41
        32 => "0.9.14-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    42
        33 => "0.9.14",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    43
        34 => "0.9.15-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    44
        35 => "0.9.14.1",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    45
        37 => "0.9.15",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    46
        38 => "0.9.16-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    47
        39 => "0.9.16",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    48
        40 => "0.9.17-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    49
        41 => "0.9.17",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    50
        42 => "0.9.18-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    51
        43 => "0.9.18",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    52
        44 => "0.9.19-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    53
        45 => "0.9.19",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    54
        46 => "0.9.20-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    55
        47 => "0.9.20",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    56
        48 => "0.9.21-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    57
        49 => "0.9.21",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    58
        50 => "0.9.22-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    59
        51 => "0.9.22",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    60
        52 => "0.9.23-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    61
        53 => "0.9.23",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    62
        54 => "0.9.24-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    63
        55 => "0.9.24",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    64
        56 => "0.9.25-dev",
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    65
        _ => "Unknown"
5fb40c8e5542 port some legacy protocol support
alfadur
parents: 13529
diff changeset
    66
    }
13421
cdf69667593b partial room implementation
alfadur
parents: 12142
diff changeset
    67
}