Skip to content

Commit

Permalink
start work on discord timer and attempt to fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomityGuy committed Mar 3, 2024
1 parent d1d4c1c commit 2afb9e9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions engine/source/discord/DiscordGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ void DiscordGame::update()
discordPresence.partyMax = mMaxPlayers;
discordPresence.partyId = mPartyId;
discordPresence.joinSecret = mJoinSecret;
discordPresence.startTimestamp = mStartTime;
discordPresence.endTimestamp = mStopTime;

//mActivity.GetAssets().SetLargeImage("game_icon");

Expand Down
8 changes: 8 additions & 0 deletions engine/source/discord/DiscordGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class DiscordGame
mMaxPlayers = maxp;
notifyParamsChange();
}
void setTimer(uint64_t start, uint64_t stop = 0)
{
mStartTime = start;
mStopTime = stop;
notifyParamsChange();
}
void notifyParamsChange() { mChanged = true; }
//void setIcon(const char* icon, const char* iconText) { mIcon = icon; if (mIcon == nullptr) mIcon = ""; mIconText = iconText; if (mIconText == nullptr) mIconText = ""; }
private:
Expand All @@ -80,6 +86,8 @@ class DiscordGame
const char* mLargeImageKey;
int mMaxPlayers;
int mPlayerCount;
uint64_t mStartTime;
uint64_t mStopTime;
StringTableEntry mJoinSecret;
StringTableEntry mPartyId;
//const char* mIcon;
Expand Down
29 changes: 23 additions & 6 deletions engine/source/xblive/xbliveFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "console/consoleInternal.h"

#include "discord/DiscordGame.h"
#include "core/crc.h"
#include "core/Guid.hpp"

#ifdef TORQUE_OS_WIN
#include <Windows.h>
Expand Down Expand Up @@ -265,7 +265,8 @@ ConsoleFunction(XBLiveSetRichPresence, void, 4, 5, "(port, presence, levelname,
Con::printf("Setting Rich Presence to Menus");
DiscordGame::get()->setStatus("In Menus");
DiscordGame::get()->setDetails("");
DiscordGame::get()->setPartyDetails(0, 0, nullptr, nullptr);;
DiscordGame::get()->setPartyDetails(0, 0, nullptr, nullptr);
DiscordGame::get()->setTimer(0, 0);
//DiscordGame::get()->setSmallImageKey("game_icon");
DiscordGame::get()->setLevel("MainMenu");
break;
Expand All @@ -274,6 +275,7 @@ ConsoleFunction(XBLiveSetRichPresence, void, 4, 5, "(port, presence, levelname,
DiscordGame::get()->setStatus(levelname);
DiscordGame::get()->setDetails("Playing Singleplayer");
DiscordGame::get()->setPartyDetails(0, 0, nullptr, nullptr);
DiscordGame::get()->setTimer(static_cast<uint64_t>(time(nullptr)));
//DiscordGame::get()->setSmallImageKey("game_icon");
DiscordGame::get()->setLevel(levelguid);
break;
Expand All @@ -288,6 +290,18 @@ ConsoleFunction(XBLiveSetRichPresence, void, 4, 5, "(port, presence, levelname,
#endif
}

ConsoleFunction(XBLivePresenceStartTimer, void, 1, 2, "([stopTime])")
{
int secsRemaining = argc > 1 ? atoi(argv[1]) : 0;
uint64_t startTime = static_cast<uint64_t>(time(nullptr));
DiscordGame::get()->setTimer(startTime, secsRemaining > 0 ? startTime + secsRemaining : 0);
}

ConsoleFunction(XBLivePresenceStopTimer, void, 1, 1, "()")
{
DiscordGame::get()->setTimer(0, 0);
}

ConsoleFunction(XBLiveLoadAchievements, void, 3, 3, "(port, callback)")
{
argc;
Expand Down Expand Up @@ -498,14 +512,17 @@ ConsoleFunction(XBLiveCreateHostedMatch, void, 8, 8, "(name, gamemode, mission,
StringTableEntry joinSecret = StringTable->insert(argv[6]);
const char* callback = argv[7];

U32 partyId = calculateCRC(name, strlen(name));
char partybuf[128];
dSprintf(partybuf, 128, "%x", partyId);

auto g = xg::newGuid();
std::string guid = g.str();
const char* ret = guid.c_str();
char* retBuffer = Con::getReturnBuffer(256);
dSprintf(retBuffer, 256, "{%s}", ret);

Con::printf(" >> Creating hosted match: %s, %s, %s, %s, %s", name, gamemode, mission, maxplayers, privateslots);

#ifdef TORQUE_DISCORD_RPC
DiscordGame::get()->setPartyDetails(1, atoi(maxplayers), joinSecret, StringTable->insert(partybuf, true));
DiscordGame::get()->setPartyDetails(1, atoi(maxplayers), joinSecret, StringTable->insert(retBuffer, true));
#endif

// TODO: Implement
Expand Down
1 change: 1 addition & 0 deletions game/marble/client/scripts/serverConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ function disconnectedCleanup()
}
else if ($Client::connectedMultiplayer)
{
XBLiveSetRichPresence(XBLiveGetSignInPort(), 0, "", "");
XBLiveDisconnect();
if (isObject($disconnectGui))
RootGui.setContent($disconnectGui);
Expand Down
2 changes: 1 addition & 1 deletion game/marble/client/ui/createGameGui.gui
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function CreateGameGui::createGame(%this)
// may need to some UI stuff here ("Creating game...")

// This sets the discord presence details
%inv = $Server::IsPrivate ? "" : $Server::InviteCode;
%inv = $Server::InviteCode;
XBLiveCreateHostedMatch($Player::name, $Server::GameModeId, $pref::Server::missionId, $Pref::Server::MaxPlayers, $Pref::Server::PrivateSlots, %inv, "CreateGameGui.onGameCreated();");
if (!$Client::UseXBLiveMatchMaking)
{
Expand Down

0 comments on commit 2afb9e9

Please sign in to comment.