steamkit/steam/handlers/client_msg_handler.rs
1//! The trait every message handler implements.
2//!
3//! Handlers keep a `Weak<SteamClient>` back-reference, and the client is also
4//! passed to [`ClientMsgHandler::handle_msg`], so a handler can reply without
5//! holding a strong reference to the client (which would be a cycle).
6//!
7//! To expect a disconnect (e.g. before logging off), handlers call
8//! `SteamClient::set_expect_disconnection`.
9
10use async_trait::async_trait;
11
12use crate::base::packet_base::IPacketMsg;
13use crate::error::SteamResult;
14use crate::steam::steam_client::steam_client::SteamClient;
15
16/// A message handler. It gets the incoming messages it cares about and replies
17/// through the [`SteamClient`].
18#[async_trait]
19pub trait ClientMsgHandler: Send + Sync {
20 /// Handles a client message. Called by the client; don't call it yourself.
21 async fn handle_msg(
22 &self,
23 client: &SteamClient,
24 packet_msg: &dyn IPacketMsg,
25 ) -> SteamResult<()>;
26}