void UpdateClientToServer()
    {
        Debug.Log("----------------------Dua du lieu moi len server----------------------");
        AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeCurrentMission(currentMissionClient));
        string data_mission = "";

        for (int i = 0; i < DataCache.dataMissionCache.Length; i++)
        {
            //Chi gui nhung mission da open len server
            if (DataCache.dataMissionCache[i].Open == 1)
            {
                if (data_mission.Length > 0)
                {
                    data_mission += ",";
                }
                data_mission += DataCache.dataMissionCache[i].Mission + "-" + DataCache.dataMissionCache[i].Score + "-" + DataCache.dataMissionCache[i].Star + "-" + DataCache.dataMissionCache[i].Open;
            }
            DialogLoadingFB.HideFBLoading();
        }
        AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfoMissionUpdate(FB.UserId, "" + data_mission));
        DataCache.SaveAchievementCache(true);
    }
    void UpdateServerToClient()
    {
        try
        {
            DialogLoadingFB.ShowFBLoading();
            PlayerPrefs.SetInt(DataMissionControlNew.key_update_mission_data_from_server, 0);
            PlayerPrefs.SetInt(DataMissionControlNew.key_update_achievement_data_from_server, 0);

            //Them du lieu tam thoi truoc(de phong truong hop ko truy van dc)
            for (int i = 0; i < currentMissionServer; i++)
            {
                DataCache.UpdateMissionScore(0, 0, i + 1, 1);
            }
            //Lay du lieu nguoi dung
            try
            {
                AudioControl.getMonoBehaviour().StartCoroutine(DHS.GetMeInfo(FB.UserId, www =>
                {
                    Debug.Log(JsonHelper.FormatJson(www.text));
                    IDictionary dict = Json.Deserialize(www.text) as IDictionary;
                    if (dict != null && dict["data"] != null)
                    {
                        List <object> lists = dict["data"] as List <object>;
                        if (lists.Count > 0)
                        {
                            Dictionary <string, object> info = lists[0] as Dictionary <string, object>;
                            int diamond        = Convert.ToInt32(info["diamond"]);
                            string achievement = Convert.ToString(info["achievement"]);
                            DataCache.RestoreUserData(diamond, achievement);
                            //GameObject.Find("DialogAchievement").GetComponent<DialogAchievement>().CountAchievementFinish();
                            string data_mission = Convert.ToString(info["mission_data"]);
                            //Phan tich du lieu va chi lay nhung du lieu co score, star > o client
                            string[] dataMission = data_mission.Split(',');
                            for (int i = 0; i < dataMission.Length; i++)
                            {
                                string[] info_mission = dataMission[i].Split('-');
                                string mission        = info_mission[0];
                                string score          = info_mission[1];
                                string star           = info_mission[2];
                                string open           = info_mission[3];
                                DataCache.UpdateMissionScore(Convert.ToInt32(score), Convert.ToInt16(star), Convert.ToInt16(mission), Convert.ToInt16(open));
                            }
                            DataCache.SaveMissionDataCache();
                            PlayerPrefs.SetInt(DataMissionControlNew.key_update_mission_data_from_server, 1);
                            //Debug.Log("------ Update ------ ");
                            ShowStarMission();
                            ShowCurrentMission();
                            DialogLoadingFB.HideFBLoading();
                        }
                    }
                }, www =>
                {
                    DialogLoadingFB.HideFBLoading();
                    ShowRetryLoad(() =>
                    {
                        UpdateServerToClient();
                    });
                    if (debug)
                    {
                        MobilePlugin.getInstance().ShowToast("Loi response CheckDataMissionServer");
                    }
                }));
            }
            catch (Exception e)
            {
                Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message);
            }
        }
        catch (Exception e)
        {
            Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message);
        }
    }
 //Lay current mission server
 void CheckDataMissionServer()
 {
     try
     {
         DialogLoadingFB.ShowFBLoading();
         //Debug.Log("Truy van toi server iduser = "******"All current mission :" + JsonHelper.FormatJson(www.text));
             bool postToServer = true;
             IDictionary dict  = Json.Deserialize(www.text) as IDictionary;
             if (dict != null && dict["data"] != null)
             {
                 List <object> lists = dict["data"] as List <object>;
                 string data_save    = "";
                 for (int i = 1; i <= lists.Count; i++)
                 {
                     Dictionary <string, object> info = lists[i - 1] as Dictionary <string, object>;
                     string id      = "" + info["fb_id"];
                     string mission = "" + info["mission"];
                     string name    = "" + info["name"];
                     if (data_save.Length > 0)
                     {
                         data_save += ",";
                     }
                     if (id.Equals(FB.UserId))
                     {
                         //Debug.Log("Mission hien tai truoc so sanh " + CurrentMissionFromClient + " mission " + mission);
                         //neu mission tren server > mission o client moi cap nhat mission cua nguoi choi
                         currentMissionServer = Convert.ToInt16(mission);
                         Debug.Log("Current mission on server " + currentMissionServer);
                         if (currentMissionServer > currentMissionClient || PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 1) == 0)
                         {
                             //Update new current data
                             data_save += "Me-" + name + "-" + currentMissionServer;
                             UpdateServerToClient();
                             postToServer = false;
                             if (PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 1) == 0)
                             {
                                 Debug.Log("---------------Update lai tu server do chua update day du-------------------");
                             }
                         }
                         else
                         {
                             data_save += "Me-" + name + "-" + currentMissionClient;
                         }
                     }
                     else
                     {
                         data_save += id + "-" + name + "-" + mission;
                     }
                 }
                 //Debug.Log("" + data_save);
                 if (!String.IsNullOrEmpty(data_save))
                 {
                     DataCache.SaveCurrentMission(data_save);
                 }
             }
             Debug.Log("currentMissionServer " + currentMissionServer);
             if (postToServer && currentMissionServer < currentMissionClient)
             {
                 UpdateClientToServer();
             }
             else
             {
                 Debug.Log("Du lieu cu => ko up");
                 if (!(currentMissionServer > currentMissionClient))
                 {
                     DialogLoadingFB.HideFBLoading();
                 }
             }
         }, www =>
         {
             DialogLoadingFB.HideFBLoading();
             Debug.Log("Loi response CheckDataMissionServer");
             if (debug)
             {
                 MobilePlugin.getInstance().ShowToast("Loi response CheckDataMissionServer");
             }
             ShowRetryLoad(() =>
             {
                 Debug.Log("Retry CheckDataMissionServer");
                 CheckDataMissionServer();
             }, () =>
             {
             });
         }));
     }
     catch (Exception e)
     {
         Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message);
     }
 }