Exemplo n.º 1
0
    public void     Process()
    {
        List <CMessage> tempList = null;

        lock (m_lock)
        {
            if (m_MessageList.Count > 0)
            {
                tempList      = m_MessageList;
                m_MessageList = new List <CMessage>();
            }
        }
        if (tempList != null)
        {
            for (int i = 0; i < tempList.Count; i++)
            {
                CMessage        msg = tempList[i];
                ushort          id  = msg.GetID();
                MessageCallback cb  = GetCallback((ushort)id);
                if (cb != null)
                {
                    //long nBegin = System.DateTime.Now.Ticks;
                    cb((ushort)id, ref msg);
                    //long nEnd = System.DateTime.Now.Ticks;
                    //SDGlobal.Log("process msg:" + id.ToString() + ", elapse:" + ((nEnd - nBegin)/10000L).ToString() + " ms");
                }
            }
        }
    }
Exemplo n.º 2
0
 public bool     Send(CMessage msg)
 {
     if (msg == null)
     {
         return(false);
     }
     if (msg.GetID() == 0xffff)
     {
         return(false);
     }
     if (m_bConnect)
     {
         CNetData data = SGDP.GetInstance().Encode(msg);
         if (data == null)
         {
             return(false);
         }
         //Debug.Log("Send=" + msg.GetType().ToString());
         if (!m_Send.Send(ref data))
         {
             Debug.Log("Send Message DisConnect");
             DisConnect();
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
    public CNetData Encode(CMessage msg)
    {
        ushort   id   = msg.GetID();
        CNetData data = new CNetData(4096);

        SGTMsgHeader head = new  SGTMsgHeader();

        head.wMsgID = id;
        head.Encode(data);

        EncoderFunc pfnEncode = FindEncodeFunc(id);

        if (null == pfnEncode)
        {
            return(null);
        }
        if (-1 == pfnEncode(msg, ref data))
        {
            return(null);
        }
        head.wDataLen  = (ushort)(data.GetDataLen() - 8);
        head.wCheckSum = (ushort)((head.wDataLen ^ 0xBBCC) & 0x88AA);
        data.Replace(0, BitConverter.GetBytes(CNetData.Inverse(head.wCheckSum)));
        data.Replace(4, BitConverter.GetBytes(CNetData.Inverse(head.wDataLen)));
        return(data);
    }