示例#1
0
int xmpp_ip_works::FireSync(XMPPSyncEventParams *e) {
	if (handler_) {
		IMEventSync* ev = EventFactory<IMEventSync>::NEW();
		int count = GetBuddyCount();
		for (int i = 0; i < count; ++i) {
			Buddy buddy;
			buddy.Group = GetBuddyGroup(i);
			buddy.Jid = GetBuddyId(i);
			buddy.NickName = GetBuddyNickName(i);
			buddy.RealName = GetBuddyRealName(i);
			buddy.Subscription = GetBuddySubscription(i);
			ev->Buddies.push_back(buddy);
		}
		handler_->Handler(ev);
	}
	return 0;
}
示例#2
0
BOOL KBuddyFactory::CheckCreation(INT			nMaster,
								  INT			nTarget,
								  KRole*		pMaster,
								  KRole*		pTarget)
{
	BOOL					bRetCode				= FALSE;
	IKRelationFactory*		pFriendFactory			= NULL;
	IKRelation*				pFriend					= NULL;
	IKBidFriendRelation*	pFriendRelation			= NULL;
	IKRelationFactory*		pTrainingFactory		= NULL;
	IKRelationFactory*		pTrainedFactory			= NULL;
	IKRelationFactory*		pIntroductionFactory	= NULL;

	LOG_PROCESS_ERROR(pMaster && pTarget);

	// 先关闭密友条件
	bRetCode = SUPER_CLASS::CanCreateRelation(nMaster, nTarget);
	goto EXIT0;

	// 检查级别
	if (pMaster->GetLevel() < emKBUDDY_MINLEVEL ||
		pTarget->GetLevel() < emKBUDDY_MINLEVEL)
	{
		bRetCode = FALSE;
		goto EXIT0;
	}

	// 检查密友数目
	if (GetBuddyCount(nMaster) >= emKBUDDY_MAXCOUNT ||
		GetBuddyCount(nTarget) >= emKBUDDY_MAXCOUNT)
	{
		bRetCode = FALSE;
		goto EXIT0;
	}

	// 必须是普通好友且亲密度达到一定等级
	bRetCode = KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_BINDFRIEND, &pFriendFactory);
	LOG_PROCESS_ERROR(bRetCode);
	if (!pFriendFactory->FindRelation(nMaster, nTarget, &pFriend))
	{
		bRetCode = FALSE;
		goto EXIT0;
	}

// 	if (!KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_BINDFRIEND, &pFriendFactory) ||
// 		!pFriendFactory->FindRelation(nMaster, nTarget, &pFriend) ||
// 		!pFriend->QueryRelation(emKPLAYERRELATION_TYPE_BINDFRIEND, (void**)&pFriendRelation) ||
// 		pFriendRelation->GetFavor() < emKBUDDY_MINFAVOR)
// 	{
// 		KGC_Error("");
// 		return FALSE;
// 	}

	// 已经是师徒不能成为指定密友
	bRetCode = KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_TRAINING, &pTrainingFactory);
	LOG_PROCESS_ERROR(bRetCode);

	if (pTrainingFactory->FindRelation(nMaster, nTarget) ||
		pTrainingFactory->FindRelation(nTarget, nMaster))
	{
		bRetCode = FALSE;
		goto EXIT0;
	}

	bRetCode = KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_TRAINED, &pTrainedFactory);
	LOG_PROCESS_ERROR(bRetCode);

	if (pTrainedFactory->FindRelation(nMaster, nTarget) ||
		pTrainedFactory->FindRelation(nTarget, nMaster))
	{
		bRetCode = FALSE;
		goto EXIT0;
	}

	// 已经是介绍人不能成为指定密友
	bRetCode = KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_INTRODUCTION, &pIntroductionFactory);
	LOG_PROCESS_ERROR(bRetCode);

	if (pIntroductionFactory->FindRelation(nMaster, nTarget) ||
		pIntroductionFactory->FindRelation(nTarget, nMaster))
	{
		bRetCode = FALSE;
		goto EXIT0;
	}

	bRetCode = SUPER_CLASS::CanCreateRelation(nMaster, nTarget);
EXIT0:
	return bRetCode;

// 	KGC_CONFIRM_RET_FALSE(pMaster && pTarget);
// 	// 检查级别
// 	if (pMaster->GetLevel() < emKBUDDY_MINLEVEL ||
// 		pTarget->GetLevel() < emKBUDDY_MINLEVEL)
// 	{
// 		return FALSE;
// 	}
// 	// 检查密友数目
// 	if (GetBuddyCount(nMaster) >= emKBUDDY_MAXCOUNT ||
// 		GetBuddyCount(nTarget) >= emKBUDDY_MAXCOUNT)
// 	{
// 		return FALSE;
// 	}
// 	// 必须是普通好友且亲密度达到一定等级
// 	IKRelationFactory* pFriendFactory = NULL;
// 	IKRelation* pFriend = NULL;
// 	IKBidFriendRelation* pFriendRelation = NULL;
// 	if (!KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_BINDFRIEND, &pFriendFactory) ||
// 		!pFriendFactory->FindRelation(nMaster, nTarget, &pFriend) ||
// 		!pFriend->QueryRelation(emKPLAYERRELATION_TYPE_BINDFRIEND, (void**)&pFriendRelation) ||
// 		pFriendRelation->GetFavor() < emKBUDDY_MINFAVOR)
// 	{
// 		KGC_Error("");
// 		return FALSE;
// 	}
// 	// 已经是师徒不能成为指定密友
// 	IKRelationFactory* pTrainingFactory = NULL;
// 	if (!KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_TRAINING, &pTrainingFactory))
// 	{
// 		KGC_Error("");
// 		return FALSE;
// 	}
// 	if (pTrainingFactory->FindRelation(nMaster, nTarget) ||
// 		pTrainingFactory->FindRelation(nTarget, nMaster))
// 	{
// 		return FALSE;
// 	}
// 	IKRelationFactory* pTrainedFactory = NULL;
// 	if (!KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_TRAINED, &pTrainedFactory))
// 	{
// 		KGC_Error("");
// 		return FALSE;
// 	}
// 	if (pTrainedFactory->FindRelation(nMaster, nTarget) ||
// 		pTrainedFactory->FindRelation(nTarget, nMaster))
// 	{
// 		return FALSE;
// 	}
// 	// 已经是介绍人不能成为指定密友
// 	IKRelationFactory* pIntroductionFactory = NULL;
// 	if (!KRelationFactoryList::Instance()->CreateFactory(emKPLAYERRELATION_TYPE_INTRODUCTION, &pIntroductionFactory))
// 	{
// 		KGC_Error("");
// 		return FALSE;
// 	}
// 	if (pIntroductionFactory->FindRelation(nMaster, nTarget) ||
// 		pIntroductionFactory->FindRelation(nTarget, nMaster))
// 	{
// 		return FALSE;
// 	}
// 	if (SUPER_CLASS::CanCreateRelation(nMaster, nTarget))
// 		return TRUE;
// 	return FALSE;
}