99 lines
2.8 KiB
Rust
99 lines
2.8 KiB
Rust
use super::{
|
|
item::{SkillType, StatType},
|
|
journal::JournalState,
|
|
};
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::BTreeMap;
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
pub struct UserTermData {
|
|
pub accepted_terms: BTreeMap<String, DateTime<Utc>>,
|
|
pub terms_complete: bool, // Recalculated on accept and login.
|
|
pub last_presented_term: Option<String>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
#[serde(default)]
|
|
pub struct UserExperienceData {
|
|
pub spent_xp: u64, // Since last chargen complete.
|
|
pub journals: JournalState,
|
|
pub xp_change_for_this_reroll: i64,
|
|
pub crafted_items: BTreeMap<String, u64>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
|
pub enum UserFlag {
|
|
Staff,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
#[serde(default)]
|
|
pub struct User {
|
|
pub username: String,
|
|
pub password_hash: String, // bcrypted.
|
|
pub email: String,
|
|
pub player_item_id: i64,
|
|
pub registered_at: Option<DateTime<Utc>>,
|
|
pub banned_until: Option<DateTime<Utc>>,
|
|
pub abandoned_at: Option<DateTime<Utc>>,
|
|
pub chargen_last_completed_at: Option<DateTime<Utc>>,
|
|
|
|
pub terms: UserTermData,
|
|
pub experience: UserExperienceData,
|
|
pub raw_skills: BTreeMap<SkillType, f64>,
|
|
pub raw_stats: BTreeMap<StatType, f64>,
|
|
pub last_skill_improve: BTreeMap<SkillType, DateTime<Utc>>,
|
|
pub last_page_from: Option<String>,
|
|
pub credits: u64,
|
|
pub danger_code: Option<String>,
|
|
pub user_flags: Vec<UserFlag>,
|
|
// Reminder: Consider backwards compatibility when updating this.
|
|
}
|
|
|
|
impl Default for UserTermData {
|
|
fn default() -> Self {
|
|
UserTermData {
|
|
accepted_terms: BTreeMap::new(),
|
|
terms_complete: false,
|
|
last_presented_term: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for UserExperienceData {
|
|
fn default() -> Self {
|
|
UserExperienceData {
|
|
spent_xp: 0,
|
|
journals: Default::default(),
|
|
xp_change_for_this_reroll: 0,
|
|
crafted_items: BTreeMap::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for User {
|
|
fn default() -> Self {
|
|
User {
|
|
username: "unknown".to_owned(),
|
|
password_hash: "unknown".to_owned(),
|
|
email: "unknown".to_owned(),
|
|
player_item_id: 0,
|
|
registered_at: None,
|
|
banned_until: None,
|
|
abandoned_at: None,
|
|
chargen_last_completed_at: None,
|
|
|
|
terms: UserTermData::default(),
|
|
experience: UserExperienceData::default(),
|
|
raw_skills: BTreeMap::new(),
|
|
raw_stats: BTreeMap::new(),
|
|
last_skill_improve: BTreeMap::new(),
|
|
last_page_from: None,
|
|
credits: 500,
|
|
danger_code: None,
|
|
user_flags: vec![],
|
|
}
|
|
}
|
|
}
|