Skip to content

Commit

Permalink
Set default log level to debug, fix getStead
Browse files Browse the repository at this point in the history
Previously, gameticks were filling up the log unnecessarily. These were
moved to trace, and the default log level was set at debug.

TODO: Make log level configurable by /etc/hkgi/config
Signed-Off-By: Cara Salter <cara@devcara.com>
  • Loading branch information
Muirrum committed Mar 14, 2024
1 parent 0392a35 commit b71f2a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -219,7 +219,7 @@ func RunTick() error {

}
state.GlobalState.ActivityPrune()
log.Info("Done")
log.Trace("Done")

time.Sleep(500 * time.Millisecond)
}
Expand Down
15 changes: 10 additions & 5 deletions internal/handlers/hkgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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!",
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions internal/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ 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"
)

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)
Expand Down

0 comments on commit b71f2a8

Please sign in to comment.