diff options
Diffstat (limited to 'internal/player')
| -rw-r--r-- | internal/player/player.go | 2 | ||||
| -rw-r--r-- | internal/player/roomset.go | 2 | ||||
| -rw-r--r-- | internal/player/roomset_test.go | 11 | ||||
| -rw-r--r-- | internal/player/store.go | 2 | ||||
| -rw-r--r-- | internal/player/store_test.go | 28 | ||||
| -rw-r--r-- | internal/player/validate.go | 3 |
6 files changed, 46 insertions, 2 deletions
diff --git a/internal/player/player.go b/internal/player/player.go index 92b017a..f7dd7bd 100644 --- a/internal/player/player.go +++ b/internal/player/player.go @@ -211,7 +211,7 @@ type Player struct { BackgroundAction *behavior.Action `yaml:"-"` WalkSequence []string `yaml:"-"` ConsumeCooldown int `yaml:"-"` - HomeTransportCooldown int `yaml:"-"` + HomeTransportCooldown int `yaml:"home_transport_cooldown,omitempty"` MoveTicks int `yaml:"-"` MoveDirection string `yaml:"-"` MoveTarget int `yaml:"-"` diff --git a/internal/player/roomset.go b/internal/player/roomset.go index d7e1b47..2a327d1 100644 --- a/internal/player/roomset.go +++ b/internal/player/roomset.go @@ -46,7 +46,7 @@ func (rs *RoomSet) ensure() { } func (rs *RoomSet) Add(roomID int) { - if roomID < 0 { + if roomID < 0 || roomID > roomSetMaxID { return } rs.ensure() diff --git a/internal/player/roomset_test.go b/internal/player/roomset_test.go index 38bd993..94b1714 100644 --- a/internal/player/roomset_test.go +++ b/internal/player/roomset_test.go @@ -143,3 +143,14 @@ func TestRoomSetRejectsOutOfRangeDelta(t *testing.T) { t.Fatal("expected error for out-of-range delta") } } + +func TestRoomSetAddRejectsOutOfRange(t *testing.T) { + rs := NewRoomSetFrom(roomSetMaxID) + if !rs.Has(roomSetMaxID) { + t.Fatal("roomSetMaxID itself should be accepted") + } + rs.Add(roomSetMaxID + 1) + if rs.Has(roomSetMaxID + 1) { + t.Fatal("out-of-range room ID was accepted") + } +} diff --git a/internal/player/store.go b/internal/player/store.go index 5d69ec3..a0e2849 100644 --- a/internal/player/store.go +++ b/internal/player/store.go @@ -33,6 +33,7 @@ func (s *AccountStore) LoadAccount(name string) (*Account, error) { if err := yaml.Unmarshal(data, &acc); err != nil { return nil, fmt.Errorf("parse account: %w", err) } + acc.Name = name return &acc, nil } @@ -124,6 +125,7 @@ func (s *AccountStore) LoadCharacter(name string) (*Player, error) { if err := yaml.Unmarshal(data, &p); err != nil { return nil, fmt.Errorf("parse character: %w", err) } + p.Name = name if p.Skills == nil { p.Skills = make(map[SkillName]int) } diff --git a/internal/player/store_test.go b/internal/player/store_test.go index 593e9d1..2987d09 100644 --- a/internal/player/store_test.go +++ b/internal/player/store_test.go @@ -79,3 +79,31 @@ func TestAccountStoreIgnoresNonYAMLFiles(t *testing.T) { } } } + +func TestLoadCharacterReconcilesNameToStem(t *testing.T) { + s := testAccountStore(t) + if err := os.WriteFile(s.CharPath("alice"), []byte("name: WRONG\nroom_id: 1\n"), 0600); err != nil { + t.Fatal(err) + } + p, err := s.LoadCharacter("alice") + if err != nil { + t.Fatal(err) + } + if p.Name != "alice" { + t.Fatalf("LoadCharacter reconciled name to %q, want %q", p.Name, "alice") + } +} + +func TestLoadAccountReconcilesNameToStem(t *testing.T) { + s := testAccountStore(t) + if err := os.WriteFile(s.AccountPath("alice"), []byte("name: WRONG\n"), 0600); err != nil { + t.Fatal(err) + } + acc, err := s.LoadAccount("alice") + if err != nil { + t.Fatal(err) + } + if acc.Name != "alice" { + t.Fatalf("LoadAccount reconciled name to %q, want %q", acc.Name, "alice") + } +} diff --git a/internal/player/validate.go b/internal/player/validate.go index 015b3d8..3a06985 100644 --- a/internal/player/validate.go +++ b/internal/player/validate.go @@ -16,6 +16,9 @@ func ValidName(name string) error { } func ValidPassword(pw string) error { + if len(pw) < 8 { + return fmt.Errorf("password must be at least 8 characters") + } if len(pw) > 128 { return fmt.Errorf("password too long") } |
