Skip to content

Commit

Permalink
Repair segfaults in craft
Browse files Browse the repository at this point in the history
Issues were with not correctly casting the final reference to the recipe
(needed to be cast to map[string]interface{} but wasn't, so was instead
interface{}, a non-indexable type).

There's currently an issue with TakeItem where it's not fetching the
inventory correctly from the database. That needs further investigation.
I suspect it's something to do with db.Get not correctly interpreting
the JSON data.

Also, the issue with `recipe_index` not passing the Required check was
due to the validator interpreting indicies of "1" as invalid. More
investigation required.

TODO: Debug Required check on recipe_index
TODO: Investigate TakeItem issues as noted above
Issue: #1
Signed-Off-By: Cara Salter <[email protected]>
  • Loading branch information
Muirrum committed Mar 14, 2024
1 parent b71f2a8 commit 2e2d32a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ func NewPlant(username string, plant_kind string) error {
tx.Commit()
return nil
}

func GiveItem(username string, items map[string]interface{}) error {
db := database.DB

var stead map[string]interface{}
err := db.Get(&stead, "SELECT inventory FROM Stead WHERE username=$1", username)
if err != nil {
Expand Down Expand Up @@ -72,6 +70,8 @@ func TakeItem(username string, items map[string]interface{}) error {

var stead map[string]interface{}
err := db.Get(&stead, "SELECT inventory FROM Stead WHERE username=$1", username)
log.Debug(stead)

if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/handlers/hkgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ func Craft(c *fiber.Ctx) error {
u := c.Locals("username").(string)

var p models.Plant
err := db.Get(&p, "SELECT * FROM plant WHERE stead_owner=(SELECT id FROM stead WHERE username=$1) AND id=$2", u, cReq.PlantId)
err := db.Get(&p, "SELECT id,kind,xp,xp_multiplier,next_yield FROM plant WHERE stead_owner=(SELECT id FROM stead WHERE username=$1) AND id=$2", u, cReq.PlantId)
if err != nil {
return err
}

recipe := manifest["plant_recipes"].(map[string]interface{})[p.Kind].([]map[string]interface{})[cReq.RecipeIndex]
recipe := manifest["plant_recipes"].(map[string]interface{})[p.Kind].([]interface{})[cReq.RecipeIndex].(map[string]interface{})

if !(game.LvlFromXp(p.Xp) == recipe["xp"].(int)) {
if !(float64(game.LvlFromXp(p.Xp)) == recipe["lvl"].(float64)) {
return &fiber.Error{
Code: fiber.ErrBadRequest.Code,
Message: "come back when you're older, plant!",
Expand Down

0 comments on commit 2e2d32a

Please sign in to comment.