Skip to content

Commit

Permalink
debugging, correctly set session id
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Sep 25, 2024
1 parent 8ec080b commit cb418e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
34 changes: 19 additions & 15 deletions src/davetest/dave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@
int main() {
using namespace std::chrono_literals;
char* t = getenv("DPP_UNIT_TEST_TOKEN");
if (t != nullptr) {
dpp::snowflake TEST_GUILD_ID(std::string(getenv("TEST_GUILD_ID")));
dpp::snowflake TEST_VC_ID(std::string(getenv("TEST_VC_ID")));
std::cout << "Test Guild ID: " << TEST_GUILD_ID << " Test VC ID: " << TEST_VC_ID << "\n\n";
dpp::cluster dave_test(t, dpp::i_default_intents | dpp::i_guild_members);
dave_test.set_websocket_protocol(dpp::ws_etf);
dave_test.on_log(dpp::utility::cout_logger());

dave_test.on_guild_create([&](const dpp::guild_create_t & event) {
if (event.created->id == TEST_GUILD_ID) {
dpp::discord_client* s = dave_test.get_shard(0);
s->connect_voice(TEST_GUILD_ID, TEST_VC_ID, false, false, true);
}
});
dave_test.start(false);
if (t == nullptr || getenv("TEST_GUILD_ID") == nullptr || getenv("TEST_VC_ID") == nullptr) {
std::cerr << "Missing unit test environment. Set DPP_UNIT_TEST_TOKEN, TEST_GUILD_ID, and TEST_VC_ID\n";
exit(1);
}
dpp::snowflake TEST_GUILD_ID(std::string(getenv("TEST_GUILD_ID")));
dpp::snowflake TEST_VC_ID(std::string(getenv("TEST_VC_ID")));
std::cout << "Test Guild ID: " << TEST_GUILD_ID << " Test VC ID: " << TEST_VC_ID << "\n\n";
dpp::cluster dave_test(t, dpp::i_default_intents, 1, 0, 1, false, dpp::cache_policy_t{ dpp::cp_none, dpp::cp_none, dpp::cp_none, dpp::cp_none, dpp::cp_none });

dave_test.on_log([&](const dpp::log_t& log) {
std::cout << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(log.severity) << ": " << log.message << std::endl;
});

dave_test.on_guild_create([&](const dpp::guild_create_t & event) {
if (event.created->id == TEST_GUILD_ID) {
dpp::discord_client* s = dave_test.get_shard(0);
s->connect_voice(TEST_GUILD_ID, TEST_VC_ID, false, false, true);
}
});
dave_test.start(false);
}
8 changes: 5 additions & 3 deletions src/dpp/discordvoiceclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,14 @@ int discord_voice_client::udp_recv(char* data, size_t max_length)

bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcode)
{
log(dpp::ll_trace, std::string("R: ") + data);
json j;

/**
* MLS frames come in as type OP_BINARY, we can also reply to them as type OP_BINARY.
*/
if (opcode == OP_BINARY && data.size() >= sizeof(dave_binary_header_t)) {

/* Debug, remove once this is working */
std::cout << dpp::utility::debug_dump((uint8_t*)(data.data()), data.length()) << "\n";
log(dpp::ll_trace, "R: " + dpp::utility::debug_dump((uint8_t*)(data.data()), data.length()));

dave_binary_header_t dave_header{};
std::memcpy(&dave_header, data.data(), sizeof(dave_binary_header_t));
Expand Down Expand Up @@ -528,6 +526,7 @@ bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcod
}

try {
log(dpp::ll_trace, std::string("R: ") + data);
j = json::parse(data);
}
catch (const std::exception &e) {
Expand Down Expand Up @@ -670,6 +669,9 @@ bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcod
send_silence(20);
}

/* Set the session id */
this->sessionid = j["d"]["media_session_id"];

/* Fire on_voice_ready */
if (!creator->on_voice_ready.empty()) {
voice_ready_t rdy(nullptr, data);
Expand Down
5 changes: 5 additions & 0 deletions src/dpp/wsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ size_t websocket_client::fill_header(unsigned char* outbuf, size_t sendlength, w

void websocket_client::write(const std::string_view data, ws_opcode _opcode)
{
if ((_opcode == OP_AUTO ? this->data_opcode : _opcode) == OP_TEXT) {
log(dpp::ll_trace, std::string("W: ") + data.data());
} else {
log(dpp::ll_trace, "W: " + dpp::utility::debug_dump((uint8_t*)(data.data()), data.length()));
}
if (state == HTTP_HEADERS) {
/* Simple write */
ssl_client::socket_write(data);
Expand Down

0 comments on commit cb418e3

Please sign in to comment.