Exemplo n.º 1
0
void CIwGameAds::AdReceived(CIwGameHttpRequest* request, int error)
{
	// If there wwas an error then set the error
	if (error != 0)
	{
		IW_GAME_ADS->setError(ErrorHttp);
		IW_GAME_ADS->setErrorString("Http error");
#if defined(_DEBUG)
		CIwGameError::LogError("Error: CIwGameAds::AdReceived(): ", CIwGameString(error).c_str());
#endif	// _DEBUG
		NotifyAdAvailable();
	}
	else
	{
#if defined(_DEBUG)
		if (request->getContentLength() > 4096)
			memcpy(g_HttpResponse, request->getContent().c_str(), 4096);
		else
			memcpy(g_HttpResponse, request->getContent().c_str(), request->getContentLength());
		g_HttpResponse[request->getContentLength()] = 0;
		CIwGameError::LogError("Info: CIwGameAds::AdReceived(): *************");
		CIwGameError::LogError((const char*)&g_HttpResponse[0]);
		CIwGameError::LogError("****************************");
#endif	// _DEBUG
		// Replace html chars
		request->getContent().ReplaceHTMLCodes();
		if (!ExtractAd(AdInfo, request->getContent()))
		{
#if defined(_DEBUG)
			CIwGameError::LogError("Error: CIwGameAds::AdReceived(): Invalid ad data");
#endif	// _DEBUG
			Error = ErrorInvalidAdData;
			NotifyAdAvailable();
			return;
		}
		if (!HtmlAds && !TextAds && AdInfo.ImageURI.GetLength() != 0)
		{
			// Download the banner ad image
			RequestBannerImage(AdInfo);
		}
		else
		{
#if defined(_DEBUG)
			if (AdInfo.ImageURI.GetLength() == 0)
			{
				CIwGameError::LogError("Error: CIwGameAds::AdReceived(): Content length is 0!");
			}
#endif	// _DEBUG
			NotifyAdAvailable();
		}
	}
}
Exemplo n.º 2
0
void CIwGameAds::Update()
{
	// Check for request timing out
	if (!AdAvailable)
	{
		if (BusyTimer.hasStarted())
		{
			if (BusyTimer.HasTimedOut())
			{
#if defined(_DEBUG)
				CIwGameError::LogError("Info: CIwGameAds::RequestAd() timed out: ");
#endif	// _DEBUG
				Error = ErrorRequestTimedOut;
				NotifyAdAvailable();
			}
		}
	}
}
Exemplo n.º 3
0
void CzAds::Update()
{
	// Check for request timing out
	if (!AdAvailable)
	{
		if (BusyTimer.hasStarted())
		{
			if (BusyTimer.HasTimedOut())
			{
#if defined(_DEBUG)
				CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "CzAds::RequestAd() timed out: ");
#endif	// _DEBUG
				Error = ErrorRequestTimedOut;
				NotifyAdAvailable();
			}
		}
	}
}
Exemplo n.º 4
0
void CIwGameAds::AdImageReceived(CIwGameHttpRequest* request, int error)
{
	s3eDebugOutputString("Ad image received");
	
	// If there wwas an error then set the error
	if (error != 0)
	{
		IW_GAME_ADS->setError(ErrorHttpImage);
		IW_GAME_ADS->setErrorString("Http error retrieving image");
#if defined(_DEBUG)
		CIwGameError::LogError("Error: CIwGameAds::AdImageReceived(): ", CIwGameString(error).c_str());
#endif	// _DEBUG
	}
	else
	{
		eIwGameImageFormat format = GetImageFormatFromHeader();
		if (format == ImageFormatInvalid)
		{
			Error = ErrorInvalidImage;
			ErrorString = "Invalid image format";
		}
		else
		{
			Error = ErrorNone;
			ErrorString = "";

			AdInfo.ImageFormat = format;
#if defined(_DEBUG)
			CIwGameError::LogError("Info: CIwGameAds::AdImageReceived() - Image format - ", CIwGameString((int)format).c_str());
			CIwGameError::LogError("Info: CIwGameAds::AdImageReceived() - Image URL - ", AdInfo.ImageURI.c_str());
			CIwGameError::LogError("Info: CIwGameAds::AdImageReceived() - Link URL - ", AdInfo.LinkURI.c_str());
#endif	// _DEBUG

			// Delete previous image (if any)
			if (AdInfo.Image != NULL)
			{
				delete AdInfo.Image;
				AdInfo.Image = NULL;
			}

			// Create new banner image
			AdInfo.Image = new CIwGameImage();
			if (!AdInfo.Image->Init((void*)request->getContent().c_str(), request->getContentLength()))
			{
#if defined(_DEBUG)
				CIwGameError::LogError("Info: CIwGameAds::AdImageReceived() - Could hot create image!");
#endif	// _DEBUG
				Error = ErrorInvalidImage;
				ErrorString = "Invalid image format";
				delete AdInfo.Image;
				AdInfo.Image = NULL;
			}
			else
			{
CIwGameError::LogError("Info: Image Width - ", CIwGameString(AdInfo.Image->getWidth()).c_str());
CIwGameError::LogError("Info: Image Height - ", CIwGameString(AdInfo.Image->getHeight()).c_str());
			}
		}
	}
	NotifyAdAvailable();
}
Exemplo n.º 5
0
void CzAds::AdImageReceived(CzHttpRequest* request, int error)
{
	CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "CzAds::AdImageReceived: Ad image received");
	
	// If there wwas an error then set the error
	if (error != 0)
	{
		CZ_ADS->setError(ErrorHttpImage);
		CZ_ADS->setErrorString("Http error retrieving image");
#if defined(_DEBUG)
		CzDebug::Log(CZ_DEBUG_CHANNEL_ERROR, "CzAds::AdImageReceived(): ", CzString(error).c_str());
#endif	// _DEBUG
	}
	else
	{
		eAdsImageFormat format = GetImageFormatFromHeader();
		if (format == ImageFormatInvalid)
		{
			Error = ErrorInvalidImage;
			ErrorString = "Invalid image format";
		}
		else
		{
			Error = ErrorNone;
			ErrorString = "";

			AdInfo.ImageFormat = format;
#if defined(_DEBUG)
			CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "CzAds::AdImageReceived() - Image format - ", CzString((int)format).c_str());
			CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "CzAds::AdImageReceived() - Image URL - ", AdInfo.ImageURI.c_str());
			CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "CzAds::AdImageReceived() - Link URL - ", AdInfo.LinkURI.c_str());
#endif	// _DEBUG

			// Delete previous image (if any)
			if (AdInfo.Image != NULL)
			{
				delete AdInfo.Image;
				AdInfo.Image = NULL;
			}

			// Create new banner image
			AdInfo.Image = new CzImage();
			if (!AdInfo.Image->Init((void*)request->getContent().c_str(), request->getContentLength()))
			{
#if defined(_DEBUG)
				CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "CzAds::AdImageReceived() - Could hot create image!");
#endif	// _DEBUG
				Error = ErrorInvalidImage;
				ErrorString = "Invalid image format";
				delete AdInfo.Image;
				AdInfo.Image = NULL;
			}
			else
			{
CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Image Width - ", CzString(AdInfo.Image->getWidth()).c_str());
CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Image Height - ", CzString(AdInfo.Image->getHeight()).c_str());
			}
		}
	}
	NotifyAdAvailable();
}