From 6ea9c46f7746b0a7fbf0b8a1204f4e89e73c6ec3 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Thu, 20 Jul 2017 15:59:15 -0700 Subject: [PATCH] Rename a thing --- CMakeLists.txt | 2 +- README.md | 21 +++++++++++++++++-- examples/send-presence/CMakeLists.txt | 3 +++ .../send-presence.c} | 0 examples/simple/CMakeLists.txt | 3 --- include/discord-rpc.h | 3 ++- src/discord-rpc.cpp | 13 ++++++++++++ src/serialization.h | 1 + 8 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 examples/send-presence/CMakeLists.txt rename examples/{simple/simple.c => send-presence/send-presence.c} (100%) delete mode 100644 examples/simple/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 29ee58f..c2de1a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,4 +22,4 @@ endif(NOT RAPIDJSON) add_library(rapidjson STATIC IMPORTED ${RAPIDJSON}) add_subdirectory(src) -add_subdirectory(examples/simple) +add_subdirectory(examples/send-presence) diff --git a/README.md b/README.md index d696147..a7d117f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,25 @@ -Discord RPC Sample -================== +# Discord RPC This is a lib and a couple of quick demos, one that implements the very minimal subset to show current status, and one that is more complete. The idea here is to give you an lib that implements the rpc connection and wraps sending events, and a basic example that uses it; you can use the lib directly if you like, or use it as a guide to writing your own if it doesn't suit your game as is. +PRs/feedback welcome if you have an improvement everyone might want. + +## Usage + +There's a CMake file that should be able to generate the lib for you; I use it like this: +``` + cd /path/to/discord-rpc + mkdir build + cd build + cmake .. + cmake --build . +``` +Sometimes I use the generated project files. + +## Sample: send-presence + +This is a text adventure "game" that inits/deinits the connection to Discord, and sends a presence +update on each command. diff --git a/examples/send-presence/CMakeLists.txt b/examples/send-presence/CMakeLists.txt new file mode 100644 index 0000000..b13cb2e --- /dev/null +++ b/examples/send-presence/CMakeLists.txt @@ -0,0 +1,3 @@ +include_directories(${PROJECT_SOURCE_DIR}/include) +add_executable(send-presence send-presence.c) +target_link_libraries(send-presence discord-rpc) diff --git a/examples/simple/simple.c b/examples/send-presence/send-presence.c similarity index 100% rename from examples/simple/simple.c rename to examples/send-presence/send-presence.c diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt deleted file mode 100644 index e891682..0000000 --- a/examples/simple/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -include_directories(${PROJECT_SOURCE_DIR}/include) -add_executable(simple-client simple.c) -target_link_libraries(simple-client discord-rpc) diff --git a/include/discord-rpc.h b/include/discord-rpc.h index a6e45e2..6166811 100644 --- a/include/discord-rpc.h +++ b/include/discord-rpc.h @@ -35,7 +35,6 @@ typedef struct DiscordEventHandlers { void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers); void Discord_Shutdown(); -void Discord_UpdatePresence(const DiscordRichPresence* presence); /* checks for incoming messages, dispatches callbacks */ void Discord_RunCallbacks(); @@ -45,6 +44,8 @@ void Discord_RunCallbacks(); void Discord_UpdateConnection(); #endif +void Discord_UpdatePresence(const DiscordRichPresence* presence); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/discord-rpc.cpp b/src/discord-rpc.cpp index a71e4b1..d3b3329 100644 --- a/src/discord-rpc.cpp +++ b/src/discord-rpc.cpp @@ -78,6 +78,19 @@ extern "C" void Discord_UpdateConnection() while (Connection->Read(message)) { // todo: do something... printf("Hey, I got a message\n"); + + // expect cmd, data, evt, nonce here? + + /* + message.FindMember("cmd"); + message.FindMember("data"); + message.FindMember("evt"); + message.FindMember("nonce"); // in responses only + + void(*presenceRequested)(); + void(*joinGame)(const char* joinSecret); + void(*spectateGame)(const char* spectateSecret); + */ } // writes diff --git a/src/serialization.h b/src/serialization.h index b736a1a..f829eb4 100644 --- a/src/serialization.h +++ b/src/serialization.h @@ -19,6 +19,7 @@ inline size_t StringCopy(char (&dest)[Len], const char* src) { size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char* applicationId); +// Commands struct DiscordRichPresence; size_t JsonWriteRichPresenceObj(char* dest, size_t maxLen, int nonce, int pid, const DiscordRichPresence* presence);