Ejemplo n.º 1
0
        /// <summary>
        /// 释放消息的同时调用
        /// </summary>
        /// <param name="msg"></param>
        protected void OnFreeMessage(Message msg)
        {
            //BinaryMessage binaryMessage = msg as BinaryMessage;
            //if (binaryMessage == null)
            //    return;

            //NetAdapter.Free(binaryMessage.mBlock);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 提前处理消息
 /// </summary>
 /// <param name="message"></param>
 protected virtual void OnDispatchMessage(Message message)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建消息时候处理
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="length"></param>
        protected void OnCreateMessage(Message msg, int length)
        {
            BinaryMessage binaryMessage = msg as BinaryMessage;
            if (binaryMessage == null)
                return;

            binaryMessage.mBlock = NetAdapter.Alloc(length - msg.HeadLength);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 派发消息
        /// </summary>
        /// <param name="lAdapterID"></param>
        /// <param name="msg"></param>
        protected void DispatchMessage(long lAdapterID, Message msg)
        {
            msg.AdapterId = lAdapterID;

            MessageHandler handler;
            mAllMessageHandler.TryGetValue(msg.MsgId, out handler);
            if (handler == null)
                return;

            handler(msg);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="net"></param>
        /// <param name="session"></param>
        /// <param name="msg"></param>
        /// <param name="Immediate"></param>
        public override void SendMessage(ENet net, object session, Message msg, bool Immediate = true)
        {
            NetAdapter adapter = GetAdapter(net, session);
            if (adapter == null)
                return;

            SendMessage(adapter.AdapterID, msg, Immediate);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="lAdapterID"></param>
        /// <param name="msg"></param>
        /// <param name="Immediate">true: 即刻发送; false: 等待发送</param>
        public override void SendMessage(long lAdapterID, Message msg, bool Immediate = true)
        {
            NetAdapter adapter = GetAdapter(lAdapterID);
            if (adapter == null)
                return;

            msg.SetByteArray(mWriteMessage);
            msg.DeconstructObj();

            MemBlock block = NetAdapter.SendAlloc(msg.GetWritePos());
            Buffer.BlockCopy(msg.GetBytes(), 0, block.GetBytes(), 0, msg.GetWritePos());
            adapter.PushSend(block);

            if (Immediate)
                ImmediateSendMessage(lAdapterID);

            //TerminalFunction.LogMessage(msg.MsgId);
        }