private bool GetPackage()
        {
            if (mParseStreamList.Length <= 0)
            {
                return(false);
            }

            NetPackage mNetPackage = new NetPackage();

            bool bSucccess = false;

            lock (mParseStreamList) {
                bSucccess = NetEncryptionStream.DeEncryption(mParseStreamList, mNetPackage);
            }

            if (bSucccess)
            {
                mLogicFuncDic [(UInt16)mNetPackage.command] (mNetPackage);
            }
            else
            {
                DebugSystem.LogError("服务器端 解码失败");
            }

            return(bSucccess);
        }
Ejemplo n.º 2
0
        public static bool DeEncryption(CircularBuffer <byte> data, NetPackage mPackage)
        {
            if (data.Length <= 8)
            {
                return(false);
            }

            for (int i = 0; i < 4; i++)
            {
                if (data [i] != mCheck [i])
                {
                    return(false);
                }
            }

            byte[] commandBytes = new byte[2];
            data.CopyTo(4, commandBytes, 0, 2);
            mPackage.command = BitConverter.ToUInt16(commandBytes, 0);

            byte[] bodyLengthBytes = new byte[2];
            data.CopyTo(6, bodyLengthBytes, 0, 2);
            UInt16 nBodyLength1 = BitConverter.ToUInt16(bodyLengthBytes, 0);

            if (nBodyLength1 < 0 || nBodyLength1 + 8 > data.Length)
            {
                return(false);
            }

            mPackage.buffer = new byte[nBodyLength1];
            data.CopyTo(8, mPackage.buffer, 0, nBodyLength1);
            data.ClearBuffer(nBodyLength1 + 8);
            return(true);
        }
        public SocketReceivePeer()
        {
            mWaitSendBuffer = new QueueArraySegment <byte> (64, ServerConfig.nMaxBufferSize);
            mNetPackage     = new NetPackage();

            mParseStreamList = new CircularBuffer <byte> (2 * ServerConfig.nMaxBufferSize);

            mLogicFuncDic = new Dictionary <ushort, Action <NetPackage> > ();
        }