void NFCProxyServerNet_ServerModule::OnReqEnterGameServer(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen) { //在没有正式进入游戏之前,nPlayerID都是FD NFGUID nPlayerID; NFMsg::ReqEnterGameServer xData; if (!m_pNetModule->ReceivePB(nSockIndex, nMsgID, msg, nLen, xData, nPlayerID)) { return; } NF_SHARE_PTR<ConnectData> pServerData = m_pProxyServerToGameModule->GetClusterModule()->GetServerNetInfo(xData.game_id()); if (pServerData && ConnectDataState::NORMAL == pServerData->eState) { //数据匹配 NetObject* pNetObject = m_pNetModule->GetNet()->GetNetObject(nSockIndex); if (pNetObject && pNetObject->GetConnectKeyState() > 0 && pNetObject->GetGameID() == xData.game_id() && pNetObject->GetAccount() == xData.account() && !xData.name().empty() && !xData.account().empty()) { NFMsg::MsgBase xMsg; if (!xData.SerializeToString(xMsg.mutable_msg_data())) { return; } //playerid在进入游戏之前都是FD,其他时候是真实的ID xMsg.mutable_player_id()->CopyFrom(NFINetModule::NFToPB(pNetObject->GetClientID())); std::string strMsg; if (!xMsg.SerializeToString(&strMsg)) { return; } m_pProxyServerToGameModule->GetClusterModule()->SendByServerID(pNetObject->GetGameID(), NFMsg::EGameMsgID::EGMI_REQ_ENTER_GAME, strMsg); } } }
void NFCCreateRoleModule::OnClienEnterGameProcess(const NFSOCK nSockIndex, const int nMsgID, const char * msg, const uint32_t nLen) { NFGUID nClientID; NFMsg::ReqEnterGameServer xMsg; if (!m_pNetModule->ReceivePB( nMsgID, msg, nLen, xMsg, nClientID)) { return; } NFGUID nRoleID = NFINetModule::PBToNF(xMsg.id()); if (m_pKernelModule->GetObject(nRoleID)) { //it should be rebind with proxy's netobject m_pKernelModule->DestroyObject(nRoleID); } ////////////////////////////////////////////////////////////////////////// NF_SHARE_PTR<NFIGameServerNet_ServerModule::GateBaseInfo> pGateInfo = m_pGameServerNet_ServerModule->GetPlayerGateInfo(nRoleID); if (nullptr != pGateInfo) { m_pGameServerNet_ServerModule->RemovePlayerGateInfo(nRoleID); } NF_SHARE_PTR<NFIGameServerNet_ServerModule::GateServerInfo> pGateServerinfo = m_pGameServerNet_ServerModule->GetGateServerInfoBySockIndex(nSockIndex); if (nullptr == pGateServerinfo) { return; } int nGateID = -1; if (pGateServerinfo->xServerData.pData) { nGateID = pGateServerinfo->xServerData.pData->server_id(); } if (nGateID < 0) { return; } if (!m_pGameServerNet_ServerModule->AddPlayerGateInfo(nRoleID, nClientID, nGateID)) { return; } if (m_pPlayerRedisModule->LoadPlayerData(nRoleID)) { int nHomeSceneID = m_pPlayerRedisModule->GetPlayerHomeSceneID(nRoleID); if (nHomeSceneID <= 0) { nHomeSceneID = m_pPVPModule->RandomTileScene(); } NFDataList var; var.AddString(NFrame::Player::Name()); var.AddString(xMsg.name()); var.AddString(NFrame::Player::GateID()); var.AddInt(nGateID); var.AddString(NFrame::Player::GameID()); var.AddInt(pPluginManager->GetAppID()); var.AddString(NFrame::Player::HomeSceneID()); var.AddInt(nHomeSceneID); var.AddString(NFrame::Player::SceneID()); var.AddInt(nHomeSceneID); var.AddString(NFrame::Player::ViewOppnent()); var.AddObject(nRoleID); NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->CreateObject(nRoleID, nHomeSceneID, 0, NFrame::Player::ThisName(), "", var); if (nullptr == pObject) { //mRoleBaseData //mRoleFDData return; } //get data first then create player m_pSceneProcessModule->RequestEnterScene(pObject->Self(), nHomeSceneID, -1, 0, NFDataList()); } }