Browse Source

move away from diesel requirement to run

pbs
Jake Probst 5 years ago
parent
commit
9db9a5e248
  1. 6
      Cargo.toml
  2. 4
      src/lib.rs
  3. 7
      src/login/character.rs
  4. 15
      src/login/dataaccess.rs
  5. 20
      src/login/entities.rs
  6. 2
      src/login/login.rs
  7. 31
      src/login/main.rs

6
Cargo.toml

@ -13,14 +13,8 @@ name = "login"
path = "src/login/main.rs" path = "src/login/main.rs"
[dependencies] [dependencies]
futures-preview = "=0.3.0-alpha.16"
libpso = { path = "../libpso" } libpso = { path = "../libpso" }
rand = "0.6.5" rand = "0.6.5"
walkdir = "2"
mio = "0.6" mio = "0.6"
crc = "^1.0.0" 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" bcrypt = "0.4"
r2d2 = "*"

4
src/lib.rs

@ -1,7 +1,3 @@
#![feature(const_generics)] #![feature(const_generics)]
#[macro_use]
extern crate diesel;
pub mod common; pub mod common;
pub mod schema;

7
src/login/character.rs

@ -18,7 +18,8 @@ use elseware::common::util::array_to_utf8;
use crate::dataaccess::DataAccess; use crate::dataaccess::DataAccess;
use crate::login::{SharedLoginState, get_login_status}; 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; pub const CHARACTER_PORT: u16 = 12001;
@ -154,7 +155,7 @@ pub fn new_client<DA: DataAccess + 'static>(socket: mio::tcp::TcpStream, shared_
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::models::{EUserSettings, UserSettings};
use crate::entities::UserSettings;
use libpso::character::settings; use libpso::character::settings;
use std::time::SystemTime; use std::time::SystemTime;
@ -168,7 +169,7 @@ mod test {
Some(UserSettings { Some(UserSettings {
id: 0, id: 0,
user_id: 0, user_id: 0,
settings: EUserSettings(settings::UserSettings::default())
settings: settings::UserSettings::default()
}) })
} }
} }

15
src/login/dataaccess.rs

@ -1,13 +1,14 @@
use std::default::Default; 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 libpso::character::settings;
use crate::models::*;
use crate::entities::*;
//use crate::models::*;
type ConnectionPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>;
//type ConnectionPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>;
pub trait DataAccess { pub trait DataAccess {
fn get_user_by_id(&self, _id: u32) -> Option<UserAccount> { fn get_user_by_id(&self, _id: u32) -> Option<UserAccount> {
@ -27,7 +28,7 @@ pub trait DataAccess {
} }
} }
#[derive(Clone)]
/*#[derive(Clone)]
pub struct DBAccess { pub struct DBAccess {
connection_pool: ConnectionPool, connection_pool: ConnectionPool,
} }
@ -40,7 +41,6 @@ impl DBAccess {
} }
} }
impl DataAccess for DBAccess { impl DataAccess for DBAccess {
fn get_user_by_name(&self, name: String) -> Option<UserAccount> { fn get_user_by_name(&self, name: String) -> Option<UserAccount> {
use elseware::schema::user_accounts::dsl::{user_accounts, username}; use elseware::schema::user_accounts::dsl::{user_accounts, username};
@ -72,3 +72,4 @@ impl DataAccess for DBAccess {
}).unwrap() }).unwrap()
} }
} }
*/

20
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<i32>,
pub team_id: Option<i32>,
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,
}

2
src/login/login.rs

@ -19,7 +19,7 @@ use elseware::common::serverstate::{SendServerPacket, RecvServerPacket, ServerS
use elseware::common::util::array_to_utf8; use elseware::common::util::array_to_utf8;
use crate::dataaccess::DataAccess; use crate::dataaccess::DataAccess;
use crate::models::UserAccount;
use crate::entities::UserAccount;
pub const LOGIN_PORT: u16 = 12000; pub const LOGIN_PORT: u16 = 12000;

31
src/login/main.rs

@ -3,7 +3,8 @@
mod login; mod login;
mod character; mod character;
mod dataaccess; mod dataaccess;
mod models;
mod entities;
use std::net::{SocketAddr, Ipv4Addr}; use std::net::{SocketAddr, Ipv4Addr};
//use std::net; //use std::net;
@ -12,18 +13,27 @@ use std::env;
use mio::tcp::TcpListener; use mio::tcp::TcpListener;
use mio::{Events, Poll, Token, Ready, PollOpt}; use mio::{Events, Poll, Token, Ready, PollOpt};
use dotenv::dotenv;
//use dotenv::dotenv;
use diesel::r2d2;
//use diesel::r2d2;
//use diesel::prelude::*; //use diesel::prelude::*;
use diesel::pg::PgConnection;
//use diesel::pg::PgConnection;
//use models::{NewUser, UserAccount, UserSettings, NewUserSettings}; //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() { 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 let Some(arg) = env::args().nth(1) {
if arg == "dbstuff" { if arg == "dbstuff" {
@ -59,14 +69,15 @@ fn main() {
println!("[login+character] starting server"); println!("[login+character] starting server");
let connection_manager = r2d2::ConnectionManager::<PgConnection>::new(database_url);
/*let connection_manager = r2d2::ConnectionManager::<PgConnection>::new(database_url);
let connection_pool = r2d2::Pool::builder() 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 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 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(); let poll = Poll::new().unwrap();
poll.register(&login_listener, Token(0), Ready::readable(), PollOpt::edge()).unwrap(); poll.register(&login_listener, Token(0), Ready::readable(), PollOpt::edge()).unwrap();

Loading…
Cancel
Save