6#include <steamclient/external/event_emitter.h>
11#include <steamclient/crypto/crypto.hpp>
12#include <steamclient/routing/commands/router.hpp>
13#include <steamclient/routing/events/dispatcher.hpp>
14#include <steamclient/types/msgbase.hpp>
15#include <steamclient/types/packetbase.hpp>
18namespace Steam::Messaging {
20 using Job = std::function<void(
const Steam::Messaging::Packets::IPacketMsg&)>;
23 static uint64_t generate_jobid() {
return next_jobid_++; }
26 inline static uint64_t next_jobid_ = 0;
27 inline static std::unordered_map<uint64_t, Job> pending_jobs_;
30class CMClient :
public medooze::EventEmitter {
32 CMClient(std::unique_ptr<Steam::Networking::IConnection> connection)
33 : connection_(std::move(connection)) {}
36 if (connection_ && connection_->is_connected())
37 connection_->network_close();
42 inline bool is_connected()
const {
return connection_->is_connected(); }
44 inline bool is_channel_secured()
const {
return channel_secured_; }
46 inline void set_channel_secured(
bool val) { channel_secured_ = val; }
48 inline Steam::Crypto::EncryptionManager& crypto() {
return crypto_; }
50 template <
typename Request>
51 inline void execute(
const Request& req) {
52 using namespace Steam::Dispatch;
54 size_t id = Steam::Dispatch::request_id<Request>();
55 auto fn = Steam::Dispatch::g_request_router.table[id];
57 if (fn) fn(*
this, &req);
62 template <
typename THdr>
63 inline void send_msg(
const Messages::MsgBaseHdr<THdr>& msg) {
64 send_msg_impl(msg.Serialize());
67 void consume_frame(
const std::vector<uint8_t>& frame,
bool encrypt =
true);
70 void send_msg_impl(std::vector<byte> buffer);
72 inline const bool is_encryption_msg(uint32_t emsg_code) {
75 (uint32_t)Steam::Internal::Enums::EMsg::ChannelEncryptRequest ||
77 (uint32_t)Steam::Internal::Enums::EMsg::ChannelEncryptResponse ||
79 (uint32_t)Steam::Internal::Enums::EMsg::ChannelEncryptResult);
82 bool channel_secured_ =
false;
83 std::unique_ptr<Steam::Networking::IConnection> connection_;
84 Steam::Crypto::EncryptionManager crypto_;
Abstract transport interface used by the Steam networking layer.