gameServer2/src/utils.rs
author Wuzzy <Wuzzy2@mail.ru>
Fri, 03 Aug 2018 00:39:50 +0200
changeset 13607 212036414957
parent 13524 5359ff75da3a
child 13801 5fb40c8e5542
permissions -rw-r--r--
Make cake bounce off bounce edge, stop cake at wrap edge to prevent other bug The "other bug" is that the cake just walks through terrain when it hits the wrap world edge. This behaviour is even worse.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
     1
use std::iter::Iterator;
12126
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12125
diff changeset
     2
use mio;
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
     3
use base64::{encode};
12126
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12125
diff changeset
     4
12137
193dfdcb0620 - Use logging facilities instead of plain println!
unc0rr
parents: 12126
diff changeset
     5
pub const PROTOCOL_VERSION : u32 = 3;
13524
5359ff75da3a indulge clippy
alfadur
parents: 13423
diff changeset
     6
pub const SERVER: mio::Token = mio::Token(1_000_000_000);
13416
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
     7
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
     8
pub fn is_name_illegal(name: &str ) -> bool{
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
     9
    name.len() > 40 ||
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
    10
        name.trim().is_empty() ||
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
    11
        name.chars().any(|c|
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
    12
            "$()*+?[]^{|}\x7F".contains(c) ||
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
    13
                '\x00' <= c && c <= '\x1F')
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    14
}
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    15
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    16
pub fn to_engine_msg<T>(msg: T) -> String
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    17
    where T: Iterator<Item = u8> + Clone
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    18
{
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    19
    let mut tmp = Vec::new();
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    20
    tmp.push(msg.clone().count() as u8);
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    21
    tmp.extend(msg);
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13416
diff changeset
    22
    encode(&tmp)
13416
cdf69667593b partial room implementation
alfadur
parents: 12137
diff changeset
    23
}