add Discord_ClearPresence() (#104)

send-presence example updated - start a line with 'c' to toggle
whether presence information is sent or not.

Added ClearPresence to .cs bindings

Added ClearPresence to UE4 blueprint class.
This commit is contained in:
Ben Morse 2018-01-05 15:17:23 -08:00 committed by GitHub
parent b0e31a9e25
commit 6a59509b7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 18 deletions

View file

@ -78,6 +78,9 @@ public class DiscordRpc
[DllImport("discord-rpc", EntryPoint = "Discord_UpdatePresence", CallingConvention = CallingConvention.Cdecl)]
public static extern void UpdatePresence(ref RichPresence presence);
[DllImport("discord-rpc", EntryPoint = "Discord_ClearPresence", CallingConvention = CallingConvention.Cdecl)]
public static extern void ClearPresence();
[DllImport("discord-rpc", EntryPoint = "Discord_Respond", CallingConvention = CallingConvention.Cdecl)]
public static extern void Respond(string userId, Reply reply);
}

View file

@ -14,6 +14,7 @@
static const char* APPLICATION_ID = "345229890980937739";
static int FrustrationLevel = 0;
static int64_t StartTime;
static int SendPresence = 1;
static int prompt(char* line, size_t size)
{
@ -32,6 +33,7 @@ static int prompt(char* line, size_t size)
static void updateDiscordPresence()
{
if (SendPresence) {
char buffer[256];
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));
@ -50,6 +52,9 @@ static void updateDiscordPresence()
discordPresence.spectateSecret = "look";
discordPresence.instance = 0;
Discord_UpdatePresence(&discordPresence);
} else {
Discord_ClearPresence();
}
}
static void handleDiscordReady()
@ -143,6 +148,18 @@ static void gameLoop()
continue;
}
if (line[0] == 'c') {
if (SendPresence) {
printf("Clearing presence information.\n");
SendPresence = 0;
} else {
printf("Restoring presence information.\n");
SendPresence = 1;
}
updateDiscordPresence();
continue;
}
if (line[0] == 'y') {
printf("Reinit Discord.\n");
discordInit();

View file

@ -145,3 +145,8 @@ void UDiscordRpc::UpdatePresence()
Discord_UpdatePresence(&rp);
}
void UDiscordRpc::ClearPresence()
{
Discord_ClearPresence();
}

View file

@ -108,6 +108,11 @@ public:
Category = "Discord")
void UpdatePresence();
UFUNCTION(BlueprintCallable,
meta = (DisplayName = "Clear presence", Keywords = "Discord rpc"),
Category = "Discord")
void ClearPresence();
UPROPERTY(BlueprintReadOnly,
meta = (DisplayName = "Is Discord connected", Keywords = "Discord rpc"),
Category = "Discord")

View file

@ -76,6 +76,7 @@ DISCORD_EXPORT void Discord_UpdateConnection(void);
#endif
DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
DISCORD_EXPORT void Discord_ClearPresence();
DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);

View file

@ -325,6 +325,11 @@ extern "C" DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence*
SignalIOActivity();
}
extern "C" DISCORD_EXPORT void Discord_ClearPresence()
{
Discord_UpdatePresence(nullptr);
}
extern "C" DISCORD_EXPORT void Discord_Respond(const char* userId, /* DISCORD_REPLY_ */ int reply)
{
// if we are not connected, let's not batch up stale messages for later

View file

@ -102,6 +102,7 @@ size_t JsonWriteRichPresenceObj(char* dest,
WriteKey(writer, "pid");
writer.Int(pid);
if (presence != nullptr)
{
WriteObject activity(writer, "activity");