server: FEATURE_TAG_TWO_FIELDS 0x1000, protocol 10, a Tag room refuses a joiner without it (TICKET-384, v1.5.0)
Release / linux (push) Successful in 1m27s
Release / windows (push) Successful in 36s
Release / android (push) Successful in 48s
Release / release (push) Successful in 3s
Release / attach-windows (push) Successful in 0s

Single and Tag rooms advertise the bit; TagDuel::Capability answers a client whose
capability lacks it with ERRMSG_VERERROR and closes the connection. Binding:
FeatureFlags.TagTwoFields (in All), Capability.ProtocolVersion 10, tests pinned.
Probe: the tag two Field slots rooms (placement on turns 1, 3 and 5 with the core's
own view reported by the Probe Field's script, the Tag refusal, the Single room that
keeps an old client); the capability pins move to 10 / 0x37FF. Contract: the 0x1000
row, the v1.5.0 behaviour row, the Lua note; CHANGELOG v1.5.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
donnyandClaude Fable 5.1 committed 2026-10-24 18:35:21 -07:00
1 parent bcd19c9cd0
commit c2eca90644
8 files changed
+279 -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
are the fork patches replayed into this repo as commits (`git log --oneline -- server/gframe core`).
## v1.5.0 — 2026-10-24
Tag two Field slots (proposal 45): a Tag team on Master Rule 4/5 holds one Field Spell per partner. No new
export or message; capability `0x1000`, protocol 10: exports 335 / 856 / 850, capabilities `0x37FF`.
| Date | Change | Ticket | Contract part |
|---|---|---|---|
| 2026-10-24 | Core: `field::has_two_fields()` (`DUEL_TAG_MODE` on Master Rule 4 or 5) gives each team a Field slot per partner, Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other (`player_info::tag_partner`, flipped in `tag_swap`; `get_szone_size` is 7 there). A Field Spell lands in the playing partner's slot (`get_fzone_landing`) and replaces only that card; a control change takes the free slot when the playing partner's is taken. A Set offers only the landing slot's bit. `LOCATION_FZONE` covers both slots in `card_state::is_location`, `filter_matching_card`, `filter_field_card`, `is_location_useable` and `Duel.IsEnvironment`; `get_field_card(p, LOCATION_FZONE, 0)` is the playing partner's field, else the other, and 1 the remaining one. Singles, Match and Master Rule 3 unchanged. | TICKET-384 | (c) `MSG_MOVE` / `MSG_RELOAD_FIELD` carry Spell/Trap sequence 6 (rules only); (d) Lua API: a second answer for `Duel.GetFieldCard` / `Duel.CheckLocation` with `LOCATION_FZONE` |
| 2026-10-24 | Server: `FEATURE_TAG_TWO_FIELDS` `0x1000` advertised by Single and Tag rooms, protocol 9 -> 10; a Tag room answers a `CTOS_CAPABILITY` without the bit with `STOC_ERROR_MSG` `ERRMSG_VERERROR` and closes the connection (`TagDuel::Capability`). | TICKET-384 | Wire: capability bit `0x1000`, protocol 10 |
| 2026-10-24 | Binding: `FeatureFlags.TagTwoFields` (in `All`), `Capability.ProtocolVersion` 10. Probe: the tag two Field slots rooms (a Tag room's placement on turns 1, 3 and 5 with the core's own view reported by the Probe Field's script, the Tag refusal, the Single room that keeps an old client). | TICKET-384 | (e) C# binding |
## v1.4.2 — 2026-10-24
Tag partner cards follow every change. Same message, same payload, no new export or capability bit:
@@ -158,7 +158,7 @@ namespace YGOLegacy.Protocol.Tests
Assert.That((int)StocCodecs.SeatResumeResult.Id, Is.EqualTo(0x57));
Assert.That((int)StocCodecs.RestartOpened.Id, Is.EqualTo(0x58));
Assert.That(FeatureFlags.RulesRestart, Is.EqualTo(0x10));
Assert.That(FeatureFlags.All, Is.EqualTo(0x27FB));
Assert.That(FeatureFlags.All, Is.EqualTo(0x37FB));
var id = Enumerable.Repeat((byte)0xAB, 16).ToArray();
var token = Enumerable.Range(1, 16).Select(i => (byte)i).ToArray();
@@ -272,13 +272,21 @@ namespace YGOLegacy.Protocol.Tests
Assert.Throws<EndOfStreamException>(() => StocCodecs.AttackPreview.Read(Reader(new byte[] { 1 })));
}
[Test]
public void TagTwoFields_Flag_AndProtocol_ArePinned_0x1000_10()
{
Assert.That(FeatureFlags.TagTwoFields, Is.EqualTo(0x1000));
Assert.That(FeatureFlags.All & FeatureFlags.TagTwoFields, Is.EqualTo(FeatureFlags.TagTwoFields));
Assert.That(Capability.ProtocolVersion, Is.EqualTo(10));
}
[Test]
public void TagPartnerCards_Id_Flag_Protocol_AndRoundTrip_ArePinned_0x5F_0x2000_9()
{
Assert.That((int)StocCodecs.TagPartnerCards.Id, Is.EqualTo(0x5F));
Assert.That(FeatureFlags.TagPartnerCards, Is.EqualTo(0x2000));
Assert.That(FeatureFlags.All & FeatureFlags.TagPartnerCards, Is.EqualTo(FeatureFlags.TagPartnerCards));
Assert.That(Capability.ProtocolVersion, Is.EqualTo(9));
Assert.That(Capability.ProtocolVersion, Is.EqualTo(10));
Assert.That(TagPartnerCardsCodec.HeaderSize, Is.EqualTo(7));
var faceUpPendulum = 0x80000000u | 16178681u;
@@ -422,7 +430,7 @@ namespace YGOLegacy.Protocol.Tests
{
var bytes = Bytes(w => LobbyCodecs.Capability.Write(w, new Capability(Capability.ProtocolVersion, FeatureFlags.All)));
Assert.That(bytes, Is.EqualTo(Concat(Le16(9), Le32(0x27FB))));
Assert.That(bytes, Is.EqualTo(Concat(Le16(10), Le32(0x37FB))));
var read = LobbyCodecs.Capability.Read(Reader(bytes));
Assert.That(read.Protocol, Is.EqualTo(Capability.ProtocolVersion));
@@ -6,7 +6,7 @@ namespace YGOLegacy.Protocol.Contracts
{
public const uint Appearance = 0x1;
public const uint Dialogue = 0x2;
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagPartnerCards;
public const uint All = Appearance | Dialogue | SeatPlan | RulesRestart | SeatState | LobbyAfterMatch | CoinToss | DeckList | Profile | AttackPreview | TagTwoFields | TagPartnerCards;
// Server-only: the host relays setup pairs (0x43); a client never advertises it.
public const uint SetupPairs = 0x4;
// Server: chosen seats (0x50-0x53). Client: it renders the seat plan.
@@ -25,7 +25,9 @@ namespace YGOLegacy.Protocol.Contracts
public const uint Profile = 0x200;
// Server: attack preview (0x5E): the seat whose battle prompt is open asks for its pairs, the host's core answers. Client: it shows the badge.
public const uint AttackPreview = 0x400;
// Server: tag partner cards (0x5F): the waiting teammate's hand, Extra Deck and deck go to that side's two seats. Client: the partner view shows them. 0x800 and 0x1000 are reserved by proposals 44 and 45.
// Server: Tag on Master Rule 4/5 gives each partner a Field slot (Spell/Trap sequence 5 and 6); a Tag room refuses a joiner without the bit. Client: it shows sequence 6 as the Field Zone and refuses a host without the bit. 0x800 is reserved by proposal 44.
public const uint TagTwoFields = 0x1000;
// Server: tag partner cards (0x5F): the waiting teammate's hand, Extra Deck and deck go to that side's two seats. Client: the partner view shows them.
public const uint TagPartnerCards = 0x2000;
// Client role, not a feature: set only on the room host's own line, so every peer can badge the host's seat.
public const uint RoomHost = 0x80000000;
@@ -56,7 +58,7 @@ namespace YGOLegacy.Protocol.Contracts
public readonly struct Capability
{
public const ushort ProtocolVersion = 9;
public const ushort ProtocolVersion = 10;
public const int ServerSender = 0xFF;
public ushort Protocol { get; }
+16 -10
View File
@@ -26,8 +26,8 @@ next to the library (`out/win64/engine.json` on Windows):
{
"version": "v0.0.1",
"exports": 335,
"protocol": 9,
"capabilities": 10239,
"protocol": 10,
"capabilities": 14335,
"binding": "v0.0.1"
}
```
@@ -36,8 +36,8 @@ next to the library (`out/win64/engine.json` on Windows):
|---|---|---|
| `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). |
| `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). |
| `protocol` | integer | `FEATURE_PROTOCOL` in `server/gframe/network.h` (10 as of 2026-10-24). |
| `capabilities` | integer | The OR of every `FEATURE_*` bit `SendServerCapability` advertises (`single_duel.cpp` and `tag_duel.cpp` must agree), as a decimal integer. 14335 = `0x37FF` = bits `0x1` to `0x400` plus `0x1000` and `0x2000` (`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`. |
The build reads `protocol` and `capabilities` from the source every time; nothing types them in.
@@ -165,9 +165,11 @@ 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` (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.
`STOC_JOIN_GAME` and `STOC_TYPE_CHANGE`: `protocol` = `FEATURE_PROTOCOL` (10) and `flags` = the OR of
the bits below (`0x37FF`). 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
client whose `CTOS_CAPABILITY` lacks `0x1000`: `STOC_ERROR_MSG` `ERRMSG_VERERROR` (code =
`FEATURE_PROTOCOL`), then the connection is closed; a Single room keeps it.
**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,
@@ -232,7 +234,7 @@ duelist's own side (v1.2.0), both sides for an observer when spectators see all
| `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) |
| `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`) |
`FEATURE_PROTOCOL` is bumped by every patch that adds a message a client must understand; the join
@@ -252,6 +254,7 @@ carry a new feature inside another feature's message.
| v1.1.1 | Tag: no Battle Phase on turns 1, 2 and 3 (1A, 2A, 1B); the fourth duelist (2B) is the first who can battle. `MSG_SELECT_IDLECMD` carries `to_bp` = 0 on those turns and `Duel.IsAbleToEnterBP` answers false. Single duels: turn 1 only, as stock. |
| v1.3.0 | Tag partner cards reach observers: when spectators see all, `STOC_TAG_PARTNER_CARDS` goes to every observer for both sides at every send point, plus both sides in an observer's resync and the late-watcher snapshot. Same id, same payload, no new capability bit (TICKET-412). |
| v1.4.0 | Life points per side: with the setup pair `ygol.side.b.lp=<n>` (section (d)) seat side B (seat 1; Tag seats 2 and 3) starts at `n` LP and side A at slot 8; without it both sides start at slot 8, as before. `set_player_info` gets each duel player its own LP, and `MSG_START` (the start and the late-watcher snapshot) carries `lp[0]`, `lp[1]` in duel player order: the side that goes first is player 0, so the two values swap when side B won the toss. `STOC_JOIN_GAME`'s `start_lp` stays side A's. Single, Match (every duel) and Tag; no new message, no capability bit. |
| v1.5.0 | Tag two Field slots (proposal 45, TICKET-384; core `field::has_two_fields` = `DUEL_TAG_MODE` on Master Rule 4 or 5): a team has a Field slot per partner, Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other (`player_info::tag_partner` flips in `tag_swap`). A Field Spell that lands (activated, Set, `Duel.MoveToField` to `LOCATION_FZONE`) goes to the playing partner's slot and replaces only the card there; one that changes control while that slot is taken and the other is free takes the free one. A Set opens only the landing slot's bit in `MSG_SELECT_PLACE`. `LOCATION_FZONE` covers both slots (`Card.IsLocation`, `Duel.GetMatchingGroup` and the other filters, `Duel.IsEnvironment`, `Duel.CheckLocation(p, LOCATION_FZONE, 0/1)`), `Duel.GetFieldCard(p, LOCATION_FZONE, 0)` is the playing partner's field, else the other one, and sequence 1 the remaining one; `Duel.GetFieldCard(p, LOCATION_SZONE, 6)` works. The second field reaches a client as `MSG_MOVE` to Spell/Trap sequence 6 and in `MSG_RELOAD_FIELD`'s sixth Spell/Trap entry: no new message. Singles, Match and Master Rule 3 (where slot 6 is a Pendulum Zone) are unchanged. Scripts that name Spell/Trap sequence 5 by number see one field (the TICKET-384 closing note lists them). Capability `0x1000`, protocol 9 -> 10. |
### Replay
@@ -414,7 +417,10 @@ into `contract/lua-reference/`: `api-card.md`, `api-duel.md`, `api-effect.md`, `
the core sets). A name that is not there is not in the core; the card scripts' `library/` defines the
rest. Regenerate with `python contract/lua-reference/generate.py` after any core change to those
files and commit the result with it. The fork's core patches add no Lua function (0001 adds the
setcode `0xFDF`, `SETCODE_FACEDOWN_TOKEN`, as a cdb convention, not an API).
setcode `0xFDF`, `SETCODE_FACEDOWN_TOKEN`, as a cdb convention, not an API). v1.5.0 gives two
existing calls a second answer in Tag on Master Rule 4/5: `Duel.GetFieldCard(p, LOCATION_FZONE, 1)`
is the other partner's field and `Duel.CheckLocation(p, LOCATION_FZONE, 1)` asks about its slot
(both say nothing elsewhere, as before).
## (e) C# binding
@@ -429,7 +435,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); 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`). |
| `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.Engine` | The four types below (TICKET-398). |
| Type | What |
+219 -4
View File
@@ -123,7 +123,7 @@
# 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
# capability said protocol 9 + flag 0x2000 (single and tag; 10 / 0x1000 since v1.5.0); 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
@@ -149,6 +149,17 @@
# MSG_SPSUMMONING and the next MSG_TAG_SWAP seats 2 and 3 get exactly one
# TAG_PARTNER_CARDS, for side 1 with an empty Extra Deck, and seats 0 and 1 none.
#
# With --dll it also gates v1.5.0 (proposal 45 / TICKET-384, Tag two Field slots):
# the capability says protocol 10 + flag 0x1000 (single and tag); a Tag room
# refuses a joiner whose CTOS_CAPABILITY lacks 0x1000 (ERROR_MSG VERERROR, then
# disconnected) and keeps one that has it, a Single room keeps both; in a Tag room
# seat 0's Field Spell lands in Spell/Trap sequence 5 on turn 1, seat 1's in
# sequence 6 on turn 3 while the first stays, and seat 0's next Field on turn 5
# sends only the sequence-5 card to the Graveyard. The Field's own script reports
# in a HINT what the core sees: LOCATION_FZONE counts both slots,
# Duel.GetFieldCard(tp, LOCATION_FZONE, 0) is the playing partner's field and 1
# the other, Duel.IsEnvironment and Card.IsLocation see sequence 6.
#
# 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
@@ -294,7 +305,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 == 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))
check(proto == 10 and flags == 0x37FF, "%s: server capability is protocol 10, flags 0x37FF (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), 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]
@@ -356,6 +367,7 @@ def main():
attack_preview_suite(o.dll, port + 100)
tag_partner_suite(o.dll, port + 110)
tag_across_swap_suite(o.dll, port + 120)
tag_two_fields_suite(o.dll, port + 130)
print()
if failures:
print("FAILED: %d check(s)" % len(failures))
@@ -538,6 +550,14 @@ def make_workspace():
db.close()
with open(os.path.join(root, "script", "c%d.lua" % PROBE_TIME_FUSION), "w", newline="\n") as f:
f.write(TIME_FUSION_LUA)
# proposal 45 (TICKET-384): a Field Spell, so a Tag team can hold one per partner
db = sqlite3.connect(os.path.join(root, "cards.cdb"))
db.execute("INSERT INTO datas VALUES(?, 3, 0, 0, 524290, 0, 0, 0, 0, 0, 0)", (PROBE_FIELD,))
db.execute("INSERT INTO texts VALUES(?, 'Probe Field', ''" + ", ''" * 16 + ")", (PROBE_FIELD,))
db.commit()
db.close()
with open(os.path.join(root, "script", "c%d.lua" % PROBE_FIELD), "w", newline="\n") as f:
f.write(FIELD_LUA)
return root
@@ -1121,7 +1141,7 @@ def restart_room(dll_path, port, label, mode):
pk = drain_all([h, g, w])
check(not statuses(pk[g]) and not restarting(pk[h]), "%s: a non-host's Prepare is ignored" % label)
for c in (h, g, w):
c.send(CTOS_CAPABILITY, capability_bytes(2, 0x1F))
c.send(CTOS_CAPABILITY, capability_bytes(2, 0x1F | FEATURE_TAG_TWO_FIELDS)) # a Tag room refuses a client without 0x1000 (proposal 45)
drain_all([h, g, w])
h.send(CTOS_RESTART_PREPARE, prepare_bytes(rid, 30000, seats + 1, [ta, tb], tw))
pk = drain_all([h, g, w])
@@ -2670,7 +2690,7 @@ def tag_partner_room(dll_path, port, label, hidden):
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))
check(cap == (10, 0x37FF), "%s: the tag server's capability is protocol 10, flags 0x37FF (got %s)" % (label, cap))
drain_all(everyone)
for c in seated:
c.send(CTOS_UPDATE_DECK, deck_bytes(TAG_PARTNER_DECKS[c.seat]))
@@ -2995,5 +3015,200 @@ def tag_across_swap_suite(dll_path, port):
print("hosting the tag card across the swap room from %s" % dll_path)
tag_across_swap_room(dll_path, port, "tag")
# --- proposal 45 (TICKET-384): Tag two Field slots ---------------------------------------------
# In Tag on Master Rule 4/5 each partner has a Field slot: Spell/Trap sequence 5 for the partner
# who plays the team's first turn, 6 for the other. A Field Spell lands in the playing partner's
# slot and replaces only that slot; LOCATION_FZONE covers both. Capability 0x1000, protocol 10; a
# Tag room refuses a client whose capability lacks the bit, a Single room does not care.
FEATURE_TAG_TWO_FIELDS = 0x1000
PROBE_FIELD = PROBE_CARD + 800
MSG_MOVE, MSG_HINT, HINT_CARD, LOCATION_SZONE, LOCATION_GRAVE = 50, 2, 10, 0x08, 0x10
STOC_ERROR_MSG, ERRMSG_VERERROR = 0x02, 0x4
FIELD_LUA = """--Probe Field (proposal 45): a Field Spell with no effect of its own. On activation it reports what the core
--sees of its team's Field Zone in one MSG_HINT (HINT_CARD): bits 0-3 = Duel.GetFieldGroupCount(tp, LOCATION_FZONE),
--0x10 GetFieldCard(FZONE, 0) exists, 0x20 GetFieldCard(FZONE, 1) exists, 0x40 IsEnvironment, 0x80 IsLocation(FZONE),
--0x100 GetFieldCard(FZONE, 0) is this card, 0x200 CheckLocation(FZONE, 1), bits 12+ = this card's sequence.
local s,id,o=GetID()
function s.initial_effect(c)
local e1=Effect.CreateEffect(c)
e1:SetType(EFFECT_TYPE_ACTIVATE)
e1:SetCode(EVENT_FREE_CHAIN)
e1:SetOperation(s.activate)
c:RegisterEffect(e1)
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler()
local f0=Duel.GetFieldCard(tp,LOCATION_FZONE,0)
local f1=Duel.GetFieldCard(tp,LOCATION_FZONE,1)
local v=Duel.GetFieldGroupCount(tp,LOCATION_FZONE,0)
if f0 then v=v+0x10 end
if f1 then v=v+0x20 end
if Duel.IsEnvironment(id,tp,LOCATION_FZONE) then v=v+0x40 end
if c:IsLocation(LOCATION_FZONE) then v=v+0x80 end
if f0==c then v=v+0x100 end
if Duel.CheckLocation(tp,LOCATION_FZONE,1) then v=v+0x200 end
v=v+c:GetSequence()*0x1000
Duel.Hint(10,tp,v)
end
"""
def info_location(v):
return (v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF)
def field_hints(pkts):
return [struct.unpack_from("<I", d, 3)[0] for p, d in pkts if p == 0x01 and len(d) >= 7 and d[0] == MSG_HINT and d[1] == HINT_CARD]
def error_msgs(pkts):
return [d[0] for p, d in pkts if p == STOC_ERROR_MSG and d]
def tag_two_fields_room(dll_path, port, label):
print("== tag two Field slots, %s (seat 0 plays a Field on turn 1, seat 1 on turn 3, seat 0 again on turn 5)" % label)
root = make_workspace()
here = os.getcwd()
os.chdir(root)
try:
write_special(root, [])
dll, thread = host_dll(dll_path, port, 2)
seated = []
for i in range(4):
c = Client("127.0.0.1", port, "tf-seat%d" % i)
c.log = list(c.join())
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]))
cap = server_capability(seated[0].log)
check(cap == (10, 0x37FF), "%s: the tag server's capability is protocol 10, flags 0x37FF (got %s)" % (label, cap))
drain_all(seated)
old = Client("127.0.0.1", port, "tf-old")
old.log = list(old.join())
old.send(CTOS_CAPABILITY, capability_bytes(9, 0x27FF))
old.log += old.drain(quiet=0.4)
check(old.seat == OBSERVER and error_msgs(old.log) == [ERRMSG_VERERROR] and old.closed,
"%s: a joiner whose capability lacks 0x1000 gets ERROR_MSG VERERROR and is disconnected (seat %r, errors %r, closed %r)" % (label, old.seat, error_msgs(old.log), old.closed))
new = Client("127.0.0.1", port, "tf-new")
new.log = list(new.join())
new.send(CTOS_CAPABILITY, capability_bytes(10, 0x37FB))
new.log += new.drain(quiet=0.4)
check(new.seat == OBSERVER and not error_msgs(new.log) and not new.closed and stamped(new.log, STOC_CAPABILITY, OBSERVER) == [capability_bytes(10, 0x37FB)],
"%s: a joiner with 0x1000 stays and its CAPABILITY is relayed (errors %r, closed %r)" % (label, error_msgs(new.log), new.closed))
new.close()
drain_all(seated)
decks = {0: [PROBE_FIELD] * 40, 1: [PROBE_FIELD] * 40, 2: [PROBE_CARD] * 40, 3: [PROBE_CARD] * 40}
for c in seated:
c.send(CTOS_UPDATE_DECK, deck_bytes(decks[c.seat]))
pump(seated, lambda: False, limit=0.8)
seated[0].send(CTOS_HS_START)
state = {"turn": 0, "acted": 0, "retries": 0, "moves": []}
def answer(c, payload):
c.send(CTOS_TIME_CONFIRM)
c.send(CTOS_RESPONSE, payload)
def play(until, limit):
deadline = time.time() + limit
while time.time() < deadline:
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])) # side A (seats 0 + 1) goes first
continue
if pid != 0x01 or not d:
continue
t = d[0]
if t == MSG_NEW_TURN and c.seat == 0:
state["turn"] += 1
elif t == MSG_MOVE and c.seat == 0 and len(d) >= 17:
code, prev, cur, _reason = struct.unpack_from("<IIII", d, 1)
state["moves"].append((state["turn"], code, info_location(prev), info_location(cur)))
elif t == MSG_RETRY:
state["retries"] += 1
elif t == MSG_SELECT_IDLECMD:
n = 2
for k in range(5):
n += 1 + d[n] * 7
activatable = d[n]
if activatable and state["acted"] != state["turn"]:
state["acted"] = state["turn"]
answer(c, struct.pack("<i", 5)) # activate the first card: a Probe Field
else:
answer(c, struct.pack("<i", 7)) # to the End Phase
elif t in (MSG_SELECT_CARD, MSG_SELECT_TRIBUTE):
answer(c, bytes([1, 0]))
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 == MSG_SELECT_POSITION:
answer(c, struct.pack("<i", next(b for b in (1, 2, 4, 8) if d[6] & b)))
elif t in (MSG_SELECT_EFFECTYN, MSG_SELECT_YESNO):
answer(c, struct.pack("<i", 1))
elif t in (MSG_SELECT_OPTION, MSG_SELECT_BATTLECMD):
answer(c, struct.pack("<i", 0 if t == MSG_SELECT_OPTION else 3))
if until():
return True
if any(c.closed for c in seated):
return False
return until()
ok = play(lambda: state["turn"] >= 6, limit=40)
check(ok, "%s: the duel reached turn 6 (turn %d)" % (label, state["turn"]))
check(state["retries"] == 0, "%s: no answer was refused (MSG_RETRY x%d)" % (label, state["retries"]))
fields = [(turn, prev, cur) for turn, code, prev, cur in state["moves"] if code == PROBE_FIELD]
to_field = [(turn, cur[2]) for turn, prev, cur in fields if cur[0] == 0 and cur[1] == LOCATION_SZONE]
check(to_field == [(1, 5), (3, 6), (5, 5)],
"%s: seat 0's Field lands in sequence 5 on turn 1, seat 1's in sequence 6 on turn 3, seat 0's next in sequence 5 on turn 5 (%r)" % (label, to_field))
left = [(turn, prev[2], cur[1]) for turn, prev, cur in fields if prev[0] == 0 and prev[1] == LOCATION_SZONE]
check(left == [(5, 5, LOCATION_GRAVE)],
"%s: only the sequence-5 Field left, to the Graveyard on turn 5; the sequence-6 Field never moved (%r)" % (label, left))
hints = field_hints(seated[0].log)
check(hints == [0x53D1, 0x61F2, 0x51F2],
"%s: the core saw it so: turn 1 seq 5, 1 field, slot 1 free; turn 3 seq 6, 2 fields, GetFieldCard(FZONE, 0) = the playing partner's, 1 = the other; turn 5 seq 5, 2 fields (%s)" % (label, ["0x%X" % h for h in hints]))
check(all(not c.closed for c in seated), "%s: every seat is still connected" % label)
marks = marks_of(seated)
for c in seated[:2]:
c.send(CTOS_SURRENDER)
ok = pump(seated, lambda: all(match_overs(since(c, marks)) for c in seated), limit=10)
check(ok, "%s: side 0 surrendered: MATCH_OVER reached everyone" % label)
for c in seated:
c.close()
stop_dll(dll, thread, label)
finally:
os.chdir(here)
shutil.rmtree(root, ignore_errors=True)
def tag_two_fields_single(dll_path, port, label):
print("== tag two Field slots, %s (a Single room keeps a client without 0x1000)" % label)
root = make_workspace()
here = os.getcwd()
os.chdir(root)
try:
write_special(root, [])
dll, thread = host_dll(dll_path, port, 0)
h = Client("127.0.0.1", port, "tf-host")
h.log = list(h.join())
cap = server_capability(h.log)
check(cap == (10, 0x37FF), "%s: the single server's capability is protocol 10, flags 0x37FF (got %s)" % (label, cap))
h.send(CTOS_CAPABILITY, capability_bytes(9, 0x27FF))
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)],
"%s: a seat whose capability lacks 0x1000 stays and its CAPABILITY is relayed (errors %r, closed %r)" % (label, error_msgs(h.log), h.closed))
h.close()
stop_dll(dll, thread, label)
finally:
os.chdir(here)
shutil.rmtree(root, ignore_errors=True)
def tag_two_fields_suite(dll_path, port):
print()
print("hosting the tag two Field slots rooms from %s" % dll_path)
tag_two_fields_room(dll_path, port, "tag")
tag_two_fields_single(dll_path, port + 1, "single")
if __name__ == "__main__":
sys.exit(main())
+6 -2
View File
@@ -224,7 +224,7 @@ static_assert(sizeof(CTOS_Appearance) == 352, "size mismatch: CTOS_Appearance");
check_trivially_copyable(CTOS_Dialogue);
static_assert(sizeof(CTOS_Dialogue) == 204, "size mismatch: CTOS_Dialogue");
constexpr int SIZE_STOC_FEATURE = sizeof(uint16_t) + sizeof(CTOS_Appearance);
constexpr uint16_t FEATURE_PROTOCOL = 9; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7; YGOL attack preview: 7 -> 8; YGOL tag partner cards: 8 -> 9
constexpr uint16_t FEATURE_PROTOCOL = 10; // YGOL host seats: 1 -> 2; YGOL seat state: 2 -> 3; YGOL lobby after match: 3 -> 4; YGOL coin toss: 4 -> 5; YGOL deck lists: 5 -> 6; YGOL profile: 6 -> 7; YGOL attack preview: 7 -> 8; YGOL tag partner cards: 8 -> 9; YGOL tag two fields: 9 -> 10
constexpr uint32_t FEATURE_APPEARANCE = 0x1;
constexpr uint32_t FEATURE_DIALOGUE = 0x2;
constexpr uint16_t FEATURE_SENDER_SERVER = 0xff;
@@ -464,7 +464,11 @@ constexpr uint8_t ATTACK_PREVIEW_VERSION = 1;
constexpr uint8_t ATTACK_PREVIEW_DIRECT = 0xFF;
constexpr int ATTACK_PREVIEW_MAX_PAIRS = 64;
constexpr int ATTACK_PREVIEW_ANSWER_SIZE = 24; // the ygol_preview_attack answer, echoed after the pair
// YGOL tag partner cards: the waiting teammate's hand, Extra Deck and deck (ygol_query_tag_cards), sent to that side's two seats only; 0x800 and 0x1000 are reserved by proposals 44 and 45
// YGOL tag two fields (proposal 45): in Tag on Master Rule 4/5 each partner has a Field slot (Spell/Trap sequence 5 and 6, the core's
// field::has_two_fields); no message, the second field reaches a client as sequence 6. A Tag room refuses a joiner without the bit
// (ERRMSG_VERERROR), a Single room does not care; 0x800 is reserved by proposal 44
constexpr uint32_t FEATURE_TAG_TWO_FIELDS = 0x1000;
// YGOL tag partner cards: the waiting teammate's hand, Extra Deck and deck (ygol_query_tag_cards), sent to that side's two seats only
constexpr uint32_t FEATURE_TAG_PARTNER_CARDS = 0x2000;
constexpr uint8_t TAG_PARTNER_CARDS_VERSION = 1;
// the one-use bootstrap secret of a replacement server: a host-string token parsed apart from the ygol.* pairs, never stored anywhere else
+1 -1
View File
@@ -98,7 +98,7 @@ void SingleDuel::AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) {
void SingleDuel::SendServerCapability(DuelPlayer* dp) {
CTOS_Capability cap;
cap.protocol = FEATURE_PROTOCOL;
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag partner cards
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag two fields + tag partner cards
unsigned char buf[SIZE_STOC_FEATURE];
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);
+10 -1
View File
@@ -50,6 +50,15 @@ void TagDuel::BroadcastFeature(unsigned char proto, unsigned char* pdata, int le
void TagDuel::Capability(DuelPlayer* dp, unsigned char* pdata, int len) {
std::memcpy(&dp->capability, pdata, sizeof dp->capability);
dp->has_capability = true;
// YGOL tag two fields: a client without the bit shows the second Field slot as a Pendulum Zone, so a Tag room refuses it as out of date
if(!(dp->capability.flags & FEATURE_TAG_TWO_FIELDS)) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_VERERROR;
scem.code = FEATURE_PROTOCOL;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
NetServer::DisconnectAfterFlush(dp);
return;
}
BroadcastFeature(STOC_CAPABILITY, pdata, len, dp->type);
}
void TagDuel::Appearance(DuelPlayer* dp, unsigned char* pdata, int len) {
@@ -96,7 +105,7 @@ void TagDuel::AttackPreview(DuelPlayer* dp, unsigned char* pdata, int len) {
void TagDuel::SendServerCapability(DuelPlayer* dp) {
CTOS_Capability cap;
cap.protocol = FEATURE_PROTOCOL;
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag partner cards
cap.flags = FEATURE_APPEARANCE | FEATURE_DIALOGUE | FEATURE_SETUP_PAIRS | FEATURE_SEAT_PLAN | FEATURE_RULES_RESTART | FEATURE_SEAT_STATE | FEATURE_LOBBY_AFTER_MATCH | FEATURE_COIN_TOSS | FEATURE_DECK_LIST | FEATURE_PROFILE | FEATURE_ATTACK_PREVIEW | FEATURE_TAG_TWO_FIELDS | FEATURE_TAG_PARTNER_CARDS; // YGOL setup pairs + host seats + rules restart + seat state + lobby after match + coin toss + deck lists + profile + attack preview + tag two fields + tag partner cards
unsigned char buf[SIZE_STOC_FEATURE];
const auto size = NetServer::CreateStampedPacket((unsigned char*)&cap, sizeof cap, buf, FEATURE_SENDER_SERVER);
NetServer::SendBufferToPlayer(dp, STOC_CAPABILITY, buf, size);