iw5-mod/src/module/discord.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

2019-01-06 13:02:57 -05:00
#include <std_include.hpp>
#include <discord_rpc.h>
#include "loader/module_loader.hpp"
#include "scheduler.hpp"
2019-01-06 14:52:51 -05:00
#include "game/game.hpp"
2019-01-06 13:02:57 -05:00
class discord final : public module
{
public:
void post_load() override
{
2019-01-06 14:52:51 -05:00
if (game::is_dedi()) return;
2019-01-06 13:02:57 -05:00
DiscordEventHandlers handlers;
ZeroMemory(&handlers, sizeof(handlers));
handlers.ready = ready;
handlers.errored = errored;
handlers.disconnected = errored;
handlers.joinGame = nullptr;
handlers.spectateGame = nullptr;
handlers.joinRequest = nullptr;
Discord_Initialize("531526691319971880", &handlers, 1, nullptr);
scheduler::on_frame(Discord_RunCallbacks);
}
void pre_destroy() override
{
Discord_Shutdown();
}
private:
static void ready(const DiscordUser* request)
{
DiscordRichPresence discord_presence;
ZeroMemory(&discord_presence, sizeof(discord_presence));
2019-01-06 14:52:51 -05:00
discord_presence.state = game::is_mp() ? "Multiplayer" : "Singleplayer";
2019-01-06 13:02:57 -05:00
discord_presence.instance = 1;
Discord_UpdatePresence(&discord_presence);
}
2019-01-06 14:52:51 -05:00
static void errored(const int error_code, const char* message)
2019-01-06 13:02:57 -05:00
{
printf("Discord: (%i) %s", error_code, message);
}
};
2019-01-06 14:56:36 -05:00
//REGISTER_MODULE(discord)