Merge branch 'feat/login_ex' into main
This commit is contained in:
commit
d3783ce48a
17 changed files with 875 additions and 28 deletions
24
src/protocols/auth/method_login.rs
Normal file
24
src/protocols/auth/method_login.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use std::io::Cursor;
|
||||
use log::error;
|
||||
use crate::nex::account::Account;
|
||||
use crate::protocols::auth::method_login_ex::login_ex;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::structures::any::Any;
|
||||
use crate::rmc::structures::RmcSerialize;
|
||||
|
||||
pub async fn login(rmcmessage: &RMCMessage, name: &str) -> RMCResponseResult{
|
||||
rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented)
|
||||
}
|
||||
|
||||
pub async fn login_raw_params(rmcmessage: &RMCMessage, data: (&Account)) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(str) = String::deserialize(&mut reader) else {
|
||||
error!("error reading packet");
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
};
|
||||
|
||||
|
||||
login(rmcmessage, &str).await
|
||||
}
|
||||
|
|
@ -1,18 +1,29 @@
|
|||
use std::io::Cursor;
|
||||
use log::error;
|
||||
use log::{error, info};
|
||||
use crate::grpc::account;
|
||||
use crate::nex::account::Account;
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponseResult};
|
||||
use crate::rmc::structures::{RmcSerialize};
|
||||
use crate::rmc::structures::any::Any;
|
||||
|
||||
pub fn login_ex(_name: &str) -> RMCResponseResult{
|
||||
pub async fn login_ex(rmcmessage: &RMCMessage, secure_server_account: &Account , pid: u32) -> RMCResponseResult{
|
||||
// todo: figure out how the AuthenticationInfo struct works, parse it and validate login info
|
||||
|
||||
//return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
unreachable!()
|
||||
let Ok(mut client) = account::Client::new().await else {
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_Exception);
|
||||
};
|
||||
|
||||
let Ok(passwd) = client.get_nex_password(pid).await else{
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_Exception);
|
||||
};
|
||||
|
||||
|
||||
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
}
|
||||
|
||||
pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
|
||||
pub async fn login_ex_raw_params(rmcmessage: &RMCMessage, (secure_server_account): (&Account)) -> RMCResponseResult{
|
||||
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
|
||||
|
||||
let Ok(_str) = String::deserialize(&mut reader) else {
|
||||
|
|
@ -35,6 +46,9 @@ pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
|
|||
}
|
||||
}
|
||||
|
||||
//login_ex(&str)
|
||||
rmcmessage.error_result_with_code(ErrorCode::Authentication_UnderMaintenance)
|
||||
let Ok(pid) = str.parse() else {
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
};
|
||||
|
||||
login_ex(rmcmessage, secure_server_account, pid).await
|
||||
}
|
||||
|
|
@ -1,14 +1,18 @@
|
|||
mod method_login_ex;
|
||||
mod method_login;
|
||||
|
||||
use log::{error};
|
||||
use crate::define_protocol;
|
||||
use crate::protocols::auth::method_login_ex::{ login_ex_raw_params};
|
||||
use crate::nex::account::Account;
|
||||
use crate::protocols::auth::method_login::login_raw_params;
|
||||
use crate::protocols::auth::method_login_ex::{login_ex, login_ex_raw_params};
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponse};
|
||||
|
||||
|
||||
define_protocol!{
|
||||
10 => {
|
||||
10(secure_server_account: &'static Account) => {
|
||||
0x01 => login_raw_params,
|
||||
0x02 => login_ex_raw_params
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,26 @@ pub mod auth;
|
|||
pub mod server;
|
||||
#[macro_export]
|
||||
macro_rules! define_protocol {
|
||||
($id:literal => {$($func_id:literal => $func:path),*} ) => {
|
||||
pub fn protocol(rmcmessage: &RMCMessage) -> Option<RMCResponse>{
|
||||
($id:literal ($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
||||
async fn protocol (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option<RMCResponse>{
|
||||
if rmcmessage.protocol_id != $id{
|
||||
return None;
|
||||
}
|
||||
|
||||
let self_data: ( $( $ty ),* ) = ($( $varname ),*);
|
||||
|
||||
let response_result = match rmcmessage.method_id{
|
||||
$(
|
||||
$func_id => $func(rmcmessage),
|
||||
),*
|
||||
$func_id => $func ( rmcmessage, self_data).await,
|
||||
)*
|
||||
_ => {
|
||||
error!("invalid method id sent to protocol {}: {:?}", $id, rmcmessage.method_id);
|
||||
rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented)
|
||||
return Some(
|
||||
RMCResponse{
|
||||
protocol_id: $id,
|
||||
response_result: rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented)
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -23,5 +30,18 @@ macro_rules! define_protocol {
|
|||
response_result
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bound_protocol($($varname : $ty,)*) -> Box<dyn for<'message_lifetime> Fn(&'message_lifetime RMCMessage) -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = Option<RMCResponse>> + Send + 'message_lifetime>> + Send + Sync>{
|
||||
Box::new(
|
||||
move |v| {
|
||||
Box::pin(async move {
|
||||
$(
|
||||
let $varname = $varname.clone();
|
||||
)*
|
||||
protocol(v, $($varname,)*).await
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
use std::future::Future;
|
||||
use std::io::Cursor;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use log::error;
|
||||
use crate::prudp::packet::PRUDPPacket;
|
||||
|
|
@ -7,7 +9,7 @@ use crate::rmc::message::RMCMessage;
|
|||
use crate::rmc::response::{RMCResponse, RMCResponseResult, send_response};
|
||||
use crate::rmc::response::ErrorCode::Core_NotImplemented;
|
||||
|
||||
type ContainedProtocolList = Box<[Box<dyn Fn(&RMCMessage) -> Option<RMCResponse> + Send + Sync>]>;
|
||||
type ContainedProtocolList = Box<[Box<dyn for<'a> Fn(&'a RMCMessage) -> Pin<Box<dyn Future<Output = Option<RMCResponse>> + Send + 'a>> + Send + Sync>]>;
|
||||
|
||||
pub struct RMCProtocolServer(ContainedProtocolList);
|
||||
|
||||
|
|
@ -25,7 +27,7 @@ impl RMCProtocolServer{
|
|||
println!("recieved rmc message: {{ protocol: {}, method: {}}}", rmc.protocol_id, rmc.method_id);
|
||||
|
||||
for proto in &self.0 {
|
||||
if let Some(response) = proto(&rmc) {
|
||||
if let Some(response) = proto(&rmc).await {
|
||||
send_response(&packet, &socket, connection, response).await;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue