Example #1
0
CElement* CClient::GetElement ( void )
{
    CElement* pElement = NULL;
    switch ( GetClientType () )
    {
        case CLIENT_CONSOLE:
        {
            CConsoleClient* pClient = static_cast < CConsoleClient* > ( this );
            pElement = static_cast < CElement* > ( pClient );
            break;
        }
        case CLIENT_PLAYER:
        {
            CPlayer* pClient = static_cast < CPlayer* > ( this );
            pElement = static_cast < CElement* > ( pClient );
            break;
        }
    }
    return pElement;
}
// 解析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;
}