|
|
@ -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() {
|
|
|
|