109 lines
2.9 KiB
Rust
109 lines
2.9 KiB
Rust
// Copyright (C) 2025-2026 Emilis Bliūdžius
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{
|
|
character::CharacterId,
|
|
id_impl,
|
|
limited::ClampedString,
|
|
message::PublicIdentity,
|
|
role::{Role, RoleTitle},
|
|
token::TokenString,
|
|
};
|
|
|
|
id_impl!(PlayerId);
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Player {
|
|
id: PlayerId,
|
|
name: String,
|
|
}
|
|
|
|
impl Player {
|
|
pub fn new(name: String) -> Self {
|
|
Self {
|
|
id: PlayerId::new(),
|
|
name,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub enum Protection {
|
|
Guardian { source: CharacterId, guarding: bool },
|
|
Protector { source: CharacterId },
|
|
Vindicator { source: CharacterId },
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
|
pub enum KillOutcome {
|
|
Killed,
|
|
Failed,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub struct RoleChange {
|
|
pub role: Role,
|
|
pub new_role: RoleTitle,
|
|
pub changed_on_night: u8,
|
|
}
|
|
|
|
pub type Username = ClampedString<1, 0x40>;
|
|
pub type Password = ClampedString<6, 0x100>;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
|
pub struct UserLogin {
|
|
pub username: Username,
|
|
pub password: Password,
|
|
}
|
|
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
|
pub struct ChangePassword {
|
|
pub current: Password,
|
|
pub new: Password,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
|
pub struct DeleteUserRequest {
|
|
pub password: Password,
|
|
}
|
|
|
|
#[cfg_attr(feature = "ssr", derive(::sqlx::FromRow))]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Session {
|
|
pub username: String,
|
|
pub display_name: Option<String>,
|
|
pub pronouns: Option<String>,
|
|
|
|
pub user_created_at: DateTime<Utc>,
|
|
pub user_updated_at: DateTime<Utc>,
|
|
pub token_created_at: DateTime<Utc>,
|
|
pub token_expires_at: DateTime<Utc>,
|
|
pub token: TokenString,
|
|
}
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ProfileUpdate {
|
|
pub display_name: Option<String>,
|
|
pub pronouns: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub struct PlayerIdentity {
|
|
pub player_id: PlayerId,
|
|
pub character_id: CharacterId,
|
|
pub public: PublicIdentity,
|
|
}
|