/
Client.cs
531 lines (447 loc) · 25.5 KB
/
Client.cs
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
/**
* Copyright 2018 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Nakama
{
/// <inheritdoc cref="IClient"/>
public class Client : IClient
{
/// <summary>
/// The default host address of the server.
/// </summary>
public const string DefaultHost = "127.0.0.1";
/// <summary>
/// The default protocol scheme for the socket connection.
/// </summary>
public const string DefaultScheme = "http";
/// <summary>
/// The default port number of the server.
/// </summary>
public const int DefaultPort = 7350;
/// <inheritdoc cref="IClient.Host"/>
public string Host { get; }
/// <summary>
/// The logger to use with the client.
/// </summary>
public ILogger Logger
{
get => _logger;
set
{
_apiClient.HttpAdapter.Logger = value;
_logger = value;
}
}
/// <inheritdoc cref="IClient.Port"/>
public int Port { get; }
/// <inheritdoc cref="IClient.Scheme"/>
public string Scheme { get; }
/// <inheritdoc cref="IClient.ServerKey"/>
public string ServerKey { get; }
/// <inheritdoc cref="IClient.Timeout"/>
public int Timeout { get; set; }
private readonly ApiClient _apiClient;
private ILogger _logger;
public Client(string serverKey) : this(serverKey, HttpRequestAdapter.WithGzip())
{
}
public Client(string serverKey, IHttpAdapter adapter) : this(DefaultScheme, DefaultHost, DefaultPort, serverKey,
adapter)
{
}
public Client(string scheme, string host, int port, string serverKey) : this(scheme, host, port, serverKey,
HttpRequestAdapter.WithGzip())
{
}
public Client(string scheme, string host, int port, string serverKey, IHttpAdapter adapter)
{
Host = host;
Port = port;
Scheme = scheme;
ServerKey = serverKey;
Timeout = 15;
_apiClient = new ApiClient(new UriBuilder(scheme, host, port).Uri, adapter, Timeout);
Logger = NullLogger.Instance; // must set logger last.
}
/// <inheritdoc cref="AddFriendsAsync"/>
public Task AddFriendsAsync(ISession session, IEnumerable<string> ids, IEnumerable<string> usernames = null) =>
_apiClient.AddFriendsAsync(session.AuthToken, ids, usernames);
/// <inheritdoc cref="AddGroupUsersAsync"/>
public Task AddGroupUsersAsync(ISession session, string groupId, IEnumerable<string> ids) =>
_apiClient.AddGroupUsersAsync(session.AuthToken, groupId, ids);
/// <inheritdoc cref="AuthenticateCustomAsync"/>
public async Task<ISession> AuthenticateCustomAsync(string id, string username = null, bool create = true,
Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateCustomAsync(ServerKey, string.Empty,
new ApiAccountCustom {Id = id, _vars = vars}, create, username);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="AuthenticateDeviceAsync"/>
public async Task<ISession> AuthenticateDeviceAsync(string id, string username = null, bool create = true,
Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateDeviceAsync(ServerKey, string.Empty,
new ApiAccountDevice {Id = id, _vars = vars}, create, username);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="AuthenticateEmailAsync"/>
public async Task<ISession> AuthenticateEmailAsync(string email, string password, string username = null,
bool create = true, Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateEmailAsync(ServerKey, string.Empty,
new ApiAccountEmail {Email = email, Password = password, _vars = vars}, create, username);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="AuthenticateFacebookAsync"/>
public async Task<ISession> AuthenticateFacebookAsync(string token, string username = null, bool create = true,
bool import = true, Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateFacebookAsync(ServerKey, string.Empty,
new ApiAccountFacebook {Token = token, _vars = vars}, create, username, import);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="AuthenticateGameCenterAsync"/>
public async Task<ISession> AuthenticateGameCenterAsync(string bundleId, string playerId, string publicKeyUrl,
string salt, string signature, string timestamp, string username = null, bool create = true,
Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateGameCenterAsync(ServerKey, string.Empty,
new ApiAccountGameCenter
{
BundleId = bundleId,
PlayerId = playerId,
PublicKeyUrl = publicKeyUrl,
Salt = salt,
Signature = signature,
TimestampSeconds = timestamp,
_vars = vars
}, create, username);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="AuthenticateGoogleAsync"/>
public async Task<ISession> AuthenticateGoogleAsync(string token, string username = null, bool create = true,
Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateGoogleAsync(ServerKey, string.Empty,
new ApiAccountGoogle {Token = token, _vars = vars}, create, username);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="AuthenticateSteamAsync"/>
public async Task<ISession> AuthenticateSteamAsync(string token, string username = null, bool create = true,
Dictionary<string, string> vars = null)
{
var response = await _apiClient.AuthenticateSteamAsync(ServerKey, string.Empty,
new ApiAccountSteam {Token = token, _vars = vars}, create, username);
return new Session(response.Token, response.Created);
}
/// <inheritdoc cref="BlockFriendsAsync"/>
public Task BlockFriendsAsync(ISession session, IEnumerable<string> ids,
IEnumerable<string> usernames = null) => _apiClient.BlockFriendsAsync(session.AuthToken, ids, usernames);
/// <inheritdoc cref="CreateGroupAsync"/>
public Task<IApiGroup> CreateGroupAsync(ISession session, string name, string description = "",
string avatarUrl = null, string langTag = null, bool open = true, int maxCount = 100) =>
_apiClient.CreateGroupAsync(session.AuthToken, new ApiCreateGroupRequest
{
Name = name,
Description = description,
AvatarUrl = avatarUrl,
LangTag = langTag,
Open = open,
MaxCount = maxCount
});
/// <inheritdoc cref="DeleteFriendsAsync"/>
public Task DeleteFriendsAsync(ISession session, IEnumerable<string> ids,
IEnumerable<string> usernames = null) => _apiClient.DeleteFriendsAsync(session.AuthToken, ids, usernames);
/// <inheritdoc cref="DeleteGroupAsync"/>
public Task DeleteGroupAsync(ISession session, string groupId) =>
_apiClient.DeleteGroupAsync(session.AuthToken, groupId);
/// <inheritdoc cref="DeleteLeaderboardRecordAsync"/>
public Task DeleteLeaderboardRecordAsync(ISession session, string leaderboardId) =>
_apiClient.DeleteLeaderboardRecordAsync(session.AuthToken, leaderboardId);
/// <inheritdoc cref="DeleteNotificationsAsync"/>
public Task DeleteNotificationsAsync(ISession session, IEnumerable<string> ids) =>
_apiClient.DeleteNotificationsAsync(session.AuthToken, ids);
/// <inheritdoc cref="DeleteStorageObjectsAsync"/>
public Task DeleteStorageObjectsAsync(ISession session, params StorageObjectId[] ids)
{
var objects = new List<ApiDeleteStorageObjectId>(ids.Length);
foreach (var id in ids)
{
objects.Add(new ApiDeleteStorageObjectId
{
Collection = id.Collection,
Key = id.Key,
Version = id.Version
});
}
return _apiClient.DeleteStorageObjectsAsync(session.AuthToken,
new ApiDeleteStorageObjectsRequest {_objectIds = objects});
}
/// <inheritdoc cref="GetAccountAsync"/>
public Task<IApiAccount> GetAccountAsync(ISession session) => _apiClient.GetAccountAsync(session.AuthToken);
/// <inheritdoc cref="GetUsersAsync"/>
public Task<IApiUsers> GetUsersAsync(ISession session, IEnumerable<string> ids,
IEnumerable<string> usernames = null, IEnumerable<string> facebookIds = null) =>
_apiClient.GetUsersAsync(session.AuthToken, ids, usernames, facebookIds);
/// <inheritdoc cref="ImportFacebookFriendsAsync"/>
public Task ImportFacebookFriendsAsync(ISession session, string token, bool? reset = null) =>
_apiClient.ImportFacebookFriendsAsync(session.AuthToken, new ApiAccountFacebook {Token = token}, reset);
/// <inheritdoc cref="JoinGroupAsync"/>
public Task JoinGroupAsync(ISession session, string groupId) =>
_apiClient.JoinGroupAsync(session.AuthToken, groupId);
/// <inheritdoc cref="JoinTournamentAsync"/>
public Task JoinTournamentAsync(ISession session, string tournamentId) =>
_apiClient.JoinTournamentAsync(session.AuthToken, tournamentId);
/// <inheritdoc cref="KickGroupUsersAsync"/>
public Task KickGroupUsersAsync(ISession session, string groupId, IEnumerable<string> ids) =>
_apiClient.KickGroupUsersAsync(session.AuthToken, groupId, ids);
/// <inheritdoc cref="LeaveGroupAsync"/>
public Task LeaveGroupAsync(ISession session, string groupId) =>
_apiClient.LeaveGroupAsync(session.AuthToken, groupId);
/// <inheritdoc cref="LinkCustomAsync"/>
public Task LinkCustomAsync(ISession session, string id) =>
_apiClient.LinkCustomAsync(session.AuthToken, new ApiAccountCustom {Id = id});
/// <inheritdoc cref="LinkDeviceAsync"/>
public Task LinkDeviceAsync(ISession session, string id) =>
_apiClient.LinkDeviceAsync(session.AuthToken, new ApiAccountDevice {Id = id});
/// <inheritdoc cref="LinkEmailAsync"/>
public Task LinkEmailAsync(ISession session, string email, string password) =>
_apiClient.LinkEmailAsync(session.AuthToken, new ApiAccountEmail {Email = email, Password = password});
/// <inheritdoc cref="LinkFacebookAsync"/>
public Task LinkFacebookAsync(ISession session, string token, bool? import = true) =>
_apiClient.LinkFacebookAsync(session.AuthToken, new ApiAccountFacebook {Token = token}, import);
/// <inheritdoc cref="LinkGameCenterAsync"/>
public Task LinkGameCenterAsync(ISession session, string bundleId, string playerId, string publicKeyUrl,
string salt, string signature, string timestamp) => _apiClient.LinkGameCenterAsync(session.AuthToken,
new ApiAccountGameCenter
{
BundleId = bundleId,
PlayerId = playerId,
PublicKeyUrl = publicKeyUrl,
Salt = salt,
Signature = signature,
TimestampSeconds = timestamp
});
/// <inheritdoc cref="LinkGoogleAsync"/>
public Task LinkGoogleAsync(ISession session, string token) =>
_apiClient.LinkGoogleAsync(session.AuthToken, new ApiAccountGoogle {Token = token});
/// <inheritdoc cref="LinkSteamAsync"/>
public Task LinkSteamAsync(ISession session, string token) =>
_apiClient.LinkSteamAsync(session.AuthToken, new ApiAccountSteam {Token = token});
/// <inheritdoc cref="ListChannelMessagesAsync(Nakama.ISession,Nakama.IChannel,int,bool,string)"/>
public Task<IApiChannelMessageList> ListChannelMessagesAsync(ISession session, IChannel channel, int limit = 1,
bool forward = true, string cursor = null) =>
ListChannelMessagesAsync(session, channel.Id, limit, forward, cursor);
/// <inheritdoc cref="ListChannelMessagesAsync(Nakama.ISession,string,int,bool,string)"/>
public Task<IApiChannelMessageList> ListChannelMessagesAsync(ISession session, string channelId, int limit = 1,
bool forward = true, string cursor = null) =>
_apiClient.ListChannelMessagesAsync(session.AuthToken, channelId, limit, forward, cursor);
/// <inheritdoc cref="ListFriendsAsync"/>
public Task<IApiFriendList> ListFriendsAsync(ISession session, int? state, int limit, string cursor) =>
_apiClient.ListFriendsAsync(session.AuthToken, limit, state, cursor);
/// <inheritdoc cref="ListGroupUsersAsync"/>
public Task<IApiGroupUserList> ListGroupUsersAsync(ISession session, string groupId, int? state, int limit,
string cursor) =>
_apiClient.ListGroupUsersAsync(session.AuthToken, groupId, limit, state, cursor);
/// <inheritdoc cref="ListGroupsAsync"/>
public Task<IApiGroupList> ListGroupsAsync(ISession session, string name = null, int limit = 1,
string cursor = null) => _apiClient.ListGroupsAsync(session.AuthToken, name, cursor, limit);
/// <inheritdoc cref="ListLeaderboardRecordsAsync"/>
public Task<IApiLeaderboardRecordList> ListLeaderboardRecordsAsync(ISession session, string leaderboardId,
IEnumerable<string> ownerIds = null, long? expiry = null, int limit = 1, string cursor = null) =>
_apiClient.ListLeaderboardRecordsAsync(session.AuthToken, leaderboardId, ownerIds, limit, cursor,
expiry?.ToString());
/// <inheritdoc cref="ListLeaderboardRecordsAroundOwnerAsync"/>
public Task<IApiLeaderboardRecordList> ListLeaderboardRecordsAroundOwnerAsync(ISession session,
string leaderboardId, string ownerId, long? expiry = null, int limit = 1) =>
_apiClient.ListLeaderboardRecordsAroundOwnerAsync(session.AuthToken, leaderboardId, ownerId, limit,
expiry?.ToString());
/// <inheritdoc cref="ListMatchesAsync"/>
public Task<IApiMatchList> ListMatchesAsync(ISession session, int min, int max, int limit, bool authoritative,
string label, string query) =>
_apiClient.ListMatchesAsync(session.AuthToken, limit, authoritative, label, min, max, query);
/// <inheritdoc cref="ListNotificationsAsync"/>
public Task<IApiNotificationList> ListNotificationsAsync(ISession session, int limit = 1,
string cacheableCursor = null) =>
_apiClient.ListNotificationsAsync(session.AuthToken, limit, cacheableCursor);
[Obsolete("ListStorageObjects is obsolete, please use ListStorageObjectsAsync instead.", false)]
public Task<IApiStorageObjectList> ListStorageObjects(ISession session, string collection, int limit = 1,
string cursor = null) =>
_apiClient.ListStorageObjectsAsync(session.AuthToken, collection, string.Empty, limit, cursor);
/// <inheritdoc cref="ListStorageObjectsAsync"/>
public Task<IApiStorageObjectList> ListStorageObjectsAsync(ISession session, string collection, int limit = 1,
string cursor = null) =>
_apiClient.ListStorageObjectsAsync(session.AuthToken, collection, string.Empty, limit, cursor);
/// <inheritdoc cref="ListTournamentRecordsAroundOwnerAsync"/>
public Task<IApiTournamentRecordList> ListTournamentRecordsAroundOwnerAsync(ISession session,
string tournamentId, string ownerId, long? expiry = null, int limit = 1) =>
_apiClient.ListTournamentRecordsAroundOwnerAsync(session.AuthToken, tournamentId, ownerId, limit,
expiry?.ToString());
/// <inheritdoc cref="ListTournamentRecordsAsync"/>
public Task<IApiTournamentRecordList> ListTournamentRecordsAsync(ISession session, string tournamentId,
IEnumerable<string> ownerIds = null, long? expiry = null, int limit = 1, string cursor = null) =>
_apiClient.ListTournamentRecordsAsync(session.AuthToken, tournamentId, ownerIds, limit, cursor,
expiry?.ToString());
/// <inheritdoc cref="ListTournamentsAsync"/>
public Task<IApiTournamentList> ListTournamentsAsync(ISession session, int categoryStart, int categoryEnd,
int startTime, int endTime, int limit = 1, string cursor = null) =>
_apiClient.ListTournamentsAsync(session.AuthToken, categoryStart, categoryEnd, startTime, endTime, limit,
cursor);
/// <inheritdoc cref="ListUserGroupsAsync(Nakama.ISession,int?,int,string)"/>
public Task<IApiUserGroupList> ListUserGroupsAsync(ISession session, int? state, int limit, string cursor) =>
ListUserGroupsAsync(session, session.UserId, state, limit, cursor);
/// <inheritdoc cref="ListUserGroupsAsync(Nakama.ISession,string,int?,int,string)"/>
public Task<IApiUserGroupList> ListUserGroupsAsync(ISession session, string userId, int? state, int limit,
string cursor) =>
_apiClient.ListUserGroupsAsync(session.AuthToken, userId, limit, state, cursor);
/// <inheritdoc cref="ListUsersStorageObjectsAsync"/>
public Task<IApiStorageObjectList> ListUsersStorageObjectsAsync(ISession session, string collection,
string userId, int limit = 1, string cursor = null) =>
_apiClient.ListStorageObjects2Async(session.AuthToken, collection, userId, limit, cursor);
/// <inheritdoc cref="PromoteGroupUsersAsync"/>
public Task PromoteGroupUsersAsync(ISession session, string groupId, IEnumerable<string> ids) =>
_apiClient.PromoteGroupUsersAsync(session.AuthToken, groupId, ids);
/// <inheritdoc cref="ReadStorageObjectsAsync"/>
public Task<IApiStorageObjects> ReadStorageObjectsAsync(ISession session, params IApiReadStorageObjectId[] ids)
{
var objects = new List<ApiReadStorageObjectId>(ids.Length);
foreach (var id in ids)
{
objects.Add(new ApiReadStorageObjectId
{
Collection = id.Collection,
Key = id.Key,
UserId = id.UserId
});
}
return _apiClient.ReadStorageObjectsAsync(session.AuthToken,
new ApiReadStorageObjectsRequest {_objectIds = objects});
}
/// <inheritdoc cref="RpcAsync(Nakama.ISession,string,string)"/>
public Task<IApiRpc> RpcAsync(ISession session, string id, string payload) =>
_apiClient.RpcFuncAsync(session.AuthToken, id, payload);
/// <inheritdoc cref="RpcAsync(Nakama.ISession,string)"/>
public Task<IApiRpc> RpcAsync(ISession session, string id) =>
_apiClient.RpcFunc2Async(session.AuthToken, id, null, null);
/// <inheritdoc cref="RpcAsync(string,string,string)"/>
public Task<IApiRpc> RpcAsync(string httpkey, string id, string payload = null) =>
_apiClient.RpcFunc2Async(null, id, payload, httpkey);
public override string ToString()
{
return $"Client(Host='{Host}', Port={Port}, Scheme='{Scheme}', ServerKey='{ServerKey}', Timeout={Timeout})";
}
/// <inheritdoc cref="UnlinkCustomAsync"/>
public Task UnlinkCustomAsync(ISession session, string id) =>
_apiClient.UnlinkCustomAsync(session.AuthToken, new ApiAccountCustom {Id = id});
/// <inheritdoc cref="UnlinkDeviceAsync"/>
public Task UnlinkDeviceAsync(ISession session, string id) =>
_apiClient.UnlinkDeviceAsync(session.AuthToken, new ApiAccountDevice {Id = id});
/// <inheritdoc cref="UnlinkEmailAsync"/>
public Task UnlinkEmailAsync(ISession session, string email, string password) =>
_apiClient.UnlinkEmailAsync(session.AuthToken, new ApiAccountEmail {Email = email, Password = password});
/// <inheritdoc cref="UnlinkFacebookAsync"/>
public Task UnlinkFacebookAsync(ISession session, string token) =>
_apiClient.UnlinkFacebookAsync(session.AuthToken, new ApiAccountFacebook {Token = token});
/// <inheritdoc cref="UnlinkGameCenterAsync"/>
public Task UnlinkGameCenterAsync(ISession session, string bundleId, string playerId, string publicKeyUrl,
string salt, string signature, string timestamp) => _apiClient.UnlinkGameCenterAsync(
session.AuthToken,
new ApiAccountGameCenter
{
BundleId = bundleId,
PlayerId = playerId,
PublicKeyUrl = publicKeyUrl,
Salt = salt,
Signature = signature,
TimestampSeconds = timestamp
});
/// <inheritdoc cref="UnlinkGoogleAsync"/>
public Task UnlinkGoogleAsync(ISession session, string token) =>
_apiClient.UnlinkGoogleAsync(session.AuthToken, new ApiAccountGoogle {Token = token});
/// <inheritdoc cref="UnlinkSteamAsync"/>
public Task UnlinkSteamAsync(ISession session, string token) =>
_apiClient.UnlinkSteamAsync(session.AuthToken, new ApiAccountSteam {Token = token});
/// <inheritdoc cref="UpdateAccountAsync"/>
public Task UpdateAccountAsync(ISession session, string username, string displayName = null,
string avatarUrl = null, string langTag = null, string location = null, string timezone = null) =>
_apiClient.UpdateAccountAsync(
session.AuthToken, new ApiUpdateAccountRequest
{
AvatarUrl = avatarUrl,
DisplayName = displayName,
LangTag = langTag,
Location = location,
Timezone = timezone,
Username = username
});
/// <inheritdoc cref="UpdateGroupAsync"/>
public Task UpdateGroupAsync(ISession session, string groupId, string name, bool open,
string description = null,
string avatarUrl = null, string langTag = null) => _apiClient.UpdateGroupAsync(
session.AuthToken, groupId,
new ApiUpdateGroupRequest
{
Name = name,
Open = open,
AvatarUrl = avatarUrl,
Description = description,
LangTag = langTag
});
/// <inheritdoc cref="WriteLeaderboardRecordAsync"/>
public Task<IApiLeaderboardRecord> WriteLeaderboardRecordAsync(ISession session, string leaderboardId,
long score, long subScore = 0, string metadata = null) => _apiClient.WriteLeaderboardRecordAsync(
session.AuthToken, leaderboardId,
new WriteLeaderboardRecordRequestLeaderboardRecordWrite
{
Metadata = metadata,
Score = score.ToString(),
Subscore = subScore.ToString()
});
/// <inheritdoc cref="WriteStorageObjectsAsync"/>
public Task<IApiStorageObjectAcks> WriteStorageObjectsAsync(ISession session,
params IApiWriteStorageObject[] objects)
{
var writes = new List<ApiWriteStorageObject>(objects.Length);
foreach (var obj in objects)
{
writes.Add(new ApiWriteStorageObject
{
Collection = obj.Collection,
Key = obj.Key,
PermissionRead = obj.PermissionRead,
PermissionWrite = obj.PermissionWrite,
Value = obj.Value,
Version = obj.Version
});
}
return _apiClient.WriteStorageObjectsAsync(session.AuthToken,
new ApiWriteStorageObjectsRequest {_objects = writes});
}
/// <inheritdoc cref="WriteTournamentRecordAsync"/>
public Task<IApiLeaderboardRecord> WriteTournamentRecordAsync(ISession session, string tournamentId, long score,
long subScore = 0, string metadata = null) => _apiClient.WriteTournamentRecordAsync(session.AuthToken,
tournamentId,
new WriteTournamentRecordRequestTournamentRecordWrite
{
Metadata = metadata,
Score = score.ToString(),
Subscore = subScore.ToString()
});
}
}