Modern UI contract: toto and exclusive sponsor reads and commands

toto and sponsor reads in the envelope (amounts as Money), toto.submit with
up to six columns and sponsor.answer for a camp's exclusive sponsor offer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:29:25 +01:00
1 parent e6bc72d3a0
commit 43317985e4
4 files changed
+73

No files matched your search

+34
View File
@@ -9492,6 +9492,40 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"advertising", "desktop", "bank"},
kind == "advertising.accept" ? "Werbevertrag abgeschlossen." : "Budget gesetzt.");
} else if (kind == "toto.submit") {
// payload {stake: Money per column, columns: [[11 tips: 1 home, 0 draw, 2 away], ... up to 6]}
const cli::Json* stake = ui_field(*payload, "stake");
const cli::Json* columns = ui_field(*payload, "columns");
int64_t cents = -1;
try { cents = stake ? std::stoll(ui_text(*stake, "minor")) : -1; } catch (const std::exception&) { cents = -1; }
if (cents <= 0 || cents % 100 || !columns || !columns->array()) return refuse("invalid_payload", "stake (Money) und columns nötig.");
std::vector<std::array<uint8_t, 11>> tips;
for (const auto& column : *columns->array()) {
const auto* c = column.array();
if (!c || c->size() != 11) return refuse("invalid_payload", "Jede Spalte hat elf Tipps.");
std::array<uint8_t, 11> t{};
for (size_t i = 0; i < 11; ++i) {
if (!(*c)[i].integer() || *(*c)[i].integer() < 0 || *(*c)[i].integer() > 2) return refuse("invalid_payload", "Tipps sind 0, 1 oder 2.");
t[i] = uint8_t(*(*c)[i].integer());
}
tips.push_back(t);
}
if (!dispatch_pools_columns(manager, uint32_t(cents / 100), tips, revision, error)) { restore(); return refuse("toto_refused", error); }
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"toto", "desktop"}, "Tippschein abgegeben.");
} else if (kind == "sponsor.answer") {
// payload {accept: bool}: the answer to the exclusive sponsor offer from a camp stay
const cli::Json* accept = ui_field(*payload, "accept");
if (!accept || !std::holds_alternative<bool>(accept->value)) return refuse("invalid_payload", "accept (true/false) nötig.");
std::string result;
if (!dispatch_exclusive_sponsor(manager, std::get<bool>(accept->value), revision, result, error)) {
restore(); return refuse(error.empty() ? "sponsor_refused" : error, "Kein Sponsorangebot offen.");
}
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"sponsor", "advertising", "desktop"},
result == "started" ? "Der Exklusiv-Sponsor beginnt sofort." :
result == "queued" ? "Der Exklusiv-Sponsor beginnt, sobald die Fläche frei ist." :
"Angebot abgelehnt.");
} else if (kind == "ticket.commit") {
// payload {price: Money}: the admission price, 8 to 25 euros
const cli::Json* price = ui_field(*payload, "price");
+20
View File
@@ -10,6 +10,7 @@
#include "formats/executable_layout.hpp"
#include "game/state.hpp"
#include "game/table.hpp"
#include "modern/content/projections.hpp"
#include "modern/content/world_package.hpp"
#include "modern/game/almanac.hpp"
#include "modern/game/desk_actions.hpp"
@@ -367,6 +368,25 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
if (kind == "toto" || kind == "sponsor") {
// the existing projections (ui-abfragen.md), amounts as Money
J p = query_projection(g, c.manager, O{{"kind", kind}});
auto* o = std::get_if<O>(&p.value);
if (!o || !(*o)["ok"].value.index() || !std::get<bool>((*o)["ok"].value))
return failure(request_id, "unavailable", "Nicht verfügbar.", c.state_revision);
o->erase("ok");
const auto money = [](J& v) { if (v.integer()) v = ui_money(*v.integer()); };
if (kind == "toto") {
money((*o)["stake"]), money((*o)["cost"]);
auto& last = std::get<O>((*o)["last"].value);
money(last["paid"]), money(last["won"]);
} else {
for (const char* key : {"offer", "queued"})
if (auto* row = std::get_if<O>(&(*o)[key].value)) money((*row)["monthly"]);
}
(*o)["kind"] = kind;
return snapshot(request_id, std::move(m), std::move(p));
}
if (kind == "squad") {
const int team = requested_team(g, c, request);
if (team < 0 || !fields_players(g, team))