RetroArch
|
Discord's Rich Presence feature is designed as an obfuscated addition to our existing RPC infrastructure. The standalone library and header files make it easy for any dev to drop it into their game.
Our library communicates with Discord over the local Discord RPC socket. We've already done the work in connecting properly, handling disconnects and reconnects, and other RPC intracacies, but those who have done this implementation for our private alpha Voice and Chat SDK can simply make use of the new RPC commands and events to implement Rich Presence.
By committing to an RPC-only integration, you decide to forego the work our library and header file have done for you in the way of error handling, state storage, disconnecting and reconnecting, and other quality of life abstractions. While simply implementing the new RPC command and events will enable Rich Presence for your game, we highly suggest that you do your best to mimic the functionality of the SDK the most that you can. It ensure not only code quality on your part, but also an excellent experience on the part of your players.
One thing that cannot be explicitly done over RPC is registering an application protocol for your game. If you choose to do an RPC-only implementation, you will have to register your application protocol yourself in the format of discord-[your_app_id]://
. You can use Discord_Register()
as a good(?) example of how to properly register an application protocol for use with Discord. For OSX and Linux it is probably simpler to handle the protocol registration as part of your install/packaging.
The new RPC command for Rich Presence is SET_ACTIVITY
. The fields are similar to what is outlined in the SDK; we've combined similar fields into objects for the sake of less data on the wire.
The one major difference is the party.size
field. It is an array with a size of two. The first element is the current party size, partySize
from the main documentation. The second element is the maximum party size, partyMax
from the main documentation.
Below is a full example of a SET_ACTIVITY
command. Field restrictions like size are the same as outlined in the main documentation.
The three new RPC events for Rich Presence power the ability to join and spectate your friends' games.
First is the ACTIVITY_JOIN
event:
Second is the ACTIVITY_SPECTATE
event:
And third is the ACTIVITY_JOIN_REQUEST
event:
In order to receive these events, you need to subscribe to them like so:
To unsubscribe from these events, resend with the command UNSUBSCRIBE
A discord user will request access to the game. If the ACTIVITY_JOIN_REQUEST has been subscribed too, the ACTIVITY_JOIN_REQUEST event will be sent to the host's game. Accept it with following model:
To reject the request, use CLOSE_ACTIVITY_REQUEST
:
Here are just some quick notes to help with some common troubleshooting problems.
stream.Write(opcode);
stream.Write(length);
as it will break the pipe. Instead create a buffer, write the data to the buffer, then send the entire buffer to the stream.discord-ipc-0
to discord-ipc-9
. It is a good idea to try and connect to each one and keeping the first one you connect too. For multiple clients (eg Discord and Canary), you might want to add a feature to manually select the pipe so you can more easily debug the application.lower_snake_case
.Little Endian Unsigned Integers (32bits)
. In some languages, you must convert them as they can be architecture specific.