|
@ -2,18 +2,14 @@ |
|
|
|
|
|
|
|
|
use std::net;
|
|
|
use std::net;
|
|
|
|
|
|
|
|
|
use rand::{Rng, RngCore};
|
|
|
|
|
|
|
|
|
use rand::Rng;
|
|
|
use bcrypt;
|
|
|
use bcrypt;
|
|
|
|
|
|
|
|
|
use libpso::packet::login::*;
|
|
|
use libpso::packet::login::*;
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::{PacketParseError, PSOPacket};
|
|
|
use libpso::crypto::{CipherError, PSOCipher, NullCipher};
|
|
|
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
|
use libpso::crypto::bb::PSOBBCipher;
|
|
|
|
|
|
|
|
|
use elseware::utf8_to_array;
|
|
|
|
|
|
use elseware::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY};
|
|
|
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::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId};
|
|
|
use elseware::common::util::array_to_utf8;
|
|
|
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> {
|
|
|
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 username = array_to_utf8(pkt.username).map_err(|_err| AccountStatus::Error)?;
|
|
|
let password = array_to_utf8(pkt.password).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> {
|
|
|
impl<DA: DataAccess> LoginServerState<DA> {
|
|
|
pub fn new(data_access: DA) -> LoginServerState<DA> {
|
|
|
pub fn new(data_access: DA) -> LoginServerState<DA> {
|
|
|
LoginServerState {
|
|
|
LoginServerState {
|
|
@ -118,7 +100,7 @@ impl<DA: DataAccess> ServerState for LoginServerState<DA> { |
|
|
type RecvPacket = RecvLoginPacket;
|
|
|
type RecvPacket = RecvLoginPacket;
|
|
|
type PacketError = LoginError;
|
|
|
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 rng = rand::thread_rng();
|
|
|
|
|
|
|
|
|
let mut server_key = [0u8; 48];
|
|
|
let mut server_key = [0u8; 48];
|
|
@ -150,6 +132,7 @@ impl<DA: DataAccess> ServerState for LoginServerState<DA> { |
|
|
mod test {
|
|
|
mod test {
|
|
|
use std::time::SystemTime;
|
|
|
use std::time::SystemTime;
|
|
|
use super::*;
|
|
|
use super::*;
|
|
|
|
|
|
use elseware::utf8_to_array;
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|
fn test_correct_login() {
|
|
|
fn test_correct_login() {
|
|
|