示例#1
0
    public void FromJson(BonDocument json)
    {
        foreach (BonElement p in json)
        {
            switch (p.name)
            {
            case "dlcType": {
                dlcType = (DLCType)p.value.AsInt;
                break;
            }

            case "files": {
                foreach (BonElement pp in p.value.AsBonDocument)
                {
                    FileDesc fd = new FileDesc();
                    fd.name        = pp.name;
                    fd.pak         = this;
                    files[fd.name] = fd;
                    fd.FromJson(pp.value.AsBonDocument);
                }
                break;
            }

            case "dependences": {
                BonArray arr = p.value.AsBonArray;
                dependences = new string[arr.Count];
                for (int i = dependences.Length; --i >= 0;)
                {
                    dependences[i] = arr[i].AsString;
                }
                break;
            }
            }
        }
    }
示例#2
0
    public BonDocument ToJson()
    {
        BonDocument json = new BonDocument();

        json["crc"] = crc;
        return(json);
    }
示例#3
0
    public BonDocument GetBonDocument(string name, BonDocument defaultValue = null)
    {
        BonElement el;

        if (elements.TryGetValue(name, out el))
        {
            return(el.value.AsBonDocument);
        }
        return(defaultValue);
    }
示例#4
0
    private BonDocument ReadDoc()
    {
        BonDocument doc   = new BonDocument();
        int         count = br.Read7BitEncodedInt();

        for (int i = 0; i < count; i++)
        {
            string name = br.ReadString();
            doc[name] = Read();
        }
        return(doc);
    }
示例#5
0
    public BonDocument ToJson()
    {
        BonDocument json     = new BonDocument();
        BonDocument packages = new BonDocument();

        json["packages"] = packages;
        foreach (KeyValuePair <string, PackageDesc> p in this.packages)
        {
            packages[p.Key] = p.Value.ToJson();
        }
        return(json);
    }
示例#6
0
 public void FromJson(BonDocument json)
 {
     foreach (BonElement p in json)
     {
         switch (p.name)
         {
         case "crc": {
             crc = p.value.AsInt;
             break;
         }
         }
     }
 }
示例#7
0
        int SyncPrivateMsgs(BonDocument chd)
        {
            lastId = chd["lastId"].AsLong;
            List <IMMsg> newMsgs = new List <IMMsg>();

            BonUtil.ToObj(chd["msgs"], newMsgs);
            for (int i = newMsgs.Count; --i >= 0;)
            {
                newMsgs[i].im     = im;
                newMsgs[i].recTgt = IMChatTarget.用户;
            }
            im.AddNewMsgs(newMsgs);
            return(newMsgs.Count);
        }
示例#8
0
        int SyncChannelMsgs(BonDocument chd, IMChannel ch)
        {
            IMChatSession session = im.GetSession(ch);

            session.lastId = chd["lastId"].AsLong;
            newMsgs.Clear();
            BonUtil.ToObj(chd["msgs"], newMsgs);
            for (int i = newMsgs.Count; --i >= 0;)
            {
                newMsgs[i].im     = im;
                newMsgs[i].recTgt = IMChatTarget.频道;
            }
            im.AddNewMsgs(newMsgs);
            return(newMsgs.Count);
        }
示例#9
0
 public void FromJson(BonDocument json)
 {
     foreach (BonElement p in json)
     {
         switch (p.name)
         {
         case "packages": {
             foreach (BonElement pp in p.value.AsBonDocument)
             {
                 PackageDesc pd = new PackageDesc();
                 pd.name           = pp.name;
                 packages[pd.name] = pd;
                 pd.FromJson(pp.value.AsBonDocument);
             }
             break;
         }
         }
     }
 }
示例#10
0
    private BonDocument NextDocument()
    {
        BonDocument d = new BonDocument();

        while (true)
        {
            char c = NextToken();
            if (c == '}')
            {
                break;
            }
            if (c != '\"')// && c != '\'')
            {
                throw SyntaxError("Document error");
            }
            string k = GetNextString();
            if (NextToken() != ':')
            {
                throw SyntaxError("Document error");
            }
            BonValue v = NextValue();
            d[k] = v;
            c    = NextToken();
            if (c == '}')
            {
                break;
            }
            if (c != ',')
            {
                string txt  = "";
                int    ends = myIndex + 20;
                ends = ends < (mySource.Length - 1) ? ends : mySource.Length - 1;
                for (int i = myIndex - 1; i < myIndex + 10; i++)
                {
                    txt += mySource[i];
                }
                throw SyntaxError("Document error token [" + txt + "]");
            }
        }
        return(d);
    }
示例#11
0
        protected override bool OnHeatbeatDone(IMHttpContext ctx)
        {
            ClearInvalidChannels();
            if (ctx.code != 0)
            {
                Debug.Log("获取频道新聊天失败");
                ClearAll();
                return(false);
            }

            BonDocument chds = ctx.response.GetBonDocument("channels");

            if (chds == null)
            {
                ClearAll();
                return(false);
            }
            bool haveMsg = false;

            for (int i = channels.Count; --i >= 0;)
            {
                IMChannel ch = im.GetChannel(channels[i]);
                try {
                    if (!chds.Contains(ch.id))
                    {
                        ch.SetOffline();
                        continue;
                    }
                    if (SyncChannelMsgs(chds[ch.id].AsBonDocument, ch) > 0)
                    {
                        haveMsg = true;
                    }
                } catch (Exception e) {
                    Debug.Log(e);
                    ch.SetOffline();
                    continue;
                }
            }
            return(haveMsg);
        }
 public AnimatorController(RuntimeAnimatorController rac)
 {
     if (rac is UnityEditor.Animations.AnimatorController ac)
     {
         Init(ac);
     }
     else if (rac is AnimatorOverrideController oac)
     {
         Init(oac.runtimeAnimatorController as UnityEditor.Animations.AnimatorController);
         this.overrides = new BonDocument();
         List <KeyValuePair <AnimationClip, AnimationClip> > overrides = new List <KeyValuePair <AnimationClip, AnimationClip> >();
         oac.GetOverrides(overrides);
         foreach (var pair in overrides)
         {
             if (pair.Value == null)
             {
                 continue;
             }
             this.overrides[pair.Key.name] = pair.Value.name;
         }
     }
 }
示例#13
0
        protected override void OnSendDone(IMMsgForSend msg, IMHttpContext ctx)
        {
            IMChannel ch = im.GetChannel(msg.recId);

            if (ch == null)
            {
                return;
            }
            ClearInvalidChannels();
            if (ctx.code < 0)
            {
                Debug.Log("发送聊天致命错误");
                msg.Distributed = false;
                ClearAll();
                return;
            }
            if (ctx.code > 0)
            {
                Debug.Log("发送聊天错误");
                msg.Distributed = false;
                ch.SetOffline();
                return;
            }
            msg.Sent = true;
            try {
                BonDocument chd = ctx.response.GetBonDocument("channel");
                if (chd == null)
                {
                    msg.Distributed = false;
                    ch.SetOffline();
                    return;
                }
                SyncChannelMsgs(chd, ch);
            } catch (Exception e) {
                Debug.Log(e);
                msg.Distributed = false;
                ch.SetOffline();
            }
        }
示例#14
0
 public static void LoadSeed()
 {
     if (File.Exists(seedpath))
     {
         try {
             byte[] bytes = File.ReadAllBytes(seedpath);
             bytes = EncryptDecrypt.Decrypt(bytes);
             BonDocument bd    = BonDocument.FromBonBytes(bytes);
             SD_AllSeeds seeds = new SD_AllSeeds();
             seeds.FromBon(bd);
             MainData.allseeds = seeds;
             Debug.Log("SD_AllSeeds loaded." + seedpath);
         } catch (Exception e) {
             Debug.LogError("SD_AllSeeds load failed.");
             Debug.LogError(e);
         }
     }
     else
     {
         Debug.Log("SD_AllSeeds was not found.");
     }
 }
示例#15
0
    public BonDocument ToJson()
    {
        BonDocument json = new BonDocument();

        json["dlcType"] = (int)dlcType;
        BonDocument files = new BonDocument();

        json["files"] = files;
        foreach (KeyValuePair <string, FileDesc> p in this.files)
        {
            files[p.Key] = p.Value.ToJson();
        }
        if (dependences != null)
        {
            BonArray dps = new BonArray();
            foreach (string d in dependences)
            {
                dps.Add(d);
            }
            json["dependences"] = dps;
        }
        return(json);
    }
示例#16
0
    public static BonValue ToBon(object obj, HashSet <string> fields = null, Type declareType = null)
    {
        if (obj == null)
        {
            return(BonNull.value);
        }
        Type t = obj.GetType();

        switch (t.Name)
        {
        case "Byte": return((int)(byte)obj);

        case "SByte": return((int)(sbyte)obj);

        case "Int16": return((int)(short)obj);

        case "UInt16": return((int)(ushort)obj);

        case "Int32": return((int)obj);

        case "UInt32": return((int)(uint)obj);

        case "Int64": return((long)obj);

        case "UInt64": return((long)(ulong)obj);

        case "Single": return((float)obj);

        case "Double": return((double)obj);

        case "Boolean": return((bool)obj);

        case "String": return((string)obj);

        case "Byte[]": return((byte[])obj);

        default: {
            if (t.IsEnum)
            {
                return((int)obj);
            }
            break;
        }
        }

        switch (t.Name)
        {
        case "List`1": {
            Type     et  = t.GetGenericArguments()[0];
            BonArray arr = null;
            arr = new BonArray();
            IList list = (IList)obj;
            int   num  = list.Count;
            for (int i = 0; i < num; i++)
            {
                arr.Add(ToBon(list[i], fields, et));
            }
            return(arr);
        }

        case "Dictionary`2": {
            Type        et  = t.GetGenericArguments()[1];
            BonDocument doc = null;
            doc = new BonDocument();
            foreach (DictionaryEntry kv in (IDictionary)obj)
            {
                if (kv.Key.GetType().IsEnum)
                {
                    doc[((int)kv.Key).ToString()] = ToBon(kv.Value, fields, et);
                }
                else
                {
                    doc[kv.Key.ToString()] = ToBon(kv.Value, fields, et);
                }
            }
            return(doc);
        }

        default: {
            if (t.IsArray)
            {
                Type     et  = t.GetElementType();
                BonArray arr = null;
                arr = new BonArray();
                Array list = (Array)obj;
                int   num  = list.Length;
                for (int i = 0; i < num; i++)
                {
                    arr.Add(ToBon(list.GetValue(i), fields, et));
                }
                return(arr);
            }
            {
                if (obj is IBon)
                {
                    return(((IBon)obj).ToBon());
                }
                ClassInfo   ci  = ClassInfo.Get(t);
                BonDocument doc = new BonDocument();
                if (declareType != null && declareType != t)
                {
                    doc["_t_"] = t.FullName;
                }
                FldInfo[] fis = ci.fields.Values;
                for (int i = fis.Length; --i >= 0;)
                {
                    FldInfo fi = fis[i];
                    if (fields != null && !fields.Contains(fi.name))
                    {
                        continue;
                    }
                    doc[fi.name] = ToBon(fi.GetValue(obj), fi.subFields);
                }
                return(doc);
            }
        }
        }
    }
示例#17
0
    public static object ToObj(BonValue v, Type t, object old, HashSet <string> fields = null)
    {
        if (v == null)
        {
            return(null);
        }
        switch (t.Name)
        {
        case "Byte": return((byte)v.AsInt);

        case "SByte": return((sbyte)v.AsInt);

        case "Int16": return((short)v.AsInt);

        case "UInt16": return((ushort)v.AsInt);

        case "Int32": return(v.AsInt);

        case "UInt32": return((uint)v.AsInt);

        case "Int64": return(v.AsLong);

        case "UInt64": return((ulong)v.AsLong);

        case "Single": return(v.AsFloat);

        case "Double": return(v.AsDouble);

        case "Boolean": return(v.AsBoolean);

        case "String": return(v.AsString);

        case "Byte[]": return(v.AsBinary);

        case "List`1": {
            BonArray arr = v.AsBonArray;
            if (arr == null)
            {
                return(null);
            }
            int   num = arr.Count;
            IList l   = null;
            if (old != null)
            {
                l = (IList)old;
            }
            else
            {
                l = (IList)Activator.CreateInstance(t, num);
            }
            Type t2 = t.GetGenericArguments()[0];
            l.Clear();
            for (int i = 0; i < num; i++)
            {
                l.Add(ToObj(arr[i], t2, null, fields));
            }
            return(l);
        }

        case "Dictionary`2": {
            BonDocument doc = v.AsBonDocument;
            if (doc == null)
            {
                return(null);
            }
            int         num = doc.Count;
            IDictionary d   = null;
            if (old != null)
            {
                d = (IDictionary)old;
            }
            else
            {
                d = (IDictionary)Activator.CreateInstance(t, num);
            }
            Type[] t2s = t.GetGenericArguments();
            Type   tk  = t2s[0];
            Type   t2  = t2s[1];
            for (int i = 0; i < num; i++)
            {
                BonElement el  = doc[i];
                object     key = null;
                switch (tk.Name)
                {
                case "Int32": key = Convert.ToInt32(el.name); break;

                case "Int64": key = Convert.ToInt64(el.name); break;

                case "String": key = el.name; break;

                default: {
                    if (tk.IsEnum)
                    {
                        key = Enum.ToObject(tk, Convert.ToInt32(el.name));
                    }
                    break;
                }
                }
                if (key != null)
                {
                    BonValue v2  = el.value;
                    object   obj = null;
                    if (d.Contains(key))
                    {
                        obj = ToObj(v2, t2, d[key], fields);
                    }
                    else
                    {
                        obj = ToObj(v2, t2, null, fields);
                    }
                    if (obj == null)
                    {
                        d.Remove(key);
                    }
                    else
                    {
                        d[key] = obj;
                    }
                }
            }
            return(d);
        }

        default: {
            if (t.IsEnum)
            {
                return(Enum.ToObject(t, v.AsInt));
            }
            if (t.IsArray)
            {
                BonArray arr = v.AsBonArray;
                if (arr == null)
                {
                    return(null);
                }
                int  num = arr.Count;
                Type t2  = t.GetElementType();
                var  obj = Array.CreateInstance(t2, num);
                for (int i = 0; i < num; i++)
                {
                    obj.SetValue(ToObj(arr[i], t2, null, fields), i);
                }
                return(obj);
            }
            if (!v.IsBonDocument)
            {
                return(null);
            }
            {
                BonDocument doc = v.AsBonDocument;
                string      _t_ = doc.GetString("_t_");
                if (_t_ != null)
                {
                    try {
                        t = Type.GetType(_t_);
                    } catch (Exception) {
                        Debug.LogWarning("δÕÒµ½ÀàÐÍ: " + doc["_t_"].AsString);
                        return(null);
                    }
                }
                ClassInfo ci  = ClassInfo.Get(t);
                object    obj = old;
                Dictionary <string, List <DataMonitor> > dataMonitors = null;
                bool monitorObj = false;
                if (old != null)
                {
                    monitorObj = dataMonitor.TryGetValue(old, out dataMonitors);
                }
                if (obj == null)
                {
                    obj = Activator.CreateInstance(t);
                }
                if (obj is IBon)
                {
                    ((IBon)obj).FromBon(doc);
                    return(obj);
                }
                CachedDictionary <string, FldInfo> fis = ci.fields;
                bool isValueType = t.IsValueType;
                int  num         = doc.Count;
                for (int i = 0; i < num; i++)
                {
                    BonElement el = doc[i];
                    if (fields != null && !fields.Contains(el.name))
                    {
                        continue;
                    }
                    FldInfo fi;
                    if (fis.TryGetValue(el.name, out fi))
                    {
                        List <DataMonitor> fieldMonitors = null;
                        bool monitorField = monitorObj && dataMonitors.TryGetValue(fi.name, out fieldMonitors) && fieldMonitors.Count > 0;
                        if ((fi.type.IsValueType || fi.type == typeof(string) || fi.type.IsEnum) && !monitorField)
                        {
                            fi.SetValue(obj, ToObj(el.value, fi.type, null, fi.subFields));
                        }
                        else
                        {
                            object oldv = fi.GetValue(obj);
                            object newv = ToObj(el.value, fi.type, oldv, fi.subFields);
                            fi.SetValue(obj, newv);
                            if (monitorField && (fi.type.IsClass || oldv != newv))
                            {
                                dataChanged.AddRange(fieldMonitors);
                            }
                        }
                    }
                }
                return(obj);
            }
        }
        }
    }
示例#18
0
    IEnumerator _Send()
    {
        IMHttpContext ctx     = sendQueue.Dequeue();
        BonDocument   request = new BonDocument();

        ctx.request   = request;
        request["ul"] = ctx.ul.GetType().Name;
        BonDocument p = BonUtil.ToBon(ctx.ul, null, null) as BonDocument;

        request["p"]   = p;
        ctx.sno        = (++snoSeed);
        request["sno"] = ctx.sno;
        IMMe me = IM.Instance.me;

        if (me != null)
        {
            p["uid"] = me.id;
            if (me.auth != null)
            {
                request["auth"] = me.auth;
            }
        }
        byte[] postdata = ctx.request.ToBonBytes();
        postdata = EncryptDecrypt.Encrypt(postdata);

        while (ctx.retry >= 0)
        {
#if HTTP_DEBUG_LOG
            Debug.Log("发送数据{" + postdata.Length + "}: " + ctx.request.ToJsonString());
            Debug.Log("到: " + ctx.url);
#endif
            ctx.sendTime = TimeUtil.UnixTimestampNow();
            float  lastProgress = 0;
            double timeout      = TimeUtil.UnixTimestampNow() + 10;
            bool   isTimeout    = false;
            using (WWW www = new WWW(ctx.url, postdata, header)) {
                while (!www.isDone)
                {
                    double now = TimeUtil.UnixTimestampNow();
                    if (now >= timeout)
                    {
                        isTimeout = true;
                        break;
                    }
                    if (lastProgress != www.progress)
                    {
                        lastProgress = www.progress;
                        timeout      = now + 20;
                    }
                    yield return(null);
                }
                if (destroyed)
                {
                    busy = false;
                    yield break;
                }
                if (isTimeout)
                {
                    ctx.error = "UI.网络错误";
                    ctx.code  = -1;
                    Debug.LogError("访问超时");
                }
                else if (www.error != null)
                {
                    ctx.error = "UI.网络错误";
                    ctx.code  = -1;
                    Debug.LogError("Err:" + www.error);
                }
                else
                {
                    byte[] data = www.bytes;
                    try {
                        if (data[0] == 31)
                        {
                            try {
                                data = GZip.Decompress(data);
                            } catch (Exception) { }
                        }
                        ctx.response = BonDocument.FromBonBytes(data);
#if HTTP_DEBUG_LOG
                        Debug.Log("收到数据: " + ctx.response);
#endif
                        ctx.code  = ctx.response.GetInt("code");
                        ctx.error = null;
                        ctx.retry = 0;
                    } catch (Exception e) {
                        ctx.error = "数据解析错误";
                        Debug.LogError("下行数据解析错误 " + e.ToString());
                    }
                }
            }
            ctx.retry--;
        }
        busy = false;
        if (ctx.callback != null)
        {
            ctx.callback(ctx);
        }
        if (OnResult != null)
        {
            OnResult(ctx);
        }
    }
示例#19
0
 public Enumerator(BonDocument doc)
 {
     this.map  = doc.elements;
     this.keys = doc.keys.GetEnumerator();
     current   = BonElement.Empty;
 }