commit f3a0acd36ff069999bdb8997072a6a1fff6cc149
parent 5103f7d6585019f59e7a7ec9f778c880913c0490
Author: anon <anon@example.com>
Date: Fri, 23 Oct 2026 22:28:49 +0000
feat(server): support native team leadership and member removal
Diffstat:
5 files changed, 314 insertions(+), 34 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -456,9 +456,9 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
- [x] Form a two-player team. Check: invitation and acceptance update both native
team windows; declining does not add a member.
-- [ ] Leave a team voluntarily. Check: both native team windows reflect the
+- [x] Leave a team voluntarily. Check: both native team windows reflect the
departure and leadership transfers correctly if the leader leaves.
-- [ ] Remove a team member as leader. Check: a leader can remove a member and
+- [x] Remove a team member as leader. Check: a leader can remove a member and
an ordinary member cannot remove another player.
- [ ] Handle a team member disconnecting. Check: the documented membership and
leadership policy is applied without stale UI entries or duplicate membership.
@@ -473,7 +473,7 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
teams after join, leave, reconnect and faction changes. Stat 213 and
CharacterAction 27 routes are recovered; unchanged neutral values must still
refresh the GUI. Current formation displays `Team side: Missing`.
-- [ ] Transfer team leadership explicitly. Check: only the leader can transfer
+- [x] Transfer team leadership explicitly. Check: only the leader can transfer
to an eligible member, both native controls update, and the change persists.
- [ ] Replicate team resources. Check: a teammate's health/nano display updates
correctly without spawning unrelated actors or exposing private inventory.
@@ -485,9 +485,11 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
zones; joining, leaving, disconnect and restart update channel access.
Native consent, roster order, persistent membership, departure and the remaining
-policy limits are documented in [teams](docs/teams.md). Go checks include
-three-member leader succession; native three-client succession and broader
-departure/disconnect coverage remain in the open lifecycle milestones.
+policy limits are documented in [teams](docs/teams.md). Three connected WASM
+clients verified transfer, loss of former-leader controls, kick feedback,
+three-member leader succession and pair dissolution. Read-only native snapshots
+and SQLite agree; all 192 item records and placements were conserved. Original
+disconnect retention and succession policy still need period corroboration.
## Travel
@@ -776,6 +778,11 @@ and server restarts. Turn every reproduced bug into a focused regression test.
Cover leaving/returning to the tab, opening/closing options or chat, held
keys/modifiers, repeats, reconnect and slow frames. Compare the first input
after each transition and the final selected target in the UI and server.
+ Concurrent software-rendered team clients suppressed the member popup;
+ closing extra clients restored it. An original input-frame fixture reproduces
+ RightPress becoming RightHold before binding dispatch at a one-second frame
+ delta. Measure live timing and establish the intended slow-frame behavior
+ before changing the adapter. Evidence: `local/team-leadership-smoke/menu-audit.md`.
- [x] Prevent browser wheel camera gestures from activating native GUI items.
Check: wheel/trackpad input over inventory cannot equip or use the hovered
item; world-camera gestures still work. A WASM armor test reproduced a wheel
diff --git a/docs/teams.md b/docs/teams.md
@@ -1,10 +1,10 @@
-# Native team formation and departure
+# Native team controls
Recruit, Yes, No and Leave now use the original 14.9.1 team controls. Accepted
rosters and their leader persist atomically in SQLite before membership is
published. Each player belongs to at most one team, with at most six members.
-This implements formation and voluntary departure; chat, rewards, loot policy,
-resource replication and the remaining team commands are separate work.
+This implements formation, leadership transfer and member removal; chat,
+rewards, loot policy and resource replication are separate work.
## Original client contract
@@ -20,6 +20,8 @@ Addresses below use the original image bases.
| Confirm an XP-range warning, action 26 | `kkr 10028570` | target player identity, `{0,1}` |
| Yes/No, action 28 | `kkr 10022840`, GUI `ddr 1004b0f0`/`1004b120` | inviter identity, `{0,1}`/`{0,0}` |
| Leave, action 24 | `kkr 10022580` | two null identities |
+| Kick, action 22 | `kkr 100224d0` | member identity, null identity |
+| Transfer leadership, action 25 | `kkr 10022620` | member identity, null identity |
These use key `5e477770` and the sending player's envelope. Recruit's boolean
is distinct from the acceptance boolean. The native CreateTeam export is an
@@ -41,6 +43,19 @@ The two-client check reproduced this ordering bug, and the server regression
now checks the recipient-specific order. Replayed membership is idempotent in
the original list implementation `10076b20`.
+Leadership transfer rechecks the current leader and target membership before
+committing the new leader. Action 35 then updates every connected member's
+native controls. Replaying the former leader's transfer or kick cannot retain
+their old authority. Kicking uses action 32 for membership removal, followed by
+action 21/reason 24 for the removed player's native kicked message. Remaining
+members receive no redundant leader announcement when leadership is unchanged.
+Shipped help describes these controls in the member's right-click-and-hold menu;
+the first icon transfers leadership and the second expels a member.
+The original CCR binding is RightPress with AnyPlayMode and TeamViewMode set,
+excluding DraggingMode and MouseLookMode. DDR `1004b210 -> 1004a150` dispatches
+the selected row to the leader or ordinary-member icon menu. The ordinary
+member menu does not offer transfer or kick.
+
Retained REA evidence includes recruit
`ev_fd6a7148930689705ee8f3111f7e05473f738a686197a46419a1f9adccba5c18`,
reply `ev_45086f995e87e784502431e0b8216bcac8890032686c5247b4113ad37e1c24f4`,
@@ -92,14 +107,33 @@ departure without publishing success. Database reopen restores a shared roster
and leader. Departure, leadership succession, dissolution, ready-message
replay, profile updates, mixed factions and differing levels have checks.
-Two unchanged WASM clients exercised Recruit, No, a second Recruit and Yes.
-The inviter displayed the native decline text, and no team existed before
-acceptance. Both windows displayed both members after the ordering fix, with
-the same team identity and leader in read-only guest samples. A normal server
-restart restored the accepted roster; subsequent native Leave cleared both
-clients and the database. Fresh formation allocated a different team identity.
-Captures, packet logs, database snapshots and verification results are retained
-in `local/team-research/`.
+Leadership checks cover transfer persistence, immediate loss of former-leader
+authority, repeated kicks, online/offline pair dissolution, forged or unrelated
+targets, loading/replaced sessions and competing transfers. A trigger that fails
+partway through roster deletion verifies rollback of both leadership and roster
+without client updates. The complete Go suite passed in 381 seconds; all team
+tests passed twice under the race detector in 144 seconds. Logs and native menu
+source contracts are retained in `local/team-leadership-smoke/`.
+
+WASM checks cover Recruit, No and Yes, reconnect, server restart and both pair
+departure directions. The inviter displays native decline feedback, and no
+team exists before acceptance. Each native window and internal roster agree.
+Fresh formation allocates a different team identity. Formation evidence is
+retained in `local/team-research/`.
+
+Three connected WASM clients also exercised the native member menus. Transfer
+changes both clients' leader controls; the former leader's menu offers only
+information. A transferred leader survives a normal server restart. Kicking
+one of three clears the victim's roster and displays "You were kicked from
+the team" while both remaining windows retain their leader. A three-member
+leader departure assigns the first remaining member and updates both remaining
+clients. A final pair kick clears all native and database membership.
+
+`local/team-leadership-smoke/verification.json` checks 18 read-only native
+snapshots against SQLite, captured native request/result fields, and conservation
+of all 192 item records and placements. Browser runs reported no page or adapter
+errors. All owned browser contexts were closed; the single shared preview stays
+available for manual testing.
The native header still displays `Team side: Missing`. The GUI starts its side
cache at -1; stat 213 notifies it through a separate local stat-change event.
@@ -107,17 +141,4 @@ Team level uses CharacterAction 27. These routes are recovered, but mixed-side
derivation, unchanged neutral-stat notification, resets and team-level
progression still need implementation and runtime checks. Roster formation is
not evidence that these fields, remote HP/nano updates, chat, XP sharing, loot
-rotation, kicking or explicit leadership transfer are complete.
-
-The final native run also reconnected one member while the other stayed online
-and then exercised the leader's Leave action. Both pair-departure directions
-cleared internal membership and the visible windows. All 192 item records and
-their placements were unchanged; the browser runs had no page or adapter errors.
-`local/team-research/verification.json` checks the native request bytes,
-read-only rosters, database transitions and item conservation. Both owned browser
-contexts were closed after testing. Focused team tests passed three repetitions
-under the race detector; the final roster-order correction also passed a fresh
-race-detector run.
-The final complete `go test ./server/...` run passed, including the roster-order
-regression; its server package completed in 309 seconds. Logs are retained as
-`go-full-final.log` and `go-team-race-final.log` alongside the native captures.
+rotation or disconnect expiry are complete.
diff --git a/server/main.go b/server/main.go
@@ -487,7 +487,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
return fmt.Errorf("short character action message")
}
switch binary.BigEndian.Uint32(body[16:20]) {
- case 24, 26, 28:
+ case 22, 24, 25, 26, 28:
if err := server.handleTeamAction(client, body); err != nil {
return err
}
diff --git a/server/team_leadership_test.go b/server/team_leadership_test.go
@@ -0,0 +1,224 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "reflect"
+ "sync"
+ "testing"
+)
+
+func TestTeamLeadershipTransferPersistsAndRevokesOldAuthority(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ formTestTeam(t, world, 1, 3)
+ before := world.characters[1].team
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+
+ err := world.handleTeamAction(world.clients[1], teamRequest(1, 25, 2, 0))
+ world.handleTeamAction(world.clients[1], teamRequest(1, 25, 3, 0))
+ world.handleTeamAction(world.clients[1], teamRequest(1, 22, 3, 0))
+ restored := newTestInventoryServer(t)
+
+ team := world.characters[1].team
+ if err != nil || team.id != before.id || team.leader != 2 || !reflect.DeepEqual(team.members, []uint32{1, 2, 3}) ||
+ !reflect.DeepEqual(restored.characters[1].team, team) || restored.characters[2].team != restored.characters[3].team || before.leader != 1 {
+ t.Fatalf("leadership transfer changed roster or lost persistence: %+v %v", team, err)
+ }
+ for _, conn := range connections[:3] {
+ if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 35 ||
+ binary.BigEndian.Uint32(conn.packets[0][37:41]) != 2 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != team.id {
+ t.Fatal("transfer or rejected former-leader action published the wrong leader")
+ }
+ }
+ if len(connections[3].packets) != 0 {
+ t.Fatal("unrelated player received team leadership")
+ }
+}
+
+func TestTeamLeaderKicksMemberWithoutChangingRemainingLeader(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ formTestTeam(t, world, 1, 3)
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+
+ err := world.handleTeamAction(world.clients[1], teamRequest(1, 22, 2, 0))
+ world.handleTeamAction(world.clients[1], teamRequest(1, 22, 2, 0))
+ restored := newTestInventoryServer(t)
+
+ if err != nil || world.characters[2].team != nil || restored.characters[2].team != nil ||
+ world.characters[1].team.leader != 1 || !reflect.DeepEqual(world.characters[1].team.members, []uint32{1, 3}) ||
+ !reflect.DeepEqual(world.characters[1].team, restored.characters[3].team) {
+ t.Fatalf("kick lost membership or persistence: %v", err)
+ }
+ for _, id := range []uint32{1, 3} {
+ packets := connections[id-1].packets
+ if len(packets) != 1 || binary.BigEndian.Uint32(packets[0][29:33]) != 32 || binary.BigEndian.Uint32(packets[0][37:41]) != 2 {
+ t.Fatal("kick repeated leadership feedback or removed the wrong member")
+ }
+ }
+ if len(connections[1].packets) != 2 || binary.BigEndian.Uint32(connections[1].packets[0][29:33]) != 32 ||
+ binary.BigEndian.Uint32(connections[1].packets[1][29:33]) != 21 || binary.BigEndian.Uint32(connections[1].packets[1][45:49]) != 24 || len(connections[3].packets) != 0 {
+ t.Fatal("kicked member did not receive native removal and kicked feedback")
+ }
+}
+
+func TestTeamKickLastPeerDissolvesPairAndOfflineKickPersists(t *testing.T) {
+ for _, offline := range []bool{false, true} {
+ name := "online"
+ if offline {
+ name = "offline"
+ }
+ t.Run(name, func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ if offline {
+ delete(world.clients, 2)
+ }
+
+ err := world.handleTeamAction(world.clients[1], teamRequest(1, 22, 2, 0))
+ restored := newTestInventoryServer(t)
+
+ if err != nil || world.characters[1].team != nil || world.characters[2].team != nil || restored.characters[1].team != nil || restored.characters[2].team != nil ||
+ len(connections[0].packets) != 2 || offline && len(connections[1].packets) != 0 || !offline && len(connections[1].packets) != 3 {
+ t.Fatalf("pair kick left an orphaned team or wrote to an offline member: %v", err)
+ }
+ })
+ }
+}
+
+func TestTeamRejectsUnauthorizedLeadershipActions(t *testing.T) {
+ for _, action := range []uint32{22, 25} {
+ for _, scenario := range []string{"nonleader", "unrelated", "self", "missing", "other team", "wrong type", "foreign owner", "argument", "flag", "loading", "not ready", "replaced"} {
+ t.Run(fmt.Sprintf("%d/%s", action, scenario), func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ formTestTeam(t, world, 1, 3)
+ client := world.clients[1]
+ request := teamRequest(1, action, 2, 0)
+ switch scenario {
+ case "nonleader":
+ client = world.clients[3]
+ request = teamRequest(3, action, 2, 0)
+ case "unrelated":
+ client = world.clients[4]
+ request = teamRequest(4, action, 2, 0)
+ case "self":
+ binary.BigEndian.PutUint32(request[24:28], 1)
+ case "missing":
+ binary.BigEndian.PutUint32(request[24:28], 100)
+ case "other team":
+ formTestTeam(t, world, 4, 5)
+ binary.BigEndian.PutUint32(request[24:28], 5)
+ case "wrong type":
+ binary.BigEndian.PutUint32(request[20:24], 57001)
+ case "foreign owner":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ case "argument":
+ binary.BigEndian.PutUint32(request[28:32], 50000)
+ case "flag":
+ binary.BigEndian.PutUint32(request[32:36], 1)
+ case "loading":
+ client.loading = true
+ case "not ready":
+ client.ready = false
+ case "replaced":
+ world.clients[1] = &worldClient{id: 1, ready: true}
+ }
+ before := world.characters[1].team
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+
+ err := world.handleTeamAction(client, request)
+
+ if err != nil || world.characters[1].team != before || world.characters[2].team != before || before.leader != 1 || !reflect.DeepEqual(before.members, []uint32{1, 2, 3}) {
+ t.Fatalf("unauthorized command changed leadership or membership: %v", err)
+ }
+ for _, conn := range connections {
+ if len(conn.packets) != 0 {
+ t.Fatal("rejected leadership action published updates")
+ }
+ }
+ })
+ }
+ }
+}
+
+func TestTeamLeadershipChangesRollBackWithoutPublishingOnSQLFailure(t *testing.T) {
+ for _, action := range []uint32{22, 25} {
+ name := "kick"
+ if action == 25 {
+ name = "transfer"
+ }
+ t.Run(name, func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ formTestTeam(t, world, 1, 3)
+ before := world.characters[1].team
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ if _, err := world.db.Exec("CREATE TRIGGER fail_leadership BEFORE DELETE ON team_members WHEN OLD.player_id=2 BEGIN SELECT RAISE(FAIL, 'test roster failure'); END"); err != nil {
+ t.Fatal(err)
+ }
+
+ err := world.handleTeamAction(world.clients[1], teamRequest(1, action, 2, 0))
+ restored := newTestInventoryServer(t)
+
+ if err == nil || world.characters[1].team != before || world.characters[2].team != before || world.characters[3].team != before ||
+ !reflect.DeepEqual(restored.characters[1].team, before) {
+ t.Fatal("failed leadership transaction changed memory or durable membership")
+ }
+ for _, conn := range connections {
+ if len(conn.packets) != 0 {
+ t.Fatal("failed leadership transaction published success")
+ }
+ }
+ })
+ }
+}
+
+func TestTeamConcurrentTransfersPublishOneAuthorizedLeader(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ formTestTeam(t, world, 1, 3)
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ var wait sync.WaitGroup
+ errors := make(chan error, 2)
+
+ for _, target := range []uint32{2, 3} {
+ wait.Add(1)
+ go func(target uint32) {
+ defer wait.Done()
+ errors <- world.handleTeamAction(world.clients[1], teamRequest(1, 25, target, 0))
+ }(target)
+ }
+ wait.Wait()
+ close(errors)
+ restored := newTestInventoryServer(t)
+
+ for err := range errors {
+ if err != nil {
+ t.Fatal(err)
+ }
+ }
+ team := world.characters[1].team
+ if team.leader != 2 && team.leader != 3 || !reflect.DeepEqual(team.members, []uint32{1, 2, 3}) || !reflect.DeepEqual(restored.characters[1].team, team) {
+ t.Fatal("concurrent transfer changed more than leadership or lost persistence")
+ }
+ for _, conn := range connections[:3] {
+ if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][37:41]) != team.leader {
+ t.Fatal("concurrent transfers published conflicting leaders")
+ }
+ }
+}
diff --git a/server/teams.go b/server/teams.go
@@ -174,7 +174,7 @@ func (server *server) handleTeamAction(client *worldClient, body []byte) error {
}
return server.leaveTeam_locked(player, updates)
}
- if (action != 26 && action != 28) || binary.BigEndian.Uint32(body[20:24]) != 50000 ||
+ if (action != 22 && action != 25 && action != 26 && action != 28) || binary.BigEndian.Uint32(body[20:24]) != 50000 ||
binary.BigEndian.Uint32(body[28:32]) != 0 || binary.BigEndian.Uint32(body[32:36]) > 1 {
return nil
}
@@ -182,6 +182,34 @@ func (server *server) handleTeamAction(client *worldClient, body []byte) error {
if target == nil || target.npc || target.id == client.id {
return nil
}
+
+ // Kick and leadership transfer require the current leader and another member.
+ if action == 22 || action == 25 {
+ if binary.BigEndian.Uint32(body[32:36]) != 0 || player.team == nil || player.team.leader != player.id || target.team != player.team {
+ return nil
+ }
+ if action == 22 {
+ if err := server.leaveTeam_locked(target, updates); err != nil {
+ return err
+ }
+ if other := server.clients[target.id]; other != nil && other.ready && !other.loading {
+ updates[other] = append(updates[other], characterActionPacket(target.id, [5]uint32{21, 50000, player.id, 0, 24}))
+ }
+ return nil
+ }
+ updated := *player.team
+ updated.leader = target.id
+ if err := server.saveTeam_locked(player.team, &updated); err != nil {
+ return err
+ }
+ for _, member := range updated.members {
+ if other := server.clients[member]; other != nil && other.ready && !other.loading {
+ updates[other] = append(updates[other], characterActionPacket(member, [5]uint32{35, 50000, target.id, 57001, updated.id}))
+ }
+ }
+ return nil
+ }
+
// CharacterAction 26 recruits; action 28 replies to the stored inviter.
if action == 26 {
other := server.clients[target.id]
@@ -275,7 +303,7 @@ func (server *server) leaveTeam_locked(player *character, updates map[*worldClie
}
} else {
updates[other] = append(updates[other], characterActionPacket(member, [5]uint32{32, 50000, player.id}))
- if member != player.id {
+ if member != player.id && remaining.leader != previous.leader {
updates[other] = append(updates[other], characterActionPacket(member, [5]uint32{35, 50000, remaining.leader, 57001, remaining.id}))
}
}