1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| func AuthoritativeWriteRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
userID, _ := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)
data := map[string]interface{}{
"achievementPoints": 100,
"unlockedAchievements": []string{"max-level", "defeat-boss-2", "equip-rare-gear"},
}
bytes, err := json.Marshal(data)
if err != nil {
return "", runtime.NewError("error marshaling data", 13)
}
write := &runtime.StorageWrite{
Collection: "Unlocks",
Key: "Achievements",
UserID: userID,
Value: string(bytes),
PermissionRead: 1, // Only the server and owner can read
PermissionWrite: 0, // Only the server can write
}
_, err = nk.StorageWrite(ctx, []*runtime.StorageWrite{write})
if err != nil {
return "", runtime.NewError("error saving data", 13)
}
return "<JsonResponse>", nil
}
|