Exemplo n.º 1
0
/**********************************************************
// Function name	: LBSC_Session::SetBaseForMaintenance
// Description	    : 
// Return type		: int 
// Argument         :  const LBSC_Ticket *pTicketPar
// Argument         : const char *szBaseName
// Argument         : const char *szUserName
// Argument         : const char *szWarningMsg
// Argument         : BOOL bSet
**********************************************************/
int LBSC_Session::SetBaseForMaintenance( const LBSC_Ticket *pTicketPar, const char *szBaseName, const char *szUserName, const char *szWarningMsg, BOOL bSet )
{
	// o parametro bSet indica se a base deve ser setada para manutencao (TRUE)
	// ou retirada da lista de bases reservadas (FALSE)


	if( !szBaseName || !szUserName ){
		ERETURN( LBSE_BADARG );
	}

	if( TicketIsOk( pTicketPar ) != 0 ){
		ERETURN( LBSE_TICKETNOTOK );
	}

	LBSC_MaintBase	cMaintBaseAux( szBaseName, szUserName, szWarningMsg );

	C_SessCritSect	cCS3( this, CRITSECT3 );

	if( !_pclMaintBaseList ){
		ERETURN( LBSE_NOMEMORY );
	}
	if( _pclMaintBaseList->Find( &cMaintBaseAux, 0, TRUE ) ){
		// a base esta' reservada
		if( !bSet ){
			// vamos retirar a base da lista
			_pclMaintBaseList->Del();
			ERETURN( LBS_OK );
		}
		ERETURN( LBSE_BASEALREADYRESERVED );
	}
	if( !bSet ){
		// deveriamos tirar a base da lista mas ela nao
		// foi encontrada. Isso nao precisa ser um erro.
		ERETURN( LBS_OK );
	}

	// so' posso fazer isso se eu (usuario logado) for um administrador 
	// na UDB ou se for o dono da base que esta' sendo reservada.

	// verificar se o cara eh administrador na udb
	int iType = GetUserType( pTicketPar, strUDBLogged, NULL);
	if ( iType != MASTER_USER ) {
		// o cara nao eh administrador. entao vamos ver se ele eh o
		// dono da base em questao.

		// ********** isso eh mais delicado de se verificar, pois tenho que abrir a base
		// para ver o nome do dono e ela pode estar aberta em modo exclusivo
		// RESOLVER!!! ************************


		ERETURN( LBSE_NOPERMISSION );
	}

	// vamos adicionar um novo elemento na lista
	LBSC_MaintBase	*pcMaintBase = cMaintBaseAux.Duplicate();
	
	if( pcMaintBase ){
		if( _pclMaintBaseList->Add( pcMaintBase, TAIL ) == OK ){
			ERETURN( LBS_OK );
		}
		delete pcMaintBase;
	}
	ERETURN( LBSE_NOMEMORY );
}
// 解析UserInfo
bool ParsingUserInfoItem(amf_object_handle handle, UserInfoItem& item)
{
	bool result = false;
	if (!handle.isnull()
		&& handle->type == DT_OBJECT)
	{
		// userId
		amf_object_handle userIdObject = handle->get_child(USERID_PARAM);
		if (!userIdObject.isnull()
			&& userIdObject->type == DT_STRING)
		{
			item.userId = userIdObject->strValue;
		}

		// userName
		amf_object_handle userNameObject = handle->get_child(USERNAME_PARAM);
		if (!userNameObject.isnull()
			&& userNameObject->type == DT_STRING)
		{
			item.userName = userNameObject->strValue;
		}

		// server
		amf_object_handle serverObject = handle->get_child(SERVER_PARAM);
		if (!serverObject.isnull()
			&& serverObject->type == DT_STRING)
		{
			item.server = serverObject->strValue;
		}

		// imgUrl
		amf_object_handle imgUrlObject = handle->get_child(IMGURL_PARAM);
		if (!imgUrlObject.isnull()
			&& imgUrlObject->type == DT_STRING)
		{
			item.imgUrl = imgUrlObject->strValue;
		}

		// gender
		amf_object_handle genderObject = handle->get_child(GENDER_PARAM);
		if (!genderObject.isnull()
			&& genderObject->type == DT_INTEGER)
		{
			item.sexType = GetUserSexType(genderObject->intValue);
		}

		// age
		amf_object_handle ageObject = handle->get_child(AGE_PARAM);
		if (!ageObject.isnull()
			&& ageObject->type == DT_INTEGER)
		{
			item.age = ageObject->intValue;
		}

		// weight
		amf_object_handle weightObject = handle->get_child(WEIGHT_PARAM);
		if (!weightObject.isnull()
			&& weightObject->type == DT_STRING)
		{
			item.weight = weightObject->strValue;
		}

		// height
		amf_object_handle heightObject = handle->get_child(HEIGHT_PARAM);
		if (!heightObject.isnull()
			&& heightObject->type == DT_STRING)
		{
			item.height = heightObject->strValue;
		}

		// country
		amf_object_handle countryObject = handle->get_child(COUNTRY_PARAM);
		if (!countryObject.isnull()
			&& countryObject->type == DT_STRING)
		{
			item.country = countryObject->strValue;
		}

		// province
		amf_object_handle provinceObject = handle->get_child(PROVINCE_PARAM);
		if (!provinceObject.isnull()
			&& provinceObject->type == DT_STRING)
		{
			item.province = provinceObject->strValue;
		}

		// videochat
		amf_object_handle videoChatObject = handle->get_child(VIDEOCHAT_PARAM);
		if (!videoChatObject.isnull()
			&& videoChatObject->type == DT_INTEGER)
		{
			item.videoChat = videoChatObject->intValue==1 ? true : false;
		}

		// video
		amf_object_handle videoObject = handle->get_child(VIDEO_PARAM);
		if (!videoObject.isnull()
			&& videoObject->type == DT_INTEGER)
		{
			item.videoCount = videoObject->intValue;
		}

		// marry
		amf_object_handle marryObject = handle->get_child(MARRY_PARAM);
		if (!marryObject.isnull()
			&& marryObject->type == DT_INTEGER)
		{
			item.marryType = GetMarryType(marryObject->intValue);
		}

		// children
		amf_object_handle childrenObject = handle->get_child(CHILDREN_PARAM);
		if (!childrenObject.isnull()
			&& childrenObject->type == DT_INTEGER)
		{
			item.childrenType = (childrenObject->intValue > 0 ? CT_YES : CT_NO);
		}

		// status
		amf_object_handle statusObject = handle->get_child(STATUS_PARAM);
		if (!statusObject.isnull()
			&& statusObject->type == DT_INTEGER)
		{
			item.status = GetUserStatusType(statusObject->intValue);
		}

		// type
		amf_object_handle typeObject = handle->get_child(TYPE_PARAM);
		if (!typeObject.isnull()
			&& typeObject->type == DT_INTEGER)
		{
			item.userType = GetUserType(typeObject->intValue);
		}

		// orderValue
		amf_object_handle orderValueObject = handle->get_child(ORDERVALUE_PARAM);
		if (!orderValueObject.isnull()
			&& orderValueObject->type == DT_INTEGER)
		{
			item.orderValue = orderValueObject->intValue;
		}

		// deviceValue
		amf_object_handle deviceTypeObject = handle->get_child(DEVICETYPE_PARAM);
		if (!deviceTypeObject.isnull()
			&& deviceTypeObject->type == DT_INTEGER)
		{
			item.deviceType = (TDEVICE_TYPE)deviceTypeObject->intValue;
		}

		// clientValue
		amf_object_handle clientTypeObject = handle->get_child(CLIENTTYPE_PARAM);
		if (!clientTypeObject.isnull()
			&& clientTypeObject->type == DT_INTEGER)
		{
			item.clientType = GetClientType(clientTypeObject->intValue);
		}

		// clientVersion
		amf_object_handle clientVersionObject = handle->get_child(CLIENTVERSION_PARAM);
		if (!clientVersionObject.isnull()
			&& clientVersionObject->type == DT_STRING)
		{
			item.clientVersion = clientVersionObject->strValue;
		}

		// --- 以下仅女士端获取自己信息才有 ---
		amf_object_handle transInfoObject = handle->get_child(TRANSINFO_PARAM);
		if (!transInfoObject.isnull()
			&& transInfoObject->type == DT_OBJECT)
		{
			// 需要翻译
			item.needTrans = true;

			// userId
			amf_object_handle transUserIdObject = transInfoObject->get_child(TRANSUSERID_PARAM);
			if (!transUserIdObject.isnull()
				&& transUserIdObject->type == DT_STRING)
			{
				item.transUserId = transUserIdObject->strValue;
			}

			// userName
			amf_object_handle transUserNameObject = transInfoObject->get_child(TRANSUSERNAME_PARAM);
			if (!transUserNameObject.isnull()
				&& transUserNameObject->type == DT_STRING)
			{
				item.transUserName = transUserNameObject->strValue;
			}

			// bind
			amf_object_handle transBindObject = transInfoObject->get_child(TRANSBIND_PARAM);
			if (!transBindObject.isnull()
				&& (transBindObject->type == DT_TRUE || transBindObject->type == DT_FALSE))
			{
				item.transBind = (transBindObject->type == DT_TRUE);
			}

			// status
			amf_object_handle transStatusObject = transInfoObject->get_child(TRANSSTATUS_PARAM);
			if (!transStatusObject.isnull()
				&& transStatusObject->type == DT_INTEGER)
			{
				item.transStatus = GetUserStatusType(transStatusObject->intValue);
			}
		}
		else {
			// 不需要翻译
			item.needTrans = false;
		}

		// 判断是否解析成功
		if (!item.userId.empty()) {
			result = true;
		}
	}
	return result;
}