[Discord]: Add invites

This commit is contained in:
FutureRave 2023-02-09 00:21:32 +00:00
parent 0d7237109c
commit 5275c71934
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31

View File

@ -10,6 +10,12 @@ namespace Components
bool Discord::Initialized_; bool Discord::Initialized_;
static unsigned int GetDiscordNonce()
{
static auto nonce = Utils::Cryptography::Rand::GenerateInt();
return nonce;
}
static void Ready([[maybe_unused]] const DiscordUser* request) static void Ready([[maybe_unused]] const DiscordUser* request)
{ {
ZeroMemory(&DiscordPresence, sizeof(DiscordPresence)); ZeroMemory(&DiscordPresence, sizeof(DiscordPresence));
@ -21,6 +27,11 @@ namespace Components
Discord_UpdatePresence(&DiscordPresence); 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) static void Errored(const int errorCode, const char* message)
{ {
Logger::Print(Game::CON_CHANNEL_ERROR, "Discord: Error (%i): %s\n", errorCode, message); Logger::Print(Game::CON_CHANNEL_ERROR, "Discord: Error (%i): %s\n", errorCode, message);
@ -75,7 +86,12 @@ namespace Components
DiscordPresence.state = hostNameBuffer; DiscordPresence.state = hostNameBuffer;
} }
DiscordPresence.partySize = 0; std::hash<Network::Address> 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(); DiscordPresence.partyMax = Party::GetMaxClients();
if (!DiscordPresence.startTimestamp) if (!DiscordPresence.startTimestamp)
@ -100,7 +116,7 @@ namespace Components
handlers.ready = Ready; handlers.ready = Ready;
handlers.errored = Errored; handlers.errored = Errored;
handlers.disconnected = Errored; handlers.disconnected = Errored;
handlers.joinGame = nullptr; handlers.joinGame = JoinGame;
handlers.spectateGame = nullptr; handlers.spectateGame = nullptr;
handlers.joinRequest = nullptr; handlers.joinRequest = nullptr;