From 6dc12b82c62f805f33a53003e886ee14c0c87a3c Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Wed, 16 Aug 2017 13:44:30 -0700 Subject: [PATCH] Actually hook up callbacks --- .../Private/DiscordRpcBlueprint.cpp | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp b/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp index 08d5746..9c394c3 100644 --- a/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp +++ b/examples/unrealstatus/Plugins/discordrpc/Source/discordrpc/Private/DiscordRpcBlueprint.cpp @@ -7,7 +7,8 @@ DEFINE_LOG_CATEGORY(Discord) static UDiscordRpc* self = nullptr; -static void ReadyHandler() { +static void ReadyHandler() +{ UE_LOG(Discord, Log, TEXT("Discord connected")); if (self) { self->IsConnected = true; @@ -15,14 +16,42 @@ static void ReadyHandler() { } } -static void DisconnectHandler(int errorCode, const char* message) { +static void DisconnectHandler(int errorCode, const char* message) +{ auto msg = FString(message); UE_LOG(Discord, Log, TEXT("Discord disconnected (%d): %s"), errorCode, *msg); if (self) { self->IsConnected = false; self->OnDisconnected.Broadcast(errorCode, msg); } -}; +} + +static void ErroredHandler(int errorCode, const char* message) +{ + auto msg = FString(message); + UE_LOG(Discord, Log, TEXT("Discord error (%d): %s"), errorCode, *msg); + if (self) { + self->OnErrored.Broadcast(errorCode, msg); + } +} + +static void JoinGameHandler(const char* joinSecret) +{ + auto secret = FString(joinSecret); + UE_LOG(Discord, Log, TEXT("Discord join %s"), *secret); + if (self) { + self->OnJoin.Broadcast(secret); + } +} + +static void SpectateGameHandler(const char* spectateSecret) +{ + auto secret = FString(spectateSecret); + UE_LOG(Discord, Log, TEXT("Discord spectate %s"), *secret); + if (self) { + self->OnSpectate.Broadcast(secret); + } +} void UDiscordRpc::Initialize(const FString& applicationId, bool autoRegister) { @@ -31,6 +60,13 @@ void UDiscordRpc::Initialize(const FString& applicationId, bool autoRegister) DiscordEventHandlers handlers{}; handlers.ready = ReadyHandler; handlers.disconnected = DisconnectHandler; + handlers.errored = ErroredHandler; + if (OnJoin.IsBound()) { + handlers.joinGame = JoinGameHandler; + } + if (OnSpectate.IsBound()) { + handlers.spectateGame = SpectateGameHandler; + } auto appId = StringCast(*applicationId); Discord_Initialize((const char*)appId.Get(), &handlers, autoRegister); }