Error message cb
This commit is contained in:
parent
88ab85c81e
commit
63058ddf23
3 changed files with 16 additions and 3 deletions
|
@ -32,6 +32,10 @@ static void handleDiscordDisconnected(int errcode, const char* message) {
|
|||
printf("\nDiscord: disconnected (%d: %s)\n", errcode, message);
|
||||
}
|
||||
|
||||
static void handleDiscordError(int errcode, const char* message) {
|
||||
printf("\nDiscord: error (%d: %s)\n", errcode, message);
|
||||
}
|
||||
|
||||
static void handleDiscordPresenceRequested() {
|
||||
printf("\nDiscord: requests presence\n");
|
||||
updateDiscordPresence();
|
||||
|
@ -83,6 +87,7 @@ int main() {
|
|||
memset(&handlers, 0, sizeof(handlers));
|
||||
handlers.ready = handleDiscordReady;
|
||||
handlers.disconnected = handleDiscordDisconnected;
|
||||
handlers.errored = handleDiscordError;
|
||||
handlers.presenceRequested = handleDiscordPresenceRequested;
|
||||
Discord_Initialize(APPLICATION_ID, &handlers);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct DiscordRichPresence {
|
|||
typedef struct DiscordEventHandlers {
|
||||
void (*ready)();
|
||||
void (*disconnected)(int errorCode, const char* message);
|
||||
void (*errored)(int errorCode, const char* message);
|
||||
void (*presenceRequested)();
|
||||
void (*joinGame)(const char* joinSecret);
|
||||
void (*spectateGame)(const char* spectateSecret);
|
||||
|
|
|
@ -25,6 +25,7 @@ static char ApplicationId[64]{};
|
|||
static DiscordEventHandlers Handlers{};
|
||||
static std::atomic_bool WasJustConnected{false};
|
||||
static std::atomic_bool WasJustDisconnected{false};
|
||||
static std::atomic_bool GotErrorMessage{false};
|
||||
static std::atomic_bool WasPresenceRequested{false};
|
||||
static std::atomic_bool WasJoinGame{false};
|
||||
static std::atomic_bool WasSpectateGame{false};
|
||||
|
@ -32,6 +33,8 @@ static char JoinGameSecret[256];
|
|||
static char SpectateGameSecret[256];
|
||||
static int LastErrorCode{0};
|
||||
static char LastErrorMessage[256];
|
||||
static int LastDisconnectErrorCode{0};
|
||||
static char LastDisconnectErrorMessage[256];
|
||||
static QueuedMessage SendQueue[MessageQueueSize]{};
|
||||
static std::atomic_uint SendQueueNextAdd{0};
|
||||
static std::atomic_uint SendQueueNextSend{0};
|
||||
|
@ -183,8 +186,8 @@ extern "C" void Discord_Initialize(const char* applicationId, DiscordEventHandle
|
|||
}
|
||||
};
|
||||
Connection->onDisconnect = [](int err, const char* message) {
|
||||
LastErrorCode = err;
|
||||
StringCopy(LastErrorMessage, message);
|
||||
LastDisconnectErrorCode = err;
|
||||
StringCopy(LastDisconnectErrorMessage, message);
|
||||
WasJustDisconnected.exchange(true);
|
||||
UpdateReconnectTime();
|
||||
};
|
||||
|
@ -221,8 +224,12 @@ extern "C" void Discord_UpdatePresence(const DiscordRichPresence* presence)
|
|||
|
||||
extern "C" void Discord_RunCallbacks()
|
||||
{
|
||||
if (GotErrorMessage.exchange(false) && Handlers.errored) {
|
||||
Handlers.errored(LastErrorCode, LastErrorMessage);
|
||||
}
|
||||
|
||||
if (WasJustDisconnected.exchange(false) && Handlers.disconnected) {
|
||||
Handlers.disconnected(LastErrorCode, LastErrorMessage);
|
||||
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
||||
}
|
||||
|
||||
if (WasJustConnected.exchange(false) && Handlers.ready) {
|
||||
|
|
Loading…
Reference in a new issue