feat(protocols): extend functionality of protocol macro
This commit is contained in:
parent
ffe4084ba3
commit
1679590bf3
6 changed files with 38 additions and 12 deletions
|
|
@ -5,11 +5,10 @@ use crate::rmc::response::{ErrorCode, RMCResponse, RMCResponseResult};
|
|||
use crate::rmc::structures::{string, any, RmcSerialize};
|
||||
use crate::rmc::structures::any::Any;
|
||||
|
||||
pub fn login_ex(name: &str) -> RMCResponseResult{
|
||||
pub fn login_ex(rmcmessage: &RMCMessage, name: &str) -> 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!()
|
||||
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
|
||||
}
|
||||
|
||||
pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
|
||||
|
|
@ -35,6 +34,5 @@ pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
|
|||
}
|
||||
}
|
||||
|
||||
//login_ex(&str)
|
||||
rmcmessage.error_result_with_code(ErrorCode::Authentication_UnderMaintenance)
|
||||
login_ex(rmcmessage, &str)
|
||||
}
|
||||
|
|
@ -2,13 +2,14 @@ mod method_login_ex;
|
|||
|
||||
use log::{error, info};
|
||||
use crate::define_protocol;
|
||||
use crate::nex::account::Account;
|
||||
use crate::protocols::auth::method_login_ex::{login_ex, login_ex_raw_params};
|
||||
use crate::rmc::message::RMCMessage;
|
||||
use crate::rmc::response::{ErrorCode, RMCResponse, RMCResponseResult};
|
||||
|
||||
|
||||
define_protocol!{
|
||||
10 => {
|
||||
10<'a>(account: &'a Account) => {
|
||||
0x02 => login_ex_raw_params
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,8 @@ 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 $( <$lifetime:lifetime> )?($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
||||
fn protocol $( <$lifetime> )? (rmcmessage: &RMCMessage, $($varname : $ty,)*) -> Option<RMCResponse>{
|
||||
if rmcmessage.protocol_id != $id{
|
||||
return None;
|
||||
}
|
||||
|
|
@ -23,5 +23,16 @@ macro_rules! define_protocol {
|
|||
response_result
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bound_protocol$(<$lifetime>)?($($varname : $ty,)*) -> Box<dyn Fn(&RMCMessage) -> Option<RMCResponse> + Send + Sync $( + $lifetime)?>{
|
||||
Box::new(
|
||||
move |v| {
|
||||
$(
|
||||
let $varname = $varname.clone();
|
||||
)*
|
||||
protocol(v, $($varname,)*)
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue