gameServer2/src/utils.rs
author Wuzzy <Wuzzy2@mail.ru>
Wed, 11 Jul 2018 17:13:25 +0200
changeset 13475 0d27f0c21b71
parent 13428 87a6cad20c90
child 13529 5359ff75da3a
permissions -rw-r--r--
Fix aihDoesntMatter not applying to hammer and shover

use std::iter::Iterator;
use mio;
use base64::{encode};

pub const PROTOCOL_VERSION : u32 = 3;
pub const SERVER: mio::Token = mio::Token(1000000000 + 0);

pub fn is_name_illegal(name: &str ) -> bool{
    name.len() > 40 ||
        name.trim().is_empty() ||
        name.chars().any(|c|
            "$()*+?[]^{|}\x7F".contains(c) ||
                '\x00' <= c && c <= '\x1F')
}

pub fn to_engine_msg<T>(msg: T) -> String
    where T: Iterator<Item = u8> + Clone
{
    let mut tmp = Vec::new();
    tmp.push(msg.clone().count() as u8);
    tmp.extend(msg);
    encode(&tmp)
}