Beispiel #1
0
        //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        byte[] INetMessageWriter.MakeStream(int msgID, byte[] data)
        {
            //
            for (int i = 0; i < 8; i++)
            {
                m_SessionByte[i] = (byte)(PingManager.Instance.sessionId >> (8 * (7 - i)));
            }

            //Debug.Log("sessionId: " + PingManager.Instance.sessionId);

            m_NotUseByte[0] = mCounter;
            m_Buffer.Clear();
            int net_msgID = IPAddress.HostToNetworkOrder(msgID);

            byte[] net_MsgID_byte = BitConverter.GetBytes(net_msgID);
            short  net_data_size  = (short)(sizeof(short) + net_MsgID_byte.Length + m_NotUseByte.Length + m_SessionByte.Length + (data != null ? data.Length : 0));

            net_data_size = IPAddress.HostToNetworkOrder(net_data_size);
            byte[] net_Data_Size_byte = BitConverter.GetBytes(net_data_size);
            m_Buffer.Write(net_Data_Size_byte, 0, net_Data_Size_byte.Length);
            m_Buffer.Write(net_MsgID_byte, 0, net_MsgID_byte.Length);
            m_Buffer.Write(m_NotUseByte, 0, m_NotUseByte.Length);
            m_Buffer.Write(m_SessionByte, 0, m_SessionByte.Length);
            mCounter++;
            if (data != null)
            {
                m_Buffer.Write(data, 0, data.Length);
            }
            return(m_Buffer.ToArray());
        }
        //private static UInt32  m_cmdSequece = 0;
        //private byte[] m_NotUseByte = new byte[4]{0,0,0,0};

        //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        //兼容新的golang服务器修改....
        byte[] INetMessageWriter.MakeStream(proto_header header, MemoryStream data)
        {
            m_Buffer.Clear();
            //m_cmdSequece ++;

            //先header初始化
            //header.uMsgContext = m_cmdSequece;
            header.iMsgBodyLen = proto_header.MODULE_HEAD_LENGTH + (data != null ?(int)data.Length : 0);
            int net_BodyLen = IPAddress.HostToNetworkOrder(header.iMsgBodyLen);

            byte[] net_BodyLen_byte = BitConverter.GetBytes(net_BodyLen);
            m_Buffer.Write(net_BodyLen_byte, 0, net_BodyLen_byte.Length);

            int net_msgID = IPAddress.HostToNetworkOrder(header.shMsgID);

            byte[] net_MsgID_byte = BitConverter.GetBytes(net_msgID);
            m_Buffer.Write(net_MsgID_byte, 0, net_MsgID_byte.Length);

            /*
             * int net_iSubCmdID = IPAddress.HostToNetworkOrder (header.iSubCmdID);
             * byte[] net_iSubCmdID_byte = BitConverter.GetBytes(net_iSubCmdID);
             *
             * int net_uMsgContext = IPAddress.HostToNetworkOrder ((int)header.uMsgContext);
             * byte[] net_uMsgContext_byte = BitConverter.GetBytes(net_uMsgContext);
             *
             * int net_iUin = IPAddress.HostToNetworkOrder ((int)header.iUin);
             * byte[] net_iUin_byte = BitConverter.GetBytes(net_iUin);
             *
             * int net_uHostTag = IPAddress.HostToNetworkOrder ((int)header.uHostTag);
             * byte[] net_uHostTag_byte = BitConverter.GetBytes(net_uHostTag);
             *
             * int net_uClientSeq = IPAddress.HostToNetworkOrder ((int)header.uClientSeq);
             * byte[] net_uClientSeq_byte = BitConverter.GetBytes(net_uClientSeq);*/

            //body
            //int net_data_size = proto_header.HEAD_LENGTH + (data != null ?(int)data.Length : 0);
            //byte[] net_Data_Size_byte = BitConverter.GetBytes(net_data_size);

            /*
             * m_Buffer.Write(net_iSubCmdID_byte,0,net_MsgID_byte.Length);
             * m_Buffer.Write(net_uMsgContext_byte,0,net_MsgID_byte.Length);
             * m_Buffer.Write(net_iUin_byte,0,net_MsgID_byte.Length);
             * m_Buffer.Write(net_uHostTag_byte,0,net_uHostTag_byte.Length);
             * m_Buffer.Write(net_uClientSeq_byte,0,net_uClientSeq_byte.Length);*/

            //body
            if (data != null)
            {
                m_Buffer.Write(data.GetBuffer(), 0, (int)data.Length);

                if (CNetWorkGlobal.Instance.IsDebug)
                {
                    Log.info(this, "[CNetStreamWriter][MakeStream] WritingHead , module head len : " + proto_header.MODULE_HEAD_LENGTH
                             + ",  stream len(not include length 4 bytes)  " + header.iMsgBodyLen);
                }
            }

            return(m_Buffer.ToArray());
        }