-
Notifications
You must be signed in to change notification settings - Fork 0
/
unused_commands.go
143 lines (123 loc) · 4.09 KB
/
unused_commands.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"context"
"database/sql"
"encoding/json"
"log"
common_api "github.com/heroiclabs/nakama-common/api"
"github.com/heroiclabs/nakama-common/runtime"
)
func StorageWriteRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
log.Print(payload)
//var params map[string]interface{}
//json.Unmarshal([]byte(payload), ¶ms)
var storageWrite []*runtime.StorageWrite
if err := json.Unmarshal([]byte(payload), &storageWrite); err != nil {
log.Printf("unable to create tournament: %q", err.Error())
return "", err
}
log.Printf("%+v", string(MarshalIndent(storageWrite)))
result, err := nk.StorageWrite(ctx, storageWrite)
if err != nil {
log.Print(err)
return "", err
}
if len(result) != 1 {
log.Printf("Invocation failed. Return result not expected: ", len(result))
return "", err
}
return MarshalIndent(result), nil
}
func TournamentDeleteRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
var params map[string]interface{}
if err := json.Unmarshal([]byte(payload), ¶ms); err != nil {
return "", err
}
if err := nk.TournamentDelete(ctx, params["ID"].(string)); err != nil {
return "", err
}
return "", nil
}
func LeaderboardCreateRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
var params map[string]interface{}
if err := json.Unmarshal([]byte(payload), ¶ms); err != nil {
return "", err
}
if err := nk.LeaderboardCreate(
ctx,
params["ID"].(string),
params["Authoritative"].(bool),
params["SortOrder"].(string),
params["Operator"].(string),
params["ResetSchedule"].(string),
params["Metadata"].(map[string]interface{}),
); err != nil {
return "", err
}
return "", nil
}
func LeaderboardDeleteRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
var params map[string]interface{}
if err := json.Unmarshal([]byte(payload), ¶ms); err != nil {
return "", err
}
if err := nk.LeaderboardDelete(ctx, params["ID"].(string)); err != nil {
return "", err
}
return "", nil
}
func LeaderboardRecordWriteRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
var params map[string]interface{}
if err := json.Unmarshal([]byte(payload), ¶ms); err != nil {
return "", err
}
//score, _ := strconv.ParseInt(params["Score"].(string), 10, 64)
//subscore, _ := strconv.ParseInt(params["Subscore"].(string), 10, 64)
//int64(params["Subscore"].(float64)),
if result, err := nk.LeaderboardRecordWrite(
ctx,
params["ID"].(string),
params["OwnerID"].(string),
params["Username"].(string),
int64(params["Score"].(float64)),
int64(params["Subscore"].(float64)),
map[string]interface{}{},
); err != nil {
return "", err
} else {
return MarshalIndent(result), err
}
}
func LeaderboardRecordDelete(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
var params map[string]interface{}
if err := json.Unmarshal([]byte(payload), ¶ms); err != nil {
return "", err
}
if err := nk.LeaderboardRecordDelete(
ctx,
params["ID"].(string),
params["OwnerID"].(string),
); err != nil {
return "", err
} else {
return "", nil
}
}
func LeaderboardRecordList(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (*common_api.LeaderboardRecordList, error) {
var params map[string]interface{}
if err := json.Unmarshal([]byte(payload), ¶ms); err != nil {
return nil, err
}
if records, ownerRecords, nextCursorStr, prevCursorStr, err := nk.LeaderboardRecordsList(
ctx,
params["ID"].(string),
params["OwnerIDs"].([]string),
params["Limit"].(int),
params["Cursor"].(string),
params["Expiry"].(int64),
); err != nil {
return nil, err
} else {
return &common_api.LeaderboardRecordList{Records: records, OwnerRecords: ownerRecords, NextCursor: nextCursorStr, PrevCursor: prevCursorStr}, nil
}
}