Ejemplo n.º 1
0
bool SFCasualGameDispatcher::ShutDownLogicSystem()
{
	m_bLogicEnd = true;

	BasePacket* pCommand = PacketPoolSingleton::instance()->Alloc();
	pCommand->SetSerial(-1);
	pCommand->SetPacketType(SFPACKET_SERVERSHUTDOWN);
	LogicGatewaySingleton::instance()->PushPacket(pCommand);

	return true;
}
Ejemplo n.º 2
0
bool SFEngine::OnDisconnect(int serial, _SessionDesc& desc)
{
	BasePacket* pPacket = new BasePacket();
	pPacket->SetSessionDesc(desc);
	pPacket->SetPacketType(SFPACKET_DISCONNECT);
	pPacket->SetSerial(serial);

	m_pLogicDispatcher->Dispatch(pPacket);
	
	return true;
}
Ejemplo n.º 3
0
bool SFEngine::OnTimer(const void *arg)
{
	UNREFERENCED_PARAMETER(arg);

	BasePacket* pPacket = new BasePacket();
	pPacket->SetPacketType(SFPACKET_TIMER);
	pPacket->SetSerial(-1);

	m_pLogicDispatcher->Dispatch(pPacket);

	return true;
}
Ejemplo n.º 4
0
bool SFEngine::OnTimer(const void *arg)
{
	int timerId = (int)arg;

	BasePacket* pPacket = new BasePacket();
	pPacket->SetPacketType(SFPACKET_TIMER);
	pPacket->SetSerial(timerId);

	m_pLogicDispatcher->Dispatch(pPacket);

	return true;
}
Ejemplo n.º 5
0
BOOL SGBattle::BroadCast(BasePacket& packet)
{
	SFRoom* pRoom = GetOwner()->GetOwner();
	auto& roomMember = pRoom->GetRoomMemberMap();
	
	for (auto& iter : roomMember)
	{
		SFPlayer* pPlayer = iter.second;
		packet.SetSerial(pPlayer->GetSerial());

		SFEngine::GetInstance()->SendRequest(&packet);
	}

	return TRUE;
}
Ejemplo n.º 6
0
	bool SFNETDispatcher::ShutDownLogicSystem()
	{
		m_bLogicEnd = true;

		for (int i = 0; i < m_nLogicThreadCnt; i++)
		{
			BasePacket* pCommand = PacketPoolSingleton::instance()->Alloc();
			pCommand->SetSerial(-1);
			pCommand->SetPacketType(SFPACKET_SERVERSHUTDOWN);
			LogicGatewaySingleton::instance()->PushPacket(pCommand);			
		}

		ACE_Thread_Manager::instance()->wait_grp(m_logicThreadGroupId);

		LogicEntrySingleton::instance()->DestroyLogic();		

		return true;
	}
Ejemplo n.º 7
0
BOOL SFDirectoryWatcherTask::ProcessShouterTask()
{
	m_Shouter.Initialize();
	m_Shouter.Read(_T("Shouter.xml"));
	_ShouterInfo* pInfo = m_Shouter.GetShouterInfo();

	if(pInfo->SentenceList.size() == 0)
		return FALSE;

	for(int i = 0; i < pInfo->RepeatCount; i++)
	{
		std::list<std::wstring>::iterator iter = pInfo->SentenceList.begin();


		if(i != 0)
			Sleep(pInfo->MessageInterval);

		DWORD Count = 0;

		for(;iter != pInfo->SentenceList.end(); iter++)
		{
			if(Count != 0)
				Sleep(pInfo->SentenceInterval);
 
			BasePacket* pCommand = new BasePacket();
			pCommand->SetPacketType(SFPACKET_SHOUTER);
			pCommand->SetSerial(-1);			

			LogicGatewaySingleton::instance()->PushPacket(pCommand);

#ifdef _DEBUG
			_tprintf( _T("Shout : %s\n"), iter->c_str());
#endif

			Count++;
		}
	}

	return TRUE;
}
Ejemplo n.º 8
0
bool SFMultiLogicDispatcher::ShutDownLogicSystem()
{
    BasePacket* pCommand = SFPacketPool::GetInstance()->Alloc();
    pCommand->SetSerial(-1);
    pCommand->SetPacketType(SFPACKET_SERVERSHUTDOWN);
    SFLogicGateway::GetInstance()->PushPacket(pCommand);

    if (m_packetDistrubutor->joinable())
        m_packetDistrubutor->join();

    for (auto& thread : m_mapThread)
    {
        tthread::thread* pThread = thread.second;
        if (pThread->joinable())
        {
            pThread->join();
            delete pThread;
        }
    }

    m_mapThread.clear();

    for (auto& queue : m_mapQueue)
    {
#ifdef _WIN32
        SFIOCPQueue<BasePacket>* pQueue = queue.second;
#else
        SFLockQueue<BasePacket>* pQueue = queue.second;
#endif
        delete pQueue;
    }

    m_mapQueue.clear();

    LogicEntry::GetInstance()->Destroy();

    return true;
}
Ejemplo n.º 9
0
void SFMultiLogicDispatcher::PacketDistributorProc(void* Args)
{
    SFMultiLogicDispatcher* pDispatcher = static_cast<SFMultiLogicDispatcher*>(Args);

    while (true)
    {
        BasePacket* pPacket = SFLogicGateway::GetInstance()->PopPacket();

        if (pPacket->GetPacketType() == SFPACKET_CONNECT)
        {
            pDispatcher->RegisterClient(pPacket);
        }

        if (pPacket->GetPacketType() == SFPACKET_TIMER)
        {
            for (auto& iter : pDispatcher->m_mapQueue)
            {
#ifdef _WIN32
                SFIOCPQueue<BasePacket>* pQueue = iter.second;
#else
                SFLockQueue<BasePacket>* pQueue = iter.second;
#endif
                pQueue->Push(pPacket);
//일단 한스레드에만 패킷을 넘기고 전체 로직 스레드에게 타이머 패킷을 보낼 수 있도록 나중에 수정한다
                break;
            }
        }
        else if (pPacket->GetPacketType() == SFPACKET_SERVERSHUTDOWN)
        {
            for (auto& queue : pDispatcher->m_mapQueue)
            {
                BasePacket* pCommand = SFPacketPool::GetInstance()->Alloc();
                pCommand->SetSerial(-1);
                pCommand->SetPacketType(SFPACKET_SERVERSHUTDOWN);

#ifdef _WIN32
                SFIOCPQueue<BasePacket>* pQueue = queue.second;
#else
                SFLockQueue<BasePacket>* pQueue = queue.second;
#endif
                pQueue->Push(pCommand);
            }

            break;
        }
        else
        {
            ClientInfo* pInfo = pDispatcher->FindClient(pPacket->GetSerial());

            if (pInfo != nullptr)
            {
                const auto& iter = pDispatcher->m_mapQueue.find(pInfo->channel);

                if (iter != pDispatcher->m_mapQueue.end())
                {
#ifdef _WIN32
                    SFIOCPQueue<BasePacket>* pQueue = iter->second;
#else
                    SFLockQueue<BasePacket>* pQueue = iter->second;
#endif
                    pQueue->Push(pPacket);
                }
                else
                {
                    LOG(WARNING) << "Invalid Channel Num : " << pInfo->channel;
                    ReleasePacket(pPacket);
                }
            }
            else
            {
                LOG(WARNING) << "ClientInfo NULL : " << pPacket->GetSerial();
            }
        }

        if (pPacket->GetPacketType() == SFPACKET_DISCONNECT)
        {
            pDispatcher->UnregisterClient(pPacket);
        }
    }
}