Need an instance of *sql.DB and runtime.NakamaModule in the RegisterEventSessionEnd

When a client disconnects from the server (for example when the client app is closed), there are some db and storage actions that I need to do for that specific client. In order to do that, I need the nakama server to pass down an instance of *sql.DB and runtime.NakamaModule to the function that I have registered to RegisterEventSessionEnd.

If that is not possible, then can I cache the *sql.DB and runtime.NakamaModule that was passed to the latest rpc call and use them for my purpose?

Here is how I am currently testing the RegisterEventSessionEnd, but I cannot find an instance of *sql.DB and runtime.NakamaModule, neither in ctx, nor in evt

  1. Versions: Nakama {“version”:“3.12.0+f5e935d6”}, {Docker}
  2. Server Framework Runtime language (If relevant) {Go}
if err := initializer.RegisterEventSessionEnd(func(ctx context.Context, logger runtime.Logger, evt *api.Event) {
		fmt.Println("============================= RegisterEventSessionEnd ==================================")
		userId := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)
		sessionId := ctx.Value(runtime.RUNTIME_CTX_SESSION_ID).(string)
		fmt.Printf("connection closed for userId '%s' and sessionId '%s'\n", userId, sessionId)
		fmt.Println("***************************** RegisterEventSessionEnd **********************************")
	}); err != nil {
		return err

Hi @s-alavi, welcome to the forum.

You can find an example that should suit your needs here:RegisterEventSessionEnd with full functionality - #2 by novabyte

Please be aware, as Chris mentions in the post, that the API is specifically designed in this way to prevent misuse and writing code that is not subject to rate limiting which could negatively impact the performance of your Nakama server, so please use with caution.

@tom Thank you for the quick response

1 Like