From 5275c71934885d37a9754eb2a0ea76059bb0a160 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 9 Feb 2023 00:21:32 +0000 Subject: [PATCH] [Discord]: Add invites --- src/Components/Modules/Discord.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Discord.cpp b/src/Components/Modules/Discord.cpp index 1797be20..12e8fd4f 100644 --- a/src/Components/Modules/Discord.cpp +++ b/src/Components/Modules/Discord.cpp @@ -10,6 +10,12 @@ namespace Components bool Discord::Initialized_; + static unsigned int GetDiscordNonce() + { + static auto nonce = Utils::Cryptography::Rand::GenerateInt(); + return nonce; + } + static void Ready([[maybe_unused]] const DiscordUser* request) { ZeroMemory(&DiscordPresence, sizeof(DiscordPresence)); @@ -21,6 +27,11 @@ namespace Components Discord_UpdatePresence(&DiscordPresence); } + static void JoinGame(const char* joinSecret) + { + Game::Cbuf_AddText(0, Utils::String::VA("connect %s\n", joinSecret)); + } + static void Errored(const int errorCode, const char* message) { Logger::Print(Game::CON_CHANNEL_ERROR, "Discord: Error (%i): %s\n", errorCode, message); @@ -75,7 +86,12 @@ namespace Components DiscordPresence.state = hostNameBuffer; } - DiscordPresence.partySize = 0; + std::hash hashFn; + const auto address = Party::Target(); + + DiscordPresence.partyId = Utils::String::VA("%zu", hashFn(address) ^ GetDiscordNonce()); + DiscordPresence.joinSecret = address.getCString(); + DiscordPresence.partySize = Game::cgArray[0].snap->numClients; DiscordPresence.partyMax = Party::GetMaxClients(); if (!DiscordPresence.startTimestamp) @@ -100,7 +116,7 @@ namespace Components handlers.ready = Ready; handlers.errored = Errored; handlers.disconnected = Errored; - handlers.joinGame = nullptr; + handlers.joinGame = JoinGame; handlers.spectateGame = nullptr; handlers.joinRequest = nullptr;