28 m_MessageType(a_MessageType)
109 size_t len = a_ParseText.length();
114 for (
size_t i = 0; i < len; i++)
116 switch (a_ParseText[i])
120 if ((i != 0) && (a_ParseText[i-1] ==
'\\'))
122 CurrentText.append(a_ParseText, cursor, i - cursor - 1).append(
"&");
131 CurrentText.append(a_ParseText, cursor, i - cursor);
138 if (a_ParseText[i] ==
'r')
144 CurrentStyle.push_back(a_ParseText[i]);
151 static const constexpr std::array<std::string_view, 2> LinkPrefixes =
158 for (
const auto & Prefix : LinkPrefixes)
160 size_t PrefixLen = Prefix.size();
162 (i >= cursor + PrefixLen) &&
163 (std::string_view(a_ParseText).substr(i - PrefixLen, PrefixLen) == Prefix)
167 if (i > cursor+ PrefixLen)
169 CurrentText.append(a_ParseText.c_str() + cursor, i - cursor - PrefixLen);
170 cursor= i - PrefixLen;
172 if (!CurrentText.empty())
181 if (isspace(a_ParseText[i]))
186 AddUrlPart(a_ParseText.substr(cursor, i - cursor), a_ParseText.substr(cursor, i - cursor), CurrentStyle);
198 CurrentText.append(a_ParseText, cursor, len - cursor);
225 [](
UrlPart & a_Part) { a_Part.Style +=
'n'; },
244 [&Msg](
const TextPart & a_Part) { Msg.append(a_Part.Text); },
246 [&Msg](
const UrlPart & a_Part) { Msg.append(a_Part.Url); },
247 [&Msg](
const RunCommandPart & a_Part) { Msg.append(a_Part.Text); },
261 switch (a_MessageType)
275 ASSERT(!
"Unhandled MessageType");
289 Json::Value JsonPart;
292 [
this, &JsonPart](
const TextPart & a_Part)
294 JsonPart[
"text"] = a_Part.Text;
299 JsonPart[
"translate"] = a_Part.Text;
301 for (
const auto & Parameter : a_Part.Parameters)
303 With.append(Parameter);
305 if (!a_Part.Parameters.empty())
307 JsonPart[
"with"] = With;
311 [
this, &JsonPart](
const UrlPart & a_Part)
313 JsonPart[
"text"] = a_Part.Text;
315 Url[
"action"] =
"open_url";
316 Url[
"value"] = a_Part.Url;
317 JsonPart[
"clickEvent"] = Url;
322 JsonPart[
"text"] = a_Part.Text;
324 Cmd[
"action"] =
"run_command";
325 Cmd[
"value"] = a_Part.Command;
326 JsonPart[
"clickEvent"] = Cmd;
331 JsonPart[
"text"] = a_Part.Text;
333 Cmd[
"action"] =
"suggest_command";
334 Cmd[
"value"] = a_Part.Command;
335 JsonPart[
"clickEvent"] = Cmd;
340 JsonPart[
"translate"] =
"chat.type.achievement";
343 Ach[
"action"] =
"show_achievement";
344 Ach[
"value"] = a_Part.Text;
346 Json::Value AchColourAndName;
347 AchColourAndName[
"color"] =
"green";
348 AchColourAndName[
"translate"] = a_Part.Text;
349 AchColourAndName[
"hoverEvent"] = Ach;
352 Extra.append(AchColourAndName);
355 Name[
"text"] = a_Part.PlayerName;
361 JsonPart[
"with"] = With;
365 Message[
"extra"].append(JsonPart);
383 size_t len = a_PartStyle.length();
384 for (
size_t i = 0; i < len; i++)
386 switch (a_PartStyle[i])
388 case 'k': a_Value[
"obfuscated"] = Json::Value(
true);
break;
389 case 'l': a_Value[
"bold"] = Json::Value(
true);
break;
391 LOGERROR(
"Value s in AddChatPartStyle() is deprecated");
392 case 'm': a_Value[
"strikethrough"] = Json::Value(
true);
break;
394 LOGERROR(
"Value u in AddChatPartStyle() is deprecated");
395 case 'n': a_Value[
"underlined"] = Json::Value(
true);
break;
397 LOGERROR(
"Value i in AddChatPartStyle() is deprecated");
398 case 'o': a_Value[
"italic"] = Json::Value(
true);
break;
399 case '0': a_Value[
"color"] = Json::Value(
"black");
break;
400 case '1': a_Value[
"color"] = Json::Value(
"dark_blue");
break;
401 case '2': a_Value[
"color"] = Json::Value(
"dark_green");
break;
402 case '3': a_Value[
"color"] = Json::Value(
"dark_aqua");
break;
403 case '4': a_Value[
"color"] = Json::Value(
"dark_red");
break;
404 case '5': a_Value[
"color"] = Json::Value(
"dark_purple");
break;
405 case '6': a_Value[
"color"] = Json::Value(
"gold");
break;
406 case '7': a_Value[
"color"] = Json::Value(
"gray");
break;
407 case '8': a_Value[
"color"] = Json::Value(
"dark_gray");
break;
408 case '9': a_Value[
"color"] = Json::Value(
"blue");
break;
409 case 'a': a_Value[
"color"] = Json::Value(
"green");
break;
410 case 'b': a_Value[
"color"] = Json::Value(
"aqua");
break;
411 case 'c': a_Value[
"color"] = Json::Value(
"red");
break;
412 case 'd': a_Value[
"color"] = Json::Value(
"light_purple");
break;
413 case 'e': a_Value[
"color"] = Json::Value(
"yellow");
break;
414 case 'f': a_Value[
"color"] = Json::Value(
"white");
break;
void LOGERROR(std::string_view a_Format, const Args &... args)
std::vector< AString > AStringVector
AString WriteStyledString(const Json::Value &a_Root)
AString WriteFastString(const Json::Value &a_Root)
static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData)
Formats the type of message with the proper color and prefix for sending to the client.
void Clear(void)
Removes all parts from the object.
AString CreateJsonString(bool a_ShouldUseChatPrefixes=true) const
void SetMessageType(eMessageType a_MessageType, const AString &a_AdditionalMessageTypeData="")
Sets the message type, which is indicated by prefixes added to the message when serializing Takes opt...
void UnderlineUrls(void)
Adds the "underline" style to each part that is an URL.
void AddUrlPart(const AString &a_Text, const AString &a_Url, const AString &a_Style="nc")
Adds a part that opens an URL when clicked.
AString ExtractText(void) const
Returns the text from the parts that comprises the human-readable data.
AString m_AdditionalMessageTypeData
Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.
void AddSuggestCommandPart(const AString &a_Text, const AString &a_SuggestedCommand, const AString &a_Style="nb")
Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when cli...
void ParseText(const AString &a_ParseText)
Parses text into various parts, adds those.
eMessageType GetMessageType(void) const
Returns the message type set previously by SetMessageType().
void AddTextPart(const AString &a_Message, const AString &a_Style="")
Adds a plain text part, with optional style.
void AddClientTranslatedPart(const AString &a_TranslationID, const AStringVector &a_Parameters, const AString &a_Style="")
Adds a part that is translated client-side, with the formatting parameters and optional style.
cCompositeChat(void)
Creates a new empty chat message.
void AddRunCommandPart(const AString &a_Text, const AString &a_Command, const AString &a_Style="na")
Adds a part that runs a command when clicked.
eMessageType m_MessageType
The message type, as indicated by prefixes.
void AddChatPartStyle(Json::Value &a_Value, const AString &a_PartStyle) const
Adds the chat part's style (represented by the part's stylestring) into the Json object.
std::vector< std::variant< TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart > > m_Parts
All the parts that.
void AddShowAchievementPart(const AString &a_PlayerName, const AString &a_Achievement, const AString &a_Style="")
Adds a part that fully formats a specified achievement using client translatable strings Takes achiev...
AString GetAdditionalMessageTypeData(void) const
Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.
static eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType)
Converts the MessageType to a LogLevel value.
You can use this struct to use in std::visit example: std::visit( OverloadedVariantAccess { [&] (cFir...