Skip to content

Commit

Permalink
Add shutdown function, fix encoding issues in username
Browse files Browse the repository at this point in the history
  • Loading branch information
dyanikoglu committed Jan 9, 2021
1 parent 5cbd929 commit 7ca93ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Source/DiscordGameSDK/Private/DiscordHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DEFINE_LOG_CATEGORY_STATIC(LogDiscord, All, All)
static discord::Core* Core = nullptr;


bool UDiscordHelper::Initialize(int64 ClientID, bool bDiscordRequired)
bool UDiscordHelper::InitializeDiscordInstance(int64 ClientID, bool bDiscordRequired)
{
// https://discordapp.com/developers/docs/game-sdk/sdk-starter-guide#code-primer-unreal-engine-4-cpp
const discord::Result Result = discord::Core::Create(ClientID, bDiscordRequired ? DiscordCreateFlags_Default : DiscordCreateFlags_NoRequireDiscord, &Core);
Expand All @@ -30,7 +30,7 @@ bool UDiscordHelper::Initialize(int64 ClientID, bool bDiscordRequired)
const discord::Result UserResult = Core->UserManager().GetCurrentUser(&CurrentUser);
if (UserResult == discord::Result::Ok)
{
OnUserConnected.Broadcast(CurrentUser.GetUsername(), CurrentUser.GetId(), CurrentUser.GetDiscriminator());
OnUserConnected.Broadcast(UTF8_TO_TCHAR(CurrentUser.GetUsername()), CurrentUser.GetId(), CurrentUser.GetDiscriminator());
}
}
};
Expand All @@ -41,6 +41,14 @@ bool UDiscordHelper::Initialize(int64 ClientID, bool bDiscordRequired)
return true;
}

void UDiscordHelper::DestroyDiscordInstance()
{
if (Core)
{
delete Core;
}
}

bool UDiscordHelper::RunCallbacks() const
{
if (Core)
Expand Down
3 changes: 2 additions & 1 deletion Source/DiscordGameSDK/Public/DiscordHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class DISCORDGAMESDK_API UDiscordHelper : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
bool Initialize(int64 ClientID, bool bDiscordRequired = false);
bool InitializeDiscordInstance(int64 ClientID, bool bDiscordRequired = false);
void DestroyDiscordInstance();
bool RunCallbacks() const;

//
Expand Down

0 comments on commit 7ca93ec

Please sign in to comment.