[Discord]: Add invites
This commit is contained in:
parent
0d7237109c
commit
5275c71934
@ -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<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();
|
||||
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user