2020-01-11 21:04:49 +00:00
|
|
|
use authc::Uuid;
|
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;
|
2019-04-10 17:23:27 +00:00
|
|
|
|
2019-06-29 15:04:06 +00:00
|
|
|
const MAX_ALIAS_LEN: usize = 32;
|
2020-07-15 12:54:53 +00:00
|
|
|
pub const MAX_MOUNT_RANGE_SQR: i32 = 20000;
|
2019-06-29 15:04:06 +00:00
|
|
|
|
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 {
|
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>;
|
|
|
|
}
|