/// <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); } } }
/// <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); } }
/// <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); } }
/// <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(); } }
/// <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); } } }
/// <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(); } }
/// <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(); } }
/// <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); } }
/// <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); } } }