Exemplo n.º 1
0
        public void SendCheckPackage(UInt16 id, byte[] buffer)
        {
            DebugSystem.Assert(id > 50, "Udp 系统内置命令 此逻辑不处理");

            int readBytes   = 0;
            int nBeginIndex = 0;

            UInt16 groupCount = 0;

            if (buffer.Length % ServerConfig.nUdpPackageFixedBodySize == 0)
            {
                groupCount = (UInt16)(buffer.Length / ServerConfig.nUdpPackageFixedBodySize);
            }
            else
            {
                groupCount = (UInt16)(buffer.Length / ServerConfig.nUdpPackageFixedBodySize + 1);
            }

            while (nBeginIndex < buffer.Length)
            {
                if (nBeginIndex + ServerConfig.nUdpPackageFixedBodySize > buffer.Length)
                {
                    readBytes = buffer.Length - nBeginIndex;
                }
                else
                {
                    readBytes = ServerConfig.nUdpPackageFixedBodySize;
                }

                NetUdpFixedSizePackage mPackage = ObjectPoolManager.Instance.mUdpFixedSizePackagePool.Pop();
                mPackage.nGroupCount = groupCount;
                mPackage.nPackageId  = id;
                mPackage.nOrderId    = nCurrentWaitSendOrderId;
                mPackage.Length      = readBytes + ServerConfig.nUdpPackageFixedHeadSize;
                Array.Copy(buffer, nBeginIndex, mPackage.buffer, ServerConfig.nUdpPackageFixedHeadSize, readBytes);

                NetPackageEncryption.Encryption(mPackage);
                AddSendCheck(mPackage);

                AddSendPackageOrderId();
                nBeginIndex += readBytes;
                groupCount   = 1;
            }
        }
Exemplo n.º 2
0
        public void ReceiveUdpSocketFixedPackage(NetUdpFixedSizePackage mPackage)
        {
            bool bSucccess = NetPackageEncryption.DeEncryption(mPackage);

            if (bSucccess)
            {
                if (mPackage.nPackageId > 50)
                {
                    mUdpCheckPool.ReceiveCheckPackage(mPackage);
                }
                else
                {
                    PackageManager.Instance.Execute(this as ClientPeer, mPackage);
                }
            }
            else
            {
                throw new Exception("解码失败 !!!");
            }
        }
        public NetUdpFixedSizePackage GetUdpSystemPackage(UInt16 id, object data)
        {
            DebugSystem.Assert(id <= 50, "不是 Udp 系统内置命令");

            IMessage data1 = data as IMessage;

            byte[] stream = Protocol3Utility.SerializePackage(data1);

            var mPackage = ObjectPoolManager.Instance.mUdpFixedSizePackagePool.Pop();

            mPackage.nOrderId    = 0;
            mPackage.nGroupCount = 0;
            mPackage.nPackageId  = id;
            mPackage.Length      = stream.Length + ServerConfig.nUdpPackageFixedHeadSize;
            Array.Copy(stream, 0, mPackage.buffer, ServerConfig.nUdpPackageFixedHeadSize, stream.Length);

            NetPackageEncryption.Encryption(mPackage);

            return(mPackage);
        }