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");