Bind confirmed bank and ticket actions to real careers (by Codex)

This commit is contained in:
Codex committed 2026-10-28 11:04:11 +01:00
1 parent f75e0f8e49
commit dcf42f2da7
23 files changed
+535 -56

No files matched your search

+112 -2
View File
@@ -4,6 +4,7 @@
#include <array>
#include <charconv>
#include <set>
#include <limits>
namespace bmh::modern_ui {
namespace {
@@ -90,9 +91,9 @@ namespace {
const Json &lineup_read(const Json &bundle, const char *kind) {
const auto &read = bundle.at(kind), &meta = bundle.at("desktop").at("meta");
require(read.value("messageType", "") == "snapshot" && read.at("data").value("kind", "") == kind,
"Kader oder Aufstellung sind in diesem Kontext nicht verfügbar.");
"Diese Engine-Ansicht ist in diesem Kontext nicht verfügbar.");
for (const auto *key : {"contractVersion", "careerId", "worldId", "worldRevision", "stateRevision", "scope"})
require(read.at("meta").at(key) == meta.at(key), "Kader und Aufstellung haben unterschiedliche Kontexte.");
require(read.at("meta").at(key) == meta.at(key), "Engine-Ansichten haben unterschiedliche Kontexte.");
return read.at("data");
}
Json metric_value(const Json &row, const char *key) {
@@ -277,4 +278,113 @@ Json engine_training_command(const Json &bundle, const Json &draft, const std::s
}
return sports_command(bundle, "training.commit", {{"types", draft.at("types")}, {"areas", draft.at("areas")}, {"players", changed}}, id);
}
Json engine_bank_projection(const Json &bundle) {
validate_engine_desk(bundle);
const auto &data = lineup_read(bundle, "bank");
require(data.at("teamId") == bundle.at("desktop").at("meta").at("scope").at("teamId"), "Bank gehört einer anderen Mannschaft.");
const auto &accounts = data.at("accounts");
const auto cash = engine_money_minor(accounts.at("cash")), deposit = engine_money_minor(accounts.at("deposit"));
require(cash == engine_money_minor(bundle.at("desktop").at("data").at("accounts").at("cash")) && deposit >= 0, "Widersprüchliche Kontostände.");
Json assets = {{"stocks", Json::array()}, {"properties", Json::array()}};
Json finance = {{"stocks", Json::array()}, {"properties", Json::array()}};
int64_t properties = 0, stocks = 0;
for (const auto *key : {"stocks", "funds"}) {
const bool stock = std::string(key) == "stocks";
const auto dest = stock ? "stocks" : "properties";
const auto &rows = data.at(key);
require(rows.is_array() && !rows.empty() && rows.size() <= size_t(stock ? 12 : 6), "Ungültiger Bankkatalog.");
std::set<std::string> ids;
for (const auto &row : rows) {
const auto id = row.at("id").get<std::string>();
bool known = false;
for (int i = 0; i < (stock ? 12 : 6); ++i) known |= id == std::string(stock ? "stock:" : "fund:") + std::to_string(i);
require(known && ids.insert(id).second, "Unbekannte oder doppelte Bankanlage.");
const auto price = engine_money_minor(row.at("price"));
const int owned = whole_in_range(row.at("owned"), 0, 65535), max = whole_in_range(row.at("maxToBuy"), 0, 99999999);
require(price >= 0 && price <= 99999999999LL, "Ungültiger Anlagenpreis.");
require(price == 0 || max <= std::numeric_limits<int64_t>::max() / price, "Anlagengesamtpreis ist zu groß.");
std::string name = row.at("name").is_string() ? row.at("name").get<std::string>() : row.at("name").value("text", "");
// A missing backend label is identified, never filled from a demo company.
if (name.empty() || name.starts_with("%%")) name = std::string(stock ? "Aktie · " : "Immobilie · ") + id;
Json item = {{"id", id}, {"name", name}, {"price", price}, {"owned", owned}, {"maxToBuy", max}};
if (stock) {
item["previous"] = engine_money_minor(row.at("previousPrice"));
item["history"] = Json::array();
require(row.at("history").is_array() && row.at("history").size() <= 1000, "Ungültiger Kursverlauf.");
for (const auto &point : row.at("history")) item["history"].push_back(engine_money_minor(point));
stocks += price * owned;
} else {
item["image"] = "bank.property." + id.substr(5);
properties += price * owned;
}
assets[dest].push_back(item); finance[dest].push_back(owned);
}
}
return {{"assets", assets}, {"state", {{"deposit", deposit}, {"finance", finance}}},
{"summary", {{"ok", true}, {"cash", cash}, {"deposit", deposit}, {"properties", properties}, {"stocks", stocks},
{"credit_line", engine_money_minor(accounts.at("creditLine"))}}}};
}
Json engine_bank_command(const Json &bundle, const Json &payload, const std::string &request_id) {
const auto projection = engine_bank_projection(bundle);
const auto action = payload.at("action").get<std::string>();
if (action == "deposit" || action == "withdraw") {
require(payload.size() == 2, "Ungültiger Bankauftrag.");
const auto amount = engine_money_minor(payload.at("amount"));
require(amount > 0 && amount % 100 == 0 && amount <= 9999999900LL &&
amount <= projection.at("summary").at(action == "deposit" ? "cash" : "deposit").get<int64_t>(), "Betrag überschreitet das verfügbare Guthaben.");
} else if (action == "buy" || action == "sell") {
require(payload.size() == 3, "Ungültiger Anlagenauftrag.");
const auto id = payload.at("assetId").get<std::string>();
const Json *asset = nullptr;
for (const auto *key : {"stocks", "properties"}) for (const auto &row : projection.at("assets").at(key)) if (row.at("id") == id) asset = &row;
require(asset, "Unbekannte Bankanlage.");
(void)whole_in_range(payload.at("count"), 1, asset->at(action == "buy" ? "maxToBuy" : "owned").get<int>());
} else require(false, "Nicht unterstützter Bankauftrag.");
return sports_command(bundle, "bank.commit", payload, request_id);
}
Json engine_ticket_projection(const Json &bundle) {
validate_engine_desk(bundle);
const auto &data = lineup_read(bundle, "stadium");
require(data.at("teamId") == bundle.at("desktop").at("meta").at("scope").at("teamId"), "Eintritt gehört einer anderen Mannschaft.");
const auto price = engine_money_minor(data.at("ticketPrice"));
const auto lo = engine_money_minor(data.at("ticketPriceRange").at("min")), hi = engine_money_minor(data.at("ticketPriceRange").at("max"));
require(lo >= 0 && hi <= 9999999900LL && lo <= price && price <= hi && lo % 100 == 0 && hi % 100 == 0 && price % 100 == 0, "Ungültige Eintrittspreise.");
return {{"ticket", price / 100}, {"min", lo / 100}, {"max", hi / 100}};
}
Json engine_ticket_command(const Json &bundle, int euros, const std::string &request_id) {
const auto price = engine_ticket_projection(bundle);
require(euros >= price.at("min").get<int64_t>() && euros <= price.at("max").get<int64_t>(), "Eintritt außerhalb des erlaubten Bereichs.");
return sports_command(bundle, "ticket.commit", {{"price", {{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(int64_t(euros) * 100)}}}}, request_id);
}
Json engine_credit_projection(const Json &bundle, const Json &read) {
validate_engine_desk(bundle);
auto context = bundle; context["credit"] = read;
const auto data = lineup_read(context, "credit");
require(data.at("lenderId") == "bank" && data.at("fields").is_array() && data.at("fields").size() == 8 && data.at("saved").size() == 6,
"Ungültige Kreditansicht.");
for (int i = 0; i < 8; ++i) {
const auto &f = data.at("fields")[size_t(i)];
require(f.at("field") == i && f.at("editable").is_boolean(), "Ungültiges Kreditfeld.");
(void)whole_in_range(f.at("value"), 0, INT32_MAX);
if (f.at("editable") == true) {
const auto lo = whole_in_range(f.at("min"), 0, INT32_MAX), hi = whole_in_range(f.at("max"), lo, INT32_MAX);
(void)hi;
}
}
for (const auto *key : {"fees", "refund", "principalPaid"}) require(engine_money_minor(data.at(key)) >= 0, "Ungültige Kreditkosten.");
return data;
}
Json engine_credit_command(const Json &bundle, const Json &read, const Json &edits, const std::string &request_id) {
const auto credit = engine_credit_projection(bundle, read);
require(credit.at("saved")[0] == 0, "Für Änderungen laufender Kredite fehlt noch die vollständige Gebührenvorschau.");
require(edits.is_array() && !edits.empty() && edits.size() <= 64, "Keine gültigen Kreditänderungen.");
for (const auto &e : edits) {
require(e.is_object() && e.size() == 2, "Ungültige Kreditänderung.");
(void)whole_in_range(e.at("field"), 0, 7); (void)whole_in_range(e.at("value"), 0, 99999999);
}
// The engine replays this ordered edit list and owns fees and all loan maths.
return sports_command(bundle, "bank.commit", {{"action", "credit"}, {"lenderId", "bank"}, {"edits", edits}, {"acceptFees", true}}, request_id);
}
} // namespace bmh::modern_ui