Session control, mesh leftovers, lobby values and card trade

Second part of “Session, mesh and lobby layers under the battle protocol”: what was left open there, read from PDUWP.exe. Nothing was checked against a packet capture, so the best grade is M (read in code); dumped tables are H. Names are ours. The summary and the capture checklist are in converter/NETCOMPAT.md.

Session object and member table (M)

The game’s own session object is at 0x140594e70 (the member table 0x140595ea8 is its

off field
0x00 u32 role: 0 off, 2 member / not hosting (set by the initialiser 0x140125010), 3 host (0x140125150). The handlers also accept 1; nothing writes 1
0x08 u32 open for joins (host; 1 on creation and on the return to the lobby 0x140187b70, rewritten by the start routine 0x140187e80 and by lobby script commands)
0x0C u32 real player ids (1 in this build: ids come from the platform; 0 would make ids from the address)
0x10 s32 own member id: −1 until accepted, 0 = host, 1..3 = joiners
0x14 u64 own platform user id, then u32 own flags word (0x14051d420 / 0x14051d428): the “player key”, 12 bytes
0x20, 0x24 u32, u32 “member table changed” marks (set by every add / leave)
0x2C s32 join result (below)
0x30 u32 maximum players: 2 or 4 (0x14051c0a4)
0x34 u32 member slots = maximum − 1 (the table holds the other members only)
0x38 u32 number of private (reserved) slots
0x3C u32 silence limit in session ticks: 150 (0x96, passed by 0x140190940)
0x40 u64 session id of the chosen session
0x58 0x130: the host’s address block
0x208 8 search results of 0x1C0 (a type 1 reply each)
0x1010 / 0x1018 game data callback: 0x140190c80

An address block is 0x130 bytes: {u32 length, u8[300] device address} (own one from 0x140281320).

Member record (0x298; completes the table of the first part):

off field
0x00 u32 in use
0x04 s32 member id (= net index 0..3)
0x08 s32 keep-alive countdown: 15 after every datagram sent to the member
0x0C s32 silence countdown: reloaded with 150 on every datagram received from the member
0x10 s32 ping countdown (15)
0x18 f64 the member’s echoed ping time (−2.0 until the first echo)
0x20 u32 holds a private slot
0x24 u32 no-voice flag
0x28 address block the datagrams are sent to (where its packets came from)
0x158 address block the member reported about itself (passed on to the others)
0x288 player key (u64 user id, u32 flags)

Lookup by member id 0x1401266c0; add 0x140126740; a second table 0x140582900 (16 bytes per member id: player key, in-use) mirrors the keys for the platform side.

Session control messages (M; handler table H)

All are one datagram: mesh header (custom 0), then {u16 length = body + 6, u16 0x1200, u16 type, s16 sender’s member id}, then the body. Offsets below are from the start of the wrapper (body at 0x08). The generic sender is 0x140125560. On every received wrapper, whatever the type, the receiver reloads the silence countdown of the member whose id is in the wrapper (0x1401253ea).

type length word datagram sender handler meaning
0 – – none found 0x140125cf0 no effect (an old search broadcast)
1 446 448 0x1401255e0 0x140125d10 session description, the answer to type 9
2 330 332 0x140125950 0x140125d50 join request
3 22 24 0x140125a20 0x140125e40 join reply: accepted with a member id, or refused
4 6 8 session tick 0x140126bd0 0x140125d40 keep-alive (no body, no effect beyond the silence reload)
5 326 328 0x140125810 0x140125f70 member introduction (host → member, about another member)
6 6 8 0x140126aa0, session tick 0x140126080 leave / “I dropped you”
7 – – none found 0x140126100 stores a body value in the silence countdown, which the common reload overwrites: no effect
8 game + 6 – 0x140125430 game packet arrival game data
9 – – none found 0x140126160 “describe your session”: a host answers type 1, or type 3 with a refusal
10 22 24 0x140126260 0x1401261f0 ping and its echo

Type 2, join request (joiner → host address):

off type field
0x08 s32 sender’s member id (−1)
0x0C u32 wants a private slot (0 from the session list; the invite / friend flag 0x14051d3a4 on a join by address)
0x10 0x130 the joiner’s own address block
0x140 u64, u32 the joiner’s player key

Type 3, join reply (host → the address the request came from):

off type field
0x08 s32 result: 1..3 = accepted, this is your member id; 5 = not hosting or closed; 6 = full; 7 = closed, sent only to a type 9 when the session’s flag + 0x188 is set
0x0C u64, u32 the host’s player key

Type 5, member introduction:

off type field
0x08 s32 member id of the member described
0x0C 0x130 that member’s reported address block
0x13C u64, u32 that member’s player key

Type 10, ping: {f64 sender’s clock at 0x08, u32 flags at 0x10}. A receiver that knows the sender: flags bit 0 clear → sets bit 0 and sends the same 24 bytes back to where they came from; bit 0 set → stores the f64 in the member’s echoed-time field.

Type 1, session description (not needed for a join through the platform session; L field meanings): u64 session id at 0x08, the host’s address block, the host’s member id, flags, a count of members (in use + 1) and the session’s settings words, 0x1B8 body. The handler takes it only while searching (object + 4 = 2) and when its u64 equals the search’s own value (+ 0x1008); results are kept apart by their first 0x148 bytes.

The join, step by step:

  1. The joiner learns the host’s device address from the platform session, copies it into the session object (0x1401265b0; from a search result 0x1401264e0) and sends type 2 to it (0x140181210 on a join by address; 0x140184210 from the list). Join result (object + 0x2C) = 4 “waiting”. The request is sent once; the join-by-address path then waits 150 frames for the host to appear in its member table and gives up after that; the list path sets a 60-frame timer (L).
  2. The host (role 3, open): picks the lowest free member id (0x1401263b0; never its own id, so 1..3). Refuses with 6 when the public slots are used up (members without a private slot ≥ maximum − private slots − 1) unless the request asks for a private slot, or when no id is free; with 5 when it is not hosting or closed.
  3. On success the host adds the member (send address = where the request came from, reported address and key from the request), answers type 3 with the id, and then sends type 5 for every ordered pair of its members (0x140125ac0: to each member i, about each other member j), so the newcomer learns everyone and everyone learns the newcomer. This is repeated in full on every join; a receiver ignores a member it has.
  4. The joiner, on type 3 with 1..3: adds the host as member 0 (send address = where the reply came from, reported address = the stored host address, key from the reply) and takes the id as its own. Any other value is stored as the join result (the lobby script reads it through 0x140215dc0).
  5. On type 5 a member adds the described member with both address blocks = the reported one. The mesh then connects the two (endpoint pair, hello) and the lobby exchange of the first part starts as soon as game packets flow.

Staying in and leaving:

Mesh: resend and time-out, searched to the end (M)

Lobby values that were open (M unless noted)

Card trade, lobby types 11..20 (M flow, L for the card routines)

A trade is its own session kind (session game type 11, 0x140527ab8), two players: role 1 = the creator (0x140185990, 0x140219a70), role 2 = the joiner (0x140186380, 0x140115a80). Every handler first checks the own role and the trade state 0x140527abc, so a peer whose role is 0 ignores all ten types: declining needs no message. A compatible peer declines by never creating or joining a session of game type 11.

All trade packets are bare 0x18 headers; the creator’s offer flag rides in the header’s net index field of type 13. Repeats are every 10th tick; timers (0x140527ab4) in ticks.

type from → to sent effect on the receiver
11 joiner → creator every 10 ticks in state 2 once the creator’s info is in (0x140192330) creator 2 → 3; answers 16 to all
16 creator answer to 11 joiner 2 → 3, timer 900 (choosing)
13 creator → joiner every 10 ticks in state 4 (0x1401923a0), header + 8 = offer flag 0x140527ab0 joiner (state ≥ 3): flag set → state 5 and the cards are put up (0x140185170), else state 4; answers 18
18 joiner answer to 13 creator in 4: offer flag set → 5 (timer 150), else 9
14 joiner → creator every 10 ticks in state 5 until 19 arrives creator 5 → 6, timer 450, its card put up (0x140185170); answers 19
19 creator answer to 14 joiner in 5: latch 0x1405279fc; its timer then runs to state 6
15 joiner → creator every 10 ticks in state 6 creator (no save running) 6 → 7, the exchange is written (0x140185240); answers 20
20 creator answer to 15 joiner 6 → 7, the exchange is written
12, 17 – – empty handlers

States: 1 idle, 2 waiting for the partner, 3 choosing, 4 offer shown, 5 agreed, 6 committing, 7 done, 8 / 9 cancelled or failed (a timer ran out, the partner (member 1) left, or the offer was withdrawn). Ticks: creator 0x140192050, joiner 0x1401921c0.

Battle leftovers (M)

Implementation notes for the rebuild