Created
May 31, 2021 04:35
-
-
Save arxdsilva/61912baafb63b37fe110d8823274b0b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"database/sql" | |
"encoding/json" | |
"github.com/heroiclabs/nakama-common/runtime" | |
) | |
// InitModule registers the RPC function into the game server | |
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error { | |
if err := initializer.RegisterRpc("my_unique_id", RPCExample); err != nil { | |
return err | |
} | |
return nil | |
} | |
// RPCExample tries to wrap the received content into a map and create | |
// a new Leaderboard with this content as metadata | |
func RPCExample(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) { | |
meta := make(map[string]interface{}) | |
if err := json.Unmarshal([]byte(payload), &meta); err != nil { | |
return "", err | |
} | |
id := "SomeId" | |
authoritative := false | |
sort := "desc" | |
operator := "best" | |
reset := "0 0 * * 1" | |
if err := nk.LeaderboardCreate(ctx, id, authoritative, sort, operator, reset, meta); err != nil { | |
return "", err | |
} | |
return "Success", nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment