From fd943651195a970aac2b066e3bdbb23253f73ce7 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Fri, 16 Oct 2020 21:58:05 +0200 Subject: update --- src/client/mod.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/client/mod.rs') diff --git a/src/client/mod.rs b/src/client/mod.rs index 9f0d66c..1b6139f 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -31,6 +31,11 @@ pub struct Client { pub compression: bool, pub state: ClientState, pub user: User, + pub funcs: Funcs, +} + +pub struct Funcs { + pub rpc_call: crate::message::RpcCallClient, } pub struct User { @@ -75,7 +80,7 @@ impl Client { }; } - pub async fn connect(address: &'static str, port: u64, compression: bool, user: User) -> Result, Error> { + pub async fn connect(address: &'static str, port: u64, compression: bool, user: User, funcs: Funcs) -> Result, Error> { let mut stream = TcpStream::connect(format!("{}:{}", address, port)).await?; info!(target: "init", "Establishing Connection"); @@ -97,10 +102,11 @@ impl Client { compression, state: ClientState::Handshake, user, + funcs, }); } - pub async fn connect_tls(address: &'static str, port: u64, compression: bool, user: User) -> Result>, Error> { + pub async fn connect_tls(address: &'static str, port: u64, compression: bool, user: User, funcs: Funcs) -> Result>, Error> { let mut stream: TcpStream = TcpStream::connect(format!("{}:{}", address, port)).await?; info!(target: "init", "Establishing Connection"); @@ -126,6 +132,7 @@ impl Client { compression, state: ClientState::Handshake, user, + funcs, }); } @@ -171,7 +178,7 @@ pub async fn handle_login_message(client: &mu pub async fn handle_message(client: &mut Client, buf: &[u8]) -> Result<(), Error> { use crate::message::Message; - use crate::primitive::VariantList; + use crate::primitive::{VariantList, Variant}; use crate::Deserialize; use crate::Serialize; @@ -179,6 +186,23 @@ pub async fn handle_message(client: &mut Clie let (_, res) = Message::parse(buf)?; debug!(target: "init", "Received Messsage: {:#?}", res); + match res { + Message::SyncMessage(_) => {} + Message::RpcCall(msg) => { + match msg.slot_name.as_str() { + "2displayMsg(Message)" => { + (client.funcs.rpc_call.display_message)(match_variant!(msg.params[0], Variant::Message)); + }, + _ => {}, + } + + } + Message::InitRequest(_) => {} + Message::InitData(_) => {} + Message::HeartBeat(_) => {} + Message::HeartBeatReply(_) => {} + } + return Ok(()); } -- cgit v1.2.3