Пример #1
0
        IEnumerator JoinToClan(bl_ClanInfo info, bool updateClanInfo)
        {
            LoadingOverlays[4].SetActive(true);
            WWWForm wf = new WWWForm();

            wf.AddField("type", 10);
            wf.AddField("hash", bl_DataBase.Instance.GetUserToken());
            wf.AddField("clanID", info.ID);
            wf.AddField("userID", bl_DataBase.Instance.LocalUser.ID);
            wf.AddField("settings", bl_DataBase.Instance.LocalUser.Score);

            using (UnityWebRequest w = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.Clans), wf))
            {
                yield return(w.SendWebRequest());

                if (!w.isNetworkError)
                {
                    string t = w.downloadHandler.text;
                    if (t.Contains("done"))
                    {
                        if (updateClanInfo)
                        {
                            bl_ClanSearch cs = FindObjectOfType <bl_ClanSearch>();
                            yield return(StartCoroutine(cs.Search(info.Name, false)));

                            info = cs.LastSearchInfo;
                        }
#if CLANS
                        bl_DataBase.Instance.LocalUser.Clan = info;
#endif
                        if (!updateClanInfo)
                        {
#if CLANS
                            bl_ClanInfo.ClanMember me = new bl_ClanInfo.ClanMember();
                            me.ID   = bl_DataBase.Instance.LocalUser.ID;
                            me.Name = bl_DataBase.Instance.LocalUser.NickName;
                            me.Role = ClanMemberRole.Member;
                            bl_DataBase.Instance.LocalUser.Clan.Members.Add(me);
#endif
                        }
                        ClearCacheUI();
                        ClanInfoOverlay.SetActive(false);
                        CreateClanWindow.SetActive(false);
                        MyClanWindow.SetActive(true);
                        OpenWindow(1);
                        ClanInfoLogText.text = "Joined to the clan: " + info.Name;
                        Debug.Log("Joined to the clan");
                    }
                    else
                    {
                        Debug.Log(t);
                    }
                }
                else
                {
                    Debug.LogError(w.error);
                }
            }
            LoadingOverlays[4].SetActive(false);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public void LeaveClan()
        {
#if CLANS
            bl_ClanInfo.ClanMember me = bl_ClanManager.Instance.ClanInfo.Members.Find(x => x.ID == bl_DataBase.Instance.LocalUser.ID);
            if (me == null)
            {
                return;
            }

            if (bl_DataBase.Instance.LocalUser.Clan.PlayerRole() != ClanMemberRole.Leader)
            {
                KickMember(me, true);
            }
            else
            {
                if (bl_ClanManager.Instance.ClanInfo.Members.Count > 1)
                {
                    //can't leave yet
                    CantLeaveUI.SetActive(true);
                }
                else
                {
                    KickMember(me, true);
                }
            }
#endif
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public void KickMember(bl_ClanInfo.ClanMember member, bool self)
        {
            string line = "";
            List <bl_ClanInfo.ClanMember> list = bl_ClanManager.Instance.ClanInfo.Members;
            int idx = list.FindIndex(x => x.ID == member.ID);

            list.RemoveAt(idx);
            for (int i = 0; i < list.Count; i++)
            {
                line += string.Format("{0}-{1},", list[i].ID, (int)list[i].Role);
            }
            StartCoroutine(ProcessKick(member, line, self));
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="member"></param>
        /// <param name="ascend"></param>
        public void ChangeMemberRole(bl_ClanInfo.ClanMember member, bool ascend)
        {
            int cr = (int)member.Role;

            cr = ascend ? cr + 1 : cr - 1;
            string line = "";
            List <bl_ClanInfo.ClanMember> list = bl_ClanManager.Instance.ClanInfo.Members;
            int idx = list.FindIndex(x => x.ID == member.ID);

            list[idx].Role = (ClanMemberRole)cr;
            for (int i = 0; i < list.Count; i++)
            {
                line += string.Format("{0}-{1},", list[i].ID, (int)list[i].Role);
            }
            StartCoroutine(ProcessAscend(line));
        }
Пример #5
0
 private void DecompileMembers(string line)
 {
     bl_ClanManager.Instance.ClanInfo.Members       = new List <bl_ClanInfo.ClanMember>();
     bl_ClanManager.Instance.ClanInfo.SourceMembers = line;
     string[] split = line.Split(","[0]);
     for (int i = 0; i < split.Length; i++)
     {
         if (string.IsNullOrEmpty(split[i]))
         {
             continue;
         }
         string[] info = split[i].Split("-"[0]);
         if (info.Length < 2)
         {
             continue;
         }
         bl_ClanInfo.ClanMember member = new bl_ClanInfo.ClanMember();
         member.ID   = int.Parse(info[0]);
         member.Role = (ClanMemberRole)int.Parse(info[1]);
         bl_ClanManager.Instance.ClanInfo.Members.Add(member);
     }
 }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="info"></param>
        /// <param name="mc"></param>
        public void Set(bl_ClanInfo.ClanMember info, bl_MyClan mc)
        {
            MyClan        = mc;
            MemberInfo    = info;
            NameText.text = MemberInfo.GetNameWithRole();
#if CLANS
            var            localUser = bl_DataBase.Instance.LocalUser;
            ClanMemberRole pr        = localUser.Clan.PlayerRole();
            if (pr != ClanMemberRole.Member)
            {
                int ph = (int)pr;
                int uh = (int)MemberInfo.Role;
                if (ph > uh)
                {
                    KickButton.SetActive(MemberInfo.ID != localUser.ID); //don't allow kick ourselves
                    DesendButton.SetActive(uh > 0);
                    if ((ph - uh) >= 2)                                  //parent ranks can't accent others just one above him.
                    {
                        AscendButton.SetActive(true);
                    }
                }
            }
#endif
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        IEnumerator ProcessKick(bl_ClanInfo.ClanMember member, string line, bool self)
        {
            bl_ClanManager.Instance.LoadingOverlays[4].SetActive(true);
            if (self)
            {
                bl_ClanManager.Instance.LoadingOverlays[1].SetActive(true);
            }
            WWWForm wf = new WWWForm();

            wf.AddField("type", 13);
            wf.AddField("hash", bl_DataBase.Instance.GetUserToken());
            wf.AddField("clanID", bl_ClanManager.Instance.ClanInfo.ID);
            wf.AddField("settings", line);
            wf.AddField("userID", member.ID);
#if CLANS
            int dc = 0;
            if (bl_LoginProDataBase.Instance.DeleteEmptyClans)
            {
                dc = member.Role == ClanMemberRole.Leader ? 1 : 0;//if this is the leader, that means that the clan will be empty so we have to delete it from DB
                wf.AddField("desc", dc);
            }
#endif
            using (UnityWebRequest w = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.Clans), wf))
            {
                yield return(w.SendWebRequest());

                if (!w.isNetworkError)
                {
                    string t = w.downloadHandler.text;
                    if (t.Contains("yes"))
                    {
                        if (self)
                        {
#if CLANS
                            bl_DataBase.Instance.LocalUser.Clan = new bl_ClanInfo();
#endif
                            initialized = false;
                            bl_ClanManager.Instance.LoadingOverlays[0].SetActive(true);
                            ClearCacheUI();
                            bl_ClanManager.Instance.ClanInfo = new bl_ClanInfo();
                            bl_ClanManager.Instance.Initialize();//reset the menu
                        }
                        else
                        {
                            Refresh();
                        }
                    }
                    else
                    {
                        Debug.Log(t);
                    }
                }
                else
                {
                    Debug.LogError(w.error);
                }
            }
            if (self)
            {
                bl_ClanManager.Instance.LoadingOverlays[1].SetActive(false);
                bl_ClanManager.Instance.LoadingOverlays[4].SetActive(false);
            }
        }