Esempio n. 1
0
// 获取到角色数据之后,回调此函数
void PlayerMng::AchievePlayerData(const roledata::PBRoleTotalInfo& roleData, const string& strDesc)
{
	map<string, Player*>::iterator playerIt = m_playerInfoMap.find(roleData.baseinfo().ptname());
	if (playerIt == m_playerInfoMap.end())
	{
		ERRORLOG("cannot find player, ptname=[" << roleData.baseinfo().ptname() << "],desc=[" << strDesc << "]");
		return;
	}
	Player* pPlayer = playerIt->second;
	if (!pPlayer)
	{
		ERRORLOG("player is NULL");
		return;
	}
	
	IConnection* pClientConn = pPlayer->GetPlayerConnection();
	if (!pClientConn)
	{
		ERRORLOG("player client connection is NULL.");
		return;
	}
	if (!pClientConn->IsConnected())
	{
		ERRORLOG("player client connection=[" << pClientConn <<"] is disconnect.");
		return;
	}
	pPlayer->GetRoleTotalInfo(roleData);
	pPlayer->SetPlayerState(PLAYER_ONLINE);

	uint32_t ID = pPlayer->GetPlayerID();
	m_playerIdMap.insert(make_pair(pPlayer->GetPlayerID(), pPlayer));

	TRACELOG("Achieve player data, ID=[" << ID << "], ptname=[" << pPlayer->PtName() << "] " << strDesc);

	// 玩家数据可能已经被修改了
	roledata::PBRoleTotalInfo newRoleTotalData;
	pPlayer->SerializeToPB(newRoleTotalData);

	// 将数据返回给客户端
	_SendPlayerDataToClient(pClientConn, newRoleTotalData);
}
Esempio n. 2
0
void PlayerMng::CreateRoleResult(const string& strPtName, int32_t nErrCode)
{
	Player* pPlayer = GetPlayer(strPtName);
	if (!pPlayer)
	{
		ERRORLOG("create role ptname=[" << strPtName << "] result, cannot find player");
		return;
	}
	IConnection* pClientConn = pPlayer->GetPlayerConnection();
	if (!pClientConn || !pClientConn->IsConnected())
	{
		ERRORLOG("create role ptname=[" << strPtName << "] result, client connection invalid");
		return;
	}

	ctos::ResponseCreateRole createRoleAck;
	createRoleAck.set_errcode(nErrCode);

	string strMessage;
	BuildResponseProto<ctos::ResponseCreateRole>(createRoleAck, strMessage, ID_ACK_ResponseCreateRole);
	pClientConn->SendMsg(strMessage.c_str(), strMessage.size());
	return;
}