示例#1
0
    /// <summary>
    /// 解析网络数据
    /// </summary>
    /// <param name="buffer"></param>
    public void OnUdpMessage(CReadPacket buffer)
    {
        if (buffer == null)
        {
            return;
        }
        uint protocol = buffer.GetMessageID();
        Dictionary <string, object> data = buffer.data;

        switch (protocol)
        {
        case NetProtocol.SYNC_KEY:
            GameData.m_GameManager.SyncKey(data);
            GameData.m_GameManager.UpdateUdpGame();
            break;

        case NetProtocol.START:
            GameData.m_IsGame = true;
            GameData.m_GameManager.m_UIManager.m_UpdateBattleUICallback();
            object[] playerObj = data["info"] as object[];
            GameData.m_GameManager.CreateAllPlayer(playerObj);
            break;

        default:
            break;
        }
    }
示例#2
0
    /// <summary>
    /// 解析网络数据
    /// </summary>
    /// <param name="buffer"></param>
    public void OnTcpMessage(CReadPacket buffer)
    {
        if (buffer == null)
        {
            return;
        }
        uint protocol = buffer.GetMessageID();
        Dictionary <string, object> data = buffer.data;

        switch (protocol)
        {
        case NetProtocol.LOGIN_RET:
            GameData.m_GameManager.LoginGame(data);
            break;

        case NetProtocol.MATCH_RET:
            GameData.m_GameManager.MatchGame(data);
            break;

        case NetProtocol.MATCH_SUCCESS_RET:
            GameData.m_GameManager.MatchGameSuccess(data);
            break;

        case NetProtocol.MATCH_JOIN_ROOM_RET:
            GameData.m_GameManager.JoinMatchRoom(data);
            break;

        case NetProtocol.MATCH_HERO_ROOM_RET:
            GameData.m_GameManager.JoinMatchHeroRoom(data);
            break;

        case NetProtocol.MATCH_JOIN_ROOM_IN_POSTION:
            GameData.m_GameManager.JoinMatchRoomInPos(data);
            break;

        default:
            break;
        }
    }
示例#3
0
    //private bool mlock = false;
    //void Lock()
    //{
    //    mlock = true;
    //}
    //void UnLock()
    //{
    //    mlock = false;
    //}
    //public bool GetLock()
    //{
    //    return mlock;
    //}

    public void ReceiveByte(byte[] bData, int nLength)
    {
        // if (!GetLock())
        {
            if (bData != null && nLength > 0)
            {
                GameLibrary.isSendPackage = false;
                // Debug.Log("收到服务器回复消息更改状态     " + GameLibrary.isSendPackage + "  " + nLength);
                if (Singleton <SceneManage> .Instance.Current == EnumSceneID.UI_MajorCity01 || Globe.isFightGuide)
                {
                    if (Control.GetUIObject(UIPanleID.UIWaitForSever) != null)
                    {
                        Control.HideGUI(UIPanleID.UIWaitForSever);
                    }
                }
                if ((m_nbyteDataLength + nLength) > DataDefine.MAX_PACKET_SIZE)
                {
                    Debug.Log("error! the packet is too large,more than " + DataDefine.MAX_PACKET_SIZE);
                    Debug.Log("m_nbyteDataLength:" + m_nbyteDataLength);
                    Debug.Log("nReceiveLen:" + m_nbyteDataLength + "---" + nLength);
                    //Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                    //m_nbyteDataLength = 0;
                    Debug.Log("ReadPacket's length too large! ");
                    return;
                }

                Array.Copy(bData, 0, m_byteDataList, m_nbyteDataLength, nLength);
                m_nbyteDataLength += nLength;

                while (true)
                {
                    // Lock();
                    if (m_nbyteDataLength == 0)
                    {
                        //Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                        //m_nbyteDataLength = 0;
                        //Debug.Log("ReadPacket's length ");
                        // UnLock();
                        return;
                    }
                    else if (m_nbyteDataLength < m_sPacketMinLength)
                    {
                        Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                        m_nbyteDataLength = 0;
                        Debug.Log("ReadPacket's length ");
                        // UnLock();
                        return;
                    }

                    //				Debug.Log("m_nbyteDataLength:"+m_nbyteDataLength);
                    //				Debug.Log("nReceiveLen:"+nLength);
                    //handle
                    CReadPacket readPacket = new CReadPacket(m_byteDataList);
                    if (m_nbyteDataLength >= readPacket.GetPacketLen())
                    {
                        //  Profiler.maxNumberOfSamplesPerFrame =
                        // Debug.Log(Profiler.maxNumberOfSamplesPerFrame);
                        CHandleMgr.Handle hHandle = GetHandle(readPacket.GetMessageID());

                        string logString = "Receive msgid:" + readPacket.GetMessageID() + readPacket.GetLogMessageID() + " Lens:" + readPacket.GetPacketLen();
                        // Debug.Log(hHandle);
                        if (hHandle != null)
                        {
                            GameLibrary.Instance().PackedCount = 0;
                            if (msgDishandled.Count == 0 || !msgDishandled.Contains(readPacket.GetMessageID()))
                            {
                                //Dictionary<string, object> data = readPacket.data;
                                //if (data.ContainsKey("ret"))
                                //{
                                //    int resolt = int.Parse(data["ret"].ToString());
                                //    if (resolt == 0)
                                //    {
                                bool isTrue = hHandle(readPacket);
                                if (isTrue)
                                {
                                    Singleton <Notification> .Instance.ReceiveMessageList(readPacket.GetMessageID());
                                }
                                //    }
                                //    else
                                //    {
                                //        if (data.ContainsKey("desc"))
                                //        {
                                //            Debug.Log(data["desc"].ToString());
                                //        }

                                //    }
                                //}
                                //else
                                //{
                                //    hHandle(readPacket);
                                //}



                                logString += " Handle:" + hHandle.Target.GetType() + "." + hHandle.Method.Name + " Time:" + Time.realtimeSinceStartup;
                            }
                        }
                        else
                        {
                            logString += " No handle attach";
                        }
                        if (DataDefine.isLogMsg && DataDefine.filterWalkMsg(readPacket.GetMessageID()))
                        {
                            Debug.Log(logString);
                        }

                        //clear
                        int nNewLen = m_nbyteDataLength - readPacket.GetPacketLen();
                        if (nNewLen > 0)
                        {
                            byte[] bTempData = new byte[nNewLen];
                            Array.Copy(m_byteDataList, readPacket.GetPacketLen(), bTempData, 0, nNewLen);
                            Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                            Array.Copy(bTempData, 0, m_byteDataList, 0, nNewLen);
                        }
                        else
                        {
                            Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                        }
                        m_nbyteDataLength = nNewLen;
                    }
                    else
                    {
                        // UnLock();
                        break;
                    }
                    // UnLock();
                }
            }
        }
    }
示例#4
0
    public void ReceiveByte(byte [] bData, int nLength)
    {
        if (bData != null && nLength > 0)
        {
            //GameLibrary.isSendPackage = false;
            //Debug.Log( "收到服务器回复消息更改状态     " + GameLibrary.isSendPackage );
            //if ( Application.loadedLevelName == "UI_MajorCity" )
            //{
            //    Control.HideGUI( GameLibrary.UIWaitForSever );
            //}
            if ((m_nbyteDataLength + nLength) > DataDefine.MAX_PACKET_SIZE)
            {
                Debug.Log("error! the packet is too large,more than " + DataDefine.MAX_PACKET_SIZE);
                Debug.Log("m_nbyteDataLength:" + m_nbyteDataLength);
                Debug.Log("nReceiveLen:" + nLength);
                //Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                //m_nbyteDataLength = 0;
                Debug.Log("ReadPacket's length too large! ");

                return;
            }

            Array.Copy(bData, 0, m_byteDataList, m_nbyteDataLength, nLength);
            m_nbyteDataLength += nLength;

            while (true)
            {
                if (m_nbyteDataLength < m_sPacketMinLength)
                {
                    Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                    m_nbyteDataLength = 0;
                    Debug.Log("ReadPacket's length ");
                    return;
                }

                //				Debug.Log("m_nbyteDataLength:"+m_nbyteDataLength);
                //				Debug.Log("nReceiveLen:"+nLength);
                //handle
                CReadPacket readPacket = new CReadPacket(m_byteDataList);
                if (m_nbyteDataLength >= readPacket.GetPacketLen())
                {
                    Debug.Log("Receive Handle msgid:" + readPacket.GetMessageID() + "lens:" + readPacket.GetPacketLen());
                    WalkHandleMgr.Handle hHandle = GetHandle(readPacket.GetMessageID());
                    Debug.Log(hHandle);
                    if (hHandle != null)
                    {
                        hHandle(readPacket);
                    }
                    else
                    {
                        Debug.Log("No handle attach:" + readPacket.GetMessageID());
                    }
                    //clear
                    int len     = readPacket.GetPacketLen();
                    int nNewLen = m_nbyteDataLength - readPacket.GetPacketLen();
                    if (nNewLen > 0)
                    {
                        byte [] bTempData = new byte [nNewLen];
                        Array.Copy(m_byteDataList, readPacket.GetPacketLen(), bTempData, 0, nNewLen);
                        Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                        Array.Copy(bTempData, 0, m_byteDataList, 0, nNewLen);
                    }
                    else
                    {
                        Array.Clear(m_byteDataList, 0, DataDefine.MAX_PACKET_SIZE);
                    }
                    m_nbyteDataLength = nNewLen;
                }
                else
                {
                    break;
                }
            }
        }
    }