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); } }
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::OnReqDelRoleProcess(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen) { //在没有正式进入游戏之前,nPlayerID都是FD NFGUID nPlayerID; NFMsg::ReqDeleteRole 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()) { m_pProxyServerToGameModule->GetClusterModule()->SendByServerID(pNetObject->GetGameID(), nMsgID, std::string(msg, nLen)); } } }
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); } }