예제 #1
0
        /// <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);
            }
        }
예제 #2
0
 void SaveGenderSelection(PlayerGender gender)
 {
     WriteStorageObject[] obj = new WriteStorageObject[]
     {
         new WriteStorageObject {
             Collection = "character",
             Key        = "base",
             Value      = "{\"Gender\":\"" + gender.ToString() + "\"}"
         }
     };
     StoreData(obj);
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }