diff --git a/src/discord/voiceclient.cpp b/src/discord/voiceclient.cpp index c3d705e..2f64b90 100644 --- a/src/discord/voiceclient.cpp +++ b/src/discord/voiceclient.cpp @@ -364,7 +364,7 @@ void DiscordVoiceClient::Identify() { msg.Token = m_token; msg.Video = true; - m_ws.Send(msg); + m_ws.Send(msg.BuildJson()); } void DiscordVoiceClient::Discovery() { @@ -442,7 +442,7 @@ void DiscordVoiceClient::HeartbeatThread() { VoiceHeartbeatMessage msg; msg.Nonce = ms; - m_ws.Send(msg); + m_ws.Send(msg.BuildJson()); } } diff --git a/src/discord/voiceclient.hpp b/src/discord/voiceclient.hpp index 0112749..540ea6a 100644 --- a/src/discord/voiceclient.hpp +++ b/src/discord/voiceclient.hpp @@ -61,6 +61,16 @@ struct VoiceHelloData { struct VoiceHeartbeatMessage { uint64_t Nonce; + std::string BuildJson() const + { + YYJsonDocument yyjsn; + yyjsn.CreateDoc(); + yyjsn.AddInt("op", (int)GatewayOp::Heartbeat); + yyjsn.AddUInt64("d", Nonce); + + return yyjsn.BuildJson(); + } + friend void to_json(nlohmann::json &j, const VoiceHeartbeatMessage &m); }; @@ -72,6 +82,34 @@ struct VoiceIdentifyMessage { bool Video; // todo streams i guess? + std::string BuildJson() const + { + YYJsonDocument yyjsn; + yyjsn.CreateDoc(); + yyjsn.AddInt("op", (int)VoiceGatewayOp::Identify); + yyjsn.CreateBlock(); + std::string* str = new std::string(std::to_string(ServerID)); + yyjsn.AddString("server_id", str->c_str()); + std::string* str2 = new std::string(std::to_string(UserID)); + yyjsn.AddString("user_id", str2->c_str()); + yyjsn.AddString("session_id", SessionID.c_str()); + yyjsn.AddString("token", Token.c_str()); + yyjsn.AddBool("video", Video); + + YYJsonArray yyjsnarr; + YYJsonDocument yyjsn2; + yyjsn2.CreateDoc(); + yyjsn2.AddString("type", "video"); + yyjsn2.AddString("rid", "100"); + yyjsn2.AddInt("quality", 100); + yyjsnarr.AddBlock(yyjsn2.GetMutableRoot()); + + yyjsn.AddArray("streams", yyjsnarr.GetArray()); + yyjsn.PushBlock("d"); + + return yyjsn.BuildJson(); + } + friend void to_json(nlohmann::json &j, const VoiceIdentifyMessage &m); }; diff --git a/src/yyjson_util.cpp b/src/yyjson_util.cpp index 3d936e6..cc8261a 100644 --- a/src/yyjson_util.cpp +++ b/src/yyjson_util.cpp @@ -95,6 +95,14 @@ void YYJsonDocument::AddInt(const char* name, std::optional value) } +void YYJsonDocument::AddUInt64(const char* name, uint64_t value) +{ + if(BuildingMode) + { + yyjson_mut_obj_add_uint(mutdoc,DataBlocks[currentBlockIndex],name,value); + } +} + //void YYJsonDocument::AddBool(const char* name, bool value) //{ // if(BuildingMode) diff --git a/src/yyjson_util.h b/src/yyjson_util.h index ed3c5c9..ff69fb3 100644 --- a/src/yyjson_util.h +++ b/src/yyjson_util.h @@ -70,6 +70,7 @@ public: void AddString(const char* name, std::optional value); //void AddInt(const char* name, int value); void AddInt(const char* name, std::optional value); + void AddUInt64(const char* name, uint64_t value); //void AddBool(const char* name, bool value); void AddBool(const char* name, std::optional value); void AddBlock(const char* name, yyjson_mut_val* block);