rust/hedgewars-server/src/utils.rs
changeset 14462 98ef2913ec73
parent 14461 a077aac9df01
child 14784 f43ab2bd76ae
equal deleted inserted replaced
14461:a077aac9df01 14462:98ef2913ec73
       
     1 use base64::encode;
       
     2 use mio;
     1 use std::iter::Iterator;
     3 use std::iter::Iterator;
     2 use mio;
       
     3 use base64::{encode};
       
     4 
     4 
     5 pub const PROTOCOL_VERSION : u32 = 3;
     5 pub const PROTOCOL_VERSION: u32 = 3;
     6 pub const SERVER: mio::Token = mio::Token(1_000_000_000);
     6 pub const SERVER: mio::Token = mio::Token(1_000_000_000);
     7 
     7 
     8 pub fn is_name_illegal(name: &str ) -> bool{
     8 pub fn is_name_illegal(name: &str) -> bool {
     9     name.len() > 40 ||
     9     name.len() > 40
    10         name.trim().is_empty() ||
    10         || name.trim().is_empty()
    11         name.chars().any(|c|
    11         || name
    12             "$()*+?[]^{|}\x7F".contains(c) ||
    12             .chars()
    13                 '\x00' <= c && c <= '\x1F')
    13             .any(|c| "$()*+?[]^{|}\x7F".contains(c) || '\x00' <= c && c <= '\x1F')
    14 }
    14 }
    15 
    15 
    16 pub fn to_engine_msg<T>(msg: T) -> String
    16 pub fn to_engine_msg<T>(msg: T) -> String
    17     where T: Iterator<Item = u8> + Clone
    17 where
       
    18     T: Iterator<Item = u8> + Clone,
    18 {
    19 {
    19     let mut tmp = Vec::new();
    20     let mut tmp = Vec::new();
    20     tmp.push(msg.clone().count() as u8);
    21     tmp.push(msg.clone().count() as u8);
    21     tmp.extend(msg);
    22     tmp.extend(msg);
    22     encode(&tmp)
    23     encode(&tmp)
    62         54 => "0.9.24-dev",
    63         54 => "0.9.24-dev",
    63         55 => "0.9.24",
    64         55 => "0.9.24",
    64         56 => "0.9.25-dev",
    65         56 => "0.9.25-dev",
    65         57 => "0.9.25",
    66         57 => "0.9.25",
    66         58 => "1.0.0-dev",
    67         58 => "1.0.0-dev",
    67         _ => "Unknown"
    68         _ => "Unknown",
    68     }
    69     }
    69 }
    70 }