use crate::client::client::ClientState;
use flare_core::error::Result;
use async_trait::async_trait;
use log::debug;
use flare_core::flare_net::net::Command;
#[async_trait]
pub trait ClientSystemHandler: Send + Sync + 'static {
async fn login_out(&self) -> Result<()>;
async fn set_background(&self) -> Result<()>;
async fn set_language(&self) -> Result<()>;
async fn kick_online(&self) -> Result<()>;
async fn close(&self) -> Result<()>;
async fn on_state_change(&self, state: ClientState);
fn supported_commands(&self) -> Vec<Command>{
vec![Command::LoginOut , Command::SetBackground ,
Command::SetLanguage , Command::KickOnline ,
Command::Close]
}
fn supports_command(&self, command: Command) -> bool {
self.supported_commands().contains(&command)
}
}
pub struct DefClientSystemHandler;
impl DefClientSystemHandler {
pub fn new() -> Self {
Self
}
}
#[async_trait]
impl ClientSystemHandler for DefClientSystemHandler {
async fn login_out(&self) -> Result<()> {
debug!("处理退出登录");
Ok(())
}
async fn set_background(&self) -> Result<()> {
debug!("处理设置后台运行");
Ok(())
}
async fn set_language(&self) -> Result<()> {
debug!("处理设置语言");
Ok(())
}
async fn kick_online(&self) -> Result<()> {
debug!("处理强制下线");
Ok(())
}
async fn close(&self) -> Result<()> {
debug!("处理关闭连接");
Ok(())
}
async fn on_state_change(&self, state: ClientState) {
debug!("连接状态变化: {:?}", state);
}
}