From 9db9a5e2487f59ec1a26de47cb92e849ba1a6b49 Mon Sep 17 00:00:00 2001 From: Jake Probst Date: Wed, 28 Aug 2019 20:39:11 -0700 Subject: [PATCH] move away from diesel requirement to run --- Cargo.toml | 8 +------- src/lib.rs | 4 ---- src/login/character.rs | 7 ++++--- src/login/dataaccess.rs | 15 ++++++++------- src/login/entities.rs | 20 ++++++++++++++++++++ src/login/login.rs | 2 +- src/login/main.rs | 31 +++++++++++++++++++++---------- 7 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 src/login/entities.rs diff --git a/Cargo.toml b/Cargo.toml index af0bb29..5eec1f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,14 +13,8 @@ name = "login" path = "src/login/main.rs" [dependencies] -futures-preview = "=0.3.0-alpha.16" libpso = { path = "../libpso" } rand = "0.6.5" -walkdir = "2" mio = "0.6" crc = "^1.0.0" -dotenv = "0.14.1" -diesel = { version = "1.4.2", features = ["r2d2", "postgres", "chrono"] } -diesel-derive-enum = { version = "0.4", features = ["postgres"]} -bcrypt = "0.4" -r2d2 = "*" \ No newline at end of file +bcrypt = "0.4" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b0ec1cd..7871731 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,3 @@ #![feature(const_generics)] -#[macro_use] -extern crate diesel; - pub mod common; -pub mod schema; diff --git a/src/login/character.rs b/src/login/character.rs index db23753..2077f7b 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -18,7 +18,8 @@ use elseware::common::util::array_to_utf8; use crate::dataaccess::DataAccess; use crate::login::{SharedLoginState, get_login_status}; -use crate::models::UserAccount; +//use crate::models::UserAccount; +use crate::entities::UserAccount; pub const CHARACTER_PORT: u16 = 12001; @@ -154,7 +155,7 @@ pub fn new_client(socket: mio::tcp::TcpStream, shared_ #[cfg(test)] mod test { use super::*; - use crate::models::{EUserSettings, UserSettings}; + use crate::entities::UserSettings; use libpso::character::settings; use std::time::SystemTime; @@ -168,7 +169,7 @@ mod test { Some(UserSettings { id: 0, user_id: 0, - settings: EUserSettings(settings::UserSettings::default()) + settings: settings::UserSettings::default() }) } } diff --git a/src/login/dataaccess.rs b/src/login/dataaccess.rs index c230e40..4bb3fdf 100644 --- a/src/login/dataaccess.rs +++ b/src/login/dataaccess.rs @@ -1,13 +1,14 @@ use std::default::Default; -use diesel::r2d2; -use diesel::prelude::*; -use diesel::pg::PgConnection; +//use diesel::r2d2; +//use diesel::prelude::*; +//use diesel::pg::PgConnection; use libpso::character::settings; -use crate::models::*; +use crate::entities::*; +//use crate::models::*; -type ConnectionPool = r2d2::Pool>; +//type ConnectionPool = r2d2::Pool>; pub trait DataAccess { fn get_user_by_id(&self, _id: u32) -> Option { @@ -27,7 +28,7 @@ pub trait DataAccess { } } -#[derive(Clone)] +/*#[derive(Clone)] pub struct DBAccess { connection_pool: ConnectionPool, } @@ -40,7 +41,6 @@ impl DBAccess { } } - impl DataAccess for DBAccess { fn get_user_by_name(&self, name: String) -> Option { use elseware::schema::user_accounts::dsl::{user_accounts, username}; @@ -72,3 +72,4 @@ impl DataAccess for DBAccess { }).unwrap() } } +*/ diff --git a/src/login/entities.rs b/src/login/entities.rs new file mode 100644 index 0000000..f6e37ec --- /dev/null +++ b/src/login/entities.rs @@ -0,0 +1,20 @@ +use std::time::SystemTime; + +use libpso::character::settings; + + +pub struct UserAccount { + pub id: i32, + pub username: String, + pub password: String, + pub guildcard: Option, + pub team_id: Option, + pub banned: bool, + pub muted_until: SystemTime, + pub created_at: SystemTime, +} +pub struct UserSettings { + pub id: i32, + pub user_id: i32, + pub settings: settings::UserSettings, +} diff --git a/src/login/login.rs b/src/login/login.rs index a6ac67b..a8c80d5 100644 --- a/src/login/login.rs +++ b/src/login/login.rs @@ -19,7 +19,7 @@ use elseware::common::serverstate::{SendServerPacket, RecvServerPacket, ServerS use elseware::common::util::array_to_utf8; use crate::dataaccess::DataAccess; -use crate::models::UserAccount; +use crate::entities::UserAccount; pub const LOGIN_PORT: u16 = 12000; diff --git a/src/login/main.rs b/src/login/main.rs index c0490d8..ab9ba31 100644 --- a/src/login/main.rs +++ b/src/login/main.rs @@ -3,7 +3,8 @@ mod login; mod character; mod dataaccess; -mod models; +mod entities; + use std::net::{SocketAddr, Ipv4Addr}; //use std::net; @@ -12,18 +13,27 @@ use std::env; use mio::tcp::TcpListener; use mio::{Events, Poll, Token, Ready, PollOpt}; -use dotenv::dotenv; +//use dotenv::dotenv; -use diesel::r2d2; +//use diesel::r2d2; //use diesel::prelude::*; -use diesel::pg::PgConnection; +//use diesel::pg::PgConnection; //use models::{NewUser, UserAccount, UserSettings, NewUserSettings}; -use dataaccess::DBAccess; +//use dataaccess::DBAccess; +use dataaccess::DataAccess; + +#[derive(Clone)] +struct LoginStubData { +} + +impl DataAccess for LoginStubData { + +} fn main() { - dotenv().ok(); - let database_url = env::var("DATABASE_URL").unwrap(); + //dotenv().ok(); + //let database_url = env::var("DATABASE_URL").unwrap(); /*if let Some(arg) = env::args().nth(1) { if arg == "dbstuff" { @@ -59,14 +69,15 @@ fn main() { println!("[login+character] starting server"); - let connection_manager = r2d2::ConnectionManager::::new(database_url); + /*let connection_manager = r2d2::ConnectionManager::::new(database_url); let connection_pool = r2d2::Pool::builder() - .build(connection_manager).unwrap(); + .build(connection_manager).unwrap();*/ let login_listener = TcpListener::bind(&SocketAddr::from((Ipv4Addr::new(0,0,0,0), login::LOGIN_PORT))).unwrap(); let character_listener = TcpListener::bind(&SocketAddr::from((Ipv4Addr::new(0,0,0,0), character::CHARACTER_PORT))).unwrap(); - let login_shared_state = login::SharedLoginState::new(DBAccess::new(connection_pool)); + //let login_shared_state = login::SharedLoginState::new(DBAccess::new(connection_pool)); + let login_shared_state = login::SharedLoginState::new(LoginStubData {}); let poll = Poll::new().unwrap(); poll.register(&login_listener, Token(0), Ready::readable(), PollOpt::edge()).unwrap();