discord-rpc: Formatting
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Discord_Register(const char* applicationId, const char* command);
|
void Discord_Register(const char *applicationId, const char *command);
|
||||||
void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);
|
void Discord_RegisterSteamGame(const char *applicationId, const char *steamId);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
78
3rdparty/discord-rpc/include/discord_rpc.h
vendored
78
3rdparty/discord-rpc/include/discord_rpc.h
vendored
@@ -12,63 +12,63 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct DiscordRichPresence {
|
typedef struct DiscordRichPresence {
|
||||||
int type;
|
int type;
|
||||||
const char* name; /* max 128 bytes */
|
const char *name; /* max 128 bytes */
|
||||||
const char* state; /* max 128 bytes */
|
const char *state; /* max 128 bytes */
|
||||||
const char* details; /* max 128 bytes */
|
const char *details; /* max 128 bytes */
|
||||||
int64_t startTimestamp;
|
int64_t startTimestamp;
|
||||||
int64_t endTimestamp;
|
int64_t endTimestamp;
|
||||||
const char* largeImageKey; /* max 32 bytes */
|
const char *largeImageKey; /* max 32 bytes */
|
||||||
const char* largeImageText; /* max 128 bytes */
|
const char *largeImageText; /* max 128 bytes */
|
||||||
const char* smallImageKey; /* max 32 bytes */
|
const char *smallImageKey; /* max 32 bytes */
|
||||||
const char* smallImageText; /* max 128 bytes */
|
const char *smallImageText; /* max 128 bytes */
|
||||||
const char* partyId; /* max 128 bytes */
|
const char *partyId; /* max 128 bytes */
|
||||||
int partySize;
|
int partySize;
|
||||||
int partyMax;
|
int partyMax;
|
||||||
int partyPrivacy;
|
int partyPrivacy;
|
||||||
const char* matchSecret; /* max 128 bytes */
|
const char *matchSecret; /* max 128 bytes */
|
||||||
const char* joinSecret; /* max 128 bytes */
|
const char *joinSecret; /* max 128 bytes */
|
||||||
const char* spectateSecret; /* max 128 bytes */
|
const char *spectateSecret; /* max 128 bytes */
|
||||||
int8_t instance;
|
int8_t instance;
|
||||||
} DiscordRichPresence;
|
} DiscordRichPresence;
|
||||||
|
|
||||||
typedef struct DiscordUser {
|
typedef struct DiscordUser {
|
||||||
const char* userId;
|
const char *userId;
|
||||||
const char* username;
|
const char *username;
|
||||||
const char* discriminator;
|
const char *discriminator;
|
||||||
const char* avatar;
|
const char *avatar;
|
||||||
} DiscordUser;
|
} DiscordUser;
|
||||||
|
|
||||||
typedef struct DiscordEventHandlers {
|
typedef struct DiscordEventHandlers {
|
||||||
void (*ready)(const DiscordUser* request);
|
void (*ready)(const DiscordUser *request);
|
||||||
void (*disconnected)(int errorCode, const char* message);
|
void (*disconnected)(int errorCode, const char *message);
|
||||||
void (*errored)(int errorCode, const char* message);
|
void (*errored)(int errorCode, const char *message);
|
||||||
void (*joinGame)(const char* joinSecret);
|
void (*joinGame)(const char *joinSecret);
|
||||||
void (*spectateGame)(const char* spectateSecret);
|
void (*spectateGame)(const char *spectateSecret);
|
||||||
void (*joinRequest)(const DiscordUser* request);
|
void (*joinRequest)(const DiscordUser *request);
|
||||||
} DiscordEventHandlers;
|
} DiscordEventHandlers;
|
||||||
|
|
||||||
#define DISCORD_REPLY_NO 0
|
#define DISCORD_REPLY_NO 0
|
||||||
#define DISCORD_REPLY_YES 1
|
#define DISCORD_REPLY_YES 1
|
||||||
#define DISCORD_REPLY_IGNORE 2
|
#define DISCORD_REPLY_IGNORE 2
|
||||||
#define DISCORD_PARTY_PRIVATE 0
|
#define DISCORD_PARTY_PRIVATE 0
|
||||||
#define DISCORD_PARTY_PUBLIC 1
|
#define DISCORD_PARTY_PUBLIC 1
|
||||||
|
|
||||||
void Discord_Initialize(const char* applicationId,
|
void Discord_Initialize(const char *applicationId,
|
||||||
DiscordEventHandlers* handlers,
|
DiscordEventHandlers *handlers,
|
||||||
int autoRegister,
|
int autoRegister,
|
||||||
const char* optionalSteamId);
|
const char *optionalSteamId);
|
||||||
void Discord_Shutdown(void);
|
void Discord_Shutdown(void);
|
||||||
|
|
||||||
/* checks for incoming messages, dispatches callbacks */
|
/* checks for incoming messages, dispatches callbacks */
|
||||||
void Discord_RunCallbacks(void);
|
void Discord_RunCallbacks(void);
|
||||||
|
|
||||||
void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
void Discord_UpdatePresence(const DiscordRichPresence *presence);
|
||||||
void Discord_ClearPresence(void);
|
void Discord_ClearPresence(void);
|
||||||
|
|
||||||
void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
|
void Discord_Respond(const char *userid, /* DISCORD_REPLY_ */ int reply);
|
||||||
|
|
||||||
void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
|
void Discord_UpdateHandlers(DiscordEventHandlers *handlers);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|||||||
47
3rdparty/discord-rpc/src/backoff.h
vendored
47
3rdparty/discord-rpc/src/backoff.h
vendored
@@ -8,37 +8,30 @@
|
|||||||
namespace discord_rpc {
|
namespace discord_rpc {
|
||||||
|
|
||||||
struct Backoff {
|
struct Backoff {
|
||||||
int64_t minAmount;
|
int64_t minAmount;
|
||||||
int64_t maxAmount;
|
int64_t maxAmount;
|
||||||
int64_t current;
|
int64_t current;
|
||||||
int fails;
|
int fails;
|
||||||
std::mt19937_64 randGenerator;
|
std::mt19937_64 randGenerator;
|
||||||
std::uniform_real_distribution<> randDistribution;
|
std::uniform_real_distribution<> randDistribution;
|
||||||
|
|
||||||
double rand01() { return randDistribution(randGenerator); }
|
double rand01() { return randDistribution(randGenerator); }
|
||||||
|
|
||||||
Backoff(int64_t min, int64_t max)
|
Backoff(int64_t min, int64_t max)
|
||||||
: minAmount(min)
|
: minAmount(min), maxAmount(max), current(min), fails(0), randGenerator(static_cast<uint64_t>(time(0))) {
|
||||||
, maxAmount(max)
|
}
|
||||||
, current(min)
|
|
||||||
, fails(0)
|
|
||||||
, randGenerator(static_cast<uint64_t>(time(0)))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset()
|
void reset() {
|
||||||
{
|
fails = 0;
|
||||||
fails = 0;
|
current = minAmount;
|
||||||
current = minAmount;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int64_t nextDelay()
|
int64_t nextDelay() {
|
||||||
{
|
++fails;
|
||||||
++fails;
|
int64_t delay = static_cast<int64_t>(static_cast<double>(current) * 2.0 * rand01());
|
||||||
int64_t delay = static_cast<int64_t>(static_cast<double>(current) * 2.0 * rand01());
|
current = std::min(current + delay, maxAmount);
|
||||||
current = std::min(current + delay, maxAmount);
|
return current;
|
||||||
return current;
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|||||||
2
3rdparty/discord-rpc/src/connection.h
vendored
2
3rdparty/discord-rpc/src/connection.h
vendored
@@ -19,4 +19,4 @@ struct BaseConnection {
|
|||||||
bool Read(void *data, size_t length);
|
bool Read(void *data, size_t length);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|||||||
3
3rdparty/discord-rpc/src/connection_unix.cpp
vendored
3
3rdparty/discord-rpc/src/connection_unix.cpp
vendored
@@ -118,5 +118,4 @@ bool BaseConnection::Read(void *data, size_t length) {
|
|||||||
return static_cast<size_t>(res) == length;
|
return static_cast<size_t>(res) == length;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
|||||||
1
3rdparty/discord-rpc/src/connection_win.cpp
vendored
1
3rdparty/discord-rpc/src/connection_win.cpp
vendored
@@ -123,4 +123,3 @@ bool BaseConnection::Read(void *data, size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
|||||||
@@ -44,12 +44,12 @@ extern "C" void Discord_Register(const char *applicationId, const char *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr char desktopFileFormat[] = "[Desktop Entry]\n"
|
constexpr char desktopFileFormat[] = "[Desktop Entry]\n"
|
||||||
"Name=Game %s\n"
|
"Name=Game %s\n"
|
||||||
"Exec=%s %%u\n" // note: it really wants that %u in there
|
"Exec=%s %%u\n" // note: it really wants that %u in there
|
||||||
"Type=Application\n"
|
"Type=Application\n"
|
||||||
"NoDisplay=true\n"
|
"NoDisplay=true\n"
|
||||||
"Categories=Discord;Games;\n"
|
"Categories=Discord;Games;\n"
|
||||||
"MimeType=x-scheme-handler/discord-%s;\n";
|
"MimeType=x-scheme-handler/discord-%s;\n";
|
||||||
char desktopFile[2048];
|
char desktopFile[2048];
|
||||||
int fileLen = snprintf(
|
int fileLen = snprintf(
|
||||||
desktopFile, sizeof(desktopFile), desktopFileFormat, applicationId, command, applicationId);
|
desktopFile, sizeof(desktopFile), desktopFileFormat, applicationId, command, applicationId);
|
||||||
@@ -101,4 +101,3 @@ extern "C" void Discord_RegisterSteamGame(const char *applicationId,
|
|||||||
sprintf(command, "xdg-open steam://rungameid/%s", steamId);
|
sprintf(command, "xdg-open steam://rungameid/%s", steamId);
|
||||||
Discord_Register(applicationId, command);
|
Discord_Register(applicationId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "discord_register.h"
|
#include "discord_register.h"
|
||||||
|
|
||||||
static void RegisterCommand(const char* applicationId, const char* command)
|
static void RegisterCommand(const char *applicationId, const char *command)
|
||||||
{
|
{
|
||||||
// There does not appear to be a way to register arbitrary commands on OSX, so instead we'll save the command
|
// There does not appear to be a way to register arbitrary commands on OSX, so instead we'll save the command
|
||||||
// to a file in the Discord config path, and when it is needed, Discord can try to load the file there, open
|
// to a file in the Discord config path, and when it is needed, Discord can try to load the file there, open
|
||||||
@@ -29,7 +29,7 @@ static void RegisterCommand(const char* applicationId, const char* command)
|
|||||||
[jsonBuffer writeToFile:path atomically:NO encoding:NSUTF8StringEncoding error:nil];
|
[jsonBuffer writeToFile:path atomically:NO encoding:NSUTF8StringEncoding error:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RegisterURL(const char* applicationId)
|
static void RegisterURL(const char *applicationId)
|
||||||
{
|
{
|
||||||
char url[256];
|
char url[256];
|
||||||
snprintf(url, sizeof(url), "discord-%s", applicationId);
|
snprintf(url, sizeof(url), "discord-%s", applicationId);
|
||||||
@@ -59,7 +59,7 @@ static void RegisterURL(const char* applicationId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Discord_Register(const char* applicationId, const char* command)
|
void Discord_Register(const char *applicationId, const char *command)
|
||||||
{
|
{
|
||||||
if (command) {
|
if (command) {
|
||||||
RegisterCommand(applicationId, command);
|
RegisterCommand(applicationId, command);
|
||||||
@@ -72,7 +72,7 @@ void Discord_Register(const char* applicationId, const char* command)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Discord_RegisterSteamGame(const char* applicationId, const char* steamId)
|
void Discord_RegisterSteamGame(const char *applicationId, const char *steamId)
|
||||||
{
|
{
|
||||||
char command[256];
|
char command[256];
|
||||||
snprintf(command, 256, "steam://rungameid/%s", steamId);
|
snprintf(command, 256, "steam://rungameid/%s", steamId);
|
||||||
|
|||||||
@@ -180,4 +180,3 @@ extern "C" void Discord_RegisterSteamGame(const char *applicationId,
|
|||||||
|
|
||||||
Discord_RegisterW(appId, command);
|
Discord_RegisterW(appId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
3rdparty/discord-rpc/src/discord_rpc.cpp
vendored
4
3rdparty/discord-rpc/src/discord_rpc.cpp
vendored
@@ -346,8 +346,7 @@ extern "C" void Discord_Shutdown(void) {
|
|||||||
extern "C" void Discord_UpdatePresence(const DiscordRichPresence *presence) {
|
extern "C" void Discord_UpdatePresence(const DiscordRichPresence *presence) {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(PresenceMutex);
|
std::lock_guard<std::mutex> guard(PresenceMutex);
|
||||||
QueuedPresence.length = JsonWriteRichPresenceObj(
|
QueuedPresence.length = JsonWriteRichPresenceObj(QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence);
|
||||||
QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence);
|
|
||||||
UpdatePresence.exchange(true);
|
UpdatePresence.exchange(true);
|
||||||
}
|
}
|
||||||
SignalIOActivity();
|
SignalIOActivity();
|
||||||
@@ -476,4 +475,3 @@ extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
|||||||
44
3rdparty/discord-rpc/src/msg_queue.h
vendored
44
3rdparty/discord-rpc/src/msg_queue.h
vendored
@@ -7,34 +7,32 @@
|
|||||||
|
|
||||||
namespace discord_rpc {
|
namespace discord_rpc {
|
||||||
|
|
||||||
template <typename ElementType, std::size_t QueueSize>
|
template<typename ElementType, std::size_t QueueSize>
|
||||||
class MsgQueue {
|
class MsgQueue {
|
||||||
ElementType queue_[QueueSize];
|
ElementType queue_[QueueSize];
|
||||||
std::atomic_uint nextAdd_{0};
|
std::atomic_uint nextAdd_ { 0 };
|
||||||
std::atomic_uint nextSend_{0};
|
std::atomic_uint nextSend_ { 0 };
|
||||||
std::atomic_uint pendingSends_{0};
|
std::atomic_uint pendingSends_ { 0 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MsgQueue() {}
|
MsgQueue() {}
|
||||||
|
|
||||||
ElementType* GetNextAddMessage()
|
ElementType *GetNextAddMessage() {
|
||||||
{
|
// if we are falling behind, bail
|
||||||
// if we are falling behind, bail
|
if (pendingSends_.load() >= QueueSize) {
|
||||||
if (pendingSends_.load() >= QueueSize) {
|
return nullptr;
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto index = (nextAdd_++) % QueueSize;
|
|
||||||
return &queue_[index];
|
|
||||||
}
|
}
|
||||||
void CommitAdd() { ++pendingSends_; }
|
auto index = (nextAdd_++) % QueueSize;
|
||||||
|
return &queue_[index];
|
||||||
|
}
|
||||||
|
void CommitAdd() { ++pendingSends_; }
|
||||||
|
|
||||||
bool HavePendingSends() const { return pendingSends_.load() != 0; }
|
bool HavePendingSends() const { return pendingSends_.load() != 0; }
|
||||||
ElementType* GetNextSendMessage()
|
ElementType *GetNextSendMessage() {
|
||||||
{
|
auto index = (nextSend_++) % QueueSize;
|
||||||
auto index = (nextSend_++) % QueueSize;
|
return &queue_[index];
|
||||||
return &queue_[index];
|
}
|
||||||
}
|
void CommitSend() { --pendingSends_; }
|
||||||
void CommitSend() { --pendingSends_; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|||||||
1
3rdparty/discord-rpc/src/rpc_connection.cpp
vendored
1
3rdparty/discord-rpc/src/rpc_connection.cpp
vendored
@@ -130,4 +130,3 @@ bool RpcConnection::Read(JsonDocument &message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
|||||||
1
3rdparty/discord-rpc/src/rpc_connection.h
vendored
1
3rdparty/discord-rpc/src/rpc_connection.h
vendored
@@ -61,4 +61,3 @@ struct RpcConnection {
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
|||||||
1
3rdparty/discord-rpc/src/serialization.cpp
vendored
1
3rdparty/discord-rpc/src/serialization.cpp
vendored
@@ -246,4 +246,3 @@ size_t JsonWriteJoinReply(char *dest, size_t maxLen, const char *userId, int rep
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user