tag partner cards: ygol_query_tag_cards + STOC_TAG_PARTNER_CARDS 0x5F, capability 0x2000, protocol 9 (TICKET-405)
Core: ygol_query_tag_cards(pduel, playerid, out) reads the waiting tag partner's tag_list_hand / tag_list_extra (bit 31 = face-up, like MSG_TAG_SWAP) and tag_list_main sorted ascending; returns the byte length, 0 when not a tag duel. Read only. Server: STOC_TAG_PARTNER_CARDS 0x5F = u8 side + those bytes, no stamp, to that side's two seats only (never the other team, never an observer): after start_duel, after every MSG_TAG_SWAP, and in a seated duelist's field resync. FEATURE_TAG_PARTNER_CARDS 0x2000 advertised by single_duel and tag_duel; FEATURE_PROTOCOL 8 -> 9. 0x800 / 0x1000 stay reserved for proposals 44 / 45. Binding: StocMessage.TagPartnerCards, FeatureFlags.TagPartnerCards, the TagPartnerCards record + StocCodecs.TagPartnerCards, EngineApi.ygol_query_tag_cards, Capability.ProtocolVersion 9, tests. Contract rows, CHANGELOG v1.2.0, the probe's tag partner cards room, the export gates 334 / 855 / 849 -> 335 / 856 / 850. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3b5e6e13b
commit
2344e5dae1
20 files changed
+444
-36
No files matched your search
+20
-13
@@ -25,9 +25,9 @@ next to the library (`out/win64/engine.json` on Windows):
|
||||
```json
|
||||
{
|
||||
"version": "v0.0.1",
|
||||
"exports": 334,
|
||||
"protocol": 8,
|
||||
"capabilities": 2047,
|
||||
"exports": 335,
|
||||
"protocol": 9,
|
||||
"capabilities": 10239,
|
||||
"binding": "v0.0.1"
|
||||
}
|
||||
```
|
||||
@@ -35,9 +35,9 @@ next to the library (`out/win64/engine.json` on Windows):
|
||||
| Key | Type | Source |
|
||||
|---|---|---|
|
||||
| `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: 334). |
|
||||
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (8 as of 2026-10-13). |
|
||||
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 2047 = `0x7FF` = bits `0x1` to `0x400`. |
|
||||
| `exports` | integer | The library's export count after the gate passed (Windows: 335). |
|
||||
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (9 as of 2026-10-15). |
|
||||
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 10239 = `0x27FF` = bits `0x1` to `0x400` plus `0x2000` (`0x800` and `0x1000` are reserved by proposals 44 and 45). |
|
||||
| `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.
|
||||
@@ -52,7 +52,7 @@ the caller's.
|
||||
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
|
||||
through the library, and they are counted by the export gate only so that the number stays exact
|
||||
(Windows: 44 contract exports + 289 SQLite + 1 = 334; the extra 1 is `ygol_engine_version`, see below).
|
||||
(Windows: 45 contract exports + 289 SQLite + 1 = 335; the extra 1 is `ygol_engine_version`, see below).
|
||||
|
||||
### Server exports (`server/gframe/serverapi.h`)
|
||||
|
||||
@@ -110,6 +110,7 @@ The host string is space-separated tokens, in this order (`server/gframe/gframe.
|
||||
| `preload_script` | `int32_t preload_script(intptr_t pduel, const char* script_name)` | 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_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. |
|
||||
| `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). |
|
||||
| `get_registry_keys` | `int32_t get_registry_keys(intptr_t pduel, byte* out_buf)` | Upstream (koishi) |
|
||||
@@ -131,7 +132,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.
|
||||
|
||||
Export count on Windows: 3 server + 42 core = 45 contract exports, + 289 `sqlite3_*` = 334. The
|
||||
Export count on Windows: 3 server + 43 core = 46 contract exports, + 289 `sqlite3_*` = 335. The
|
||||
Unity repo's old `ygoserver.dll` had 327: its own core copy never carried patch 0008, and it had no
|
||||
`ygol_engine_version`.
|
||||
|
||||
@@ -164,14 +165,15 @@ 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.
|
||||
|
||||
**Capability.** The server sends `STOC_CAPABILITY` (stamp `0xFF`) to every connection between
|
||||
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (8) and `flags` = the OR of
|
||||
the bits below (`0x7FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
|
||||
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (9) and `flags` = the OR of
|
||||
the bits below (`0x27FF`). A client sends its own `CTOS_CAPABILITY` after joining. A client refuses a
|
||||
host without bit `0x4` as out of date.
|
||||
|
||||
**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,
|
||||
then the setup pairs (0009), the seat plan (0011) if one was ever sent, and, during a duel, the field
|
||||
resync (0005) and the deck lists the audience may see (0019).
|
||||
resync (0005), the deck lists the audience may see (0019) and, for a seated Tag duelist, its side's
|
||||
partner cards (v1.2.0).
|
||||
|
||||
### Client to server
|
||||
|
||||
@@ -212,6 +214,7 @@ resync (0005) and the deck lists the audience may see (0019).
|
||||
| `0x5C` | `STOC_DECK_LIST` | `STOC_DeckList` (5): `u8 version` (1), `u8 side`, `u8 kind`, `u16 count`, then `u32 codes[count]` | No | Kind 0 (the deck's remaining cards, SORTED) to its owner (both teammates in Tag); kind 1 (real order, top first) and kind 2 (the submitted Main Deck of the duelist whose deck is in the zone, sorted) to observers only when spectators see all. Sent when a list differs from the last one that audience got; in the late-watcher snapshot | `0x100` | 6 | 0019 |
|
||||
| `0x5D` | `STOC_PROFILE` | `u16 sender` + `CTOS_Profile` (100) | Yes | Everyone; stored per seat, in the snapshot after APPEARANCE, swapped with the seat, kept across the 0014 lobby reset, cleared when the seat empties | `0x200` | 7 | 0020 |
|
||||
| `0x5E` | `STOC_ATTACK_PREVIEW` | `u8 version` (1), `u8 count`, then per pair the 4 ask bytes echoed + the 24-byte `ygol_preview_attack` answer | No | The asker only. Only attackers the open prompt listed; a pair the engine refuses is left out (the count shrinks); a valid ask whose every pair is left out still gets count 0 | `0x400` | 8 | 0023 |
|
||||
| `0x5F` | `STOC_TAG_PARTNER_CARDS` | `u8 side` + the `ygol_query_tag_cards` bytes (7 + 4 x the three counts) | No | The two seats of `side` only, never the other team and never an observer. Sent after `start_duel` (the waiting members' opening hands), after every `MSG_TAG_SWAP` for the side that swapped (the member that just left is the waiting one), and to a seated duelist in its field resync (`CTOS_REQUEST_FIELD`, after the `MSG_RELOAD_FIELD`). Tag rooms only; a Single / Match room never sends it | `0x2000` | 9 | v1.2.0 |
|
||||
|
||||
### Capability bits and protocol numbers
|
||||
|
||||
@@ -228,6 +231,9 @@ resync (0005) and the deck lists the audience may see (0019).
|
||||
| `0x100` | `FEATURE_DECK_LIST` | 6 | 0019 | Deck lists |
|
||||
| `0x200` | `FEATURE_PROFILE` | 7 | 0020 | Profile |
|
||||
| `0x400` | `FEATURE_ATTACK_PREVIEW` | 8 | 0023 | Attack preview over the wire |
|
||||
| `0x800` | reserved | - | - | Proposal 44 (agreed, not shipped) |
|
||||
| `0x1000` | reserved | - | - | Proposal 45 (agreed, not shipped) |
|
||||
| `0x2000` | `FEATURE_TAG_PARTNER_CARDS` | 9 | v1.2.0 | Tag partner cards (`STOC_TAG_PARTNER_CARDS`, `ygol_query_tag_cards`) |
|
||||
|
||||
`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
|
||||
@@ -351,7 +357,7 @@ fork-related rows are marked.
|
||||
| 142 | `MSG_ANNOUNCE_CARD` | `u8 player`; `n` x 4 | yes |
|
||||
| 143 | `MSG_ANNOUNCE_NUMBER` | `u8 player`; `n` x 4 | yes |
|
||||
| 160 | `MSG_CARD_HINT` | 9 | - |
|
||||
| 161 | `MSG_TAG_SWAP` | `u8 player`, `u8 main count`, `u8 extra count`, `u8 extra pendulum count`, `u8 hand count`, `u32 top code`, then `u32` x hand, `u32` x extra. Not in `Scan` (the bot host never runs Tag). **Fork (core patch 0015): never emitted on a team's first turn; the first swap comes on turn 3 or later.** | - |
|
||||
| 161 | `MSG_TAG_SWAP` | `u8 player`, `u8 main count`, `u8 extra count`, `u8 extra pendulum count`, `u8 hand count`, `u32 top code`, then `u32` x hand, `u32` x extra. Not in `Scan` (the bot host never runs Tag). **Fork (core patch 0015): never emitted on a team's first turn; the first swap comes on turn 3 or later. v1.2.0: the server follows every swap with `STOC_TAG_PARTNER_CARDS` to the swapping side's two seats.** | - |
|
||||
| 162 | `MSG_RELOAD_FIELD` | `u8 duel rule`; per player: `u32 lp`, 7 monster zones (`u8 present`, +2 when present), 8 spell zones (`u8 present`, +1 when present), 6 count bytes; then ONE chain block `n` x 15 after both players. Produced by `query_field_info` and `Debug.ReloadFieldEnd()`; the server sends it as the 0005 field resync | - |
|
||||
| 163 | `MSG_AI_NAME` | `u16 len` + bytes + 1 | - |
|
||||
| 164 | `MSG_SHOW_HINT` | `u16 len` + bytes + 1 | - |
|
||||
@@ -415,7 +421,7 @@ Namespaces:
|
||||
|
||||
| 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). |
|
||||
| `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. |
|
||||
| `YGOLegacy.Engine` | The four types below (TICKET-398). |
|
||||
|
||||
| Type | What |
|
||||
@@ -456,6 +462,7 @@ Every row is one export of section (a) with its managed signature. A `string` pa
|
||||
| `preload_script` | `int preload_script(IntPtr pduel, string script_name)` |
|
||||
| `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_query_tag_cards` | `int ygol_query_tag_cards(IntPtr pduel, byte playerid, byte[] @out)` |
|
||||
| `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)` |
|
||||
| `get_registry_keys` | `int get_registry_keys(IntPtr pduel, byte[] out_buf)` |
|
||||
|
||||
@@ -83,6 +83,13 @@ OCGCORE_API byte* default_script_reader(const char* script_name, int* len);
|
||||
// the duel is byte-identical afterwards (proposal 43).
|
||||
OCGCORE_API 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);
|
||||
|
||||
// [YGOL] v1.2.0 (tag partner cards, TICKET-405): the waiting tag partner's cards of playerid's side, read
|
||||
// only. out: version (1), hand count, extra count, one pad byte, uint16 deck count, then the uint32 hand
|
||||
// codes, the uint32 extra codes (bit 31 = face-up, like MSG_TAG_SWAP) and the uint32 deck codes sorted
|
||||
// ascending (the order stays secret). Returns the byte length, 0 refused (bad pointer, bad player, not a
|
||||
// tag duel); a refusal writes nothing. The duel is byte-identical afterwards (proposal 33 Rule 11).
|
||||
OCGCORE_API int32_t ygol_query_tag_cards(intptr_t pduel, uint8_t playerid, uint8_t* out);
|
||||
|
||||
// koishi specific
|
||||
OCGCORE_API int32_t get_registry_value(intptr_t pduel, const char* key, byte* out_buf);
|
||||
OCGCORE_API void set_registry_value(intptr_t pduel, const char* key, const char* value);
|
||||
|
||||
@@ -121,6 +121,18 @@
|
||||
# a wrong version, too many pairs and a wrong length are dropped without a reply;
|
||||
# a seat that never asks gets no 0x5E and the duel goes on. Single and Tag.
|
||||
#
|
||||
# With --dll it also gates v1.2.0 (TICKET-405, tag partner cards): the server's
|
||||
# capability says protocol 9 + flag 0x2000 (single and tag); in a Tag room each
|
||||
# seat gets TAG_PARTNER_CARDS (0x5F: side, version 1, hand count, extra count,
|
||||
# pad, u16 deck count, then the hand, Extra Deck and deck codes) for its own side
|
||||
# only -- at the start the waiting member's 5-card opening hand, its two Probe
|
||||
# Fusions and its 35 remaining cards SORTED; after each MSG_TAG_SWAP the member
|
||||
# that just left, hand = every card it drew, deck = its deck minus them; a seat's
|
||||
# field resync (CTOS_REQUEST_FIELD) carries the same list again to that seat
|
||||
# alone -- and the other team, the watcher, a watcher's resync and a late
|
||||
# watcher's snapshot never get one. The hand a swap brings in is the hand the
|
||||
# opening 0x5F announced.
|
||||
#
|
||||
# Exit 0 only when every check passed. Stock DLL: the first check fails; the
|
||||
# 0011 DLL fails at the capability flags.
|
||||
import argparse, base64, ctypes, lzma, os, shutil, socket, sqlite3, struct, sys, tempfile, threading, time
|
||||
@@ -266,7 +278,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)
|
||||
if server_caps:
|
||||
proto, flags = struct.unpack_from("<HI", server_caps[0][1], 2)
|
||||
check(proto == 8 and flags == 0x7FF, "%s: server capability is protocol 8, flags 0x7FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview), got %d / 0x%x" % (who, proto, flags))
|
||||
check(proto == 9 and flags == 0x27FF, "%s: server capability is protocol 9, flags 0x27FF (appearance | dialogue | setup pairs | seat plan | rules restart | seat state | lobby after match | coin toss | deck lists | profile | attack preview | tag partner cards), got %d / 0x%x" % (who, proto, flags))
|
||||
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]
|
||||
apps = [i for i, (p, d) in enumerate(pkts) if p == STOC_APPEARANCE and struct.unpack_from("<H", d, 0)[0] == seat]
|
||||
@@ -323,6 +335,7 @@ def main():
|
||||
deck_list_suite(o.dll, port + 80)
|
||||
profile_suite(o.dll, port + 90)
|
||||
attack_preview_suite(o.dll, port + 100)
|
||||
tag_partner_suite(o.dll, port + 110)
|
||||
print()
|
||||
if failures:
|
||||
print("FAILED: %d check(s)" % len(failures))
|
||||
@@ -494,6 +507,9 @@ def make_workspace():
|
||||
# patch 0023: a level-4 normal monster, so a seat can summon without a tribute and attack with it
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 17, 1800, 1000, 4, 1, 16, 0)", (PROBE_KNIGHT,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Knight', ''" + ", ''" * 16 + ")", (PROBE_KNIGHT,))
|
||||
# v1.2.0 (TICKET-405): a Fusion monster, so a submitted deck has an Extra Deck
|
||||
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 65, 2000, 2000, 6, 1, 16, 0)", (PROBE_FUSION,))
|
||||
db.execute("INSERT INTO texts VALUES(?, 'Probe Fusion', ''" + ", ''" * 16 + ")", (PROBE_FUSION,))
|
||||
db.commit()
|
||||
db.close()
|
||||
return root
|
||||
@@ -2525,5 +2541,187 @@ def attack_preview_suite(dll_path, port):
|
||||
attack_preview_room(dll_path, port + 1, "tag", 2)
|
||||
|
||||
|
||||
# --- v1.2.0 (TICKET-405): tag partner cards --------------------------------------
|
||||
STOC_TAG_PARTNER_CARDS, CTOS_REQUEST_FIELD, MSG_RELOAD_FIELD = 0x5F, 0x30, 162
|
||||
NAMES.update({0x5F: "TAG_PARTNER_CARDS"})
|
||||
PROBE_FUSION = PROBE_CARD + 600 # a Fusion monster: it goes to the Extra Deck
|
||||
TAG_PARTNER_DECKS = [DECK_LIST_CODES[seat] + [PROBE_FUSION, PROBE_FUSION] for seat in range(4)]
|
||||
|
||||
|
||||
def partner_cards(pkts, side=None):
|
||||
# (side, version, hand, extra, deck, size); hand / extra / deck are None when the size does not match the counts
|
||||
out = []
|
||||
for p, d in pkts:
|
||||
if p != STOC_TAG_PARTNER_CARDS or len(d) < 7:
|
||||
continue
|
||||
s, version, hand_n, extra_n, _pad, deck_n = struct.unpack_from("<BBBBBH", d, 0)
|
||||
if side is not None and s != side:
|
||||
continue
|
||||
n = hand_n + extra_n + deck_n
|
||||
if len(d) != 7 + 4 * n:
|
||||
out.append((s, version, None, None, None, len(d)))
|
||||
continue
|
||||
codes = list(struct.unpack_from("<%dI" % n, d, 7))
|
||||
out.append((s, version, codes[:hand_n], codes[hand_n:hand_n + extra_n], codes[hand_n + extra_n:], len(d)))
|
||||
return out
|
||||
|
||||
|
||||
def server_capability(pkts):
|
||||
for p, d in pkts:
|
||||
if p == STOC_CAPABILITY and len(d) == 8 and struct.unpack_from("<H", d, 0)[0] == SERVER:
|
||||
return struct.unpack_from("<HI", d, 2)
|
||||
return None
|
||||
|
||||
|
||||
def tag_swap_hand(d):
|
||||
# MSG_TAG_SWAP: player, main count, extra count, pendulum count, hand count, u32 top, u32 x hand, u32 x extra
|
||||
hcount = d[5]
|
||||
return [c & 0x7FFFFFFF for c in struct.unpack_from("<%dI" % hcount, d, 10)]
|
||||
|
||||
|
||||
def tag_partner_room(dll_path, port, label):
|
||||
print("== tag partner cards, %s (4 seats + a watcher: the opening hands, both swaps, a seat's field resync, a late watcher)" % label)
|
||||
root = make_workspace()
|
||||
here = os.getcwd()
|
||||
os.chdir(root)
|
||||
try:
|
||||
write_special(root, [])
|
||||
dll, thread = host_dll(dll_path, port, 2)
|
||||
clients = []
|
||||
|
||||
def client(name):
|
||||
c = Client("127.0.0.1", port, name)
|
||||
c.log = list(c.join())
|
||||
clients.append(c)
|
||||
return c
|
||||
|
||||
seated = [client("tp-seat%d" % i) for i in range(4)]
|
||||
w = client("tp-watch")
|
||||
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]))
|
||||
cap = server_capability(seated[0].log)
|
||||
check(cap == (9, 0x27FF), "%s: the tag server's capability is protocol 9, flags 0x27FF (got %s)" % (label, cap))
|
||||
drain_all(everyone)
|
||||
for c in seated:
|
||||
c.send(CTOS_UPDATE_DECK, deck_bytes(TAG_PARTNER_DECKS[c.seat]))
|
||||
pump(everyone, lambda: False, limit=0.8)
|
||||
marks = start_duel_on(label, seated[0], everyone, None, "tag partner cards")
|
||||
ok = pump(everyone, lambda: all(len(draws(since(c, marks))) >= 2 for c in everyone) and any(game_msgs(since(c, marks), MSG_SELECT_IDLECMD) for c in seated), limit=10)
|
||||
check(ok, "%s: the opening draws and the first idle prompt reached the seats" % label)
|
||||
side_of = {}
|
||||
for c in seated:
|
||||
s = starts(since(c, marks))
|
||||
side_of[c] = s[0] if len(s) == 1 else -1
|
||||
by_side = {p: [c for c in seated if side_of[c] == p] for p in (0, 1)}
|
||||
if not check(all(len(by_side[p]) == 2 for p in (0, 1)), "%s: every seat got one MSG_START naming its side (%s)" % (label, {k: [c.name for c in v] for k, v in by_side.items()})):
|
||||
return
|
||||
first_seat = {p: min(c.seat for c in by_side[p]) for p in (0, 1)}
|
||||
partner_seat = {p: max(c.seat for c in by_side[p]) for p in (0, 1)}
|
||||
extra_expected = [PROBE_FUSION, PROBE_FUSION]
|
||||
|
||||
def check_cards(side, since_marks, stage, waiting_seat, expect_hand=None):
|
||||
pool = set(DECK_LIST_CODES[waiting_seat])
|
||||
latest = None
|
||||
for c in by_side[side]:
|
||||
got = partner_cards(since(c, since_marks), side)
|
||||
check(len(got) == 1, "%s: %s: seat %d got exactly one TAG_PARTNER_CARDS for its side %d (%d)" % (label, stage, c.seat, side, len(got)))
|
||||
check(not partner_cards(since(c, since_marks), 1 - side), "%s: %s: seat %d got none for the other side" % (label, stage, c.seat))
|
||||
if not got:
|
||||
continue
|
||||
s, version, hand, extra, deck, size = got[-1]
|
||||
if not check(hand is not None, "%s: %s: seat %d's TAG_PARTNER_CARDS is 7 + 4 x counts bytes (%d)" % (label, stage, c.seat, size)):
|
||||
continue
|
||||
check(version == 1, "%s: %s: seat %d's list is version 1 (%d)" % (label, stage, c.seat, version))
|
||||
if expect_hand is None:
|
||||
check(len(hand) == 5 and set(hand) <= pool, "%s: %s: seat %d's partner hand is 5 cards of seat %d's deck (%s)" % (label, stage, c.seat, waiting_seat, hand))
|
||||
else:
|
||||
check(sorted(hand) == sorted(expect_hand), "%s: %s: seat %d's partner hand is every card seat %d drew (%d; expected %d)" % (label, stage, c.seat, waiting_seat, len(hand), len(expect_hand)))
|
||||
check(extra == extra_expected, "%s: %s: seat %d's partner Extra Deck is the two Probe Fusions, face-down (%s)" % (label, stage, c.seat, extra))
|
||||
check(deck == sorted(deck) and len(deck) == len(set(deck)), "%s: %s: seat %d's partner deck is sorted ascending" % (label, stage, c.seat))
|
||||
check(deck == sorted(pool - set(hand)), "%s: %s: seat %d's partner deck is seat %d's Main Deck minus the hand (%d)" % (label, stage, c.seat, waiting_seat, len(deck)))
|
||||
latest = got[-1]
|
||||
for c in by_side[1 - side]:
|
||||
check(not partner_cards(since(c, since_marks), side), "%s: %s: seat %d (the other team) got no TAG_PARTNER_CARDS for side %d" % (label, stage, c.seat, side))
|
||||
check(not partner_cards(since(w, since_marks)), "%s: %s: the watcher got no TAG_PARTNER_CARDS" % (label, stage))
|
||||
return latest
|
||||
|
||||
opening = {}
|
||||
for p in (0, 1):
|
||||
opening[p] = check_cards(p, marks, "opening", partner_seat[p])
|
||||
|
||||
def end_turn(stage):
|
||||
holders = [c for c in seated if game_msgs(since(c, end_turn.marks), MSG_SELECT_IDLECMD)]
|
||||
check(len(holders) == 1, "%s: %s: exactly one seat holds the idle prompt (%s)" % (label, stage, [c.name for c in holders]))
|
||||
if not holders:
|
||||
return None
|
||||
before = marks_of(everyone)
|
||||
holders[0].send(CTOS_TIME_CONFIRM) # the timed server holds the seat until the clock is acknowledged
|
||||
holders[0].send(CTOS_RESPONSE, struct.pack("<i", 7)) # idle command 7: to the End Phase
|
||||
ok = pump(everyone, lambda: any(draws(since(c, before)) for c in seated) and any(game_msgs(since(c, before), MSG_SELECT_IDLECMD) for c in seated), limit=10, chain=True)
|
||||
check(ok, "%s: %s: the turn passed and the next seat drew" % (label, stage))
|
||||
end_turn.marks = before
|
||||
return before
|
||||
end_turn.marks = marks
|
||||
|
||||
def check_swap(side, before, stage):
|
||||
owner = by_side[side][0]
|
||||
new = since(owner, before)
|
||||
cut = next((i for i, (pid, _) in enumerate(new) if pid == STOC_TAG_PARTNER_CARDS), None)
|
||||
if not check(cut is not None, "%s: %s: side %d got a TAG_PARTNER_CARDS after its swap" % (label, stage, side)):
|
||||
return
|
||||
pre = owner.log[marks[owner]:before[owner] + cut]
|
||||
drawn = [x for d in draws(pre, side) for x in draw_codes(d)]
|
||||
check(len(drawn) >= 5, "%s: %s: seat %d drew %d cards before the swap" % (label, stage, first_seat[side], len(drawn)))
|
||||
check_cards(side, before, stage, first_seat[side], expect_hand=drawn)
|
||||
swaps = [d for d in game_msgs(new, MSG_TAG_SWAP) if len(d) > 10 and d[1] == side]
|
||||
check(len(swaps) == 1, "%s: %s: side %d saw one MSG_TAG_SWAP for itself (%d)" % (label, stage, side, len(swaps)))
|
||||
if swaps and opening.get(side) and opening[side][2] is not None:
|
||||
check(sorted(tag_swap_hand(swaps[0])) == sorted(opening[side][2]), "%s: %s: the hand the swap brought in is the hand the opening TAG_PARTNER_CARDS announced" % (label, stage))
|
||||
|
||||
before = end_turn("pass 1") # turn 2: side 1's first turn, no swap
|
||||
if before:
|
||||
check(all(not partner_cards(since(c, before)) for c in everyone), "%s: pass 1: a turn without a swap sent nobody a TAG_PARTNER_CARDS" % label)
|
||||
before = end_turn("pass 2") # turn 3: side 0 swaps to its partner
|
||||
if before:
|
||||
check_swap(0, before, "pass 2")
|
||||
before = end_turn("pass 3") # turn 4: side 1 swaps to its partner
|
||||
if before:
|
||||
check_swap(1, before, "pass 3")
|
||||
|
||||
asker = by_side[0][1]
|
||||
last = partner_cards(asker.log[marks[asker]:], 0)
|
||||
marks3 = marks_of(everyone)
|
||||
asker.send(CTOS_REQUEST_FIELD)
|
||||
w.send(CTOS_REQUEST_FIELD)
|
||||
pump(everyone, lambda: partner_cards(since(asker, marks3)) and game_msgs(since(w, marks3), MSG_RELOAD_FIELD), limit=3)
|
||||
got = partner_cards(since(asker, marks3), 0)
|
||||
check(len(got) == 1 and bool(game_msgs(since(asker, marks3), MSG_RELOAD_FIELD)), "%s: a seat's field resync carried one TAG_PARTNER_CARDS for its side (%d)" % (label, len(got)))
|
||||
check(bool(got) and bool(last) and got[0][2:5] == last[-1][2:5], "%s: the resync list equals the last list that seat got" % label)
|
||||
check(bool(game_msgs(since(w, marks3), MSG_RELOAD_FIELD)) and all(not partner_cards(since(c, marks3)) for c in everyone if c is not asker), "%s: the watcher's resync and everyone else carried no TAG_PARTNER_CARDS" % label)
|
||||
|
||||
l = client("tp-late")
|
||||
l.log += l.drain(quiet=0.6)
|
||||
check(l.seat == OBSERVER and STOC_DUEL_START in ids_of(l.log), "%s: a mid-duel joiner is an observer and got DUEL_START" % label)
|
||||
check(not partner_cards(l.log), "%s: the late watcher's snapshot has no TAG_PARTNER_CARDS" % label)
|
||||
|
||||
marks4 = marks_of(everyone + [l])
|
||||
for c in by_side[0]:
|
||||
c.send(CTOS_SURRENDER)
|
||||
ok = pump(everyone + [l], lambda: all(match_overs(since(c, marks4)) for c in everyone + [l]), limit=10)
|
||||
check(ok, "%s: side 0 surrendered: MATCH_OVER reached everyone" % label)
|
||||
for c in clients:
|
||||
c.close()
|
||||
stop_dll(dll, thread, label)
|
||||
finally:
|
||||
os.chdir(here)
|
||||
shutil.rmtree(root, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_partner_suite(dll_path, port):
|
||||
print()
|
||||
print("hosting the tag partner cards room from %s" % dll_path)
|
||||
tag_partner_room(dll_path, port, "tag")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user