discord-rpc/src/discord-rpc.cpp

41 lines
1 KiB
C++
Raw Normal View History

2017-06-30 23:18:54 +00:00
#include "discord-rpc.h"
#include "connection.h"
#include "yolojson.h"
static RpcConnection* MyConnection = nullptr;
static char ApplicationId[64]{};
static DiscordEventHandlers Handlers{};
void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers)
{
StringCopy(ApplicationId, applicationId, sizeof(ApplicationId));
if (handlers) {
Handlers = *handlers;
}
else {
Handlers = {};
}
MyConnection = RpcConnection::Create();
MyConnection->onConnect = Handlers.ready;
MyConnection->onDisconnect = Handlers.disconnected;
2017-06-30 23:18:54 +00:00
MyConnection->Open();
}
void Discord_Shutdown()
{
Handlers = {};
MyConnection->Close();
RpcConnection::Destroy(MyConnection);
}
void Discord_UpdatePresence(const DiscordRichPresence* presence)
{
auto frame = MyConnection->GetNextFrame();
char* jsonWrite = frame->message;
JsonWriteRichPresenceObj(jsonWrite, presence);
frame->length = sizeof(uint32_t) + (jsonWrite - frame->message);
MyConnection->WriteFrame(frame);
}