diff --git a/src/login/character.rs b/src/login/character.rs index 7120509..914dd41 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -1,27 +1,19 @@ -use std::net; -use std::sync::Arc; use std::io::Read; use std::collections::HashMap; -use rand::{Rng, RngCore}; -use bcrypt::{DEFAULT_COST, hash, verify}; +use rand::Rng; use crc::{crc32, Hasher32}; use libpso::packet::login::*; use libpso::{PacketParseError, PSOPacket}; -use libpso::crypto::{CipherError, PSOCipher, NullCipher}; use libpso::crypto::bb::PSOBBCipher; use elseware::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; -use elseware::common::network::{PacketNetworkError}; -use elseware::common::client::Client; use elseware::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; -use elseware::common::util::array_to_utf8; use elseware::utf8_to_array; use crate::dataaccess::DataAccess; -use crate::login::{SharedLoginState, get_login_status}; -//use crate::models::UserAccount; +use crate::login::get_login_status; use crate::entities::{UserAccount, Character}; pub const CHARACTER_PORT: u16 = 12001; diff --git a/src/login/dataaccess.rs b/src/login/dataaccess.rs index fe6492d..841d09d 100644 --- a/src/login/dataaccess.rs +++ b/src/login/dataaccess.rs @@ -1,15 +1,4 @@ -use std::default::Default; - -//use diesel::r2d2; -//use diesel::prelude::*; -//use diesel::pg::PgConnection; - -//use libpso::character::settings; -//use libpso::character::character; use crate::entities::*; -//use crate::models::*; - -//type ConnectionPool = r2d2::Pool>; // 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?) diff --git a/src/login/login.rs b/src/login/login.rs index f2c86c9..0938edc 100644 --- a/src/login/login.rs +++ b/src/login/login.rs @@ -2,18 +2,14 @@ use std::net; -use rand::{Rng, RngCore}; +use rand::Rng; use bcrypt; use libpso::packet::login::*; use libpso::{PacketParseError, PSOPacket}; -use libpso::crypto::{CipherError, PSOCipher, NullCipher}; use libpso::crypto::bb::PSOBBCipher; -use elseware::utf8_to_array; use elseware::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; -//use elseware::common::network::{PacketNetworkError}; -use elseware::common::client::Client; use elseware::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; use elseware::common::util::array_to_utf8; @@ -60,24 +56,6 @@ impl SendServerPacket for SendLoginPacket { } -#[derive(Clone)] -pub struct SharedLoginState { - pub data_access: DA, -} - -impl SharedLoginState { - pub fn new(data_access: DA) -> SharedLoginState { - SharedLoginState { - data_access: data_access, - } - } -} - -pub struct LoginServerState { - data_access: DA, -} - - pub fn get_login_status(data_access: &dyn DataAccess, pkt: &Login) -> Result { let username = array_to_utf8(pkt.username).map_err(|_err| AccountStatus::Error)?; let password = array_to_utf8(pkt.password).map_err(|_err| AccountStatus::Error)?; @@ -90,6 +68,10 @@ pub fn get_login_status(data_access: &dyn DataAccess, pkt: &Login) -> Result { + data_access: DA, +} + impl LoginServerState { pub fn new(data_access: DA) -> LoginServerState { LoginServerState { @@ -118,7 +100,7 @@ impl ServerState for LoginServerState { type RecvPacket = RecvLoginPacket; type PacketError = LoginError; - fn on_connect(&mut self, id: ClientId) -> Vec> { + fn on_connect(&mut self, _id: ClientId) -> Vec> { let mut rng = rand::thread_rng(); let mut server_key = [0u8; 48]; @@ -150,6 +132,7 @@ impl ServerState for LoginServerState { mod test { use std::time::SystemTime; use super::*; + use elseware::utf8_to_array; #[test] fn test_correct_login() { diff --git a/src/login/main.rs b/src/login/main.rs index c064a4f..654ceed 100644 --- a/src/login/main.rs +++ b/src/login/main.rs @@ -5,36 +5,18 @@ mod character; mod dataaccess; mod entities; - -use std::net::{SocketAddr, Ipv4Addr}; -//use std::net; use std::thread; -use std::env; - -use mio::tcp::TcpListener; -use mio::{Events, Poll, Token, Ready, PollOpt}; -use mio_extras::channel::{channel, Sender, Receiver}; -//use std::sync::mpsc::{channel, Sender, Receiver}; -//use dotenv::dotenv; - -use elseware::common::serverstate::ServerState; use bcrypt; -//use diesel::r2d2; -//use diesel::prelude::*; -//use diesel::pg::PgConnection; use libpso::character::settings; use libpso::character::character as pso_character; use libpso::character::guildcard; -//use models::{NewUser, UserAccount, UserSettings, NewUserSettings}; -//use dataaccess::DBAccess; use entities::{UserAccount, UserSettings, Character, GuildCardData}; use dataaccess::DataAccess; use elseware::utf8_to_utf16_array; -use elseware::common::clientpool::{ClientPool, ClientPoolAction}; use login::LoginServerState; use character::CharacterServerState; @@ -104,6 +86,6 @@ fn main() { elseware::common::mainloop::mainloop(char_state, character::CHARACTER_PORT); }); - auth_thread.join(); - char_thread.join(); + auth_thread.join().unwrap(); + char_thread.join().unwrap(); } diff --git a/src/patch/main.rs b/src/patch/main.rs index b15df0b..875105c 100644 --- a/src/patch/main.rs +++ b/src/patch/main.rs @@ -1,22 +1,14 @@ use std::collections::{HashMap, HashSet}; -use std::net::{TcpListener, SocketAddr, Ipv4Addr}; -use std::net; -use std::thread; use std::fs; use std::io; use std::io::{Read}; use std::path::PathBuf; -use mio_extras::channel::{channel, Sender, Receiver}; -use rand::{Rng, RngCore}; +use rand::Rng; use crc::{crc32, Hasher32}; -use mio::{Events, Poll, Token, Ready, PollOpt}; -use mio::tcp::TcpStream; use libpso::{PacketParseError, PSOPacket}; use libpso::packet::patch::*; use libpso::crypto::pc::PSOPCCipher; -use elseware::common::clientpool::{ClientPool, ClientAction, ClientPoolAction}; use elseware::common::network::{PacketNetworkError}; -use elseware::common::client::Client; use elseware::common::serverstate::{RecvServerPacket, SendServerPacket, ServerState, OnConnect, ClientId}; const PATCH_PORT: u16 = 11000; @@ -24,9 +16,7 @@ const PATCH_PORT: u16 = 11000; #[derive(Debug)] enum PatchError { PacketNetworkError(PacketNetworkError), - //UnexpectedPacket(Box), IOError(std::io::Error), - //CloseConnection, } // TODO: something like