int NFCProxyServerNet_ServerModule::Transpond(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen) { NFMsg::MsgBase xMsg; if (!xMsg.ParseFromArray(msg, nLen)) { char szData[MAX_PATH] = { 0 }; sprintf(szData, "Parse Message Failed from Packet to MsgBase, MessageID: %d\n", nMsgID); return false; } //broadcast many palyer for (int i = 0; i < xMsg.player_client_list_size(); ++i) { NF_SHARE_PTR<int> pFD = mxClientIdent.GetElement(NFINetModule::PBToNF(xMsg.player_client_list(i))); if (pFD) { if (xMsg.has_hash_ident()) { NetObject* pNetObject = m_pNetModule->GetNet()->GetNetObject(*pFD); if (pNetObject) { pNetObject->SetHashIdentID(NFINetModule::PBToNF(xMsg.hash_ident())); } } m_pNetModule->GetNet()->SendMsgWithOutHead(nMsgID, msg, nLen, *pFD); } } //send message to one player if (xMsg.player_client_list_size() <= 0) { //playerid==ClientID; NF_SHARE_PTR<int> pFD = mxClientIdent.GetElement(NFINetModule::PBToNF(xMsg.player_id())); if (pFD) { if (xMsg.has_hash_ident()) { NetObject* pNetObject = m_pNetModule->GetNet()->GetNetObject(*pFD); if (pNetObject) { pNetObject->SetHashIdentID(NFINetModule::PBToNF(xMsg.hash_ident())); } } m_pNetModule->GetNet()->SendMsgWithOutHead(nMsgID, msg, nLen, *pFD); } } return true; }
void NFCProxyServerNet_ServerModule::OnOtherMessage(const int nSockIndex, const int nMsgID, const char * msg, const uint32_t nLen) { NFMsg::MsgBase xMsg; if (!xMsg.ParseFromArray(msg, nLen)) { char szData[MAX_PATH] = { 0 }; sprintf(szData, "Parse Message Failed from Packet to MsgBase, MessageID: %d\n", nMsgID); return; } NetObject* pNetObject = m_pNetModule->GetNet()->GetNetObject(nSockIndex); if (!pNetObject || pNetObject->GetConnectKeyState() <= 0 || pNetObject->GetGameID() <= 0) { //state error return; } if (xMsg.has_hash_ident()) { //special for distributed if (!pNetObject->GetHashIdentID().IsNull()) { NFCMachineNode xNode; if (mxConsistentHash.GetSuitNode(pNetObject->GetHashIdentID().ToString(), xNode)) { m_pProxyServerToGameModule->GetClusterModule()->SendByServerID(xNode.GetDataID(), nMsgID, msg, nLen); } } else { NFGUID xHashIdent = NFINetModule::PBToNF(xMsg.hash_ident()); NFCMachineNode xNode; if (mxConsistentHash.GetSuitNode(xHashIdent.ToString(), xNode)) { m_pProxyServerToGameModule->GetClusterModule()->SendByServerID(xNode.GetDataID(), nMsgID, msg, nLen); } } } else { m_pProxyServerToGameModule->GetClusterModule()->SendByServerID(pNetObject->GetGameID(), nMsgID, msg, nLen); } }