Files
DarkflameServer/dDashboardServer/routes/LocaleText.h
Aaron Kimbrell 9a5a9a274f feat(dashboard): Mail page with every mail, translated text and deleted mail
New Mail page (/mail, characters_mail, under Moderation): every in-game
mail newest first and live, with sender and receiver linked to their
character and account, the attachment with its icon and name (waiting
or claimed), and the state (unread, read, deleted by the player with
the time). Filters: state, character (sent or received), account,
text. Open shows the body, the attachment's item ID, subkey and data.

Locale keys in mail (%[MissionEmail_12_subjectText], the game's sender
name) are shown as the client shows them, from locale.xml; the stored
text stays under "Stored text". LocaleText::Expand, unit tested.

The character Mailbox uses the same view. Staff see mail the player
deleted (marked) and a link to the character's mail on the Mail page;
the owner sees only what is still in the mailbox, without account IDs.
/api/characters/:id/mail keeps its old fields and adds the new ones.

Check: /mail with each filter, Open on game, staff and player mail,
a mission mail's subject translated; a character's Mailbox as staff
and as the owner after deleting a mail in game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 00:59:50 -05:00

29 lines
1.0 KiB
C++

#pragma once
#include <functional>
#include <string>
// Text the game stores with locale keys in it, as the client shows it
namespace LocaleText {
/**
* Every %[KEY] in `text` replaced with the phrase `lookup` gives for KEY (the client's locale.xml); a key without a
* phrase stays as written. Mail from the game is stored this way ("%[MissionEmail_12_subjectText]"). Pure; unit tested.
*/
inline std::string Expand(const std::string& text, const std::function<const std::string&(const std::string&)>& lookup) {
std::string out;
size_t pos = 0;
while (pos < text.size()) {
const auto start = text.find("%[", pos);
const auto end = start == std::string::npos ? std::string::npos : text.find(']', start + 2);
if (end == std::string::npos) break;
out.append(text, pos, start - pos);
const auto& phrase = lookup(text.substr(start + 2, end - start - 2));
if (phrase.empty()) out.append(text, start, end - start + 1);
else out += phrase;
pos = end + 1;
}
out.append(text, pos, std::string::npos);
return out;
}
}