void SFMulitiCasualGameDispatcher::Dispatch(BasePacket* pPacket)
{		
	ISession* pSession = pPacket->GetSessionDesc().pSession;

	switch (pPacket->GetPacketType())
	{
	case SFPACKET_CONNECT:
	{
#ifdef _DEBUG
		pSession->SetLoginState(SESSION_STATE_AUTENTICATE);
		pSession->m_channelNum = 1;
		SFPacket* pkt = PacketPoolSingleton::instance()->Alloc();
		pkt->SetPacketType(SFPACKET_DATA);
		pkt->SetSerial(pPacket->GetSerial());
		pkt->SetPacketID(12345);
		pkt->SetSessionDesc(pPacket->GetSessionDesc());

		DistributePacket(pkt);
#else
		pSession->SetLoginState(SESSION_STATE_CONNECT);		
#endif
		ReleasePacket(pPacket);
	}
		return;
	case SFPACKET_DISCONNECT:
	{
		if (pSession->GetLoginState() == SESSION_STATE_AUTENTICATE)
		{
			DistributePacket(pPacket);
		}
		
		return;
	}
	case SFPACKET_DATA:
		if (pSession->GetLoginState() == SESSION_STATE_AUTENTICATE)
			DistributePacket(pPacket);		
		else if (pSession->GetLoginState() == SESSION_STATE_CONNECT)
		{
			if (true == OnAuthenticate(pPacket))
			{
				pSession->m_channelNum = 1;
				pSession->SetLoginState(SESSION_STATE_AUTENTICATE);
			}
			else
			{
				pSession->SetLoginState(SESSION_STATE_NULL);
				SFEngine::GetInstance()->Disconnect(pPacket->GetSerial());
			}

			ReleasePacket(pPacket);
		}
		else
		{
			pSession->SetLoginState(SESSION_STATE_NULL);
			SFEngine::GetInstance()->Disconnect(pPacket->GetSerial());

			ReleasePacket(pPacket);
		}
	}
}
Example #2
0
void SFMultiLogicDispatcher::MultiLogicProc(void* Args)
{
#ifdef _WIN32
    SFIOCPQueue<BasePacket>* pQueue = static_cast<SFIOCPQueue<BasePacket>*>(Args);
#else
    SFLockQueue<BasePacket>* pQueue = static_cast<SFLockQueue<BasePacket>*>(Args);
#endif

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

    while (true)
    {
        BasePacket* pPacket = pQueue->Pop(-1);

        if (pPacket == nullptr)
            continue;

        if (pPacket->GetPacketType() == SFPACKET_SERVERSHUTDOWN)
            break;
        else
        {
            LogicEntry::GetInstance()->ProcessPacket(pPacket);
            if (pPacket->GetPacketType() != SFPACKET_DB)
            {
                ReleasePacket(pPacket);
            }
        }
    }
}
Example #3
0
void WritePacket(int Snaplen)
{
    LPPACKET lpPacket = 0;   // define a pointer to a PACKET structure

    if (Snaplen > sizeof(tx_buffer)) Snaplen = sizeof(tx_buffer);
    lpPacket = CreatePacket((char*)tx_buffer, Snaplen);
    PacketSetNumWrites(lpAdapter, 1);
    PacketSendPacket(lpAdapter, lpPacket, TRUE);
    ReleasePacket(lpPacket);
}
Example #4
0
	void SFNETDispatcher::LogicThreadProc(void* Args)
	{
		UNREFERENCED_PARAMETER(Args);
		
		while (m_bLogicEnd == false)
		{
			//로직게이트웨이 큐에서 패킷을 꺼낸다.
			//로직엔트리 객체의 ProcessPacket 메소드를 호출해서 패킷 처리를 수행한다.
			BasePacket* pPacket = LogicGatewaySingleton::instance()->PopPacket();

			LogicEntrySingleton::instance()->ProcessPacket(pPacket);

			ReleasePacket(pPacket);
		}
	}
void SFMulitiCasualGameDispatcher::CasualGameLogicProc(void* Args)
{
	CasualGameParam* pParam = static_cast<CasualGameParam*>(Args);
	SFIOCPQueue<BasePacket>* pQueue = pParam->pQueue;
	ILogicEntry* pEntry = pParam->pLogicEntry;

	while (m_bLogicEnd == false)
	{
		BasePacket* pPacket = pQueue->Pop(INFINITE);

		if (pPacket)
		{
			pEntry->ProcessPacket(pPacket);
			if (pPacket->GetPacketType() != SFPACKET_DB)
			{
				ReleasePacket(pPacket);
			}
		}
	}
}
Example #6
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);
        }
    }
}