Player

Type Alias Player 

Source
pub type Player = Model;

Aliased Type§

pub struct Player {
    pub id: u32,
    pub email: String,
    pub display_name: String,
    pub password: Option<String>,
    pub role: PlayerRole,
}

Fields§

§id: u32

Unique Identifier for the player

§email: String

Email address of the player

§display_name: String

Display name / Username of the player

§password: Option<String>

Hashed password which is omitted from serialization

§role: PlayerRole

The role of the player

Implementations§

Source§

impl Player

Source

pub async fn all( db: &DatabaseConnection, page: u64, count: u64, ) -> DbResult<(Vec<Self>, bool)>

Takes all the player models using a cursor starting at the offset row and finding the count number of values will check the count + 1 rows in order to determine if there are more entires to come.

db The database connection offset The number of rows to skip count The number of rows to collect

Source

pub fn create( db: &DatabaseConnection, email: String, display_name: String, password: Option<String>, ) -> Pin<Box<dyn Future<Output = DbResult<Self>> + Send + '_>>

Creates a new player with the proivded details and inserts it into the database

db The database instance email The player account email display_name The player display name password The hashed player password origin Whether the account is an origin account

Source

pub fn delete( self, db: &DatabaseConnection, ) -> Pin<Box<dyn Future<Output = DbResult<DeleteResult>> + Send + '_>>

Deletes the provided player

db The database connection

Source

pub fn all_data( id: u32, db: &DatabaseConnection, ) -> impl Future<Output = DbResult<Vec<PlayerData>>> + Send + '_

Retrieves all the player data for the desired player

id The ID of the player db The database connection

Source

pub async fn set_data( id: u32, db: &DatabaseConnection, key: String, value: String, ) -> DbResult<PlayerData>

Sets the key value data for the provided player. If the data exists then the value is updated otherwise the data will be created. The new data is returned.

id The ID of the player db The database connection key The data key value The data value

Source

pub fn bulk_insert_data<'a>( &self, db: &'a DatabaseConnection, data: impl Iterator<Item = (String, String)>, ) -> impl Future<Output = DbResult<InsertResult<ActiveModel>>> + Send + 'a

Bulk inserts a collection of player data for the provided player. Will not handle conflicts so this should only be done on a freshly create player where data doesnt already exist

db The database connection data Iterator of the data keys and values

Source

pub fn delete_data<'a>( &self, db: &'a DatabaseConnection, key: &str, ) -> impl Future<Output = DbResult<DeleteResult>> + Send + 'a

Deletes the player data with the provided key for the current player

db The database connection key The data key

Source

pub fn get_data<'a>( &self, db: &'a DatabaseConnection, key: &str, ) -> impl Future<Output = DbResult<Option<PlayerData>>> + Send + 'a

Gets the player data with the provided key for the current player

db The database connection key The data key

Source

pub fn get_classes<'a>( &self, db: &'a DatabaseConnection, ) -> impl Future<Output = DbResult<Vec<PlayerData>>> + Send + 'a

Gets all the player class data for the current player

db The database connection

Source

pub fn get_characters<'a>( &self, db: &'a DatabaseConnection, ) -> impl Future<Output = DbResult<Vec<PlayerData>>> + Send + 'a

Gets all the player character data for the current player

db The database connection

Source

pub async fn get_challenge_points(&self, db: &DatabaseConnection) -> Option<u32>

Parses the challenge points value which is the second item in the completion list.

db The database connection

Source

pub fn by_id( db: &DatabaseConnection, id: u32, ) -> impl Future<Output = DbResult<Option<Player>>> + Send + '_

Attempts to find a player with the provided ID will return none if there was no players with that ID

db The database instance id The ID of the player to find

Source

pub fn by_email<'a>( db: &'a DatabaseConnection, email: &str, ) -> impl Future<Output = DbResult<Option<Player>>> + Send + 'a

Attempts to find a player with the provided email.

db The database connection email The email address to search for

Source

pub fn has_permission_over(&self, other: &Self) -> bool

Determines whether the current player has permission to make actions on behalf of the other player. This can occur when they are both the same player or the role of self is greater than the other role

other The player to check for permission over

Source

pub fn set_password( self, db: &DatabaseConnection, password: String, ) -> Pin<Box<dyn Future<Output = DbResult<Player>> + Send + '_>>

Updates the password for the provided player returning a future resolving to the new player with its updated password value

db The database connection password The new hashed password

Source

pub fn set_role( self, db: &DatabaseConnection, role: PlayerRole, ) -> Pin<Box<dyn Future<Output = DbResult<Player>> + Send + '_>>

Sets the role of the provided player

db The database connection role The new role for the player

Source

pub fn set_details( self, db: &DatabaseConnection, username: Option<String>, email: Option<String>, ) -> Pin<Box<dyn Future<Output = DbResult<Player>> + Send + '_>>

Updates the basic details of the provided player if they are provided

db The database connection username Optional new username for the player email Optional new email for the player