commit b97da952b3a56f2918d3cb7be644f2a1e4514d2e
parent f3a0acd36ff069999bdb8997072a6a1fff6cc149
Author: anon <anon@example.com>
Date: Fri, 23 Oct 2026 23:00:48 +0000
Deliver team affiliation metadata and fix neutral team headers
Diffstat:
11 files changed, 413 insertions(+), 64 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -468,11 +468,19 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
evidence and native tests cover Recruit permissions, visibility/range,
combat, XP-range warnings, competing/pending invitations, expiry and Ignore.
The current single-prompt and same-playfield gates are explicit policies.
-- [ ] Initialize and update team side and team level. Check: native headers
- show the correct affiliations and level for neutral, Clan, Omni and mixed
- 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`.
+- [x] Verify team side delivery throughout the native lifecycle. Check: neutral,
+ Clan, Omni and mixed teams display the current derived side after join,
+ leave, reconnect, zoning, restart and faction changes, including an unchanged
+ neutral value. Stat 213 delivery and a readable client header cache correction
+ are implemented; current derivation uses the common affiliation or neutral.
+- [ ] Recover the complete 14.9.1 team-side matrix. Check: target-period evidence
+ resolves all faction combinations, leader/order dependence and departure
+ recomputation. The current mixed-neutral policy has partial 2002 support;
+ Omni/Neutral is unresolved and a 2006 report describes a different result.
+- [ ] Implement original team-level progression. Check: recovered thresholds,
+ penalties, resets and bonuses agree with native headers after join, leave,
+ reconnect and restart. CharacterAction 27 is recovered; the current native
+ initial level is 1. Later manuals do not establish the original timer.
- [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
diff --git a/client/Makefile.linux b/client/Makefile.linux
@@ -170,6 +170,7 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric
./build/linux/linecrypt
./build/linux/guest-heap
./build/linux/native-input
+ ./build/linux/team-header
./build/linux/weapon-range
./build/linux/ip-training
./build/linux/fling-result
@@ -585,6 +586,12 @@ build/linux/loading-fade: tests/loading_fade.c game/ddr.dll/lifted-0014.c runtim
test: build/linux/loading-fade
+build/linux/team-header: tests/team_header.c game/ddr.dll/lifted-0019.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
+ @mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
+
+test: build/linux/team-header
+
build/linux/music: tests/music.c runtime/linux_music.c runtime/linux_thread.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c game/mmr.dll/lifted-0001.c runtime/linux_music.h runtime/linux_thread.h
mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@
diff --git a/client/Makefile.wasm b/client/Makefile.wasm
@@ -208,6 +208,10 @@ build/wasm/loading-fade.js: tests/loading_fade.c game/ddr.dll/lifted-0014.c runt
mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
+build/wasm/team-header.js: tests/team_header.c game/ddr.dll/lifted-0019.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
+ @mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@
+
build/wasm/web/music-test.html: tests/music.c runtime/linux_music.c runtime/linux_thread.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c game/mmr.dll/lifted-0001.c runtime/linux_music.h runtime/linux_thread.h
@mkdir -p $(@D)
diff --git a/client/game/ddr.dll/lifted-0019.c b/client/game/ddr.dll/lifted-0019.c
@@ -2263,53 +2263,50 @@ L_2B04A080:
}
void sub_2B04A100(void) {
- int _fpu_cmp = 0;
- uint32_t _cf = 0;
- int _df = 1;
- uint32_t _flag_k = FK_NONE;
- uint32_t _flag_a = 0, _flag_b = 0;
- uint32_t _itail_tgt = 0;
+ uint32_t _flag_k = FK_NONE, _flag_a = 0, _flag_b = 0, _cf = 0;
RECOMP_REGS_LOCALS
RECOMP_ENTER(0x2B04A100u);
+ const uint32_t view = ecx;
+ PUSH32(esp, ebp);
+ ebp = esp;
+ esp -= 52;
+ const uint32_t text = esp;
-L_2B04A100:
- PUSH32(esp, ebp); /* 0x2B04A100: push ebp */
- ebp = esp; /* 0x2B04A101: mov ebp, esp */
- _flag_a = (uint32_t)(esp); _flag_b = (uint32_t)(0x34u);
- _cf = (uint32_t)CMP_B(_flag_a, _flag_b);
- esp = esp - 0x34u; /* 0x2B04A103: sub esp, 0x34 */
- _flag_k = FK_CMP;
- PUSH32(esp, esi); /* 0x2B04A106: push esi */
- esi = ecx; /* 0x2B04A107: mov esi, ecx */
- eax = MEM32(esi + 0x60); /* 0x2B04A109: mov eax, dword ptr [esi + 0x60] */
- PUSH32(esp, eax); /* 0x2B04A10C: push eax */
- RECOMP_ICALL(MEM32(0x2B0B5D6C)); /* 0x2B04A10D: call dword ptr [0x2b0b5d6c] */
- RECOMP_FLAGS_IN();
- ecx = eax; /* 0x2B04A113: mov ecx, eax */
- RECOMP_ICALL(MEM32(0x2B0B5E5C)); /* 0x2B04A115: call dword ptr [0x2b0b5e5c] */
- RECOMP_FLAGS_IN();
- ecx = MEM32(esi + 0x64); /* 0x2B04A11B: mov ecx, dword ptr [esi + 0x64] */
- PUSH32(esp, eax); /* 0x2B04A11E: push eax */
- PUSH32(esp, ecx); /* 0x2B04A11F: push ecx */
- PUSH32(esp, 0x2B0E7B7Cu); /* 0x2B04A120: push 0x2b0e7b7c */
- edx = ebp + (-0x34); /* 0x2B04A125: lea edx, [ebp - 0x34] */
- PUSH32(esp, 0x32u); /* 0x2B04A128: push 0x32 */
- PUSH32(esp, edx); /* 0x2B04A12A: push edx */
- RECOMP_ICALL(0x2B012180u); /* 0x2B04A12B: call 0x2b012180 */ /* not lifted */
- RECOMP_FLAGS_IN();
- ecx = MEM32(esi + 0x44); /* 0x2B04A130: mov ecx, dword ptr [esi + 0x44] */
- _flag_a = (uint32_t)(esp); _flag_b = (uint32_t)(0x14u);
- _cf = (uint32_t)((uint32_t)(_flag_a + _flag_b) < (uint32_t)_flag_a);
- esp = esp + 0x14u; /* 0x2B04A133: add esp, 0x14 */
- _flag_k = FK_ADD;
- eax = ebp + (-0x34); /* 0x2B04A136: lea eax, [ebp - 0x34] */
- PUSH32(esp, eax); /* 0x2B04A139: push eax */
- RECOMP_ICALL(MEM32(0x2B0B5850)); /* 0x2B04A13A: call dword ptr [0x2b0b5850] */
+ /* Read raw TeamSide; an unchanged neutral stat does not notify the GUI. */
+ PUSH32(esp, 0);
+ PUSH32(esp, 213);
+ RECOMP_ICALL(MEM32(0x2B0B5D6C));
+ RECOMP_FLAGS_IN();
+ ecx = eax;
+ RECOMP_ICALL(MEM32(0x2B0B5D70));
+ RECOMP_FLAGS_IN();
+ MEM32(view + 0x60) = eax;
+
+ /* Use the native side labels, level and bounded header formatter. */
+ PUSH32(esp, eax);
+ RECOMP_ICALL(MEM32(0x2B0B5D6C));
RECOMP_FLAGS_IN();
- esi = POP32_VAL(esp); /* 0x2B04A140: pop esi */
- esp = ebp; /* 0x2B04A141: mov esp, ebp */
- ebp = POP32_VAL(esp); /* 0x2B04A143: pop ebp */
- RECOMP_FLAGS_OUT(); esp += 4; { RECOMP_REGS_OUT(); return; } /* 0x2B04A144: ret */
+ ecx = eax;
+ RECOMP_ICALL(MEM32(0x2B0B5E5C));
+ RECOMP_FLAGS_IN();
+ PUSH32(esp, eax);
+ PUSH32(esp, MEM32(view + 0x64));
+ PUSH32(esp, 0x2B0E7B7C);
+ PUSH32(esp, 50);
+ PUSH32(esp, text);
+ RECOMP_ICALL(0x2B012180u);
+ RECOMP_FLAGS_IN();
+ esp += 20;
+
+ /* Publish the label and preserve the guest caller's frame. */
+ ecx = MEM32(view + 0x44);
+ PUSH32(esp, text);
+ RECOMP_ICALL(MEM32(0x2B0B5850));
+ RECOMP_FLAGS_IN();
+ esp = ebp;
+ ebp = POP32_VAL(esp);
+ esp += 4;
+ RECOMP_FLAGS_OUT();
RECOMP_REGS_OUT();
}
diff --git a/client/tests/team_header.c b/client/tests/team_header.c
@@ -0,0 +1,97 @@
+#include "recomp_types.h"
+#include <assert.h>
+
+void sub_2B04A100(void);
+static uint32_t current_side;
+static unsigned queries;
+static char published[64];
+
+static void interface_instance(void) { g_eax = 0x50002000; g_esp += 4; }
+static void get_skill(void)
+{
+ assert(g_ecx == 0x50002000);
+ assert(MEM32(g_esp + 4) == 213 && MEM32(g_esp + 8) == 0);
+ ++queries;
+ g_eax = current_side;
+ g_esp += 12;
+}
+static void side_string(void)
+{
+ assert(g_ecx == 0x50002000);
+ switch (MEM32(g_esp + 4)) {
+ case 0: g_eax = 0x50003000; break;
+ case 1: g_eax = 0x50003010; break;
+ case 2: g_eax = 0x50003020; break;
+ default: g_eax = 0x50003030; break;
+ }
+ g_esp += 8;
+}
+static void format_header(void)
+{
+ uint32_t output = MEM32(g_esp + 4), size = MEM32(g_esp + 8);
+ const char *format = (const char *)ADDR(MEM32(g_esp + 12));
+ assert(size == 50 && !strcmp(format, "Team level: %u Team side: %s"));
+ snprintf((char *)ADDR(output), size, format, MEM32(g_esp + 16), (char *)ADDR(MEM32(g_esp + 20)));
+ g_esp += 4;
+}
+static void set_text(void)
+{
+ assert(g_ecx == 0x50001000);
+ snprintf(published, sizeof(published), "%s", (char *)ADDR(MEM32(g_esp + 4)));
+ g_esp += 8;
+}
+recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
+recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
+recomp_func_t recomp_lookup(uint32_t address)
+{
+ switch (address) {
+ case 1: return interface_instance;
+ case 2: return get_skill;
+ case 3: return side_string;
+ case 4: return set_text;
+ case 0x2b012180: return format_header;
+ default: abort();
+ }
+}
+
+static void check_header(uint32_t cached, uint32_t side, uint32_t level, const char *expected)
+{
+ MEM32(0x50000044) = 0x50001000;
+ MEM32(0x50000060) = cached;
+ MEM32(0x50000064) = level;
+ g_esp = 0x5000ff00;
+ g_ecx = 0x50000000;
+ g_esi = 123;
+ g_edi = 456;
+ g_ebp = 789;
+ current_side = side;
+ queries = 0;
+ published[0] = 0;
+
+ sub_2B04A100();
+
+ assert(!strcmp(published, expected));
+ assert(queries == 1 && MEM32(0x50000060) == side && MEM32(0x50000064) == level);
+ assert(g_esp == 0x5000ff04 && g_esi == 123 && g_edi == 456 && g_ebp == 789);
+}
+
+int main(void)
+{
+ assert(guest_map("team UI", 0x2b000000, 0x100000));
+ assert(guest_map("team header fixture", 0x50000000, 0x10000));
+ MEM32(0x2b0b5d6c) = 1;
+ MEM32(0x2b0b5d70) = 2;
+ MEM32(0x2b0b5e5c) = 3;
+ MEM32(0x2b0b5850) = 4;
+ strcpy((char *)ADDR(0x2b0e7b7c), "Team level: %u Team side: %s");
+ strcpy((char *)ADDR(0x50003000), "neutral");
+ strcpy((char *)ADDR(0x50003010), "clan");
+ strcpy((char *)ADDR(0x50003020), "omni");
+ strcpy((char *)ADDR(0x50003030), "Missing");
+
+ check_header(UINT32_MAX, 0, 1, "Team level: 1 Team side: neutral");
+ check_header(UINT32_MAX, 1, 1, "Team level: 1 Team side: clan");
+ check_header(0, 2, 3, "Team level: 3 Team side: omni");
+ check_header(2, 0, 1, "Team level: 1 Team side: neutral");
+ puts("team header: fresh neutral and stale affiliation caches refresh from native stats");
+}
diff --git a/docs/teams.md b/docs/teams.md
@@ -135,10 +135,55 @@ 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.
-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 or disconnect expiry are complete.
+## Team affiliation metadata
+
+The server derives team side from the accepted roster and current character
+affiliations. Unanimous rosters use that affiliation; differing affiliations
+currently produce neutral (0). Each recipient receives local stat 213 through
+StatIIR key `2b333d6e`, after its roster and leader. Departure clears the former
+member's value and recomputes remaining members' values. Durable faction edits,
+including edits to offline members, update connected teammates. The derived
+value needs no separate database field and is restored on ready/reconnect.
+
+This complete matrix is a reconstruction policy, not recovered 14.9.1 server
+code. The April 2002 report above describes Clan/Neutral teams as neutral; an
+[August 2002 firsthand report](https://forums-archive.anarchy-online.com/showthread.php?46566-Q-amp-A-from-Pro-Forum=&p=642292&viewfull=1)
+describes multiple Clan players and one Omni producing neutral status. Neither
+establishes every combination or leader dependence. A
+[November 2006 report](https://forums-archive.anarchy-online.com/showthread.php?470615-End-game-Clan-Omni-toons-vs-Neutral-toons=)
+instead describes Neutral/Omni displaying Omni. That later observation does
+not establish the target version's rule. Exact target-period side derivation
+remains open, especially Omni/Neutral.
+
+Fresh neutral formation reproduced an original client cache bug: actor defaults
+initialize raw stat 213 to 0 without a GUI callback, while TeamView starts its
+side cache at -1. Sending 0 again is filtered by the native changed-only setter,
+leaving the visible header at `Team side: Missing`. The readable C formatter
+`client/game/ddr.dll/lifted-0019.c:sub_2B04A100` now queries current raw stat 213
+through the existing native GetSkill API before formatting the header. It keeps
+native side strings, level formatting and text publication. No artificial
+intermediate side is sent. The original formatter fails the new regression;
+the correction passes it as both native code and WASM.
+
+The source/ABI audit and period evidence are retained in
+`local/team-metadata-research/`. Go checks cover the current affiliation matrix,
+join/leave/kick recomputation, online/offline edits, database reopen and failed
+SQL updates with no published success. The full Go suite passed in 383 seconds;
+all team tests passed twice under the race detector in 148 seconds. The full
+native test suite passed on the GPU, including the header regression.
+
+Two hardware-rendered WASM clients verified fresh neutral restoration after
+server restart, leave/rejoin in the same guest, all-Clan/all-Omni and mixed
+faction edits, native reconnects, cross-playfield shop zoning and a fresh page
+reload. Both native headers and raw stat 213 agreed with the current policy.
+`local/team-metadata-research/verification.json` checks 24 read-only native
+snapshots against the database and conserves all 192 item records and placements.
+The test roster was dissolved, original profiles restored, and all owned browser
+contexts closed. No page or adapter errors were reported; the single shared LAN
+preview remains available on HTTPS 8443.
+
+Team level still uses the native initial value 1. CharacterAction 27 carries
+level updates, but original progression thresholds, penalties and bonuses are
+unverified. A later official manual describes time-based growth, but does not
+establish a 14.9.1 timer. Team-level progression, remote HP/nano updates, chat,
+XP sharing, loot rotation and disconnect expiry remain separate open work.
diff --git a/server/control.go b/server/control.go
@@ -321,11 +321,20 @@ func (server *server) prepareUser_locked(character, updated *character) {
func (server *server) applyUser_locked(character, updated *character) error {
// Hold updateMutex and mutex; release mutex before sending reconnect packets.
previousPlayfield := character.playfield
+ previousSide := character.appearance >> 9 & 3
updates := make(map[*worldClient][][]byte)
server.cancelCombat_locked(character.id, updates)
updated.fighting = 0
updated.nextAttack = time.Time{}
*character = *updated
+ // Team side is derived from the durable roster and each member's affiliation.
+ if character.team != nil && previousSide != character.appearance>>9&3 {
+ for _, member := range character.team.members {
+ if other := server.clients[member]; other != nil && other.ready && !other.loading {
+ updates[other] = append(updates[other], server.teamSidePacket_locked(member))
+ }
+ }
+ }
client := server.clients[character.id]
if client == nil || !client.ready {
server.mutex.Unlock()
diff --git a/server/team_leadership_test.go b/server/team_leadership_test.go
@@ -57,12 +57,12 @@ func TestTeamLeaderKicksMemberWithoutChangingRemainingLeader(t *testing.T) {
}
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 {
+ if len(packets) != 2 || 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 {
+ if len(connections[1].packets) != 3 || binary.BigEndian.Uint32(connections[1].packets[0][29:33]) != 32 ||
+ binary.BigEndian.Uint32(connections[1].packets[2][29:33]) != 21 || binary.BigEndian.Uint32(connections[1].packets[2][45:49]) != 24 || len(connections[3].packets) != 0 {
t.Fatal("kicked member did not receive native removal and kicked feedback")
}
}
@@ -87,7 +87,7 @@ func TestTeamKickLastPeerDissolvesPairAndOfflineKickPersists(t *testing.T) {
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 {
+ len(connections[0].packets) != 3 || offline && len(connections[1].packets) != 0 || !offline && len(connections[1].packets) != 4 {
t.Fatalf("pair kick left an orphaned team or wrote to an offline member: %v", err)
}
})
diff --git a/server/team_side_test.go b/server/team_side_test.go
@@ -0,0 +1,165 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "testing"
+)
+
+func assertTeamSide(t *testing.T, packets [][]byte, owner, want uint32) {
+ t.Helper()
+ var found int
+ for _, packet := range packets {
+ if binary.BigEndian.Uint32(packet[16:20]) != 0x2b333d6e || binary.BigEndian.Uint32(packet[29:33]) != 213 {
+ continue
+ }
+ found++
+ if len(packet) != 40 || binary.BigEndian.Uint32(packet[20:24]) != 50000 ||
+ binary.BigEndian.Uint32(packet[24:28]) != owner || binary.BigEndian.Uint32(packet[33:37]) != want {
+ t.Fatalf("team side owner=%d want=%d: %x", owner, want, packet)
+ }
+ }
+ if found != 1 {
+ t.Fatalf("owner %d received %d team-side updates, want one", owner, found)
+ }
+}
+
+func TestTeamSideFormationUsesCommonAffiliationOrNeutral(t *testing.T) {
+ for _, scenario := range []struct {
+ name string
+ sides []uint16
+ want uint32
+ }{
+ {"neutral", []uint16{0, 0}, 0},
+ {"clan", []uint16{1, 1}, 1},
+ {"omni", []uint16{2, 2}, 2},
+ {"clan neutral", []uint16{1, 0}, 0},
+ {"neutral clan", []uint16{0, 1}, 0},
+ {"omni neutral", []uint16{2, 0}, 0},
+ {"neutral omni", []uint16{0, 2}, 0},
+ {"clan omni", []uint16{1, 2}, 0},
+ {"omni clan", []uint16{2, 1}, 0},
+ {"clan majority", []uint16{1, 1, 2}, 0},
+ {"all affiliations", []uint16{0, 1, 2}, 0},
+ } {
+ t.Run(scenario.name, func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ for index, side := range scenario.sides {
+ world.characters[uint32(index+1)].appearance = 16 | side<<9
+ }
+ if len(scenario.sides) == 3 {
+ formTestTeam(t, world, 1, 2)
+ }
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+
+ formTestTeam(t, world, 1, uint32(len(scenario.sides)))
+
+ for index := range scenario.sides {
+ assertTeamSide(t, connections[index].packets, uint32(index+1), scenario.want)
+ }
+ for _, conn := range connections[len(scenario.sides):] {
+ if len(conn.packets) != 0 {
+ t.Fatal("unrelated player received team metadata")
+ }
+ }
+ })
+ }
+}
+
+func TestTeamSideDepartureReclassifiesRemainingMembersAndClearsLeaver(t *testing.T) {
+ for _, action := range []uint32{22, 24} {
+ t.Run(fmt.Sprint(action), func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ world.characters[1].appearance, world.characters[2].appearance = 16|1<<9, 16|1<<9
+ world.characters[3].appearance = 16 | 2<<9
+ formTestTeam(t, world, 1, 2)
+ formTestTeam(t, world, 1, 3)
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ client, target := world.clients[1], uint32(3)
+ if action == 24 {
+ client, target = world.clients[3], 0
+ }
+
+ err := world.handleTeamAction(client, teamRequest(client.id, action, target, 0))
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ assertTeamSide(t, connections[0].packets, 1, 1)
+ assertTeamSide(t, connections[1].packets, 2, 1)
+ assertTeamSide(t, connections[2].packets, 3, 0)
+ })
+ }
+}
+
+func TestTeamSideProfileEditPublishesDurableAffiliationToCurrentMembers(t *testing.T) {
+ for _, offline := range []bool{false, true} {
+ t.Run(fmt.Sprint(offline), func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ world.characters[1].appearance, world.characters[2].appearance = 16|1<<9, 16|1<<9
+ formTestTeam(t, world, 1, 2)
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ if offline {
+ delete(world.clients, 1)
+ }
+ updated := world.characters[1].userData()
+ updated.Appearance = 16 | 2<<9
+
+ err := world.updateUser(updated)
+ restored := newTestInventoryServer(t)
+ conn := &combatTestConn{}
+ restored.clients[1] = &worldClient{id: 1, conn: conn, target: true, ready: true, loading: true}
+ ready := restored.handleCharacterReady(restored.clients[1])
+
+ if err != nil || ready != nil || restored.characters[1].appearance != 16|2<<9 || world.characters[1].team != world.characters[2].team {
+ t.Fatalf("profile edit lost durable affiliation or membership: %v %v", err, ready)
+ }
+ assertTeamSide(t, connections[1].packets, 2, 0)
+ assertTeamSide(t, conn.packets, 1, 0)
+ if offline {
+ if len(connections[0].packets) != 0 {
+ t.Fatal("offline member received metadata")
+ }
+ } else {
+ assertTeamSide(t, connections[0].packets, 1, 0)
+ }
+ for _, packet := range connections[2].packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e {
+ t.Fatal("unrelated player received private team stats")
+ }
+ }
+ })
+ }
+}
+
+func TestTeamSideFailedProfileEditPublishesNoAffiliation(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ formTestTeam(t, world, 1, 2)
+ for _, conn := range connections {
+ conn.packets = nil
+ }
+ updated := world.characters[1].userData()
+ updated.Appearance = 16 | 2<<9
+ if _, err := world.db.Exec("CREATE TRIGGER fail_side BEFORE UPDATE ON characters WHEN OLD.id=1 BEGIN SELECT RAISE(FAIL, 'test profile failure'); END"); err != nil {
+ t.Fatal(err)
+ }
+ before := world.characters[1].appearance
+
+ err := world.updateUser(updated)
+ restored := newTestInventoryServer(t)
+
+ if err == nil || world.characters[1].appearance != before || restored.characters[1].appearance != before {
+ t.Fatal("failed profile transaction changed affiliation")
+ }
+ for _, conn := range connections {
+ if len(conn.packets) != 0 {
+ t.Fatal("failed profile transaction published affiliation")
+ }
+ }
+}
diff --git a/server/teams.go b/server/teams.go
@@ -129,7 +129,23 @@ func (server *server) teamPackets_locked(owner uint32) [][]byte {
body = append(body, name...)
packets = append(packets, n3Packet(0x46312d2e, 50000, owner, body))
}
- return append(packets, characterActionPacket(owner, [5]uint32{35, 50000, team.leader, 57001, team.id}))
+ return append(packets, characterActionPacket(owner, [5]uint32{35, 50000, team.leader, 57001, team.id}), server.teamSidePacket_locked(owner))
+}
+
+func (server *server) teamSidePacket_locked(owner uint32) []byte {
+ side := uint32(0)
+ if team := server.characters[owner].team; team != nil {
+ side = uint32(server.characters[team.members[0]].appearance >> 9 & 3)
+ for _, member := range team.members[1:] {
+ if uint32(server.characters[member].appearance>>9&3) != side {
+ side = 0
+ break
+ }
+ }
+ }
+ body := binary.BigEndian.AppendUint32(nil, 213)
+ body = binary.BigEndian.AppendUint32(body, side)
+ return n3Packet(0x2b333d6e, 50000, owner, body)
}
func (server *server) teamInCombat_locked(player *character) bool {
@@ -307,6 +323,7 @@ func (server *server) leaveTeam_locked(player *character, updates map[*worldClie
updates[other] = append(updates[other], characterActionPacket(member, [5]uint32{35, 50000, remaining.leader, 57001, remaining.id}))
}
}
+ updates[other] = append(updates[other], server.teamSidePacket_locked(member))
}
return nil
}
diff --git a/server/teams_test.go b/server/teams_test.go
@@ -67,11 +67,11 @@ func TestTeamInvitationRequiresAcceptanceAndPublishesNativeRoster(t *testing.T)
binary.BigEndian.Uint32(prompt[29:33]) != 26 || binary.BigEndian.Uint32(prompt[37:41]) != 1 {
t.Fatalf("native invitation: %x", prompt)
}
- if len(connections[0].packets) != 3 || len(connections[1].packets) != 4 || len(connections[2].packets) != 0 {
+ if len(connections[0].packets) != 4 || len(connections[1].packets) != 5 || len(connections[2].packets) != 0 {
t.Fatal("roster reached unrelated player or repeated membership")
}
for index, connection := range connections[:2] {
- roster := connection.packets[len(connection.packets)-3:]
+ roster := connection.packets[len(connection.packets)-4:]
if binary.BigEndian.Uint32(roster[0][16:20]) != 0x46312d2e || binary.BigEndian.Uint32(roster[index][45:49]) != 100 ||
binary.BigEndian.Uint32(roster[0][33:37]) != uint32(index+1) || binary.BigEndian.Uint32(roster[1][33:37]) != uint32(2-index) || binary.BigEndian.Uint32(roster[2][29:33]) != 35 ||
binary.BigEndian.Uint32(roster[2][37:41]) != 1 || binary.BigEndian.Uint32(roster[2][41:45]) != 57001 {
@@ -277,7 +277,7 @@ func TestTeamLeaveTransfersLeadershipAndDissolvesLastPair(t *testing.T) {
world.characters[1].team != nil || world.characters[2].team != nil || world.characters[3].team != nil || restored.characters[3].team != nil {
t.Fatal("departure retained membership or lost leadership succession")
}
- if len(connections[0].packets) != 1 || len(connections[1].packets) != 4 || len(connections[2].packets) != 4 ||
+ if len(connections[0].packets) != 2 || len(connections[1].packets) != 6 || len(connections[2].packets) != 6 ||
binary.BigEndian.Uint32(connections[1].packets[1][29:33]) != 35 || binary.BigEndian.Uint32(connections[1].packets[1][37:41]) != 2 {
t.Fatal("departure did not publish native removal and new leader exactly once")
}
@@ -299,7 +299,7 @@ func TestTeamReadyReplaysRosterOnceAndProfileEditRetainsMembership(t *testing.T)
updated.Name = "Renamed member"
err := world.updateUser(updated)
- if first != nil || second != nil || err != nil || world.characters[1].team != team || world.characters[2].team != team || len(connections[0].packets) != 5 {
+ if first != nil || second != nil || err != nil || world.characters[1].team != team || world.characters[2].team != team || len(connections[0].packets) != 6 {
t.Fatalf("ready replay or profile change lost team: %v %v %v", first, second, err)
}
}