2019-05-24 19:20:28 +00:00
|
|
|
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
|
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,
|
2019-05-19 00:45:02 +00:00
|
|
|
pub view_distance: Option<u32>,
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Player {
|
2019-05-19 00:45:02 +00:00
|
|
|
pub fn new(alias: String, view_distance: Option<u32>) -> Self {
|
|
|
|
Self {
|
|
|
|
alias,
|
|
|
|
view_distance,
|
|
|
|
}
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
2019-06-29 15:04:06 +00:00
|
|
|
|
|
|
|
pub fn is_valid(&self) -> bool {
|
2019-06-29 15:48:34 +00:00
|
|
|
self.alias.chars().all(|c| c.is_alphanumeric() || c == '_')
|
|
|
|
&& self.alias.len() <= MAX_ALIAS_LEN
|
2019-06-29 15:04:06 +00:00
|
|
|
}
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for Player {
|
|
|
|
type Storage = FlaggedStorage<Self, VecStorage<Self>>;
|
|
|
|
}
|
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>;
|
|
|
|
}
|