veloren/common/src/comp/player.rs
Joshua Barretto a4b9230f03 fixed Cargo.lock conflict
Fixed `crossbeam-queue` being referenced  twice in the lockfile
2021-01-07 20:25:12 +00:00

41 lines
1.1 KiB
Rust

use serde::{Deserialize, Serialize};
use specs::{Component, DerefFlaggedStorage, NullStorage};
use specs_idvs::IdvStorage;
use uuid::Uuid;
const MAX_ALIAS_LEN: usize = 32;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Player {
pub alias: String,
uuid: Uuid,
}
impl Player {
pub fn new(alias: String, uuid: Uuid) -> Self { Self { alias, uuid } }
pub fn is_valid(&self) -> bool { Self::alias_is_valid(&self.alias) }
pub fn alias_is_valid(alias: &str) -> bool {
// TODO: Expose auth name validation and use it here.
// See https://gitlab.com/veloren/auth/-/blob/master/server/src/web.rs#L20
alias
.chars()
.all(|c| c.is_alphanumeric() || c == '_' || c == '-')
&& alias.len() <= MAX_ALIAS_LEN
}
/// Not to be confused with uid
pub fn uuid(&self) -> Uuid { self.uuid }
}
impl Component for Player {
type Storage = DerefFlaggedStorage<Self, IdvStorage<Self>>;
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Respawn;
impl Component for Respawn {
type Storage = NullStorage<Self>;
}