contract: prompt context rows, changelog v1.7.0, probe suite (TICKET-451)
Release / windows (push) Successful in 40s
Release / android (push) Successful in 53s
Release / linux (push) Successful in 1m34s
Release / release (push) Skipped
Release / attach-windows (push) Skipped

Contract: the export row (22 bytes, the stable index, the hidden rule), the
0x44 message row (23 bytes), bit 0x8000, protocol 12, binding rows. README
export counts. Probe: Single, a second Single duel with another deck order
and an opponent without the bit, Tag: a card asks in cost, target and
operation, a Fusion's material procedure asks inside that operation and the
outer context comes back, then the card hides in the deck and asks both
players.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donnyandClaude Opus 5.5 committed 2026-11-08 16:05:09 -07:00
1 parent 458c9df105
commit ca2004112b
4 files changed
+344 -24

No files matched your search

+11
View File
@@ -5,6 +5,17 @@ wire protocol, the engine message stream, the setup pairs and the Lua API. A row
change first shipped in the Unity repo, the ticket, and the contract part it touched. Rows 0001-0024 change first shipped in the Unity repo, the ticket, and the contract part it touched. Rows 0001-0024
are the fork patches replayed into this repo as commits (`git log --oneline -- server/gframe core`). are the fork patches replayed into this repo as commits (`git log --oneline -- server/gframe core`).
## Unreleased (v1.7.0)
Prompt context (proposal 55): right before every prompt the answering seat learns which card and which effect asks.
One export, one message, capability `0x8000`, protocol 12: exports 336 / 857 / 851, capabilities `0xF7FF`.
| Date | Change | Ticket | Contract part |
|---|---|---|---|
| 2026-11-08 | Core: `ygol_query_prompt_context(pduel, playerid, out)` (22 bytes: version, has effect, code, controller, location, sequence, position, u64 description, u16 effect index, phase, chain link). `field::execute_cost` / `execute_target` / `execute_operation` push the running effect (handler, description, index, phase 1 / 2 / 3, chain link) on `core.ygol_running` at step 0 and pop it when the function finishes; the innermost one answers. `effect::ygol_script_index`: `card::add_effect` stamps `initial_effect.size()` while the card loads (`STATUS_INITIALIZING`), `0xFFFF` otherwise. A handler the asking player does not control and that is not face-up answers code 0, index `0xFFFF`, description 0. | TICKET-451 | (a) new export |
| 2026-11-08 | Server: `STOC_PROMPT_CONTEXT` `0x44` = those 22 bytes + the prompt's `MSG_*` id, to the answering seat (Tag: `cur_player`) right before every relayed prompt but rock-paper-scissors, only when its capability has the bit; never observers, recorders or replays. `FEATURE_PROMPT_CONTEXT` `0x8000` advertised by Single and Tag rooms, protocol 11 -> 12; no room refuses a joiner without it. Export gates 335 / 856 / 850 -> 336 / 857 / 851. | TICKET-451 | Wire: message `0x44`, capability bit `0x8000`, protocol 12 |
| 2026-11-08 | Binding: `StocMessage.PromptContext`, `FeatureFlags.PromptContext` (in `All`), the `PromptContext` record + `StocCodecs.PromptContext`, `EngineApi.ygol_query_prompt_context`, `Capability.ProtocolVersion` 12. Probe: the prompt context rooms (Single, a second Single duel whose opponent lacks the bit, Tag): a card asks in its cost, target and operation, then hides itself in the Deck and asks both players. | TICKET-451 | (e) C# binding |
## v1.6.0 — 2026-11-02 ## v1.6.0 — 2026-11-02
Tag shared Extra Deck (proposal 53): a setup pair gives a Tag team one Extra Deck, and each card keeps the partner who Tag shared Extra Deck (proposal 53): a setup pair gives a Tag team one Extra Deck, and each card keeps the partner who
+6 -6
View File
@@ -81,9 +81,9 @@ pwsh C:\ygol-engine\build\windows.ps1 -Version v0.0.1
### The export gate is the truth ### The export gate is the truth
The script FAILS unless the DLL exports exactly **334** symbols: `start_server`, `stop_server`, The script FAILS unless the DLL exports exactly **336** symbols: `start_server`, `stop_server`,
`ygol_engine_version`, and the core's whole C API re-exported, including the six `ygol_sb_*` Sandbox `ygol_engine_version`, and the core's whole C API re-exported, including the six `ygol_sb_*` Sandbox
exports and `ygol_preview_attack` (45 contract exports + 289 `sqlite3_*`; see the contract). A different count means the wrong tree, not "a small difference". For the exports and `ygol_preview_attack` (47 contract exports, `ygol_query_tag_cards` and `ygol_query_prompt_context` included, + 289 `sqlite3_*`; see the contract). A different count means the wrong tree, not "a small difference". For the
record: the Unity repo's old `ygoserver.dll` exported 327 because its build applied patch 0008 record: the Unity repo's old `ygoserver.dll` exported 327 because its build applied patch 0008
(the `ygol_sb_*` six) only to `ocgcore.dll`, never to the server's own core copy; with one core they (the `ygol_sb_*` six) only to `ocgcore.dll`, never to the server's own core copy; with one core they
are in the one library. are in the one library.
@@ -119,10 +119,10 @@ Windows VM: it has no nested virtualisation). From a clean clone on any Linux bo
built any more. built any more.
- The same contract-header check runs first, and the same export gate runs last, with the plain C - The same contract-header check runs first, and the same export gate runs last, with the plain C
export count (`nm --dynamic --defined-only --extern-only`, names without a leading underscore; C++ export count (`nm --dynamic --defined-only --extern-only`, names without a leading underscore; C++
symbols are `_Z`-mangled) and every name in `contract/ocgapi.h` present. Expected: **Linux 855**, symbols are `_Z`-mangled) and every name in `contract/ocgapi.h` present. Expected: **Linux 857**,
**Android 849** (the shipped Android server had 842: 841 + `ygol_preview_attack`; one core adds **Android 851** (the shipped Android server had 842: 841 + `ygol_preview_attack`; one core adds
the six `ygol_sb_*` and `ygol_engine_version`; `lua_*`, `event_*`, `z*`, ... count on these the six `ygol_sb_*` and `ygol_engine_version`; `lua_*`, `event_*`, `z*`, ... count on these
platforms, unlike on Windows, so the numbers differ from 334; Linux has one more than Android, platforms, unlike on Windows, so the numbers differ from 336; Linux has one more than Android,
`evutil_secure_rng_add_bytes`, which libevent only builds where glibc has no `arc4random`, so the `evutil_secure_rng_add_bytes`, which libevent only builds where glibc has no `arc4random`, so the
number belongs to the pinned base image). `engine.json` is written the same way as on Windows. A number belongs to the pinned base image). `engine.json` is written the same way as on Windows. A
`docker build` that fails the gate leaves nothing in `out/`. `docker build` that fails the gate leaves nothing in `out/`.
@@ -190,7 +190,7 @@ the run's own `GITHUB_TOKEN`.
| `ygol-engine-linux-x64.tar.gz` | `libygol-engine.so`, `engine.json` | | `ygol-engine-linux-x64.tar.gz` | `libygol-engine.so`, `engine.json` |
| `ygoserver-linux-x64.tar.gz` | `ygoserver` (the plain server executable), `engine.json` | | `ygoserver-linux-x64.tar.gz` | `ygoserver` (the plain server executable), `engine.json` |
| `ygol-engine-android-arm64.tar.gz` | `libygol-engine.so`, `engine.json` | | `ygol-engine-android-arm64.tar.gz` | `libygol-engine.so`, `engine.json` |
| `engine.json` | `{ version, exports, protocol, capabilities, binding }`; a copy of the Linux bundle's. `version`, `protocol`, `capabilities` and `binding` are identical in every bundle (the release job checks); `exports` is each platform's own count (334 / 855 / 849) | | `engine.json` | `{ version, exports, protocol, capabilities, binding }`; a copy of the Linux bundle's. `version`, `protocol`, `capabilities` and `binding` are identical in every bundle (the release job checks); `exports` is each platform's own count (336 / 857 / 851) |
## Line endings ## Line endings
+19 -13
View File
@@ -25,9 +25,9 @@ next to the library (`out/win64/engine.json` on Windows):
```json ```json
{ {
"version": "v0.0.1", "version": "v0.0.1",
"exports": 335, "exports": 336,
"protocol": 11, "protocol": 12,
"capabilities": 30719, "capabilities": 63487,
"binding": "v0.0.1" "binding": "v0.0.1"
} }
``` ```
@@ -35,9 +35,9 @@ next to the library (`out/win64/engine.json` on Windows):
| Key | Type | Source | | Key | Type | Source |
|---|---|---| |---|---|---|
| `version` | string | The `-Version` the build was given; `local` when none. The same string `ygol_engine_version()` returns. | | `version` | string | The `-Version` the build was given; `local` when none. The same string `ygol_engine_version()` returns. |
| `exports` | integer | The library's export count after the gate passed (Windows: 335). | | `exports` | integer | The library's export count after the gate passed (Windows: 336). |
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (11 as of 2026-11-02). | | `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (12 as of 2026-11-08). |
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 30719 = `0x77FF` = bits `0x1` to `0x400` plus `0x1000`, `0x2000` and `0x4000` (`0x800` is reserved by proposal 44). | | `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 63487 = `0xF7FF` = bits `0x1` to `0x400` plus `0x1000` to `0x8000` (`0x800` is reserved by proposal 44). |
| `binding` | string | The version of the C# binding released with this engine (section (e)); the same string as `version`. | | `binding` | string | The version of the C# binding released with this engine (section (e)); the same string as `version`. |
The build reads `protocol` and `capabilities` from the source every time; nothing types them in. The build reads `protocol` and `capabilities` from the source every time; nothing types them in.
@@ -52,7 +52,7 @@ the caller's.
The library also exports 289 `sqlite3_*` symbols because the server links SQLite with The library also exports 289 `sqlite3_*` symbols because the server links SQLite with
`SQLITE_API=__declspec(dllexport)`. They are NOT part of this contract: nothing of ours calls them `SQLITE_API=__declspec(dllexport)`. They are NOT part of this contract: nothing of ours calls them
through the library, and they are counted by the export gate only so that the number stays exact through the library, and they are counted by the export gate only so that the number stays exact
(Windows: 45 contract exports + 289 SQLite + 1 = 335; the extra 1 is `ygol_engine_version`, see below). (Windows: 46 contract exports + 289 SQLite + 1 = 336; the extra 1 is `ygol_engine_version`, see below).
### Server exports (`server/gframe/serverapi.h`) ### Server exports (`server/gframe/serverapi.h`)
@@ -111,6 +111,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
| `default_script_reader` | `byte* default_script_reader(const char* script_name, int* len)` | Upstream | | `default_script_reader` | `byte* default_script_reader(const char* script_name, int* len)` | Upstream |
| `ygol_preview_attack` | `int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out)` | Patch 0022 (TICKET-374) + 0024 (TICKET-379), 2026-10-13. A read-only dry run of the damage step. Returns 1 answered, 0 refused (bad pointer, no such card, attacker not a face-up monster on `playerid`'s field, target not a monster on the other field); a refusal writes nothing. `target_location` `0xFF` = direct. `out` is 24 bytes: version (1), flags (bit 0 direct, bit 1 unknown, bit 2 attacker destroyed, bit 3 target destroyed, bit 4 pierce, bit 5 illegal), 2 pad bytes, then five `int32`: attacker value, target value, damage to player 0, damage to player 1, reserved 0. A face-down target answers unknown with every number 0. A pair the battle menu (`field::get_attack_target`) would not offer answers illegal alone with every number 0. Call it only while the engine is parked on a prompt; the duel is byte-identical afterwards. | | `ygol_preview_attack` | `int32_t ygol_preview_attack(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t target_location, uint8_t target_sequence, uint8_t* out)` | Patch 0022 (TICKET-374) + 0024 (TICKET-379), 2026-10-13. A read-only dry run of the damage step. Returns 1 answered, 0 refused (bad pointer, no such card, attacker not a face-up monster on `playerid`'s field, target not a monster on the other field); a refusal writes nothing. `target_location` `0xFF` = direct. `out` is 24 bytes: version (1), flags (bit 0 direct, bit 1 unknown, bit 2 attacker destroyed, bit 3 target destroyed, bit 4 pierce, bit 5 illegal), 2 pad bytes, then five `int32`: attacker value, target value, damage to player 0, damage to player 1, reserved 0. A face-down target answers unknown with every number 0. A pair the battle menu (`field::get_attack_target`) would not offer answers illegal alone with every number 0. Call it only while the engine is parked on a prompt; the duel is byte-identical afterwards. |
| `ygol_query_tag_cards` | `int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out)` | v1.2.0 (TICKET-405), 2026-10-15. The waiting tag partner's cards of `playerid`'s side, read only. Returns the byte length written, 0 refused (bad pointer, bad player, not a tag duel); a refusal writes nothing. `out`: `u8 version` (1), `u8 hand_count`, `u8 extra_count`, `u8 pad` (0), `u16 deck_count`, then `u32 hand[hand_count]`, `u32 extra[extra_count]` (bit 31 = face-up, as in `MSG_TAG_SWAP`), `u32 deck[deck_count]` sorted ascending (the order stays secret). At most 7 + 4 x (255 + 255 + 250) bytes in practice; size the buffer for your deck limits. The duel is byte-identical afterwards. | | `ygol_query_tag_cards` | `int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out)` | v1.2.0 (TICKET-405), 2026-10-15. The waiting tag partner's cards of `playerid`'s side, read only. Returns the byte length written, 0 refused (bad pointer, bad player, not a tag duel); a refusal writes nothing. `out`: `u8 version` (1), `u8 hand_count`, `u8 extra_count`, `u8 pad` (0), `u16 deck_count`, then `u32 hand[hand_count]`, `u32 extra[extra_count]` (bit 31 = face-up, as in `MSG_TAG_SWAP`), `u32 deck[deck_count]` sorted ascending (the order stays secret). At most 7 + 4 x (255 + 255 + 250) bytes in practice; size the buffer for your deck limits. The duel is byte-identical afterwards. |
| `ygol_query_prompt_context` | `int32_t ygol_query_prompt_context(intptr_t pduel, uint8_t playerid, uint8_t* out)` | v1.7.0 (TICKET-451), 2026-11-08. Which effect asks the prompt the engine is parked on, read only; `playerid` is the answering player. Returns 22 (the bytes written), 0 refused (bad pointer, bad player); a refusal writes nothing. `out` (22 bytes, little-endian): `u8 version` (1), `u8 has_effect`, `u32 code` (the handler's `get_code()` now), `u8 controller`, `u8 location`, `u8 sequence`, `u8 position` (the handler now), `u64 description` (the effect's, 0 when none), `u16 effect_index`, `u8 phase` (1 cost, 2 target, 3 operation), `u8 chain_link` (the newest chain link whose effect it is, 0 when none). The effect is the innermost cost / target / operation function running (`field::execute_cost` / `execute_target` / `execute_operation`, the core's only coroutine calls, tracked in `core.ygol_running`); none running (battle and idle commands, chain prompts, a Summon without an effect) = `has_effect` 0, every other byte 0 and `effect_index` `0xFFFF`. **`effect_index`** is the order the card's script registered the effect while the card loaded (`card::add_effect` under `STATUS_INITIALIZING` stamps `initial_effect.size()`): the same in every duel and on every machine for that card's script; an effect registered at any other time (a clone, a copy, a grant, an effect made during the duel) is `0xFFFF`. **Hidden**: when the handler is not controlled by `playerid` and is not face-up (`is_position(POS_FACEUP)`: a face-down card, the other player's hand, Deck or face-down Extra Deck), `code` is 0, `effect_index` `0xFFFF` and `description` 0; the other fields stay. The duel is byte-identical afterwards. |
| `get_registry_value` | `int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf)` | Upstream (koishi) | | `get_registry_value` | `int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf)` | Upstream (koishi) |
| `set_registry_value` | `void set_registry_value(intptr_t pduel, const char* key, const char* value)` | Upstream (koishi). The server writes every setup pair here before `special.lua` (patch 0009). | | `set_registry_value` | `void set_registry_value(intptr_t pduel, const char* key, const char* value)` | Upstream (koishi). The server writes every setup pair here before `special.lua` (patch 0009). |
| `get_registry_keys` | `int32_t get_registry_keys(intptr_t pduel, byte* out_buf)` | Upstream (koishi) | | `get_registry_keys` | `int32_t get_registry_keys(intptr_t pduel, byte* out_buf)` | Upstream (koishi) |
@@ -132,7 +133,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
Locations the sandbox exports accept: DECK, HAND, MZONE, SZONE, GRAVE, REMOVED, EXTRA. Locations the sandbox exports accept: DECK, HAND, MZONE, SZONE, GRAVE, REMOVED, EXTRA.
Export count on Windows: 3 server + 43 core = 46 contract exports, + 289 `sqlite3_*` = 335. The Export count on Windows: 3 server + 44 core = 47 contract exports, + 289 `sqlite3_*` = 336. The
Unity repo's old `ygoserver.dll` had 327: its own core copy never carried patch 0008, and it had no Unity repo's old `ygoserver.dll` had 327: its own core copy never carried patch 0008, and it had no
`ygol_engine_version`. `ygol_engine_version`.
@@ -165,11 +166,12 @@ the server itself speaks. The STOC form of a relayed message is always the CTOS
stamp in front. "Stamp" in the tables below says whether the STOC message carries one. stamp in front. "Stamp" in the tables below says whether the STOC message carries one.
**Capability.** The server sends `STOC_CAPABILITY` (stamp `0xFF`) to every connection between **Capability.** The server sends `STOC_CAPABILITY` (stamp `0xFF`) to every connection between
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (11) and `flags` = the OR of `STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (12) and `flags` = the OR of
the bits below (`0x77FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a the bits below (`0xF7FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
host without bit `0x4` as out of date, and without bit `0x1000` too (v1.5.0). A Tag room refuses a host without bit `0x4` as out of date, and without bit `0x1000` too (v1.5.0). A Tag room refuses a
client whose `CTOS_CAPABILITY` lacks `0x1000` or `0x4000` (v1.6.0): `STOC_ERROR_MSG` `ERRMSG_VERERROR` client whose `CTOS_CAPABILITY` lacks `0x1000` or `0x4000` (v1.6.0): `STOC_ERROR_MSG` `ERRMSG_VERERROR`
(code = `FEATURE_PROTOCOL`), then the connection is closed; a Single room keeps it. (code = `FEATURE_PROTOCOL`), then the connection is closed; a Single room keeps it. No room refuses a client
without `0x8000` (v1.7.0): it just never gets `STOC_PROMPT_CONTEXT`.
**Join snapshot.** A joiner gets, per occupied seat, right after that seat's `STOC_HS_PLAYER_ENTER`: **Join snapshot.** A joiner gets, per occupied seat, right after that seat's `STOC_HS_PLAYER_ENTER`:
the seat's stored capability, appearance (0006), seat state (0013) and profile (0020) when present, the seat's stored capability, appearance (0006), seat state (0013) and profile (0020) when present,
@@ -205,6 +207,7 @@ duelist's own side (v1.2.0), both sides for an observer when spectators see all
| `0x41` | `STOC_APPEARANCE` | `u16 sender` + `CTOS_Appearance` (354) | Yes | Everyone; stored per seat, replayed to joiners, dropped when the seat empties or moves to the watchers | `0x1` | 1 | 0006 | | `0x41` | `STOC_APPEARANCE` | `u16 sender` + `CTOS_Appearance` (354) | Yes | Everyone; stored per seat, replayed to joiners, dropped when the seat empties or moves to the watchers | `0x1` | 1 | 0006 |
| `0x42` | `STOC_DIALOGUE` | `u16 sender` + `CTOS_Dialogue` (206) | Yes | Everyone | `0x2` | 1 | 0006 | | `0x42` | `STOC_DIALOGUE` | `u16 sender` + `CTOS_Dialogue` (206) | Yes | Everyone | `0x2` | 1 | 0006 |
| `0x43` | `STOC_SETUP_PAIRS` | `u16 0xFF`, `u16 count`, then per pair `u16 length` + `key=value` bytes (no terminator) | Yes (`0xFF`) | Every joiner, in the snapshot | `0x4` | 1 | 0009 | | `0x43` | `STOC_SETUP_PAIRS` | `u16 0xFF`, `u16 count`, then per pair `u16 length` + `key=value` bytes (no terminator) | Yes (`0xFF`) | Every joiner, in the snapshot | `0x4` | 1 | 0009 |
| `0x44` | `STOC_PROMPT_CONTEXT` | The 22 `ygol_query_prompt_context` bytes (section (a)) + `u8 prompt` (the `MSG_*` id of the prompt it belongs to); 23 bytes | No | The seat that answers the prompt (Tag: the team's current hand), and only when its `CTOS_CAPABILITY` had `0x8000`; the packet right before that prompt's `STOC_GAME_MSG`. Sent before every prompt the server relays but `MSG_ROCK_PAPER_SCISSORS`: `MSG_SELECT_BATTLECMD`, `IDLECMD`, `EFFECTYN`, `YESNO`, `OPTION`, `CARD`, `TRIBUTE`, `UNSELECT_CARD`, `CHAIN`, `PLACE`, `DISFIELD`, `POSITION`, `COUNTER`, `SUM`, `MSG_SORT_CARD`, `MSG_ANNOUNCE_RACE`, `ATTRIB`, `CARD`, `NUMBER`. A prompt with no effect running gets `has_effect` 0, so a client never keeps a stale context. Never to observers, the waiting Tag partner or the server-mode recorders, never in a replay; a `MSG_RETRY` re-ask gets none (the context still stands) | `0x8000` | 12 | v1.7.0 |
| `0x50` | `STOC_SEAT_PLAN` | `u16 0xFF` + `STOC_SeatPlan` (23): `u8 restart_id[16]`, `u16 revision`, `u8 seat_count`, `u8 kind[4]` (25 total; no token on the wire) | Yes (`0xFF`) | Everyone after a plan, swap or move; joiners in the snapshot | `0x8` | 2 | 0011 | | `0x50` | `STOC_SEAT_PLAN` | `u16 0xFF` + `STOC_SeatPlan` (23): `u8 restart_id[16]`, `u16 revision`, `u8 seat_count`, `u8 kind[4]` (25 total; no token on the wire) | Yes (`0xFF`) | Everyone after a plan, swap or move; joiners in the snapshot | `0x8` | 2 | 0011 |
| `0x54` | `STOC_ROOM_RESTARTING` | `u16 0xFF` + `STOC_RoomRestarting` (38): `u8 phase` (1 Prepare, 2 Commit, 3 Abort), `u8 restart_id[16]`, `u8 seat`, `u8 token[16]`, `u32 timeout_ms` | Yes (`0xFF`) | Each participant, with ITS OWN seat and token only | `0x10` | 2 | 0012 | | `0x54` | `STOC_ROOM_RESTARTING` | `u16 0xFF` + `STOC_RoomRestarting` (38): `u8 phase` (1 Prepare, 2 Commit, 3 Abort), `u8 restart_id[16]`, `u8 seat`, `u8 token[16]`, `u32 timeout_ms` | Yes (`0xFF`) | Each participant, with ITS OWN seat and token only | `0x10` | 2 | 0012 |
| `0x56` | `STOC_RESTART_STATUS` | `u16 0xFF` + `STOC_RestartStatus` (21): `u8 phase`, `u8 restart_id[16]`, `u8 acked`, `u8 expected`, `u8 complete`, `u8 reason` (0 none, 1 incompatible, 2 ack timeout, 3 not lobby, 4 not host, 5 busy, 6 bad request) | Yes (`0xFF`) | The host only | `0x10` | 2 | 0012 | | `0x56` | `STOC_RESTART_STATUS` | `u16 0xFF` + `STOC_RestartStatus` (21): `u8 phase`, `u8 restart_id[16]`, `u8 acked`, `u8 expected`, `u8 complete`, `u8 reason` (0 none, 1 incompatible, 2 ack timeout, 3 not lobby, 4 not host, 5 busy, 6 bad request) | Yes (`0xFF`) | The host only | `0x10` | 2 | 0012 |
@@ -237,6 +240,7 @@ duelist's own side (v1.2.0), both sides for an observer when spectators see all
| `0x1000` | `FEATURE_TAG_TWO_FIELDS` | 10 | v1.5.0 | Tag two Field slots: Spell/Trap sequence 6 is a team's second Field Zone (no message); a Tag room refuses a joiner without it | | `0x1000` | `FEATURE_TAG_TWO_FIELDS` | 10 | v1.5.0 | Tag two Field slots: Spell/Trap sequence 6 is a team's second Field Zone (no message); a Tag room refuses a joiner without it |
| `0x2000` | `FEATURE_TAG_PARTNER_CARDS` | 9 | v1.2.0 | Tag partner cards (`STOC_TAG_PARTNER_CARDS`, `ygol_query_tag_cards`) | | `0x2000` | `FEATURE_TAG_PARTNER_CARDS` | 9 | v1.2.0 | Tag partner cards (`STOC_TAG_PARTNER_CARDS`, `ygol_query_tag_cards`) |
| `0x4000` | `FEATURE_TAG_SHARED_EXTRA` | 11 | v1.6.0 | Tag shared Extra Deck: the setup pair `ygol.tag.extra=shared`, `QUERY_TAG_MEMBER` on Extra Deck refreshes; a Tag room refuses a joiner without it | | `0x4000` | `FEATURE_TAG_SHARED_EXTRA` | 11 | v1.6.0 | Tag shared Extra Deck: the setup pair `ygol.tag.extra=shared`, `QUERY_TAG_MEMBER` on Extra Deck refreshes; a Tag room refuses a joiner without it |
| `0x8000` | `FEATURE_PROMPT_CONTEXT` | 12 | v1.7.0 | Prompt context (`STOC_PROMPT_CONTEXT`, `ygol_query_prompt_context`): which card and which effect asks; no room refuses a joiner without it |
`FEATURE_PROTOCOL` is bumped by every patch that adds a message a client must understand; the join `FEATURE_PROTOCOL` is bumped by every patch that adds a message a client must understand; the join
list hides hosts older than the client's number. Rule 4 (proposal 47): one feature, one door. Never list hides hosts older than the client's number. Rule 4 (proposal 47): one feature, one door. Never
@@ -278,7 +282,8 @@ The table is the one `MessageScan.Scan` in the C# binding reads (section (e)); t
`core/common.h`, the enum `GameMessage`. `core/common.h`, the enum `GameMessage`.
`n` = a count byte read at that point; "prompt" = the engine waits for `set_responsei` / `n` = a count byte read at that point; "prompt" = the engine waits for `set_responsei` /
`set_responseb` from `player`. **The fork adds NO message id and changes NO layout**; the only `set_responseb` from `player`. **The fork adds NO message id and changes NO layout**; the only
fork-related rows are marked. fork-related rows are marked. The prompt context (v1.7.0) is read beside the stream through
`ygol_query_prompt_context` while the engine is parked on a prompt; no message carries it.
| Id | Name | Payload length rule | Prompt | | Id | Name | Payload length rule | Prompt |
|---|---|---|---| |---|---|---|---|
@@ -453,7 +458,7 @@ Namespaces:
| Namespace | What | | Namespace | What |
|---|---| |---|---|
| `YGOLegacy.Protocol.{Contracts, Codecs, Framing, Routing}` | Section (b) in C#: the message ids and payload records, the CTOS / STOC codecs, the frame codec and the STOC router. Unchanged from the Unity repo (TICKET-397); v1.2.0 adds `StocMessage.TagPartnerCards`, `FeatureFlags.TagPartnerCards`, the `TagPartnerCards` record and `StocCodecs.TagPartnerCards`, and `Capability.ProtocolVersion` is 9; v1.4.0 adds `ReplayFlags` (`SetupPairs` = `0x40000000`, `SideLp` = `0x20000000`); v1.5.0 adds `FeatureFlags.TagTwoFields` (`0x1000`, in `All`) and `Capability.ProtocolVersion` is 10. | | `YGOLegacy.Protocol.{Contracts, Codecs, Framing, Routing}` | Section (b) in C#: the message ids and payload records, the CTOS / STOC codecs, the frame codec and the STOC router. Unchanged from the Unity repo (TICKET-397); v1.2.0 adds `StocMessage.TagPartnerCards`, `FeatureFlags.TagPartnerCards`, the `TagPartnerCards` record and `StocCodecs.TagPartnerCards`, and `Capability.ProtocolVersion` is 9; v1.4.0 adds `ReplayFlags` (`SetupPairs` = `0x40000000`, `SideLp` = `0x20000000`); v1.5.0 adds `FeatureFlags.TagTwoFields` (`0x1000`, in `All`) and `Capability.ProtocolVersion` is 10; v1.6.0 adds `FeatureFlags.TagSharedExtra` (`0x4000`, in `All`) and `Capability.ProtocolVersion` is 11; v1.7.0 adds `StocMessage.PromptContext` (`0x44`), `FeatureFlags.PromptContext` (`0x8000`, in `All`), the `PromptContext` record (`HasEffect`, `Code`, `Controller`, `Location`, `Sequence`, `Position`, `Description`, `EffectIndex`, `Phase`, `ChainLink`, `Prompt`, `IsHidden`, `None(prompt)`, `UnknownIndex` `0xFFFF`, `PhaseCost` / `PhaseTarget` / `PhaseOperation` 1 / 2 / 3) and `StocCodecs.PromptContext` (`PromptContextCodec`, 23 bytes), and `Capability.ProtocolVersion` is 12. |
| `YGOLegacy.Engine` | The four types below (TICKET-398). | | `YGOLegacy.Engine` | The four types below (TICKET-398). |
| Type | What | | Type | What |
@@ -495,6 +500,7 @@ Every row is one export of section (a) with its managed signature. A `string` pa
| `default_script_reader` | `IntPtr default_script_reader(string script_name, int* len)` | | `default_script_reader` | `IntPtr default_script_reader(string script_name, int* len)` |
| `ygol_preview_attack` | `int ygol_preview_attack(IntPtr pduel, byte playerid, byte location, byte sequence, byte target_location, byte target_sequence, byte[] @out)` | | `ygol_preview_attack` | `int ygol_preview_attack(IntPtr pduel, byte playerid, byte location, byte sequence, byte target_location, byte target_sequence, byte[] @out)` |
| `ygol_query_tag_cards` | `int ygol_query_tag_cards(IntPtr pduel, byte playerid, byte[] @out)` | | `ygol_query_tag_cards` | `int ygol_query_tag_cards(IntPtr pduel, byte playerid, byte[] @out)` |
| `ygol_query_prompt_context` | `int ygol_query_prompt_context(IntPtr pduel, byte playerid, byte[] @out)` |
| `get_registry_value` | `int get_registry_value(IntPtr pduel, string key, byte[] out_buf)` | | `get_registry_value` | `int get_registry_value(IntPtr pduel, string key, byte[] out_buf)` |
| `set_registry_value` | `void set_registry_value(IntPtr pduel, string key, string value)` | | `set_registry_value` | `void set_registry_value(IntPtr pduel, string key, string value)` |
| `get_registry_keys` | `int get_registry_keys(IntPtr pduel, byte[] out_buf)` | | `get_registry_keys` | `int get_registry_keys(IntPtr pduel, byte[] out_buf)` |
+308 -5
View File
@@ -173,6 +173,18 @@
# the library to the same Summons. Without the pair the partners' lists stay # the library to the same Summons. Without the pair the partners' lists stay
# apart and no query carries the bit. # apart and no query carries the bit.
# #
# With --dll it also gates v1.7.0 (proposal 55 / TICKET-451, prompt context): the capability says protocol 12 +
# flag 0x8000 (single and tag) and no room refuses a joiner without it. A card (Probe Ask) registers two effects
# that never run, then an Activate that asks a yes/no in its cost, an option in its target and a yes/no in its
# operation, runs a Fusion Monster's material procedure (which asks) inside that operation and asks again, shuffles
# itself into the deck and asks the opponent, then its controller. Every prompt a seat with
# 0x8000 gets comes right after one 23-byte PROMPT_CONTEXT (0x44) naming that prompt: idle, chain and battle
# prompts say no effect; cost / target / operation say Probe Ask, phase 1 / 2 / 3, effect index 2, its
# description, chain link 1; the nested procedure names the Fusion (index 1, chain link 0) and the operation's
# next prompt names Probe Ask again; the opponent's yes/no names the card in the deck as hidden (code 0, index 0xFFFF,
# description 0) while its controller's next one still names it. A watcher with 0x8000, a seat without it and
# the waiting Tag partners get none; a second duel with another deck order reports the same indexes.
#
# Exit 0 only when every check passed. Stock DLL: the first check fails; the # Exit 0 only when every check passed. Stock DLL: the first check fails; the
# 0011 DLL fails at the capability flags. # 0011 DLL fails at the capability flags.
import argparse, base64, ctypes, lzma, os, shutil, socket, sqlite3, struct, sys, tempfile, threading, time import argparse, base64, ctypes, lzma, os, shutil, socket, sqlite3, struct, sys, tempfile, threading, time
@@ -318,7 +330,7 @@ def check_snapshot(who, pkts, expect_seat_appearance, forbid_seat):
check(len(server_caps) == 1 and j < server_caps[0][0] < t, "%s: the server's CAPABILITY(0xFF) sits between JOIN_GAME and TYPE_CHANGE" % who) check(len(server_caps) == 1 and j < server_caps[0][0] < t, "%s: the server's CAPABILITY(0xFF) sits between JOIN_GAME and TYPE_CHANGE" % who)
if server_caps: if server_caps:
proto, flags = struct.unpack_from("<HI", server_caps[0][1], 2) proto, flags = struct.unpack_from("<HI", server_caps[0][1], 2)
check(proto == 11 and flags == 0x77FF, "%s: server capability is protocol 11, flags 0x77FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview | tag two fields | tag partner cards | tag shared extra), got %d / 0x%x" % (who, proto, flags)) check(proto == 12 and flags == 0xF7FF, "%s: server capability is protocol 12, flags 0xF7FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview | tag two fields | tag partner cards | tag shared extra | prompt context), got %d / 0x%x" % (who, proto, flags))
for seat, expected in expect_seat_appearance.items(): for seat, expected in expect_seat_appearance.items():
enters = [i for i, (p, d) in enumerate(pkts) if p == STOC_HS_PLAYER_ENTER and d[40] == seat] enters = [i for i, (p, d) in enumerate(pkts) if p == STOC_HS_PLAYER_ENTER and d[40] == seat]
apps = [i for i, (p, d) in enumerate(pkts) if p == STOC_APPEARANCE and struct.unpack_from("<H", d, 0)[0] == seat] apps = [i for i, (p, d) in enumerate(pkts) if p == STOC_APPEARANCE and struct.unpack_from("<H", d, 0)[0] == seat]
@@ -382,6 +394,7 @@ def main():
tag_across_swap_suite(o.dll, port + 120) tag_across_swap_suite(o.dll, port + 120)
tag_two_fields_suite(o.dll, port + 130) tag_two_fields_suite(o.dll, port + 130)
tag_shared_extra_suite(o.dll, port + 140) tag_shared_extra_suite(o.dll, port + 140)
prompt_context_suite(o.dll, port + 150)
print() print()
if failures: if failures:
print("FAILED: %d check(s)" % len(failures)) print("FAILED: %d check(s)" % len(failures))
@@ -2715,7 +2728,7 @@ def tag_partner_room(dll_path, port, label, hidden):
everyone = seated + [w] everyone = seated + [w]
check([c.seat for c in everyone] == [0, 1, 2, 3, OBSERVER], "%s: four seats and a watcher (%r)" % (label, [c.seat for c in everyone])) check([c.seat for c in everyone] == [0, 1, 2, 3, OBSERVER], "%s: four seats and a watcher (%r)" % (label, [c.seat for c in everyone]))
cap = server_capability(seated[0].log) cap = server_capability(seated[0].log)
check(cap == (11, 0x77FF), "%s: the tag server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap)) check(cap == (12, 0xF7FF), "%s: the tag server's capability is protocol 12, flags 0xF7FF (got %s)" % (label, cap))
drain_all(everyone) drain_all(everyone)
for c in seated: for c in seated:
c.send(CTOS_UPDATE_DECK, deck_bytes(TAG_PARTNER_DECKS[c.seat])) c.send(CTOS_UPDATE_DECK, deck_bytes(TAG_PARTNER_DECKS[c.seat]))
@@ -3105,7 +3118,7 @@ def tag_two_fields_room(dll_path, port, label):
seated.append(c) seated.append(c)
check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated])) check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated]))
cap = server_capability(seated[0].log) cap = server_capability(seated[0].log)
check(cap == (11, 0x77FF), "%s: the tag server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap)) check(cap == (12, 0xF7FF), "%s: the tag server's capability is protocol 12, flags 0xF7FF (got %s)" % (label, cap))
drain_all(seated) drain_all(seated)
old = Client("127.0.0.1", port, "tf-old") old = Client("127.0.0.1", port, "tf-old")
old.log = list(old.join()) old.log = list(old.join())
@@ -3217,7 +3230,7 @@ def tag_two_fields_single(dll_path, port, label):
h = Client("127.0.0.1", port, "tf-host") h = Client("127.0.0.1", port, "tf-host")
h.log = list(h.join()) h.log = list(h.join())
cap = server_capability(h.log) cap = server_capability(h.log)
check(cap == (11, 0x77FF), "%s: the single server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap)) check(cap == (12, 0xF7FF), "%s: the single server's capability is protocol 12, flags 0xF7FF (got %s)" % (label, cap))
h.send(CTOS_CAPABILITY, capability_bytes(9, 0x27FF)) h.send(CTOS_CAPABILITY, capability_bytes(9, 0x27FF))
h.log += h.drain(quiet=0.4) h.log += h.drain(quiet=0.4)
check(h.seat == 0 and not error_msgs(h.log) and not h.closed and stamped(h.log, STOC_CAPABILITY, 0) == [capability_bytes(9, 0x27FF)], check(h.seat == 0 and not error_msgs(h.log) and not h.closed and stamped(h.log, STOC_CAPABILITY, 0) == [capability_bytes(9, 0x27FF)],
@@ -3436,7 +3449,7 @@ def tag_shared_extra_room(dll_path, port, label, shared):
seated.append(c) seated.append(c)
check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated])) check([c.seat for c in seated] == [0, 1, 2, 3], "%s: four seats (%r)" % (label, [c.seat for c in seated]))
cap = server_capability(seated[0].log) cap = server_capability(seated[0].log)
check(cap == (11, 0x77FF), "%s: the tag server's capability is protocol 11, flags 0x77FF (got %s)" % (label, cap)) check(cap == (12, 0xF7FF), "%s: the tag server's capability is protocol 12, flags 0xF7FF (got %s)" % (label, cap))
drain_all(seated) drain_all(seated)
old = Client("127.0.0.1", port, "se-old") old = Client("127.0.0.1", port, "se-old")
old.log = list(old.join()) old.log = list(old.join())
@@ -3612,5 +3625,295 @@ def tag_shared_extra_suite(dll_path, port):
tag_shared_extra_room(dll_path, port + 1, "pair absent", False) tag_shared_extra_room(dll_path, port + 1, "pair absent", False)
tag_shared_extra_single(dll_path, port + 2, "single") tag_shared_extra_single(dll_path, port + 2, "single")
# --- v1.7.0 (proposal 55 / TICKET-451): prompt context ----------------------------
STOC_PROMPT_CONTEXT = 0x44
NAMES.update({0x44: "PROMPT_CONTEXT"})
PROBE_ASK = PROBE_CARD + 1000
PROBE_ASK_FUSION = PROBE_CARD + 1001
LOCATION_DECK = 0x01
PROMPT_MSGS = {10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 22, 23, 24, 25, 26, 140, 141, 142, 143}
ASK_LUA = """--Probe Ask (TICKET-451): two effects that never run, then an Activate that asks in its cost, target and operation,
--runs Probe Ask Fusion's material procedure (which asks too) and asks again, shuffles itself into the deck and asks
--the opponent, then its controller.
local s,id,o=GetID()
function s.initial_effect(c)
local e0=Effect.CreateEffect(c)
e0:SetType(EFFECT_TYPE_SINGLE)
e0:SetCode(EFFECT_UPDATE_ATTACK)
e0:SetRange(LOCATION_MZONE)
e0:SetValue(0)
c:RegisterEffect(e0)
local e1=e0:Clone()
e1:SetCode(EFFECT_UPDATE_DEFENSE)
c:RegisterEffect(e1)
local e2=Effect.CreateEffect(c)
e2:SetDescription(id*16+1)
e2:SetType(EFFECT_TYPE_ACTIVATE)
e2:SetCode(EVENT_FREE_CHAIN)
e2:SetCost(s.cost)
e2:SetTarget(s.target)
e2:SetOperation(s.activate)
c:RegisterEffect(e2)
end
function s.cost(e,tp,eg,ep,ev,re,r,rp,chk)
if chk==0 then return true end
Duel.SelectYesNo(tp,id*16+2)
end
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
if chk==0 then return true end
Duel.SelectOption(tp,id*16+3,id*16+4)
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
Duel.SelectYesNo(tp,id*16+5)
local fc=Duel.GetFirstMatchingCard(Card.IsCode,tp,LOCATION_EXTRA,0,nil,id+1)
if fc then Duel.SelectFusionMaterial(tp,fc,Duel.GetFieldGroup(tp,LOCATION_HAND,0)) end
Duel.SelectYesNo(tp,id*16+8)
c:CancelToGrave()
Duel.SendtoDeck(c,nil,0,REASON_EFFECT)
Duel.SelectYesNo(1-tp,id*16+6)
Duel.SelectYesNo(tp,id*16+7)
end
"""
ASK_DESCRIPTION = PROBE_ASK * 16 + 1
ASK_INDEX = 2
ASK_FUSION_LUA = """--Probe Ask Fusion (TICKET-451): a Fusion Monster whose material procedure (its second effect) asks a yes/no.
local s,id,o=GetID()
function s.initial_effect(c)
local e0=Effect.CreateEffect(c)
e0:SetType(EFFECT_TYPE_SINGLE)
e0:SetCode(EFFECT_UPDATE_ATTACK)
e0:SetRange(LOCATION_MZONE)
e0:SetValue(0)
c:RegisterEffect(e0)
local e1=Effect.CreateEffect(c)
e1:SetDescription(id*16+1)
e1:SetType(EFFECT_TYPE_SINGLE)
e1:SetCode(EFFECT_FUSION_MATERIAL)
e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
e1:SetCondition(s.fcon)
e1:SetOperation(s.fop)
c:RegisterEffect(e1)
end
function s.fcon(e,g,gc,chkf)
return true
end
function s.fop(e,tp,eg,ep,ev,re,r,rp,gc,chkf)
Duel.SelectYesNo(tp,id*16+2)
Duel.SetFusionMaterial(Group.CreateGroup())
end
"""
ASK_FUSION_INDEX = 1
def prompt_context(d):
# 22-byte record + the prompt's MSG id: version, has effect, u32 code, controller, location, sequence, position,
# u64 description, u16 effect index, phase, chain link, prompt
keys = ("version", "has", "code", "controller", "location", "sequence", "position", "description", "index", "phase", "chain", "prompt")
return dict(zip(keys, struct.unpack("<BBIBBBBQHBBB", d)))
def prompts_with_context(c):
# every prompt this seat got, with the PROMPT_CONTEXT packet right before it (None when there was none)
out = []
for i, (p, d) in enumerate(c.log):
if p == 0x01 and d and d[0] in PROMPT_MSGS:
prev = c.log[i - 1] if i else (None, b"")
ctx = prompt_context(prev[1]) if prev[0] == STOC_PROMPT_CONTEXT and len(prev[1]) == 23 else None
out.append((d[0], d, ctx))
return out
def contexts_of(c):
return [d for p, d in c.log if p == STOC_PROMPT_CONTEXT]
def is_none_context(ctx, prompt):
return ctx == {"version": 1, "has": 0, "code": 0, "controller": 0, "location": 0, "sequence": 0, "position": 0,
"description": 0, "index": 0xFFFF, "phase": 0, "chain": 0, "prompt": prompt}
def prompt_context_room(dll_path, port, label, mode, opponent_bit=True, fusion_first=False):
seats = 4 if mode == 2 else 2
print("== prompt context, %s (%d seats + a watcher that advertises 0x8000; the first player activates Probe Ask)" % (label, seats))
root = make_workspace()
here = os.getcwd()
os.chdir(root)
seen = {}
try:
db = sqlite3.connect(os.path.join(root, "cards.cdb"))
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0)", (PROBE_ASK,))
db.execute("INSERT INTO texts VALUES(?, 'Probe Ask', ''" + ", ''" * 16 + ")", (PROBE_ASK,))
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 65, 2000, 2000, 6, 1, 16, 0)", (PROBE_ASK_FUSION,))
db.execute("INSERT INTO texts VALUES(?, 'Probe Ask Fusion', ''" + ", ''" * 16 + ")", (PROBE_ASK_FUSION,))
db.commit()
db.close()
with open(os.path.join(root, "script", "c%d.lua" % PROBE_ASK), "w", newline="\n") as f:
f.write(ASK_LUA)
with open(os.path.join(root, "script", "c%d.lua" % PROBE_ASK_FUSION), "w", newline="\n") as f:
f.write(ASK_FUSION_LUA)
write_special(root, [])
dll, thread = host_dll(dll_path, port, mode)
clients = []
def client(name):
c = Client("127.0.0.1", port, name)
c.log = list(c.join())
clients.append(c)
return c
seated = [client("pc-seat%d" % i) for i in range(seats)]
w = client("pc-watch")
everyone = seated + [w]
check([c.seat for c in everyone] == list(range(seats)) + [OBSERVER], "%s: %d seats and a watcher (%r)" % (label, seats, [c.seat for c in everyone]))
cap = server_capability(seated[0].log)
check(cap == (12, 0xF7FF), "%s: the server's capability is protocol 12, flags 0xF7FF (got %s)" % (label, cap))
bitless = set()
for c in everyone:
if c is seated[-1] and not opponent_bit:
c.send(CTOS_CAPABILITY, capability_bytes(12, 0x77FF))
bitless.add(c)
else:
c.send(CTOS_CAPABILITY, capability_bytes(12, 0xF7FF))
drain_all(everyone)
check(not any(c.closed for c in everyone), "%s: every joiner stays, with or without 0x8000" % label)
for c in seated:
c.send(CTOS_UPDATE_DECK, deck_bytes([PROBE_ASK_FUSION] + [PROBE_ASK] * 40 if fusion_first else [PROBE_ASK] * 40 + [PROBE_ASK_FUSION]))
pump(everyone, lambda: False, limit=0.8)
seated[0].send(CTOS_HS_START)
state = {"turn": 0, "activated": None, "bp": False, "done": False, "retries": 0}
def answer(c, payload):
c.send(CTOS_TIME_CONFIRM)
c.send(CTOS_RESPONSE, payload)
def play(limit):
deadline = time.time() + limit
while time.time() < deadline:
w.log += w.drain(quiet=0.02, limit=0.1)
for c in seated:
for pid, d in c.drain(quiet=0.02, limit=0.2):
c.log.append((pid, d))
if pid == STOC_SELECT_TP:
c.send(CTOS_TP_RESULT, bytes([1 if c.seat == 0 else 0])) # seat 0's side goes first
continue
if pid != 0x01 or not d:
continue
t = d[0]
if t == MSG_NEW_TURN and c is seated[0]:
state["turn"] += 1
elif t == MSG_RETRY:
state["retries"] += 1
elif t == MSG_SELECT_IDLECMD:
if state["turn"] == 1 and state["activated"] is None:
state["activated"] = c
answer(c, struct.pack("<i", 5)) # activate the first card: a Probe Ask
elif state["turn"] == 1:
answer(c, struct.pack("<i", 7)) # to the End Phase
elif mode != 2 and not state["bp"]:
state["bp"] = True
answer(c, struct.pack("<i", 6)) # to the Battle Phase
else:
state["done"] = True # Tag: turn 2 has no Battle Phase; stop on its idle prompt
elif t == MSG_SELECT_BATTLECMD:
state["done"] = True
elif t == MSG_SELECT_CHAIN:
answer(c, struct.pack("<i", -1))
elif t in (MSG_SELECT_PLACE, MSG_SELECT_DISFIELD):
answer(c, first_free_zone(d))
elif t in (MSG_SELECT_EFFECTYN, MSG_SELECT_YESNO):
answer(c, struct.pack("<i", 1))
elif t == MSG_SELECT_OPTION:
answer(c, struct.pack("<i", 0))
if state["done"]:
return True
if any(c.closed for c in seated):
return False
return state["done"]
ok = play(limit=30)
check(ok, "%s: the duel reached the second player's %s prompt (turn %d)" % (label, "idle" if mode == 2 else "battle", state["turn"]))
check(state["retries"] == 0, "%s: no answer was refused (MSG_RETRY x%d)" % (label, state["retries"]))
a = state["activated"]
if not check(a is not None, "%s: a seat activated Probe Ask on turn 1" % label):
return seen
for c in seated:
got = prompts_with_context(c)
if c in bitless:
check(not contexts_of(c), "%s: %s advertised no 0x8000 and got no PROMPT_CONTEXT (%d)" % (label, c.name, len(contexts_of(c))))
continue
missing = [hex(t) for t, _, ctx in got if ctx is None or ctx["prompt"] != t]
check(not missing, "%s: %s: each of its %d prompts came right after a 23-byte PROMPT_CONTEXT naming that prompt (missing: %s)" % (label, c.name, len(got), missing))
check(len(contexts_of(c)) == len(got), "%s: %s: one PROMPT_CONTEXT per prompt, none on its own (%d contexts, %d prompts)" % (label, c.name, len(contexts_of(c)), len(got)))
check(not contexts_of(w), "%s: the watcher advertised 0x8000 and got no PROMPT_CONTEXT (%d)" % (label, len(contexts_of(w))))
mine = [(t, d, ctx) for t, d, ctx in prompts_with_context(a) if ctx]
player = next((d[1] for t, d, ctx in mine if t == MSG_SELECT_IDLECMD), None)
idle = [ctx for t, d, ctx in mine if t == MSG_SELECT_IDLECMD]
check(bool(idle) and all(is_none_context(ctx, MSG_SELECT_IDLECMD) for ctx in idle),
"%s: the idle prompt's context says no effect: every field 0, index 0xFFFF (%s)" % (label, idle[:1]))
chains = [ctx for c in seated for t, d, ctx in prompts_with_context(c) if t == MSG_SELECT_CHAIN and ctx]
check(all(is_none_context(ctx, MSG_SELECT_CHAIN) for ctx in chains), "%s: every chain prompt's context says no effect (%d)" % (label, len(chains)))
asks = [ctx for t, d, ctx in mine if ctx["has"] and ctx["prompt"] in (MSG_SELECT_YESNO, MSG_SELECT_OPTION)]
shape = [(ctx["prompt"], ctx["phase"], ctx["code"], ctx["chain"]) for ctx in asks]
Y, O, A, F = MSG_SELECT_YESNO, MSG_SELECT_OPTION, PROBE_ASK, PROBE_ASK_FUSION
check(shape == [(Y, 1, A, 1), (O, 2, A, 1), (Y, 3, A, 1), (Y, 3, F, 0), (Y, 3, A, 1), (Y, 3, A, 1)],
"%s: the activator's effect prompts are Probe Ask's cost yes/no (phase 1), target option (2), operation yes/no (3), then Probe Ask Fusion's material procedure inside that operation (3, chain link 0), then Probe Ask again: the outer context is back (chain link 1), then once more from the deck (%s)" % (label, shape))
if len(asks) == 6:
on_field = asks[:3] + [asks[4]]
check(all(ctx["code"] == PROBE_ASK and ctx["controller"] == player and ctx["location"] == LOCATION_SZONE and ctx["position"] & 0x5
and ctx["description"] == ASK_DESCRIPTION and ctx["index"] == ASK_INDEX and ctx["chain"] == 1 for ctx in on_field),
"%s: cost, target and both operation prompts name Probe Ask, its controller %r, face-up in the Spell & Trap Zone, description id*16+1, effect index 2, chain link 1 (%s)" % (label, player, on_field))
nested = asks[3]
check(nested["controller"] == player and nested["location"] == LOCATION_EXTRA and nested["index"] == ASK_FUSION_INDEX and nested["description"] == PROBE_ASK_FUSION * 16 + 1,
"%s: the nested procedure names Probe Ask Fusion in its controller's Extra Deck, effect index 1, its own description (%s)" % (label, nested))
last = asks[5]
check(last["location"] == LOCATION_DECK and last["index"] == ASK_INDEX and last["description"] == ASK_DESCRIPTION,
"%s: after it shuffled itself into the deck its controller still sees it: code, index 2, description, location Deck (%s)" % (label, last))
seen["index"] = [ctx["index"] for ctx in asks]
opponent = [c for c in seated if c is not a and any(t == MSG_SELECT_YESNO for t, _, _ in prompts_with_context(c))]
check(len(opponent) == 1, "%s: exactly one other seat answered the operation's yes/no (%s)" % (label, [c.name for c in opponent]))
if opponent and opponent[0] not in bitless:
hidden = [ctx for t, d, ctx in prompts_with_context(opponent[0]) if t == MSG_SELECT_YESNO and ctx]
check(len(hidden) == 1 and hidden[0]["has"] == 1 and hidden[0]["code"] == 0 and hidden[0]["index"] == 0xFFFF and hidden[0]["description"] == 0
and hidden[0]["location"] == LOCATION_DECK and hidden[0]["controller"] == player and hidden[0]["phase"] == 3 and hidden[0]["chain"] == 1 and hidden[0]["position"] & 0xA,
"%s: the opponent's yes/no names a hidden card: code 0, index 0xFFFF, description 0, but its controller, the Deck, face-down, phase 3, chain link 1 (%s)" % (label, hidden))
if mode == 2:
answering = {a} | set(opponent)
waiting = [c for c in seated if c not in answering]
check(len(waiting) == 2 and all(not contexts_of(c) for c in waiting),
"%s: the two waiting partners got no PROMPT_CONTEXT (%s)" % (label, [(c.name, len(contexts_of(c))) for c in waiting]))
else:
battle = [ctx for c in seated for t, d, ctx in prompts_with_context(c) if t == MSG_SELECT_BATTLECMD]
if opponent and opponent[0] not in bitless:
check(len(battle) == 1 and battle[0] is not None and is_none_context(battle[0], MSG_SELECT_BATTLECMD),
"%s: the battle prompt's context says no effect (%s)" % (label, battle))
marks = marks_of(seated)
for c in seated:
if (c.seat == 0) if mode != 2 else (c.seat in (0, 1)):
c.send(CTOS_SURRENDER)
ok = pump(seated, lambda: all(match_overs(since(c, marks)) for c in seated), limit=10)
check(ok, "%s: a surrender ended the match for everyone" % label)
for c in clients:
c.close()
stop_dll(dll, thread, label)
return seen
finally:
os.chdir(here)
shutil.rmtree(root, ignore_errors=True)
def prompt_context_suite(dll_path, port):
print()
print("hosting prompt context rooms from %s" % dll_path)
first = prompt_context_room(dll_path, port, "single", 0)
second = prompt_context_room(dll_path, port + 1, "single, second duel, other deck order, opponent without 0x8000", 0, opponent_bit=False, fusion_first=True)
prompt_context_room(dll_path, port + 2, "tag", 2)
expected = [ASK_INDEX] * 3 + [ASK_FUSION_INDEX] + [ASK_INDEX] * 2
check(first.get("index") == second.get("index") == expected,
"the effect indexes are the same in two duels with a different deck order and seed: %s and %s" % (first.get("index"), second.get("index")))
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())