gameServer2/src/utils.rs
author Wuzzy <Wuzzy2@mail.ru>
Sat, 07 Jul 2018 23:29:02 +0200
changeset 13452 2d787d122083
parent 13423 87a6cad20c90
child 13524 5359ff75da3a
permissions -rw-r--r--
Fix TotalRounds still being -1 in first real turn after hog placement phase Now it is: Hog placement phase: -1 First real round: 0 (previously -1) Second real round: 1 (previously 0) Third real round: 2 (previously 1) ...

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