bool NFNetModule::SendMsgPBToAllClient(const uint16_t nMsgID, const google::protobuf::Message& xData) { NFMsg::MsgBase xMsg; if (!xData.SerializeToString(xMsg.mutable_msg_data())) { std::ostringstream stream; stream << " SendMsgPBToAllClient"; stream << " Failed For Serialize of MsgData, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } std::string strMsg; if (!xMsg.SerializeToString(&strMsg)) { std::ostringstream stream; stream << " SendMsgPBToAllClient"; stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } return SendMsgToAllClientWithOutHead(nMsgID, strMsg); }
bool NFNetModule::SendMsgPB(const uint16_t nMsgID, const google::protobuf::Message& xData, const NFSOCK nSockIndex) { NFMsg::MsgBase xMsg; if (!xData.SerializeToString(xMsg.mutable_msg_data())) { std::ostringstream stream; stream << " SendMsgPB Message to " << nSockIndex; stream << " Failed For Serialize of MsgData, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } NFMsg::Ident* pPlayerID = xMsg.mutable_player_id(); *pPlayerID = NFToPB(NFGUID()); std::string strMsg; if (!xMsg.SerializeToString(&strMsg)) { std::ostringstream stream; stream << " SendMsgPB Message to " << nSockIndex; stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } SendMsgWithOutHead(nMsgID, strMsg, nSockIndex); return true; }
bool NFNetModule::SendMsgPB(const uint16_t nMsgID, const google::protobuf::Message& xData, const NFSOCK nSockIndex, const std::vector<NFGUID>* pClientIDList) { if (!m_pNet) { std::ostringstream stream; stream << " m_pNet SendMsgPB faailed fd " << nSockIndex; stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } NFMsg::MsgBase xMsg; if (!xData.SerializeToString(xMsg.mutable_msg_data())) { std::ostringstream stream; stream << " SendMsgPB faailed fd " << nSockIndex; stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } NFMsg::Ident* pPlayerID = xMsg.mutable_player_id(); *pPlayerID = NFToPB(NFGUID()); if (pClientIDList) { for (int i = 0; i < pClientIDList->size(); ++i) { const NFGUID& ClientID = (*pClientIDList)[i]; NFMsg::Ident* pData = xMsg.add_player_client_list(); if (pData) { *pData = NFToPB(ClientID); } } } std::string strMsg; if (!xMsg.SerializeToString(&strMsg)) { std::ostringstream stream; stream << " SendMsgPB faailed fd " << nSockIndex; stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID; m_pLogModule->LogError(stream, __FUNCTION__, __LINE__); return false; } return SendMsgWithOutHead(nMsgID, strMsg, nSockIndex); }
void NFCNetLogic::SendToServerByPB(const uint16_t nMsgID, google::protobuf::Message& xData) { if(m_bSocketReady) { g_pNetClientModule->SendToAllServerByPB(nMsgID, xData); } else { NFMsg::MsgBase xMsg; xData.SerializeToString(xMsg.mutable_msg_data()); NFMsg::Ident* pPlayerID = xMsg.mutable_player_id(); *pPlayerID = NFINetModule::NFToPB(NFGUID()); std::string strMsg; xMsg.SerializeToString(&strMsg); m_listDelayMsg.push_back(std::make_pair((uint16_t)nMsgID, strMsg)); } }
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 NFCProxyServerNet_ServerModule::OnClientDisconnect(const int nAddress) { NetObject* pNetObject = m_pNetModule->GetNet()->GetNetObject(nAddress); if (pNetObject) { int nGameID = pNetObject->GetGameID(); if (nGameID > 0) { if (!pNetObject->GetUserID().IsNull()) { //掉线 NFMsg::ReqLeaveGameServer xData; NFMsg::MsgBase xMsg; //playerid主要是网关转发消息的时候做识别使用,其他使用不使用 *xMsg.mutable_player_id() = NFINetModule::NFToPB(pNetObject->GetUserID()); if (!xData.SerializeToString(xMsg.mutable_msg_data())) { return; } std::string strMsg; if (!xMsg.SerializeToString(&strMsg)) { return; } m_pProxyServerToGameModule->GetClusterModule()->SendByServerID(nGameID, NFMsg::EGameMsgID::EGMI_REQ_LEAVE_GAME, strMsg); } } NFGUID xClientIdent = pNetObject->GetClientID(); mxClientIdent.RemoveElement(xClientIdent); } }