Add discord rpc

This commit is contained in:
momo5502 2020-10-04 19:53:28 +02:00
parent 74fd8e8b3b
commit 7a5bf83629
4 changed files with 94 additions and 0 deletions

3
.gitmodules vendored
View File

@ -29,3 +29,6 @@
path = deps/zlib
url = https://github.com/madler/zlib.git
branch = develop
[submodule "deps/discord-rpc"]
path = deps/discord-rpc
url = https://github.com/discord/discord-rpc.git

1
deps/discord-rpc vendored Submodule

@ -0,0 +1 @@
Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33

38
deps/premake/discord-rpc.lua vendored Normal file
View File

@ -0,0 +1,38 @@
discordrpc = {
source = path.join(dependencies.basePath, "discord-rpc"),
}
function discordrpc.import()
links { "discord-rpc" }
discordrpc.includes()
end
function discordrpc.includes()
includedirs {
path.join(discordrpc.source, "include"),
}
end
function discordrpc.project()
project "discord-rpc"
language "C++"
discordrpc.includes()
rapidjson.import();
files {
path.join(discordrpc.source, "src/*.h"),
path.join(discordrpc.source, "src/*.cpp"),
}
removefiles {
path.join(discordrpc.source, "src/*_linux.cpp"),
path.join(discordrpc.source, "src/*_unix.cpp"),
path.join(discordrpc.source, "src/*_osx.cpp"),
}
warnings "Off"
kind "StaticLib"
end
table.insert(dependencies, discordrpc)

View File

@ -0,0 +1,52 @@
#include <std_include.hpp>
#include <discord_rpc.h>
#include "loader/module_loader.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
class discord final : public module
{
public:
void post_load() override
{
if (game::environment::is_dedi()) return;
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("762374436183343114", &handlers, 1, nullptr);
scheduler::loop(Discord_RunCallbacks, scheduler::pipeline::main);
}
void pre_destroy() override
{
Discord_Shutdown();
}
private:
static void ready(const DiscordUser* request)
{
DiscordRichPresence discord_presence;
ZeroMemory(&discord_presence, sizeof(discord_presence));
discord_presence.state = game::environment::is_mp() ? "Multiplayer" : "Singleplayer";
discord_presence.instance = 1;
Discord_UpdatePresence(&discord_presence);
}
static void errored(const int error_code, const char* message)
{
printf("Discord: (%i) %s", error_code, message);
}
};
#ifndef DEV_BUILD
REGISTER_MODULE(discord)
#endif