Browse Source

fix compiler warnings

pbs
jake 5 years ago
parent
commit
5c520949b6
  1. 12
      src/login/character.rs
  2. 11
      src/login/dataaccess.rs
  3. 31
      src/login/login.rs
  4. 22
      src/login/main.rs
  5. 12
      src/patch/main.rs

12
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;

11
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<r2d2::ConnectionManager<PgConnection>>;
// 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?)

31
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<DA: DataAccess> {
pub data_access: DA,
}
impl<DA: DataAccess> SharedLoginState<DA> {
pub fn new(data_access: DA) -> SharedLoginState<DA> {
SharedLoginState {
data_access: data_access,
}
}
}
pub struct LoginServerState<DA: DataAccess> {
data_access: DA,
}
pub fn get_login_status(data_access: &dyn DataAccess, pkt: &Login) -> Result<UserAccount, AccountStatus> {
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<Use
}
pub struct LoginServerState<DA: DataAccess> {
data_access: DA,
}
impl<DA: DataAccess> LoginServerState<DA> {
pub fn new(data_access: DA) -> LoginServerState<DA> {
LoginServerState {
@ -118,7 +100,7 @@ impl<DA: DataAccess> ServerState for LoginServerState<DA> {
type RecvPacket = RecvLoginPacket;
type PacketError = LoginError;
fn on_connect(&mut self, id: ClientId) -> Vec<OnConnect<Self::SendPacket>> {
fn on_connect(&mut self, _id: ClientId) -> Vec<OnConnect<Self::SendPacket>> {
let mut rng = rand::thread_rng();
let mut server_key = [0u8; 48];
@ -150,6 +132,7 @@ impl<DA: DataAccess> ServerState for LoginServerState<DA> {
mod test {
use std::time::SystemTime;
use super::*;
use elseware::utf8_to_array;
#[test]
fn test_correct_login() {

22
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();
}

12
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<dyn PSOPacket>),
IOError(std::io::Error),
//CloseConnection,
}
// TODO: something like

Loading…
Cancel
Save