示例#1
0
void TwitterProto::UpdateFriends()
{
	try
	{
		ScopedLock s(twitter_lock_);
		std::vector<twitter_user> friends = twit_.get_friends();
		s.Unlock();
		for(std::vector<twitter_user>::iterator i=friends.begin(); i!=friends.end(); ++i)
		{
			if(i->username == twit_.get_username())
				continue;

			HANDLE hContact = AddToClientList(i->username.c_str(),i->status.text.c_str());
			UpdateAvatar(hContact,i->profile_image_url);
		}
		disconnectionCount = 0; 
		debugLogA( _T("***** Friends list updated"));
	}
	catch(const bad_response &)
	{
		++disconnectionCount;
		debugLogA( _T("***** UpdateFriends - Bad response from server, this has happened %d time(s)"), disconnectionCount);
		if (disconnectionCount > 2) {
			debugLogA( _T("***** UpdateFriends - Too many bad responses from the server, signing off"));
			SetStatus(ID_STATUS_OFFLINE);
		}
	}
	catch(const std::exception &e)
	{
		ShowPopup( (std::string("While updating friends list, an error occurred: ")+e.what()).c_str());
		debugLogA( _T("***** Error updating friends list: %s"), e.what());
	}

}
示例#2
0
HBITMAP Protocol::GetAvatarImage()
{
	if (!avatar_initialized)
		UpdateAvatar();
	
	return avatar_bmp;
}
示例#3
0
const char * Protocol::GetAvatarFile()
{
	if (!avatar_initialized)
		UpdateAvatar();

	return avatar_file.c_str();
}
示例#4
0
bool Protocol::HasAvatar()
{
	if (!avatar_initialized)
		UpdateAvatar();

	return avatar_bmp != NULL;
}
示例#5
0
void TwitterProto::UpdateFriends()
{
	try
	{
		ScopedLock s(twitter_lock_);
		std::vector<twitter_user> friends = twit_.get_friends();
		s.Unlock();

		for(std::vector<twitter_user>::iterator i=friends.begin(); i!=friends.end(); ++i)
		{
			if(i->username == twit_.get_username())
				continue;

			HANDLE hContact = AddToClientList(i->username.c_str(),i->status.text.c_str());
			UpdateAvatar(hContact,i->profile_image_url);
		}
		LOG("***** Friends list updated");
	}
	catch(const bad_response &)
	{
		LOG("***** Bad response from server, signing off");
		SetStatus(ID_STATUS_OFFLINE);
	}
	catch(const std::exception &e)
	{
		ShowPopup( (std::string("While updating friends list, an error occurred: ")
			+e.what()).c_str() );
		LOG("***** Error updating friends list: %s",e.what());
	}

}
示例#6
0
void TwitterProto::UpdateInfoWorker(void *arg)
{
	MCONTACT hContact = (MCONTACT)(DWORD_PTR)arg;
	twitter_user user;

	ptrA username(getStringA(hContact, TWITTER_KEY_UN));
	if (username == NULL)
		return;

	{
		mir_cslock s(twitter_lock_);
		twit_.get_info(std::string(username), &user);
	}

	UpdateAvatar(hContact, user.profile_image_url, true);
	ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, 0);
}
示例#7
0
void TwitterProto::AddToListWorker(void *pArg)
{
	// TODO: what happens if there is an error?
	if (pArg == 0)
		return;

	char *name = static_cast<char*>(pArg);

	try {
		twitter_user user;
		{
			mir_cslock s(twitter_lock_);
			user = twit_.add_friend(name);
		}

		MCONTACT hContact = UsernameToHContact(name);
		UpdateAvatar(hContact, user.profile_image_url);
	}
	catch (const std::exception &e) {
		ShowPopup((std::string("While adding a friend, an error occurred: ") + e.what()).c_str());
		debugLogA("***** Error adding friend: %s", e.what());
	}
	mir_free(name);
}
示例#8
0
void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg)
{
	try
	{
		ScopedLock s(twitter_lock_);
		twitter::status_list updates = twit_.get_statuses(200,since_id_);
		s.Unlock();
		if(!updates.empty()) {
			since_id_ = std::max(since_id_, updates[0].status.id);
		}

		for(twitter::status_list::reverse_iterator i=updates.rbegin(); i!=updates.rend(); ++i)
		{

			if(!pre_read && in_chat_)
				UpdateChat(*i);

			if(i->username == twit_.get_username())
				continue;

			HANDLE hContact = AddToClientList(i->username.c_str(),"");
			UpdateAvatar(hContact,i->profile_image_url); // as UpdateFriends() doesn't work at the moment, i'm going to update the avatars here

			// i think we maybe should just do that DBEF_READ line instead of stopping ALL this code.  have to test.
			if (tweetToMsg) {
				DBEVENTINFO dbei = {sizeof(dbei)};
				dbei.pBlob = (BYTE*)(i->status.text.c_str());
				dbei.cbBlob = (int)i->status.text.size()+1;
				dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET;
				dbei.flags = DBEF_UTF | DBEF_READ;
				dbei.timestamp = static_cast<DWORD>(i->status.time);
				dbei.szModule = m_szModuleName;
				db_event_add(hContact, &dbei);
			}

			db_set_utf(hContact,"CList","StatusMsg",i->status.text.c_str());

			if(!pre_read && popups)
				ShowContactPopup(hContact,i->status.text);
		}

		db_pod_set(0,m_szModuleName,TWITTER_KEY_SINCEID,since_id_);
		disconnectionCount = 0;
		debugLogA( _T("***** Status messages updated"));
	}
	catch(const bad_response &)
	{
		++disconnectionCount;
		debugLogA( _T("***** UpdateStatuses - Bad response from server, this has happened %d time(s)"), disconnectionCount);
		if (disconnectionCount > 2) {
			debugLogA( _T("***** UpdateStatuses - Too many bad responses from the server, signing off"));
			SetStatus(ID_STATUS_OFFLINE);
		}
	}
	catch(const std::exception &e)
	{
		ShowPopup( (std::string("While updating status messages, an error occurred: ")
			+e.what()).c_str());
		debugLogA( _T("***** Error updating status messages: %s"), e.what());
	}
}
示例#9
0
void Framework::Update()
{
	// Get the current time in milliseconds since the computer was turned on
	DWORD newFrameTime = timeGetTime();
	
	// Calculate the amount of milliseconds since the last update
	DWORD timeElapsed = newFrameTime - m_OldFrameTime;

	static float totalTime = 0.0f;
	totalTime += (timeElapsed / 1000.0f);

	// If someone's computer has been running for 49 days, the counter may wrap over
	if (newFrameTime < m_OldFrameTime)
	{
		timeElapsed = newFrameTime + (MAXDWORD - m_OldFrameTime);
	}

	// Update the 1 second accumulator
	m_OneSecondIntervalAccumulator += timeElapsed;

	// Increment the update accumulator;
	++m_UpdateAccumulator;

	if (m_OneSecondIntervalAccumulator >= kOneSecond)
	{
		DWORD secondElapsed = 0;

		while (m_OneSecondIntervalAccumulator >= kOneSecond)
		{
			++secondElapsed;
			m_OneSecondIntervalAccumulator -= kOneSecond;
		}

		m_CurrentFPS = m_UpdateAccumulator / secondElapsed;

		m_UpdateAccumulator = 0;
	}

	// Update the old time for the next update
	m_OldFrameTime = newFrameTime;

	glm::mat4 avatarOrientation;

	UpdateAvatar( timeElapsed, avatarOrientation );

	m_CameraManager->Update( timeElapsed );

	//static const GLfloat clearColor[] = { 0.34f, 0.34f, 0.9f, 1.0f };
	static const GLfloat clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
	static const GLfloat one = 1.0f;
	//static bool wireframe = true;
	//static bool enable_fog = true;
	//static bool enable_displacement = true;

	OpenGLInterface::ClearBufferfv( GL_COLOR, 0, clearColor );
	OpenGLInterface::ClearBufferfv( GL_DEPTH, 0, &one );

	const Camera* currentCamera = m_CameraManager->GetCurrentCamera();

	const glm::mat4& viewMatrix = currentCamera->GetOrientation();

	glm::mat4 projectionMatrix = glm::perspective( 45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 10000.0f );

	glViewport( 0, 0, windowWidth, windowHeight );

	m_Landscape.Render( projectionMatrix, viewMatrix );
	m_Loki.Render( projectionMatrix, viewMatrix );

#if 1
	glPolygonMode(GL_FRONT, GL_FILL);

	char stringBuffer[256];

	sprintf( stringBuffer, "FPS:%4u  Camera Mode: %s", m_CurrentFPS, currentCamera->GetName().c_str() );
	m_Text2D.drawText( stringBuffer, 0, 0 );

	glm::vec3 cameraPosition = currentCamera->GetPosition();
	glm::vec3 cameraDirection = currentCamera->GetForwardDirection();

	sprintf( stringBuffer, "Camera Position(%6.2f, %6.2f, %6.2f) Camera Direction(%6.2f, %6.2f, %6.2f)", cameraPosition[ 0 ], cameraPosition[ 1 ], cameraPosition[ 2 ], cameraDirection[ 0 ], cameraDirection[ 1 ], cameraDirection[ 2 ] );
	m_Text2D.drawText( stringBuffer, 0, 1 );

	sprintf( stringBuffer, "Avatar Position(%6.2f, %6.2f, %6.2f) Avatar Orientation(%6.2f, %6.2f, %6.2f)", m_PlayerPosition[ 0 ], m_PlayerPosition[ 1 ], m_PlayerPosition[ 2 ], m_PlayerOrientation[ 0 ], m_PlayerOrientation[ 1 ], m_PlayerOrientation[ 2 ] );
	m_Text2D.drawText( stringBuffer, 0, 2 );

	m_Text2D.draw();
#endif

	SwapBuffers(m_WindowHandleToDeviceContext);

	m_pInput->AdvanceFrame();
}