Esempio n. 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);
        }
    }
Esempio n. 2
0
        public Core()
        {
            this.shell    = new ShellStub();
            this.registry = new RegistryStub();
            this.storage  = new StorageStub();
            this.network  = new NetworkStub();

            Container.Shell    = this.shell;
            Container.Registry = this.registry;
            Container.Storage  = this.storage;
            Container.Network  = this.network;
        }
Esempio n. 3
0
    public static ByteBuffer BuildMessageBody(byte[] arrBody, int nMessageID, int nTimeStamp)
    {
        ByteBuffer pBuffer = new ByteBuffer(arrBody.Length + MsgBase.META_DATA_LENGTH);

        ushort sCheckCode     = NetworkStub.GetCheckCode(arrBody);
        byte   byteEncodeType = MsgBase.MESSAGE_ENCODE_TYPE_JSON;

        pBuffer.WriteByte(byteEncodeType);
        pBuffer.WriteInt(nMessageID);
        pBuffer.WriteUShort((ushort)sCheckCode);
        pBuffer.WriteInt(nTimeStamp);
        pBuffer.WriteBytes(arrBody);

        return(pBuffer);
    }
Esempio n. 4
0
 /// Get evaluated server time.
 public int EvaluateSvrTime()
 {
     //Debugger.Assert(_connectionState == ConnectionState.VALIDATED);
     return(_nLastSvrTime + (NetworkStub.CurrentTimeSeconds() - _nLastLocalTime));
 }