Unregister RPCs #

There are many reasons why you may want to limit or completely prevent client access to any or all of the Hiro APIs, such as performing validation on a client request or preventing client attempts at circumventing your game logic.

An easy way to do this is to unregister RPCs that you don’t want clients to be able to call directly. You can always make your own custom RPC that implements your own logic before calling the Hiro function from the server-side.

You can find the collection of RPCs that have been registered by Hiro in your Nakama Console -> Runtime Modules -> Registered RPC Functions.

Server Example #

Make sure to first register the Hiro systems that you will be using in your game. Then you can call hiro.UnregisterRpc, passing in the initializer followed by as many IDs as you need by using the hiro.RpcId_RPC_ID consts.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
systems, err := hiro.Init(ctx, logger, nk, initializer, binPath, hiroLicense,
	hiro.WithBaseSystem(fmt.Sprintf("base-system-%s.json", env), true),
	hiro.WithEconomySystem(fmt.Sprintf("base-economy-%s.json", env), true),
	hiro.WithInventorySystem(fmt.Sprintf("base-inventory-%s.json", env), true))
if err != nil {
	return err
}

// Keep chaining RPC IDs as much as you need
if err = hiro.UnregisterRpc(initializer,
	// Inventory
	hiro.RpcId_RPC_ID_INVENTORY_GRANT,
	hiro.RpcId_RPC_ID_INVENTORY_UPDATE,
	// Economy
	hiro.RpcId_RPC_ID_ECONOMY_GRANT,
); err != nil {
	return err
}

Custom logic #

In your own RPCs, you can still directly call the Hiro functions after implementing your custom logic. This example shows how we can still directly use ECONOMY_GRANT on the server-side after unregistering it for clients in the previous example.

1
2
3
4
5
6
7
8
9
func rpcCustomLogic(systems hiro.Hiro) func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
	return func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
		// Custom validation logic

		systems.GetEconomySystem().Grant( /*Params*/ )

		return "{}", nil
	}
}

Debug RPCs #

Some Hiro systems have RPCs that are designed for debugging use only, such as in Event Leaderboards.

To unregister all Debug RPCs, call hiro.UnregisterDebugRpc after you have registered the Hiro systems that you will be using in your game.

1
2
3
if err = hiro.UnregisterDebugRpc(initializer); err != nil {
	return err
}