Exemple #1
0
        public async Task ShouldDeleteStorageObjects()
        {
            var session = await _client.AuthenticateCustomAsync($"{Guid.NewGuid()}");

            var          collection = $"{Guid.NewGuid()}";
            const string key        = "a";
            await _client.WriteStorageObjectsAsync(session, new WriteStorageObject
            {
                Collection = collection,
                Key        = key,
                Value      = "{}"
            });

            var objectId = new StorageObjectId
            {
                Collection = collection,
                Key        = key,
                UserId     = session.UserId
            };
            await _client.DeleteStorageObjectsAsync(session, objectId);

            var result = await _client.ReadStorageObjectsAsync(session, objectId);

            Assert.NotNull(result);
            Assert.IsEmpty(result.Objects);
        }
Exemple #2
0
        /// <summary>
        /// Sends request to read data from the server and returns json.
        /// </summary>
        public virtual async Task <string> LoadDataJsonAsync(string userId, string key)
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            StorageObjectId storageObject = new StorageObjectId();

            storageObject.Collection = StorageCollection;
            storageObject.Key        = key;
            storageObject.UserId     = userId;

            try
            {
                IApiStorageObjects receivedObjects = await client.ReadStorageObjectsAsync(session, storageObject);

                // Method Client.ReadStorageObjectsAsync returns an enumerable of json strings, and because we
                // passed only a single StorageObjectId, we expect to receive only one string
                if (receivedObjects.Objects.Count() > 0)
                {
                    string json = receivedObjects.Objects.ElementAt(0).Value;
                    return(json);
                }
                else
                {
                    Debug.Log("No " + typeof(T).Name + " data in " + StorageCollection + "." + key + " found for this user");
                    return(null);
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("An exception has occured while receiving user data: " + e);
                return(null);
            }
        }
        /// <summary>
        /// Sets fields of this panel to show <see cref="PlayerData"/> gathered from <paramref name="user"/>.
        /// </summary>
        /// <param name="user">User to be displayed in this panel.</param>
        private async void PopulateDataAsync(IApiUser user)
        {
            StorageObjectId personalStorageId = new StorageObjectId();

            personalStorageId.Collection = "personal";
            personalStorageId.UserId     = _connection.Session.UserId;
            personalStorageId.Key        = "player_data";

            IApiStorageObjects personalStorageObjects = await _connection.Client.ReadStorageObjectsAsync(_connection.Session, personalStorageId);

            PlayerData playerData        = new PlayerData();
            IUserGroupListUserGroup clan = null;

            try
            {
                IApiUserGroupList clanList = await _connection.Client.ListUserGroupsAsync(_connection.Session);

                // user should only be in one clan.
                clan = clanList.UserGroups.Any() ? clanList.UserGroups.First() : null;
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error fetching user clans " + e.Message);
            }

            CardCollection cardCollection = null;

            try
            {
                var response = await _connection.Client.RpcAsync(_connection.Session, "load_user_cards", "");

                cardCollection = response.Payload.FromJson <CardCollection>();
            }
            catch (ApiResponseException e)
            {
                throw e;
            }

            _usernameText.text = user.Username;
            _statsText.text    = GenerateStats(playerData).TrimEnd();

            _clanNameText.text = clan == null ?
                                 "<i><color=#b0b0b0>[Not a clan member yet]</color></i>" :
                                 clan.Group.Name;

            List <string> deckIds = cardCollection.GetDeckList();

            for (int i = 0; i < deckIds.Count; i++)
            {
                Card card = cardCollection.GetDeckCard(deckIds[i]);
                _cardSlots[i].SetCard(card);
            }
        }
    public async void GetLoginInfo()
    {
        StorageObjectId[] objs = new StorageObjectId[]
        {
            new StorageObjectId
            {
                Collection = "character",
                Key        = "location",
                UserId     = session.UserId
            }
        };
        IApiStorageObjects result = await client.ReadStorageObjectsAsync(session, objs);

        foreach (IApiStorageObject entry in result.Objects)
        {
            //Debug.Log(entry.Value);
            PlayerDataResponse pData = JsonUtility.FromJson <PlayerDataResponse>(entry.Value);
            EventManager.onGetLoginInformation.Invoke(pData);
            return;
        }

        EventManager.onGetLoginInformation.Invoke(new PlayerDataResponse());
    }