Modern UI contract: bank read and bank.commit

The bank read lists account, fixed deposit, credit line, investments, the 12
stocks with their price history and the offered funds as Money. bank.commit
moves money to or from the fixed deposit and buys or sells shares and fund
units through the desk's own checks. Credits follow; the stock tip draws a
random number and will be a quote.request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 08:44:02 +01:00
1 parent 43ae1ab510
commit a1590a34ef
3 files changed
+84 -1

No files matched your search

+60 -1
View File
@@ -8765,7 +8765,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
const int manager = context.manager;
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
(kind != "lineup" && kind != "tactics" && kind != "training"))
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank"))
return modern::ui_read(g_, context, request);
if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
@@ -8795,6 +8795,36 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
{"rows", std::move(rows)}, {"positions", std::move(positions)}, {"depthMax", 19}, {"laneMax", 8},
{"manual", g_.manager_options.size() > size_t(manager) * 5 && g_.manager_options[size_t(manager) * 5] == 0}});
}
if (kind == "bank") {
// account, fixed deposit, credit line, the 12 stocks and 6 funds (prices in whole euros,
// converted to Money); the stock tip draws a random number and is no read
ui::BankState b;
try { b = ui::bank_from_game(g_, exe_, revision); } catch (const std::exception&) {
return modern::ui_error(request_id, "bank_unavailable", "Die Bank ist hier nicht verfügbar.", revision, false);
}
A stocks, funds;
for (size_t i = 0; i < b.stocks.size(); ++i) {
const auto& s = b.stocks[i];
A history;
for (uint16_t h : s.history) history.push_back(modern::ui_money(h));
stocks.push_back(O{{"id", "stock:" + std::to_string(i)}, {"name", b.finance_stock_labels[i]},
{"price", modern::ui_money(s.price)}, {"previousPrice", modern::ui_money(s.previous_price)},
{"owned", int(s.owned)}, {"paid", modern::ui_money(s.paid)}, {"maxToBuy", s.max_to_buy},
{"history", std::move(history)}});
}
for (size_t i = 0; i < b.funds.size(); ++i) {
const auto& f = b.funds[i];
if (f.price == 0) continue; // a fund the game does not offer
funds.push_back(O{{"id", "fund:" + std::to_string(i)}, {"name", f.name}, {"price", modern::ui_money(f.price)},
{"owned", int(f.owned)}, {"paid", modern::ui_money(f.paid)}, {"maxToBuy", f.max_to_buy}});
}
return modern::ui_snapshot(g_, context, request_id,
O{{"kind", "bank"}, {"teamId", modern::ui_team_id(g_, team)},
{"accounts", O{{"cash", modern::ui_money(b.balance)}, {"deposit", modern::ui_money(b.deposit)},
{"creditLine", modern::ui_money(b.credit_line)}, {"investments", modern::ui_money(b.investment_balance)}}},
{"stocks", std::move(stocks)}, {"funds", std::move(funds)},
{"credit", O{{"status", "unavailable"}, {"reasonCode", "not_yet_in_contract"}, {"missingFields", A{}}}}});
}
if (kind == "tactics") {
// the eight settings (record +0xd2..+0xd9) with the executable's maxima; the meaning of
// settings 1-3, 5 and 6 (diagrams on the original board) is not proven, hence neutral labels
@@ -9015,6 +9045,35 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
if (!ok) { restore(); return refuse(error.empty() ? "invalid_training" : error, "Training nicht übernommen: " + error); }
if (revision != previous) revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"training"}, "Training übernommen.");
} else if (kind == "bank.commit") {
// payload {action: deposit|withdraw, amount: Money} or {action: buy|sell, assetId: stock:<n>|fund:<n>, count}
const std::string action = ui_text(*payload, "action");
ui::BankRequest r;
r.manager_slot = manager, r.runtime_club = g_.manager_teams[size_t(manager)], r.revision = revision;
if (action == "deposit" || action == "withdraw") {
const cli::Json* amount = ui_field(*payload, "amount");
const std::string minor = amount ? ui_text(*amount, "minor") : std::string{};
int64_t cents = 0;
try { cents = minor.empty() ? 0 : std::stoll(minor); } catch (const std::exception&) { cents = 0; }
if (cents <= 0 || cents % 100 != 0 || cents / 100 > INT32_MAX)
return refuse("invalid_amount", "amount ist ein positiver Betrag in ganzen Euro (Money).");
r.kind = ui::BankRequestKind::move_to_deposit;
r.amount = int32_t(cents / 100) * (action == "deposit" ? 1 : -1);
} else if (action == "buy" || action == "sell") {
const std::string asset = ui_text(*payload, "assetId");
const cli::Json* count = ui_field(*payload, "count");
const bool stock = asset.starts_with("stock:"), fund = asset.starts_with("fund:");
if ((!stock && !fund) || !count || !count->integer()) return refuse("invalid_payload", "assetId und count nötig.");
try { r.asset_index = std::stoi(asset.substr(stock ? 6 : 5)); } catch (const std::exception&) { return refuse("unknown_asset", asset); }
r.count = int(*count->integer());
r.kind = stock ? (action == "buy" ? ui::BankRequestKind::buy_shares : ui::BankRequestKind::sell_shares)
: (action == "buy" ? ui::BankRequestKind::buy_fund : ui::BankRequestKind::sell_fund);
} else {
return refuse("invalid_payload", "action ist deposit, withdraw, buy oder sell.");
}
if (!dispatch_bank(r, revision, error)) { restore(); return refuse(error, "Bankauftrag abgelehnt: " + error); }
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"bank", "desktop"}, "Bankauftrag ausgeführt.");
} else if (kind == "lineup.commit") {
// payload {order: [player ids]}: the squad in this order (the first eleven start); the
// board opens as on the desk (the human line-up path), then rows are swapped into place