Add domain clone helpers for user patches#569
Closed
CaseyLabs wants to merge 1 commit intofix/mapper-js-lintfrom
Closed
Add domain clone helpers for user patches#569CaseyLabs wants to merge 1 commit intofix/mapper-js-lintfrom
CaseyLabs wants to merge 1 commit intofix/mapper-js-lintfrom
Conversation
3bc018c to
4045ace
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why This PR Exists
This PR adds safe copy helpers for user-owned game data.
In Go, a plain struct copy is only partly independent.
int,bool, andstringcopy cleanly.That matters for
UserRecordandCharacter.Maintainability Approach
This PR keeps clone rules close to the types that own the data.
Character.Clone()still coordinates the full character copy.Clone()methods.This does not try to use reflection or serialization for cloning.
The pattern is now easier to extend.
ShopItemlater gains a mutable field, updateShopItem.Clone().ItemSpeclater gains a mutable field, updateItemSpec.Clone().PetAbilitylater gains a mutable field, updatePetAbility.Clone().Clone()method.What Changed
Added top-level user and character clone helpers.
UserRecord.Clone()copies user account state and nested character state.Character.Clone()copies player identity, gameplay state, runtime maps, inventory, equipment, pet data, buffs, shops, room visits, and combat tracking.Added clone helpers for character-owned support types.
Shop.Clone()andShopItem.Clone()handle merchant stock data.Cooldowns.Clone()handles cooldown maps.KDStats.Clone()handles kill/death maps.MobMasteries.Clone()handles mastery maps.RoomBitset.Clone()handles visited-room bitsets.Added clone helpers for item-owned state.
Item.Clone()copies item instance data.ItemSpec.Clone()copies item override specs.Damage.Clone()copies crit buff ids.Added clone helpers for pet-owned state.
Pet.Clone()copies pet inventory and abilities.PetAbility.Clone()copies ability damage, stat mods, and buff ids.Added clone helpers for user logs.
UserLog.Clone()copies the event log slice.Go Concepts Used
maps.Clone(...)copies a map.slices.Clone(...)copies a slice.Pointer fields need explicit handling.
Cached pointers are intentionally reset.
Tests Added
Added focused clone independence tests.
internal/users/clone_test.gointernal/characters/clone_test.gointernal/items/clone_test.gointernal/pets/clone_test.goThe tests mutate cloned data and check that the original data stays unchanged.
Why This Is Its Own PR
The next PR uses these helpers for admin API hardening.
The changes are mechanical but security-relevant.
Stack
Fix mapper JavaScript lint errors #568 comes first.
This PR comes second.
security: harden admin user mutation endpoints #567 comes third.
Validation
go test ./internal/users ./internal/characters ./internal/items ./internal/pets ./internal/buffsgo test ./internal/web ./internal/users ./internal/characters ./internal/items ./internal/pets ./internal/buffs