elseware/src/entity/account.rs

144 lines
3.8 KiB
Rust
Raw Normal View History

use serde::{Serialize, Deserialize};
use libpso::character::settings;
2019-09-05 15:09:29 -07:00
use libpso::character::guildcard;
2019-09-23 22:24:51 -07:00
pub const USERFLAG_NEWCHAR: u32 = 0x00000001;
pub const USERFLAG_DRESSINGROOM: u32 = 0x00000002;
2021-09-27 23:06:21 -06:00
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
pub struct UserAccountId(pub u32);
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct UserSettingsId(pub u32);
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct GuildCardDataId(pub u32);
#[derive(Clone, Debug)]
pub struct NewUserAccountEntity {
2020-10-22 08:56:37 -06:00
pub email: String,
pub username: String,
pub password: String,
pub guildcard: u32,
pub team_id: Option<u32>,
2020-10-03 17:13:29 -06:00
pub banned_until: Option<chrono::DateTime<chrono::Utc>>,
pub muted_until: Option<chrono::DateTime<chrono::Utc>>,
pub flags: u32,
2020-10-27 22:31:54 -06:00
pub activated: bool
}
impl Default for NewUserAccountEntity {
fn default() -> NewUserAccountEntity {
NewUserAccountEntity {
email: "".into(),
username: "".into(),
password: "".into(),
guildcard: 0xFFFFFFFF,
team_id: None,
banned_until: None,
muted_until: None,
flags: 0,
activated: false,
}
}
}
2019-09-23 22:24:51 -07:00
#[derive(Clone, Debug)]
pub struct UserAccountEntity {
pub id: UserAccountId,
pub username: String,
pub password: String,
2020-03-22 22:40:40 -03:00
pub guildcard: u32,
2019-09-05 15:09:29 -07:00
pub team_id: Option<u32>,
2020-10-03 17:13:29 -06:00
pub banned_until: Option<chrono::DateTime<chrono::Utc>>,
pub muted_until: Option<chrono::DateTime<chrono::Utc>>,
pub created_at: chrono::DateTime<chrono::Utc>,
2019-09-23 22:24:51 -07:00
pub flags: u32, // TODO: is this used for anything other than character creation?
pub activated: bool,
2020-10-27 22:31:54 -06:00
pub at_login: bool,
pub at_character: bool,
pub at_ship: bool,
}
2019-09-05 15:09:29 -07:00
2021-09-27 23:06:21 -06:00
impl Default for UserAccountEntity {
fn default() -> UserAccountEntity {
UserAccountEntity {
id: UserAccountId(0),
username: "".into(),
password: "".into(),
guildcard: 0xFFFFFFFF,
team_id: None,
banned_until: None,
muted_until: None,
created_at: chrono::Utc::now(),
flags: 0,
activated: false,
at_login: false,
at_character: false,
at_ship: false,
}
}
}
2020-10-27 22:31:54 -06:00
impl UserAccountEntity {
pub fn is_currently_online(&self) -> bool {
self.at_login | self.at_character | self.at_ship
}
}
2020-03-29 22:00:07 -07:00
#[derive(Clone, Debug)]
pub struct NewUserSettingsEntity {
pub user_id: UserAccountId,
pub settings: settings::UserSettings,
}
2019-09-05 15:09:29 -07:00
impl NewUserSettingsEntity {
pub fn new(user_id: UserAccountId) -> NewUserSettingsEntity {
NewUserSettingsEntity {
2021-06-18 20:38:29 -06:00
user_id,
2020-03-29 22:00:07 -07:00
settings: settings::UserSettings::default(),
}
}
}
#[derive(Clone, Debug)]
pub struct UserSettingsEntity {
pub id: UserSettingsId,
pub user_id: UserAccountId,
pub settings: settings::UserSettings,
}
#[derive(Clone)]
pub struct NewGuildCardDataEntity {
pub user_id: UserAccountId,
pub guildcard: guildcard::GuildCardData,
}
impl NewGuildCardDataEntity {
pub fn new(user_id: UserAccountId) -> NewGuildCardDataEntity {
NewGuildCardDataEntity {
2021-06-18 20:38:29 -06:00
user_id,
guildcard: guildcard::GuildCardData::default(),
}
}
}
2020-03-29 22:00:07 -07:00
// TODO: implement this properly
2020-03-29 22:00:07 -07:00
#[derive(Clone)]
pub struct GuildCardDataEntity {
pub id: GuildCardDataId,
pub user_id: UserAccountId,
2019-09-05 15:09:29 -07:00
pub guildcard: guildcard::GuildCardData,
}
2020-03-29 22:00:07 -07:00
impl GuildCardDataEntity {
pub fn new(user_id: UserAccountId) -> GuildCardDataEntity {
GuildCardDataEntity {
id: GuildCardDataId(0),
2021-06-18 20:38:29 -06:00
user_id,
2020-03-29 22:00:07 -07:00
guildcard: guildcard::GuildCardData::default(),
}
}
}