aboutsummaryrefslogtreecommitdiff
path: root/internal/player
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 04:46:27 -0400
committerhistoria <[not public]>2026-06-11 08:58:37 +0000
commit1b9e2da3b3c438d8dc53d3489725dd5ba0022777 (patch)
tree62264f24420bf4cfaa734942c65cc8dd45ba3d3b /internal/player
parent06c02a697e5daf8832a462de5970dd4c0e13a02c (diff)
downloadthehouseoficarus-1b9e2da3b3c438d8dc53d3489725dd5ba0022777.tar.gz
feat: web client, get/drop updates and fixes
Diffstat (limited to 'internal/player')
-rw-r--r--internal/player/player.go14
-rw-r--r--internal/player/validate.go37
2 files changed, 40 insertions, 11 deletions
diff --git a/internal/player/player.go b/internal/player/player.go
index fee6578..cccf979 100644
--- a/internal/player/player.go
+++ b/internal/player/player.go
@@ -16,6 +16,7 @@ const (
Fishing SkillName = "fishing"
Cooking SkillName = "cooking"
Woodcutting SkillName = "woodcutting"
+ Firemaking SkillName = "firemaking"
Mining SkillName = "mining"
Smithing SkillName = "smithing"
Crafting SkillName = "crafting"
@@ -32,7 +33,7 @@ const (
var AllSkills = []SkillName{
Attack, Strength, Defense, Hitpoints, Ranged, Science, Technology,
- Fishing, Cooking, Woodcutting, Mining, Smithing, Crafting, Fletching,
+ Fishing, Cooking, Woodcutting, Firemaking, Mining, Smithing, Crafting, Fletching,
Alchemy, Thieving, Agility, Construction, Scavenging, Hacking, Assassin, Farming,
}
@@ -47,6 +48,7 @@ var SkillAbbr = map[SkillName]string{
Fishing: "fis",
Cooking: "cok",
Woodcutting: "wct",
+ Firemaking: "fmk",
Mining: "min",
Smithing: "smt",
Crafting: "cft",
@@ -89,7 +91,6 @@ type Player struct {
Skills map[SkillName]int `yaml:"skills"`
Inventory map[int]*InventorySlot `yaml:"inventory"`
Equipment map[object.EquipSlot]string `yaml:"equipment"`
- Toolbelt []string `yaml:"toolbelt"`
RoomID int `yaml:"room_id"`
HP int `yaml:"hp"`
Credits int `yaml:"credits"`
@@ -195,15 +196,6 @@ func (p *Player) StartRegen() {
}
}
-func (p *Player) HasToolbeltItem(itemID string) bool {
- for _, id := range p.Toolbelt {
- if id == itemID {
- return true
- }
- }
- return false
-}
-
func (p *Player) HasItem(itemID string) bool {
for _, slot := range p.Inventory {
if slot != nil && slot.ItemID == itemID && slot.Quantity > 0 {
diff --git a/internal/player/validate.go b/internal/player/validate.go
new file mode 100644
index 0000000..63f40d2
--- /dev/null
+++ b/internal/player/validate.go
@@ -0,0 +1,37 @@
+package player
+
+import (
+ "fmt"
+ "regexp"
+ "unicode"
+)
+
+var validNameRE = regexp.MustCompile(`^[A-Za-z0-9 ]{1,30}$`)
+
+func ValidName(name string) error {
+ if !validNameRE.MatchString(name) {
+ return fmt.Errorf("name must be 1-30 alphanumeric characters or spaces")
+ }
+ return nil
+}
+
+func ValidPassword(pw string) error {
+ if len(pw) > 128 {
+ return fmt.Errorf("Password too long.")
+ }
+ return nil
+}
+
+func StripControl(input string) string {
+ runes := make([]rune, 0, len(input))
+ for _, r := range input {
+ if r == '\n' || r == '\t' {
+ continue
+ }
+ if unicode.IsControl(r) {
+ continue
+ }
+ runes = append(runes, r)
+ }
+ return string(runes)
+}