Esempio n. 1
0
bool CPlayerManager::onCrossServerRequestRet(stMsgCrossServerRequestRet* pResult,Json::Value* vJsValue)
{
	if ( eCrossSvrReq_SelectTakeIn == pResult->nRequestType && eCrossSvrReqSub_SelectPlayerData == pResult->nRequestSubType )
	{
		stMsgRequestPlayerDataRet msgBack ;
		msgBack.nRet = 0 ;
		msgBack.isDetail = pResult->vArg[3] ;
		CPlayer* pPlayer = GetPlayerByUserUID(pResult->vArg[0]);
		if ( pPlayer == nullptr )
		{
			CLogMgr::SharedLogMgr()->ErrorLog("why this player is null , can not , funck!") ;
			return true ;
		}

		stPlayerDetailDataClient stData ;
		stData.nCurrentRoomID = 0 ;
		CAutoBuffer auB (sizeof(msgBack) + sizeof(stPlayerDetailDataClient));
		if ( pPlayer )
		{
			CPlayerTaxas* pTaxasData = (CPlayerTaxas*)pPlayer->GetComponent(ePlayerComponent_PlayerTaxas);
			stData.nCurrentRoomID = pResult->nReqOrigID;
			if ( msgBack.isDetail )
			{
				pPlayer->GetBaseData()->GetPlayerDetailData(&stData);
				pTaxasData->getTaxasData(&stData.tTaxasData);
				if ( vJsValue )
				{
					stData.tTaxasData.nPlayTimes += (*vJsValue)["playTimes"].asUInt();
					stData.tTaxasData.nWinTimes += (*vJsValue)["winTimes"].asUInt();
					stData.tTaxasData.nSingleWinMost = (*vJsValue)["singleMost"].asUInt() < stData.tTaxasData.nSingleWinMost ? stData.tTaxasData.nSingleWinMost : (*vJsValue)["singleMost"].asUInt();
				}
				else
				{
					CLogMgr::SharedLogMgr()->PrintLog("targe player not sit down uid = %llu",pResult->vArg[0]);
				}
			}
			else
			{
				pPlayer->GetBaseData()->GetPlayerBrifData(&stData) ;
			}

			if ( pResult->vArg[1] )
			{
				stData.nCoin += pResult->vArg[2] ;
			}
			else
			{
				stData.nDiamoned += pResult->vArg[2] ;
			}
			stData.nCurrentRoomID = pResult->nReqOrigID;
			auB.addContent(&msgBack,sizeof(msgBack));
			auB.addContent(&stData,msgBack.isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ) ;
			CGameServerApp::SharedGameServerApp()->sendMsg(pResult->nTargetID,auB.getBufferPtr(),auB.getContentSize()) ;
			CLogMgr::SharedLogMgr()->PrintLog("select take in ret , send player data");
			return true ;
		}
		return true ;
	}
	return false ;
}
Esempio n. 2
0
bool CPlayerManager::onCrossServerRequest(stMsgCrossServerRequest* pRequest , eMsgPort eSenderPort,Json::Value* vJsValue)
{
	if ( pRequest->nRequestType == eCrossSvrReq_Inform )
	{
		CPlayer* pp = GetPlayerByUserUID(pRequest->nTargetID) ;
		if ( pp )
		{
			((CPlayerMailComponent*)pp->GetComponent(ePlayerComponent_Mail))->ReciveMail(((char*)pRequest) + sizeof(stMsgCrossServerRequest),pRequest->nJsonsLen);
		}
		else
		{
			CPlayerMailComponent::PostMailToDB(((char*)pRequest) + sizeof(stMsgCrossServerRequest),pRequest->nJsonsLen,pRequest->nTargetID);
		}
		return true ;
	}
	return false ;
}
Esempio n. 3
0
bool CPlayerFriend::OnMessage(stMsg* pMsg, eMsgPort eSenderPort )
{
	switch ( pMsg->usMsgType )
	{
	case MSG_READ_FRIEND_LIST:
		{
			stMsgReadFriendListRet* pRet = (stMsgReadFriendListRet*)pMsg ;
			char* pBuffer = (char*)&pRet;
			pBuffer += sizeof(stMsgReadFriendListRet);

			if ( pRet->nFriendCountLen )
			{
				Json::Reader reader ;
				Json::Value arrayValue ;
				reader.parse(pBuffer,pBuffer + pRet->nFriendCountLen,arrayValue,false);
				for ( uint16_t nIdx = 0 ; nIdx < arrayValue.size(); ++nIdx )
				{
					m_vAllFriends.insert(arrayValue[nIdx].asUInt());
				}
			}
			LOGFMTD("read friend list ok uid = %d",GetPlayer()->GetUserUID());
		}
		break;
	case MSG_REQUEST_FRIEND_LIST:
		{
			SendListToClient();
		}
		break;
	case MSG_PLAYER_ADD_FRIEND:
		{
			stMsgPlayerAddFriend* pMsgRet = (stMsgPlayerAddFriend*)pMsg ;
			CPlayer* pTargetPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pMsgRet->nTargetUID,false) ;
			stMsgPlayerAddFriendRet msg ;
			msg.nRet = 0 ;
			msg.nTaregtUID = pMsgRet->nTargetUID ;
			memset(msg.pReplayerName,0,sizeof(msg.pReplayerName));
			if ( pTargetPlayer )
			{
				sprintf_s(msg.pReplayerName,sizeof(msg.pReplayerName),"%s",pTargetPlayer->GetBaseData()->GetPlayerName()) ;
			}

			if ( IsFriendListFull() )
			{
				msg.nRet = 2 ;
				LOGFMTD("friend list is full, can not add");
			}
			else if ( isPlayerUIDFriend(pMsgRet->nTargetUID) )
			{
				msg.nRet = 5 ;
				LOGFMTD("already your friend , can not add");
			}
			else if ( pTargetPlayer == nullptr )
			{
				msg.nRet = 4 ;
			}
			else
			{
				CPlayerFriend* pTaretFriendModule = (CPlayerFriend*)pTargetPlayer->GetComponent(ePlayerComponent_Friend);
				if ( pTaretFriendModule->IsFriendListFull() )
				{
					msg.nRet = 3 ;
				}
				else
				{
					pTaretFriendModule->OnPlayerWantAddMe(this);
				}
			}
			if ( msg.nRet )
			{
				SendMsg(&msg,sizeof(msg)) ;
			}
		}
		break;
	case MSG_PLAYER_BE_ADDED_FRIEND_REPLY:
		{
			stMsgPlayerBeAddedFriendReply* pMsgRet = (stMsgPlayerBeAddedFriendReply*)pMsg ;
			CPlayer* pReplyToPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pMsgRet->nReplayToPlayerUserUID) ;
			CPlayerFriend* pReplyToFriendComponed =  NULL;
			stMsgPlayerBeAddedFriendReplyRet msgBack ;
			msgBack.nNewFriendUserUID = pMsgRet->nReplayToPlayerUserUID ;
			msgBack.nRet = 0 ;
			if ( pReplyToPlayer )
			{
				pReplyToFriendComponed = (CPlayerFriend*)pReplyToPlayer->GetComponent(ePlayerComponent_Friend) ;
			}

			if ( pReplyToFriendComponed )
			{
				if ( IsFriendListFull() )
				{
					msgBack.nRet = 2 ;
				}

				if ( msgBack.nRet == 0 && pReplyToFriendComponed->IsFriendListFull() )
				{
					msgBack.nRet = 1 ;
				}

				if ( pMsgRet->bAgree && msgBack.nRet == 0  )
				{
					AddFriend(pMsgRet->nReplayToPlayerUserUID) ;
				}

				pReplyToFriendComponed->OnOtherReplayMeAboutAddItbeFriend(pMsgRet->bAgree,this);
			}
			else
			{
				LOGFMTE("%d uid offline can not reply add friend ",pMsgRet->nReplayToPlayerUserUID);
				msgBack.nRet = 3 ;
			}

			if ( pMsgRet->bAgree )
			{
				SendMsg(&msgBack,sizeof(msgBack)) ;
				LOGFMTD("uid = %u msg type = stMsgPlayerBeAddedFriendReplyRet, typeid = %s",GetPlayer()->GetUserUID(),typeid(stMsgPlayerBeAddedFriendReplyRet)) ;
			}
		}
		break;
	case MSG_PLAYER_DELETE_FRIEND:
		{
			stMsgPlayerDelteFriendRet msgBack ;
			msgBack.nRet = 0 ;
			stMsgPlayerDelteFriend* pMsgRet = (stMsgPlayerDelteFriend*)pMsg ;
			msgBack.nDeleteUID = pMsgRet->nDelteFriendUserUID ;
			if ( isPlayerUIDFriend(pMsgRet->nDelteFriendUserUID) == false )
			{
				msgBack.nRet = 1 ;
			}
			else
			{
				RemoveFriendByUID(pMsgRet->nDelteFriendUserUID) ;
			}
			SendMsg(&msgBack,sizeof(msgBack));

			CPlayer* pReplyToPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(msgBack.nDeleteUID) ;
			CPlayerFriend* pReplyToFriendComponed =  NULL;
			if ( pReplyToPlayer )
			{
				pReplyToFriendComponed = (CPlayerFriend*)pReplyToPlayer->GetComponent(ePlayerComponent_Friend) ;
				pReplyToFriendComponed->RemoveFriendByUID(GetPlayer()->GetUserUID()) ;
			}
			else
			{
				LOGFMTE("no online tell mail to delete friend");
			}
		}
		break;
	default:
		return false ;
	}
	return true ;
}
Esempio n. 4
0
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 ;
}