/ include / discord_rpc.h
discord_rpc.h
 1  #pragma once
 2  #include <stdint.h>
 3  
 4  // clang-format off
 5  
 6  #if defined(DISCORD_DYNAMIC_LIB)
 7  #  if defined(_WIN32)
 8  #    if defined(DISCORD_BUILDING_SDK)
 9  #      define DISCORD_EXPORT __declspec(dllexport)
10  #    else
11  #      define DISCORD_EXPORT __declspec(dllimport)
12  #    endif
13  #  else
14  #    define DISCORD_EXPORT __attribute__((visibility("default")))
15  #  endif
16  #else
17  #  define DISCORD_EXPORT
18  #endif
19  
20  // clang-format on
21  
22  #ifdef __cplusplus
23  extern "C" {
24  #endif
25  
26  typedef struct DiscordRichPresence {
27      const char* state;   /* max 128 bytes */
28      const char* details; /* max 128 bytes */
29      int64_t startTimestamp;
30      int64_t endTimestamp;
31      const char* largeImageKey;  /* max 32 bytes */
32      const char* largeImageText; /* max 128 bytes */
33      const char* smallImageKey;  /* max 32 bytes */
34      const char* smallImageText; /* max 128 bytes */
35      const char* partyId;        /* max 128 bytes */
36      int partySize;
37      int partyMax;
38      int partyPrivacy;
39      const char* matchSecret;    /* max 128 bytes */
40      const char* joinSecret;     /* max 128 bytes */
41      const char* spectateSecret; /* max 128 bytes */
42      int8_t instance;
43  } DiscordRichPresence;
44  
45  typedef struct DiscordUser {
46      const char* userId;
47      const char* username;
48      const char* discriminator;
49      const char* avatar;
50  } DiscordUser;
51  
52  typedef struct DiscordEventHandlers {
53      void (*ready)(const DiscordUser* request);
54      void (*disconnected)(int errorCode, const char* message);
55      void (*errored)(int errorCode, const char* message);
56      void (*joinGame)(const char* joinSecret);
57      void (*spectateGame)(const char* spectateSecret);
58      void (*joinRequest)(const DiscordUser* request);
59  } DiscordEventHandlers;
60  
61  #define DISCORD_REPLY_NO 0
62  #define DISCORD_REPLY_YES 1
63  #define DISCORD_REPLY_IGNORE 2
64  #define DISCORD_PARTY_PRIVATE 0
65  #define DISCORD_PARTY_PUBLIC 1
66  
67  DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
68                                         DiscordEventHandlers* handlers,
69                                         int autoRegister,
70                                         const char* optionalSteamId);
71  DISCORD_EXPORT void Discord_Shutdown(void);
72  
73  /* checks for incoming messages, dispatches callbacks */
74  DISCORD_EXPORT void Discord_RunCallbacks(void);
75  
76  /* If you disable the lib starting its own io thread, you'll need to call this from your own */
77  #ifdef DISCORD_DISABLE_IO_THREAD
78  DISCORD_EXPORT void Discord_UpdateConnection(void);
79  #endif
80  
81  DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
82  DISCORD_EXPORT void Discord_ClearPresence(void);
83  
84  DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
85  
86  DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
87  
88  #ifdef __cplusplus
89  } /* extern "C" */
90  #endif