Skip to content

Commit

Permalink
ACTUALLY register the handlers on init
Browse files Browse the repository at this point in the history
  • Loading branch information
msciotti committed Mar 29, 2018
1 parent c70acbe commit be8a8e9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/discord_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct JoinRequest {
};

static RpcConnection* Connection{nullptr};
static DiscordEventHandlers QueuedHandlers{};
static DiscordEventHandlers Handlers{};
static std::atomic_bool WasJustConnected{false};
static std::atomic_bool WasJustDisconnected{false};
Expand Down Expand Up @@ -282,12 +283,16 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,

{
std::lock_guard<std::mutex> guard(HandlerMutex);

if (handlers) {
Handlers = *handlers;
QueuedHandlers = *handlers;
}
else {
Handlers = {};
QueuedHandlers = {};
}

Handlers = {};

}

if (Connection) {
Expand All @@ -296,13 +301,17 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,

Connection = RpcConnection::Create(applicationId);
Connection->onConnect = []() {
Discord_UpdateHandlers(&Handlers);
Discord_UpdateHandlers(&QueuedHandlers);
WasJustConnected.exchange(true);
ReconnectTimeMs.reset();
};
Connection->onDisconnect = [](int err, const char* message) {
LastDisconnectErrorCode = err;
StringCopy(LastDisconnectErrorMessage, message);
{
std::lock_guard<std::mutex> guard(HandlerMutex);
Handlers = {};
}
WasJustDisconnected.exchange(true);
UpdateReconnectTime();
};
Expand Down

0 comments on commit be8a8e9

Please sign in to comment.