사용자 메타데이터 업데이트 #

다음 예시에서는 RPC를 사용하여 플레이어의 메타데이터를 정식으로 업데이트하는 방법을 보여줍니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
initializer.RegisterRpc("UpdateMetadata", func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
    userId, ok := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)
    if !ok {
        return "", errors.New("could not get user ID from context")
    }

    if err := nk.AccountUpdateId(ctx, userId, "", map[string]interface{}{
        "title": "Definitely Not The Imposter",
        "hat":  "space_helmet"
        "skin": "alien"},
    }, "", "", "", "", ""); err != nil {
        return "", errors.New("could not update account")
    }

    return "{}", nil
})