コード例 #1
0
ファイル: GameSocket.cs プロジェクト: hproof/notes
        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
ファイル: GameSocket.cs プロジェクト: hproof/notes
        //byte[] bufWrite = new byte[1024*16];
        // 写入头部信息
        public BinByteBufWriter WriteHead(uint lua_code, EncodeType enc_type)
        {
            if (App.config.trace_bin_sndrcv && (null != PBBase.CPBBase.g_pIPBLogger))
            {
                PBBase.CPBBase.g_pIPBLogger.WriteLog("INFO", "WriteHead",
                                                     string.Format("lua_code:{0}({1}) enc_type:{2}", lua_code, (OpCodes_C2S)lua_code, enc_type));
            }

            BinByteBufWriter bw = new BinByteBufWriter();
            bw.enableTraceBin(App.config.trace_encdec_detail);
            //bw.Init (bufWrite, 0, bufWrite.Length);
            if (4 == GetPkgHdrPkgSize())
            {
                bw.WriteUInt32(0);  // len
            }
            else
            {
                bw.WriteUInt16(0);  // len
            }
            bw.WriteUInt16((UInt16)lua_code); // lua code
            bw.WriteByte((byte)enc_type);//Network.GetEncodeTypeByte((int)enc_type,(int)lua_code));    // encode
            if (IsPkgHdrEnablePacketId())
            {
                bw.WriteUInt32((UInt32)0);   // packet_id
            }
            //包头不压缩
            bw.SetPBC(Network.IsPBCBinPkg(lua_code));

            return bw;
        }
コード例 #3
0
ファイル: GameSocket.cs プロジェクト: hproof/notes
        // 是否阻塞发送包
        //public bool BlockSend
        //{
        //    get { return _block_send; }
        //    set
        //    {
        //        if (_block_send != value)
        //        {
        //            _block_send = value;

        //            // send now 
        //            if (!_block_send && _send_list != null)
        //            {
        //                foreach (var br in _send_list)
        //                {
        //                    SendNow(br);
        //                }
        //                _send_list = null;
        //            }
        //        }
        //    }
        //}

        // 发送
        public void Send(BinByteBufWriter bw)
        {
            if (!IsConnected) return;

            // 发包阻塞
            //if (_block_send)
            //{
            //    if (_send_list == null) _send_list = new List<BinByteBufWriter>();
            //    Log.LogWarning("block send");
            //    _send_list.Add(bw);
            //}
            //else
            {
                SendNow(bw);
            }
        }
コード例 #4
0
ファイル: GameSocket.cs プロジェクト: hproof/notes
 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);
 }