void cObjectTypeScript::Update()
{
	if (IsRun())
	{
		if (m_pParser->SkipTo("start"))
		{
			m_strToken=m_pParser->GetToken();
			if (m_strToken=="index")
			{
				m_unObjectTypeIndex = m_pParser->GetInteger();
			}
		}
		while (!m_pParser->IsFeof())
		{
			if (m_pParser->SkipTo("type"))
			{
				m_strToken=m_pParser->GetToken();
				g_pGameManager->RegisterObjectType(m_strToken,
					m_unObjectTypeIndex++);
			}
		}
		StopScript();

	}
}
int CSenceManager::svc(void)
{
	ACE_Message_Block* mb = NULL;
	ACE_Time_Value xtime;

	ACE_OS::sleep(1);

	while(IsRun())
	{
		mb = NULL;
		//xtime = ACE_OS::gettimeofday() + ACE_Time_Value(0, MAX_MSG_PUTTIMEOUT);
		if(getq(mb, 0) == -1)
		{
			OUR_DEBUG((LM_ERROR,"[CMessageService::svc] PutMessage error errno = [%d].\n", errno));
			m_blRun = false;
			break;
		}
		if (mb == NULL)
		{
			continue;
		}

		//处理消息
		_QueueMessage* pQueueMessage = *((_QueueMessage**)mb->base());
		if (! pQueueMessage)
		{
			OUR_DEBUG((LM_ERROR,"[CMessageService::svc] mb msg == NULL CurrthreadNo=[0]!\n"));
			m_objMessageBlockPool.Delete(mb);
			m_objMessagePool.Delete(pQueueMessage);
			continue;
		}

		ACE_hrtime_t tvBegin = ACE_OS::gethrtime();
		ProcessMessage(pQueueMessage);
		m_u4TimeCost += (uint32)(ACE_OS::gethrtime() - tvBegin);
		m_u4ProCount++;

		if(m_u4ProCount == 6000)
		{
			OUR_DEBUG((LM_ERROR,"[CMessageService::svc]m_u4ProCount = %d,m_u4TimeCost = %d!\n", m_u4ProCount, m_u4TimeCost));
		}

		m_objMessageBlockPool.Delete(mb);
		m_objMessagePool.Delete(pQueueMessage);
	}

	OUR_DEBUG((LM_INFO,"[CSenceManager::svc] svc finish!\n"));
	return 0;
}
Beispiel #3
0
int CMessageService::svc(void)
{
    ACE_Message_Block* mb = NULL;

    //稍微休息一下,等一下其他线程再如主循环
    ACE_Time_Value tvSleep(0, MAX_MSG_SENDCHECKTIME*MAX_BUFF_1000);
    ACE_OS::sleep(tvSleep);

    while(IsRun())
    {
        mb = NULL;

        //xtime = ACE_OS::gettimeofday() + ACE_Time_Value(0, MAX_MSG_PUTTIMEOUT);
        if(getq(mb, 0) == -1)
        {
            OUR_DEBUG((LM_ERROR,"[CMessageService::svc] PutMessage error errno = [%d].\n", errno));
            m_blRun = false;
            break;
        }

        if(mb == NULL)
        {
            continue;
        }

        while(m_emThreadState != THREAD_RUN)
        {
            //如果模块正在卸载或者重载,线程在这里等加载完毕(等1ms)。
            ACE_Time_Value tvsleep(0, 1000);
            ACE_OS::sleep(tvsleep);
        }

        CMessage* msg = *((CMessage**)mb->base());

        if(! msg)
        {
            OUR_DEBUG((LM_ERROR,"[CMessageService::svc] mb msg == NULL CurrthreadNo=[%d]!\n", m_u4ThreadID));
            continue;
        }

        this->ProcessMessage(msg, m_u4ThreadID);

		//使用内存池,这块内存不必再释放
    }

    OUR_DEBUG((LM_INFO,"[CMessageService::svc] svc finish!\n"));
    return 0;
}
Beispiel #4
0
void CQuiz::LoadScript()
{
	if( IsRun() )
		return;
	
	CLuaBase Lua;
	if( Lua.RunScript( "QuizEvent.lua" ) != 0 )
	{
		Error( "QuizEvent.lua Load Failed!!!" );
		exit(0);
	}
	m_bAuto						= static_cast<BOOL>( Lua.GetGlobalBool( "AutoMode" ) );
	m_nType						= static_cast<int>( Lua.GetGlobalNumber( "QuizType" ) );
	m_dwEntranceTime			= static_cast<DWORD>( Lua.GetGlobalNumber( "EntranceTime" ) );
#ifdef __WORLDSERVER
	m_nChannel					= static_cast<int>( Lua.GetGlobalNumber( "QuizChannel" ) );
	if( !m_nChannel )
		m_nChannel = g_uIdofMulti;

	Lua.GetGloabal( "tNPC" );
	Lua.PushNil();
	while( Lua.TableLoop( -2 ) )
	{
		m_sNPC.dwNPCId			= static_cast<DWORD>( CScript::GetDefineNum( Lua.GetFieldToString( -1, "strNPCId" ) ) );
		m_sNPC.strCharKey		= Lua.GetFieldToString( -1, "strCharKey" );
		m_sNPC.vPos.x			= static_cast<float>( Lua.GetFieldToNumber( -1, "xPos" ) );
		m_sNPC.vPos.y			= static_cast<float>( Lua.GetFieldToNumber( -1, "yPos" ) );
		m_sNPC.vPos.z			= static_cast<float>( Lua.GetFieldToNumber( -1, "zPos" ) );
		Lua.Pop( 1 );
	}
	Lua.Pop( 0 );

	m_dwWaitTime				= static_cast<DWORD>( Lua.GetGlobalNumber( "WaitTime" ) );
	m_dwQuestionTime			= static_cast<DWORD>( Lua.GetGlobalNumber( "QuestionTime" ) );
	m_dwAnswerTime				= static_cast<DWORD>( Lua.GetGlobalNumber( "AnswerTime" ) );
	m_dwWatchingZoneOpenTime	= static_cast<DWORD>( Lua.GetGlobalNumber( "WatchingZoneOpenTime" ) );
	m_dwCloseWaitTime			= static_cast<DWORD>( Lua.GetGlobalNumber( "CloseWaitTime" ) );
	m_dwPrizeItemId				= static_cast<DWORD>( CScript::GetDefineNum( Lua.GetGlobalString( "PrizeItemId" ) ) );
	m_nPrizeItemNum				= static_cast<int>( Lua.GetGlobalNumber( "PrizeItemNum" ) );
#endif // __WORLDSERVER
}
Beispiel #5
0
int CLogManager::Create_Log_Block(int nLogType, uint32* pMailID, const char* pTitle, va_list* ap, const char* fmt, int nfmtSize)
{
    //查看当前日志是否需要入库
    if (GetLogInfoByLogLevel(nLogType) < m_pServerLogger->GetCurrLevel())
    {
        //低于当前日志等级的全部忽略
        return 0;
    }

    //从日志块池里面找到一块空余的日志块
    m_Logger_Mutex.acquire();
    _LogBlockInfo* pLogBlockInfo = m_objLogBlockPool.GetLogBlockInfo();


    if (NULL == pLogBlockInfo)
    {
        OUR_DEBUG((LM_ERROR, "[CLogManager::WriteLog] m_objLogBlockPool is full!\n"));
        m_Logger_Mutex.release();
        return -1;
    }

    if (NULL != ap)
    {
        //文本数据
        ACE_OS::vsnprintf(pLogBlockInfo->m_pBlock, m_objLogBlockPool.GetBlockSize() - 1, fmt, *ap);
    }
    else
    {
        //二进制数据
        char szLog[10] = { '\0' };
        int nLen = nfmtSize;

        for (int i = 0; i < nLen; i++)
        {
            sprintf_safe(szLog, 10, "0x%02X ", (unsigned char)fmt[i]);
            sprintf_safe(pLogBlockInfo->m_pBlock + 5 * i, m_objLogBlockPool.GetBlockSize() - 5 * i, "%s", szLog);
        }

        pLogBlockInfo->m_u4Length = (uint32)(nLen * 5);
    }

    pLogBlockInfo->m_u4Length = (uint32)strlen(pLogBlockInfo->m_pBlock);
    pLogBlockInfo->m_u4LogID = (uint32)nLogType;

    if (NULL != pMailID && NULL != pTitle)
    {
        if (m_blIsMail == false)
        {
            pLogBlockInfo->m_u4MailID = 0;
        }
        else
        {
            pLogBlockInfo->m_u4MailID = *pMailID;
        }

        ACE_OS::snprintf(pLogBlockInfo->m_szMailTitle, MAX_BUFF_200, "%s", pTitle);
    }

    if (IsRun())
    {
        if (0 != PutLog(pLogBlockInfo))
        {
            OUR_DEBUG((LM_INFO, "[CLogManager::WriteToMail]PutLog error.\n"));
        }
    }
    else
    {
        m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo);
    }

    m_Logger_Mutex.release();

    return 0;
}
Beispiel #6
0
void CQuiz::MakeQuizList( QUIZLIST & QL )
{
	if( IsRun() )
		m_vecQuizList.push_back( QL );
}