From 8ef9bee184c9c480ed033d5e743f8d75558c3e9a Mon Sep 17 00:00:00 2001 From: Calm0 Date: Mon, 21 Sep 2026 11:33:14 +0100 Subject: [PATCH 1/2] Thread a database handle through Init --- CHANGELOG.md | 4 ++++ base.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28e4b2f..6282bdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr :warning: This server code is versioned separately to the download of the [Hiro game framework](https://heroiclabs.com/hiro/). :warning: +## [Unreleased] +### Changed +- The "Init" function takes a database handle, which is passed through to the gameplay systems. Callers must pass the "db" given to "InitModule". + ## [1.35.0] - 2026-07-29 ### Added - Streaks have new options "grace_window_sec" and "auto_claim" for configuration. diff --git a/base.go b/base.go index d5bc15a..12b3ebb 100644 --- a/base.go +++ b/base.go @@ -159,7 +159,7 @@ const ( ) // Init initializes a Hiro type with the configurations provided. -func Init(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, initializer runtime.Initializer, binPath string, licenseKey string, configs ...SystemConfig) (Hiro, error) { +func Init(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer, binPath string, licenseKey string, configs ...SystemConfig) (Hiro, error) { // Open the plugin. binFile, err := nk.ReadFile(binPath) if err != nil { @@ -180,7 +180,7 @@ func Init(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, i } // Ensure the function has the correct types. - fn, ok := f.(func(context.Context, runtime.Logger, runtime.NakamaModule, runtime.Initializer, *protojson.MarshalOptions, *protojson.UnmarshalOptions, string, ...SystemConfig) (Hiro, error)) + fn, ok := f.(func(context.Context, runtime.Logger, *sql.DB, runtime.NakamaModule, runtime.Initializer, *protojson.MarshalOptions, *protojson.UnmarshalOptions, string, ...SystemConfig) (Hiro, error)) if !ok { return nil, errors.New("error reading hiro-gdk.Init function in Go module") } @@ -192,7 +192,7 @@ func Init(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, i } unmarshaler := &protojson.UnmarshalOptions{DiscardUnknown: false} - return fn(ctx, logger, nk, initializer, marshaler, unmarshaler, licenseKey, configs...) + return fn(ctx, logger, db, nk, initializer, marshaler, unmarshaler, licenseKey, configs...) } // The SystemConfig describes the configuration that each gameplay system must use to configure itself. From 8621088ff83ea9a1265db9b5e7b9bbe46f111914 Mon Sep 17 00:00:00 2001 From: Calm0 Date: Mon, 21 Sep 2026 13:06:32 +0100 Subject: [PATCH 2/2] Update readme to include the db --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9abe5aa..8d983ae 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ import ( ) func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error { - systems, err := hiro.Init(ctx, logger, nk, initializer, "hiro.bin", "LicenseKey", + systems, err := hiro.Init(ctx, logger, db, nk, initializer, "hiro.bin", "LicenseKey", hiro.WithEconomySystem("economy.json", true), hiro.WithEnergySystem("energy.json", true), hiro.WithInventorySystem("inventory.json", true))