feat(pipeline): add WMAL (Wowee Mail Template) format

Novel open replacement for AzerothCore-style
mail_loot_template SQL + the in-game mail subset of the
inventory + currency systems. The 34th open format added
to the editor.

Defines templated mail messages with currency + item
attachments. Triggered by quest reward delivery (overflow
when bag is full), auction house bid wins / sales,
achievement reward attachments, GM correspondence, holiday
event mailings (Brewfest samples, Hallow's End candy), and
returned-mail-on-rejection.

Cross-references with previously-added formats:
  WMAL.entry.senderNpcId        -> WCRT.entry.creatureId
  WMAL.entry.attachments.itemId -> WIT.entry.itemId

Format:
  • magic "WMAL", version 1, little-endian
  • per template: templateId / senderNpcId / subject / body /
    senderName / moneyCopperAttached / categoryId / cod /
    returnable / expiryDays / attachments[] (each: itemId +
    quantity)

Enums:
  • Category (8): QuestReward / Auction / GmCorrespondence /
                   AchievementReward / EventMailing / Raffle /
                   ScriptDelivery / ReturnedMail

API: WoweeMailLoader::save / load / exists / findById.

Three preset emitters showcase typical mail templates:
  • makeStarter — 3 templates (quest overflow / auction won /
                   GM gift) covering the 3 most common
                   categories
  • makeHoliday — 4 holiday samples that cross-reference the
                   WTKN seasonal token IDs (200=Tricky Treats,
                   201=Brewfest, 202=Coin of Ancestry,
                   203=Stranger's Gift) so the demo content
                   stack ships a full holiday onboarding
                   experience
  • makeAuction — 5-template auction-house family (outbid /
                   won / sold / expired / cancelled) — runtime
                   fills in actual bid amounts / sold items
                   at send time

CLI added (5 flags, 635 documented total now):
  --gen-mail / --gen-mail-holiday / --gen-mail-auction
  --info-wmal / --validate-wmal

Validator catches: templateId=0 + duplicates, empty subject,
neither senderNpcId nor senderName set (no displayable
sender), unknown category, expiryDays=0 (mail expires
immediately), cod=1 with no money attached (free COD),
empty mail in categories where the runtime doesn't fill in
content (skips Auction / GmCorrespondence / ReturnedMail
where empty templates are intentional).

Two bugs caught + fixed during smoke-test on the auction
preset:
  • print formatting glued the `0` from senderNpcId after
    the senderName when no NPC was set (rendered as
    "Postmaster0" instead of "Postmaster") — fixed with an
    explicit if/else split
  • validator's "no money + no items" warning was too
    aggressive for the Auction category, where templates
    are intentionally informational and the runtime fills
    in the real values — added Auction + ReturnedMail to
    the skip list
This commit is contained in:
Kelsi 2026-05-09 17:41:03 -07:00
parent b5995073b9
commit 492d626c3b
8 changed files with 669 additions and 0 deletions

View file

@ -0,0 +1,271 @@
#include "cli_mail_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_mail.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWmalExt(std::string base) {
stripExt(base, ".wmal");
return base;
}
bool saveOrError(const wowee::pipeline::WoweeMail& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeMailLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wmal\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeMail& c,
const std::string& base) {
std::printf("Wrote %s.wmal\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" templates : %zu\n", c.entries.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterMail";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWmalExt(base);
auto c = wowee::pipeline::WoweeMailLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-mail")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenHoliday(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "HolidayMail";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWmalExt(base);
auto c = wowee::pipeline::WoweeMailLoader::makeHoliday(name);
if (!saveOrError(c, base, "gen-mail-holiday")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenAuction(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "AuctionMail";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWmalExt(base);
auto c = wowee::pipeline::WoweeMailLoader::makeAuction(name);
if (!saveOrError(c, base, "gen-mail-auction")) return 1;
printGenSummary(c, base);
return 0;
}
int handleInfo(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWmalExt(base);
if (!wowee::pipeline::WoweeMailLoader::exists(base)) {
std::fprintf(stderr, "WMAL not found: %s.wmal\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeMailLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wmal"] = base + ".wmal";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json je;
je["templateId"] = e.templateId;
je["senderNpcId"] = e.senderNpcId;
je["subject"] = e.subject;
je["body"] = e.body;
je["senderName"] = e.senderName;
je["moneyCopperAttached"] = e.moneyCopperAttached;
je["categoryId"] = e.categoryId;
je["categoryName"] = wowee::pipeline::WoweeMail::categoryName(e.categoryId);
je["cod"] = e.cod;
je["returnable"] = e.returnable;
je["expiryDays"] = e.expiryDays;
nlohmann::json att = nlohmann::json::array();
for (const auto& a : e.attachments) {
att.push_back({{"itemId", a.itemId},
{"quantity", a.quantity}});
}
je["attachments"] = att;
arr.push_back(je);
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WMAL: %s.wmal\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" templates : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
for (const auto& e : c.entries) {
std::printf("\n templateId=%u category=%s expires=%ud cod=%u return=%u\n",
e.templateId,
wowee::pipeline::WoweeMail::categoryName(e.categoryId),
e.expiryDays, e.cod, e.returnable);
if (e.senderNpcId) {
std::printf(" sender : %s (npcId=%u)\n",
e.senderName.c_str(), e.senderNpcId);
} else {
std::printf(" sender : %s\n", e.senderName.c_str());
}
std::printf(" subject : %s\n", e.subject.c_str());
if (!e.body.empty()) {
std::printf(" body : %s\n", e.body.c_str());
}
if (e.moneyCopperAttached) {
std::printf(" money : %uc\n", e.moneyCopperAttached);
}
if (!e.attachments.empty()) {
std::printf(" items :");
for (const auto& a : e.attachments) {
std::printf(" item%u x%u", a.itemId, a.quantity);
}
std::printf("\n");
}
}
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWmalExt(base);
if (!wowee::pipeline::WoweeMailLoader::exists(base)) {
std::fprintf(stderr,
"validate-wmal: WMAL not found: %s.wmal\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeMailLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
std::vector<uint32_t> idsSeen;
for (size_t k = 0; k < c.entries.size(); ++k) {
const auto& e = c.entries[k];
std::string ctx = "entry " + std::to_string(k) +
" (id=" + std::to_string(e.templateId) + ")";
if (e.templateId == 0) errors.push_back(ctx + ": templateId is 0");
if (e.subject.empty()) errors.push_back(ctx + ": subject is empty");
if (e.senderNpcId == 0 && e.senderName.empty()) {
errors.push_back(ctx +
": neither senderNpcId nor senderName set (no displayable sender)");
}
if (e.categoryId > wowee::pipeline::WoweeMail::ReturnedMail) {
errors.push_back(ctx + ": categoryId " +
std::to_string(e.categoryId) + " not in 0..7");
}
if (e.expiryDays == 0) {
warnings.push_back(ctx +
": expiryDays=0 (mail expires immediately)");
}
if (e.cod && e.moneyCopperAttached == 0) {
warnings.push_back(ctx +
": cod=1 but moneyCopperAttached=0 (free COD)");
}
// Mail with no money + no items is informational only.
// Legitimate for GM correspondence (text-only notices)
// and for the Auction category where the runtime fills
// in the real outcome (winning bid amount / sold item)
// at send time. Flag only for the categories where
// empty mail is genuinely a typo.
if (e.moneyCopperAttached == 0 && e.attachments.empty() &&
e.categoryId != wowee::pipeline::WoweeMail::GmCorrespondence &&
e.categoryId != wowee::pipeline::WoweeMail::Auction &&
e.categoryId != wowee::pipeline::WoweeMail::ReturnedMail) {
warnings.push_back(ctx +
": no money + no items (informational mail only)");
}
for (size_t ai = 0; ai < e.attachments.size(); ++ai) {
const auto& a = e.attachments[ai];
if (a.itemId == 0) {
errors.push_back(ctx + " attachment " + std::to_string(ai) +
": itemId is 0");
}
if (a.quantity == 0) {
errors.push_back(ctx + " attachment " + std::to_string(ai) +
": quantity is 0");
}
}
for (uint32_t prev : idsSeen) {
if (prev == e.templateId) {
errors.push_back(ctx + ": duplicate templateId");
break;
}
}
idsSeen.push_back(e.templateId);
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wmal"] = base + ".wmal";
j["ok"] = ok;
j["errors"] = errors;
j["warnings"] = warnings;
std::printf("%s\n", j.dump(2).c_str());
return ok ? 0 : 1;
}
std::printf("validate-wmal: %s.wmal\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu templates, all templateIds unique\n",
c.entries.size());
return 0;
}
if (!warnings.empty()) {
std::printf(" warnings (%zu):\n", warnings.size());
for (const auto& w : warnings)
std::printf(" - %s\n", w.c_str());
}
if (!errors.empty()) {
std::printf(" ERRORS (%zu):\n", errors.size());
for (const auto& e : errors)
std::printf(" - %s\n", e.c_str());
}
return ok ? 0 : 1;
}
} // namespace
bool handleMailCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-mail") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-mail-holiday") == 0 && i + 1 < argc) {
outRc = handleGenHoliday(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-mail-auction") == 0 && i + 1 < argc) {
outRc = handleGenAuction(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wmal") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wmal") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee