You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.8 KiB

  1. use serde::{Serialize, Deserialize};
  2. use libpso::character::settings;
  3. use libpso::character::guildcard;
  4. pub const USERFLAG_NEWCHAR: u32 = 0x00000001;
  5. pub const USERFLAG_DRESSINGROOM: u32 = 0x00000002;
  6. #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]
  7. pub struct UserAccountId(pub u32);
  8. #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
  9. pub struct UserSettingsId(pub u32);
  10. #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
  11. pub struct GuildCardDataId(pub u32);
  12. #[derive(Clone, Debug)]
  13. pub struct NewUserAccountEntity {
  14. pub email: String,
  15. pub username: String,
  16. pub password: String,
  17. pub guildcard: u32,
  18. pub team_id: Option<u32>,
  19. pub banned_until: Option<chrono::DateTime<chrono::Utc>>,
  20. pub muted_until: Option<chrono::DateTime<chrono::Utc>>,
  21. pub flags: u32,
  22. pub activated: bool
  23. }
  24. impl Default for NewUserAccountEntity {
  25. fn default() -> NewUserAccountEntity {
  26. NewUserAccountEntity {
  27. email: "".into(),
  28. username: "".into(),
  29. password: "".into(),
  30. guildcard: 0xFFFFFFFF,
  31. team_id: None,
  32. banned_until: None,
  33. muted_until: None,
  34. flags: 0,
  35. activated: false,
  36. }
  37. }
  38. }
  39. #[derive(Clone, Debug)]
  40. pub struct UserAccountEntity {
  41. pub id: UserAccountId,
  42. pub username: String,
  43. pub password: String,
  44. pub guildcard: u32,
  45. pub team_id: Option<u32>,
  46. pub banned_until: Option<chrono::DateTime<chrono::Utc>>,
  47. pub muted_until: Option<chrono::DateTime<chrono::Utc>>,
  48. pub created_at: chrono::DateTime<chrono::Utc>,
  49. pub flags: u32, // TODO: is this used for anything other than character creation?
  50. pub activated: bool,
  51. pub at_login: bool,
  52. pub at_character: bool,
  53. pub at_ship: bool,
  54. }
  55. impl Default for UserAccountEntity {
  56. fn default() -> UserAccountEntity {
  57. UserAccountEntity {
  58. id: UserAccountId(0),
  59. username: "".into(),
  60. password: "".into(),
  61. guildcard: 0xFFFFFFFF,
  62. team_id: None,
  63. banned_until: None,
  64. muted_until: None,
  65. created_at: chrono::Utc::now(),
  66. flags: 0,
  67. activated: false,
  68. at_login: false,
  69. at_character: false,
  70. at_ship: false,
  71. }
  72. }
  73. }
  74. impl UserAccountEntity {
  75. pub fn is_currently_online(&self) -> bool {
  76. self.at_login | self.at_character | self.at_ship
  77. }
  78. }
  79. #[derive(Clone, Debug)]
  80. pub struct NewUserSettingsEntity {
  81. pub user_id: UserAccountId,
  82. pub settings: settings::UserSettings,
  83. }
  84. impl NewUserSettingsEntity {
  85. pub fn new(user_id: UserAccountId) -> NewUserSettingsEntity {
  86. NewUserSettingsEntity {
  87. user_id,
  88. settings: settings::UserSettings::default(),
  89. }
  90. }
  91. }
  92. #[derive(Clone, Debug)]
  93. pub struct UserSettingsEntity {
  94. pub id: UserSettingsId,
  95. pub user_id: UserAccountId,
  96. pub settings: settings::UserSettings,
  97. }
  98. #[derive(Clone)]
  99. pub struct NewGuildCardDataEntity {
  100. pub user_id: UserAccountId,
  101. pub guildcard: guildcard::GuildCardData,
  102. }
  103. impl NewGuildCardDataEntity {
  104. pub fn new(user_id: UserAccountId) -> NewGuildCardDataEntity {
  105. NewGuildCardDataEntity {
  106. user_id,
  107. guildcard: guildcard::GuildCardData::default(),
  108. }
  109. }
  110. }
  111. // TODO: implement this properly
  112. #[derive(Clone)]
  113. pub struct GuildCardDataEntity {
  114. pub id: GuildCardDataId,
  115. pub user_id: UserAccountId,
  116. pub guildcard: guildcard::GuildCardData,
  117. }
  118. impl GuildCardDataEntity {
  119. pub fn new(user_id: UserAccountId) -> GuildCardDataEntity {
  120. GuildCardDataEntity {
  121. id: GuildCardDataId(0),
  122. user_id,
  123. guildcard: guildcard::GuildCardData::default(),
  124. }
  125. }
  126. }