Exemple #1
0
        /// <summary>
        /// Updates <see cref="_usernameText"/> and <see cref="_avatarImage"/>.
        /// Invoked after user successfully updates their account using <see cref="ProfileUpdatePanel"/>.
        /// </summary>
        private void OnAccoutUpdated()
        {
            IApiUser user = NakamaSessionManager.Instance.Account.User;

            _usernameText.text  = user.Username;
            _avatarImage.sprite = AvatarManager.Instance.LoadAvatar(user.AvatarUrl);
        }
        /// <summary>
        /// Updates <see cref="_usernameText"/> and <see cref="_avatarImage"/>.
        /// Invoked after user successfully updates their account using <see cref="ProfileUpdatePanel"/>.
        /// </summary>
        private void OnAccountUpdated()
        {
            IApiUser user = _connection.Account.User;

            _usernameText.text  = user.Username;
            _avatarImage.sprite = _avatarSprites.GetSpriteByName(user.AvatarUrl);
        }
Exemple #3
0
        /// <summary>
        /// Initializes this <see cref="ClanUserEntry"/> object.
        /// </summary>
        /// <param name="user">The user all associated with this <see cref="ClanUserEntry"/> object.</param>
        /// <param name="userState">The state of <paramref name="user"/> in currently shown Clan.</param>
        /// <param name="localState">The state of local user in currently shown Clan.</param>
        /// <param name="onKick">Method called after clicking <see cref="_kickButton"/>.</param>
        /// <param name="onPromote">Method called after clicking <see cref="_promoteButton"/>.</param>
        /// <param name="onShowProfile">Method called after clicking <see cref="_profileButton"/>.</param>
        public void SetUser(IApiUser user, int userState, int localState, Action <ClanUserEntry> onSelected,
                            Action <IApiUser> onKick, Action <IApiUser> onPromote, Action <IApiUser> onShowProfile)
        {
            // Setting basic information based on supplied parameters.
            _usernameText.text = user.Username;
            _rankImage.sprite  = GetRankSprite(userState);
            _rankImage.gameObject.SetActive(_rankImage.sprite != null);

            // If local user is the same as supplied user, show their name in green color
            // and disable kick and promote options.
            if (user.Id == _userId)
            {
                _usernameText.color = Color.green;
                _kickButton.gameObject.SetActive(false);
                _promoteButton.gameObject.SetActive(false);
            }
            // If local user cannot manager supplied user (because local user's ClanUserState is lower
            // or local user does not belong to this clan), disable kick and promote options.
            else if (!CanManageUser(localState, userState))
            {
                _kickButton.gameObject.SetActive(false);
                _promoteButton.gameObject.SetActive(false);
            }
            // Add listeners to buttons
            else
            {
                _kickButton.onClick.AddListener(() => onKick?.Invoke(user));
                _promoteButton.onClick.AddListener(() => onPromote?.Invoke(user));
            }
            _profileButton.onClick.AddListener(() => onShowProfile?.Invoke(user));
            _panelButton.onClick.AddListener(() => onSelected(this));
        }
Exemple #4
0
        /// <summary>
        /// Returns true if
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private async Task <bool> CanBeFriendAsync(IApiUser user)
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            if (user.Id == session.UserId)
            {
                return(false);
            }

            var friends = await FriendsManager.LoadFriendsAsync(client, session);

            if (friends == null)
            {
                Debug.Log("Couldn't retrieve friends list");
                return(false);
            }
            foreach (IApiFriend friend in friends.Friends)
            {
                if (friend.User.Id == user.Id)
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// Enables and disables UI.
        /// </summary>
        /// <remarks>
        /// Disables <see cref="_profileUpdateButton"/> if displayed user is not the local user.
        /// If displayed user is already a friend of local user (or is the local user),
        /// <see cref="_befriendButton"/> is disabled.
        /// If asPopup is true, show raycast blocking background and close button, otherwise,
        /// caller of this method should take care of closing this panel.
        /// </remarks>
        private async Task SetUIAccessAsync(IApiUser user)
        {
            IApiUser localUser = _connection.Account.User;
            bool     isFriend  = await CanBeFriendAsync(user);

            _avatarImage.sprite = _avatarSprites.GetSpriteByName(user.AvatarUrl);
            _profileUpdateButton.gameObject.SetActive(user.Id == localUser.Id);
            _befriendButton.gameObject.SetActive(isFriend);
        }
        /// <summary>
        /// Invoked whenever user clicks <see cref="LeaderboardEntry._profile"/> button of a record.
        /// </summary>
        private async void OnProfileClicked(string userId)
        {
            IApiUser user = await NakamaSessionManager.Instance.GetUserInfoAsync(userId, null);

            if (user != null)
            {
                ProfilePopup.Instance.Show(userId);
            }
        }
Exemple #7
0
        /// <summary>
        /// Enables and disables UI.
        /// </summary>
        /// <remarks>
        /// Disables <see cref="_profileUpdateButton"/> if displayed user is not the local user.
        /// If displayed user is already a friend of local user (or is the local user),
        /// <see cref="_befriendButton"/> is disabled.
        /// If asPopup is true, show raycast blocking background and close button, otherwise,
        /// caller of this method should take care of closing this panel.
        /// </remarks>
        private async Task SetUIAccessAsync(IApiUser user)
        {
            IApiUser localUser = NakamaSessionManager.Instance.Account.User;
            bool     isFriend  = await CanBeFriendAsync(user);

            _avatarImage.sprite = AvatarManager.Instance.LoadAvatar(user.AvatarUrl);
            _profileUpdateButton.gameObject.SetActive(user.Id == localUser.Id);
            _befriendButton.gameObject.SetActive(isFriend);
        }
Exemple #8
0
 public UsersController(SignInManager <IdentityUser> signInManager,
                        UserManager <IdentityUser> userManager,
                        IOptions <ApiUserClaimsSettings> appSettings,
                        IApiUser user, ILogger <UsersController> logger)
 {
     _signInManager = signInManager;
     _userManager   = userManager;
     _logger        = logger;
     _appSettings   = appSettings.Value;
 }
Exemple #9
0
 public AuthController(IApiNotification notificador,
                       SignInManager <IdentityUser> signInManager,
                       UserManager <IdentityUser> userManager,
                       IOptions <ApiUserClaimsSettings> appSettings,
                       IApiUser user, ILogger <AuthController> logger) : base(notificador, user)
 {
     _signInManager = signInManager;
     _userManager   = userManager;
     _logger        = logger;
     _appSettings   = appSettings.Value;
 }
Exemple #10
0
 /// <summary>
 /// Method invoked by clicking on <see cref="ClanUserEntry._promoteButton"/>.
 /// Promotes the user to higher <see cref="ClanUserState"/>.
 /// </summary>
 private async void OnUserPromote(IApiUser user)
 {
     try
     {
         await _connection.Client.PromoteGroupUsersAsync(_connection.Session, _state.UserClan.Id, new string[] { user.Id });
     }
     catch (ApiResponseException e)
     {
         Debug.LogWarning("An exception has occured when promoting user " + user.Username
                          + " in clan " + _state.UserClan.Name + ": " + e);
     }
 }
        /// <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);
            }
        }
Exemple #12
0
        public RootController(IApiNotification notification,
                              IApiUser appUser)
        {
            _notification = notification;
            AppUser       = appUser;

            if (appUser.IsAuthenticated())
            {
                UserId = appUser.GetUserId();
                IsUserAuthenticated = true;
            }
        }
Exemple #13
0
        public void Init(GameConnection connection, string deviceId)
        {
            _deviceId   = deviceId;
            _connection = connection;

            _backButton.onClick.AddListener(() => Hide());
            _doneButton.onClick.AddListener(Done);

            IApiUser user = _connection.Account.User;

            _backButton.gameObject.SetActive(true);
        }
Exemple #14
0
        /// <summary>
        /// Method invoked by clicking on <see cref="ClanUserEntry._kickButton"/>.
        /// Removes user from current clan and updates user list.
        /// </summary>
        private async void OnUserKick(IApiUser kickedUser)
        {
            try
            {
                await _connection.Client.KickGroupUsersAsync(_connection.Session, _state.UserClan.Id, new string[] { kickedUser.Id });

                var userEnumeration = await _connection.Client.ListGroupUsersAsync(_connection.Session, _state.UserClan.Id, null, 1, null);

                OnClanUserListReceived(userEnumeration.GroupUsers);
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("An exception has occured when kicking user " + e.Message);
            }
        }
Exemple #15
0
        /// <summary>
        /// Method invoked by clicking on <see cref="ClanUserEntry._promoteButton"/>.
        /// Promotes the user to higher <see cref="ClanUserState"/>.
        /// </summary>
        private async void OnUserPromote(IApiUser user)
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan == null)
            {
                Debug.Log("Not a member of any clan");
            }
            Debug.Log("Promoted user " + user.Username);
            bool good = await ClanManager.PromoteUserAsync(Client, Session, user, clan.Group);

            if (good == true)
            {
                await UpdateUserListAsync();
            }
        }
Exemple #16
0
        /// <summary>
        /// Populates fields of this panel using <see cref="PlayerData"/> gathered from <paramref name="user"/>.
        /// Makes this panel visible to the user.
        /// </summary>
        /// <param name="user">User to be displayed in this panel.</param>
        public async Task <bool> ShowAsync(IApiUser user)
        {
            bool populated = await PopulateDataAsync(user);

            if (populated == true)
            {
                // If asPopup is true, show raycast blocking background and close button.
                // Otherwise, caller of this method should take care of closing this panel.
                await SetUIAccessAsync(user);

                return(true);
            }
            else
            {
                return(false);
            }
        }
    async void ListGroupMembers(string groupId)
    {
        var result = await client.ListGroupUsersAsync(session, groupId, state : 2, limit : 100, cursor : null);

        playersOnline.Clear();

        foreach (var ug in result.GroupUsers)
        {
            IApiUser g = ug.User;
            if (g.Online)
            {
                playersOnline.Add(new OnlinePlayerInfo(g.Username, g.Id));
            }
            //Debug.LogFormat("User '{0}' role '{1}', '{2}'", g.Id, g.Username, g.Online);
        }

        if (playersOnline.Count == 0)
        {
            ListGroupMembers(online_players_group_id);
        }
    }
        /// <summary>
        /// Makes this panel visible to the viewer.
        /// Fills fields with local user data.
        /// </summary>
        /// <param name="canTerminate">
        /// If false, user can't exit this panel before updating their account.
        /// </param>
        public void ShowUpdatePanel(Action onDone, bool canTerminate)
        {
            // Update done button listeners
            _doneButton.onClick.RemoveAllListeners();
            _doneButton.onClick.AddListener(() => Done(onDone));

            IApiUser user = NakamaSessionManager.Instance.Account.User;

            _usernameText.text  = user.Username;
            _avatarPath         = user.AvatarUrl;
            _avatarImage.sprite = AvatarManager.Instance.LoadAvatar(_avatarPath);
            MenuManager.Instance.ShowMenu(this, false);

            if (canTerminate == true)
            {
                _backButton.gameObject.SetActive(true);
            }
            else
            {
                _backButton.gameObject.SetActive(false);
            }
        }
Exemple #19
0
        /// <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 Task <bool> PopulateDataAsync(IApiUser user)
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            PlayerData data = await _playerDataStorage.LoadDataAsync(user.Id, "player_data");

            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(client, session, user.Id);

            Deck deck = await _deckStorage.LoadDataAsync(user.Id, "deck");

            if (data != null && deck != null)
            {
                _usernameText.text = user.Username;
                _statsText.text    = GenerateStats(data).TrimEnd();

                if (clan != null)
                {
                    _clanNameText.text = clan.Group.Name;
                }
                else
                {
                    _clanNameText.text = "<i><color=#b0b0b0>[Not a clan member yet]</color></i>";
                }

                for (int i = 0; i < deck.usedCards.Count; i++)
                {
                    Card card = deck.usedCards[i];
                    _cardSlots[i].SetCard(card);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Returns true if
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private async Task <bool> CanBeFriendAsync(IApiUser user)
        {
            if (user.Id == _connection.Session.UserId)
            {
                return(false);
            }

            var friends = await _connection.Client.ListFriendsAsync(_connection.Session);

            if (friends == null)
            {
                Debug.LogError("Couldn't retrieve friends list");
                return(false);
            }
            foreach (IApiFriend friend in friends.Friends)
            {
                if (friend.User.Id == user.Id)
                {
                    return(false);
                }
            }
            return(true);
        }
 /// <summary>
 /// Populates fields of this panel using <see cref="PlayerData"/> gathered from <paramref name="user"/>.
 /// Makes this panel visible to the user.
 /// </summary>
 /// <param name="user">User to be displayed in this panel.</param>
 public async void Show(IApiUser user)
 {
     PopulateDataAsync(user);
     await SetUIAccessAsync(user);
 }
 /// <summary>
 /// Shows <see cref="ProfilePanel"/> using given user data.
 /// </summary>
 public void Show(IApiUser user)
 {
     _profilePanel.Show(user);
     base.Show();
 }
Exemple #23
0
 /// <summary>
 /// Method invoked by clicking on <see cref="ClanUserEntry._profileButton"/>.
 /// Shows <see cref="ProfilePanel"/> filled with <paramref name="user"/> data.
 /// </summary>
 private void OnUserShowProfile(IApiUser user)
 {
     _profilePopup.Show(user);
 }
Exemple #24
0
        /// <summary>
        /// Shows <see cref="ProfilePanel"/> using given user data.
        /// </summary>
        public async void Show(IApiUser user)
        {
            await _profilePanel.ShowAsync(user);

            base.Show();
        }
Exemple #25
0
 /// <summary>
 /// Method invoked by clicking on <see cref="ClanUserEntry._profileButton"/>.
 /// Shows <see cref="ProfilePanel"/> filled with <paramref name="user"/> data.
 /// </summary>
 private void OnUserShowProfile(IApiUser user)
 {
     Debug.Log("Showed user " + user.Username + "'s profile");
     ProfilePopup.Instance.Show(user);
 }
Exemple #26
0
        /// <summary>
        /// Rises the <see cref="ClanUserState"/> of supplied member in given clan.
        /// Fails if promoting user has no permissions to promote given user.
        /// </summary>
        public static async Task <bool> PromoteUserAsync(Client client, ISession session, IApiUser promotedUser, IApiGroup clan)
        {
            try
            {
                await client.PromoteGroupUsersAsync(session, clan.Id, new string[] { promotedUser.Id });

                return(true);
            }
            catch (ApiResponseException e)
            {
                if (e.StatusCode == (long)System.Net.HttpStatusCode.BadRequest)
                {
                    Debug.LogWarning("Insufficient permissions to promote user or clan not found");
                    return(false);
                }
                else
                {
                    Debug.LogWarning("An internal exception has occured when promoting user " + promotedUser.Username
                                     + " in clan " + clan.Name + ": " + e);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("An exception has occured when promoting user " + promotedUser.Username + " in clan " + clan.Name + ": " + e);
                return(false);
            }
        }
Exemple #27
0
        /// <summary>
        /// Kicks supplied user out of given clan.
        /// Fails if kicking user has no permissions to kick the user.
        /// </summary>
        public static async Task <bool> KickUserAsync(Client client, ISession session, IApiUser kickedUser, IApiGroup clan)
        {
            try
            {
                await client.KickGroupUsersAsync(session, clan.Id, new string[] { kickedUser.Id });

                return(true);
            }
            catch (ApiResponseException e)
            {
                if (e.StatusCode == (long)System.Net.HttpStatusCode.NotFound)
                {
                    Debug.LogWarning("Insufficient permissions to kick " + kickedUser.Username
                                     + " from clan " + clan.Name + " or clan not found: " + e);
                    return(false);
                }
                else
                {
                    Debug.LogWarning("An internal exception has occured when kicking user " + kickedUser.Username
                                     + " from clan " + clan.Name + " with code " + e.StatusCode + ": " + e);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("An exception has occured when kicking user " + kickedUser.Username + " from clan " + clan.Name + ": " + e);
                return(false);
            }
        }