Пример #1
0
 private void OnError(IChannelPipeline obj)
 {
     if (this.ErrorCallBack == null)
     {
         return;
     }
     //当前不是主线程,,得添加到loom中
     Loom.QueueOnMainThread(() =>
     {
         ErrorCallBack.Invoke(obj);
     });
 }
Пример #2
0
        private void OnHandShake(IChannelPipeline pipe)
        {
            Debug.Log(string.Format("channel {0} 握手成功", pipe.Channel.Options.Name));

            if (this.HandShakeCallBack == null)
            {
                return;
            }
            //当前不是主线程,,得添加到loom中
            Loom.QueueOnMainThread(() =>
            {
                HandShakeCallBack.Invoke(pipe);
            });
        }
Пример #3
0
        //先检查消息id的回调是否存在.
        //如果不存在则调用action
        private void OnRead(IChannelPipeline pipe, IResponseMessage message)
        {
            var channelName = pipe.Channel.Options.Name;
            var msg         = message as ResponseMessagePacket;

            if (this.ReadCallBack != null)
            {
                //当前不是主线程,,得添加到loom中
                Loom.QueueOnMainThread(() =>
                {
                    ReadCallBack.Invoke(pipe, msg);
                });
            }

            GameAction action;

            if (this.SendActions.ContainsKey(msg.MessageID))
            {
                action = this.SendActions[msg.MessageID];
                this.SendActions.Remove(msg.MessageID);
            }
            else
            {
                action = ActionFactory.CreateAction.Invoke(channelName, msg.ContractID);
            }
            if (action != null)
            {
                if (msg.StateCode == 200)
                {
                    action.Handler(msg.BodyContent);
                    return;
                }
                action.HandlerError(new ErrorInfo()
                {
                    StateCode = msg.StateCode,
                    MsgId     = msg.MessageID
                });
            }
        }