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); } } } }
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); } } } }
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); } } }