Skip to content

Commit

Permalink
Allow all string values to be empty/reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 12, 2023
1 parent a872851 commit 148fb34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
17 changes: 11 additions & 6 deletions Client/core/CDiscordRichPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void CDiscordRichPresence::UpdatePresence()

discordPresence.state = (!m_strDiscordAppCustomState.empty() || !m_bDisallowCustomDetails) ? m_strDiscordAppCustomState.c_str() : m_strDiscordAppState.c_str();

discordPresence.details = m_strDiscordAppDetails.c_str();
discordPresence.details =
(!m_strDiscordAppCustomDetails.empty() || !m_bDisallowCustomDetails) ? m_strDiscordAppCustomDetails.c_str() : m_strDiscordAppDetails.c_str();
discordPresence.startTimestamp = m_uiDiscordAppStart;
discordPresence.endTimestamp = m_uiDiscordAppEnd;

Expand Down Expand Up @@ -139,13 +140,13 @@ void CDiscordRichPresence::SetAsset(const char* szAsset, const char* szAssetText
{
if (isLarge)
{
m_strDiscordAppAsset = (szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET;
m_strDiscordAppAssetText = (szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_TEXT;
m_strDiscordAppAsset = (std::string(szAsset).length() > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET;
m_strDiscordAppAssetText = (std::string(szAssetText).length() > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_TEXT;
}
else
{
m_strDiscordAppAssetSmall = (szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET_SMALL;
m_strDiscordAppAssetSmallText = (szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_SMALL_TEXT;
m_strDiscordAppAssetSmall = (std::string(szAsset).length() > 0 && szAsset && *szAsset) ? szAsset : DEFAULT_APP_ASSET_SMALL;
m_strDiscordAppAssetSmallText = (std::string(szAssetText).length() > 0 && szAssetText && *szAssetText) ? szAssetText : DEFAULT_APP_ASSET_SMALL_TEXT;
}
m_bUpdateRichPresence = true;
}
Expand Down Expand Up @@ -186,7 +187,11 @@ bool CDiscordRichPresence::SetPresenceButtons(unsigned short int iIndex, const c

bool CDiscordRichPresence::SetPresenceDetails(const char* szDetails, bool bCustom)
{
m_strDiscordAppDetails = szDetails;
if (bCustom)
m_strDiscordAppCustomDetails = szDetails;
else
m_strDiscordAppDetails = szDetails;

m_bUpdateRichPresence = true;
return true;
}
Expand Down
1 change: 1 addition & 0 deletions Client/core/CDiscordRichPresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class CDiscordRichPresence : public CDiscordInterface
std::string m_strDiscordAppState;
std::string m_strDiscordAppDetails;
std::string m_strDiscordAppCustomState;
std::string m_strDiscordAppCustomDetails;

std::optional<std::tuple<std::pair<std::string, std::string>, std::pair<std::string, std::string>>> m_aButtons;

Expand Down
20 changes: 10 additions & 10 deletions Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ bool CLuaDiscordDefs::SetDetails(std::string strDetails)
{
int detailsLength = strDetails.length();

if (detailsLength < 1 || detailsLength > 128)
throw std::invalid_argument("Details length must be greater than 0, or less than/equal to 128");
if (detailsLength > 128)
throw std::invalid_argument("Details length must be less than/equal to 128");

auto discord = g_pCore->GetDiscord();

Expand Down Expand Up @@ -181,10 +181,10 @@ bool CLuaDiscordDefs::SetAsset(std::string szAsset, std::string szAssetText, boo
int assetLength = szAsset.length();
int assetTextLength = szAssetText.length();

if (assetLength < 1 || assetLength > 32)
throw std::invalid_argument("Asset name length must be greater than 0, or less than/equal to 32");
if (assetTextLength < 1 || assetTextLength > 128)
throw std::invalid_argument("Asset text length must be greater than 0, or less than/equal to 128");
if (assetLength > 32)
throw std::invalid_argument("Asset name length must be less than/equal to 32");
if (assetTextLength > 128)
throw std::invalid_argument("Asset text length must be less than/equal to 128");

auto discord = g_pCore->GetDiscord();

Expand Down Expand Up @@ -220,10 +220,10 @@ bool CLuaDiscordDefs::SetButtons(unsigned short int iIndex, std::string szName,
int nameLength = szName.length();
int urlLength = szUrl.length();

if (nameLength < 1 || nameLength > 32)
throw std::invalid_argument("Button name length must be greater than 0, or less than/equal to 32");
if (urlLength < 1 || urlLength > 128)
throw std::invalid_argument("Button URL length must be greater than 0, or less than/equal to 128");
if (nameLength > 32)
throw std::invalid_argument("Button name length must be less than/equal to 32");
if (urlLength > 128)
throw std::invalid_argument("Button URL length must be less than/equal to 128");

if (szUrl.find("https://") != 0 && szUrl.find("mtasa://") != 0)
throw std::invalid_argument("Button URL should include the https:// or mtasa:// link");
Expand Down

0 comments on commit 148fb34

Please sign in to comment.