bool CGameServer::DispatchGateServer(const PacketPtr& PktPtr, KeyRef krSocket) { bool bRet = false; switch (PktPtr->GetEvent()) { case PAK_EVENT_LINK: { bRet = OnServerLink(static_cast<CPAKLink*>(PktPtr.Get()), krSocket); } break; case PAK_EVENT_UPDATE: { bRet = OnServerUpdate(static_cast<CPAKUpdate*>(PktPtr.Get()), krSocket); } break; case PAK_EVENT_UNLINK: { bRet = OnServerUnlink(PktPtr.Get(), krSocket); } break; case PAK_EVENT_GAME_ID: { CPAKGameIdAck GameIdAck; GameIdAck.SetId((Int)m_ServerInfo.usId); GameIdAck.AdjustSize(); m_NetworkPtr->Send(krSocket, GameIdAck); } break; default: { LOGV_WARN(m_FileLog, TF("[游戏服务器]%p无法识别的网关服务器信令包数据[event=%d]"), krSocket, PktPtr->GetEvent()); } } return bRet; }
bool CGameServer::DispatchGameDBServer(const PacketPtr& PktPtr, KeyRef krSocket) { switch (PktPtr->GetEvent()) { case PAK_EVENT_LINKACK: { m_bGameDBLinked = true; NET_ADDR NetAddr; m_NetworkPtr->GetAddr(krSocket, NetAddr, false); m_pUIHandler->OnHandle(PAK_EVENT_LINK, reinterpret_cast<uintptr_t>(&NetAddr), DATA_INDEX_GAMEDB); LOG_INFO(m_FileLog, TF("[游戏服务器]收到游戏DB服务器注册回复包")); } break; case PAK_EVENT_UPDATEACK: { DEV_INFO(TF("[游戏服务器]收到游戏DB服务器更新回复包")); } break; case PAK_EVENT_UNLINKACK: { m_bGameDBLinked = false; LOG_INFO(m_FileLog, TF("[游戏服务器]收到游戏DB服务器注销回复包")); } break; case PAK_EVENT_LIVEACK: { } break; default: { LOGV_WARN(m_FileLog, TF("[游戏服务器]%p无法识别的游戏DB服务器信令包数据[event=%d]"), krSocket, PktPtr->GetEvent()); } } return true; }
bool CGameServer::DispatchZoneServer(const PacketPtr& PktPtr, KeyRef krSocket) { bool bRet = false; switch (PktPtr->GetEvent()) { case PAK_EVENT_LINK: { bRet = OnServerLink(static_cast<CPAKLink*>(PktPtr.Get()), krSocket); } break; case PAK_EVENT_UPDATE: { bRet = OnServerUpdate(static_cast<CPAKUpdate*>(PktPtr.Get()), krSocket); } break; case PAK_EVENT_UNLINK: { bRet = OnServerUnlink(PktPtr.Get(), krSocket); } break; default: { LOGV_WARN(m_FileLog, TF("[游戏服务器]%p无法识别的地图服务器信令包数据[event=%d]"), krSocket, PktPtr->GetEvent()); } } return bRet; }
//-------------------------------------- bool CGameServer::OnUdpDispatch(const PacketPtr& PktPtr, PUDP_PARAM pUdp) { // PUDP_PARAM->pCache == nullptr, 上层可以保存从底层申请的缓存数据 // PUDP_PARAM->pCache, PUDP_PARAM->index是底层申请的缓存数据的起始地址和索引号 // 如果上层保存缓存, 设置PUDP_PARAM->pData为nullptr通知网络底层 // 释放缓存使用MObject::sMCFree(index, pCache) assert(PktPtr->GetEvent() == PAK_EVENT_LOGIN_SELECT_GAME); CPAKLoginSelectGame* pSelect = static_cast<CPAKLoginSelectGame*>(PktPtr.Get()); if (SelectGame(pSelect) == false) { pSelect->SetAck(LOGIN_ERROR_NONE_GATE); m_NetworkPtr->SendTo(pUdp->krSocket, *pSelect, pUdp->NetAddr); LOG_INFO(m_FileLog, TF("[游戏服务器]游戏服务器收到客户端选择游戏服务器请求, 但是没有网关服务器")); } return true; }
//-------------------------------------- bool CGameServer::OnTcpDispatch(const PacketPtr& PktPtr, PTCP_PARAM pTcp) { // PTCP_PARAM->pCache == nullptr, 上层可以保存从底层申请的缓存数据 // PTCP_PARAM->pCache, PTCP_PARAM->index是底层申请的缓存数据的起始地址和索引号 // 如果上层保存缓存, 设置PTCP_PARAM->pData为nullptr通知网络底层 // 释放缓存使用MObject::sMCFree(index, pCache) bool bRet = false; if (PktPtr->GetEvent() != PAK_EVENT_LIVE) { switch (PktPtr->GetType()) { case PAK_TYPE_GATE: { bRet = DispatchGateServer(PktPtr, pTcp->krSocket); } break; case PAK_TYPE_ZONE: { bRet = DispatchZoneServer(PktPtr, pTcp->krSocket); } break; case PAK_TYPE_GAMEDB: { bRet = DispatchGameDBServer(PktPtr, pTcp->krSocket); } break; case PAK_TYPE_CENTER: { bRet = DispatchCenterServer(PktPtr, pTcp->krSocket); } break; default: { LOGV_WARN(m_FileLog, TF("[游戏服务器]%p信令包服务器类型[%d]不正确"), pTcp->krSocket, PktPtr->GetType()); bRet = false; } } } else { CPAKSimple<PAK_EVENT_LIVEACK, PAK_TYPE_GAME> LiveAck; LiveAck.AdjustSize(); bRet = m_NetworkPtr->Send(pTcp->krSocket, LiveAck); } return bRet; }