static int Init(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        NetworkProfiler obj = (NetworkProfiler)LuaScriptMgr.GetNetObjectSelf(L, 1, "NetworkProfiler");

        obj.Init();
        return(0);
    }
Пример #2
0
    virtual public void Update(float fdeltaTime)
    {
        if (m_beginRead)
        {
            m_readTimeCounter += Time.deltaTime;
        }
        //登录服务器没有心跳机制,取消超时断线
        if (m_beginRead && m_readTimeCounter > m_iReceiveTimeout && m_type != Type.eLoginServer && m_type != Type.eVirtualServer)
        {
            Debug.Log("Disconnected: can not receive heartbeat data within: " + m_iReceiveTimeout + " sec.");
            m_serverDisconnectedFlag_Passive = true;
        }

        //m_curTime = Time.time;
        //lock (m_log)
        //{
        //    if (m_log.Length != 0)
        //    {
        //        Debug.Log(m_log);
        //        m_log = "";
        //    }
        //}

        //将网络消息缓存池中的数据放入待处理队列
        _msgCache.Clear();
        lock (m_MsgQueue)
        {
            if (m_MsgQueue.Count != 0)
            {
                _msgCache.AddRange(m_MsgQueue);
                m_MsgQueue.Clear();
            }
        }

        //没有看明白是干什么使用的,貌似只是个日志输出
        //if (m_type == Type.ePlatformServer || m_type == Type.eLoginServer)
        //{
        //    int countWithOutTimeTracer = _msgCache.FindAll(msg =>
        //    {
        //        MsgID msgID = (MsgID)msg.MessageID;
        //        return msgID != MsgID.TimeTracerID && msgID != MsgID.HeartbeatID;
        //    }).Count;
        //    if (countWithOutTimeTracer > 0)
        //    {
        //        Debug.Log("msg cnt: " + countWithOutTimeTracer);
        //        foreach (Pack pack in _msgCache)
        //        {
        //            Debug.Log("Msg:" + (MsgID)pack.MessageID);
        //        }
        //    }
        //}

        //if( (System.DateTime.Now.Ticks - now) * 0.0001f > 10.0f )
        //	Debug.LogError( "out lock .update : " + (System.DateTime.Now.Ticks - now) * 0.0001f );


        foreach (Pack pack in _msgCache)
        {
            m_handler.HandleMsg(pack);
        }

        if (m_profiler != null)
        {
            m_profiler.FixedUpdate(fdeltaTime);
        }

        if (m_handler != null)
        {
            m_handler.Update();
        }

        if (m_serverConnectedFlag)
        {
            if (m_type != Type.eVirtualServer)
            {
                m_stream = m_client.GetStream();
                AsyncRead();
                //m_recvMsgThread = new Thread(AsyncRead);
                //m_recvMsgThread.Name = m_strName + "_thread";
                //m_recvMsgThread.Start();
            }
            else
            {
                m_stream             = new MemoryStream();
                m_recvMsgThread      = new Thread(_Recv);
                m_recvMsgThread.Name = m_strName + "_thread";
                m_recvMsgThread.Start();
            }

            NotifyAllListener(NetworkEvent.connected);
            m_serverConnectedFlag = false;
            m_serverDisconnectedFlag_Initiative = false;
            m_serverDisconnectedFlag_Passive    = false;

            if (m_profiler != null)
            {
                m_profiler.Init();
            }
        }

        if (m_serverDisconnectedFlag_Passive)
        {
            NotifyAllListener(NetworkEvent.disconnected);
            m_serverDisconnectedFlag_Passive = false;
            m_readTimeCounter = 0.0f;
            m_beginRead       = false;
        }

        if (m_serverConnectFailedFlag)
        {
            NotifyAllListener(NetworkEvent.connectFail);
            m_serverConnectFailedFlag = false;
            m_readTimeCounter         = 0.0f;
            m_beginRead = false;
        }
    }
Пример #3
0
    virtual public void Update(float fdeltaTime)
    {
        if (m_type != Type.eVirtualServer && !m_client.Connected)
        {
            m_serverDisconnectedFlag_Passive = true;
        }
        m_curTime = Time.time;
        lock (m_log)
        {
            if (m_log.Length != 0)
            {
                Logger.Log(m_log);
                m_log = "";
            }
        }

        _msgCache.Clear();

        lock ( m_MsgQueue )
        {
            if (m_MsgQueue.Count != 0)
            {
                _msgCache.AddRange(m_MsgQueue);
                m_MsgQueue.Clear();
            }
        }

        //if( (System.DateTime.Now.Ticks - now) * 0.0001f > 10.0f )
        //	Logger.LogError( "out lock .update : " + (System.DateTime.Now.Ticks - now) * 0.0001f );


        foreach (Pack pack in _msgCache)
        {
            m_handler.HandleMsg(pack);
        }

        if (m_profiler != null)
        {
            m_profiler.FixedUpdate(fdeltaTime);
        }

        if (m_handler != null)
        {
            m_handler.Update();
        }

        if (m_serverConnectedFlag)
        {
            if (m_type != Type.eVirtualServer)
            {
                m_stream = m_client.GetStream();
                AsyncRead();
            }
            else
            {
                m_stream             = new MemoryStream();
                m_recvMsgThread      = new Thread(_Recv);
                m_recvMsgThread.Name = m_strName + "_thread";
                m_recvMsgThread.Start();
            }

            NotifyAllListener(NetworkEvent.connected);
            m_serverConnectedFlag = false;
            m_serverDisconnectedFlag_Initiative = false;
            m_serverDisconnectedFlag_Passive    = false;

            if (m_profiler != null)
            {
                m_profiler.Init();
            }
        }

        if (m_serverDisconnectedFlag_Passive)
        {
            NotifyAllListener(NetworkEvent.disconnected);
            m_serverDisconnectedFlag_Passive = false;
        }

        if (m_serverConnectFailedFlag)
        {
            NotifyAllListener(NetworkEvent.connectFail);
            m_serverConnectFailedFlag = false;
        }
    }