2025-02-12 18:46:27 -05:00
use polariton ::operation ::Typed ;
use polariton_server ::operations ::{ Operation , OperationCode };
pub struct MoreLobbyAuth ;
impl MoreLobbyAuth {
const AUTH_PAYLOAD_KEY : u8 = 245 ;
}
2025-05-07 20:23:22 -04:00
#[async_trait::async_trait]
2025-04-06 11:00:37 -04:00
impl < C : Send + 'static > Operation < C > for MoreLobbyAuth {
2025-02-12 18:46:27 -05:00
type User = crate ::UserTy ;
2025-05-07 20:23:22 -04:00
async fn handle_async ( & self , params : polariton ::operation ::ParameterTable < C > , user : & Self ::User ) -> polariton ::operation ::OperationResponse < C > {
2025-02-12 18:46:27 -05:00
let params_dict = params . to_dict ();
if let Some ( Typed ::Str ( auth_payload )) = params_dict . get ( & Self ::AUTH_PAYLOAD_KEY ) {
2025-03-30 16:22:25 -04:00
//let mut write_lock = user.write().unwrap();
2025-05-07 20:23:22 -04:00
if user . update_with_auth ( & auth_payload . string ). await {
2025-10-26 15:43:51 -04:00
let user_info = user . user (). unwrap ();
if user_info . is_banned () {
2025-07-27 16:19:54 -04:00
return polariton ::operation ::OperationResponse {
code : Self ::op_code (),
return_code : oj_rc_core ::data ::error_codes ::WebServicesError ::Banned as i16 ,
message : polariton ::operation ::Typed ::Null ,
params : polariton ::operation ::ParameterTable ::with_capacity ( 0 ),
}
} else {
2025-10-26 15:43:51 -04:00
match user_info . webservice_listener (). await {
Ok ( listener ) => {
2025-11-03 19:24:20 -05:00
crate ::update_status ( user_info . as_ref (). as_ref ()). await ;
2025-10-26 15:43:51 -04:00
let mut resp_params = std ::collections ::HashMap ::with_capacity ( 1 );
resp_params . insert ( Self ::AUTH_PAYLOAD_KEY , polariton ::operation ::Typed ::Byte ( 0 ));
crate ::events ::IntercomHandler ::new ( listener , & user_info , user . event_sender ()). run ();
return polariton ::operation ::OperationResponse {
code : Self ::op_code (),
return_code : 0 ,
message : polariton ::operation ::Typed ::Null ,
params : resp_params . into (),
}
},
Err ( e ) => {
log ::error! ( "Failed to start web service intercom listener for user {}: {}" , user_info . public_id (), e . error_msg (). map ( | x | x . to_owned ()). unwrap_or ( "" . to_string ()));
return polariton ::operation ::OperationResponse {
code : Self ::op_code (),
return_code : oj_rc_core ::data ::error_codes ::WebServicesError ::PlatformFeatureNotAvailable as i16 ,
message : polariton ::operation ::Typed ::Null ,
params : polariton ::operation ::ParameterTable ::with_capacity ( 0 ),
}
},
2025-07-27 16:19:54 -04:00
}
2025-02-12 18:46:27 -05:00
}
2025-07-27 16:19:54 -04:00
2025-02-12 18:46:27 -05:00
}
}
polariton ::operation ::OperationResponse {
2025-05-07 20:23:22 -04:00
code : Self ::op_code (),
2025-02-12 18:46:27 -05:00
return_code : 120 ,
message : polariton ::operation ::Typed ::Null ,
params : std ::collections ::HashMap ::new (). into (),
}
}
2025-05-07 20:23:22 -04:00
fn handle ( & self , _params : polariton ::operation ::ParameterTable < C > , _user : & Self ::User ) -> polariton ::operation ::OperationResponse < C > {
unreachable! ()
}
2025-02-12 18:46:27 -05:00
}
impl OperationCode for MoreLobbyAuth {
fn op_code () -> u8 {
230
}
}