Skip to content

Commit 4db2240

Browse files
committed
Persist and move the voice connections on shard reconnection.
1 parent 74b3865 commit 4db2240

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/dpp/discordclient.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ class DPP_EXPORT voiceconn {
232232
* @return reference to self
233233
*/
234234
voiceconn& disconnect();
235+
236+
/**
237+
* @brief Reassigns the owner to the given discord_client.
238+
*/
239+
void reassign_owner(class discord_client* o);
235240
};
236241

237242
/** @brief Implements a discord client. Each discord_client connects to one shard and derives from a websocket client. */

src/dpp/discordclient.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <thread>
2929
#include <dpp/json.h>
3030
#include <dpp/etf.h>
31+
#include <utility>
3132

3233
#define PATH_UNCOMPRESSED_JSON "/?v=" DISCORD_API_VERSION "&encoding=json"
3334
#define PATH_COMPRESSED_JSON "/?v=" DISCORD_API_VERSION "&encoding=json&compress=zlib-stream"
@@ -72,8 +73,12 @@ discord_client::discord_client(discord_client &old, uint64_t sequence, const std
7273
ready(false),
7374
last_heartbeat_ack(time(nullptr)),
7475
protocol(old.protocol),
76+
connecting_voice_channels(std::move(old.connecting_voice_channels)),
7577
resume_gateway_url(old.resume_gateway_url)
7678
{
79+
for (auto& [shard_id, vconn] : connecting_voice_channels) {
80+
vconn->reassign_owner(this);
81+
}
7782
start_connecting();
7883
}
7984

@@ -615,5 +620,8 @@ voiceconn& voiceconn::connect(snowflake guild_id) {
615620
return *this;
616621
}
617622

623+
void voiceconn::reassign_owner(discord_client* o) {
624+
creator = o;
625+
}
618626

619627
}

0 commit comments

Comments
 (0)