6#include <steamclient/external/event_emitter.h>
8#include <boost/asio/steady_timer.hpp>
12#include <steamclient/crypto/crypto.hpp>
13#include <steamclient/routing/commands/router.hpp>
14#include <steamclient/routing/events/dispatcher.hpp>
15#include <steamclient/types/msgbase.hpp>
16#include <steamclient/types/packetbase.hpp>
19namespace Steam::Messaging {
21 using Job = std::function<void(
const Steam::Messaging::Packets::IPacketMsg&)>;
24 static uint64_t generate_jobid() {
return next_jobid_++; }
27 inline static uint64_t next_jobid_ = 0;
28 inline static std::unordered_map<uint64_t, Job> pending_jobs_;
31class CMClient :
public medooze::EventEmitter {
33 CMClient(std::unique_ptr<Steam::Networking::IConnection> connection,
34 boost::asio::io_context& ctx)
35 : io_ctx_(ctx), connection_(std::move(connection)) {}
37 ~CMClient() { shutdown(); }
41 inline bool is_connected()
const {
return connection_->is_connected(); }
43 inline bool is_channel_secured()
const {
return channel_secured_; }
45 inline void set_channel_secured(
bool val) { channel_secured_ = val; }
47 inline Steam::Crypto::EncryptionManager& crypto() {
return crypto_; }
49 template <
typename Request>
50 inline void execute(
const Request& req) {
51 using namespace Steam::Dispatch;
53 size_t id = Steam::Dispatch::request_id<Request>();
54 auto fn = Steam::Dispatch::g_request_router.table[id];
56 if (fn) fn(*
this, &req);
60 template <
typename THdr>
61 inline void send_msg(
const Messages::MsgBaseHdr<THdr>& msg) {
62 send_msg_impl(msg.Serialize());
65 void consume_frame(
const std::vector<uint8_t>& frame,
bool encrypt =
true);
66 void kickoff_heartbeat(
int interval);
69 void schedule_heartbeat();
70 void send_msg_impl(std::vector<byte> buffer);
73 inline const bool is_encryption_msg(uint32_t emsg_code) {
76 (uint32_t)Steam::Internal::Enums::EMsg::ChannelEncryptRequest ||
78 (uint32_t)Steam::Internal::Enums::EMsg::ChannelEncryptResponse ||
80 (uint32_t)Steam::Internal::Enums::EMsg::ChannelEncryptResult);
83 bool channel_secured_ =
false;
84 boost::asio::io_context& io_ctx_;
85 std::unique_ptr<Steam::Networking::IConnection> connection_;
86 Steam::Crypto::EncryptionManager crypto_;
87 std::optional<boost::asio::steady_timer> heartbeat_timer_;
88 std::chrono::seconds heartbeat_interval_{};
Abstract transport interface used by the Steam networking layer.