Add discord rich presence
This commit is contained in:
parent
6fd413db8a
commit
d5ccf4c7a3
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -22,3 +22,6 @@
|
||||
[submodule "deps/udis86"]
|
||||
path = deps/udis86
|
||||
url = https://github.com/vmt/udis86.git
|
||||
[submodule "deps/discord-rpc"]
|
||||
path = deps/discord-rpc
|
||||
url = https://github.com/momo5502/discord-rpc.git
|
||||
|
1
deps/discord-rpc
vendored
Submodule
1
deps/discord-rpc
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33
|
39
deps/premake/discord-rpc.lua
vendored
Normal file
39
deps/premake/discord-rpc.lua
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
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/dllmain.cpp"),
|
||||
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)
|
75
src/client/component/discord.cpp
Normal file
75
src/client/component/discord.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include <discord_rpc.h>
|
||||
|
||||
#include "scheduler.hpp"
|
||||
|
||||
namespace discord
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void ready(const DiscordUser* /*request*/)
|
||||
{
|
||||
printf("Discord: Ready\n");
|
||||
|
||||
DiscordRichPresence discord_presence{};
|
||||
ZeroMemory(&discord_presence, sizeof(discord_presence));
|
||||
|
||||
discord_presence.instance = 1;
|
||||
//discord_presence.state = "BOIII";
|
||||
|
||||
discord_presence.partySize = 0;
|
||||
discord_presence.partyMax = 0;
|
||||
discord_presence.startTimestamp = 0;
|
||||
|
||||
Discord_UpdatePresence(&discord_presence);
|
||||
}
|
||||
|
||||
void errored(const int error_code, const char* message)
|
||||
{
|
||||
printf("Discord: Error (%i): %s\n", error_code, message);
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_load() override
|
||||
{
|
||||
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("1047539933922988112", &handlers, 1, nullptr);
|
||||
|
||||
this->initialized_ = true;
|
||||
|
||||
scheduler::once([]()
|
||||
{
|
||||
scheduler::once(Discord_RunCallbacks, scheduler::pipeline::async);
|
||||
scheduler::loop(Discord_RunCallbacks, scheduler::pipeline::async, 15s);
|
||||
}, scheduler::pipeline::main);
|
||||
}
|
||||
|
||||
void pre_destroy() override
|
||||
{
|
||||
if (this->initialized_)
|
||||
{
|
||||
Discord_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef DEV_BUILD
|
||||
REGISTER_COMPONENT(discord::component)
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user