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:
parent
b0e31a9e25
commit
6a59509b7b
7 changed files with 55 additions and 18 deletions
|
@ -78,6 +78,9 @@ public class DiscordRpc
|
||||||
[DllImport("discord-rpc", EntryPoint = "Discord_UpdatePresence", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("discord-rpc", EntryPoint = "Discord_UpdatePresence", CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void UpdatePresence(ref RichPresence presence);
|
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)]
|
[DllImport("discord-rpc", EntryPoint = "Discord_Respond", CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void Respond(string userId, Reply reply);
|
public static extern void Respond(string userId, Reply reply);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
static const char* APPLICATION_ID = "345229890980937739";
|
static const char* APPLICATION_ID = "345229890980937739";
|
||||||
static int FrustrationLevel = 0;
|
static int FrustrationLevel = 0;
|
||||||
static int64_t StartTime;
|
static int64_t StartTime;
|
||||||
|
static int SendPresence = 1;
|
||||||
|
|
||||||
static int prompt(char* line, size_t size)
|
static int prompt(char* line, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +33,7 @@ static int prompt(char* line, size_t size)
|
||||||
|
|
||||||
static void updateDiscordPresence()
|
static void updateDiscordPresence()
|
||||||
{
|
{
|
||||||
|
if (SendPresence) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
DiscordRichPresence discordPresence;
|
DiscordRichPresence discordPresence;
|
||||||
memset(&discordPresence, 0, sizeof(discordPresence));
|
memset(&discordPresence, 0, sizeof(discordPresence));
|
||||||
|
@ -50,6 +52,9 @@ static void updateDiscordPresence()
|
||||||
discordPresence.spectateSecret = "look";
|
discordPresence.spectateSecret = "look";
|
||||||
discordPresence.instance = 0;
|
discordPresence.instance = 0;
|
||||||
Discord_UpdatePresence(&discordPresence);
|
Discord_UpdatePresence(&discordPresence);
|
||||||
|
} else {
|
||||||
|
Discord_ClearPresence();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleDiscordReady()
|
static void handleDiscordReady()
|
||||||
|
@ -143,6 +148,18 @@ static void gameLoop()
|
||||||
continue;
|
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') {
|
if (line[0] == 'y') {
|
||||||
printf("Reinit Discord.\n");
|
printf("Reinit Discord.\n");
|
||||||
discordInit();
|
discordInit();
|
||||||
|
|
|
@ -145,3 +145,8 @@ void UDiscordRpc::UpdatePresence()
|
||||||
|
|
||||||
Discord_UpdatePresence(&rp);
|
Discord_UpdatePresence(&rp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UDiscordRpc::ClearPresence()
|
||||||
|
{
|
||||||
|
Discord_ClearPresence();
|
||||||
|
}
|
||||||
|
|
|
@ -108,6 +108,11 @@ public:
|
||||||
Category = "Discord")
|
Category = "Discord")
|
||||||
void UpdatePresence();
|
void UpdatePresence();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable,
|
||||||
|
meta = (DisplayName = "Clear presence", Keywords = "Discord rpc"),
|
||||||
|
Category = "Discord")
|
||||||
|
void ClearPresence();
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly,
|
UPROPERTY(BlueprintReadOnly,
|
||||||
meta = (DisplayName = "Is Discord connected", Keywords = "Discord rpc"),
|
meta = (DisplayName = "Is Discord connected", Keywords = "Discord rpc"),
|
||||||
Category = "Discord")
|
Category = "Discord")
|
||||||
|
|
|
@ -76,6 +76,7 @@ DISCORD_EXPORT void Discord_UpdateConnection(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
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);
|
DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
|
||||||
|
|
||||||
|
|
|
@ -325,6 +325,11 @@ extern "C" DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence*
|
||||||
SignalIOActivity();
|
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)
|
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
|
// if we are not connected, let's not batch up stale messages for later
|
||||||
|
|
|
@ -102,6 +102,7 @@ size_t JsonWriteRichPresenceObj(char* dest,
|
||||||
WriteKey(writer, "pid");
|
WriteKey(writer, "pid");
|
||||||
writer.Int(pid);
|
writer.Int(pid);
|
||||||
|
|
||||||
|
if (presence != nullptr)
|
||||||
{
|
{
|
||||||
WriteObject activity(writer, "activity");
|
WriteObject activity(writer, "activity");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue