Skip to content

Commit

Permalink
fix discord game invites
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowberryHN committed Jan 7, 2024
1 parent b152380 commit eca703f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/fpsgame/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,9 @@ namespace game
getstring(text, p);
filtertext(d->team, text, false, false, MAXTEAMLEN);
d->playermodel = getint(p);
#ifdef DISCORD
discord::updatePresence((player1->state == CS_SPECTATOR ? discord::D_SPECTATE : discord::D_PLAYING), gamemodes[gamemode + -(STARTGAMEMODE)].name, player1, true);
#endif
break;
}

Expand Down
21 changes: 12 additions & 9 deletions src/fpsgame/discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ namespace discord
discordCore->SetLogHook(LogLevel::Debug, discordLogging);
conoutf(CON_DEBUG, "\f0Discord: Successfully connected.");
discordCore->ActivityManager().OnActivityJoin.Connect([](const char* secret) {
//conoutf(CON_DEBUG, "Join: %s", secret);
conoutf(CON_DEBUG, "Discord: Joining from Discord invite...");
char* decoded = (char*)b64_decode(secret, strlen(secret));
defformatstring(bruh, "connect %s", decoded);
execute(bruh); // yo what the fuck -Y
//conoutf(CON_DEBUG, "Decoded: %s", decoded);
defformatstring(connectCommand, "connect %s", decoded);
execute(connectCommand);
});
discordCore->ActivityManager().OnActivitySpectate.Connect([](const char* secret) {
conoutf(CON_DEBUG, "Spectate: %s", secret);
conoutf(CON_DEBUG, "Discord: Spectate: %s", secret);
});
discordCore->ActivityManager().OnActivityJoinRequest.Connect([](discord::User const& user) {
conoutf(CON_DEBUG, "Join Request from %s", user.GetUsername());
conoutf(CON_DEBUG, "Discord: Join Request from %s", user.GetUsername());
// always accept, for testing reasons
discordCore->ActivityManager().SendRequestReply(user.GetId(), discord::ActivityJoinRequestReply::Yes, [](discord::Result res) {
if (res == discord::Result::Ok) conoutf(CON_DEBUG, "Accepted join request automatically");
if (res == discord::Result::Ok) conoutf(CON_DEBUG, "Discord: Accepted join request automatically");
});
});
} else conoutf(CON_ERROR, "\f2Discord: Failed to initialize! Status code: %d", (int)initStatus);
Expand Down Expand Up @@ -105,18 +104,22 @@ namespace discord
activity.GetAssets().SetLargeText(largeText);

if(address) {
if(enet_address_get_host_ip(address, serverip, strlen(serverip)) >= 0)
if(enet_address_get_host_ip(address, serverip, sizeof(serverip)) >= 0)
{
conoutf(CON_DEBUG, "ip: %s", serverip);
activity.SetState("Online");
defformatstring(partykey, "%s %u", serverip, address->port);
defformatstring(partyid, "S_%s", partyid);
defformatstring(partyid, "S_%s", partykey);
const char* b64key = b64_encode((unsigned char*)partykey, strlen(partykey));
activity.GetParty().SetId(partyid);
activity.GetParty().GetSize().SetCurrentSize(game::players.length());
activity.GetParty().GetSize().SetMaxSize(game::players.length() + 1);
activity.GetSecrets().SetJoin(b64key);
conoutf(CON_DEBUG, "discord join secret: %s", b64key);
}
else {
conoutf("address: %u, port: %u", address->host, address->port);
}
}
}
else
Expand Down
3 changes: 3 additions & 0 deletions src/fpsgame/fps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ namespace game
players.removeobj(d);
DELETEP(clients[cn]);
cleardynentcache();
#ifdef DISCORD
discord::updatePresence((player1->state == CS_SPECTATOR ? discord::D_SPECTATE : discord::D_PLAYING), gamemodes[gamemode + -(STARTGAMEMODE)].name, player1, true);
#endif
}

void clearclients(bool notify)
Expand Down

0 comments on commit eca703f

Please sign in to comment.