cleaned up code, condensed code and fixed a couple of things

This commit is contained in:
DJMrTV 2025-01-26 23:21:35 +01:00
commit 38bcad37bd
10 changed files with 178 additions and 95 deletions

View file

@ -2,7 +2,8 @@ use std::io::Cursor;
use log::{error, info};
use crate::rmc::message::RMCMessage;
use crate::rmc::response::{ErrorCode, RMCResponse, RMCResponseResult};
use crate::rmc::structures::{string, any};
use crate::rmc::structures::{string, any, RmcSerialize};
use crate::rmc::structures::any::Any;
pub fn login_ex(name: &str) -> RMCResponseResult{
// todo: figure out how the AuthenticationInfo struct works, parse it and validate login info
@ -14,12 +15,12 @@ pub fn login_ex(name: &str) -> RMCResponseResult{
pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
let mut reader = Cursor::new(&rmcmessage.rest_of_data);
let Ok(str) = string::read(&mut reader) else {
let Ok(str) = String::deserialize(&mut reader) else {
error!("error reading packet");
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
};
let Ok(any) = any::read(&mut reader) else {
let Ok(any) = Any::deserialize(&mut reader) else {
error!("error reading packet");
return rmcmessage.error_result_with_code(ErrorCode::Core_InvalidArgument);
};
@ -35,5 +36,5 @@ pub fn login_ex_raw_params(rmcmessage: &RMCMessage) -> RMCResponseResult{
}
//login_ex(&str)
rmcmessage.error_result_with_code(ErrorCode::Core_AccessDenied)
rmcmessage.error_result_with_code(ErrorCode::Authentication_UnderMaintenance)
}

View file

@ -1,25 +1,14 @@
mod method_login_ex;
use log::{error, info};
use crate::define_protocol;
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};
pub fn try_process_via_protocol(rmcmessage: &RMCMessage) -> Option<RMCResponse>{
if rmcmessage.protocol_id != 10{
return None;
define_protocol!{
10 => {
0x02 => login_ex_raw_params
}
let response_result = match rmcmessage.method_id{
0x02 => login_ex_raw_params(rmcmessage),
_ => {
error!("invalid method id sent to ticket-granting protocol: {:?}", rmcmessage.method_id);
rmcmessage.error_result_with_code(ErrorCode::Core_Exception)
}
};
Some(RMCResponse{
protocol_id: 10,
response_result
})
}