Update Unreal example (register more callbacks, still mostly debug prints)
This commit is contained in:
parent
c053b72f58
commit
79eea99d19
4 changed files with 43 additions and 1 deletions
Binary file not shown.
|
@ -7,6 +7,7 @@
|
||||||
DEFINE_LOG_CATEGORY(Discord)
|
DEFINE_LOG_CATEGORY(Discord)
|
||||||
|
|
||||||
static UDiscordRpc* self = nullptr;
|
static UDiscordRpc* self = nullptr;
|
||||||
|
|
||||||
static void ReadyHandler()
|
static void ReadyHandler()
|
||||||
{
|
{
|
||||||
UE_LOG(Discord, Log, TEXT("Discord connected"));
|
UE_LOG(Discord, Log, TEXT("Discord connected"));
|
||||||
|
@ -53,6 +54,19 @@ static void SpectateGameHandler(const char* spectateSecret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void JoinRequestHandler(const DiscordJoinRequest* request)
|
||||||
|
{
|
||||||
|
FDiscordJoinRequestData jr;
|
||||||
|
jr.userId = ANSI_TO_TCHAR(request->userId);
|
||||||
|
jr.username = ANSI_TO_TCHAR(request->username);
|
||||||
|
jr.discriminator = ANSI_TO_TCHAR(request->discriminator);
|
||||||
|
jr.avatar = ANSI_TO_TCHAR(request->avatar);
|
||||||
|
UE_LOG(Discord, Log, TEXT("Discord join request from %s#%s"), *jr.username, *jr.discriminator);
|
||||||
|
if (self) {
|
||||||
|
self->OnJoinRequest.Broadcast(jr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UDiscordRpc::Initialize(const FString& applicationId,
|
void UDiscordRpc::Initialize(const FString& applicationId,
|
||||||
bool autoRegister,
|
bool autoRegister,
|
||||||
const FString& optionalSteamId)
|
const FString& optionalSteamId)
|
||||||
|
@ -69,6 +83,9 @@ void UDiscordRpc::Initialize(const FString& applicationId,
|
||||||
if (OnSpectate.IsBound()) {
|
if (OnSpectate.IsBound()) {
|
||||||
handlers.spectateGame = SpectateGameHandler;
|
handlers.spectateGame = SpectateGameHandler;
|
||||||
}
|
}
|
||||||
|
if (OnJoinRequest.IsBound()) {
|
||||||
|
handlers.joinRequest = JoinRequestHandler;
|
||||||
|
}
|
||||||
auto appId = StringCast<ANSICHAR>(*applicationId);
|
auto appId = StringCast<ANSICHAR>(*applicationId);
|
||||||
auto steamId = StringCast<ANSICHAR>(*optionalSteamId);
|
auto steamId = StringCast<ANSICHAR>(*optionalSteamId);
|
||||||
Discord_Initialize(
|
Discord_Initialize(
|
||||||
|
|
|
@ -9,6 +9,24 @@
|
||||||
// unreal's header tool hates clang-format
|
// unreal's header tool hates clang-format
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask to join callback data
|
||||||
|
*/
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FDiscordJoinRequestData {
|
||||||
|
GENERATED_USTRUCT_BODY()
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadOnly)
|
||||||
|
FString userId;
|
||||||
|
UPROPERTY(BlueprintReadOnly)
|
||||||
|
FString username;
|
||||||
|
UPROPERTY(BlueprintReadOnly)
|
||||||
|
FString discriminator;
|
||||||
|
UPROPERTY(BlueprintReadOnly)
|
||||||
|
FString avatar;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All);
|
DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All);
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDiscordConnected);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDiscordConnected);
|
||||||
|
@ -16,6 +34,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDiscordDisconnected, int, errorCod
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDiscordErrored, int, errorCode, const FString&, errorMessage);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDiscordErrored, int, errorCode, const FString&, errorMessage);
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordJoin, const FString&, joinSecret);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordJoin, const FString&, joinSecret);
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordSpectate, const FString&, spectateSecret);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordSpectate, const FString&, spectateSecret);
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDiscordJoinRequest, const FDiscordJoinRequestData&, joinRequest);
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
@ -119,6 +138,12 @@ public:
|
||||||
Category = "Discord")
|
Category = "Discord")
|
||||||
FDiscordSpectate OnSpectate;
|
FDiscordSpectate OnSpectate;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintAssignable,
|
||||||
|
meta = (DisplayName = "When Discord another user sends a join request",
|
||||||
|
Keywords = "Discord rpc"),
|
||||||
|
Category = "Discord")
|
||||||
|
FDiscordJoinRequest OnJoinRequest;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite,
|
UPROPERTY(BlueprintReadWrite,
|
||||||
meta = (DisplayName = "Rich presence info", Keywords = "Discord rpc"),
|
meta = (DisplayName = "Rich presence info", Keywords = "Discord rpc"),
|
||||||
Category = "Discord")
|
Category = "Discord")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"FileVersion": 3,
|
"FileVersion": 3,
|
||||||
"EngineAssociation": "4.16",
|
"EngineAssociation": "4.18",
|
||||||
"Category": "",
|
"Category": "",
|
||||||
"Description": "",
|
"Description": "",
|
||||||
"Modules": [
|
"Modules": [
|
||||||
|
|
Loading…
Reference in a new issue