jake
5 years ago
11 changed files with 92 additions and 128 deletions
-
8src/entity/account.rs
-
8src/entity/character.rs
-
36src/entity/gateway/entitygateway.rs
-
3src/entity/gateway/mod.rs
-
0src/entity/item.rs
-
4src/entity/mod.rs
-
1src/lib.rs
-
38src/login/character.rs
-
83src/login/dataaccess.rs
-
30src/login/login.rs
-
9src/login/main.rs
@ -0,0 +1,8 @@ |
|||||
|
use libpso::character::character;
|
||||
|
|
||||
|
#[derive(Copy, Clone, Debug)]
|
||||
|
pub struct Character {
|
||||
|
pub id: u32,
|
||||
|
pub user_id: u32,
|
||||
|
pub character: character::Character,
|
||||
|
}
|
@ -0,0 +1,36 @@ |
|||||
|
use crate::entity::account::*;
|
||||
|
use crate::entity::character::*;
|
||||
|
|
||||
|
pub trait EntityGateway {
|
||||
|
fn get_user_by_id(&self, _id: u32) -> Option<UserAccount> {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn get_user_by_name(&self, _username: String) -> Option<UserAccount> {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn set_user(&mut self, _user: &UserAccount) {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn get_user_settings_by_user(&self, _user: &UserAccount) -> Option<UserSettings> {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn create_user_settings_by_user(&self, _user: &UserAccount) -> UserSettings {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn get_characters_by_user(&self, _user: &UserAccount) -> [Option<Character>; 4] {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn set_character_by_user(&mut self, _user: &UserAccount, _slot: u32, _char: Character) {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
|
||||
|
fn get_guild_card_data_by_user(&self, _user: &UserAccount) -> GuildCardData {
|
||||
|
unimplemented!();
|
||||
|
}
|
||||
|
}
|
@ -0,0 +1,3 @@ |
|||||
|
pub mod entitygateway;
|
||||
|
|
||||
|
pub use entitygateway::EntityGateway;
|
@ -0,0 +1,4 @@ |
|||||
|
pub mod gateway;
|
||||
|
pub mod account;
|
||||
|
pub mod character;
|
||||
|
pub mod item;
|
@ -1,3 +1,4 @@ |
|||||
#![feature(const_generics)]
|
#![feature(const_generics)]
|
||||
|
|
||||
pub mod common;
|
pub mod common;
|
||||
|
pub mod entity;
|
@ -1,83 +0,0 @@ |
|||||
use crate::entities::*;
|
|
||||
|
|
||||
// TODO: should any of these be options? as in, what does failure look like
|
|
||||
// TODO: determine best way to design this, current path will lead to 8493024039280x functions (probably?)
|
|
||||
pub trait DataAccess {
|
|
||||
fn get_user_by_id(&self, _id: u32) -> Option<UserAccount> {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn get_user_by_name(&self, _username: String) -> Option<UserAccount> {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn set_user(&mut self, _user: &UserAccount) {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn get_user_settings_by_user(&self, _user: &UserAccount) -> Option<UserSettings> {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn create_user_settings_by_user(&self, _user: &UserAccount) -> UserSettings {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn get_characters_by_user(&self, _user: &UserAccount) -> [Option<Character>; 4] {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn set_character_by_user(&mut self, _user: &UserAccount, slot: u32, char: Character) {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
|
|
||||
fn get_guild_card_data_by_user(&self, _user: &UserAccount) -> GuildCardData {
|
|
||||
unimplemented!();
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
/*#[derive(Clone)]
|
|
||||
pub struct DBAccess {
|
|
||||
connection_pool: ConnectionPool,
|
|
||||
}
|
|
||||
|
|
||||
impl DBAccess {
|
|
||||
pub fn new(pool: ConnectionPool) -> DBAccess {
|
|
||||
DBAccess {
|
|
||||
connection_pool: pool,
|
|
||||
}
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
impl DataAccess for DBAccess {
|
|
||||
fn get_user_by_name(&self, name: String) -> Option<UserAccount> {
|
|
||||
use elseware::schema::user_accounts::dsl::{user_accounts, username};
|
|
||||
self.connection_pool.get()
|
|
||||
.map(|conn| {
|
|
||||
user_accounts.filter(username.eq(name)).load::<UserAccount>(&conn)
|
|
||||
.map(|mut user| user.pop()).unwrap_or(None)
|
|
||||
})
|
|
||||
.unwrap_or(None)
|
|
||||
}
|
|
||||
|
|
||||
fn get_user_settings_by_user(&self, user: &UserAccount) -> Option<UserSettings> {
|
|
||||
self.connection_pool.get()
|
|
||||
.ok()
|
|
||||
.and_then(|conn| {
|
|
||||
UserSettings::belonging_to(user).first::<UserSettings>(&conn).ok()
|
|
||||
})
|
|
||||
}
|
|
||||
|
|
||||
fn create_user_settings_by_user(&self, user: &UserAccount) -> UserSettings {
|
|
||||
use elseware::schema::user_settings::dsl::user_settings;
|
|
||||
self.connection_pool.get()
|
|
||||
.map(|conn| {
|
|
||||
let new_settings = NewUserSettings {
|
|
||||
user_id: user.id,
|
|
||||
settings: EUserSettings(settings::UserSettings::default())
|
|
||||
};
|
|
||||
diesel::insert_into(user_settings).values(&new_settings).get_result(&conn).unwrap()
|
|
||||
}).unwrap()
|
|
||||
}
|
|
||||
}
|
|
||||
*/
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue