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
15
src/main.rs
15
src/main.rs
|
|
@ -10,6 +10,7 @@ use once_cell::sync::Lazy;
|
|||
use rc4::{KeyInit, Rc4, StreamCipher};
|
||||
use rc4::consts::U5;
|
||||
use simplelog::{ColorChoice, CombinedLogger, Config, LevelFilter, TerminalMode, TermLogger, WriteLogger};
|
||||
use crate::nex::account::Account;
|
||||
use crate::protocols::auth;
|
||||
use crate::protocols::server::RMCProtocolServer;
|
||||
use crate::prudp::socket::{Socket, SocketData};
|
||||
|
|
@ -24,6 +25,18 @@ mod prudp;
|
|||
pub mod rmc;
|
||||
mod protocols;
|
||||
|
||||
mod nex;
|
||||
|
||||
static KERBEROS_SERVER_PASSWORD: Lazy<String> = Lazy::new(||{
|
||||
env::var("AUTH_SERVER_PORT")
|
||||
.ok()
|
||||
.unwrap_or("password".to_owned())
|
||||
});
|
||||
|
||||
|
||||
static AUTH_SERVER_ACCOUNT: Lazy<Account> = Lazy::new(|| Account::new(1, "Quazal Authentication", &KERBEROS_SERVER_PASSWORD));
|
||||
static SECURE_SERVER_ACCOUNT: Lazy<Account> = Lazy::new(|| Account::new(2, "Quazal Rendez-Vous", &KERBEROS_SERVER_PASSWORD));
|
||||
|
||||
static AUTH_SERVER_PORT: Lazy<u16> = Lazy::new(||{
|
||||
env::var("AUTH_SERVER_PORT")
|
||||
.ok()
|
||||
|
|
@ -70,7 +83,7 @@ async fn start_servers(){
|
|||
|
||||
// dont assign it to the name _ as that will make it drop right here and now
|
||||
let rmcserver = RMCProtocolServer::new(Box::new([
|
||||
Box::new(auth::protocol)
|
||||
Box::new(auth::bound_protocol(&SECURE_SERVER_ACCOUNT))
|
||||
]));
|
||||
|
||||
let mut _socket =
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
|
||||
|
||||
struct Account{
|
||||
pub struct Account{
|
||||
pid: u32,
|
||||
username: Box<str>,
|
||||
kerbros_password: Box<str>,
|
||||
|
||||
}
|
||||
|
||||
impl Account{
|
||||
const fn new(pid: u32, passwd: &str) -> Self{
|
||||
pub fn new(pid: u32, username: &str, passwd: &str) -> Self{
|
||||
Self{
|
||||
kerbros_password: passwd.into(),
|
||||
username: username.into(),
|
||||
pid
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
mod account;
|
||||
pub mod account;
|
||||
|
|
@ -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