bool CPlayerManager::ProcessPublicMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nSessionID ) { if ( prealMsg->usMsgType == MSG_PLAYER_LOGIN ) { stMsgOnPlayerLogin* pmsgenter = (stMsgOnPlayerLogin*)prealMsg ; CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer != NULL && pPlayer->GetUserUID() == pmsgenter->nUserUID ) { CLogMgr::SharedLogMgr()->ErrorLog("double nSession, this nSessionID already have player, already login , do not login again ? ") ; return true ; } if ( pPlayer != NULL && pPlayer->GetUserUID() != pmsgenter->nUserUID ) // switch account in main scene { // disconnect pre player OnPlayerOffline(pPlayer); } if ( ProcessIsAlreadyLogin(pmsgenter->nUserUID,nSessionID) ) { return true ; } // is offline peer MAP_UID_PLAYERS::iterator iterOfflien = m_vOfflinePlayers.begin(); for ( ; iterOfflien != m_vOfflinePlayers.end(); ++iterOfflien ) { if ( iterOfflien->second && iterOfflien->first == pmsgenter->nUserUID ) { iterOfflien->second->OnReactive(nSessionID) ; AddPlayer(iterOfflien->second) ; m_vOfflinePlayers.erase(iterOfflien) ; return true ; } } CPlayer* pNew = new CPlayer ; pNew->Init(pmsgenter->nUserUID,nSessionID ) ; AddPlayer(pNew) ; return true ; } // process player logout ; if ( MSG_DISCONNECT_CLIENT == prealMsg->usMsgType ) { CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer ) { // post online event ; OnPlayerOffline(pPlayer) ; } else { CLogMgr::SharedLogMgr()->ErrorLog("client disconnect ! client is NULL session id = %d",nSessionID) ; } //#ifdef _DEBUG LogState(); //#endif return true ; } if ( ProcessTaxasServerMsg(prealMsg,eSenderPort,nSessionID) ) { return true ; } return false ; }
bool CPlayerManager::ProcessPublicMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nSessionID ) { switch ( prealMsg->usMsgType ) { case MSG_CROSS_SERVER_REQUEST: { stMsgCrossServerRequest* pRet = (stMsgCrossServerRequest*)prealMsg ; Json::Value* pJsValue = nullptr ; Json::Value rootValue ; if ( pRet->nJsonsLen ) { Json::Reader reader; char* pstr = ((char*)&pRet->nJsonsLen) + sizeof(pRet->nJsonsLen) ; reader.parse(pstr,pstr + pRet->nJsonsLen,rootValue,false); pJsValue = &rootValue ; } if ( onCrossServerRequest(pRet,eSenderPort,pJsValue) == false ) { CPlayer* pPlayer = GetPlayerByUserUID(pRet->nTargetID); assert(pPlayer&&"this request no one to process or target id error"); if ( pPlayer && pPlayer->onCrossServerRequest(pRet,eSenderPort,pJsValue) ) { return true ; } CLogMgr::SharedLogMgr()->ErrorLog("cross request type = %d , subType = %d ,unprocessed",pRet->nRequestType,pRet->nRequestSubType); return false; } return true ; } break; case MSG_CROSS_SERVER_REQUEST_RET: { stMsgCrossServerRequestRet* pRet = (stMsgCrossServerRequestRet*)prealMsg ; Json::Value* pJsValue = nullptr ; Json::Value rootValue ; if ( pRet->nJsonsLen ) { Json::Reader reader; char* pstr = ((char*)&pRet->nJsonsLen) + sizeof(pRet->nJsonsLen) ; reader.parse(pstr,pstr + pRet->nJsonsLen,rootValue,false); pJsValue = &rootValue ; } if ( onCrossServerRequestRet(pRet,pJsValue) == false ) { CPlayer* pPlayer = GetPlayerByUserUID(pRet->nTargetID); assert(pPlayer&&"this request no one to process or target id error"); if ( pPlayer && pPlayer->onCrossServerRequestRet(pRet,pJsValue) ) { return true ; } CLogMgr::SharedLogMgr()->ErrorLog("cross request result type = %d , subType = %d ,unprocessed",pRet->nRequestType,pRet->nRequestSubType); return false; } return true ; } break; case MSG_REQUEST_PLAYER_DATA: { stMsgRequestPlayerData* pRet = (stMsgRequestPlayerData*)prealMsg ; stMsgRequestPlayerDataRet msgBack ; msgBack.nRet = 0 ; msgBack.isDetail = pRet->isDetail ; CPlayer* pPlayer = GetPlayerByUserUID(pRet->nPlayerUID); stPlayerDetailDataClient stData ; stData.nCurrentRoomID = 0 ; CAutoBuffer auB (sizeof(msgBack) + sizeof(stPlayerDetailData)); if ( pPlayer ) { CPlayerTaxas* pTaxasData = (CPlayerTaxas*)pPlayer->GetComponent(ePlayerComponent_PlayerTaxas); stData.nCurrentRoomID = pTaxasData->getCurRoomID() ; if ( stData.nCurrentRoomID ) // select take in { stMsgCrossServerRequest msgReq ; msgReq.nJsonsLen = 0 ; msgReq.nReqOrigID = nSessionID ; msgReq.nRequestSubType = eCrossSvrReqSub_SelectPlayerData ; msgReq.nRequestType = eCrossSvrReq_SelectTakeIn ; msgReq.nTargetID = stData.nCurrentRoomID ; msgReq.cSysIdentifer = ID_MSG_PORT_TAXAS ; msgReq.vArg[0] = pRet->nPlayerUID; msgReq.vArg[1] = pRet->isDetail ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,(char*)&msgReq,sizeof(msgReq)) ; CLogMgr::SharedLogMgr()->PrintLog("select take in for player detail") ; return true ; } if ( pRet->isDetail ) { pPlayer->GetBaseData()->GetPlayerDetailData(&stData); pTaxasData->getTaxasData(&stData.tTaxasData); } else { pPlayer->GetBaseData()->GetPlayerBrifData(&stData) ; } auB.addContent(&msgBack,sizeof(msgBack)); auB.addContent(&stData,pRet->isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ) ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,auB.getBufferPtr(),auB.getContentSize()) ; return true ; } if ( m_tPlayerDataCaher.getPlayerData(pRet->nPlayerUID,&stData,pRet->isDetail) ) { auB.addContent(&msgBack,sizeof(msgBack)); auB.addContent(&stData,pRet->isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ) ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,auB.getBufferPtr(),auB.getContentSize()) ; CLogMgr::SharedLogMgr()->PrintLog("get player data from cahe") ; return true ; } CLogMgr::SharedLogMgr()->PrintLog("req detail player not online , req from db target uid = %u",pRet->nPlayerUID) ; stMsgSelectPlayerData msgReq ; msgReq.isDetail = pRet->isDetail ; msgReq.nReqPlayerSessionID = nSessionID ; msgReq.nTargetPlayerUID = pRet->nPlayerUID ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,(char*)&msgReq,sizeof(msgReq)) ; } break; case MSG_SELECT_DB_PLAYER_DATA: { stMsgSelectPlayerDataRet* pRet = (stMsgSelectPlayerDataRet*)prealMsg ; stMsgRequestPlayerDataRet msgBack ; msgBack.nRet = pRet->nRet ; msgBack.isDetail = pRet->isDetail ; if ( pRet->nRet ) { CGameServerApp::SharedGameServerApp()->sendMsg(pRet->nReqPlayerSessionID,(char*)&msgBack,sizeof(msgBack)) ; } else { m_tPlayerDataCaher.cachePlayerData(pRet); CAutoBuffer auB (sizeof(msgBack) + sizeof(stPlayerDetailDataClient)); auB.addContent(&msgBack,sizeof(msgBack)); uint16_t nLen = pRet->isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ; auB.addContent((char*)prealMsg + sizeof(stMsgSelectPlayerDataRet),nLen ); CGameServerApp::SharedGameServerApp()->sendMsg(pRet->nReqPlayerSessionID,auB.getBufferPtr(),auB.getContentSize()) ; } CLogMgr::SharedLogMgr()->PrintLog("session id = %d req play data ret = %d",pRet->nReqPlayerSessionID,pRet->nRet ) ; } break; case MSG_PLAYER_LOGIN: { stMsgOnPlayerLogin* pmsgenter = (stMsgOnPlayerLogin*)prealMsg ; CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer != NULL && pPlayer->GetUserUID() == pmsgenter->nUserUID ) { CLogMgr::SharedLogMgr()->ErrorLog("double nSession, this nSessionID already have player, already login , do not login again id = %d? ",nSessionID) ; return true ; } if ( pPlayer != NULL && pPlayer->GetUserUID() != pmsgenter->nUserUID ) // switch account in main scene { // disconnect pre player OnPlayerOffline(pPlayer); } if ( ProcessIsAlreadyLogin(pmsgenter->nUserUID,nSessionID) ) { return true ; } // is offline peer MAP_UID_PLAYERS::iterator iterOfflien = m_vOfflinePlayers.begin(); for ( ; iterOfflien != m_vOfflinePlayers.end(); ++iterOfflien ) { if ( iterOfflien->second && iterOfflien->first == pmsgenter->nUserUID ) { iterOfflien->second->OnReactive(nSessionID) ; AddPlayer(iterOfflien->second) ; m_vOfflinePlayers.erase(iterOfflien) ; return true ; } } CPlayer* pNew = new CPlayer ; pNew->Init(pmsgenter->nUserUID,nSessionID ) ; AddPlayer(pNew) ; } break; case MSG_DISCONNECT_CLIENT: case MSG_PLAYER_LOGOUT: { CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer ) { // post online event ; CLogMgr::SharedLogMgr()->PrintLog("player disconnect session id = %d",nSessionID); OnPlayerOffline(pPlayer) ; } else { CLogMgr::SharedLogMgr()->ErrorLog("client disconnect ! client is NULL session id = %d",nSessionID) ; } //#ifdef _DEBUG LogState(); //#endif } break; case MSG_TP_ORDER_LEAVE: { stMsgOrderTaxasPlayerLeaveRet* pRet = (stMsgOrderTaxasPlayerLeaveRet*)prealMsg ; CPlayer* pp = GetPlayerByUserUID(pRet->nUserUID) ; if (!pp) { CLogMgr::SharedLogMgr()->ErrorLog("uid = %d not find , so can not inform leave",pRet->nUserUID); } else { pp->OnMessage(prealMsg,eSenderPort); } } break; case MSG_TP_INFORM_LEAVE: { stMsgInformTaxasPlayerLeave* pRet = (stMsgInformTaxasPlayerLeave*)prealMsg ; CPlayer* pp = GetPlayerByUserUID(pRet->nUserUID) ; if (!pp) { CLogMgr::SharedLogMgr()->ErrorLog("uid = %d not find , so can not inform leave",pRet->nUserUID); } else { pp->OnMessage(prealMsg,eSenderPort); } } break; case MSG_TP_SYNC_PLAYER_DATA: { stMsgSyncTaxasPlayerData* pRet = (stMsgSyncTaxasPlayerData*)prealMsg ; CPlayer* pp = GetPlayerByUserUID(pRet->nUserUID) ; if (!pp) { CLogMgr::SharedLogMgr()->ErrorLog("uid = %d not find , so can not sys data",pRet->nUserUID); } else { pp->OnMessage(prealMsg,eSenderPort); } } break; default: return false; } return true ; }