コード例 #1
0
    private void _processMessageData()
    {
        Debugger.Assert(__nMsgLength != 0);

        bool bNeedFurtherProcessing = _pConnectionHost.ReceivingFilter(__receiveBuffer, __nMsgLength);

        if (!bNeedFurtherProcessing)
        {
            return;
        }

        /// Mono has a bug on AES. Must recreate transform object each time.
        if (_pDecryptor != null)
        {
            _pDecryptor.Dispose();
        }
        _pDecryptor = _pAESMgr.CreateDecryptor();

        /// Check AES blocks size
        Debugger.Assert((__nMsgLength - MsgBase.HEAD_LENGTH) % 16 == 0);

        byte[] bytesDecoded = _pDecryptor.TransformFinalBlock(__receiveBuffer, MsgBase.HEAD_LENGTH
                                                              , __nMsgLength - MsgBase.HEAD_LENGTH);

        ByteBuffer pByteBuffer = new ByteBuffer(bytesDecoded);

        //get message meta
        byte   encodeType = pByteBuffer.FReadByte();
        int    nMessageID = pByteBuffer.FReadInt();
        ushort sCheckCode = pByteBuffer.FReadUShort();
        int    nTimestamp = pByteBuffer.FReadInt();

        //get message body
        byte[] bodyBytes = pByteBuffer.FReadBytes(pByteBuffer.size - MsgBase.META_DATA_LENGTH);

        Debugger.Assert(_pConnectionHost.ContainsServerMsgID(nMessageID));

        ///...Debugger.Assert(_isValidMsgFormat());

        if (nMessageID == SERVER_SESSION_UPDATE_KEY)
        {
            /// Update local time stamp
            _nLastSvrTime   = nTimestamp;
            _nLastLocalTime = NetworkStub.CurrentTimeSeconds();

            /// process session key
            _onUpdateSessionKey(bodyBytes);
        }
        else
        {
            /// Process normal message
            MsgBase message = new MsgBase(nMessageID);
            message.timeStamp = nTimestamp;
            Debugger.Assert(message.type != SERVER_SESSION_UPDATE_KEY);

            message.DeserializeFrom(bodyBytes);

            __receiveMsgQueue.Add(message);
        }
    }
コード例 #2
0
 /// Get evaluated server time.
 public int EvaluateSvrTime()
 {
     //Debugger.Assert(_connectionState == ConnectionState.VALIDATED);
     return(_nLastSvrTime + (NetworkStub.CurrentTimeSeconds() - _nLastLocalTime));
 }