Exemplo n.º 1
0
 public bool DoMessage(string key, Protomsg.MsgBase msg)
 {
     if (m_Handler.ContainsKey(key))
     {
         return(m_Handler[key](msg));
     }
     return(true);
 }
Exemplo n.º 2
0
        public void SendMsg(Protomsg.MsgBase msg)
        {
            //UnityEngine.Debug.Log("msg:"+ msg.ToString());

            ByteBuf bb = new ByteBuf(msg.ToByteArray());

            this.Send(bb);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 超时
        /// </summary>
        protected override void HandleTimeout()
        {
            base.HandleTimeout();
            UnityEngine.Debug.Log("HandleTimeout");

            Protomsg.MsgBase msg = new Protomsg.MsgBase();
            msg.MsgType = "TimeOut";
            MsgManager.Instance.AddMessage(msg);
        }
Exemplo n.º 4
0
        public void SendHeartMsg()
        {
            Protomsg.MsgBase msg1 = new Protomsg.MsgBase();
            msg1.MsgType = "CS_Heart";
            ByteBuf bb = new ByteBuf(msg1.ToByteArray());

            //UnityEngine.Debug.Log("SendHeartMsg:"+ Tool.getMemory(this));
            this.Send(bb);

            m_SendHeartTime = Tool.GetTime();
        }
Exemplo n.º 5
0
 public void UpdateMessage()
 {
     while (true)
     {
         Protomsg.MsgBase msgobj = PopMessage();
         if (msgobj == null)
         {
             return;
         }
         if (DoMessage(msgobj.MsgType, msgobj) == false)
         {
             return;
         }
     }
 }
Exemplo n.º 6
0
        public void SendMsg(String modetype, String msgtype, IMessage msg)
        {
            Protomsg.MsgBase msg1 = new Protomsg.MsgBase();
            msg1.ModeType = modetype;
            msg1.MsgType  = msgtype;
            if (msg != null)
            {
                msg1.Datas = ByteString.CopyFrom(msg.ToByteArray());
            }


            ByteBuf bb = new ByteBuf(msg1.ToByteArray());

            this.Send(bb);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 异常
        /// </summary>
        protected override void HandleException(Exception ex)
        {
            base.HandleException(ex);
            UnityEngine.Debug.Log("-------HandleException" + ex.ToString());
            //UnityEngine.Debug.Log("HandleException:" + Tool.getMemory(this));
            Protomsg.CC_Disconnect msg = new Protomsg.CC_Disconnect();
            msg.Err = ex.ToString();

            Protomsg.MsgBase msg1 = new Protomsg.MsgBase();
            msg1.ModeType = "";
            msg1.MsgType  = "CC_Disconnect";
            if (msg != null)
            {
                msg1.Datas = ByteString.CopyFrom(msg.ToByteArray());
            }
            MsgManager.Instance.AddMessage(msg1);
        }
Exemplo n.º 8
0
        protected override void HandleReceive(ByteBuf bb)
        {
            IMessage IMperson = new Protomsg.MsgBase();

            Protomsg.MsgBase p1 = (Protomsg.MsgBase)IMperson.Descriptor.Parser.ParseFrom(bb.GetRaw());
            //UnityEngine.Debug.Log("HandleReceive:" + p1.MsgType);
            if (p1.MsgType == "SC_Heart")
            {
                //this.SendHeartMsg();
                var time = Tool.GetTime();
                PingValue = (int)Math.Floor((time - m_SendHeartTime) * 1000);
                //UnityEngine.Debug.Log("ping:"+ PingValue);
                return;
            }



            MsgManager.Instance.AddMessage(p1);
            //  UnityEngine.Debug.Log("MsgType:" + p1.MsgType+ "ModeType:" + p1.ModeType + "ConnectId:" + p1.ConnectId + "Uid:" + p1.Uid);
            //this.Send(bb.Copy());
        }