Core/Misc: Add support for custom link colors. Clean-up hyperlink validation, no more long-ass defines. Remove UI.ShowQuestLevelsInDialogs.

(cherry picked from commit eaf8fa75a1)
This commit is contained in:
Treeston
2020-09-02 22:01:51 +02:00
committed by Shauren
parent f7c65960a5
commit 0d54a5ecb4
3 changed files with 34 additions and 20 deletions

View File

@@ -842,7 +842,7 @@ bool StringEqualI(std::string_view str1, std::string_view str2)
bool StringStartsWith(std::string_view haystack, std::string_view needle)
{
return (haystack.rfind(needle, 0) == 0);
return (haystack.substr(0, needle.length()) == needle);
}
bool StringContainsStringI(std::string_view haystack, std::string_view needle)

View File

@@ -449,6 +449,9 @@ struct LinkValidator<LinkTags::quest>
{
static bool IsTextValid(QuestLinkData const& data, std::string_view text)
{
if (text.empty())
return false;
if (text == data.Quest->GetLogTitle())
return true;
@@ -629,25 +632,32 @@ struct LinkValidator<LinkTags::worldmap>
}
};
#define TryValidateAs(tagname) \
{ \
static_assert(LinkTags::tagname::tag() == #tagname); \
if (info.tag == LinkTags::tagname::tag()) \
{ \
advstd::remove_cvref_t<typename LinkTags::tagname::value_type> t; \
if (!LinkTags::tagname::StoreTo(t, info.data)) \
return false; \
if (!LinkValidator<LinkTags::tagname>::IsColorValid(t, info.color)) \
return false; \
if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY)) \
if (!LinkValidator<LinkTags::tagname>::IsTextValid(t, info.text)) \
return false; \
return true; \
} \
template <typename TAG>
static bool ValidateAs(HyperlinkInfo const& info)
{
std::decay_t<typename TAG::value_type> t;
if (!TAG::StoreTo(t, info.data))
return false;
int32 const severity = static_cast<int32>(sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY));
if (severity >= 0)
{
if (!LinkValidator<TAG>::IsColorValid(t, info.color))
return false;
if (severity >= 1)
{
if (!LinkValidator<TAG>::IsTextValid(t, info.text))
return false;
}
}
return true;
}
#define TryValidateAs(T) do { if (info.tag == T::tag()) return ValidateAs<T>(info); } while (0)
static bool ValidateLinkInfo(HyperlinkInfo const& info)
{
using namespace LinkTags;
TryValidateAs(achievement);
TryValidateAs(apower);
TryValidateAs(azessence);

View File

@@ -1987,10 +1987,14 @@ ChatFakeMessagePreventing = 1
#
# ChatStrictLinkChecking.Severity
# Description: Check chat messages for in-game links to spells, items, quests, etc.
# Default: 0 - (Only verify that link format looks valid without checking the text)
# 1 - (Check if color, entry and name don't contradict each other. For this to
# work correctly, please assure that you have extracted locale DBCs of
# every language specific client playing on this server)
# -1 - (Only verify validity of link data, but permit use of custom colors)
# Default: 0 - (Only verify that link data and color are valid without checking text)
# 1 - (Additionally verifies that the link text matches the provided data)
#
# Note: If this is set to '1', you must additionally provide .dbc files for all
# client locales that are in use on your server.
# If any files are missing, messages with links from clients using those
# locales will likely be blocked by the server.
ChatStrictLinkChecking.Severity = 0