コード例 #1
0
    //读取全部本地账户信息
    void Load()
    {
        //
        string dataStr = PlayerPrefs.GetString(AllUserAddress, "");

        if (String.IsNullOrEmpty(dataStr))
        {
            return;
        }

        QK_JsonValue_Map tData = new QK_JsonValue_Map();

        if (!tData.Parse(dataStr))
        {
            return;
        }

        mData.Clear();
        foreach (KeyValuePair <string, QK_JsonValue> kuser in tData)
        {
            QK_JsonValue_Map uData = kuser.Value as QK_JsonValue_Map;

            string uid = kuser.Key;
            Dictionary <string, string> userIn = new Dictionary <string, string>();
            foreach (KeyValuePair <string, QK_JsonValue> uda in uData)
            {
                string uvalue = uda.Value as QK_JsonValue_Str;
                //反转译字符串  防止多次转译
                uvalue = System.Text.RegularExpressions.Regex.Unescape(uvalue);
                userIn.Add(uda.Key, uvalue);
            }
            mData.Add(kuser.Key, userIn);
        }
    }
コード例 #2
0
    //保存信息
    void Save()
    {
        QK_JsonValue_Map tData = new QK_JsonValue_Map();

        foreach (KeyValuePair <string, Dictionary <string, string> > userKeyValue in mData)
        {
            QK_JsonValue_Map tUser = new QK_JsonValue_Map();

            foreach (KeyValuePair <string, string> kv in userKeyValue.Value)
            {
                tUser.addStrValue(kv.Key, kv.Value);
            }

            tData.addValue(userKeyValue.Key, tUser);
        }

        String usersDate = tData.ToString();

        PlayerPrefs.SetString(AllUserAddress, usersDate);
    }
コード例 #3
0
        /// <summary>
        /// 执行封包分发
        /// </summary>
        /// <returns></returns>
        public bool DoDispatcher(QK_JsonValue_Map doc)
        {
            if (null == doc)
            {
                return(false);
            }
            if ("_Sync" != doc.StrValue("n"))
            {
                return(false);                             //这不是一个同步包
            }
            uint   sid = uint.Parse(doc.StrValue("sid"));
            string tm  = doc.StrValue("tm");

            if (tm == null)
            {
                return(false);
            }
            DateTime svrTime = DateTime.FromFileTime(long.Parse(tm)); //服务器的当前时间

            var svrNode = UpdateSvrTime(sid, svrTime);                //服务器时间刷新到本地内存

            QK_JsonValue_Array paths = doc["o"] as QK_JsonValue_Array;

            if (paths == null)
            {
                return(false);              //不是正确的同步消息
            }
            foreach (KeyValuePair <string, QK_JsonValue> kvpath in paths)
            {
                var objs = kvpath.Value as QK_JsonValue_Array;
                if (objs == null)
                {
                    continue;              //错误的协议
                }
                var path = kvpath.Key;

                //获取本路径对应的对象
                var pathObj = GetObject(sid, path, true);

                foreach (KeyValuePair <string, QK_JsonValue> kvobj in objs)
                {
                    QK_JsonValue_Map objInfo = kvobj.Value as QK_JsonValue_Map;
                    if (objInfo == null)
                    {
                        return(false);
                    }

                    //取得对象id
                    string  name    = objInfo.StrValue("n");
                    SyncObj currObj = pathObj.GetChild(name);

                    if (objInfo["d"] != null) //本对象被删除
                    {
                        pathObj.RemoveChild(name);
                    }
                    else //变更属性
                    {
                        QK_JsonValue_Array mNode = objInfo["m"] as QK_JsonValue_Array;
                        if (mNode != null) //存在属性
                        {
                            foreach (KeyValuePair <string, QK_JsonValue> currkv in mNode)
                            {
                                string           attName       = currkv.Key;
                                QK_JsonValue_Str attValue_json = currkv.Value as QK_JsonValue_Str;
                                if (attValue_json == null)
                                {
                                    continue;
                                }

                                string attValue = (string)attValue_json;

                                currObj.SetValue(attName, attValue);
                            }
                        }
                    }
                } //end  foreach (KeyValuePair<string, QK_JsonValue> kvobj in objs)
            }     //end foreach (KeyValuePair<string, QK_JsonValue> kvpath in paths)

            return(true);
        }