2020-01-11 21:04:49 +00:00
|
|
|
use authc::Uuid;
|
2019-07-29 19:54:48 +00:00
|
|
|
use specs::{Component, FlaggedStorage, NullStorage};
|
|
|
|
use specs_idvs::IDVStorage;
|
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-05-09 15:41:25 +00:00
|
|
|
pub character_id: Option<i32>,
|
2019-05-19 00:45:02 +00:00
|
|
|
pub view_distance: Option<u32>,
|
2020-01-11 21:04:49 +00:00
|
|
|
uuid: Uuid,
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Player {
|
2020-05-09 15:41:25 +00:00
|
|
|
pub fn new(
|
|
|
|
alias: String,
|
|
|
|
character_id: Option<i32>,
|
|
|
|
view_distance: Option<u32>,
|
|
|
|
uuid: Uuid,
|
|
|
|
) -> Self {
|
2019-05-19 00:45:02 +00:00
|
|
|
Self {
|
|
|
|
alias,
|
2020-05-09 15:41:25 +00:00
|
|
|
character_id,
|
2019-05-19 00:45:02 +00:00
|
|
|
view_distance,
|
2020-01-11 21:04:49 +00:00
|
|
|
uuid,
|
2019-05-19 00:45:02 +00:00
|
|
|
}
|
2019-04-10 17:23:27 +00:00
|
|
|
}
|
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 {
|
|
|
|
alias.chars().all(|c| c.is_alphanumeric() || 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 {
|
2019-07-29 19:54:48 +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>;
|
|
|
|
}
|