Пример #1
0
        void SendNow(BinByteBufWriter bw)
        {
            _send_packet_id++;
            if (NetConstant.PROFILE_ENABLE_C2P_PKG_SEQ)
            {
                //尾巴补充包id
                bw.nonPBCWriteUInt(_send_packet_id);
            }

            PBAssert.AssertTrue(bw.GetLength() < NetConstant.MAX_SMALL_PKG_SIZE);

            // 写入长度信息
            if (4 == GetPkgHdrPkgSize())
            {
                uint iLen = (uint)bw.GetLength();
                bw.SetUInt32(0, iLen);
            }
            else
            {
                UInt16 iLen = (UInt16)bw.GetLength();
                bw.SetUInt16(0, iLen);
            }

            // 写入包 ID
            if (IsPkgHdrEnablePacketId())
            {
                bw.SetUInt32(GetPacketIdOffset(), (UInt32)(_send_packet_id));   // packet_id
            }


            if (App.config.trace_bin_sndrcv && (null != PBBase.CPBBase.g_pIPBLogger))
            {
                ushort opcode = 0;
                if (bw.GetLength() > GetOpCodeOffset())
                {
                    bw.GetUInt16(GetOpCodeOffset(), ref opcode);
                }
                string strTxt = "";
                PBBase.CPBBase.Bin2Txt(bw.GetBuffer(), 0, bw.GetLength(), ref strTxt);

                string strMsg = string.Format("SendBin opcode:{0}({1}) Len:{2} Txt:{3}",
                                            opcode, (OpCodes_C2S)opcode, bw.GetLength(), strTxt);
                PBBase.CPBBase.g_pIPBLogger.WriteLog("INFO", "SendBin", strMsg);
            }

            EncryptPkg(bw.GetBuffer(), (uint)bw.GetLength());

            // 发送
            base.Send(bw.GetBuffer(), (int)bw.GetLength());

            // 记录发包时间
#if !PING_HAS_RET
            UInt16 lua_code = 0;
            bw.GetUInt16(GetOpCodeOffset(), ref lua_code);
            if (lua_code >= 10)
#endif
            {
                time_last_send = Time.unscaledTime;
            }

        }
Пример #2
0
 public void SendProbuf(uint lua_code, BinByteBufWriter bwData, Type tp)
 {
     BinByteBufWriter bw = null;
     bw = WriteHead(lua_code, EncodeType.ProBuf);
     if (bwData.GetLength() > 0) bw.WriteBytes(bwData.GetBuffer(), bwData.GetLength(), 0);
     Send(bw);
 }