diff --git a/internal/game/game.go b/internal/game/game.go index 4f164f0..d111a5f 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -147,7 +147,7 @@ func RunTick() error { db := database.DB for { - log.Info("Running game tick...") + log.Trace("Running game tick...") var users []models.Stead err := db.Select(&users, "SELECT * FROM stead") if err != nil { @@ -219,7 +219,7 @@ func RunTick() error { } state.GlobalState.ActivityPrune() - log.Info("Done") + log.Trace("Done") time.Sleep(500 * time.Millisecond) } diff --git a/internal/handlers/hkgi.go b/internal/handlers/hkgi.go index d0194c7..abed83c 100644 --- a/internal/handlers/hkgi.go +++ b/internal/handlers/hkgi.go @@ -10,6 +10,7 @@ import ( "time" "github.com/gofiber/fiber/v2" + fiberLog "github.com/gofiber/fiber/v2/log" "github.com/hackagotchi/hkgi/database" "github.com/hackagotchi/hkgi/internal/game" "github.com/hackagotchi/hkgi/internal/models" @@ -45,7 +46,9 @@ func GetStead(c *fiber.Ctx) error { var inventory json.RawMessage var ephemeral_statuses []uint8 - err := db.QueryRowx("SELECT inventory, (CASE WHEN ephemeral_statuses IS NULL THEN '{\"\"}' ELSE ephemeral_statuses END) as ephemeral_statuses FROM stead WHERE username=$1", user).Scan(&inventory, &ephemeral_statuses) + fiberLog.Debug("Fetching stead") + + err := db.QueryRowx("SELECT inventory, (CASE WHEN ephemeral_statuses IS NULL THEN '{}' ELSE ephemeral_statuses END) as ephemeral_statuses FROM stead WHERE username=$1", user).Scan(&inventory, &ephemeral_statuses) if err != nil { return err @@ -149,7 +152,7 @@ func UseItem(c *fiber.Ctx) error { } var item models.UseItem - if err := c.BodyParser(item); err != nil { + if err := c.BodyParser(&item); err != nil { return err } if errs := val.Validate(item); len(errs) > 0 && errs[0].Error { @@ -171,15 +174,17 @@ func UseItem(c *fiber.Ctx) error { } manifest := state.GlobalState.Manifest + items := manifest["items"].(map[string]interface{}) - if manifest[item.Item] == nil { + if items[item.Item] == nil { return &fiber.Error{ Code: fiber.ErrBadRequest.Code, Message: "no such item found", } } - if !manifest[item.Item].(map[string]interface{})["usable"].(bool) { + usable, ok := items[item.Item].(map[string]interface{})["usable"] + if !ok || !usable.(bool) { return &fiber.Error{ Code: fiber.ErrBadRequest.Code, Message: "that's not an item you can use!", @@ -252,7 +257,7 @@ func Craft(c *fiber.Ctx) error { } var cReq models.Craft - if err := c.BodyParser(cReq); err != nil { + if err := c.BodyParser(&cReq); err != nil { return err } diff --git a/internal/router.go b/internal/router.go index dda4155..c39418c 100644 --- a/internal/router.go +++ b/internal/router.go @@ -2,6 +2,7 @@ package internal import ( "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/log" "github.com/gofiber/fiber/v2/middleware/logger" "github.com/hackagotchi/hkgi/internal/handlers" "github.com/hackagotchi/hkgi/internal/routers" @@ -9,6 +10,7 @@ import ( func SetupRoutes(app *fiber.App) { app.Use(logger.New()) + log.SetLevel(log.LevelDebug) app.Post("/signup", handlers.Signup) hkgi := app.Group("/hkgi", logger.New()) routers.SetupHkgiRoutes(hkgi)