aboutsummaryrefslogtreecommitdiff
path: root/internal/behavior/store.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-06 12:57:23 -0400
committerhistoria <[not public]>2026-10-06 12:57:23 -0400
commit9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch)
tree0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/behavior/store.go
parent4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff)
downloadthehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/behavior/store.go')
-rw-r--r--internal/behavior/store.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/internal/behavior/store.go b/internal/behavior/store.go
index d31fe84..3ea527c 100644
--- a/internal/behavior/store.go
+++ b/internal/behavior/store.go
@@ -32,13 +32,16 @@ func excludedContentPath(root, path string) bool {
func BuildPathIndex(dir string) map[string]string {
index := make(map[string]string)
filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
- if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") {
+ if err != nil || d.IsDir() {
+ return nil
+ }
+ id, ok := yamlID(d.Name())
+ if !ok {
return nil
}
if excludedContentPath(dir, path) {
return nil
}
- id := strings.TrimSuffix(d.Name(), ".yaml")
index[id] = path
return nil
})
@@ -48,13 +51,16 @@ func BuildPathIndex(dir string) map[string]string {
func BuildRoomIndex(dir string) map[int]string {
index := make(map[int]string)
filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
- if err != nil || d.IsDir() || !strings.HasSuffix(d.Name(), ".yaml") {
+ if err != nil || d.IsDir() {
+ return nil
+ }
+ id, ok := yamlID(d.Name())
+ if !ok {
return nil
}
if excludedContentPath(dir, path) {
return nil
}
- id := strings.TrimSuffix(d.Name(), ".yaml")
n, convErr := strconv.Atoi(id)
if convErr != nil {
// A non-numeric filename (for example a "1001_copy.yaml"
@@ -187,6 +193,9 @@ func LoadDropTable(dataDir, id string) (*DropTableDef, error) {
index := loadDropIndex(dataDir)
path, ok := index[id]
if !ok {
+ if id == "" || strings.Contains(id, "..") || strings.ContainsAny(id, `/\`) {
+ return nil, fmt.Errorf("invalid drop table id %q", id)
+ }
path = filepath.Join(dataDir, "drops", id+".yaml")
}
data, err := os.ReadFile(path)
@@ -268,6 +277,9 @@ func resolveDrop(dataDir string, drops []DropEntry, depth int) *DropEntry {
Quantity: qty,
Depletes: picked.Depletes,
SuccessMessage: picked.SuccessMessage,
+ Tool: picked.Tool,
+ Level: picked.Level,
+ XP: picked.XP,
}
}
return picked