gameServer2/src/utils.rs
author Wuzzy <Wuzzy2@mail.ru>
Sun, 09 Sep 2018 12:25:23 +0200
changeset 13767 2e8b3081cf80
parent 13524 5359ff75da3a
child 13801 5fb40c8e5542
permissions -rw-r--r--
Only reset CursorMovement to 0 if command "-cur_*" is called with appropriate direction

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

pub const PROTOCOL_VERSION : u32 = 3;
pub const SERVER: mio::Token = mio::Token(1_000_000_000);

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)
}