feat(server): reduce data exposed to users
This commit is contained in:
parent
350cca1ea2
commit
4490994a6c
|
@ -291,42 +291,107 @@ impl PlayerInfo {
|
|||
|
||||
#[derive(Serialize)]
|
||||
struct AnonymousPlayerInfo {
|
||||
world: i64,
|
||||
x: f64,
|
||||
y: f64,
|
||||
z: f64,
|
||||
w: f64,
|
||||
#[serde(with = "serde_bytes")]
|
||||
customize: Vec<u8>,
|
||||
gender: u8,
|
||||
race: u8,
|
||||
level: i64,
|
||||
job: i64,
|
||||
free_company: Option<String>,
|
||||
current_hp: i64,
|
||||
max_hp: i64,
|
||||
hp_percent: f64,
|
||||
age: i64,
|
||||
territory_unique_id: u64,
|
||||
}
|
||||
|
||||
impl AnonymousPlayerInfo {
|
||||
fn new_from(value: AnonymousPlayerInfoInternal, hasher: &SipHasher, salt: &str, territory: u32) -> Self {
|
||||
let customize = value.customize();
|
||||
|
||||
Self {
|
||||
territory_unique_id: value.gen_hash(hasher, salt, territory),
|
||||
world: value.world,
|
||||
x: value.x,
|
||||
y: value.y,
|
||||
z: value.z,
|
||||
w: value.w,
|
||||
customize: value.customize,
|
||||
gender: customize.gender,
|
||||
race: customize.race,
|
||||
level: value.level,
|
||||
job: value.job,
|
||||
free_company: value.free_company,
|
||||
current_hp: value.current_hp,
|
||||
max_hp: value.max_hp,
|
||||
hp_percent: value.current_hp as f64 / value.max_hp as f64,
|
||||
age: value.age,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[allow(dead_code)]
|
||||
struct Customize {
|
||||
race: u8,
|
||||
gender: u8,
|
||||
model_type: u8,
|
||||
height: u8,
|
||||
tribe: u8,
|
||||
face_type: u8,
|
||||
hairstyle: u8,
|
||||
has_highlights: u8,
|
||||
skin_colour: u8,
|
||||
eye_colour: u8,
|
||||
hair_colour: u8,
|
||||
hair_colour2: u8,
|
||||
face_features: u8,
|
||||
face_features_colour: u8,
|
||||
eyebrows: u8,
|
||||
eye_colour2: u8,
|
||||
eye_shape: u8,
|
||||
nose_shape: u8,
|
||||
jaw_shape: u8,
|
||||
lip_style: u8,
|
||||
lip_colour: u8,
|
||||
race_feature_size: u8,
|
||||
race_feature_type: u8,
|
||||
bust_size: u8,
|
||||
facepaint: u8,
|
||||
facepaint_colour: u8,
|
||||
}
|
||||
|
||||
impl Customize {
|
||||
pub fn new(data: &[u8]) -> Option<Self> {
|
||||
if data.len() < 26 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(Self {
|
||||
race: data[0],
|
||||
gender: data[1],
|
||||
model_type: data[2],
|
||||
height: data[3],
|
||||
tribe: data[4],
|
||||
face_type: data[5],
|
||||
hairstyle: data[6],
|
||||
has_highlights: data[7],
|
||||
skin_colour: data[8],
|
||||
eye_colour: data[9],
|
||||
hair_colour: data[10],
|
||||
hair_colour2: data[11],
|
||||
face_features: data[12],
|
||||
face_features_colour: data[13],
|
||||
eyebrows: data[14],
|
||||
eye_colour2: data[15],
|
||||
eye_shape: data[16],
|
||||
nose_shape: data[17],
|
||||
jaw_shape: data[18],
|
||||
lip_style: data[19],
|
||||
lip_colour: data[20],
|
||||
race_feature_size: data[21],
|
||||
race_feature_type: data[22],
|
||||
bust_size: data[23],
|
||||
facepaint: data[24],
|
||||
facepaint_colour: data[25],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct AnonymousPlayerInfoInternal {
|
||||
#[serde(skip)]
|
||||
|
@ -355,6 +420,10 @@ impl AnonymousPlayerInfoInternal {
|
|||
data_encoding::HEXLOWER.encode(&self.hash),
|
||||
).as_bytes())
|
||||
}
|
||||
|
||||
pub fn customize(&self) -> Customize {
|
||||
Customize::new(&self.customize).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
// Make our own error that wraps `anyhow::Error`.
|
||||
|
|
Loading…
Reference in New Issue