diff --git a/.gitmodules b/.gitmodules index b7f25858..76e12692 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/deps/discord-rpc b/deps/discord-rpc new file mode 160000 index 00000000..963aa9f3 --- /dev/null +++ b/deps/discord-rpc @@ -0,0 +1 @@ +Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33 diff --git a/deps/premake/discord-rpc.lua b/deps/premake/discord-rpc.lua new file mode 100644 index 00000000..13b36d57 --- /dev/null +++ b/deps/premake/discord-rpc.lua @@ -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) \ No newline at end of file diff --git a/src/client/component/discord.cpp b/src/client/component/discord.cpp new file mode 100644 index 00000000..50eeda16 --- /dev/null +++ b/src/client/component/discord.cpp @@ -0,0 +1,75 @@ +#include +#include "loader/component_loader.hpp" + +#include + +#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