[PR #62] [MERGED] SMP: the lottery (/lottery), part of gambling, off by default #70

Closed
opened 2026-11-03 04:03:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon-mods/pull/62
Author: @ludovic111
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @levzzz5154

Base: main ← Head: feat/smp-lottery


📝 Commits (1)

  • 4fbe64e SMP: the lottery (/lottery), part of gambling, off by default

📊 Changes

10 files changed (+341 additions, -15 deletions)

View changed files

📝 native/smp/Cargo.lock (+1 -1)
📝 native/smp/Cargo.toml (+1 -1)
📝 native/smp/README.md (+10 -4)
📝 native/smp/mixins/smp/glue.rs (+21 -4)
📝 native/smp/mixins/smp/horizon-mixin.toml (+7 -1)
📝 native/smp/mixins/smp/smp_economy.rs (+2 -0)
📝 native/smp/mixins/smp/smp_games.rs (+8 -0)
➕ native/smp/mixins/smp/smp_lottery.rs (+258 -0)
📝 native/smp/proof.py (+31 -4)
📝 native/smp/src/lib.rs (+2 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

On main (#58 is merged): one commit.

What

The end of phase 3 of the official server's SMP (design): the lottery. It needs no new Horizon hook points, and players install nothing.

Command Does
/lottery the pot, your tickets, and the time to the draw
/lottery buy <tickets> buys tickets, ticket_price each, up to max_tickets a player a draw

How a round goes.

  1. It starts with its first ticket and is drawn lottery_seconds later (3600 by default).
  2. Tickets are held in economy.json exactly like coinflip stakes, through the same hold and award (#58).
  3. At the draw one ticket is picked uniformly among all those sold (more tickets, more chances), and its owner gets the pot, less fee_percent (0 by default). Everyone hears it.
  4. The tickets come back in three cases: a round with only one player (nobody to win from), a draw the log refuses, and a round the server stopped with (held_returned at the next start). A round is never lost or counted twice.

The random number is a fresh system key, never the world's random. The audit log gets lottery_ticket, lottery_win (with each stake) and lottery_refund.

Config. It is part of gambling (off by default in the mod; on for the official server only): ticket_price 10, max_tickets 100, lottery_seconds 3600. In-game currency only: no ticket or pot is ever bought with real money or paid out of the game. Out::All, a line to every player through native_broadcast, is new.

License

MIT, all original.

Proof

native.py proof smp (Horizon main f533c3a), after the economy, market, trade and coinflip checks, with lottery_seconds 30:

  • Alex: "You bought 3 ticket(s) for 30 coins; the pot is 30 coins, drawn in 30 s.";
  • Steve bought 2, and the pot was 50;
  • both balances dropped by the tickets' price (held);
  • Steve's /lottery: "pot 50 coins, 2 ticket(s) of yours, draws in 26 s";
  • the draw: "Lottery: Alex won 50 coins with 3 of 5 tickets!", in both players' chat;
  • both balances were right;
  • the totals still held after the restart (balances 815, nothing held), and the coinflip stake left waiting came back (held_returned).

Checks

cargo fmt --check, cargo clippy --all-targets --locked -- -D warnings, and cargo test --locked: 28 passed. The lottery tests cover:

  • the tickets held and a drawn ticket paying its owner;
  • a one-player round given back;
  • the limits, off by default, and a restart giving the tickets back.

Cost per tick

The draw check runs once a second (a comparison until a round is due). The 55-bot A/B in #57 and #58 (SMP on 6.13 ms, off 6.08 ms) covers the same quiet tick.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon-mods/pull/62 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `feat/smp-lottery` --- ### 📝 Commits (1) - [`4fbe64e`](https://github.com/horizon-rust/horizon-mods/commit/4fbe64e3763ec8cf7bf219ecea1dd1f85f81096a) SMP: the lottery (/lottery), part of gambling, off by default ### 📊 Changes **10 files changed** (+341 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `native/smp/Cargo.lock` (+1 -1) 📝 `native/smp/Cargo.toml` (+1 -1) 📝 `native/smp/README.md` (+10 -4) 📝 `native/smp/mixins/smp/glue.rs` (+21 -4) 📝 `native/smp/mixins/smp/horizon-mixin.toml` (+7 -1) 📝 `native/smp/mixins/smp/smp_economy.rs` (+2 -0) 📝 `native/smp/mixins/smp/smp_games.rs` (+8 -0) ➕ `native/smp/mixins/smp/smp_lottery.rs` (+258 -0) 📝 `native/smp/proof.py` (+31 -4) 📝 `native/smp/src/lib.rs` (+2 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **On main (#58 is merged): one commit.** ## What The end of phase 3 of the official server's SMP ([design](https://github.com/horizon-rust/horizon/blob/main/docs/smp.md)): the lottery. It needs no new Horizon hook points, and players install nothing. | Command | Does | |---|---| | `/lottery` | the pot, your tickets, and the time to the draw | | `/lottery buy <tickets>` | buys tickets, `ticket_price` each, up to `max_tickets` a player a draw | **How a round goes.** 1. It starts with its first ticket and is drawn `lottery_seconds` later (3600 by default). 2. Tickets are **held in `economy.json`** exactly like coinflip stakes, through the same `hold` and `award` (#58). 3. At the draw one ticket is picked uniformly among all those sold (more tickets, more chances), and its owner gets the pot, less `fee_percent` (0 by default). Everyone hears it. 4. The tickets come back in three cases: a round with only one player (nobody to win from), a draw the log refuses, and a round the server stopped with (`held_returned` at the next start). A round is never lost or counted twice. The random number is a fresh system key, never the world's random. The audit log gets `lottery_ticket`, `lottery_win` (with each stake) and `lottery_refund`. **Config.** It is part of `gambling` (off by default in the mod; on for the official server only): `ticket_price` 10, `max_tickets` 100, `lottery_seconds` 3600. In-game currency only: no ticket or pot is ever bought with real money or paid out of the game. `Out::All`, a line to every player through `native_broadcast`, is new. ## License MIT, all original. ## Proof `native.py proof smp` (Horizon main f533c3a), after the economy, market, trade and coinflip checks, with `lottery_seconds` 30: - Alex: "You bought 3 ticket(s) for 30 coins; the pot is 30 coins, drawn in 30 s."; - Steve bought 2, and the pot was 50; - both balances dropped by the tickets' price (held); - Steve's `/lottery`: "pot 50 coins, 2 ticket(s) of yours, draws in 26 s"; - the draw: "Lottery: Alex won 50 coins with 3 of 5 tickets!", in both players' chat; - both balances were right; - the totals still held after the restart (balances 815, nothing held), and the coinflip stake left waiting came back (`held_returned`). ## Checks `cargo fmt --check`, `cargo clippy --all-targets --locked -- -D warnings`, and `cargo test --locked`: 28 passed. The lottery tests cover: - the tickets held and a drawn ticket paying its owner; - a one-player round given back; - the limits, off by default, and a restart giving the tickets back. ## Cost per tick The draw check runs once a second (a comparison until a round is due). The 55-bot A/B in #57 and #58 (SMP on 6.13 ms, off 6.08 ms) covers the same quiet tick. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:03:00 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon-mods#70
No description provided.