commit 3cb33f7f887fb958e74cb8ee774f942e2ea5cade
parent 0cceab8510e58e02f1be404cd68e53e97ce784cb
Author: anon <anon@example.com>
Date: Sat, 24 Oct 2026 10:35:16 +0000
Implement native player information replies
Diffstat:
14 files changed, 501 insertions(+), 14 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -719,12 +719,26 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah
- [ ] Recover remaining original friend-list policies. Check: period evidence
establishes temporary-entry durability, maximum list size, other presence
states and original denial behavior; do not invent limits or away flags.
-- [ ] Verify the native reference and Friends-window action paths. Check:
+- [x] Verify the native reference and Friends-window action paths. Check:
Alt+left-click creates a player reference, dropping it adds a permanent
friend, Accept promotes a temporary entry and Remove sends native 41.
- Exercise self/NPC references and repeat actions. The manual reference attempt
- left Knowledge empty; investigate input/reference handling before claiming
- these UI paths work. Commands and incoming-tell addition are verified.
+ Two hardware WASM clients verified Alt/G creation, reference pickup/drop,
+ repeated adds, self-add rejection, NPC reference suppression and the full
+ right-hold/hover/release Accept/Remove gesture. CharacterAction 105 now has
+ its original InfoPacket reply; C adapters fix reached `_strdate` and
+ `strcspn` crashes. Description values and reference persistence remain below.
+ See [player information](docs/character-info.md).
+- [ ] Correct native reference description stats. Check: a level-150 Engineer
+ reference shows the actual level/profession/title, rather than level 0 and
+ no profession. Live raw actor stats are correct after InfoPacket, and the
+ original effective-stat getter chain passes controlled Linux/WASM fixtures.
+ Resolve the live renderer/lookup discrepancy without replacing original
+ stat behavior with a raw-value shortcut. Evidence: `local/reference-research/render.md`
+ and `local/reference-smoke/reference-description-final.png`.
+- [ ] Persist Knowledge references in the browser using the original native
+ format and save timing. Check: player references and their descriptions
+ survive reload/reconnect and remain separate between characters. The verified
+ Friends entry survives reload, but its source Knowledge reference disappears.
- [ ] Ignore one player. Check: the supported chat channels honor the saved
ignore entry and removing it restores delivery.
- [ ] Recover original channel flags, preferences and flood rules. Check: native
@@ -901,6 +915,10 @@ and server restarts. Turn every reproduced bug into a focused regression test.
- [ ] Audit combat scheduling and outcomes. Cover range boundaries, moving or
unavailable targets, repeated starts/stops, timing changes, equipment changes,
two attackers, lethal and nonlethal hits, queued native results and HP agreement.
+ Include player inspection while a weapon hit is queued: original InfoPacket
+ applies absolute remote HP without an animation guard, so it shares the
+ unresolved healing/hit ordering problem. Verify the server, owner and observer
+ through impact and subsequent regeneration; see [inspection](docs/character-info.md).
- [ ] Audit ranged ammunition and reload. Cover empty/partial/full magazines,
matching/wrong/missing ammunition, insufficient stacks, repeated reloads,
reload during each attack phase, failed saves and round conservation across
diff --git a/client/Makefile.linux b/client/Makefile.linux
@@ -391,7 +391,7 @@ test: build/linux/locale
build/linux/crt-time: tests/crt_time.c runtime/guest_crt.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_crt.h runtime/guest_heap.h runtime/guest_memory.h
mkdir -p $(@D)
- $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -lm -o $@
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -Wl,--wrap=time -lm -o $@
test: build/linux/crt-time
diff --git a/client/runtime/guest_crt.c b/client/runtime/guest_crt.c
@@ -627,6 +627,16 @@ static void crt_gmtime(void)
memcpy((void *)ADDR(g_eax), fields, sizeof(fields));
}
+static void crt_strdate(void)
+{
+ time_t now = time(NULL);
+ struct tm converted;
+ localtime_r(&now, &converted);
+ g_eax = MEM32(g_esp + 4);
+ strftime((char *)ADDR(g_eax), 9, "%m/%d/%y", &converted);
+ g_esp += 4;
+}
+
static void crt_asctime(void)
{
uint32_t input = MEM32(g_esp + 4);
@@ -674,6 +684,13 @@ static void crt_strchr(void)
g_esp += 4;
}
+static void crt_strcspn(void)
+{
+ g_eax = (uint32_t)strcspn((const char *)ADDR(MEM32(g_esp + 4)),
+ (const char *)ADDR(MEM32(g_esp + 8)));
+ g_esp += 4;
+}
+
static void crt_strstr(void)
{
uint32_t start = MEM32(g_esp + 4);
@@ -1085,10 +1102,10 @@ recomp_func_t guest_crt_lookup(const char *name)
{"srand", crt_srand}, {"rand", crt_rand},
{"qsort", crt_qsort},
{"calloc", crt_calloc}, {"strncpy", crt_strncpy}, {"strchr", crt_strchr},
- {"strcpy", crt_strcpy},
+ {"strcpy", crt_strcpy}, {"strcspn", crt_strcspn},
{"strstr", crt_strstr},
{"time", crt_time},
- {"gmtime", crt_gmtime}, {"asctime", crt_asctime},
+ {"gmtime", crt_gmtime}, {"asctime", crt_asctime}, {"_strdate", crt_strdate},
{"memcpy", crt_memcpy}, {"memmove", crt_memmove}, {"memset", crt_memset},
{"_initterm", crt_initterm},
{"__dllonexit", crt_dllonexit},
diff --git a/client/tests/crt_time.c b/client/tests/crt_time.c
@@ -5,10 +5,50 @@
#ifdef _WIN32
#include <windows.h>
#else
+#include <stdlib.h>
+#include <time.h>
#include "guest_crt.h"
#include "guest_memory.h"
recomp_func_t recomp_lookup(uint32_t address) { abort(); }
recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
+
+static time_t current_time;
+time_t __wrap_time(time_t *output)
+{
+ if (output) *output = current_time;
+ return current_time;
+}
+
+static void local_date_formats_exactly_nine_bytes(void)
+{
+ const struct { time_t seconds; const char *zone, *text; } cases[] = {
+ {0, "UTC0", "01/01/70"},
+ {951782400, "UTC0", "02/29/00"},
+ {946684799, "UTC0", "12/31/99"},
+ {946684800, "UTC0", "01/01/00"},
+ {2147483647, "UTC0", "01/19/38"},
+ {0, "PST8", "12/31/69"},
+ {28800, "PST8", "01/01/70"},
+ };
+ for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
+ current_time = cases[i].seconds;
+ setenv("TZ", cases[i].zone, 1);
+ tzset();
+ memset((void *)ADDR(0x50000100), 0xa5, 11);
+ MEM32(guest_crt_errno_address()) = 777;
+ g_esp = 0x5000ff00;
+ MEM32(g_esp + 4) = 0x50000101;
+ g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
+
+ guest_crt_lookup("_strdate")();
+
+ assert(g_eax == 0x50000101 && g_esp == 0x5000ff04);
+ assert(!strcmp((char *)ADDR(g_eax), cases[i].text));
+ assert(MEM8(0x50000100) == 0xa5 && MEM8(0x5000010a) == 0xa5);
+ assert(MEM32(guest_crt_errno_address()) == 777);
+ assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
+ }
+}
#endif
int main(void)
@@ -96,5 +136,8 @@ int main(void)
assert(g_esp == 0x5000ff04);
#endif
}
+#ifndef _WIN32
+ local_date_formats_exactly_nine_bytes();
+#endif
puts("CRT time: epoch, leap day, 2038 limit, negative boundary, invalid times, x86 layout, stable storage, errno and ABI passed");
}
diff --git a/client/tests/guest_crt.c b/client/tests/guest_crt.c
@@ -436,6 +436,33 @@ static void substring_search_returns_guest_addresses(void)
}
}
+static void rejected_character_search_returns_guest_length(void)
+{
+ const struct { const char *text, *reject; uint32_t length; } cases[] = {
+ {"", ":", 0}, {"abc", "", 3}, {"abc", "a", 0},
+ {"abc", "bc", 1}, {"abc", "c", 2}, {"abc", "z", 3},
+ {"abc\0hidden", "h", 3}, {"aa:bb:cc", ":;", 2},
+ {"\x80\xff:x", ":", 2}, {"\x80\xff:x", "\xff", 1},
+ };
+ for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
+ strcpy((char *)ADDR(0x50008003u), cases[i].text);
+ strcpy((char *)ADDR(0x50009001u), cases[i].reject);
+ g_esp = 0x5000ff00u;
+ MEM32(g_esp + 4) = 0x50008003u;
+ MEM32(g_esp + 8) = 0x50009001u;
+ MEM32(guest_crt_errno_address()) = 777;
+ g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
+
+ guest_crt_lookup("strcspn")();
+
+ assert(g_eax == cases[i].length && g_esp == 0x5000ff04u);
+ assert(!strcmp((char *)ADDR(0x50008003u), cases[i].text));
+ assert(!strcmp((char *)ADDR(0x50009001u), cases[i].reject));
+ assert(MEM32(guest_crt_errno_address()) == 777);
+ assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
+ }
+}
+
int main(void)
{
assert(guest_map("test memory and stack", 0x50000000u, 0x10000u));
@@ -458,6 +485,7 @@ int main(void)
strcpy_returns_guest_pointer_and_copies_terminator();
time_writes_only_a_32_bit_guest_value();
substring_search_returns_guest_addresses();
+ rejected_character_search_returns_guest_length();
assert(MEM32(guest_crt_data("_adjust_fdiv")) == 0);
puts("guest CRT: constructors, heap, EH frame, FILE data, rounding and startup state passed");
return 0;
diff --git a/docs/buddies.md b/docs/buddies.md
@@ -115,6 +115,16 @@ connects. Stable logout testing closes that client's tab during its countdown.
Both saved lists also restored after a real server restart. An administrative
teleport exercised native world reconnection on the final build: the friend
stayed online, with no offline packet during the round trip. Artifacts are
-retained in `local/buddy-smoke/`. Player-reference creation/drop and the
-Friends-window Accept/Remove controls remain explicit TODOs; the reference
-attempt left Knowledge empty and was not counted as a successful UI check.
+retained in `local/buddy-smoke/`.
+
+The native reference and Friends controls are also verified with two hardware
+WASM clients. Alt+left-click or G creates a reference after the original
+[player information](character-info.md) reply; picking up its INFO icon and
+placing it in Friends adds a permanent entry. A repeated drop leaves one row,
+self-add is rejected and NPC reference creation is suppressed. Hold the right
+button over a friend, move onto the radial Accept or Remove icon, then release.
+Short clicks do not exercise that gesture. Accept sends type 40 with blob 1;
+Remove sends type 41. Headers and cancelled menus do not change the list.
+Evidence is retained in `local/reference-smoke/` and `local/buddy-ui-research/`.
+The reference description's scalar stats and Knowledge-reference persistence
+remain explicit TODOs; these limitations do not affect the saved friend entry.
diff --git a/docs/character-info.md b/docs/character-info.md
@@ -0,0 +1,123 @@
+# Player inspection and references
+
+The original 14.9.1 client requests player information with CharacterAction
+105. Alt+left-click creates a reference; G creates one for the selected target.
+Reference creation waits for the server's InfoPacket response before adding
+the player to Knowledge. The existing SimpleChar nickname is retained.
+
+## Original packet and callback
+
+Original KKR SHA-256 is
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+`N3Msg_RequestInfoPacket` 0x1002c720 -> 0x10056420 constructs action 105.
+`InfoPacketIIR_t` uses key `0x4d38242e` and the requested player's identity.
+Serializer 0x1005b9a0 and decoder 0x1005bbd0 establish this mandatory payload:
+
+| Offset | Value |
+| --- | --- |
+| 0 | Extension flags, u8 |
+| 1..5 | Five u8 stats: Profession 60, ProfessionLevel 10, TitleLevel 37, VisualSex 369, VisualProfession 368 |
+| 6 | PetMaster 196, u32 |
+| 10 | Side XP bonus, u16 |
+| 12, 16 | Current and maximum HP, u32 each |
+| 20, 24 | Health regeneration delta and interval, u32 each |
+| 28, 32 | Nano regeneration delta and interval, u32 each |
+| 36, 40 | BreedHostility 204 and clan 5, u32 each |
+| 44 onward | Four u16-counted strings: first name, last name, title, description |
+
+Multi-byte fields are big-endian. Flags 0 and four empty strings produce a
+52-byte payload, with no version byte or optional tail. Level 54 and Side 33
+are absent from this packet; the actor spawn already carries them. The title
+string is separate from the nickname. The current player model has no authored
+first/last/title names, description, pet ownership, organization or side XP.
+Those fields remain empty or zero. It has no false-profession effect, so real
+and visual profession agree. ProfessionLevel retains its independent native
+default 1: KKR constructor 0x10072760 initializes stat 10 separately from Level
+54. The current server has no separately authored ProfessionLevel state.
+
+Execute 0x1007faa0 resolves the target actor, applies the packet through
+0x1005b1a0, stores it in the character control and sends module 20/event 0xbb.
+It does not safely handle an absent target. The server only answers for a
+connected player on the requester's current playfield after both world clients
+are ready and their equipment effects have replayed. It serializes replies
+with actor spawn/removal. Self-inspection is supported.
+NPC inspection and the optional extension schemas remain unfinished.
+
+Original DDR SHA-256 is
+`3c937161de8f690351c3c08e158431417cee9ced77a41b677e7123b61a8c9883`.
+`KnowledgeViewModule_t::CreateRef` 0x10045840 suppresses NPC references and
+requests player information through 0x10074b20. InfoPacketAvailable 0x10075780
+-> 0x10074a20 renders the pending player description, then sends module 20/
+event 0xb2. `CreateCharRefMessage` 0x100457c0 adds the resulting reference.
+The renderer 0x1006fc30 calls MSVCRT `_strdate` for its date stamp. Its C adapter
+writes the documented nine-byte, local-date `mm/dd/yy` string and returns the
+guest buffer pointer. See Microsoft's
+[`_strdate` contract](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strdate-wstrdate).
+Picking up the resulting reference also reaches `strcspn` from the native text
+renderer. Its C adapter returns the initial guest-string length before any
+rejected byte, preserving the input strings and the cdecl calling convention.
+
+Complete original exports, matching snapshots and symbol/evidence ledgers are
+retained in `local/reference-research/`. KKR serializer/decoder evidence:
+`ev_9757bf4c1ea87a6c956385944b865747d7fc39852948c4e924483be99a0e916a`,
+`ev_3cedbe5b069de93a1e1edc950983ea6dc092c5addeb822813d7fa2534a84dd7c`.
+DDR reference creation/callback evidence:
+`ev_645f68bf2e0d320519efda9e3a3362e8b91149be672b4ff8240cefe463346be8`,
+`ev_c0f7434f7fc5741f2e24a5e6f102c4ef81baf2b9ced2069a0136cfeca3d355df`.
+
+## Resource interaction and limits
+
+Remote InfoPacket application overwrites raw HP and maximum HP, then resets
+the maximum-HP modifier cache. The server records the direct health equipment
+bonus absorbed by this snapshot, preserving any separately absorbed nano
+bonus. Later equipment/skill corrections use the same observer accounting as
+[team resources](team-resources.md). Local actors retain their owner stats.
+Inspection does not persist anything or broadcast the reply to other players.
+
+The original apply function has no guard for pending weapon animations.
+Inspection during a queued hit therefore shares the outstanding absolute-HP
+ordering problem documented in [nano healing](nano-healing.md). Authoritative
+HP in this response does not resolve that timing problem. Combat-time
+inspection needs further verification and reconstruction of the common hit
+timeline; this feature does not introduce a fabricated stop or alternate
+packet to hide it.
+
+## Verification
+
+Go regressions cover exact native bytes, real world-socket dispatch, self and
+repeated requests, profile fields and combat regeneration intervals, unchanged
+SQLite state, recipient isolation, invalid identities/arguments, unavailable
+targets, cross-playfield requests, loading/replaced/unsupported sessions and
+malformed lengths. A health-bonus snapshot followed by equipment replacement
+checks subsequent maximum accounting without changing the nano basis.
+
+C runtime tests cover leap day, year rollover, the 2038 boundary, local timezone
+offsets, exact buffer bounds, return pointer, errno and preserved registers.
+String tests cover empty inputs/reject sets, each match position, missing and
+repeated delimiters, embedded NUL and high bytes, unchanged inputs and ABI.
+
+Two hardware WASM clients verified Alt/G creation, reference pickup/drop,
+repeated friend additions, self-reference/self-add rejection, NPC suppression,
+native Accept/Remove, owner reload, profile variation and equipped-resource
+accounting. A level-150 female Engineer retained Level 150 and ProfessionLevel
+1 while InfoPacket corrected remote profession/title/regeneration fields.
+Dust Collector inspection changed raw maximum HP from 931 plus modifier 90 to
+1021 plus modifier 0, preserving the nano modifier. Removal and replacement
+with Pioneer left both owner and observer at effective maximum HP 934.
+The reference-created friend, both backpack instances and their exact slots
+survived a real preview restart. The final bundle captured eight native 105
+requests and eight InfoPacket replies with no adapter/page errors. Owned
+characters/items were then removed with all unrelated rows unchanged and
+SQLite integrity and foreign-key checks passing.
+
+The description currently displays Level 0 and no profession despite those
+correct actor stats. The original renderer uses the effective-stat identity
+getter for these fields. Its actual lifted DDR/EER/KKR chain passes controlled
+Linux and WASM fixtures, including production optimization settings, register/
+stack/FPU preservation and real trickle math. Live shop mode, actor backpointer,
+raw getter and import targets have been checked; the live loss remains
+unresolved. Do not replace that getter with raw reads as a workaround.
+Knowledge references also disappear on browser reload; only the resulting
+Friends entry is durable. Both remaining issues are tracked in TODO.
+Runtime artifacts and diagnostic commands are in `local/reference-smoke/` and
+`local/reference-research/render.md`.
diff --git a/docs/nano-learning.md b/docs/nano-learning.md
@@ -54,8 +54,9 @@ starting values. The original twelve professions are accepted. Owner
FullCharacter publishes real Profession 60 and VisualProfession 368 explicitly;
visual profession defaults to zero in the native initializer, and no fallback
to real profession is established. The supported state has no false-profession
-effect, so both values use the saved profession. Observer profession updates
-through InfoPacket are a separate unimplemented path.
+effect, so both values use the saved profession. Requested observer updates
+now use [InfoPacket](character-info.md); the native reference description's
+effective-stat lookup discrepancy remains under investigation.
## Native upload and consumption
diff --git a/docs/team-resources.md b/docs/team-resources.md
@@ -67,6 +67,10 @@ and removal reset this basis. Skill training and equipment-derived foundation
changes use the same accounting. Ordinary hit, death, resurrection and quiet
health packets retain their established paths.
+[Player inspection](character-info.md) also folds the health bonus into the
+remote actor's raw maximum through InfoPacket. It updates the health part of
+this basis without changing the separately absorbed nano bonus.
+
The original server's resource publication frequency and remote prediction
phase were not recovered. Two seconds is the current server's existing cadence,
not an asserted historical constant. Remote actors do not necessarily hold all
diff --git a/server/character_info.go b/server/character_info.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+)
+
+func characterInfoPacket(player *character) []byte {
+ // The five byte stats are Profession, ProfessionLevel, TitleLevel, VisualSex and VisualProfession.
+ // ProfessionLevel retains the native default 1; displayed Level is a separate spawn stat.
+ profession := byte(max(1, player.profession))
+ body := []byte{0, profession, 1, byte(player.titleLevel()), byte(player.appearance >> 7 & 3), profession}
+ body = binary.BigEndian.AppendUint32(body, 0) // PetMaster; ordinary players have no owner.
+ body = binary.BigEndian.AppendUint16(body, 0) // Side XP bonus is not implemented.
+
+ // InfoPacket shares the native resource values used by team snapshots.
+ resources := teamResourceStats(player)
+ for _, value := range []uint32{player.health, player.maximumHealth(), resources[0][1], resources[1][1], resources[2][1], resources[3][1], 0, 0} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ // BreedHostility, clan and the four counted name/description strings are empty.
+ body = append(body, make([]byte, 8)...)
+ return n3Packet(0x4d38242e, 50000, player.id, body)
+}
+
+func (server *server) handleCharacterInfo(client *worldClient, body []byte) error {
+ if len(body) != 36 {
+ return fmt.Errorf("invalid character info request length")
+ }
+ if binary.BigEndian.Uint32(body) != 0x5e477770 || binary.BigEndian.Uint32(body[16:20]) != 105 ||
+ binary.BigEndian.Uint32(body[20:24]) != 50000 || binary.BigEndian.Uint64(body[28:36]) != 0 {
+ return nil
+ }
+
+ // Serialize inspection with spawn/removal and resource changes on this connection.
+ server.updateMutex.Lock()
+ defer server.updateMutex.Unlock()
+ server.mutex.Lock()
+ owner := server.characters[client.id]
+ target := server.characters[binary.BigEndian.Uint32(body[24:28])]
+ if server.clients[client.id] != client || !client.target || !client.ready || client.loading ||
+ binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id ||
+ target == nil || target.npc || target.playfield != owner.playfield || server.clients[target.id] == nil ||
+ !server.clients[target.id].ready || server.clients[target.id].loading {
+ server.mutex.Unlock()
+ return nil
+ }
+ packet := characterInfoPacket(target)
+ if target.id != client.id {
+ // Remote InfoPacket overwrites raw health maxima, absorbing existing OnWear bonuses.
+ if client.absorbedBonuses == nil {
+ client.absorbedBonuses = make(map[uint32]resourceBonuses)
+ }
+ bonuses := client.absorbedBonuses[target.id]
+ bonuses.health = target.inventory.equipmentBonus(1)
+ client.absorbedBonuses[target.id] = bonuses
+ }
+ server.mutex.Unlock()
+ return client.send(packet)
+}
diff --git a/server/character_info_test.go b/server/character_info_test.go
@@ -0,0 +1,179 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "encoding/hex"
+ "testing"
+)
+
+func TestCharacterInfoReturnsOnlyTheRequestedPlayerWithoutWrites(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ world.characters[2].health = 15
+ auditCheckpointWrites(t, world)
+
+ for range 2 {
+ if err := world.handleCharacterInfo(world.clients[1], teamRequest(1, 105, 2, 0)); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if len(connections[0].packets) != 2 || !bytes.Equal(connections[0].packets[0], connections[0].packets[1]) {
+ t.Fatal("repeated inspection did not return the same snapshot")
+ }
+ packet := connections[0].packets[0]
+ if len(packet) != 84 || binary.BigEndian.Uint32(packet[16:20]) != 0x4d38242e ||
+ binary.BigEndian.Uint32(packet[12:16]) != 1 || binary.BigEndian.Uint32(packet[20:24]) != 50000 || binary.BigEndian.Uint32(packet[24:28]) != 2 {
+ t.Fatalf("native info envelope: %x", packet)
+ }
+ if got := hex.EncodeToString(packet[29:81]); got != "0001010102010000000000000000000f00000025000000030000001d000000030000001d00000000000000000000000000000000" {
+ t.Fatalf("native info fields: %s", got)
+ }
+ for _, connection := range connections[1:] {
+ if len(connection.packets) != 0 {
+ t.Fatal("inspection reached another player")
+ }
+ }
+ if writes := checkpointWrites(t, world); len(writes) != 0 {
+ t.Fatalf("inspection wrote durable state: %v", writes)
+ }
+}
+
+func TestCharacterInfoSelfUsesProfileStatsWithoutAbsorbingModifiers(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ player := world.characters[1]
+ player.level, player.profession, player.appearance = 150, 12, 0x1a9
+ player.sitting = true
+ player.fighting = 2
+
+ err := world.handleCharacterInfo(world.clients[1], teamRequest(1, 105, 1, 0))
+
+ if err != nil || len(connections[0].packets) != 1 {
+ t.Fatalf("self inspection: %v", err)
+ }
+ packet := connections[0].packets[0]
+ if !bytes.Equal(packet[29:35], []byte{0, 12, 1, 5, 3, 12}) ||
+ binary.BigEndian.Uint32(packet[53:57]) != 59 || binary.BigEndian.Uint32(packet[61:65]) != 59 || len(world.clients[1].absorbedBonuses) != 0 {
+ t.Fatalf("self profile, fighting intervals or modifier basis: %x", packet)
+ }
+}
+
+func TestCharacterInfoRejectsUnrepresentedOrUnauthenticatedRequests(t *testing.T) {
+ for _, scenario := range []string{"missing", "npc", "other zone", "offline", "foreign owner", "sender type", "target type", "argument", "action", "key", "legacy", "not ready", "loading", "target not ready", "target loading", "replaced"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ client := world.clients[1]
+ request := teamRequest(1, 105, 2, 0)
+ switch scenario {
+ case "missing":
+ binary.BigEndian.PutUint32(request[24:28], 90)
+ case "npc":
+ world.characters[2].npc = true
+ case "other zone":
+ world.characters[2].playfield = 705
+ case "offline":
+ delete(world.clients, 2)
+ case "foreign owner":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ case "sender type":
+ binary.BigEndian.PutUint32(request[4:8], 0)
+ case "target type":
+ binary.BigEndian.PutUint32(request[20:24], 51005)
+ case "argument":
+ binary.BigEndian.PutUint32(request[28:32], 1)
+ case "action":
+ binary.BigEndian.PutUint32(request[16:20], 106)
+ case "key":
+ binary.BigEndian.PutUint32(request, 0)
+ case "legacy":
+ client.target = false
+ case "not ready":
+ client.ready = false
+ case "loading":
+ client.loading = true
+ case "target not ready":
+ world.clients[2].ready = false
+ case "target loading":
+ world.clients[2].loading = true
+ case "replaced":
+ world.clients[1] = &worldClient{id: 1, ready: true}
+ }
+
+ err := world.handleCharacterInfo(client, request)
+
+ if err != nil || len(client.absorbedBonuses) != 0 {
+ t.Fatalf("invalid inspection changed observer state: %v", err)
+ }
+ for _, connection := range connections {
+ if len(connection.packets) != 0 {
+ t.Fatal("invalid inspection sent a packet")
+ }
+ }
+ })
+ }
+}
+
+func TestCharacterInfoRejectsMalformedLengths(t *testing.T) {
+ world, connections := newTeamWorld(t)
+ request := teamRequest(1, 105, 2, 0)
+
+ for _, body := range [][]byte{nil, request[:35], append(request, 0)} {
+ if err := world.handleCharacterInfo(world.clients[1], body); err == nil {
+ t.Fatal("malformed inspection accepted")
+ }
+ }
+
+ if len(connections[0].packets) != 0 {
+ t.Fatal("malformed inspection sent a reply")
+ }
+}
+
+func TestCharacterInfoAbsorbsOnlyHealthBeforeEquipmentRemoval(t *testing.T) {
+ world, connections := newResourceBackpackTeam(t)
+ if granted, err := world.grantItem_locked(world.characters[1], 152039); err != nil || !granted {
+ t.Fatal("Pioneer grant failed", err)
+ }
+ client := world.clients[2]
+ client.absorbedBonuses = map[uint32]resourceBonuses{1: {nano: 123}}
+ for _, connection := range connections {
+ connection.packets = nil
+ }
+
+ info := world.handleCharacterInfo(client, teamRequest(2, 105, 1, 0))
+ remove := world.handleInventory(world.clients[1], itemMovePacket(1, 19, 111)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ wear := world.handleInventory(world.clients[1], inventoryMovePacket(1, 64, 19)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+
+ if info != nil || remove != nil || wear != nil || client.absorbedBonuses[1] != (resourceBonuses{health: 90, nano: 123}) {
+ t.Fatalf("info modifier basis: %v %v %v %+v", info, remove, wear, client.absorbedBonuses)
+ }
+ packet := connections[1].packets[0]
+ if binary.BigEndian.Uint32(packet[45:49]) != 139 {
+ t.Fatalf("inspection did not report the effective maximum: %x", packet)
+ }
+ var maxima []uint32
+ for _, packet := range connections[1].packets[1:] {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x2b333d6e && binary.BigEndian.Uint32(packet[29:33]) == 1 {
+ maxima = append(maxima, binary.BigEndian.Uint32(packet[33:37]))
+ }
+ }
+ if len(maxima) != 1 || maxima[0] != 142 || world.characters[1].maximumHealth() != 52 {
+ t.Fatalf("observer must apply OnRemove once after the absorbed snapshot: %v", maxima)
+ }
+}
+
+func TestCharacterInfoNativeWireDispatch(t *testing.T) {
+ world := newCheckpointWorld(t)
+ client := connectZoningClient(t, world, true)
+ request := targetPacket(characterActionPacket(1, [5]uint32{105, 50000, 1, 0, 0}))
+
+ if _, err := client.Write(request); err != nil {
+ t.Fatal(err)
+ }
+ reply, err := readPacket(client)
+
+ if err != nil || len(reply) != 81 || binary.BigEndian.Uint32(reply[16:20]) != 0x4d38242e || binary.BigEndian.Uint32(reply[24:28]) != 1 {
+ t.Fatalf("native inspection dispatch: %v %x", err, reply)
+ }
+}
diff --git a/server/main.go b/server/main.go
@@ -551,6 +551,10 @@ func (server *server) serveWorldClient(client *worldClient) error {
if err := server.handleReload(client, body); err != nil {
return err
}
+ case 105:
+ if err := server.handleCharacterInfo(client, body); err != nil {
+ return err
+ }
case 109, 110:
if err := server.handleReclaim(client, body); err != nil {
return err
diff --git a/server/state.go b/server/state.go
@@ -210,7 +210,7 @@ func (server *server) broadcast(playfield, exclude uint32, packet []byte) {
key := binary.BigEndian.Uint32(packet[20:24])
for id, client := range server.clients {
if id != exclude && client.ready && server.characters[id].playfield == playfield {
- // A new or removed actor no longer has its previous TeamMemberInfo basis.
+ // A new or removed actor no longer has its previous resource snapshot basis.
if (key == 0x271b3a6b || key == 0x36510078) && binary.BigEndian.Uint32(packet[24:28]) == 50000 {
delete(client.absorbedBonuses, binary.BigEndian.Uint32(packet[28:32]))
}
diff --git a/server/team_resources.go b/server/team_resources.go
@@ -2,7 +2,7 @@ package main
import "encoding/binary"
-// TeamMemberInfo folds these direct modifiers into each observer's raw maxima.
+// Resource snapshots fold these direct modifiers into each observer's raw maxima.
type resourceBonuses struct {
health int32
nano int32