Ejemplo n.º 1
0
    //缓存中有数据处理
    public static void onData()
    {
        //长度解码
        byte[] result = decode(ref cache);

        //长度解码返回空 说明消息体不全,等待下条消息过来补全
        if (result == null)
        {
            isReading = false;
            return;
        }

        //decode方法反编message

        byte[] message = messageDecode(result);

        // 这里开始解析之前的值
        read(message);

        LuaManager.AddEvent(new ByteArray(message));

        if (message == null)
        {
            isReading = false;
            return;
        }

        //尾递归 防止在消息处理过程中 有其他消息到达而没有经过处理
        onData();
    }
Ejemplo n.º 2
0
    public static void read(byte[] message)
    {
        // 改为在CSharp里面解析
        ByteArray array = new ByteArray(message);

        /*
         * 序号 字节  字节数 类型     意义     描述
         *  0  0000    4   Int     0       包大小 后接12个字节
         *  4  00      2   Short   TP
         *  6  0       1   Byte    1
         *  7  00      2   Short   gameID
         *  9  0000    4   Int     cmd
         *  13 00      2   Short   subCmd
         *  15 0       1   Byte    0
         */
        array.SetPosition(4);
        byte T = array.ReadByte();
        byte P = array.ReadByte();

        byte[] TPByte   = new byte[] { T, P };
        string TPString = System.Text.Encoding.ASCII.GetString(TPByte);

        if (TPString.Equals("TP"))
        {
            array.SetPosition(7);
            int gid = array.ReadShort();
            int cmd = array.ReadInt();

            int len = array.Length - 16;
            array.SetPosition(16);
            if (len >= 4)
            {
                int    protoBufLen  = array.ReadInt();
                byte[] protoBufData = array.ReadBuffer(protoBufLen - 1);

                LuaManager.AddEvent(cmd, protoBufData);

                // if (cmd.Equals(0x101))
                // {
                //     SendTableInfo info = SendTableInfo.Parser.ParseFrom(protoBufData);
                //     Debug.Log(info);
                // }
                // if (FishingGameControl.Instance)
                // {
                //     FishingGameControl.Instance.addServerLister(cmd, protoBufData);
                // }
            }
        }
    }