/// <summary> /// Stores given <paramref name="data"/> under specified <paramref name="key"/> in Nakama storage system. /// </summary> public virtual async Task <bool> StoreDataAsync(string key, string data) { Client client = NakamaSessionManager.Instance.Client; ISession session = NakamaSessionManager.Instance.Session; WriteStorageObject storageObject = new WriteStorageObject(); storageObject.Collection = StorageCollection; storageObject.Key = key; storageObject.Value = data; storageObject.PermissionRead = (int)ReadPermission; storageObject.PermissionWrite = (int)WritePermission; try { // Method Client.WriteStorageObjectsAsync allows us to send multiple WriteStorageObjects at once, but in this // demo we only ever need to send one at the time IApiStorageObjectAcks sentObjects = await client.WriteStorageObjectsAsync(session, storageObject); Debug.Log("Successfully send " + typeof(T).Name + " data: " + (sentObjects.Acks.Count() == 1 ? "true" : "false")); return(true); } catch (Exception e) { Debug.LogWarning("An exception has occured while sending user data: " + e); return(false); } }
void SaveGenderSelection(PlayerGender gender) { WriteStorageObject[] obj = new WriteStorageObject[] { new WriteStorageObject { Collection = "character", Key = "base", Value = "{\"Gender\":\"" + gender.ToString() + "\"}" } }; StoreData(obj); }
public async Task ShouldNotWriteStorageObjectsNotFirstVersion() { var session = await _client.AuthenticateCustomAsync($"{Guid.NewGuid()}"); var aobject = new WriteStorageObject { Collection = $"{Guid.NewGuid()}", Key = "key", Value = "{}", Version = "*" }; await _client.WriteStorageObjectsAsync(session, aobject); var ex = Assert.ThrowsAsync <HttpRequestException>(() => _client.WriteStorageObjectsAsync(session, aobject)); Assert.AreEqual("400 (Bad Request)", ex.Message); }
public async Task ShouldNotWriteStorageObjectsNotFirstVersion() { var session = await _client.AuthenticateCustomAsync($"{Guid.NewGuid()}"); var aobject = new WriteStorageObject { Collection = $"{Guid.NewGuid()}", Key = "key", Value = "{}", Version = "*" }; await _client.WriteStorageObjectsAsync(session, aobject); var ex = Assert.ThrowsAsync <ApiResponseException>(() => _client.WriteStorageObjectsAsync(session, aobject)); Assert.NotNull(ex); Assert.AreEqual(HttpStatusCode.BadRequest, ex.StatusCode); }
public async Task ShouldNotWriteStorageObjectsBadVersion() { var session = await _client.AuthenticateCustomAsync($"{Guid.NewGuid()}"); var aobject = new WriteStorageObject { Collection = $"{Guid.NewGuid()}", Key = "key", Value = "{}" }; var result = await _client.WriteStorageObjectsAsync(session, aobject); Assert.NotNull(result); Assert.IsNotEmpty(result.Acks); aobject.Version = "*"; aobject.Value = "{\"some\":\"newvalue\"}"; var ex = Assert.ThrowsAsync <HttpRequestException>(() => _client.WriteStorageObjectsAsync(session, aobject)); Assert.AreEqual("400 (Bad Request)", ex.Message); }