Esempio n. 1
0
        /// <summary>
        /// Invoked by <see cref="ClanSearchResult._joinClanButton"/>.
        /// Joins selected clan.
        /// If user is already member of this clan, changes tab to <see cref="_detailsTab"/>.
        /// If user is already member of another clan, does nothing.
        /// </summary>
        private async void JoinClan()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null)
            {
                if (clan.Group.Id == DisplayedClan.Id)
                {
                    Debug.Log("This user has already joined clan with name \"" + DisplayedClan.Name + "\"");
                    ShowClanDetails(DisplayedClan);
                }
                else
                {
                    Debug.LogWarning("Cannot join more then one clan. Leave current clan first.");
                }
            }
            else
            {
                IApiGroup newClan = await ClanManager.JoinClanAsync(Client, Session, DisplayedClan);

                if (newClan != null)
                {
                    OnClanChanged(newClan);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Shows <see cref="_detailsTab"/> panel and hides <see cref="_searchTab"/> panel.
        /// Displays local user clan info and updates user list.
        /// </summary>
        private async void ShowMyClanDetails()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null)
            {
                ShowClanDetails(clan.Group);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Called when user connects to Nakama server.
        /// Tries to retrieve the clan local user belongs to.
        /// On success calls <see cref="OnClanChanged(IApiGroup)"/>.
        /// </summary>
        private async void Init()
        {
            NakamaSessionManager.Instance.OnConnectionSuccess -= Init;
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null)
            {
                OnClanChanged(clan.Group);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Searches Nakama database in order to find clans containing a keyword in their names.
        /// The keyword is determined by <see cref="_clanSearchText"/> textfield.
        /// </summary>
        private async void SearchClan()
        {
            string        name     = _clanSearchInput.text;
            IApiGroupList clanList = await ClanManager.ListClansAsync(Client, Session, "%" + name + "%", _clansPerPage, null);

            if (clanList != null)
            {
                OnClanListFound(clanList);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Deletes the clan local user currently belongs to.
        /// Does nothing if user is not a member of any clan or has insufficient permissions.
        /// The name of newly created clan is determined by <see cref="_clanCreateName"/> textfield.
        /// </summary>
        private async void DeleteClan()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            bool good = await ClanManager.DeleteClanAsync(Client, Session, clan.Group);

            if (good == true)
            {
                OnClanLeft();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Updates user list based on currently <see cref="DisplayedClan"/>
        /// using <see cref="OnClanUserListReceived(List{IGroupUserListGroupUser})"/>.
        /// Invokes <paramref name="onEnded"/> on succes or failure.
        /// </summary>
        private async Task <bool> UpdateUserListAsync()
        {
            List <IGroupUserListGroupUser> userList = await ClanManager.GetClanUsersAsync(Client, Session, DisplayedClan);

            if (userList != null)
            {
                OnClanUserListReceived(userList);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Requests clan search list and clan member list refresh.
        /// </summary>
        public async void RefreshClanMenu()
        {
            SearchClan();
            bool good = await UpdateUserListAsync();

            if (good == false)
            {
                IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

                if (clan == null)
                {
                    OnClanChanged(null);
                }
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Leaves current clan.
        /// Invokes <see cref="OnClanLeft"/> on success.
        /// </summary>
        private async void LeaveClan()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan == null)
            {
                Debug.Log("User is not a member of any clan");
                return;
            }

            bool good = await ClanManager.LeaveClanAsync(Client, Session, clan.Group);

            if (good == true)
            {
                OnClanLeft();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Activates or deactivates buttons responsible for leaving, joining and removing clan
        /// depending on whether we belong to currently displayed clan.
        /// </summary>
        private async Task SetClanManagementButtonsAsync()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null && DisplayedClan.Id == clan.Group.Id)
            {
                _joinClanButton.gameObject.SetActive(false);
                _leaveClanButton.gameObject.SetActive(true);
                _removeClanButton.gameObject.SetActive(clan.State == (int)ClanUserState.Superadmin);
                _chatButton.gameObject.SetActive(true);
            }
            else
            {
                _joinClanButton.gameObject.SetActive(true);
                _leaveClanButton.gameObject.SetActive(false);
                _removeClanButton.gameObject.SetActive(false);
                _chatButton.gameObject.SetActive(false);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Sends clan creation request to Nakama server.
        /// Does nothing if user already belongs to a clan.
        /// </summary>
        private async void CreateClan(Action <IApiGroup> onCreated)
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            string name = _clanName.text;
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(client, session);

            if (clan != null)
            {
                Debug.LogWarning("User is already a member of a clan. Leave current clan first.");
            }
            else
            {
                IApiGroup newClan = await ClanManager.CreateClanAsync(client, session, name, _currentAvatar);

                if (newClan != null)
                {
                    MenuManager.Instance.HideTopMenu();
                    onCreated(newClan);
                }
            }
        }