Пример #1
0
        public static int SendLuaProtocol(IntPtr L)
        {
            IntPtr idptr = LuaDLL.lua_touserdata(L, 1);
            ECGameSession self = default(ECGameSession);
            System.Object temp = default(System.Object);
            if (objs.TryGetValue(idptr.ToInt64(), out temp))
            {
                self = (ECGameSession)temp;
            }
            else
            {
                LuaStatic.traceback(L);
                LuaDLL.lua_error(L); return 1;
            }

            int nType = LuaDLL.lua_tointeger(L, 2);

            OctetsStream os = (OctetsStream)Funcs.GetObj(L, 3);
            CommonData data = new CommonData(nType, os);
            self.SendNetData(data);

            return 0;
        }
Пример #2
0
    public static int ReportProtocolRecord(IntPtr L)
    {
        string path = EntryPoint.Instance.AssetsPath + "/protocol.dat";
        FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read);
        if (fs == null)
        {
            LuaDLL.lua_pushnil(L);
            return 1;
        }
        BinaryReader br = new BinaryReader(fs);
        br.ReadInt32();
		br.ReadSingle();
		br.ReadSingle();
		br.ReadSingle();
        br.ReadSingle();
        br.ReadSingle();
        br.ReadSingle();
        int framecount = 0;
        StringBuilder sb = new StringBuilder(100000000);

        while (true)
        {
            int rc_type = br.ReadInt32();
            if (rc_type == 0)
            {
                if (fs.Position != fs.Length)
                    Debug.LogError("wrong proto file");
                break;
            }
            else if (rc_type == 1)
            {
                int type = br.ReadInt32();
                int datalen = br.ReadInt32();
                byte[] data = br.ReadBytes(datalen);
                float protime = br.ReadSingle();

                OctetsStream os = new OctetsStream();
                os.replace(data);
                GNET.CommonData proto = new GNET.CommonData(type, os);

                if (type == 34)
                {
                    Octets oc = proto.GetData().unmarshal_Octets();
                    MemoryStream mms = new MemoryStream(oc.buffer(), 0, oc.size());
                    BinaryReader br2 = new BinaryReader(mms);
                    UInt16 cmd_type = br2.ReadUInt16();
                    sb.Append(string.Format("    cmd = {0} time = {1}", cmd_type, (int)(protime * 1000)));
                    sb.Append("\r\n");
                }
                else
                {
                    if (type == 502)
                    {
                        sb.Append(string.Format("    ds = {0} time = {1}", proto.GetData().unmarshal_ushort(), (int)(protime * 1000)));
                        sb.Append("\r\n");
                    }
                    else
                    {
                        sb.Append(string.Format("    pro = {0} time = {1}", type, (int)(protime * 1000)));
                        sb.Append("\r\n");
                    }
                }
            }
            else if (rc_type == 2)
            {
                float frametime = br.ReadSingle();
                sb.Append(string.Format("frame {0} time = {1}", framecount++, (int)(frametime * 1000)));
                sb.Append("\r\n");
            }
            else if (rc_type == 3)
            {
                br.ReadSingle();
                br.ReadSingle();
                br.ReadSingle();
            }
            else
            {
                br.ReadSingle();
                br.ReadSingle();
                br.ReadSingle();
                br.ReadSingle();
                br.ReadSingle();
                br.ReadSingle();
            }
        }

        File.WriteAllText(EntryPoint.Instance.AssetsPath + "/protolog.txt", sb.ToString());
        return 0;
    }
Пример #3
0
    public static int ReadProtocol(IntPtr L)
    {
        if (proto_br == null)
        {
            UnityEngine.Debug.LogError("proto_br == null");
            return 0;
        }

        int type = proto_br.ReadInt32();
        int datalen = proto_br.ReadInt32();
        byte[] data = proto_br.ReadBytes(datalen);

        OctetsStream os = new OctetsStream();
        os.replace(data);
        GNET.CommonData proto = new GNET.CommonData(type, os);

        LuaStatic.addGameObject2Lua(L, proto, "userdata");
        LuaDLL.lua_pushinteger(L, type);
        return 2;
    }