2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2019-07-29 19:54:48 +00:00
|
|
|
use specs::{Component, FlaggedStorage, NullStorage};
|
2020-07-06 05:56:02 +00:00
|
|
|
use specs_idvs::IdvStorage;
|
2020-12-13 17:40:15 +00:00
|
|
|
use uuid::Uuid;
|
2019-04-10 17:23:27 +00:00
|
|
|
|
2019-06-29 15:04:06 +00:00
|
|
|
const MAX_ALIAS_LEN: usize = 32;
|
|
|
|
|
2019-04-10 17:23:27 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct Player {
|
|
|
|
pub alias: String,
|
2020-01-11 21:04:49 +00:00
|
|
|
uuid: Uuid,
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Player {
|
2020-10-30 16:39:53 +00:00
|
|
|
pub fn new(alias: String, uuid: Uuid) -> Self { Self { alias, uuid } }
|
2019-06-29 15:04:06 +00:00
|
|
|
|
2020-01-11 21:04:49 +00:00
|
|
|
pub fn is_valid(&self) -> bool { Self::alias_is_valid(&self.alias) }
|
|
|
|
|
|
|
|
pub fn alias_is_valid(alias: &str) -> bool {
|
2020-08-19 11:24:06 +00:00
|
|
|
// 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
|
2019-06-29 15:04:06 +00:00
|
|
|
}
|
2020-01-11 21:04:49 +00:00
|
|
|
|
|
|
|
/// Not to be confused with uid
|
|
|
|
pub fn uuid(&self) -> Uuid { self.uuid }
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for Player {
|
2020-07-06 05:56:02 +00:00
|
|
|
type Storage = FlaggedStorage<Self, IdvStorage<Self>>;
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
2019-05-23 15:14:39 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
|
|
|
pub struct Respawn;
|
|
|
|
impl Component for Respawn {
|
|
|
|
type Storage = NullStorage<Self>;
|
|
|
|
}
|