rust/hedgewars-server/src/utils.rs
author S.D.
Tue, 27 Sep 2022 14:59:03 +0300
changeset 15900 fc3cb23fd26f
parent 15853 7d0f747afcb8
child 15901 4c58b320056c
permissions -rw-r--r--
Allow to see rooms of incompatible versions in the lobby For the new clients the room version is shown in a separate column. There is also a hack for previous versions clients: the room vesion specifier is prepended to the room names for rooms of incompatible versions, and the server shows 'incompatible version' error if the client tries to join them.

use base64::encode;
use std::iter::Iterator;

pub const SERVER_VERSION: u32 = 3;
pub const SERVER_MESSAGE: &str = &"Hedgewars server https://www.hedgewars.org/";

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

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

pub fn protocol_version_string(protocol_number: u16) -> &'static str {
    match protocol_number {
        17 => "0.9.7-dev",
        19 => "0.9.7",
        20 => "0.9.8-dev",
        21 => "0.9.8",
        22 => "0.9.9-dev",
        23 => "0.9.9",
        24 => "0.9.10-dev",
        25 => "0.9.10",
        26 => "0.9.11-dev",
        27 => "0.9.11",
        28 => "0.9.12-dev",
        29 => "0.9.12",
        30 => "0.9.13-dev",
        31 => "0.9.13",
        32 => "0.9.14-dev",
        33 => "0.9.14",
        34 => "0.9.15-dev",
        35 => "0.9.14.1",
        37 => "0.9.15",
        38 => "0.9.16-dev",
        39 => "0.9.16",
        40 => "0.9.17-dev",
        41 => "0.9.17",
        42 => "0.9.18-dev",
        43 => "0.9.18",
        44 => "0.9.19-dev",
        45 => "0.9.19",
        46 => "0.9.20-dev",
        47 => "0.9.20",
        48 => "0.9.21-dev",
        49 => "0.9.21",
        50 => "0.9.22-dev",
        51 => "0.9.22",
        52 => "0.9.23-dev",
        53 => "0.9.23",
        54 => "0.9.24-dev",
        55 => "0.9.24",
        56 => "0.9.25-dev",
        57 => "0.9.25",
        58 => "1.0.0-dev",
        59 => "1.0.0",
        60 => "1.0.1-dev",
        _ => "Unknown",
    }
}